9#include "absl/strings/str_format.h"
28#include "imgui/imgui.h"
29#include "imgui/misc/cpp/imgui_stdlib.h"
30#include "nlohmann/json.hpp"
42 LOG_INFO(
"MusicEditor",
"Initialize() START: rom_=%p, emulator_=%p",
71 LOG_INFO(
"MusicEditor",
"Created shared audio backend: %s @ %dHz",
74 LOG_ERROR(
"MusicEditor",
"Failed to initialize audio backend!");
82 LOG_INFO(
"MusicEditor",
"Shared audio backend with main emulator");
85 "Cannot share with main emulator: backend=%p, emulator=%p",
93 LOG_INFO(
"MusicEditor",
"Set ROM on MusicPlayer");
95 LOG_WARN(
"MusicEditor",
"No ROM available for MusicPlayer!");
101 LOG_INFO(
"MusicEditor",
"Injected main emulator into MusicPlayer");
104 "No emulator available to inject into MusicPlayer!");
112 panel_manager->
RegisterPanel({.card_id =
"music.song_browser",
113 .display_name =
"Song Browser",
114 .window_title =
" Song Browser",
117 .shortcut_hint =
"Ctrl+Shift+B",
119 panel_manager->RegisterPanel({.card_id =
"music.tracker",
120 .display_name =
"Playback Control",
121 .window_title =
" Playback Control",
124 .shortcut_hint =
"Ctrl+Shift+M",
126 panel_manager->RegisterPanel({.card_id =
"music.piano_roll",
127 .display_name =
"Piano Roll",
128 .window_title =
" Piano Roll",
131 .shortcut_hint =
"Ctrl+Shift+P",
133 panel_manager->RegisterPanel({.card_id =
"music.instrument_editor",
134 .display_name =
"Instrument Editor",
135 .window_title =
" Instrument Editor",
138 .shortcut_hint =
"Ctrl+Shift+I",
140 panel_manager->RegisterPanel({.card_id =
"music.sample_editor",
141 .display_name =
"Sample Editor",
142 .window_title =
" Sample Editor",
145 .shortcut_hint =
"Ctrl+Shift+S",
147 panel_manager->RegisterPanel({.card_id =
"music.assembly",
148 .display_name =
"Assembly View",
149 .window_title =
" Music Assembly",
152 .shortcut_hint =
"Ctrl+Shift+A",
154 panel_manager->RegisterPanel({.card_id =
"music.audio_debug",
155 .display_name =
"Audio Debug",
156 .window_title =
" Audio Debug",
161 panel_manager->RegisterPanel({.card_id =
"music.help",
162 .display_name =
"Help",
163 .window_title =
" Music Editor Help",
175 auto song_browser = std::make_unique<MusicSongBrowserPanel>(
177 panel_manager->RegisterEditorPanel(std::move(song_browser));
180 auto playback_control = std::make_unique<MusicPlaybackControlPanel>(
182 playback_control->SetOnOpenSong([
this](
int index) {
OpenSong(index); });
183 playback_control->SetOnOpenPianoRoll(
185 panel_manager->RegisterEditorPanel(std::move(playback_control));
188 auto piano_roll = std::make_unique<MusicPianoRollPanel>(
191 panel_manager->RegisterEditorPanel(std::move(piano_roll));
194 auto instrument_editor = std::make_unique<MusicInstrumentEditorPanel>(
196 panel_manager->RegisterEditorPanel(std::move(instrument_editor));
199 auto sample_editor = std::make_unique<MusicSampleEditorPanel>(
201 panel_manager->RegisterEditorPanel(std::move(sample_editor));
205 panel_manager->RegisterEditorPanel(std::move(assembly));
210 panel_manager->RegisterEditorPanel(std::move(audio_debug));
213 auto help = std::make_unique<MusicHelpPanel>();
214 panel_manager->RegisterEditorPanel(std::move(help));
218 LOG_INFO(
"MusicEditor",
"set_emulator(%p): audio_backend_=%p",
226 "Shared audio backend with main emulator (deferred)");
259 if (restore.ok() && restore.value()) {
260 LOG_INFO(
"MusicEditor",
"Restored music state from web storage");
261 return absl::OkStatus();
262 }
else if (!restore.ok()) {
263 LOG_WARN(
"MusicEditor",
"Failed to restore music state: %s",
264 restore.status().ToString().c_str());
272 LOG_INFO(
"MusicEditor",
"Load(): Set ROM on MusicPlayer, IsAudioReady=%d",
277 LOG_WARN(
"MusicEditor",
"Load(): No ROM available!");
279 return absl::OkStatus();
286 if (state.is_playing && !state.is_paused) {
288 }
else if (state.is_paused) {
304 music_player_->SetPlaybackSpeed(state.playback_speed + delta);
311 music_player_->SetPlaybackSpeed(state.playback_speed - delta);
332 auto now = std::chrono::steady_clock::now();
335 elapsed > std::chrono::seconds(3))) {
338 LOG_WARN(
"MusicEditor",
"Music autosave failed: %s",
339 status.ToString().c_str());
346 return absl::OkStatus();
355 bool* browser_visible =
358 *browser_visible =
true;
363 bool* playback_visible = panel_manager->GetVisibilityFlag(
"music.tracker");
365 *playback_visible =
true;
370 static bool piano_roll_auto_shown =
false;
371 bool* piano_roll_visible =
372 panel_manager->GetVisibilityFlag(
"music.piano_roll");
373 if (piano_roll_visible && !piano_roll_auto_shown) {
374 *piano_roll_visible =
true;
375 piano_roll_auto_shown =
true;
387 std::string card_id = absl::StrFormat(
"music.song_%d", song_index);
390 bool panel_visible =
true;
396 if (!panel_visible) {
410 std::string active_category =
415 if (active_category !=
"Music" && !is_pinned) {
425 std::string song_name = song ? song->
name :
"Unknown";
426 std::string card_title = absl::StrFormat(
427 "[%02X] %s###SongTracker%d", song_index + 1, song_name, song_index);
431 song_cards_[song_index] = std::make_shared<gui::PanelWindow>(
437 std::make_unique<editor::music::TrackerView>();
447 if (song_card->Begin(&open)) {
467 int song_index = it->first;
468 auto& window = it->second;
471 std::string card_id = absl::StrFormat(
"music.piano_roll_%d", song_index);
473 if (!song || !window.card || !window.view) {
482 bool panel_visible =
true;
488 if (!panel_visible) {
492 delete window.visible_flag;
500 std::string active_category =
505 if (active_category !=
"Music" && !is_pinned) {
516 if (window.card->Begin(&open)) {
517 window.view->SetOnEditCallback([
this]() {
PushUndoState(); });
518 window.view->SetOnNotePreview(
520 int segment_idx,
int channel_idx) {
524 music_player_->PreviewNote(*target, evt, segment_idx, channel_idx);
526 window.view->SetOnSegmentPreview(
537 window.view->SetPlaybackState(state.is_playing, state.is_paused,
539 window.view->Draw(song);
548 delete window.visible_flag;
557 return absl::OkStatus();
562 return absl::FailedPreconditionError(
"No ROM loaded");
567 if (!persist_status.ok()) {
568 return persist_status;
572 return absl::OkStatus();
582 if (!storage_or.ok()) {
587 auto parsed = nlohmann::json::parse(storage_or.value());
592 }
catch (
const std::exception& e) {
593 return absl::InvalidArgumentError(
594 absl::StrFormat(
"Failed to parse stored music state: %s", e.what()));
604 return absl::OkStatus();
612 auto now = std::chrono::system_clock::now();
613 auto time_t = std::chrono::system_clock::to_time_t(now);
614 std::stringstream ss;
615 ss << std::put_time(std::localtime(&time_t),
"%Y-%m-%d %H:%M:%S");
623 LOG_DEBUG(
"MusicEditor",
"Persisted music state (%s)", reason);
625 return absl::OkStatus();
628 return absl::OkStatus();
641 return absl::OkStatus();
647 return absl::UnimplementedError(
648 "Copy not yet implemented - clipboard support coming soon");
654 return absl::UnimplementedError(
655 "Paste not yet implemented - clipboard support coming soon");
660 return absl::FailedPreconditionError(
"Nothing to undo");
672 return absl::OkStatus();
677 return absl::FailedPreconditionError(
"Nothing to redo");
689 return absl::OkStatus();
704 constexpr size_t kMaxUndoStates = 50;
753 std::string song_name =
754 song ? song->
name : absl::StrFormat(
"Song %02X", song_index);
756 std::string card_id = absl::StrFormat(
"music.song_%d", song_index);
760 .display_name = song_name,
765 .visibility_flag =
nullptr,
766 .priority = 200 + song_index});
773 LOG_INFO(
"MusicEditor",
"Opened song %d tracker window", song_index);
784 if (song_index < 0 ||
791 if (it->second.card && it->second.visible_flag) {
792 *it->second.visible_flag =
true;
793 it->second.card->Focus();
799 std::string song_name =
800 song ? song->
name : absl::StrFormat(
"Song %02X", song_index);
801 std::string card_title =
802 absl::StrFormat(
"[%02X] %s - Piano Roll###SongPianoRoll%d",
803 song_index + 1, song_name, song_index);
807 window.
card = std::make_shared<gui::PanelWindow>(
809 window.
card->SetDefaultSize(900, 450);
810 window.
view = std::make_unique<editor::music::PianoRollView>();
811 window.
view->SetActiveChannel(0);
812 window.
view->SetActiveSegment(0);
819 std::string card_id = absl::StrFormat(
"music.piano_roll_%d", song_index);
823 .display_name = song_name +
" (Piano)",
828 .visibility_flag =
nullptr,
829 .priority = 250 + song_index});
839 ImGui::TextDisabled(
"Song not loaded");
847 bool is_playing_this_song =
848 state.
is_playing && (state.playing_song_index == song_index);
849 bool is_paused_this_song =
850 state.is_paused && (state.playing_song_index == song_index);
854 ImGui::BeginDisabled();
857 if (is_playing_this_song && !is_paused_this_song) {
858 ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.5f, 0.2f, 1.0f));
859 ImGui::PushStyleColor(ImGuiCol_ButtonHovered,
860 ImVec4(0.3f, 0.6f, 0.3f, 1.0f));
864 ImGui::PopStyleColor(2);
865 }
else if (is_paused_this_song) {
866 ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.5f, 0.5f, 0.2f, 1.0f));
867 ImGui::PushStyleColor(ImGuiCol_ButtonHovered,
868 ImVec4(0.6f, 0.6f, 0.3f, 1.0f));
872 ImGui::PopStyleColor(2);
883 if (ImGui::IsItemHovered())
884 ImGui::SetTooltip(
"Stop playback");
887 ImGui::EndDisabled();
890 if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) &&
893 if (ImGui::IsKeyPressed(ImGuiKey_Space,
false)) {
896 if (ImGui::IsKeyPressed(ImGuiKey_Escape,
false)) {
899 if (ImGui::IsKeyPressed(ImGuiKey_Equal,
false) ||
900 ImGui::IsKeyPressed(ImGuiKey_KeypadAdd,
false)) {
903 if (ImGui::IsKeyPressed(ImGuiKey_Minus,
false) ||
904 ImGui::IsKeyPressed(ImGuiKey_KeypadSubtract,
false)) {
911 if (is_playing_this_song && !is_paused_this_song) {
913 if (ImGui::IsItemHovered())
914 ImGui::SetTooltip(
"Playing");
915 }
else if (is_paused_this_song) {
917 if (ImGui::IsItemHovered())
918 ImGui::SetTooltip(
"Paused");
922 float right_offset = ImGui::GetWindowWidth() - 200;
923 ImGui::SameLine(right_offset);
928 ImGui::SetNextItemWidth(55);
929 float speed = state.playback_speed;
935 if (ImGui::IsItemHovered())
936 ImGui::SetTooltip(
"Playback speed (0.25x - 2.0x) - use mouse wheel");
942 if (ImGui::IsItemHovered())
943 ImGui::SetTooltip(
"Open Piano Roll view");
946 const char* bank_name =
nullptr;
947 switch (song->bank) {
949 bank_name =
"Overworld";
952 bank_name =
"Dungeon";
955 bank_name =
"Credits";
958 bank_name =
"Expanded";
961 bank_name =
"Auxiliary";
964 bank_name =
"Unknown";
967 ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1.0f),
"[%02X]", song_index + 1);
969 ImGui::Text(
"%s", song->name.c_str());
971 ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.7f, 1.0f),
"(%s)", bank_name);
973 if (song->modified) {
975 ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.2f, 1.0f),
980 ImGui::SameLine(right_offset);
981 ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1.0f),
"%zu segments",
982 song->segments.size());
987 if (is_playing_this_song) {
1014 ImGui::Text(
"Selected Song:");
1016 ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f),
"[%02X] %s",
1021 ImGui::TextDisabled(
"| %zu segments", song->segments.size());
1022 if (song->modified) {
1024 ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.2f, 1.0f),
1030 if (state.is_playing || state.is_paused) {
1034 if (song && !song->segments.empty()) {
1035 uint32_t total_duration = 0;
1036 for (
const auto& seg : song->segments) {
1037 total_duration += seg.GetDuration();
1041 (total_duration > 0)
1042 ?
static_cast<float>(state.current_tick) / total_duration
1044 progress = std::clamp(progress, 0.0f, 1.0f);
1047 float current_seconds = state.ticks_per_second > 0
1048 ? state.current_tick / state.ticks_per_second
1050 float total_seconds = state.ticks_per_second > 0
1051 ? total_duration / state.ticks_per_second
1054 int cur_min =
static_cast<int>(current_seconds) / 60;
1055 int cur_sec =
static_cast<int>(current_seconds) % 60;
1056 int tot_min =
static_cast<int>(total_seconds) / 60;
1057 int tot_sec =
static_cast<int>(total_seconds) % 60;
1059 ImGui::Text(
"%d:%02d / %d:%02d", cur_min, cur_sec, tot_min, tot_sec);
1063 ImGui::ProgressBar(progress, ImVec2(-1, 0),
"");
1067 ImGui::Text(
"Segment: %d | Tick: %u", state.current_segment_index + 1,
1068 state.current_tick);
1070 ImGui::TextDisabled(
"| %.1f ticks/sec | %.2fx speed",
1071 state.ticks_per_second, state.playback_speed);
1075 if (state.is_playing) {
1086 if (ImGui::IsItemHovered())
1087 ImGui::SetTooltip(
"Open song in dedicated tracker window");
1093 if (ImGui::IsItemHovered())
1094 ImGui::SetTooltip(
"Open piano roll view for this song");
1098 ImGui::BulletText(
"Space: Play/Pause toggle");
1099 ImGui::BulletText(
"Escape: Stop playback");
1100 ImGui::BulletText(
"+/-: Increase/decrease speed");
1101 ImGui::BulletText(
"Arrow keys: Navigate in tracker/piano roll");
1102 ImGui::BulletText(
"Z,S,X,D,C,V,G,B,H,N,J,M: Piano keyboard (C to B)");
1103 ImGui::BulletText(
"Ctrl+Wheel: Zoom (Piano Roll)");
1125 int segment_idx,
int channel_idx) {
1129 music_player_->PreviewNote(*target, evt, segment_idx, channel_idx);
1144 state.current_tick);
1160 static int current_volume = 100;
1169 ImGui::BeginDisabled();
1172 const ImVec4 paused_color(0.9f, 0.7f, 0.2f, 1.0f);
1174 if (state.is_playing && !state.is_paused) {
1175 ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.5f, 0.2f, 1.0f));
1178 ImGui::PopStyleColor();
1179 if (ImGui::IsItemHovered())
1180 ImGui::SetTooltip(
"Pause (Space)");
1181 }
else if (state.is_paused) {
1182 ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.5f, 0.4f, 0.1f, 1.0f));
1185 ImGui::PopStyleColor();
1186 if (ImGui::IsItemHovered())
1187 ImGui::SetTooltip(
"Resume (Space)");
1191 if (ImGui::IsItemHovered())
1192 ImGui::SetTooltip(
"Play (Space)");
1198 if (ImGui::IsItemHovered())
1199 ImGui::SetTooltip(
"Stop (Escape)");
1202 ImGui::EndDisabled();
1207 if (state.is_playing && !state.is_paused) {
1209 float t =
static_cast<float>(ImGui::GetTime() * 3.0);
1210 float alpha = 0.5f + 0.5f * std::sin(t);
1213 }
else if (state.is_paused) {
1217 ImGui::Text(
"%s", song->name.c_str());
1218 if (song->modified) {
1220 ImGui::TextColored(ImVec4(1.0f, 0.8f, 0.2f, 1.0f),
ICON_MD_EDIT);
1223 ImGui::TextDisabled(
"No song selected");
1227 if (state.is_playing || state.is_paused) {
1229 float seconds = state.ticks_per_second > 0
1230 ? state.current_tick / state.ticks_per_second
1232 int mins =
static_cast<int>(seconds) / 60;
1233 int secs =
static_cast<int>(seconds) % 60;
1234 ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.8f, 1.0f),
" %d:%02d", mins, secs);
1238 float right_offset = ImGui::GetWindowWidth() - 380;
1239 ImGui::SameLine(right_offset);
1244 ImGui::SetNextItemWidth(70);
1245 float speed = state.playback_speed;
1251 if (ImGui::IsItemHovered())
1252 ImGui::SetTooltip(
"Playback speed (+/- keys)");
1257 ImGui::SetNextItemWidth(60);
1262 if (ImGui::IsItemHovered())
1263 ImGui::SetTooltip(
"Volume");
1270 if (ImGui::IsItemHovered())
1271 ImGui::SetTooltip(
"Reload from ROM");
1275 ImGui::SetNextItemWidth(100);
1277 static int interpolation_type = 2;
1278 const char* items[] = {
"Linear",
"Hermite",
"Gaussian",
"Cosine",
"Cubic"};
1279 if (ImGui::Combo(
"##Interp", &interpolation_type, items,
1280 IM_ARRAYSIZE(items))) {
1284 if (ImGui::IsItemHovered())
1286 "Audio interpolation quality\nGaussian = authentic SNES sound");
1292 if (ImGui::BeginTable(
1294 ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchProp)) {
1296 ImGui::TableSetupColumn(
"Master", ImGuiTableColumnFlags_WidthFixed, 60.0f);
1297 for (
int i = 0; i < 8; i++) {
1298 ImGui::TableSetupColumn(absl::StrFormat(
"Ch %d", i + 1).c_str());
1300 ImGui::TableHeadersRow();
1302 ImGui::TableNextRow();
1305 ImGui::TableSetColumnIndex(0);
1310 auto& dsp = audio_emu->
snes().apu().dsp();
1312 ImGui::Text(
"Scope");
1315 const int16_t* buffer = dsp.GetSampleBuffer();
1316 uint16_t offset = dsp.GetSampleOffset();
1318 static float scope_values[128];
1320 constexpr int kBufferSize = 0x400;
1321 for (
int i = 0; i < 128; i++) {
1322 int sample_idx = ((offset - 128 + i + kBufferSize) & (kBufferSize - 1));
1323 scope_values[i] =
static_cast<float>(buffer[sample_idx * 2]) /
1327 ImGui::PlotLines(
"##Scope", scope_values, 128, 0,
nullptr, -1.0f, 1.0f,
1332 for (
int i = 0; i < 8; i++) {
1333 ImGui::TableSetColumnIndex(i + 1);
1336 auto& dsp = audio_emu->
snes().apu().dsp();
1337 const auto& ch = dsp.GetChannel(i);
1340 bool is_muted = dsp.GetChannelMute(i);
1345 ImGui::PushStyleColor(ImGuiCol_Button,
1348 if (ImGui::Button(absl::StrFormat(
"M##%d", i).c_str(),
1350 dsp.SetChannelMute(i, !is_muted);
1353 ImGui::PopStyleColor();
1358 ImGui::PushStyleColor(ImGuiCol_Button,
1361 if (ImGui::Button(absl::StrFormat(
"S##%d", i).c_str(),
1365 bool any_solo =
false;
1366 for (
int j = 0; j < 8; j++)
1370 for (
int j = 0; j < 8; j++) {
1374 dsp.SetChannelMute(j,
false);
1379 ImGui::PopStyleColor();
1382 float level = std::abs(ch.sampleOut) / 32768.0f;
1383 ImGui::ProgressBar(level, ImVec2(-1, 60),
"");
1386 ImGui::Text(
"Vol: %d %d", ch.volumeL, ch.volumeR);
1387 ImGui::Text(
"Pitch: %04X", ch.pitch);
1394 ImGui::TextDisabled(
"---");
1397 ImGui::TextDisabled(
"Offline");
1410 if (audio_backend) {
1411 auto status = audio_backend->
GetStatus();
1412 auto config = audio_backend->GetConfig();
1413 bool resampling = audio_backend->IsAudioStreamEnabled();
1416 ImGui::Text(
"Backend: %s @ %dHz | Queue: %u frames",
1417 audio_backend->GetBackendName().c_str(), config.sample_rate,
1418 status.queued_frames);
1422 ImGui::TextColored(ImVec4(0.3f, 0.9f, 0.3f, 1.0f),
1423 "Resampling: 32040 -> %d Hz", config.sample_rate);
1426 " Resampling DISABLED - 1.5x speed bug!");
1429 if (status.has_underrun) {
1430 ImGui::TextColored(ImVec4(1.0f, 0.5f, 0.0f, 1.0f),
1434 ImGui::TextDisabled(
"Open Audio Debug panel for full diagnostics");
1437 ImGui::TextDisabled(
"Play a song to see audio status");
1444 ImGui::TextDisabled(
"Music player not initialized");
1450 if (!audio_emu || !audio_emu->is_snes_initialized()) {
1451 ImGui::TextDisabled(
"Play a song to see channel activity");
1456 ImVec2 avail = ImGui::GetContentRegionAvail();
1457 if (avail.y < 50.0f) {
1458 ImGui::TextDisabled(
"(Channel view - expand for details)");
1464 if (ImGui::BeginTable(
1465 "ChannelOverview", 9,
1466 ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchProp)) {
1467 ImGui::TableSetupColumn(
"Master", ImGuiTableColumnFlags_WidthFixed, 70.0f);
1468 for (
int i = 0; i < 8; i++) {
1469 ImGui::TableSetupColumn(absl::StrFormat(
"Ch %d", i + 1).c_str());
1471 ImGui::TableHeadersRow();
1473 ImGui::TableNextRow();
1475 ImGui::TableSetColumnIndex(0);
1476 ImGui::Text(
"DSP Live");
1478 for (
int ch = 0; ch < 8; ++ch) {
1479 ImGui::TableSetColumnIndex(ch + 1);
1480 const auto& state = channel_states[ch];
1484 ImGui::TextColored(ImVec4(0.2f, 1.0f, 0.2f, 1.0f),
"ON");
1486 ImGui::TextDisabled(
"OFF");
1490 float vol_l = state.volume_l / 128.0f;
1491 float vol_r = state.volume_r / 128.0f;
1492 ImGui::ProgressBar(vol_l, ImVec2(-1, 6.0f),
"");
1493 ImGui::ProgressBar(vol_r, ImVec2(-1, 6.0f),
"");
1496 ImGui::Text(
"S: %02X", state.sample_index);
1497 ImGui::Text(
"P: %04X", state.pitch);
1500 const char* adsr_str =
"???";
1501 switch (state.adsr_state) {
1515 ImGui::Text(
"%s", adsr_str);
1538 LOG_WARN(
"MusicEditor",
"ExportSongToAsm: Invalid song index %d",
1561 auto result = exporter.
ExportSong(*song, options);
1563 LOG_ERROR(
"MusicEditor",
"ExportSongToAsm failed: %s",
1564 result.status().message().data());
1573 LOG_INFO(
"MusicEditor",
"Exported song '%s' to ASM (%zu bytes)",
1582 LOG_INFO(
"MusicEditor",
"No ASM source to import - showing import dialog");
1615 const auto message = result.status().message();
1617 LOG_ERROR(
"MusicEditor",
"ImportSongFromAsm failed: %s",
1623 for (
const auto& warning : result->warnings) {
1624 LOG_WARN(
"MusicEditor",
"ASM import warning: %s", warning.c_str());
1629 std::string original_name = song->name;
1630 *song = result->song;
1631 if (song->name.empty()) {
1632 song->name = original_name;
1634 song->modified =
true;
1636 LOG_INFO(
"MusicEditor",
"Imported ASM to song '%s' (%d lines, %d bytes)",
1637 song->name.c_str(), result->lines_parsed, result->bytes_generated);
1651 ImGui::OpenPopup(
"Export Song ASM");
1655 ImGui::OpenPopup(
"Import Song ASM");
1659 if (ImGui::BeginPopupModal(
"Export Song ASM",
nullptr,
1660 ImGuiWindowFlags_AlwaysAutoResize)) {
1661 ImGui::TextWrapped(
"Copy the generated ASM below or tweak before saving.");
1662 ImGui::InputTextMultiline(
"##AsmExportText", &
asm_buffer_, ImVec2(520, 260),
1663 ImGuiInputTextFlags_AllowTabInput);
1665 if (ImGui::Button(
"Copy to Clipboard")) {
1669 if (ImGui::Button(
"Close")) {
1670 ImGui::CloseCurrentPopup();
1676 if (ImGui::BeginPopupModal(
"Import Song ASM",
nullptr,
1677 ImGuiWindowFlags_AlwaysAutoResize)) {
1680 if (song_slot > 0) {
1681 ImGui::Text(
"Target Song: [%02X]", song_slot);
1683 ImGui::TextDisabled(
"Select a song to import into");
1685 ImGui::TextWrapped(
"Paste Oracle of Secrets-compatible ASM here.");
1687 ImGui::InputTextMultiline(
"##AsmImportText", &
asm_buffer_, ImVec2(520, 260),
1688 ImGuiInputTextFlags_AllowTabInput);
1691 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.9f, 0.3f, 0.3f, 1.0f));
1693 ImGui::PopStyleColor();
1698 ImGui::BeginDisabled();
1700 if (ImGui::Button(
"Import")) {
1704 ImGui::CloseCurrentPopup();
1708 ImGui::EndDisabled();
1712 if (ImGui::Button(
"Cancel")) {
1716 ImGui::CloseCurrentPopup();
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()
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_
std::vector< UndoState > undo_stack_
void OpenSong(int song_index)
emu::Emulator * emulator() const
void ExportSongToAsm(int song_index)
editor::music::SampleEditorView sample_editor_view_
absl::Status Save() override
absl::Status Cut() override
int current_channel_index_
void OpenSongPianoRoll(int song_index)
absl::Status Load() override
void RestoreState(const UndoState &state)
void ImportSongFromAsm(int song_index)
absl::StatusOr< bool > RestoreMusicState()
absl::Status Copy() override
std::vector< UndoState > redo_stack_
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_
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_
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_
bool * GetVisibilityFlag(size_t session_id, const std::string &base_card_id)
bool ShowPanel(size_t session_id, const std::string &base_card_id)
void RegisterPanel(size_t session_id, const PanelDescriptor &base_info)
std::string GetActiveCategory() const
bool IsPanelVisible(size_t session_id, const std::string &base_card_id) const
void UnregisterPanel(size_t session_id, const std::string &base_card_id)
bool IsPanelPinned(size_t session_id, const std::string &base_card_id) const
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.
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,...)
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)
bool SliderFloatWheel(const char *label, float *v, float v_min, float v_max, const char *format, float wheel_step, ImGuiSliderFlags flags)
constexpr uint16_t kAuxSongTableAram
constexpr uint16_t kSongTableAram
#define RETURN_IF_ERROR(expr)
PanelManager * panel_manager
std::unique_ptr< editor::music::PianoRollView > view
std::shared_ptr< gui::PanelWindow > card
zelda3::music::MusicSong song_snapshot
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).