11#include "absl/strings/str_format.h"
31#include "imgui/imgui.h"
32#include "imgui/misc/cpp/imgui_stdlib.h"
33#include "nlohmann/json.hpp"
52 LOG_INFO(
"MusicEditor",
"Initialize() START: rom_=%p, emulator_=%p",
81 LOG_INFO(
"MusicEditor",
"Created shared audio backend: %s @ %dHz",
84 LOG_ERROR(
"MusicEditor",
"Failed to initialize audio backend!");
92 LOG_INFO(
"MusicEditor",
"Shared audio backend with main emulator");
95 "Cannot share with main emulator: backend=%p, emulator=%p",
103 LOG_INFO(
"MusicEditor",
"Set ROM on MusicPlayer");
105 LOG_WARN(
"MusicEditor",
"No ROM available for MusicPlayer!");
111 LOG_INFO(
"MusicEditor",
"Injected main emulator into MusicPlayer");
114 "No emulator available to inject into MusicPlayer!");
122 window_manager->
RegisterPanel({.card_id =
"music.song_browser",
123 .display_name =
"Song Browser",
124 .window_title =
" Song Browser",
127 .shortcut_hint =
"Ctrl+Shift+B",
129 window_manager->RegisterPanel({.card_id =
"music.tracker",
130 .display_name =
"Playback Control",
131 .window_title =
" Playback Control",
134 .shortcut_hint =
"Ctrl+Shift+M",
136 window_manager->RegisterPanel({.card_id =
"music.piano_roll",
137 .display_name =
"Piano Roll",
138 .window_title =
" Piano Roll",
141 .shortcut_hint =
"Ctrl+Shift+P",
143 window_manager->RegisterPanel({.card_id =
"music.instrument_editor",
144 .display_name =
"Instrument Editor",
145 .window_title =
" Instrument Editor",
148 .shortcut_hint =
"Ctrl+Shift+I",
150 window_manager->RegisterPanel({.card_id =
"music.sample_editor",
151 .display_name =
"Sample Editor",
152 .window_title =
" Sample Editor",
155 .shortcut_hint =
"Ctrl+Shift+S",
157 window_manager->RegisterPanel({.card_id =
"music.assembly",
158 .display_name =
"Assembly View",
159 .window_title =
" Music Assembly",
162 .shortcut_hint =
"Ctrl+Shift+A",
171 auto song_browser = std::make_unique<MusicSongBrowserPanel>(
173 window_manager->RegisterWindowContent(std::move(song_browser));
176 auto playback_control = std::make_unique<MusicPlaybackControlPanel>(
178 playback_control->SetOnOpenSong([
this](
int index) {
OpenSong(index); });
179 playback_control->SetOnOpenPianoRoll(
181 window_manager->RegisterWindowContent(std::move(playback_control));
184 auto piano_roll = std::make_unique<MusicPianoRollPanel>(
187 window_manager->RegisterWindowContent(std::move(piano_roll));
190 auto instrument_editor = std::make_unique<MusicInstrumentEditorPanel>(
192 window_manager->RegisterWindowContent(std::move(instrument_editor));
195 auto sample_editor = std::make_unique<MusicSampleEditorPanel>(
197 window_manager->RegisterWindowContent(std::move(sample_editor));
201 window_manager->RegisterWindowContent(std::move(assembly));
207 LOG_INFO(
"MusicEditor",
"set_emulator(%p): audio_backend_=%p",
215 "Shared audio backend with main emulator (deferred)");
248 if (restore.ok() && restore.value()) {
249 LOG_INFO(
"MusicEditor",
"Restored music state from web storage");
250 return absl::OkStatus();
251 }
else if (!restore.ok()) {
252 LOG_WARN(
"MusicEditor",
"Failed to restore music state: %s",
253 restore.status().ToString().c_str());
261 LOG_INFO(
"MusicEditor",
"Load(): Set ROM on MusicPlayer, IsAudioReady=%d",
266 LOG_WARN(
"MusicEditor",
"Load(): No ROM available!");
268 return absl::OkStatus();
275 if (state.is_playing && !state.is_paused) {
277 }
else if (state.is_paused) {
293 music_player_->SetPlaybackSpeed(state.playback_speed + delta);
300 music_player_->SetPlaybackSpeed(state.playback_speed - delta);
321 auto now = std::chrono::steady_clock::now();
324 elapsed > std::chrono::seconds(3))) {
327 LOG_WARN(
"MusicEditor",
"Music autosave failed: %s",
328 status.ToString().c_str());
335 return absl::OkStatus();
344 bool* browser_visible =
347 *browser_visible =
true;
352 bool* playback_visible =
353 window_manager->GetWindowVisibilityFlag(
"music.tracker");
355 *playback_visible =
true;
360 bool* piano_roll_visible =
361 window_manager->GetWindowVisibilityFlag(
"music.piano_roll");
363 *piano_roll_visible =
true;
376 std::string card_id = absl::StrFormat(
"music.song_%d", song_index);
379 bool panel_visible =
true;
385 if (!panel_visible) {
399 std::string active_category =
404 if (active_category !=
"Music" && !is_pinned) {
414 std::string song_name = song ? song->
name :
"Unknown";
415 std::string card_title = absl::StrFormat(
416 "[%02X] %s###SongTracker%d", song_index + 1, song_name, song_index);
420 song_cards_[song_index] = std::make_shared<gui::PanelWindow>(
426 std::make_unique<editor::music::TrackerView>();
436 if (song_card->Begin(&open)) {
456 int song_index = it->first;
457 auto& window = it->second;
460 std::string card_id = absl::StrFormat(
"music.piano_roll_%d", song_index);
462 if (!song || !window.card || !window.view) {
471 bool panel_visible =
true;
477 if (!panel_visible) {
481 delete window.visible_flag;
489 std::string active_category =
494 if (active_category !=
"Music" && !is_pinned) {
505 if (window.card->Begin(&open)) {
506 window.view->SetOnEditCallback(
508 window.view->SetOnNotePreview(
510 int segment_idx,
int channel_idx) {
514 music_player_->PreviewNote(*target, evt, segment_idx, channel_idx);
516 window.view->SetOnSegmentPreview(
527 window.view->SetPlaybackState(state.is_playing, state.is_paused,
529 window.view->Draw(song);
538 delete window.visible_flag;
547 return absl::OkStatus();
552 return absl::FailedPreconditionError(
"No ROM loaded");
557 if (!persist_status.ok()) {
558 return persist_status;
562 return absl::OkStatus();
572 if (!storage_or.ok()) {
577 auto parsed = nlohmann::json::parse(storage_or.value());
582 }
catch (
const std::exception& e) {
583 return absl::InvalidArgumentError(
584 absl::StrFormat(
"Failed to parse stored music state: %s", e.what()));
594 return absl::OkStatus();
602 auto now = std::chrono::system_clock::now();
603 auto time_t = std::chrono::system_clock::to_time_t(now);
604 std::stringstream ss;
605 ss << std::put_time(std::localtime(&time_t),
"%Y-%m-%d %H:%M:%S");
613 LOG_DEBUG(
"MusicEditor",
"Persisted music state (%s)", reason);
615 return absl::OkStatus();
618 return absl::OkStatus();
631 return absl::OkStatus();
637 return absl::UnimplementedError(
638 "Copy not yet implemented - clipboard support coming soon");
644 return absl::UnimplementedError(
645 "Paste not yet implemented - clipboard support coming soon");
737 std::string song_name =
738 song ? song->
name : absl::StrFormat(
"Song %02X", song_index);
740 std::string card_id = absl::StrFormat(
"music.song_%d", song_index);
744 .display_name = song_name,
749 .visibility_flag =
nullptr,
750 .priority = 200 + song_index});
757 LOG_INFO(
"MusicEditor",
"Opened song %d tracker window", song_index);
768 if (song_index < 0 ||
775 if (it->second.card && it->second.visible_flag) {
776 *it->second.visible_flag =
true;
777 it->second.card->Focus();
783 std::string song_name =
784 song ? song->
name : absl::StrFormat(
"Song %02X", song_index);
785 std::string card_title =
786 absl::StrFormat(
"[%02X] %s - Piano Roll###SongPianoRoll%d",
787 song_index + 1, song_name, song_index);
791 window.
card = std::make_shared<gui::PanelWindow>(
793 window.
card->SetDefaultSize(900, 450);
794 window.
view = std::make_unique<editor::music::PianoRollView>();
795 window.
view->SetActiveChannel(0);
796 window.
view->SetActiveSegment(0);
803 std::string card_id = absl::StrFormat(
"music.piano_roll_%d", song_index);
807 .display_name = song_name +
" (Piano)",
812 .visibility_flag =
nullptr,
813 .priority = 250 + song_index});
823 ImGui::TextDisabled(
"Song not loaded");
831 bool is_playing_this_song =
832 state.
is_playing && (state.playing_song_index == song_index);
833 bool is_paused_this_song =
834 state.is_paused && (state.playing_song_index == song_index);
838 ImGui::BeginDisabled();
841 if (is_playing_this_song && !is_paused_this_song) {
844 {{ImGuiCol_Button, sc.button},
845 {ImGuiCol_ButtonHovered, sc.hovered}});
849 }
else if (is_paused_this_song) {
852 {{ImGuiCol_Button, wc.button},
853 {ImGuiCol_ButtonHovered, wc.hovered}});
867 if (ImGui::IsItemHovered())
868 ImGui::SetTooltip(
"Stop playback");
871 ImGui::EndDisabled();
872 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) {
873 ImGui::SetTooltip(
"Audio not ready - initialize music player first");
878 if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) &&
881 if (ImGui::IsKeyPressed(ImGuiKey_Space,
false)) {
884 if (ImGui::IsKeyPressed(ImGuiKey_Escape,
false)) {
887 if (ImGui::IsKeyPressed(ImGuiKey_Equal,
false) ||
888 ImGui::IsKeyPressed(ImGuiKey_KeypadAdd,
false)) {
891 if (ImGui::IsKeyPressed(ImGuiKey_Minus,
false) ||
892 ImGui::IsKeyPressed(ImGuiKey_KeypadSubtract,
false)) {
899 if (is_playing_this_song && !is_paused_this_song) {
901 if (ImGui::IsItemHovered())
902 ImGui::SetTooltip(
"Playing");
903 }
else if (is_paused_this_song) {
905 if (ImGui::IsItemHovered())
906 ImGui::SetTooltip(
"Paused");
910 float right_offset = ImGui::GetWindowWidth() - 200;
911 ImGui::SameLine(right_offset);
916 ImGui::SetNextItemWidth(55);
917 float speed = state.playback_speed;
923 if (ImGui::IsItemHovered())
924 ImGui::SetTooltip(
"Playback speed (0.25x - 2.0x) - use mouse wheel");
930 if (ImGui::IsItemHovered())
931 ImGui::SetTooltip(
"Open Piano Roll view");
934 const char* bank_name =
nullptr;
935 switch (song->bank) {
937 bank_name =
"Overworld";
940 bank_name =
"Dungeon";
943 bank_name =
"Credits";
946 bank_name =
"Expanded";
949 bank_name =
"Auxiliary";
952 bank_name =
"Unknown";
957 ImGui::Text(
"%s", song->name.c_str());
961 if (song->modified) {
968 ImGui::SameLine(right_offset);
970 song->segments.size());
975 if (is_playing_this_song) {
1002 ImGui::Text(
"Selected Song:");
1009 ImGui::TextDisabled(
"| %zu segments", song->segments.size());
1010 if (song->modified) {
1018 if (state.is_playing || state.is_paused) {
1022 if (song && !song->segments.empty()) {
1023 uint32_t total_duration = 0;
1024 for (
const auto& seg : song->segments) {
1025 total_duration += seg.GetDuration();
1029 (total_duration > 0)
1030 ?
static_cast<float>(state.current_tick) / total_duration
1032 progress = std::clamp(progress, 0.0f, 1.0f);
1035 float current_seconds = state.ticks_per_second > 0
1036 ? state.current_tick / state.ticks_per_second
1038 float total_seconds = state.ticks_per_second > 0
1039 ? total_duration / state.ticks_per_second
1042 int cur_min =
static_cast<int>(current_seconds) / 60;
1043 int cur_sec =
static_cast<int>(current_seconds) % 60;
1044 int tot_min =
static_cast<int>(total_seconds) / 60;
1045 int tot_sec =
static_cast<int>(total_seconds) % 60;
1047 ImGui::Text(
"%d:%02d / %d:%02d", cur_min, cur_sec, tot_min, tot_sec);
1051 ImGui::ProgressBar(progress, ImVec2(-1, 0),
"");
1055 ImGui::Text(
"Segment: %d | Tick: %u", state.current_segment_index + 1,
1056 state.current_tick);
1058 ImGui::TextDisabled(
"| %.1f ticks/sec | %.2fx speed",
1059 state.ticks_per_second, state.playback_speed);
1063 if (state.is_playing) {
1074 if (ImGui::IsItemHovered())
1075 ImGui::SetTooltip(
"Open song in dedicated tracker window");
1081 if (ImGui::IsItemHovered())
1082 ImGui::SetTooltip(
"Open piano roll view for this song");
1086 ImGui::BulletText(
"Space: Play/Pause toggle");
1087 ImGui::BulletText(
"Escape: Stop playback");
1088 ImGui::BulletText(
"+/-: Increase/decrease speed");
1089 ImGui::BulletText(
"Arrow keys: Navigate in tracker/piano roll");
1090 ImGui::BulletText(
"Z,S,X,D,C,V,G,B,H,N,J,M: Piano keyboard (C to B)");
1091 ImGui::BulletText(
"Ctrl+Wheel: Zoom (Piano Roll)");
1113 int segment_idx,
int channel_idx) {
1117 music_player_->PreviewNote(*target, evt, segment_idx, channel_idx);
1132 state.current_tick);
1148 static int current_volume = 100;
1157 ImGui::BeginDisabled();
1162 if (state.is_playing && !state.is_paused) {
1167 if (ImGui::IsItemHovered())
1168 ImGui::SetTooltip(
"Pause (Space)");
1169 }
else if (state.is_paused) {
1174 if (ImGui::IsItemHovered())
1175 ImGui::SetTooltip(
"Resume (Space)");
1179 if (ImGui::IsItemHovered())
1180 ImGui::SetTooltip(
"Play (Space)");
1186 if (ImGui::IsItemHovered())
1187 ImGui::SetTooltip(
"Stop (Escape)");
1190 ImGui::EndDisabled();
1195 if (state.is_playing && !state.is_paused) {
1197 float t =
static_cast<float>(ImGui::GetTime() * 3.0);
1198 float alpha = 0.5f + 0.5f * std::sin(t);
1200 ImGui::TextColored(ImVec4(success_c.x, success_c.y, success_c.z, alpha),
1203 }
else if (state.is_paused) {
1207 ImGui::Text(
"%s", song->name.c_str());
1208 if (song->modified) {
1213 ImGui::TextDisabled(
"No song selected");
1217 if (state.is_playing || state.is_paused) {
1219 float seconds = state.ticks_per_second > 0
1220 ? state.current_tick / state.ticks_per_second
1222 int mins =
static_cast<int>(seconds) / 60;
1223 int secs =
static_cast<int>(seconds) % 60;
1228 float right_offset = ImGui::GetWindowWidth() - 380;
1229 ImGui::SameLine(right_offset);
1234 ImGui::SetNextItemWidth(70);
1235 float speed = state.playback_speed;
1241 if (ImGui::IsItemHovered())
1242 ImGui::SetTooltip(
"Playback speed (+/- keys)");
1247 ImGui::SetNextItemWidth(60);
1252 if (ImGui::IsItemHovered())
1253 ImGui::SetTooltip(
"Volume");
1258 ImGui::BeginDisabled();
1265 ImGui::EndDisabled();
1267 if (ImGui::IsItemHovered())
1268 ImGui::SetTooltip(
"Reload from ROM");
1272 ImGui::SetNextItemWidth(100);
1274 static int interpolation_type = 2;
1275 const char* items[] = {
"Linear",
"Hermite",
"Gaussian",
"Cosine",
"Cubic"};
1276 if (ImGui::Combo(
"##Interp", &interpolation_type, items,
1277 IM_ARRAYSIZE(items))) {
1281 if (ImGui::IsItemHovered())
1283 "Audio interpolation quality\nGaussian = authentic SNES sound");
1289 if (ImGui::BeginTable(
1291 ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchProp)) {
1293 ImGui::TableSetupColumn(
"Master", ImGuiTableColumnFlags_WidthFixed, 60.0f);
1294 for (
int i = 0; i < 8; i++) {
1295 ImGui::TableSetupColumn(absl::StrFormat(
"Ch %d", i + 1).c_str());
1297 ImGui::TableHeadersRow();
1299 ImGui::TableNextRow();
1302 ImGui::TableSetColumnIndex(0);
1307 auto& dsp = audio_emu->
snes().apu().dsp();
1309 ImGui::Text(
"Scope");
1312 const int16_t* buffer = dsp.GetSampleBuffer();
1313 uint16_t offset = dsp.GetSampleOffset();
1315 static float scope_values[128];
1317 constexpr int kBufferSize = 0x400;
1318 for (
int i = 0; i < 128; i++) {
1319 int sample_idx = ((offset - 128 + i + kBufferSize) & (kBufferSize - 1));
1320 scope_values[i] =
static_cast<float>(buffer[sample_idx * 2]) /
1324 ImGui::PlotLines(
"##Scope", scope_values, 128, 0,
nullptr, -1.0f, 1.0f,
1329 for (
int i = 0; i < 8; i++) {
1330 ImGui::TableSetColumnIndex(i + 1);
1333 auto& dsp = audio_emu->
snes().apu().dsp();
1334 const auto& ch = dsp.GetChannel(i);
1337 bool is_muted = dsp.GetChannelMute(i);
1342 std::optional<gui::StyleColorGuard> mute_guard;
1344 mute_guard.emplace(ImGuiCol_Button,
1347 if (ImGui::Button(absl::StrFormat(
"M##%d", i).c_str(),
1349 dsp.SetChannelMute(i, !is_muted);
1356 std::optional<gui::StyleColorGuard> solo_guard;
1358 solo_guard.emplace(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);
1381 float level = std::abs(ch.sampleOut) / 32768.0f;
1382 ImGui::ProgressBar(level, ImVec2(-1, 60),
"");
1385 ImGui::Text(
"Vol: %d %d", ch.volumeL, ch.volumeR);
1386 ImGui::Text(
"Pitch: %04X", ch.pitch);
1393 ImGui::TextDisabled(
"---");
1396 ImGui::TextDisabled(
"Offline");
1409 if (audio_backend) {
1410 auto status = audio_backend->
GetStatus();
1411 auto config = audio_backend->GetConfig();
1412 bool resampling = audio_backend->IsAudioStreamEnabled();
1415 ImGui::Text(
"Backend: %s @ %dHz | Queue: %u frames",
1416 audio_backend->GetBackendName().c_str(), config.sample_rate,
1417 status.queued_frames);
1422 "Resampling: 32040 -> %d Hz", config.sample_rate);
1425 " Resampling DISABLED - 1.5x speed bug!");
1428 if (status.has_underrun) {
1433 ImGui::TextDisabled(
"Open Audio Debug panel for full diagnostics");
1436 ImGui::TextDisabled(
"Play a song to see audio status");
1443 ImGui::TextDisabled(
"Music player not initialized");
1449 if (!audio_emu || !audio_emu->is_snes_initialized()) {
1450 ImGui::TextDisabled(
"Play a song to see channel activity");
1455 ImVec2 avail = ImGui::GetContentRegionAvail();
1456 if (avail.y < 50.0f) {
1457 ImGui::TextDisabled(
"(Channel view - expand for details)");
1463 if (ImGui::BeginTable(
1464 "ChannelOverview", 9,
1465 ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchProp)) {
1466 ImGui::TableSetupColumn(
"Master", ImGuiTableColumnFlags_WidthFixed, 70.0f);
1467 for (
int i = 0; i < 8; i++) {
1468 ImGui::TableSetupColumn(absl::StrFormat(
"Ch %d", i + 1).c_str());
1470 ImGui::TableHeadersRow();
1472 ImGui::TableNextRow();
1474 ImGui::TableSetColumnIndex(0);
1475 ImGui::Text(
"DSP Live");
1477 for (
int ch = 0; ch < 8; ++ch) {
1478 ImGui::TableSetColumnIndex(ch + 1);
1479 const auto& state = channel_states[ch];
1485 ImGui::TextDisabled(
"OFF");
1489 float vol_l = state.volume_l / 128.0f;
1490 float vol_r = state.volume_r / 128.0f;
1491 ImGui::ProgressBar(vol_l, ImVec2(-1, 6.0f),
"");
1492 ImGui::ProgressBar(vol_r, ImVec2(-1, 6.0f),
"");
1495 ImGui::Text(
"S: %02X", state.sample_index);
1496 ImGui::Text(
"P: %04X", state.pitch);
1499 const char* adsr_str =
"???";
1500 switch (state.adsr_state) {
1514 ImGui::Text(
"%s", adsr_str);
1537 LOG_WARN(
"MusicEditor",
"ExportSongToAsm: Invalid song index %d",
1560 auto result = exporter.
ExportSong(*song, options);
1562 LOG_ERROR(
"MusicEditor",
"ExportSongToAsm failed: %s",
1563 result.status().message().data());
1572 LOG_INFO(
"MusicEditor",
"Exported song '%s' to ASM (%zu bytes)",
1581 LOG_INFO(
"MusicEditor",
"No ASM source to import - showing import dialog");
1614 const auto message = result.status().message();
1616 LOG_ERROR(
"MusicEditor",
"ImportSongFromAsm failed: %s",
1622 for (
const auto& warning : result->warnings) {
1623 LOG_WARN(
"MusicEditor",
"ASM import warning: %s", warning.c_str());
1631 std::string original_name = song->name;
1632 *song = result->song;
1633 if (song->name.empty()) {
1634 song->name = original_name;
1636 song->modified =
true;
1638 LOG_INFO(
"MusicEditor",
"Imported ASM to song '%s' (%d lines, %d bytes)",
1639 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);
1698 ImGui::BeginDisabled();
1700 if (ImGui::Button(
"Import")) {
1704 ImGui::CloseCurrentPopup();
1708 ImGui::EndDisabled();
1712 if (ImGui::Button(
"Cancel")) {
1716 ImGui::CloseCurrentPopup();
UndoManager undo_manager_
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,...)
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
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).