mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-15 17:25:06 +00:00
GUI: partially add a piano
This commit is contained in:
parent
2e2fafd878
commit
e86174921b
4 changed files with 106 additions and 3 deletions
|
@ -3650,7 +3650,10 @@ FurnaceGUI::FurnaceGUI():
|
|||
oscTotal(0),
|
||||
oscZoom(0.5f),
|
||||
oscZoomSlider(false),
|
||||
followLog(true) {
|
||||
followLog(true),
|
||||
pianoOctaves(7),
|
||||
pianoOptions(false),
|
||||
pianoOffset(6) {
|
||||
// value keys
|
||||
valueKeys[SDLK_0]=0;
|
||||
valueKeys[SDLK_1]=1;
|
||||
|
|
|
@ -1048,6 +1048,12 @@ class FurnaceGUI {
|
|||
// log window
|
||||
bool followLog;
|
||||
|
||||
// piano
|
||||
int pianoOctaves;
|
||||
bool pianoOptions;
|
||||
float pianoKeyHit[180];
|
||||
int pianoOffset;
|
||||
|
||||
void drawSSGEnv(unsigned char type, const ImVec2& size);
|
||||
void drawWaveform(unsigned char type, bool opz, const ImVec2& size);
|
||||
void drawAlgorithm(unsigned char alg, FurnaceGUIFMAlgs algType, const ImVec2& size);
|
||||
|
|
|
@ -494,6 +494,12 @@ void FurnaceGUI::drawPattern() {
|
|||
ImVec4 chanHeadHover=chanHead;
|
||||
if (e->keyHit[i]) {
|
||||
keyHit[i]=0.2;
|
||||
if (!muted) {
|
||||
int note=e->getChanState(i)->note+60;
|
||||
if (note>=0 && note<180) {
|
||||
pianoKeyHit[note]=1.0;
|
||||
}
|
||||
}
|
||||
e->keyHit[i]=false;
|
||||
}
|
||||
if (settings.guiColorsBase) {
|
||||
|
|
|
@ -19,6 +19,20 @@
|
|||
|
||||
#include "gui.h"
|
||||
#include "guiConst.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
|
||||
const float topKeyStarts[5]={
|
||||
0.9f/7.0f, 2.1f/7.0f, 3.9f/7.0f, 5.0f/7.0f, 6.1f/7.0f
|
||||
};
|
||||
|
||||
const int topKeyNotes[5]={
|
||||
1, 3, 6, 8, 10
|
||||
};
|
||||
|
||||
const int bottomKeyNotes[7]={
|
||||
0, 2, 4, 5, 7, 9, 11
|
||||
};
|
||||
|
||||
// TODO: actually implement a piano!
|
||||
void FurnaceGUI::drawPiano() {
|
||||
|
@ -28,7 +42,81 @@ void FurnaceGUI::drawPiano() {
|
|||
nextWindow=GUI_WINDOW_NOTHING;
|
||||
}
|
||||
if (!pianoOpen) return;
|
||||
if (ImGui::Begin("Piano",&pianoOpen)) {
|
||||
if (ImGui::Begin("Piano",&pianoOpen,(pianoOptions)?0:ImGuiWindowFlags_NoTitleBar)) {
|
||||
if (ImGui::BeginTable("PianoLayout",pianoOptions?2:1,ImGuiTableFlags_BordersInnerV)) {
|
||||
if (pianoOptions) {
|
||||
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed);
|
||||
}
|
||||
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
ImGui::TableNextRow();
|
||||
if (pianoOptions) {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button("Options");
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGuiWindow* window=ImGui::GetCurrentWindow();
|
||||
ImVec2 size=ImGui::GetContentRegionAvail();
|
||||
ImDrawList* dl=ImGui::GetWindowDrawList();
|
||||
|
||||
ImVec2 minArea=window->DC.CursorPos;
|
||||
ImVec2 maxArea=ImVec2(
|
||||
minArea.x+size.x,
|
||||
minArea.y+size.y
|
||||
);
|
||||
ImRect rect=ImRect(minArea,maxArea);
|
||||
|
||||
// render piano
|
||||
//ImGui::ItemSize(size,ImGui::GetStyle().FramePadding.y);
|
||||
if (ImGui::ItemAdd(rect,ImGui::GetID("pianoDisplay"))) {
|
||||
int bottomNotes=7*pianoOctaves;
|
||||
for (int i=0; i<bottomNotes; i++) {
|
||||
int note=bottomKeyNotes[i%7]+12*((i/7)+pianoOffset);
|
||||
if (note<0) continue;
|
||||
if (note>=180) continue;
|
||||
float pkh=pianoKeyHit[note]*0.5;
|
||||
ImVec4 color=ImVec4(1.0f-pkh,1.0f-pkh,1.0f-pkh,1.0f);
|
||||
ImVec2 p0=ImLerp(rect.Min,rect.Max,ImVec2((float)i/bottomNotes,0.0f));
|
||||
ImVec2 p1=ImLerp(rect.Min,rect.Max,ImVec2((float)(i+1)/bottomNotes,1.0f));
|
||||
p1.x-=dpiScale;
|
||||
dl->AddRectFilled(p0,p1,ImGui::ColorConvertFloat4ToU32(color));
|
||||
}
|
||||
|
||||
for (int i=0; i<pianoOctaves; i++) {
|
||||
ImVec2 op0=ImLerp(rect.Min,rect.Max,ImVec2((float)i/pianoOctaves,0.0f));
|
||||
ImVec2 op1=ImLerp(rect.Min,rect.Max,ImVec2((float)(i+1)/pianoOctaves,1.0f));
|
||||
|
||||
for (int j=0; j<5; j++) {
|
||||
int note=topKeyNotes[j]+12*(i+pianoOffset);
|
||||
if (note<0) continue;
|
||||
if (note>=180) continue;
|
||||
float pkh=pianoKeyHit[note]*0.5;
|
||||
ImVec4 color=ImVec4(pkh,pkh,pkh,1.0f);
|
||||
ImVec2 p0=ImLerp(op0,op1,ImVec2(topKeyStarts[j]-0.05f,0.0f));
|
||||
ImVec2 p1=ImLerp(op0,op1,ImVec2(topKeyStarts[j]+0.05f,0.64f));
|
||||
dl->AddRectFilled(p0,p1,0xff000000);
|
||||
p0.x+=dpiScale;
|
||||
p1.x-=dpiScale;
|
||||
p1.y-=dpiScale;
|
||||
dl->AddRectFilled(p0,p1,ImGui::ColorConvertFloat4ToU32(color));
|
||||
}
|
||||
}
|
||||
|
||||
const float reduction=ImGui::GetIO().DeltaTime*60.0f*0.12;
|
||||
for (int i=0; i<180; i++) {
|
||||
pianoKeyHit[i]-=reduction;
|
||||
if (pianoKeyHit[i]<0) pianoKeyHit[i]=0;
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
|
||||
pianoOptions=!pianoOptions;
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
/*
|
||||
for (int i=0; i<e->getTotalChannelCount(); i++) {
|
||||
DivChannelState* cs=e->getChanState(i);
|
||||
if (cs->keyOn) {
|
||||
|
@ -40,7 +128,7 @@ void FurnaceGUI::drawPiano() {
|
|||
}
|
||||
ImGui::Text("%d: %s",i,noteName);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_PIANO;
|
||||
ImGui::End();
|
||||
|
|
Loading…
Reference in a new issue