12#include "absl/strings/str_format.h"
33#include "imgui/imgui.h"
34#include "imgui/misc/cpp/imgui_stdlib.h"
35#include "nlohmann/json.hpp"
54 LOG_INFO(
"MusicEditor",
"Initialize() START: rom_=%p, emulator_=%p",
83 LOG_INFO(
"MusicEditor",
"Created shared audio backend: %s @ %dHz",
86 LOG_ERROR(
"MusicEditor",
"Failed to initialize audio backend!");
94 LOG_INFO(
"MusicEditor",
"Shared audio backend with main emulator");
97 "Cannot share with main emulator: backend=%p, emulator=%p",
105 LOG_INFO(
"MusicEditor",
"Set ROM on MusicPlayer");
107 LOG_WARN(
"MusicEditor",
"No ROM available for MusicPlayer!");
113 LOG_INFO(
"MusicEditor",
"Injected main emulator into MusicPlayer");
116 "No emulator available to inject into MusicPlayer!");
124 window_manager->
RegisterPanel({.card_id =
"music.song_browser",
125 .display_name =
"Song Browser",
126 .window_title =
" Song Browser",
129 .shortcut_hint =
"Ctrl+Shift+B",
131 window_manager->RegisterPanel({.card_id =
"music.tracker",
132 .display_name =
"Playback Control",
133 .window_title =
" Playback Control",
136 .shortcut_hint =
"Ctrl+Shift+M",
138 window_manager->RegisterPanel({.card_id =
"music.piano_roll",
139 .display_name =
"Piano Roll",
140 .window_title =
" Piano Roll",
143 .shortcut_hint =
"Ctrl+Shift+P",
145 window_manager->RegisterPanel({.card_id =
"music.instrument_editor",
146 .display_name =
"Instrument Editor",
147 .window_title =
" Instrument Editor",
150 .shortcut_hint =
"Ctrl+Shift+I",
152 window_manager->RegisterPanel({.card_id =
"music.sample_editor",
153 .display_name =
"Sample Editor",
154 .window_title =
" Sample Editor",
157 .shortcut_hint =
"Ctrl+Shift+S",
159 window_manager->RegisterPanel({.card_id =
"music.assembly",
160 .display_name =
"Assembly View",
161 .window_title =
" Music Assembly",
164 .shortcut_hint =
"Ctrl+Shift+A",
173 auto song_browser = std::make_unique<MusicSongBrowserPanel>(
175 window_manager->RegisterWindowContent(std::move(song_browser));
178 auto playback_control = std::make_unique<MusicPlaybackControlPanel>(
180 playback_control->SetOnOpenSong([
this](
int index) {
OpenSong(index); });
181 playback_control->SetOnOpenPianoRoll(
183 window_manager->RegisterWindowContent(std::move(playback_control));
186 auto piano_roll = std::make_unique<MusicPianoRollPanel>(
189 window_manager->RegisterWindowContent(std::move(piano_roll));
192 auto instrument_editor = std::make_unique<MusicInstrumentEditorPanel>(
194 window_manager->RegisterWindowContent(std::move(instrument_editor));
197 auto sample_editor = std::make_unique<MusicSampleEditorPanel>(
199 window_manager->RegisterWindowContent(std::move(sample_editor));
203 window_manager->RegisterWindowContent(std::move(assembly));
209 LOG_INFO(
"MusicEditor",
"set_emulator(%p): audio_backend_=%p",
217 "Shared audio backend with main emulator (deferred)");
250 if (restore.ok() && restore.value()) {
251 LOG_INFO(
"MusicEditor",
"Restored music state from web storage");
252 return absl::OkStatus();
253 }
else if (!restore.ok()) {
254 LOG_WARN(
"MusicEditor",
"Failed to restore music state: %s",
255 restore.status().ToString().c_str());
263 LOG_INFO(
"MusicEditor",
"Load(): Set ROM on MusicPlayer, IsAudioReady=%d",
268 LOG_WARN(
"MusicEditor",
"Load(): No ROM available!");
270 return absl::OkStatus();
277 if (state.is_playing && !state.is_paused) {
279 }
else if (state.is_paused) {
295 music_player_->SetPlaybackSpeed(state.playback_speed + delta);
302 music_player_->SetPlaybackSpeed(state.playback_speed - delta);
323 auto now = std::chrono::steady_clock::now();
326 elapsed > std::chrono::seconds(3))) {
329 LOG_WARN(
"MusicEditor",
"Music autosave failed: %s",
330 status.ToString().c_str());
337 return absl::OkStatus();
346 bool* browser_visible =
349 *browser_visible =
true;
354 bool* playback_visible =
355 window_manager->GetWindowVisibilityFlag(
"music.tracker");
357 *playback_visible =
true;
362 bool* piano_roll_visible =
363 window_manager->GetWindowVisibilityFlag(
"music.piano_roll");
365 *piano_roll_visible =
true;
378 std::string card_id = absl::StrFormat(
"music.song_%d", song_index);
381 bool panel_visible =
true;
387 if (!panel_visible) {
401 std::string active_category =
406 if (active_category !=
"Music" && !is_pinned) {
416 std::string song_name = song ? song->
name :
"Unknown";
417 std::string card_title = absl::StrFormat(
418 "[%02X] %s###SongTracker%d", song_index + 1, song_name, song_index);
422 song_cards_[song_index] = std::make_shared<gui::PanelWindow>(
428 std::make_unique<editor::music::TrackerView>();
438 if (song_card->Begin(&open)) {
458 int song_index = it->first;
459 auto& window = it->second;
462 std::string card_id = absl::StrFormat(
"music.piano_roll_%d", song_index);
464 if (!song || !window.card || !window.view) {
473 bool panel_visible =
true;
479 if (!panel_visible) {
483 delete window.visible_flag;
491 std::string active_category =
496 if (active_category !=
"Music" && !is_pinned) {
507 if (window.card->Begin(&open)) {
508 window.view->SetOnEditCallback(
510 window.view->SetOnNotePreview(
512 int segment_idx,
int channel_idx) {
516 music_player_->PreviewNote(*target, evt, segment_idx, channel_idx);
518 window.view->SetOnSegmentPreview(
529 window.view->SetPlaybackState(state.is_playing, state.is_paused,
531 window.view->Draw(song);
540 delete window.visible_flag;
549 return absl::OkStatus();
554 return absl::FailedPreconditionError(
"No ROM loaded");
559 if (!persist_status.ok()) {
560 return persist_status;
564 return absl::OkStatus();
574 if (!storage_or.ok()) {
579 auto parsed = nlohmann::json::parse(storage_or.value());
584 }
catch (
const std::exception& e) {
585 return absl::InvalidArgumentError(
586 absl::StrFormat(
"Failed to parse stored music state: %s", e.what()));
596 return absl::OkStatus();
604 auto now = std::chrono::system_clock::now();
605 auto time_t = std::chrono::system_clock::to_time_t(now);
606 std::stringstream ss;
607 ss << std::put_time(std::localtime(&time_t),
"%Y-%m-%d %H:%M:%S");
615 LOG_DEBUG(
"MusicEditor",
"Persisted music state (%s)", reason);
617 return absl::OkStatus();
620 return absl::OkStatus();
633 return absl::OkStatus();
639 return absl::UnimplementedError(
640 "Copy not yet implemented - clipboard support coming soon");
646 return absl::UnimplementedError(
647 "Paste not yet implemented - clipboard support coming soon");
738 std::string song_name =
739 song ? song->
name : absl::StrFormat(
"Song %02X", song_index);
741 std::string card_id = absl::StrFormat(
"music.song_%d", song_index);
745 .display_name = song_name,
751 .visibility_flag =
nullptr,
752 .priority = 200 + song_index});
759 LOG_INFO(
"MusicEditor",
"Opened song %d tracker window", song_index);
770 if (song_index < 0 ||
777 if (it->second.card && it->second.visible_flag) {
778 *it->second.visible_flag =
true;
779 it->second.card->Focus();
785 std::string song_name =
786 song ? song->
name : absl::StrFormat(
"Song %02X", song_index);
787 std::string card_title =
788 absl::StrFormat(
"[%02X] %s - Piano Roll###SongPianoRoll%d",
789 song_index + 1, song_name, song_index);
793 window.
card = std::make_shared<gui::PanelWindow>(
795 window.
card->SetDefaultSize(900, 450);
796 window.
view = std::make_unique<editor::music::PianoRollView>();
797 window.
view->SetActiveChannel(0);
798 window.
view->SetActiveSegment(0);
805 std::string card_id = absl::StrFormat(
"music.piano_roll_%d", song_index);
809 .display_name = song_name +
" (Piano)",
815 .visibility_flag =
nullptr,
816 .priority = 250 + song_index});
826 ImGui::TextDisabled(tr(
"Song not loaded"));
834 bool is_playing_this_song =
835 state.
is_playing && (state.playing_song_index == song_index);
836 bool is_paused_this_song =
837 state.is_paused && (state.playing_song_index == song_index);
841 ImGui::BeginDisabled();
844 if (is_playing_this_song && !is_paused_this_song) {
847 {{ImGuiCol_Button, sc.button}, {ImGuiCol_ButtonHovered, sc.hovered}});
851 }
else if (is_paused_this_song) {
854 {{ImGuiCol_Button, wc.button}, {ImGuiCol_ButtonHovered, wc.hovered}});
868 if (ImGui::IsItemHovered())
869 ImGui::SetTooltip(tr(
"Stop playback"));
872 ImGui::EndDisabled();
873 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) {
874 ImGui::SetTooltip(tr(
"Audio not ready - initialize music player first"));
879 if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) &&
882 if (ImGui::IsKeyPressed(ImGuiKey_Space,
false)) {
885 if (ImGui::IsKeyPressed(ImGuiKey_Escape,
false)) {
888 if (ImGui::IsKeyPressed(ImGuiKey_Equal,
false) ||
889 ImGui::IsKeyPressed(ImGuiKey_KeypadAdd,
false)) {
892 if (ImGui::IsKeyPressed(ImGuiKey_Minus,
false) ||
893 ImGui::IsKeyPressed(ImGuiKey_KeypadSubtract,
false)) {
900 if (is_playing_this_song && !is_paused_this_song) {
902 if (ImGui::IsItemHovered())
903 ImGui::SetTooltip(tr(
"Playing"));
904 }
else if (is_paused_this_song) {
906 if (ImGui::IsItemHovered())
907 ImGui::SetTooltip(tr(
"Paused"));
911 float right_offset = ImGui::GetWindowWidth() - 200;
912 ImGui::SameLine(right_offset);
917 ImGui::SetNextItemWidth(55);
918 float speed = state.playback_speed;
924 if (ImGui::IsItemHovered())
925 ImGui::SetTooltip(tr(
"Playback speed (0.25x - 2.0x) - use mouse wheel"));
931 if (ImGui::IsItemHovered())
932 ImGui::SetTooltip(tr(
"Open Piano Roll view"));
935 const char* bank_name =
nullptr;
936 switch (song->bank) {
938 bank_name =
"Overworld";
941 bank_name =
"Dungeon";
944 bank_name =
"Credits";
947 bank_name =
"Expanded";
950 bank_name =
"Auxiliary";
953 bank_name =
"Unknown";
958 ImGui::Text(
"%s", song->name.c_str());
962 if (song->modified) {
968 ImGui::SameLine(right_offset);
970 song->segments.size());
975 if (is_playing_this_song) {
1002 ImGui::Text(tr(
"Selected Song:"));
1009 ImGui::TextDisabled(tr(
"| %zu segments"), song->segments.size());
1010 if (song->modified) {
1017 if (state.is_playing || state.is_paused) {
1021 if (song && !song->segments.empty()) {
1022 uint32_t total_duration = 0;
1023 for (
const auto& seg : song->segments) {
1024 total_duration += seg.GetDuration();
1028 (total_duration > 0)
1029 ?
static_cast<float>(state.current_tick) / total_duration
1031 progress = std::clamp(progress, 0.0f, 1.0f);
1034 float current_seconds = state.ticks_per_second > 0
1035 ? state.current_tick / state.ticks_per_second
1037 float total_seconds = state.ticks_per_second > 0
1038 ? total_duration / state.ticks_per_second
1041 int cur_min =
static_cast<int>(current_seconds) / 60;
1042 int cur_sec =
static_cast<int>(current_seconds) % 60;
1043 int tot_min =
static_cast<int>(total_seconds) / 60;
1044 int tot_sec =
static_cast<int>(total_seconds) % 60;
1046 ImGui::Text(
"%d:%02d / %d:%02d", cur_min, cur_sec, tot_min, tot_sec);
1050 ImGui::ProgressBar(progress, ImVec2(-1, 0),
"");
1054 ImGui::Text(tr(
"Segment: %d | Tick: %u"), state.current_segment_index + 1,
1055 state.current_tick);
1057 ImGui::TextDisabled(tr(
"| %.1f ticks/sec | %.2fx speed"),
1058 state.ticks_per_second, state.playback_speed);
1062 if (state.is_playing) {
1073 if (ImGui::IsItemHovered())
1074 ImGui::SetTooltip(tr(
"Open song in dedicated tracker window"));
1080 if (ImGui::IsItemHovered())
1081 ImGui::SetTooltip(tr(
"Open piano roll view for this song"));
1085 ImGui::BulletText(tr(
"Space: Play/Pause toggle"));
1086 ImGui::BulletText(tr(
"Escape: Stop playback"));
1087 ImGui::BulletText(tr(
"+/-: Increase/decrease speed"));
1088 ImGui::BulletText(tr(
"Arrow keys: Navigate in tracker/piano roll"));
1089 ImGui::BulletText(tr(
"Z,S,X,D,C,V,G,B,H,N,J,M: Piano keyboard (C to B)"));
1090 ImGui::BulletText(tr(
"Ctrl+Wheel: Zoom (Piano Roll)"));
1112 int segment_idx,
int channel_idx) {
1116 music_player_->PreviewNote(*target, evt, segment_idx, channel_idx);
1131 state.current_tick);
1147 static int current_volume = 100;
1156 ImGui::BeginDisabled();
1158 if (state.is_playing && !state.is_paused) {
1162 }
else if (state.is_paused) {
1164 ImVec2(0, 0),
true))
1176 ImGui::EndDisabled();
1181 if (state.is_playing && !state.is_paused) {
1183 float t =
static_cast<float>(ImGui::GetTime() * 3.0);
1184 float alpha = 0.5f + 0.5f * std::sin(t);
1186 ImGui::TextColored(ImVec4(success_c.x, success_c.y, success_c.z, alpha),
1189 }
else if (state.is_paused) {
1194 ImGui::Text(
"%s", song->name.c_str());
1195 if (song->modified) {
1200 ImGui::TextDisabled(tr(
"No song selected"));
1204 if (state.is_playing || state.is_paused) {
1206 float seconds = state.ticks_per_second > 0
1207 ? state.current_tick / state.ticks_per_second
1209 int mins =
static_cast<int>(seconds) / 60;
1210 int secs =
static_cast<int>(seconds) % 60;
1215 float right_offset = ImGui::GetWindowWidth() - 380;
1216 ImGui::SameLine(right_offset);
1221 ImGui::SetNextItemWidth(70);
1222 float speed = state.playback_speed;
1228 if (ImGui::IsItemHovered())
1229 ImGui::SetTooltip(tr(
"Playback speed (+/- keys)"));
1234 ImGui::SetNextItemWidth(60);
1239 if (ImGui::IsItemHovered())
1240 ImGui::SetTooltip(tr(
"Volume"));
1245 ImGui::BeginDisabled();
1252 ImGui::EndDisabled();
1254 if (ImGui::IsItemHovered())
1255 ImGui::SetTooltip(tr(
"Reload from ROM"));
1259 ImGui::SetNextItemWidth(100);
1261 static int interpolation_type = 2;
1262 const char* items[] = {
"Linear",
"Hermite",
"Gaussian",
"Cosine",
"Cubic"};
1263 if (ImGui::Combo(
"##Interp", &interpolation_type, items,
1264 IM_ARRAYSIZE(items))) {
1268 if (ImGui::IsItemHovered())
1270 tr(
"Audio interpolation quality\nGaussian = authentic SNES sound"));
1276 if (ImGui::BeginTable(
1278 ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchProp)) {
1280 ImGui::TableSetupColumn(
"Master", ImGuiTableColumnFlags_WidthFixed, 60.0f);
1281 for (
int i = 0; i < 8; i++) {
1282 ImGui::TableSetupColumn(absl::StrFormat(
"Ch %d", i + 1).c_str());
1284 ImGui::TableHeadersRow();
1286 ImGui::TableNextRow();
1289 ImGui::TableSetColumnIndex(0);
1294 auto& dsp = audio_emu->
snes().apu().dsp();
1296 ImGui::Text(tr(
"Scope"));
1299 const int16_t* buffer = dsp.GetSampleBuffer();
1300 uint16_t offset = dsp.GetSampleOffset();
1302 static float scope_values[128];
1304 constexpr int kBufferSize = 0x400;
1305 for (
int i = 0; i < 128; i++) {
1306 int sample_idx = ((offset - 128 + i + kBufferSize) & (kBufferSize - 1));
1307 scope_values[i] =
static_cast<float>(buffer[sample_idx * 2]) /
1311 ImGui::PlotLines(
"##Scope", scope_values, 128, 0,
nullptr, -1.0f, 1.0f,
1316 for (
int i = 0; i < 8; i++) {
1317 ImGui::TableSetColumnIndex(i + 1);
1320 auto& dsp = audio_emu->
snes().apu().dsp();
1321 const auto& ch = dsp.GetChannel(i);
1324 bool is_muted = dsp.GetChannelMute(i);
1329 std::optional<gui::StyleColorGuard> mute_guard;
1331 mute_guard.emplace(ImGuiCol_Button,
1334 if (ImGui::Button(absl::StrFormat(
"M##%d", i).c_str(),
1336 dsp.SetChannelMute(i, !is_muted);
1343 std::optional<gui::StyleColorGuard> solo_guard;
1345 solo_guard.emplace(ImGuiCol_Button,
1348 if (ImGui::Button(absl::StrFormat(
"S##%d", i).c_str(),
1352 bool any_solo =
false;
1353 for (
int j = 0; j < 8; j++)
1357 for (
int j = 0; j < 8; j++) {
1361 dsp.SetChannelMute(j,
false);
1368 float level = std::abs(ch.sampleOut) / 32768.0f;
1369 ImGui::ProgressBar(level, ImVec2(-1, 60),
"");
1372 ImGui::Text(tr(
"Vol: %d %d"), ch.volumeL, ch.volumeR);
1373 ImGui::Text(tr(
"Pitch: %04X"), ch.pitch);
1380 ImGui::TextDisabled(
"---");
1383 ImGui::TextDisabled(tr(
"Offline"));
1396 if (audio_backend) {
1397 auto status = audio_backend->
GetStatus();
1398 auto config = audio_backend->GetConfig();
1399 bool resampling = audio_backend->IsAudioStreamEnabled();
1402 ImGui::Text(tr(
"Backend: %s @ %dHz | Queue: %u frames"),
1403 audio_backend->GetBackendName().c_str(), config.sample_rate,
1404 status.queued_frames);
1409 tr(
"Resampling: 32040 -> %d Hz"),
1410 config.sample_rate);
1413 " Resampling DISABLED - 1.5x speed bug!");
1416 if (status.has_underrun) {
1421 ImGui::TextDisabled(tr(
"Open Audio Debug panel for full diagnostics"));
1424 ImGui::TextDisabled(tr(
"Play a song to see audio status"));
1431 ImGui::TextDisabled(tr(
"Music player not initialized"));
1437 if (!audio_emu || !audio_emu->is_snes_initialized()) {
1438 ImGui::TextDisabled(tr(
"Play a song to see channel activity"));
1443 ImVec2 avail = ImGui::GetContentRegionAvail();
1444 if (avail.y < 50.0f) {
1445 ImGui::TextDisabled(tr(
"(Channel view - expand for details)"));
1451 if (ImGui::BeginTable(
1452 "ChannelOverview", 9,
1453 ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchProp)) {
1454 ImGui::TableSetupColumn(
"Master", ImGuiTableColumnFlags_WidthFixed, 70.0f);
1455 for (
int i = 0; i < 8; i++) {
1456 ImGui::TableSetupColumn(absl::StrFormat(
"Ch %d", i + 1).c_str());
1458 ImGui::TableHeadersRow();
1460 ImGui::TableNextRow();
1462 ImGui::TableSetColumnIndex(0);
1463 ImGui::Text(tr(
"DSP Live"));
1465 for (
int ch = 0; ch < 8; ++ch) {
1466 ImGui::TableSetColumnIndex(ch + 1);
1467 const auto& state = channel_states[ch];
1473 ImGui::TextDisabled(tr(
"OFF"));
1477 float vol_l = state.volume_l / 128.0f;
1478 float vol_r = state.volume_r / 128.0f;
1479 ImGui::ProgressBar(vol_l, ImVec2(-1, 6.0f),
"");
1480 ImGui::ProgressBar(vol_r, ImVec2(-1, 6.0f),
"");
1483 ImGui::Text(tr(
"S: %02X"), state.sample_index);
1484 ImGui::Text(tr(
"P: %04X"), state.pitch);
1487 const char* adsr_str =
"???";
1488 switch (state.adsr_state) {
1502 ImGui::Text(
"%s", adsr_str);
1525 LOG_WARN(
"MusicEditor",
"ExportSongToAsm: Invalid song index %d",
1548 auto result = exporter.
ExportSong(*song, options);
1550 LOG_ERROR(
"MusicEditor",
"ExportSongToAsm failed: %s",
1551 result.status().message().data());
1560 LOG_INFO(
"MusicEditor",
"Exported song '%s' to ASM (%zu bytes)",
1569 LOG_INFO(
"MusicEditor",
"No ASM source to import - showing import dialog");
1602 const auto message = result.status().message();
1604 LOG_ERROR(
"MusicEditor",
"ImportSongFromAsm failed: %s",
1610 for (
const auto& warning : result->warnings) {
1611 LOG_WARN(
"MusicEditor",
"ASM import warning: %s", warning.c_str());
1619 std::string original_name = song->name;
1620 *song = result->song;
1621 if (song->name.empty()) {
1622 song->name = original_name;
1624 song->modified =
true;
1626 LOG_INFO(
"MusicEditor",
"Imported ASM to song '%s' (%d lines, %d bytes)",
1627 song->name.c_str(), result->lines_parsed, result->bytes_generated);
1639 ImGui::OpenPopup(
"Export Song ASM");
1643 ImGui::OpenPopup(
"Import Song ASM");
1647 if (ImGui::BeginPopupModal(
"Export Song ASM",
nullptr,
1648 ImGuiWindowFlags_AlwaysAutoResize)) {
1650 tr(
"Copy the generated ASM below or tweak before saving."));
1651 ImGui::InputTextMultiline(
"##AsmExportText", &
asm_buffer_, ImVec2(520, 260),
1652 ImGuiInputTextFlags_AllowTabInput);
1654 if (ImGui::Button(tr(
"Copy to Clipboard"))) {
1658 if (ImGui::Button(tr(
"Close"))) {
1659 ImGui::CloseCurrentPopup();
1665 if (ImGui::BeginPopupModal(
"Import Song ASM",
nullptr,
1666 ImGuiWindowFlags_AlwaysAutoResize)) {
1669 if (song_slot > 0) {
1670 ImGui::Text(tr(
"Target Song: [%02X]"), song_slot);
1672 ImGui::TextDisabled(tr(
"Select a song to import into"));
1674 ImGui::TextWrapped(tr(
"Paste Oracle of Secrets-compatible ASM here."));
1676 ImGui::InputTextMultiline(
"##AsmImportText", &
asm_buffer_, ImVec2(520, 260),
1677 ImGuiInputTextFlags_AllowTabInput);
1687 ImGui::BeginDisabled();
1689 if (ImGui::Button(tr(
"Import"))) {
1693 ImGui::CloseCurrentPopup();
1697 ImGui::EndDisabled();
1701 if (ImGui::Button(tr(
"Cancel"))) {
1705 ImGui::CloseCurrentPopup();
UndoManager undo_manager_
project::YazeProject * project() const
virtual void SetDependencies(const EditorDependencies &deps)
EditorDependencies dependencies_
void DrawInstrumentEditor()
std::unordered_map< int, std::unique_ptr< editor::music::TrackerView > > song_trackers_
void FocusSong(int song_index)
std::unique_ptr< emu::audio::IAudioBackend > audio_backend_
bool persist_custom_music_
ImVector< int > active_songs_
std::vector< bool > channel_soloed_
int current_segment_index_
void SlowDown(float delta=0.1f)
std::string music_storage_key_
void DrawSongTrackerWindow(int song_index)
emu::Emulator * emulator_
std::unordered_map< int, std::shared_ptr< gui::PanelWindow > > song_cards_
void DrawChannelOverview()
std::optional< zelda3::music::MusicSong > pending_undo_before_
absl::Status Paste() override
zelda3::music::MusicBank music_bank_
std::unordered_map< int, SongPianoRollWindow > song_piano_rolls_
void SetProject(project::YazeProject *project)
void Initialize() override
bool show_asm_export_popup_
void OpenSong(int song_index)
emu::Emulator * emulator() const
void ExportSongToAsm(int song_index)
editor::music::SampleEditorView sample_editor_view_
absl::Status Save() override
void FinalizePendingUndo()
absl::Status Cut() override
int current_channel_index_
void OpenSongPianoRoll(int song_index)
absl::Status Load() override
void SetDependencies(const EditorDependencies &deps) override
void ImportSongFromAsm(int song_index)
absl::StatusOr< bool > RestoreMusicState()
absl::Status Copy() override
void SpeedUp(float delta=0.1f)
absl::Status PersistMusicState(const char *reason=nullptr)
absl::Status Update() override
void DrawPlaybackControl()
editor::music::InstrumentEditorView instrument_editor_view_
bool song_browser_auto_shown_
int pending_undo_song_index_
std::unique_ptr< editor::music::MusicPlayer > music_player_
void set_emulator(emu::Emulator *emulator)
absl::Status Undo() override
absl::Status Redo() override
std::vector< std::string > song_names_
int asm_import_target_index_
bool show_asm_import_popup_
std::chrono::steady_clock::time_point last_music_persist_
std::string asm_import_error_
AssemblyEditor assembly_editor_
bool ImportAsmBufferToSong(int song_index)
project::YazeProject * project_
bool piano_roll_auto_shown_
void SeekToSegment(int segment_index)
editor::music::TrackerView tracker_view_
editor::music::SongBrowserView song_browser_view_
editor::music::PianoRollView piano_roll_view_
ImGuiWindowClass song_window_class_
void Push(std::unique_ptr< UndoAction > action)
absl::Status Redo()
Redo the top action. Returns error if stack is empty.
absl::Status Undo()
Undo the top action. Returns error if stack is empty.
void RegisterPanel(size_t session_id, const WindowDescriptor &base_info)
void UnregisterPanel(size_t session_id, const std::string &base_card_id)
std::string GetActiveCategory() const
void RegisterWindow(size_t session_id, const WindowDescriptor &descriptor)
bool IsWindowOpen(size_t session_id, const std::string &base_window_id) const
bool OpenWindow(size_t session_id, const std::string &base_window_id)
bool IsWindowPinned(size_t session_id, const std::string &base_window_id) const
bool * GetWindowVisibilityFlag(size_t session_id, const std::string &base_window_id)
void UnregisterWindow(size_t session_id, const std::string &base_window_id)
void Draw(MusicBank &bank)
Draw the instrument editor.
int GetActiveSegment() const
int GetActiveChannel() const
void SetActiveSegment(int segment)
void SetPlaybackState(bool is_playing, bool is_paused, uint32_t current_tick)
void Draw(zelda3::music::MusicSong *song, const zelda3::music::MusicBank *bank=nullptr)
Draw the piano roll view for the given song.
void SetOnNotePreview(std::function< void(const zelda3::music::TrackEvent &, int, int)> callback)
Set callback for note preview.
void SetActiveChannel(int channel)
void SetOnEditCallback(std::function< void()> callback)
Set callback for when edits occur.
void SetOnSegmentPreview(std::function< void(const zelda3::music::MusicSong &, int)> callback)
Set callback for segment preview.
void Draw(MusicBank &bank)
Draw the sample editor.
int GetSelectedSongIndex() const
void Draw(MusicBank &bank)
Draw the song browser.
void SetSelectedSongIndex(int index)
void Draw(MusicSong *song, const MusicBank *bank=nullptr)
Draw the tracker view for the given song.
A class for emulating and debugging SNES games.
void SetExternalAudioBackend(audio::IAudioBackend *backend)
bool is_snes_initialized() const
audio::IAudioBackend * audio_backend()
static std::unique_ptr< IAudioBackend > Create(BackendType type)
virtual AudioStatus GetStatus() const =0
RAII timer for automatic timing management.
RAII guard for ImGui style colors.
const Theme & GetCurrentTheme() const
static ThemeManager & Get()
Exports MusicSong to Oracle of Secrets music_macros.asm format.
absl::StatusOr< std::string > ExportSong(const MusicSong &song, const AsmExportOptions &options)
Export a song to ASM string.
Imports music_macros.asm format files into MusicSong.
absl::StatusOr< AsmParseResult > ImportSong(const std::string &asm_source, const AsmImportOptions &options)
Import a song from ASM string.
bool HasModifications() const
Check if any music data has been modified.
nlohmann::json ToJson() const
absl::Status LoadFromJson(const nlohmann::json &j)
MusicSong * GetSong(int index)
Get a song by index.
size_t GetSongCount() const
Get the number of songs loaded.
absl::Status SaveToRom(Rom &rom)
Save all modified music data back to ROM.
bool IsExpandedSong(int index) const
Check if a song is from an expanded bank.
absl::Status LoadFromRom(Rom &rom)
Load all music data from a ROM.
#define ICON_MD_PAUSE_CIRCLE
#define ICON_MD_LIBRARY_MUSIC
#define ICON_MD_VOLUME_UP
#define ICON_MD_PLAY_ARROW
#define ICON_MD_BUG_REPORT
#define ICON_MD_GRAPHIC_EQ
#define ICON_MD_MUSIC_NOTE
#define ICON_MD_PLAY_CIRCLE
#define ICON_MD_OPEN_IN_NEW
#define LOG_DEBUG(category, format,...)
#define LOG_ERROR(category, format,...)
#define LOG_WARN(category, format,...)
#define LOG_INFO(category, format,...)
bool ThemedIconButton(const char *icon, const char *tooltip, const ImVec2 &size, bool is_active, bool is_disabled, const char *panel_id, const char *anim_id)
Draw a standard icon button with theme-aware colors.
ImVec4 ConvertColorToImVec4(const Color &color)
bool SliderIntWheel(const char *label, int *v, int v_min, int v_max, const char *format, int wheel_step, ImGuiSliderFlags flags)
ButtonColorSet GetWarningButtonColors()
bool SliderFloatWheel(const char *label, float *v, float v_min, float v_max, const char *format, float wheel_step, ImGuiSliderFlags flags)
ButtonColorSet GetSuccessButtonColors()
ImVec4 GetDisabledColor()
constexpr uint16_t kAuxSongTableAram
constexpr uint16_t kSongTableAram
#define RETURN_IF_ERROR(expr)
Unified dependency container for all editor types.
project::YazeProject * project
WorkspaceWindowManager * window_manager
std::unique_ptr< editor::music::PianoRollView > view
std::shared_ptr< gui::PanelWindow > card
static WindowPresentationPolicy OptionalPopOut()
Represents the current playback state of the music player.
std::string last_saved_at
bool persist_custom_music
Modern project structure with comprehensive settings consolidation.
std::string MakeStorageKey(absl::string_view suffix) const
struct yaze::project::YazeProject::MusicPersistence music_persistence
Options for ASM export in music_macros.asm format.
bool use_instrument_macros
uint16_t base_aram_address
Options for ASM import from music_macros.asm format.
A complete song composed of segments.
A single event in a music track (note, command, or control).