diff --git a/TODO.md b/TODO.md index 62364e06..1e86ae13 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,6 @@ # to-do for 0.6pre1 - piano/input pad - - note input via piano - input pad - settings - RF5C68 system diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 582ea3f3..7933a14b 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -4268,13 +4268,23 @@ FurnaceGUI::FurnaceGUI(): chanOscWindowSize(20.0f), chanOscWaveCorr(true), followLog(true), +#ifdef IS_MOBILE + pianoOctaves(7), + pianoOctavesEdit(2), + pianoOptions(true), + pianoSharePosition(false), + pianoOffset(6), + pianoOffsetEdit(9), + pianoView(2), +#else pianoOctaves(7), pianoOctavesEdit(4), pianoOptions(false), - pianoSharePosition(false), + pianoSharePosition(true), pianoOffset(6), pianoOffsetEdit(6), - pianoView(2), + pianoView(0), +#endif hasACED(false) { // value keys valueKeys[SDLK_0]=0; @@ -4333,4 +4343,7 @@ FurnaceGUI::FurnaceGUI(): memset(lastCorrPos,0,sizeof(short)*DIV_MAX_CHANS); memset(acedData,0,23); + + memset(pianoKeyHit,0,sizeof(float)*180); + memset(pianoKeyPressed,0,sizeof(bool)*180); } diff --git a/src/gui/gui.h b/src/gui/gui.h index 2bcbf25e..ee80a3d6 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -194,6 +194,14 @@ enum FurnaceGUIColors { GUI_COLOR_PATTERN_EFFECT_SYS_SECONDARY, GUI_COLOR_PATTERN_EFFECT_MISC, + GUI_COLOR_PIANO_BACKGROUND, + GUI_COLOR_PIANO_KEY_BOTTOM, + GUI_COLOR_PIANO_KEY_TOP, + GUI_COLOR_PIANO_KEY_BOTTOM_HIT, + GUI_COLOR_PIANO_KEY_TOP_HIT, + GUI_COLOR_PIANO_KEY_BOTTOM_ACTIVE, + GUI_COLOR_PIANO_KEY_TOP_ACTIVE, + GUI_COLOR_LOGLEVEL_ERROR, GUI_COLOR_LOGLEVEL_WARNING, GUI_COLOR_LOGLEVEL_INFO, @@ -1216,6 +1224,7 @@ class FurnaceGUI { int pianoOctaves, pianoOctavesEdit; bool pianoOptions, pianoSharePosition; float pianoKeyHit[180]; + bool pianoKeyPressed[180]; int pianoOffset, pianoOffsetEdit; int pianoView; diff --git a/src/gui/guiConst.cpp b/src/gui/guiConst.cpp index 31aad643..62f065f9 100644 --- a/src/gui/guiConst.cpp +++ b/src/gui/guiConst.cpp @@ -799,6 +799,14 @@ const FurnaceGUIColorDef guiColors[GUI_COLOR_MAX]={ D(GUI_COLOR_PATTERN_EFFECT_SYS_SECONDARY,"",ImVec4(0.0f,1.0f,0.5f,1.0f)), D(GUI_COLOR_PATTERN_EFFECT_MISC,"",ImVec4(0.3f,0.3f,1.0f,1.0f)), + D(GUI_COLOR_PIANO_BACKGROUND,"",ImVec4(0.0f,0.0f,0.0f,1.0f)), + D(GUI_COLOR_PIANO_KEY_BOTTOM,"",ImVec4(1.0f,1.0f,1.0f,1.0f)), + D(GUI_COLOR_PIANO_KEY_TOP,"",ImVec4(0.0f,0.0f,0.0f,1.0f)), + D(GUI_COLOR_PIANO_KEY_BOTTOM_HIT,"",ImVec4(0.5f,0.7f,0.9f,1.0f)), + D(GUI_COLOR_PIANO_KEY_TOP_HIT,"",ImVec4(0.3f,0.5f,0.7f,1.0f)), + D(GUI_COLOR_PIANO_KEY_BOTTOM_ACTIVE,"",ImVec4(0.5f,0.5f,0.5f,1.0f)), + D(GUI_COLOR_PIANO_KEY_TOP_ACTIVE,"",ImVec4(0.4f,0.4f,0.4f,1.0f)), + D(GUI_COLOR_LOGLEVEL_ERROR,"",ImVec4(1.0f,0.2f,0.2f,1.0f)), D(GUI_COLOR_LOGLEVEL_WARNING,"",ImVec4(1.0f,1.0f,0.2f,1.0f)), D(GUI_COLOR_LOGLEVEL_INFO,"",ImVec4(0.4f,1.0f,0.4f,1.0f)), diff --git a/src/gui/piano.cpp b/src/gui/piano.cpp index 65c06f9d..b198933e 100644 --- a/src/gui/piano.cpp +++ b/src/gui/piano.cpp @@ -49,6 +49,9 @@ void FurnaceGUI::drawPiano() { } if (!pianoOpen) return; if (ImGui::Begin("Piano",&pianoOpen,(pianoOptions)?0:ImGuiWindowFlags_NoTitleBar)) { + bool oldPianoKeyPressed[180]; + memcpy(oldPianoKeyPressed,pianoKeyPressed,180*sizeof(bool)); + memset(pianoKeyPressed,0,180*sizeof(bool)); if (ImGui::BeginTable("PianoLayout",pianoOptions?2:1,ImGuiTableFlags_BordersInnerV)) { int& off=(e->isPlaying() || pianoSharePosition)?pianoOffset:pianoOffsetEdit; int& oct=(e->isPlaying() || pianoSharePosition)?pianoOctaves:pianoOctavesEdit; @@ -116,12 +119,31 @@ void FurnaceGUI::drawPiano() { if (ImGui::ItemAdd(rect,ImGui::GetID("pianoDisplay"))) { if (view) { int notes=oct*12; + // evaluate input + for (TouchPoint& i: activePoints) { + if (rect.Contains(ImVec2(i.x,i.y))) { + int note=(((i.x-rect.Min.x)/(rect.Max.x-rect.Min.x))*notes)+12*off; + if (note<0) continue; + if (note>=180) continue; + pianoKeyPressed[note]=true; + } + } + for (int i=0; i=180) continue; - float pkh=pianoKeyHit[note]*0.5; - ImVec4 color=isTopKey[i%12]?ImVec4(pkh,pkh,pkh,1.0f):ImVec4(1.0f-pkh,1.0f-pkh,1.0f-pkh,1.0f); + float pkh=pianoKeyHit[note]; + ImVec4 color=isTopKey[i%12]?uiColors[GUI_COLOR_PIANO_KEY_TOP]:uiColors[GUI_COLOR_PIANO_KEY_BOTTOM]; + if (pianoKeyPressed[note]) { + color=isTopKey[i%12]?uiColors[GUI_COLOR_PIANO_KEY_TOP_ACTIVE]:uiColors[GUI_COLOR_PIANO_KEY_BOTTOM_ACTIVE]; + } else { + ImVec4 colorHit=isTopKey[i%12]?uiColors[GUI_COLOR_PIANO_KEY_TOP_HIT]:uiColors[GUI_COLOR_PIANO_KEY_BOTTOM_HIT]; + color.x+=(colorHit.x-color.x)*pkh; + color.y+=(colorHit.y-color.y)*pkh; + color.z+=(colorHit.z-color.z)*pkh; + color.w+=(colorHit.w-color.w)*pkh; + } ImVec2 p0=ImLerp(rect.Min,rect.Max,ImVec2((float)i/notes,0.0f)); ImVec2 p1=ImLerp(rect.Min,rect.Max,ImVec2((float)(i+1)/notes,1.0f)); p1.x-=dpiScale; @@ -137,15 +159,61 @@ void FurnaceGUI::drawPiano() { } } else { int bottomNotes=7*oct; + // evaluate input + for (TouchPoint& i: activePoints) { + if (rect.Contains(ImVec2(i.x,i.y))) { + // top + int o=((i.x-rect.Min.x)/(rect.Max.x-rect.Min.x))*oct; + ImVec2 op0=ImLerp(rect.Min,rect.Max,ImVec2((float)o/oct,0.0f)); + ImVec2 op1=ImLerp(rect.Min,rect.Max,ImVec2((float)(o+1)/oct,1.0f)); + bool foundTopKey=false; + + for (int j=0; j<5; j++) { + int note=topKeyNotes[j]+12*(o+off); + if (note<0) continue; + if (note>=180) continue; + ImRect keyRect=ImRect( + ImLerp(op0,op1,ImVec2(topKeyStarts[j]-0.05f,0.0f)), + ImLerp(op0,op1,ImVec2(topKeyStarts[j]+0.05f,0.64f)) + ); + if (keyRect.Contains(ImVec2(i.x,i.y))) { + pianoKeyPressed[note]=true; + foundTopKey=true; + break; + } + } + if (foundTopKey) continue; + + // bottom + int n=((i.x-rect.Min.x)/(rect.Max.x-rect.Min.x))*bottomNotes; + int note=bottomKeyNotes[n%7]+12*((n/7)+off); + if (note<0) continue; + if (note>=180) continue; + pianoKeyPressed[note]=true; + } + } + for (int i=0; i=180) continue; - float pkh=pianoKeyHit[note]*0.5; - ImVec4 color=ImVec4(1.0f-pkh,1.0f-pkh,1.0f-pkh,1.0f); + + float pkh=pianoKeyHit[note]; + ImVec4 color=uiColors[GUI_COLOR_PIANO_KEY_BOTTOM]; + if (pianoKeyPressed[note]) { + color=uiColors[GUI_COLOR_PIANO_KEY_BOTTOM_ACTIVE]; + } else { + ImVec4 colorHit=uiColors[GUI_COLOR_PIANO_KEY_BOTTOM_HIT]; + color.x+=(colorHit.x-color.x)*pkh; + color.y+=(colorHit.y-color.y)*pkh; + color.z+=(colorHit.z-color.z)*pkh; + color.w+=(colorHit.w-color.w)*pkh; + } + 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)); if ((i%7)==0) { String label=fmt::sprintf("%d",(note-60)/12); @@ -165,11 +233,20 @@ void FurnaceGUI::drawPiano() { int note=topKeyNotes[j]+12*(i+off); if (note<0) continue; if (note>=180) continue; - float pkh=pianoKeyHit[note]*0.5; - ImVec4 color=ImVec4(pkh,pkh,pkh,1.0f); + float pkh=pianoKeyHit[note]; + ImVec4 color=uiColors[GUI_COLOR_PIANO_KEY_TOP]; + if (pianoKeyPressed[note]) { + color=uiColors[GUI_COLOR_PIANO_KEY_TOP_ACTIVE]; + } else { + ImVec4 colorHit=uiColors[GUI_COLOR_PIANO_KEY_TOP_HIT]; + color.x+=(colorHit.x-color.x)*pkh; + color.y+=(colorHit.y-color.y)*pkh; + color.z+=(colorHit.z-color.z)*pkh; + color.w+=(colorHit.w-color.w)*pkh; + } 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); + dl->AddRectFilled(p0,p1,ImGui::GetColorU32(uiColors[GUI_COLOR_PIANO_BACKGROUND])); p0.x+=dpiScale; p1.x-=dpiScale; p1.y-=dpiScale; @@ -189,22 +266,32 @@ void FurnaceGUI::drawPiano() { pianoOptions=!pianoOptions; } + // first check released keys + for (int i=0; i<180; i++) { + int note=i-60; + if (!pianoKeyPressed[i]) { + if (pianoKeyPressed[i]!=oldPianoKeyPressed[i]) { + e->synchronized([this,note]() { + e->autoNoteOff(-1,note); + }); + } + } + } + // then pressed ones + for (int i=0; i<180; i++) { + int note=i-60; + if (pianoKeyPressed[i]) { + if (pianoKeyPressed[i]!=oldPianoKeyPressed[i]) { + e->synchronized([this,note]() { + e->autoNoteOn(-1,curIns,note); + }); + } + } + } + ImGui::EndTable(); } - /* - for (int i=0; igetTotalChannelCount(); i++) { - DivChannelState* cs=e->getChanState(i); - if (cs->keyOn) { - const char* noteName=NULL; - if (cs->note<-60 || cs->note>120) { - noteName="???"; - } else { - noteName=noteNames[cs->note+60]; - } - ImGui::Text("%d: %s",i,noteName); - } - }*/ } if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_PIANO; ImGui::End(); -} \ No newline at end of file +} diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index 6a99d84c..983e3b33 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -1426,6 +1426,16 @@ void FurnaceGUI::drawSettings() { UI_COLOR_CONFIG(GUI_COLOR_EE_VALUE,"External command output"); ImGui::TreePop(); } + if (ImGui::TreeNode("Piano")) { + UI_COLOR_CONFIG(GUI_COLOR_PIANO_BACKGROUND,"Background"); + UI_COLOR_CONFIG(GUI_COLOR_PIANO_KEY_TOP,"Upper key"); + UI_COLOR_CONFIG(GUI_COLOR_PIANO_KEY_TOP_HIT,"Upper key (feedback)"); + UI_COLOR_CONFIG(GUI_COLOR_PIANO_KEY_TOP_ACTIVE,"Upper key (pressed)"); + UI_COLOR_CONFIG(GUI_COLOR_PIANO_KEY_BOTTOM,"Lower key"); + UI_COLOR_CONFIG(GUI_COLOR_PIANO_KEY_BOTTOM_HIT,"Lower key (feedback)"); + UI_COLOR_CONFIG(GUI_COLOR_PIANO_KEY_BOTTOM_ACTIVE,"Lower key (pressed)"); + ImGui::TreePop(); + } if (ImGui::TreeNode("Log Viewer")) { UI_COLOR_CONFIG(GUI_COLOR_LOGLEVEL_ERROR,"Log level: Error"); UI_COLOR_CONFIG(GUI_COLOR_LOGLEVEL_WARNING,"Log level: Warning");