12#include "absl/strings/str_format.h"
32#include "imgui/imgui.h"
33#include "imgui/misc/cpp/imgui_stdlib.h"
34#include "nlohmann/json.hpp"
53 LOG_INFO(
"MusicEditor",
"Initialize() START: rom_=%p, emulator_=%p",
82 LOG_INFO(
"MusicEditor",
"Created shared audio backend: %s @ %dHz",
85 LOG_ERROR(
"MusicEditor",
"Failed to initialize audio backend!");
93 LOG_INFO(
"MusicEditor",
"Shared audio backend with main emulator");
96 "Cannot share with main emulator: backend=%p, emulator=%p",
104 LOG_INFO(
"MusicEditor",
"Set ROM on MusicPlayer");
106 LOG_WARN(
"MusicEditor",
"No ROM available for MusicPlayer!");
112 LOG_INFO(
"MusicEditor",
"Injected main emulator into MusicPlayer");
115 "No emulator available to inject into MusicPlayer!");
123 window_manager->
RegisterPanel({.card_id =
"music.song_browser",
124 .display_name =
"Song Browser",
125 .window_title =
" Song Browser",
128 .shortcut_hint =
"Ctrl+Shift+B",
130 window_manager->RegisterPanel({.card_id =
"music.tracker",
131 .display_name =
"Playback Control",
132 .window_title =
" Playback Control",
135 .shortcut_hint =
"Ctrl+Shift+M",
137 window_manager->RegisterPanel({.card_id =
"music.piano_roll",
138 .display_name =
"Piano Roll",
139 .window_title =
" Piano Roll",
142 .shortcut_hint =
"Ctrl+Shift+P",
144 window_manager->RegisterPanel({.card_id =
"music.instrument_editor",
145 .display_name =
"Instrument Editor",
146 .window_title =
" Instrument Editor",
149 .shortcut_hint =
"Ctrl+Shift+I",
151 window_manager->RegisterPanel({.card_id =
"music.sample_editor",
152 .display_name =
"Sample Editor",
153 .window_title =
" Sample Editor",
156 .shortcut_hint =
"Ctrl+Shift+S",
158 window_manager->RegisterPanel({.card_id =
"music.assembly",
159 .display_name =
"Assembly View",
160 .window_title =
" Music Assembly",
163 .shortcut_hint =
"Ctrl+Shift+A",
172 auto song_browser = std::make_unique<MusicSongBrowserPanel>(
174 window_manager->RegisterWindowContent(std::move(song_browser));
177 auto playback_control = std::make_unique<MusicPlaybackControlPanel>(
179 playback_control->SetOnOpenSong([
this](
int index) {
OpenSong(index); });
180 playback_control->SetOnOpenPianoRoll(
182 window_manager->RegisterWindowContent(std::move(playback_control));
185 auto piano_roll = std::make_unique<MusicPianoRollPanel>(
188 window_manager->RegisterWindowContent(std::move(piano_roll));
191 auto instrument_editor = std::make_unique<MusicInstrumentEditorPanel>(
193 window_manager->RegisterWindowContent(std::move(instrument_editor));
196 auto sample_editor = std::make_unique<MusicSampleEditorPanel>(
198 window_manager->RegisterWindowContent(std::move(sample_editor));
202 window_manager->RegisterWindowContent(std::move(assembly));
208 LOG_INFO(
"MusicEditor",
"set_emulator(%p): audio_backend_=%p",
216 "Shared audio backend with main emulator (deferred)");
249 if (restore.ok() && restore.value()) {
250 LOG_INFO(
"MusicEditor",
"Restored music state from web storage");
251 return absl::OkStatus();
252 }
else if (!restore.ok()) {
253 LOG_WARN(
"MusicEditor",
"Failed to restore music state: %s",
254 restore.status().ToString().c_str());
262 LOG_INFO(
"MusicEditor",
"Load(): Set ROM on MusicPlayer, IsAudioReady=%d",
267 LOG_WARN(
"MusicEditor",
"Load(): No ROM available!");
269 return absl::OkStatus();
276 if (state.is_playing && !state.is_paused) {
278 }
else if (state.is_paused) {
294 music_player_->SetPlaybackSpeed(state.playback_speed + delta);
301 music_player_->SetPlaybackSpeed(state.playback_speed - delta);
322 auto now = std::chrono::steady_clock::now();
325 elapsed > std::chrono::seconds(3))) {
328 LOG_WARN(
"MusicEditor",
"Music autosave failed: %s",
329 status.ToString().c_str());
336 return absl::OkStatus();
345 bool* browser_visible =
348 *browser_visible =
true;
353 bool* playback_visible =
354 window_manager->GetWindowVisibilityFlag(
"music.tracker");
356 *playback_visible =
true;
361 bool* piano_roll_visible =
362 window_manager->GetWindowVisibilityFlag(
"music.piano_roll");
364 *piano_roll_visible =
true;
377 std::string card_id = absl::StrFormat(
"music.song_%d", song_index);
380 bool panel_visible =
true;
386 if (!panel_visible) {
400 std::string active_category =
405 if (active_category !=
"Music" && !is_pinned) {
415 std::string song_name = song ? song->
name :
"Unknown";
416 std::string card_title = absl::StrFormat(
417 "[%02X] %s###SongTracker%d", song_index + 1, song_name, song_index);
421 song_cards_[song_index] = std::make_shared<gui::PanelWindow>(
427 std::make_unique<editor::music::TrackerView>();
437 if (song_card->Begin(&open)) {
457 int song_index = it->first;
458 auto& window = it->second;
461 std::string card_id = absl::StrFormat(
"music.piano_roll_%d", song_index);
463 if (!song || !window.card || !window.view) {
472 bool panel_visible =
true;
478 if (!panel_visible) {
482 delete window.visible_flag;
490 std::string active_category =
495 if (active_category !=
"Music" && !is_pinned) {
506 if (window.card->Begin(&open)) {
507 window.view->SetOnEditCallback(
509 window.view->SetOnNotePreview(
511 int segment_idx,
int channel_idx) {
515 music_player_->PreviewNote(*target, evt, segment_idx, channel_idx);
517 window.view->SetOnSegmentPreview(
528 window.view->SetPlaybackState(state.is_playing, state.is_paused,
530 window.view->Draw(song);
539 delete window.visible_flag;
548 return absl::OkStatus();
553 return absl::FailedPreconditionError(
"No ROM loaded");
558 if (!persist_status.ok()) {
559 return persist_status;
563 return absl::OkStatus();
573 if (!storage_or.ok()) {
578 auto parsed = nlohmann::json::parse(storage_or.value());
583 }
catch (
const std::exception& e) {
584 return absl::InvalidArgumentError(
585 absl::StrFormat(
"Failed to parse stored music state: %s", e.what()));
595 return absl::OkStatus();
603 auto now = std::chrono::system_clock::now();
604 auto time_t = std::chrono::system_clock::to_time_t(now);
605 std::stringstream ss;
606 ss << std::put_time(std::localtime(&time_t),
"%Y-%m-%d %H:%M:%S");
614 LOG_DEBUG(
"MusicEditor",
"Persisted music state (%s)", reason);
616 return absl::OkStatus();
619 return absl::OkStatus();
632 return absl::OkStatus();
638 return absl::UnimplementedError(
639 "Copy not yet implemented - clipboard support coming soon");
645 return absl::UnimplementedError(
646 "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(tr(
"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}, {ImGuiCol_ButtonHovered, sc.hovered}});
848 }
else if (is_paused_this_song) {
851 {{ImGuiCol_Button, wc.button}, {ImGuiCol_ButtonHovered, wc.hovered}});
865 if (ImGui::IsItemHovered())
866 ImGui::SetTooltip(tr(
"Stop playback"));
869 ImGui::EndDisabled();
870 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) {
871 ImGui::SetTooltip(tr(
"Audio not ready - initialize music player first"));
876 if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) &&
879 if (ImGui::IsKeyPressed(ImGuiKey_Space,
false)) {
882 if (ImGui::IsKeyPressed(ImGuiKey_Escape,
false)) {
885 if (ImGui::IsKeyPressed(ImGuiKey_Equal,
false) ||
886 ImGui::IsKeyPressed(ImGuiKey_KeypadAdd,
false)) {
889 if (ImGui::IsKeyPressed(ImGuiKey_Minus,
false) ||
890 ImGui::IsKeyPressed(ImGuiKey_KeypadSubtract,
false)) {
897 if (is_playing_this_song && !is_paused_this_song) {
899 if (ImGui::IsItemHovered())
900 ImGui::SetTooltip(tr(
"Playing"));
901 }
else if (is_paused_this_song) {
903 if (ImGui::IsItemHovered())
904 ImGui::SetTooltip(tr(
"Paused"));
908 float right_offset = ImGui::GetWindowWidth() - 200;
909 ImGui::SameLine(right_offset);
914 ImGui::SetNextItemWidth(55);
915 float speed = state.playback_speed;
921 if (ImGui::IsItemHovered())
922 ImGui::SetTooltip(tr(
"Playback speed (0.25x - 2.0x) - use mouse wheel"));
928 if (ImGui::IsItemHovered())
929 ImGui::SetTooltip(tr(
"Open Piano Roll view"));
932 const char* bank_name =
nullptr;
933 switch (song->bank) {
935 bank_name =
"Overworld";
938 bank_name =
"Dungeon";
941 bank_name =
"Credits";
944 bank_name =
"Expanded";
947 bank_name =
"Auxiliary";
950 bank_name =
"Unknown";
955 ImGui::Text(
"%s", song->name.c_str());
959 if (song->modified) {
965 ImGui::SameLine(right_offset);
967 song->segments.size());
972 if (is_playing_this_song) {
999 ImGui::Text(tr(
"Selected Song:"));
1006 ImGui::TextDisabled(tr(
"| %zu segments"), song->segments.size());
1007 if (song->modified) {
1014 if (state.is_playing || state.is_paused) {
1018 if (song && !song->segments.empty()) {
1019 uint32_t total_duration = 0;
1020 for (
const auto& seg : song->segments) {
1021 total_duration += seg.GetDuration();
1025 (total_duration > 0)
1026 ?
static_cast<float>(state.current_tick) / total_duration
1028 progress = std::clamp(progress, 0.0f, 1.0f);
1031 float current_seconds = state.ticks_per_second > 0
1032 ? state.current_tick / state.ticks_per_second
1034 float total_seconds = state.ticks_per_second > 0
1035 ? total_duration / state.ticks_per_second
1038 int cur_min =
static_cast<int>(current_seconds) / 60;
1039 int cur_sec =
static_cast<int>(current_seconds) % 60;
1040 int tot_min =
static_cast<int>(total_seconds) / 60;
1041 int tot_sec =
static_cast<int>(total_seconds) % 60;
1043 ImGui::Text(
"%d:%02d / %d:%02d", cur_min, cur_sec, tot_min, tot_sec);
1047 ImGui::ProgressBar(progress, ImVec2(-1, 0),
"");
1051 ImGui::Text(tr(
"Segment: %d | Tick: %u"), state.current_segment_index + 1,
1052 state.current_tick);
1054 ImGui::TextDisabled(tr(
"| %.1f ticks/sec | %.2fx speed"),
1055 state.ticks_per_second, state.playback_speed);
1059 if (state.is_playing) {
1070 if (ImGui::IsItemHovered())
1071 ImGui::SetTooltip(tr(
"Open song in dedicated tracker window"));
1077 if (ImGui::IsItemHovered())
1078 ImGui::SetTooltip(tr(
"Open piano roll view for this song"));
1082 ImGui::BulletText(tr(
"Space: Play/Pause toggle"));
1083 ImGui::BulletText(tr(
"Escape: Stop playback"));
1084 ImGui::BulletText(tr(
"+/-: Increase/decrease speed"));
1085 ImGui::BulletText(tr(
"Arrow keys: Navigate in tracker/piano roll"));
1086 ImGui::BulletText(tr(
"Z,S,X,D,C,V,G,B,H,N,J,M: Piano keyboard (C to B)"));
1087 ImGui::BulletText(tr(
"Ctrl+Wheel: Zoom (Piano Roll)"));
1109 int segment_idx,
int channel_idx) {
1113 music_player_->PreviewNote(*target, evt, segment_idx, channel_idx);
1128 state.current_tick);
1144 static int current_volume = 100;
1153 ImGui::BeginDisabled();
1158 if (state.is_playing && !state.is_paused) {
1163 if (ImGui::IsItemHovered())
1164 ImGui::SetTooltip(tr(
"Pause (Space)"));
1165 }
else if (state.is_paused) {
1170 if (ImGui::IsItemHovered())
1171 ImGui::SetTooltip(tr(
"Resume (Space)"));
1175 if (ImGui::IsItemHovered())
1176 ImGui::SetTooltip(tr(
"Play (Space)"));
1182 if (ImGui::IsItemHovered())
1183 ImGui::SetTooltip(tr(
"Stop (Escape)"));
1186 ImGui::EndDisabled();
1191 if (state.is_playing && !state.is_paused) {
1193 float t =
static_cast<float>(ImGui::GetTime() * 3.0);
1194 float alpha = 0.5f + 0.5f * std::sin(t);
1196 ImGui::TextColored(ImVec4(success_c.x, success_c.y, success_c.z, alpha),
1199 }
else if (state.is_paused) {
1203 ImGui::Text(
"%s", song->name.c_str());
1204 if (song->modified) {
1209 ImGui::TextDisabled(tr(
"No song selected"));
1213 if (state.is_playing || state.is_paused) {
1215 float seconds = state.ticks_per_second > 0
1216 ? state.current_tick / state.ticks_per_second
1218 int mins =
static_cast<int>(seconds) / 60;
1219 int secs =
static_cast<int>(seconds) % 60;
1224 float right_offset = ImGui::GetWindowWidth() - 380;
1225 ImGui::SameLine(right_offset);
1230 ImGui::SetNextItemWidth(70);
1231 float speed = state.playback_speed;
1237 if (ImGui::IsItemHovered())
1238 ImGui::SetTooltip(tr(
"Playback speed (+/- keys)"));
1243 ImGui::SetNextItemWidth(60);
1248 if (ImGui::IsItemHovered())
1249 ImGui::SetTooltip(tr(
"Volume"));
1254 ImGui::BeginDisabled();
1261 ImGui::EndDisabled();
1263 if (ImGui::IsItemHovered())
1264 ImGui::SetTooltip(tr(
"Reload from ROM"));
1268 ImGui::SetNextItemWidth(100);
1270 static int interpolation_type = 2;
1271 const char* items[] = {
"Linear",
"Hermite",
"Gaussian",
"Cosine",
"Cubic"};
1272 if (ImGui::Combo(
"##Interp", &interpolation_type, items,
1273 IM_ARRAYSIZE(items))) {
1277 if (ImGui::IsItemHovered())
1279 tr(
"Audio interpolation quality\nGaussian = authentic SNES sound"));
1285 if (ImGui::BeginTable(
1287 ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchProp)) {
1289 ImGui::TableSetupColumn(
"Master", ImGuiTableColumnFlags_WidthFixed, 60.0f);
1290 for (
int i = 0; i < 8; i++) {
1291 ImGui::TableSetupColumn(absl::StrFormat(
"Ch %d", i + 1).c_str());
1293 ImGui::TableHeadersRow();
1295 ImGui::TableNextRow();
1298 ImGui::TableSetColumnIndex(0);
1303 auto& dsp = audio_emu->
snes().apu().dsp();
1305 ImGui::Text(tr(
"Scope"));
1308 const int16_t* buffer = dsp.GetSampleBuffer();
1309 uint16_t offset = dsp.GetSampleOffset();
1311 static float scope_values[128];
1313 constexpr int kBufferSize = 0x400;
1314 for (
int i = 0; i < 128; i++) {
1315 int sample_idx = ((offset - 128 + i + kBufferSize) & (kBufferSize - 1));
1316 scope_values[i] =
static_cast<float>(buffer[sample_idx * 2]) /
1320 ImGui::PlotLines(
"##Scope", scope_values, 128, 0,
nullptr, -1.0f, 1.0f,
1325 for (
int i = 0; i < 8; i++) {
1326 ImGui::TableSetColumnIndex(i + 1);
1329 auto& dsp = audio_emu->
snes().apu().dsp();
1330 const auto& ch = dsp.GetChannel(i);
1333 bool is_muted = dsp.GetChannelMute(i);
1338 std::optional<gui::StyleColorGuard> mute_guard;
1340 mute_guard.emplace(ImGuiCol_Button,
1343 if (ImGui::Button(absl::StrFormat(
"M##%d", i).c_str(),
1345 dsp.SetChannelMute(i, !is_muted);
1352 std::optional<gui::StyleColorGuard> solo_guard;
1354 solo_guard.emplace(ImGuiCol_Button,
1357 if (ImGui::Button(absl::StrFormat(
"S##%d", i).c_str(),
1361 bool any_solo =
false;
1362 for (
int j = 0; j < 8; j++)
1366 for (
int j = 0; j < 8; j++) {
1370 dsp.SetChannelMute(j,
false);
1377 float level = std::abs(ch.sampleOut) / 32768.0f;
1378 ImGui::ProgressBar(level, ImVec2(-1, 60),
"");
1381 ImGui::Text(tr(
"Vol: %d %d"), ch.volumeL, ch.volumeR);
1382 ImGui::Text(tr(
"Pitch: %04X"), ch.pitch);
1389 ImGui::TextDisabled(
"---");
1392 ImGui::TextDisabled(tr(
"Offline"));
1405 if (audio_backend) {
1406 auto status = audio_backend->
GetStatus();
1407 auto config = audio_backend->GetConfig();
1408 bool resampling = audio_backend->IsAudioStreamEnabled();
1411 ImGui::Text(tr(
"Backend: %s @ %dHz | Queue: %u frames"),
1412 audio_backend->GetBackendName().c_str(), config.sample_rate,
1413 status.queued_frames);
1418 tr(
"Resampling: 32040 -> %d Hz"),
1419 config.sample_rate);
1422 " Resampling DISABLED - 1.5x speed bug!");
1425 if (status.has_underrun) {
1430 ImGui::TextDisabled(tr(
"Open Audio Debug panel for full diagnostics"));
1433 ImGui::TextDisabled(tr(
"Play a song to see audio status"));
1440 ImGui::TextDisabled(tr(
"Music player not initialized"));
1446 if (!audio_emu || !audio_emu->is_snes_initialized()) {
1447 ImGui::TextDisabled(tr(
"Play a song to see channel activity"));
1452 ImVec2 avail = ImGui::GetContentRegionAvail();
1453 if (avail.y < 50.0f) {
1454 ImGui::TextDisabled(tr(
"(Channel view - expand for details)"));
1460 if (ImGui::BeginTable(
1461 "ChannelOverview", 9,
1462 ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchProp)) {
1463 ImGui::TableSetupColumn(
"Master", ImGuiTableColumnFlags_WidthFixed, 70.0f);
1464 for (
int i = 0; i < 8; i++) {
1465 ImGui::TableSetupColumn(absl::StrFormat(
"Ch %d", i + 1).c_str());
1467 ImGui::TableHeadersRow();
1469 ImGui::TableNextRow();
1471 ImGui::TableSetColumnIndex(0);
1472 ImGui::Text(tr(
"DSP Live"));
1474 for (
int ch = 0; ch < 8; ++ch) {
1475 ImGui::TableSetColumnIndex(ch + 1);
1476 const auto& state = channel_states[ch];
1482 ImGui::TextDisabled(tr(
"OFF"));
1486 float vol_l = state.volume_l / 128.0f;
1487 float vol_r = state.volume_r / 128.0f;
1488 ImGui::ProgressBar(vol_l, ImVec2(-1, 6.0f),
"");
1489 ImGui::ProgressBar(vol_r, ImVec2(-1, 6.0f),
"");
1492 ImGui::Text(tr(
"S: %02X"), state.sample_index);
1493 ImGui::Text(tr(
"P: %04X"), state.pitch);
1496 const char* adsr_str =
"???";
1497 switch (state.adsr_state) {
1511 ImGui::Text(
"%s", adsr_str);
1534 LOG_WARN(
"MusicEditor",
"ExportSongToAsm: Invalid song index %d",
1557 auto result = exporter.
ExportSong(*song, options);
1559 LOG_ERROR(
"MusicEditor",
"ExportSongToAsm failed: %s",
1560 result.status().message().data());
1569 LOG_INFO(
"MusicEditor",
"Exported song '%s' to ASM (%zu bytes)",
1578 LOG_INFO(
"MusicEditor",
"No ASM source to import - showing import dialog");
1611 const auto message = result.status().message();
1613 LOG_ERROR(
"MusicEditor",
"ImportSongFromAsm failed: %s",
1619 for (
const auto& warning : result->warnings) {
1620 LOG_WARN(
"MusicEditor",
"ASM import warning: %s", warning.c_str());
1628 std::string original_name = song->name;
1629 *song = result->song;
1630 if (song->name.empty()) {
1631 song->name = original_name;
1633 song->modified =
true;
1635 LOG_INFO(
"MusicEditor",
"Imported ASM to song '%s' (%d lines, %d bytes)",
1636 song->name.c_str(), result->lines_parsed, result->bytes_generated);
1648 ImGui::OpenPopup(
"Export Song ASM");
1652 ImGui::OpenPopup(
"Import Song ASM");
1656 if (ImGui::BeginPopupModal(
"Export Song ASM",
nullptr,
1657 ImGuiWindowFlags_AlwaysAutoResize)) {
1659 tr(
"Copy the generated ASM below or tweak before saving."));
1660 ImGui::InputTextMultiline(
"##AsmExportText", &
asm_buffer_, ImVec2(520, 260),
1661 ImGuiInputTextFlags_AllowTabInput);
1663 if (ImGui::Button(tr(
"Copy to Clipboard"))) {
1667 if (ImGui::Button(tr(
"Close"))) {
1668 ImGui::CloseCurrentPopup();
1674 if (ImGui::BeginPopupModal(
"Import Song ASM",
nullptr,
1675 ImGuiWindowFlags_AlwaysAutoResize)) {
1678 if (song_slot > 0) {
1679 ImGui::Text(tr(
"Target Song: [%02X]"), song_slot);
1681 ImGui::TextDisabled(tr(
"Select a song to import into"));
1683 ImGui::TextWrapped(tr(
"Paste Oracle of Secrets-compatible ASM here."));
1685 ImGui::InputTextMultiline(
"##AsmImportText", &
asm_buffer_, ImVec2(520, 260),
1686 ImGuiInputTextFlags_AllowTabInput);
1696 ImGui::BeginDisabled();
1698 if (ImGui::Button(tr(
"Import"))) {
1702 ImGui::CloseCurrentPopup();
1706 ImGui::EndDisabled();
1710 if (ImGui::Button(tr(
"Cancel"))) {
1714 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,...)
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).