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 panel_manager->
RegisterPanel({.card_id =
"music.song_browser",
123 .display_name =
"Song Browser",
124 .window_title =
" Song Browser",
127 .shortcut_hint =
"Ctrl+Shift+B",
129 panel_manager->RegisterPanel({.card_id =
"music.tracker",
130 .display_name =
"Playback Control",
131 .window_title =
" Playback Control",
134 .shortcut_hint =
"Ctrl+Shift+M",
136 panel_manager->RegisterPanel({.card_id =
"music.piano_roll",
137 .display_name =
"Piano Roll",
138 .window_title =
" Piano Roll",
141 .shortcut_hint =
"Ctrl+Shift+P",
143 panel_manager->RegisterPanel({.card_id =
"music.instrument_editor",
144 .display_name =
"Instrument Editor",
145 .window_title =
" Instrument Editor",
148 .shortcut_hint =
"Ctrl+Shift+I",
150 panel_manager->RegisterPanel({.card_id =
"music.sample_editor",
151 .display_name =
"Sample Editor",
152 .window_title =
" Sample Editor",
155 .shortcut_hint =
"Ctrl+Shift+S",
157 panel_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 panel_manager->RegisterEditorPanel(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 panel_manager->RegisterEditorPanel(std::move(playback_control));
184 auto piano_roll = std::make_unique<MusicPianoRollPanel>(
187 panel_manager->RegisterEditorPanel(std::move(piano_roll));
190 auto instrument_editor = std::make_unique<MusicInstrumentEditorPanel>(
192 panel_manager->RegisterEditorPanel(std::move(instrument_editor));
195 auto sample_editor = std::make_unique<MusicSampleEditorPanel>(
197 panel_manager->RegisterEditorPanel(std::move(sample_editor));
201 panel_manager->RegisterEditorPanel(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 = panel_manager->GetVisibilityFlag(
"music.tracker");
354 *playback_visible =
true;
359 bool* piano_roll_visible =
360 panel_manager->GetVisibilityFlag(
"music.piano_roll");
362 *piano_roll_visible =
true;
375 std::string card_id = absl::StrFormat(
"music.song_%d", song_index);
378 bool panel_visible =
true;
384 if (!panel_visible) {
398 std::string active_category =
403 if (active_category !=
"Music" && !is_pinned) {
413 std::string song_name = song ? song->
name :
"Unknown";
414 std::string card_title = absl::StrFormat(
415 "[%02X] %s###SongTracker%d", song_index + 1, song_name, song_index);
419 song_cards_[song_index] = std::make_shared<gui::PanelWindow>(
425 std::make_unique<editor::music::TrackerView>();
435 if (song_card->Begin(&open)) {
455 int song_index = it->first;
456 auto& window = it->second;
459 std::string card_id = absl::StrFormat(
"music.piano_roll_%d", song_index);
461 if (!song || !window.card || !window.view) {
470 bool panel_visible =
true;
476 if (!panel_visible) {
480 delete window.visible_flag;
488 std::string active_category =
493 if (active_category !=
"Music" && !is_pinned) {
504 if (window.card->Begin(&open)) {
505 window.view->SetOnEditCallback(
507 window.view->SetOnNotePreview(
509 int segment_idx,
int channel_idx) {
513 music_player_->PreviewNote(*target, evt, segment_idx, channel_idx);
515 window.view->SetOnSegmentPreview(
526 window.view->SetPlaybackState(state.is_playing, state.is_paused,
528 window.view->Draw(song);
537 delete window.visible_flag;
546 return absl::OkStatus();
551 return absl::FailedPreconditionError(
"No ROM loaded");
556 if (!persist_status.ok()) {
557 return persist_status;
561 return absl::OkStatus();
571 if (!storage_or.ok()) {
576 auto parsed = nlohmann::json::parse(storage_or.value());
581 }
catch (
const std::exception& e) {
582 return absl::InvalidArgumentError(
583 absl::StrFormat(
"Failed to parse stored music state: %s", e.what()));
593 return absl::OkStatus();
601 auto now = std::chrono::system_clock::now();
602 auto time_t = std::chrono::system_clock::to_time_t(now);
603 std::stringstream ss;
604 ss << std::put_time(std::localtime(&time_t),
"%Y-%m-%d %H:%M:%S");
612 LOG_DEBUG(
"MusicEditor",
"Persisted music state (%s)", reason);
614 return absl::OkStatus();
617 return absl::OkStatus();
630 return absl::OkStatus();
636 return absl::UnimplementedError(
637 "Copy not yet implemented - clipboard support coming soon");
643 return absl::UnimplementedError(
644 "Paste not yet implemented - clipboard support coming soon");
736 std::string song_name =
737 song ? song->
name : absl::StrFormat(
"Song %02X", song_index);
739 std::string card_id = absl::StrFormat(
"music.song_%d", song_index);
743 .display_name = song_name,
748 .visibility_flag =
nullptr,
749 .priority = 200 + song_index});
756 LOG_INFO(
"MusicEditor",
"Opened song %d tracker window", song_index);
767 if (song_index < 0 ||
774 if (it->second.card && it->second.visible_flag) {
775 *it->second.visible_flag =
true;
776 it->second.card->Focus();
782 std::string song_name =
783 song ? song->
name : absl::StrFormat(
"Song %02X", song_index);
784 std::string card_title =
785 absl::StrFormat(
"[%02X] %s - Piano Roll###SongPianoRoll%d",
786 song_index + 1, song_name, song_index);
790 window.
card = std::make_shared<gui::PanelWindow>(
792 window.
card->SetDefaultSize(900, 450);
793 window.
view = std::make_unique<editor::music::PianoRollView>();
794 window.
view->SetActiveChannel(0);
795 window.
view->SetActiveSegment(0);
802 std::string card_id = absl::StrFormat(
"music.piano_roll_%d", song_index);
806 .display_name = song_name +
" (Piano)",
811 .visibility_flag =
nullptr,
812 .priority = 250 + song_index});
822 ImGui::TextDisabled(
"Song not loaded");
830 bool is_playing_this_song =
831 state.
is_playing && (state.playing_song_index == song_index);
832 bool is_paused_this_song =
833 state.is_paused && (state.playing_song_index == song_index);
837 ImGui::BeginDisabled();
840 if (is_playing_this_song && !is_paused_this_song) {
843 {{ImGuiCol_Button, sc.button},
844 {ImGuiCol_ButtonHovered, sc.hovered}});
848 }
else if (is_paused_this_song) {
851 {{ImGuiCol_Button, wc.button},
852 {ImGuiCol_ButtonHovered, wc.hovered}});
866 if (ImGui::IsItemHovered())
867 ImGui::SetTooltip(
"Stop playback");
870 ImGui::EndDisabled();
871 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) {
872 ImGui::SetTooltip(
"Audio not ready - initialize music player first");
877 if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) &&
880 if (ImGui::IsKeyPressed(ImGuiKey_Space,
false)) {
883 if (ImGui::IsKeyPressed(ImGuiKey_Escape,
false)) {
886 if (ImGui::IsKeyPressed(ImGuiKey_Equal,
false) ||
887 ImGui::IsKeyPressed(ImGuiKey_KeypadAdd,
false)) {
890 if (ImGui::IsKeyPressed(ImGuiKey_Minus,
false) ||
891 ImGui::IsKeyPressed(ImGuiKey_KeypadSubtract,
false)) {
898 if (is_playing_this_song && !is_paused_this_song) {
900 if (ImGui::IsItemHovered())
901 ImGui::SetTooltip(
"Playing");
902 }
else if (is_paused_this_song) {
904 if (ImGui::IsItemHovered())
905 ImGui::SetTooltip(
"Paused");
909 float right_offset = ImGui::GetWindowWidth() - 200;
910 ImGui::SameLine(right_offset);
915 ImGui::SetNextItemWidth(55);
916 float speed = state.playback_speed;
922 if (ImGui::IsItemHovered())
923 ImGui::SetTooltip(
"Playback speed (0.25x - 2.0x) - use mouse wheel");
929 if (ImGui::IsItemHovered())
930 ImGui::SetTooltip(
"Open Piano Roll view");
933 const char* bank_name =
nullptr;
934 switch (song->bank) {
936 bank_name =
"Overworld";
939 bank_name =
"Dungeon";
942 bank_name =
"Credits";
945 bank_name =
"Expanded";
948 bank_name =
"Auxiliary";
951 bank_name =
"Unknown";
956 ImGui::Text(
"%s", song->name.c_str());
960 if (song->modified) {
967 ImGui::SameLine(right_offset);
969 song->segments.size());
974 if (is_playing_this_song) {
1001 ImGui::Text(
"Selected Song:");
1008 ImGui::TextDisabled(
"| %zu segments", song->segments.size());
1009 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(
"Segment: %d | Tick: %u", state.current_segment_index + 1,
1055 state.current_tick);
1057 ImGui::TextDisabled(
"| %.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(
"Open song in dedicated tracker window");
1080 if (ImGui::IsItemHovered())
1081 ImGui::SetTooltip(
"Open piano roll view for this song");
1085 ImGui::BulletText(
"Space: Play/Pause toggle");
1086 ImGui::BulletText(
"Escape: Stop playback");
1087 ImGui::BulletText(
"+/-: Increase/decrease speed");
1088 ImGui::BulletText(
"Arrow keys: Navigate in tracker/piano roll");
1089 ImGui::BulletText(
"Z,S,X,D,C,V,G,B,H,N,J,M: Piano keyboard (C to B)");
1090 ImGui::BulletText(
"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();
1161 if (state.is_playing && !state.is_paused) {
1166 if (ImGui::IsItemHovered())
1167 ImGui::SetTooltip(
"Pause (Space)");
1168 }
else if (state.is_paused) {
1173 if (ImGui::IsItemHovered())
1174 ImGui::SetTooltip(
"Resume (Space)");
1178 if (ImGui::IsItemHovered())
1179 ImGui::SetTooltip(
"Play (Space)");
1185 if (ImGui::IsItemHovered())
1186 ImGui::SetTooltip(
"Stop (Escape)");
1189 ImGui::EndDisabled();
1194 if (state.is_playing && !state.is_paused) {
1196 float t =
static_cast<float>(ImGui::GetTime() * 3.0);
1197 float alpha = 0.5f + 0.5f * std::sin(t);
1199 ImGui::TextColored(ImVec4(success_c.x, success_c.y, success_c.z, alpha),
1202 }
else if (state.is_paused) {
1206 ImGui::Text(
"%s", song->name.c_str());
1207 if (song->modified) {
1212 ImGui::TextDisabled(
"No song selected");
1216 if (state.is_playing || state.is_paused) {
1218 float seconds = state.ticks_per_second > 0
1219 ? state.current_tick / state.ticks_per_second
1221 int mins =
static_cast<int>(seconds) / 60;
1222 int secs =
static_cast<int>(seconds) % 60;
1227 float right_offset = ImGui::GetWindowWidth() - 380;
1228 ImGui::SameLine(right_offset);
1233 ImGui::SetNextItemWidth(70);
1234 float speed = state.playback_speed;
1240 if (ImGui::IsItemHovered())
1241 ImGui::SetTooltip(
"Playback speed (+/- keys)");
1246 ImGui::SetNextItemWidth(60);
1251 if (ImGui::IsItemHovered())
1252 ImGui::SetTooltip(
"Volume");
1257 ImGui::BeginDisabled();
1264 ImGui::EndDisabled();
1266 if (ImGui::IsItemHovered())
1267 ImGui::SetTooltip(
"Reload from ROM");
1271 ImGui::SetNextItemWidth(100);
1273 static int interpolation_type = 2;
1274 const char* items[] = {
"Linear",
"Hermite",
"Gaussian",
"Cosine",
"Cubic"};
1275 if (ImGui::Combo(
"##Interp", &interpolation_type, items,
1276 IM_ARRAYSIZE(items))) {
1280 if (ImGui::IsItemHovered())
1282 "Audio interpolation quality\nGaussian = authentic SNES sound");
1288 if (ImGui::BeginTable(
1290 ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchProp)) {
1292 ImGui::TableSetupColumn(
"Master", ImGuiTableColumnFlags_WidthFixed, 60.0f);
1293 for (
int i = 0; i < 8; i++) {
1294 ImGui::TableSetupColumn(absl::StrFormat(
"Ch %d", i + 1).c_str());
1296 ImGui::TableHeadersRow();
1298 ImGui::TableNextRow();
1301 ImGui::TableSetColumnIndex(0);
1306 auto& dsp = audio_emu->
snes().apu().dsp();
1308 ImGui::Text(
"Scope");
1311 const int16_t* buffer = dsp.GetSampleBuffer();
1312 uint16_t offset = dsp.GetSampleOffset();
1314 static float scope_values[128];
1316 constexpr int kBufferSize = 0x400;
1317 for (
int i = 0; i < 128; i++) {
1318 int sample_idx = ((offset - 128 + i + kBufferSize) & (kBufferSize - 1));
1319 scope_values[i] =
static_cast<float>(buffer[sample_idx * 2]) /
1323 ImGui::PlotLines(
"##Scope", scope_values, 128, 0,
nullptr, -1.0f, 1.0f,
1328 for (
int i = 0; i < 8; i++) {
1329 ImGui::TableSetColumnIndex(i + 1);
1332 auto& dsp = audio_emu->
snes().apu().dsp();
1333 const auto& ch = dsp.GetChannel(i);
1336 bool is_muted = dsp.GetChannelMute(i);
1341 std::optional<gui::StyleColorGuard> mute_guard;
1343 mute_guard.emplace(ImGuiCol_Button,
1346 if (ImGui::Button(absl::StrFormat(
"M##%d", i).c_str(),
1348 dsp.SetChannelMute(i, !is_muted);
1355 std::optional<gui::StyleColorGuard> solo_guard;
1357 solo_guard.emplace(ImGuiCol_Button,
1360 if (ImGui::Button(absl::StrFormat(
"S##%d", i).c_str(),
1364 bool any_solo =
false;
1365 for (
int j = 0; j < 8; j++)
1369 for (
int j = 0; j < 8; j++) {
1373 dsp.SetChannelMute(j,
false);
1380 float level = std::abs(ch.sampleOut) / 32768.0f;
1381 ImGui::ProgressBar(level, ImVec2(-1, 60),
"");
1384 ImGui::Text(
"Vol: %d %d", ch.volumeL, ch.volumeR);
1385 ImGui::Text(
"Pitch: %04X", ch.pitch);
1392 ImGui::TextDisabled(
"---");
1395 ImGui::TextDisabled(
"Offline");
1408 if (audio_backend) {
1409 auto status = audio_backend->
GetStatus();
1410 auto config = audio_backend->GetConfig();
1411 bool resampling = audio_backend->IsAudioStreamEnabled();
1414 ImGui::Text(
"Backend: %s @ %dHz | Queue: %u frames",
1415 audio_backend->GetBackendName().c_str(), config.sample_rate,
1416 status.queued_frames);
1421 "Resampling: 32040 -> %d Hz", config.sample_rate);
1424 " Resampling DISABLED - 1.5x speed bug!");
1427 if (status.has_underrun) {
1432 ImGui::TextDisabled(
"Open Audio Debug panel for full diagnostics");
1435 ImGui::TextDisabled(
"Play a song to see audio status");
1442 ImGui::TextDisabled(
"Music player not initialized");
1448 if (!audio_emu || !audio_emu->is_snes_initialized()) {
1449 ImGui::TextDisabled(
"Play a song to see channel activity");
1454 ImVec2 avail = ImGui::GetContentRegionAvail();
1455 if (avail.y < 50.0f) {
1456 ImGui::TextDisabled(
"(Channel view - expand for details)");
1462 if (ImGui::BeginTable(
1463 "ChannelOverview", 9,
1464 ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchProp)) {
1465 ImGui::TableSetupColumn(
"Master", ImGuiTableColumnFlags_WidthFixed, 70.0f);
1466 for (
int i = 0; i < 8; i++) {
1467 ImGui::TableSetupColumn(absl::StrFormat(
"Ch %d", i + 1).c_str());
1469 ImGui::TableHeadersRow();
1471 ImGui::TableNextRow();
1473 ImGui::TableSetColumnIndex(0);
1474 ImGui::Text(
"DSP Live");
1476 for (
int ch = 0; ch < 8; ++ch) {
1477 ImGui::TableSetColumnIndex(ch + 1);
1478 const auto& state = channel_states[ch];
1484 ImGui::TextDisabled(
"OFF");
1488 float vol_l = state.volume_l / 128.0f;
1489 float vol_r = state.volume_r / 128.0f;
1490 ImGui::ProgressBar(vol_l, ImVec2(-1, 6.0f),
"");
1491 ImGui::ProgressBar(vol_r, ImVec2(-1, 6.0f),
"");
1494 ImGui::Text(
"S: %02X", state.sample_index);
1495 ImGui::Text(
"P: %04X", state.pitch);
1498 const char* adsr_str =
"???";
1499 switch (state.adsr_state) {
1513 ImGui::Text(
"%s", adsr_str);
1536 LOG_WARN(
"MusicEditor",
"ExportSongToAsm: Invalid song index %d",
1559 auto result = exporter.
ExportSong(*song, options);
1561 LOG_ERROR(
"MusicEditor",
"ExportSongToAsm failed: %s",
1562 result.status().message().data());
1571 LOG_INFO(
"MusicEditor",
"Exported song '%s' to ASM (%zu bytes)",
1580 LOG_INFO(
"MusicEditor",
"No ASM source to import - showing import dialog");
1613 const auto message = result.status().message();
1615 LOG_ERROR(
"MusicEditor",
"ImportSongFromAsm failed: %s",
1621 for (
const auto& warning : result->warnings) {
1622 LOG_WARN(
"MusicEditor",
"ASM import warning: %s", warning.c_str());
1630 std::string original_name = song->name;
1631 *song = result->song;
1632 if (song->name.empty()) {
1633 song->name = original_name;
1635 song->modified =
true;
1637 LOG_INFO(
"MusicEditor",
"Imported ASM to song '%s' (%d lines, %d bytes)",
1638 song->name.c_str(), result->lines_parsed, result->bytes_generated);
1650 ImGui::OpenPopup(
"Export Song ASM");
1654 ImGui::OpenPopup(
"Import Song ASM");
1658 if (ImGui::BeginPopupModal(
"Export Song ASM",
nullptr,
1659 ImGuiWindowFlags_AlwaysAutoResize)) {
1660 ImGui::TextWrapped(
"Copy the generated ASM below or tweak before saving.");
1661 ImGui::InputTextMultiline(
"##AsmExportText", &
asm_buffer_, ImVec2(520, 260),
1662 ImGuiInputTextFlags_AllowTabInput);
1664 if (ImGui::Button(
"Copy to Clipboard")) {
1668 if (ImGui::Button(
"Close")) {
1669 ImGui::CloseCurrentPopup();
1675 if (ImGui::BeginPopupModal(
"Import Song ASM",
nullptr,
1676 ImGuiWindowFlags_AlwaysAutoResize)) {
1679 if (song_slot > 0) {
1680 ImGui::Text(
"Target Song: [%02X]", song_slot);
1682 ImGui::TextDisabled(
"Select a song to import into");
1684 ImGui::TextWrapped(
"Paste Oracle of Secrets-compatible ASM here.");
1686 ImGui::InputTextMultiline(
"##AsmImportText", &
asm_buffer_, ImVec2(520, 260),
1687 ImGuiInputTextFlags_AllowTabInput);
1697 ImGui::BeginDisabled();
1699 if (ImGui::Button(
"Import")) {
1703 ImGui::CloseCurrentPopup();
1707 ImGui::EndDisabled();
1711 if (ImGui::Button(
"Cancel")) {
1715 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_
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 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 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
PanelManager * panel_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).