-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAXEPianoRoll.cpp
More file actions
130 lines (93 loc) · 3.11 KB
/
AXEPianoRoll.cpp
File metadata and controls
130 lines (93 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "AXEPianoRoll.hpp"
#include "Debug/EditorConsole.hpp"
#include "imgui.h"
#include "ShadowIcons.hpp"
#include "imgui_internal.h"
#include <string>
#define EC_THIS "Piano Roll"
namespace Shadow::AXE {
PianoRoll::PianoRoll(
Song* songInfo,
EditorState* editorState,
ma_engine* audioEngine
)
: songInfo(songInfo)
, editorState(editorState)
, audioEngine(audioEngine)
{
EC_NEWCAT(EC_THIS);
}
PianoRoll::~PianoRoll() { }
void PianoRoll::openPianoRoll(Clip* clip) {
if (clip == nullptr) return;
openedPianoRolls.emplace_back(clip);
}
void PianoRoll::onUpdate() {
using namespace ImGui;
// Don't waste time doing anything else if there are no piano rolls to edit
if (openedPianoRolls.empty()) return;
int it = 0;
for (auto clip : openedPianoRolls) {
auto removeMeFromOpened = [this, it]() {
openedPianoRolls.erase(openedPianoRolls.begin() + it);
};
if (clip == nullptr) removeMeFromOpened();
if (clip->clipType != TimelineClipType_PianoRoll) removeMeFromOpened();
// initialize piano roll data if it doesn't exist already
if (clip->pianoRollData == nullptr) clip->pianoRollData = std::make_shared<PianoRollData>();
std::string windowTitle = SHADOW_ICON_PIANO " Piano Roll " SHADOW_ICON_ARROW_RIGHT + clip->name + "##" + std::to_string(it);
PushStyleColor(ImGuiCol_Border, IM_COL32(255, 0, 0, 255));
PushStyleVar(ImGuiStyleVar_WindowBorderSize, 3.0f);
if (!Begin(windowTitle.c_str(), nullptr, ImGuiWindowFlags_MenuBar)) {
PopStyleVar();
PopStyleColor();
End();
it++;
continue;
}
PopStyleVar();
PopStyleColor();
PushID(it);
if (BeginMenuBar()) {
if (MenuItem("Close")) removeMeFromOpened();
EndMenuBar();
}
auto winPos = GetWindowPos();
auto winSize = GetWindowSize();
auto fg = GetForegroundDrawList();
auto mouse = GetMousePos();
if (BeginDragDropTargetCustom(ImRect(winPos, winPos + winSize), GetID("DrumMachineDropTarget"))) {
fg->AddCircleFilled(GetMousePos(), 5.0f, IM_COL32(0, 255, 0, 255));
std::string text = "Add clip to drum machine " + clip->name;
fg->AddText(ImVec2(mouse.x, mouse.y - 40.0f), IM_COL32(0, 255, 0, 255), text.c_str());
if (const ImGuiPayload* payload = AcceptDragDropPayload("AXE_CLIP_PATH_PAYLOAD")) {
const char* clipPath = static_cast<const char*>(payload->Data);
EC_PRINT("All", "dropped %s", clipPath);
clip->baseAudioSource = clipPath;
}
EndDragDropTarget();
}
if (clip->baseAudioSource.empty()) {
// Center text in the window
const char txt[] = "Drop an audio file here to use as sample for the piano roll";
auto txtSize = CalcTextSize(txt);
SetCursorPos(ImVec2((winSize.x - txtSize.x) / 2.0f, (winSize.y - txtSize.y) / 2.0f));
TextUnformatted(txt);
} else {
// Sample loaded, show piano roll UI
auto drawOctave = []() {
};
ImGuiTableFlags tableFlags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders;
// if (BeginTable("PianoRollTable", 2, tableFlags)) {
// TableSetupColumn("Keys");
// TableSetColumnIndex(0);
// // for ()
// EndTable();
// }
}
PopID();
End();
it++;
}
}
}