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

View File

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