update music_editor gui

This commit is contained in:
scawful
2022-12-30 18:32:21 -06:00
parent 7b349a077f
commit 1787294f0f
2 changed files with 121 additions and 106 deletions

View File

@@ -8,26 +8,23 @@ namespace app {
namespace editor { namespace editor {
void MusicEditor::Update() { void MusicEditor::Update() {
ImGui::Text("Preview:");
DrawToolset();
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)9);
ImGui::BeginChild(child_id, ImVec2(0, 90), false)) {
DrawPianoStaff();
}
ImGui::EndChild();
ImGui::Separator(); ImGui::Separator();
if (ImGui::BeginTable("MusicEditorColumns", 2, toolset_table_flags_, if (ImGui::BeginTable("MusicEditorColumns", 2, music_editor_flags_,
ImVec2(0, 0))) { ImVec2(0, 0))) {
ImGui::TableSetupColumn("#SongList"); ImGui::TableSetupColumn("Assembly");
ImGui::TableSetupColumn("#EditorArea"); ImGui::TableSetupColumn("Composition");
ImGui::TableHeadersRow();
ImGui::TableNextColumn(); ImGui::TableNextRow();
DrawSongList();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
assembly_editor_.InlineUpdate(); assembly_editor_.InlineUpdate();
ImGui::TableNextColumn();
DrawToolset();
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)9);
ImGui::BeginChild(child_id, ImVec2(0, 250), false)) {
DrawPianoStaff();
}
ImGui::EndChild();
DrawPianoRoll(); DrawPianoRoll();
ImGui::EndTable(); ImGui::EndTable();
@@ -39,8 +36,8 @@ static bool keys[NUM_KEYS];
void MusicEditor::DrawPianoStaff() { void MusicEditor::DrawPianoStaff() {
const int NUM_LINES = 5; const int NUM_LINES = 5;
const int LINE_THICKNESS = 1; const int LINE_THICKNESS = 2;
const int LINE_SPACING = 20; const int LINE_SPACING = 50;
// Get the draw list for the current window // Get the draw list for the current window
ImDrawList* draw_list = ImGui::GetWindowDrawList(); ImDrawList* draw_list = ImGui::GetWindowDrawList();
@@ -48,10 +45,14 @@ void MusicEditor::DrawPianoStaff() {
// Draw the staff lines // Draw the staff lines
ImVec2 canvas_p0 = ImVec2 canvas_p0 =
ImVec2(ImGui::GetCursorScreenPos().x, ImGui::GetCursorScreenPos().y); ImVec2(ImGui::GetCursorScreenPos().x, ImGui::GetCursorScreenPos().y);
ImVec2 canvas_p1 = ImVec2(canvas_p0.x + ImGui::GetContentRegionAvail().x,
canvas_p0.y + ImGui::GetContentRegionAvail().y);
draw_list->AddRectFilled(canvas_p0, canvas_p1, IM_COL32(32, 32, 32, 255));
for (int i = 0; i < NUM_LINES; i++) { for (int i = 0; i < NUM_LINES; i++) {
auto line_start = ImVec2(canvas_p0.x, canvas_p0.y + i * LINE_SPACING); auto line_start = ImVec2(canvas_p0.x, canvas_p0.y + i * LINE_SPACING);
auto line_end = ImVec2(ImGui::GetContentRegionAvail().x, canvas_p0.y + i * LINE_SPACING); auto line_end = ImVec2(canvas_p1.x + ImGui::GetContentRegionAvail().x,
draw_list->AddLine(line_start, line_end, IM_COL32(255, 255, 255, 255), canvas_p0.y + i * LINE_SPACING);
draw_list->AddLine(line_start, line_end, IM_COL32(200, 200, 200, 255),
LINE_THICKNESS); LINE_THICKNESS);
} }
@@ -60,8 +61,8 @@ void MusicEditor::DrawPianoStaff() {
for (int i = -NUM_LEDGER_LINES; i <= NUM_LINES + NUM_LEDGER_LINES; i++) { for (int i = -NUM_LEDGER_LINES; i <= NUM_LINES + NUM_LEDGER_LINES; i++) {
if (i % 2 == 0) continue; // skip every other line if (i % 2 == 0) continue; // skip every other line
auto line_start = ImVec2(canvas_p0.x, canvas_p0.y + i * LINE_SPACING / 2); auto line_start = ImVec2(canvas_p0.x, canvas_p0.y + i * LINE_SPACING / 2);
auto line_end = auto line_end = ImVec2(canvas_p1.x + ImGui::GetContentRegionAvail().x,
ImVec2(ImGui::GetContentRegionAvail().x, canvas_p0.y + i * LINE_SPACING / 2); canvas_p0.y + i * LINE_SPACING / 2);
draw_list->AddLine(line_start, line_end, IM_COL32(150, 150, 150, 255), draw_list->AddLine(line_start, line_end, IM_COL32(150, 150, 150, 255),
LINE_THICKNESS); LINE_THICKNESS);
} }
@@ -72,56 +73,49 @@ void MusicEditor::DrawPianoRoll() {
float key_width = ImGui::GetContentRegionAvail().x / NUM_KEYS; float key_width = ImGui::GetContentRegionAvail().x / NUM_KEYS;
float white_key_height = ImGui::GetContentRegionAvail().y * 0.8f; float white_key_height = ImGui::GetContentRegionAvail().y * 0.8f;
float black_key_height = ImGui::GetContentRegionAvail().y * 0.5f; float black_key_height = ImGui::GetContentRegionAvail().y * 0.5f;
ImGui::Text("Click on the keys to toggle notes"); ImGui::Text("Piano Roll");
ImGui::Separator(); ImGui::Separator();
// Get the draw list for the current window ImDrawList* draw_list = ImGui::GetWindowDrawList();
// ImDrawList* draw_list = ImGui::GetWindowDrawList();
// draw_list->AddRectFilled(ImVec2(0, 0), ImGui::GetContentRegionAvail(), // Draw the staff lines
// IM_COL32(35, 35, 35, 255)); ImVec2 canvas_p0 =
// // Iterate through the keys and draw them ImVec2(ImGui::GetCursorScreenPos().x, ImGui::GetCursorScreenPos().y);
// for (int i = 0; i < NUM_KEYS; i++) { ImVec2 canvas_p1 = ImVec2(canvas_p0.x + ImGui::GetContentRegionAvail().x,
// // Calculate the position and size of the key canvas_p0.y + ImGui::GetContentRegionAvail().y);
// ImVec2 key_pos = ImVec2(i * key_width, 0.0f); draw_list->AddRectFilled(canvas_p0, canvas_p1, IM_COL32(200, 200, 200, 255));
// ImVec2 key_size;
// if (i % 12 == 1 || i % 12 == 3 || i % 12 == 6 || i % 12 == 8 ||
// i % 12 == 10) {
// // This is a black key
// key_size = ImVec2(key_width * 0.6f, black_key_height);
// ImVec2 dest;
// dest.x = key_pos.x + key_size.x;
// dest.y = key_pos.y + key_size.y;
// draw_list->AddRectFilled(key_pos, dest, IM_COL32(0, 0, 0, 255));
// } else {
// // This is a white key
// ImVec2 dest;
// dest.x = key_pos.x + key_size.x;
// dest.y = key_pos.y + key_size.y;
// key_size = ImVec2(key_width, white_key_height);
// draw_list->AddRectFilled(key_pos, dest, IM_COL32(255, 255, 255,
// 255));
// }
// }
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4.f, 0.f));
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0.f);
for (int i = 0; i < NUM_KEYS; i++) { for (int i = 0; i < NUM_KEYS; i++) {
// Calculate the position and size of the key // Calculate the position and size of the key
ImVec2 key_pos = ImVec2(i * key_width, 0.0f); ImVec2 key_pos = ImVec2(i * key_width, 0.0f);
ImVec2 key_size; ImVec2 key_size;
ImVec4 key_color;
ImVec4 text_color;
if (i % 12 == 1 || i % 12 == 3 || i % 12 == 6 || i % 12 == 8 || if (i % 12 == 1 || i % 12 == 3 || i % 12 == 6 || i % 12 == 8 ||
i % 12 == 10) { i % 12 == 10) {
// This is a black key // This is a black key
key_size = ImVec2(key_width * 0.6f, black_key_height); key_size = ImVec2(key_width * 0.6f, black_key_height);
key_color = ImVec4(0, 0, 0, 255);
text_color = ImVec4(255, 255, 255, 255);
} else { } else {
// This is a white key // This is a white key
key_size = ImVec2(key_width, white_key_height); key_size = ImVec2(key_width, white_key_height);
key_color = ImVec4(255, 255, 255, 255);
text_color = ImVec4(0, 0, 0, 255);
} }
ImGui::PushID(i); ImGui::PushID(i);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.f, 0.f));
ImGui::PushStyleColor(ImGuiCol_Button, key_color);
ImGui::PushStyleColor(ImGuiCol_Text, text_color);
if (ImGui::Button(kSongNotes[i].data(), key_size)) { if (ImGui::Button(kSongNotes[i].data(), key_size)) {
keys[i] ^= 1; keys[i] ^= 1;
} }
ImGui::PopStyleColor();
ImGui::PopStyleColor();
ImGui::PopStyleVar();
ImVec2 button_pos = ImGui::GetItemRectMin(); ImVec2 button_pos = ImGui::GetItemRectMin();
ImVec2 button_size = ImGui::GetItemRectSize(); ImVec2 button_size = ImGui::GetItemRectSize();
if (keys[i]) { if (keys[i]) {
@@ -129,44 +123,63 @@ void MusicEditor::DrawPianoRoll() {
dest.x = button_pos.x + button_size.x; dest.x = button_pos.x + button_size.x;
dest.y = button_pos.y + button_size.y; dest.y = button_pos.y + button_size.y;
ImGui::GetWindowDrawList()->AddRectFilled(button_pos, dest, ImGui::GetWindowDrawList()->AddRectFilled(button_pos, dest,
IM_COL32(200, 200, 255, 255)); IM_COL32(200, 200, 255, 200));
} }
ImGui::PopID(); ImGui::PopID();
ImGui::SameLine(); ImGui::SameLine();
} }
ImGui::PopStyleVar();
ImGui::PopStyleVar();
} }
void MusicEditor::DrawSongList() const { void MusicEditor::DrawSongToolset() {
static int current_song = 0; if (ImGui::BeginTable("DWToolset", 8, toolset_table_flags_, ImVec2(0, 0))) {
ImGui::BeginChild("Song List", ImVec2(250, 0)); ImGui::TableSetupColumn("#1");
ImGui::Text("Select a song to edit:"); ImGui::TableSetupColumn("#play");
ImGui::ListBox( ImGui::TableSetupColumn("#rewind");
"##songs", &current_song, ImGui::TableSetupColumn("#fastforward");
[](void* data, int idx, const char** out_text) { ImGui::TableSetupColumn("volumeController");
*out_text = kGameSongs[idx].data();
return true; ImGui::EndTable();
}, }
nullptr, 30, 30);
ImGui::EndChild();
} }
void MusicEditor::DrawToolset() { void MusicEditor::DrawToolset() {
static bool is_playing = false; static bool is_playing = false;
if (ImGui::BeginTable("DWToolset", 3, toolset_table_flags_, ImVec2(0, 0))) { static int selected_option = 0;
if (ImGui::BeginTable("SongToolset", 5, toolset_table_flags_, ImVec2(0, 0))) {
ImGui::TableSetupColumn("#SelectSong");
ImGui::TableSetupColumn("#play"); ImGui::TableSetupColumn("#play");
ImGui::TableSetupColumn("#rewind"); ImGui::TableSetupColumn("#rewind");
ImGui::TableSetupColumn("#fastforward"); ImGui::TableSetupColumn("#fastforward");
ImGui::TableSetupColumn("#volume");
ImGui::TableNextColumn();
ImGui::Combo("Controls: ", &selected_option, kGameSongs, 30);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (ImGui::Button(is_playing ? ICON_MD_STOP : ICON_MD_PLAY_ARROW)) { if (ImGui::Button(is_playing ? ICON_MD_STOP : ICON_MD_PLAY_ARROW)) {
is_playing = !is_playing; is_playing = !is_playing;
} }
ImGui::TableNextColumn(); BUTTON_COLUMN(ICON_MD_FAST_REWIND)
ImGui::Button(ICON_MD_FAST_REWIND); BUTTON_COLUMN(ICON_MD_FAST_FORWARD)
BUTTON_COLUMN(ICON_MD_VOLUME_UP)
ImGui::EndTable();
}
ImGui::TableNextColumn(); if (ImGui::BeginTable("ChannelToolset", 9, toolset_table_flags_,
ImGui::Button(ICON_MD_FAST_FORWARD); ImVec2(0, 0))) {
ImGui::TableSetupColumn("#Channels");
for (int i = 0; i < 3; i++) {
ImGui::TableSetupColumn(absl::StrFormat("#%d", i).data());
}
ImGui::Text("Channels: ");
for (int i = 0; i < 8; i++) {
ImGui::TableNextColumn();
ImGui::Button(absl::StrFormat("%d", i).data());
}
ImGui::EndTable(); ImGui::EndTable();
} }

View File

@@ -12,41 +12,41 @@ namespace yaze {
namespace app { namespace app {
namespace editor { namespace editor {
static constexpr absl::string_view kGameSongs[] = {"Title", static const char* kGameSongs[] = {"Title",
"Light World", "Light World",
"Beginning", "Beginning",
"Rabbit", "Rabbit",
"Forest", "Forest",
"Intro", "Intro",
"Town", "Town",
"Warp", "Warp",
"Dark world", "Dark world",
"Master sword", "Master sword",
"File select", "File select",
"Soldier", "Soldier",
"Mountain", "Mountain",
"Shop", "Shop",
"Fanfare", "Fanfare",
"Castle", "Castle",
"Palace (Pendant)", "Palace (Pendant)",
"Cave (Same as Secret Way)", "Cave (Same as Secret Way)",
"Clear (Dungeon end)", "Clear (Dungeon end)",
"Church", "Church",
"Boss", "Boss",
"Dungeon (Crystal)", "Dungeon (Crystal)",
"Psychic", "Psychic",
"Secret Way (Same as Cave)", "Secret Way (Same as Cave)",
"Rescue", "Rescue",
"Crystal", "Crystal",
"Fountain", "Fountain",
"Pyramid", "Pyramid",
"Kill Agahnim", "Kill Agahnim",
"Ganon Room", "Ganon Room",
"Last Boss"}; "Last Boss"};
static constexpr absl::string_view kSongNotes[] = { static constexpr absl::string_view kSongNotes[] = {
"C", "D", "E", "F", "G", "A", "B", "C", "D", "E", "F", "G", "A", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", "C",
"B", "C", "D", "E", "F", "G", "A", "B", "C", "D", "E", "F"}; "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", "C"};
class MusicEditor { class MusicEditor {
public: public:
void Update(); void Update();
@@ -54,12 +54,14 @@ class MusicEditor {
private: private:
void DrawPianoStaff(); void DrawPianoStaff();
void DrawPianoRoll(); void DrawPianoRoll();
void DrawSongList() const; void DrawSongToolset();
void DrawToolset(); void DrawToolset();
AssemblyEditor assembly_editor_; AssemblyEditor assembly_editor_;
ImGuiTableFlags toolset_table_flags_ = ImGuiTableFlags toolset_table_flags_ = ImGuiTableFlags_SizingFixedFit;
ImGuiTableFlags_SizingFixedFit; ImGuiTableFlags music_editor_flags_ = ImGuiTableFlags_SizingFixedFit |
ImGuiTableFlags_Resizable |
ImGuiTableFlags_Reorderable;
}; };
} // namespace editor } // namespace editor