Skip to content

Commit 173f59d

Browse files
committed
GUI: refactor the poly button
1 parent a8a5734 commit 173f59d

File tree

3 files changed

+43
-66
lines changed

3 files changed

+43
-66
lines changed

src/gui/editControls.cpp

Lines changed: 26 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,20 @@ const bool mobileButtonPersist[32]={
169169
false,
170170
};
171171

172+
const char* noteInputModes[4]={
173+
_N("Mono##PolyInput"),
174+
_N("Poly##PolyInput"),
175+
_N("Chord##PolyInput"),
176+
// unused
177+
_N("Of fuckin' course!##PolyInput")
178+
};
179+
180+
#define CHANGE_NOTE_INPUT_MODE \
181+
noteInputMode++; \
182+
if (noteInputMode>GUI_NOTE_INPUT_CHORD) noteInputMode=GUI_NOTE_INPUT_MONO; \
183+
if (noteInputMode==GUI_NOTE_INPUT_MONO) memset(multiIns,-1,7*sizeof(int)); \
184+
e->setAutoNotePoly(noteInputMode!=GUI_NOTE_INPUT_MONO);
185+
172186
void FurnaceGUI::drawMobileControls() {
173187
float timeScale=60.0*ImGui::GetIO().DeltaTime;
174188
if (dragMobileMenu) {
@@ -758,20 +772,9 @@ void FurnaceGUI::drawEditControls() {
758772
}
759773

760774
ImGui::SameLine();
761-
pushToggleColors(noteInputPoly);
762-
if (ImGui::Button(noteInputPoly?(noteInputChord?(_("Chord##PolyInput")):(_("Poly##PolyInput"))):(_("Mono##PolyInput")))) {
763-
if (noteInputPoly) {
764-
if (noteInputChord) {
765-
noteInputPoly=false;
766-
noteInputChord=false;
767-
} else {
768-
noteInputChord=true;
769-
}
770-
} else {
771-
noteInputPoly=true;
772-
noteInputChord=false;
773-
}
774-
e->setAutoNotePoly(noteInputPoly);
775+
pushToggleColors(noteInputMode!=GUI_NOTE_INPUT_MONO);
776+
if (ImGui::Button(_(noteInputModes[noteInputMode&3]))) {
777+
CHANGE_NOTE_INPUT_MODE;
775778
}
776779
if (ImGui::IsItemHovered()) {
777780
ImGui::SetTooltip(_("Polyphony"));
@@ -898,20 +901,9 @@ void FurnaceGUI::drawEditControls() {
898901
unimportant(ImGui::Checkbox(_("Pattern"),&followPattern));
899902

900903
ImGui::SameLine();
901-
pushToggleColors(noteInputPoly);
902-
if (ImGui::Button(noteInputPoly?(noteInputChord?(_("Chord##PolyInput")):(_("Poly##PolyInput"))):(_("Mono##PolyInput")))) {
903-
if (noteInputPoly) {
904-
if (noteInputChord) {
905-
noteInputPoly=false;
906-
noteInputChord=false;
907-
} else {
908-
noteInputChord=true;
909-
}
910-
} else {
911-
noteInputPoly=true;
912-
noteInputChord=false;
913-
}
914-
e->setAutoNotePoly(noteInputPoly);
904+
pushToggleColors(noteInputMode!=GUI_NOTE_INPUT_MONO);
905+
if (ImGui::Button(_(noteInputModes[noteInputMode&3]))) {
906+
CHANGE_NOTE_INPUT_MODE;
915907
}
916908
if (ImGui::IsItemHovered()) {
917909
ImGui::SetTooltip(_("Polyphony"));
@@ -1046,20 +1038,9 @@ void FurnaceGUI::drawEditControls() {
10461038
}
10471039
popToggleColors();
10481040

1049-
pushToggleColors(noteInputPoly);
1050-
if (ImGui::Button(noteInputPoly?(noteInputChord?(_("Chord##PolyInput")):(_("Poly##PolyInput"))):(_("Mono##PolyInput")))) {
1051-
if (noteInputPoly) {
1052-
if (noteInputChord) {
1053-
noteInputPoly=false;
1054-
noteInputChord=false;
1055-
} else {
1056-
noteInputChord=true;
1057-
}
1058-
} else {
1059-
noteInputPoly=true;
1060-
noteInputChord=false;
1061-
}
1062-
e->setAutoNotePoly(noteInputPoly);
1041+
pushToggleColors(noteInputMode!=GUI_NOTE_INPUT_MONO);
1042+
if (ImGui::Button(_(noteInputModes[noteInputMode&3]))) {
1043+
CHANGE_NOTE_INPUT_MODE;
10631044
}
10641045
if (ImGui::IsItemHovered()) {
10651046
ImGui::SetTooltip(_("Polyphony"));
@@ -1156,20 +1137,9 @@ void FurnaceGUI::drawEditControls() {
11561137
popToggleColors();
11571138

11581139
ImGui::SameLine();
1159-
pushToggleColors(noteInputPoly);
1160-
if (ImGui::Button(noteInputPoly?(noteInputChord?(_("Chord##PolyInput")):(_("Poly##PolyInput"))):(_("Mono##PolyInput")))) {
1161-
if (noteInputPoly) {
1162-
if (noteInputChord) {
1163-
noteInputPoly=false;
1164-
noteInputChord=false;
1165-
} else {
1166-
noteInputChord=true;
1167-
}
1168-
} else {
1169-
noteInputPoly=true;
1170-
noteInputChord=false;
1171-
}
1172-
e->setAutoNotePoly(noteInputPoly);
1140+
pushToggleColors(noteInputMode!=GUI_NOTE_INPUT_MONO);
1141+
if (ImGui::Button(_(noteInputModes[noteInputMode&3]))) {
1142+
CHANGE_NOTE_INPUT_MODE;
11731143
}
11741144
if (ImGui::IsItemHovered()) {
11751145
ImGui::SetTooltip(_("Polyphony"));

src/gui/gui.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ void FurnaceGUI::noteInput(int num, int key, int vol, int chanOff) {
13991399
int tick=0;
14001400
int speed=0;
14011401

1402-
if (chanOff>0 && noteInputChord) {
1402+
if (chanOff>0 && noteInputMode==GUI_NOTE_INPUT_CHORD) {
14031403
ch=e->getViableChannel(ch,chanOff,curIns);
14041404
if ((!e->isPlaying() || !followPattern)) {
14051405
y-=editStep;
@@ -1466,7 +1466,7 @@ void FurnaceGUI::noteInput(int num, int key, int vol, int chanOff) {
14661466
pat->newData[y][DIV_PAT_VOL]=-1;
14671467
}
14681468
}
1469-
if ((!e->isPlaying() || !followPattern) && (chanOff<1 || !noteInputChord)) {
1469+
if ((!e->isPlaying() || !followPattern) && (chanOff<1 || noteInputMode!=GUI_NOTE_INPUT_CHORD)) {
14701470
editAdvance();
14711471
}
14721472
makeUndo(GUI_UNDO_PATTERN_EDIT,UndoRegion(ord,ch,y,ord,ch,y));
@@ -7657,7 +7657,7 @@ bool FurnaceGUI::init() {
76577657

76587658
initSystemPresets();
76597659

7660-
e->setAutoNotePoly(noteInputPoly);
7660+
e->setAutoNotePoly(noteInputMode!=GUI_NOTE_INPUT_MONO);
76617661

76627662
SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER,"1");
76637663
#if SDL_VERSION_ATLEAST(2,0,17)
@@ -8326,8 +8326,10 @@ void FurnaceGUI::syncState() {
83268326
orderLock=e->getConfBool("orderLock",false);
83278327
followOrders=e->getConfBool("followOrders",true);
83288328
followPattern=e->getConfBool("followPattern",true);
8329-
noteInputPoly=e->getConfBool("noteInputPoly",true);
8330-
noteInputChord=e->getConfBool("noteInputChord",false);
8329+
noteInputMode=e->getConfInt("noteInputMode",GUI_NOTE_INPUT_POLY);
8330+
if (noteInputMode!=GUI_NOTE_INPUT_MONO && noteInputMode!=GUI_NOTE_INPUT_POLY && noteInputMode!=GUI_NOTE_INPUT_CHORD) {
8331+
noteInputMode=GUI_NOTE_INPUT_POLY;
8332+
}
83318333
filePlayerSync=e->getConfBool("filePlayerSync",true);
83328334
audioExportOptions.loops=e->getConfInt("exportLoops",0);
83338335
if (audioExportOptions.loops<0) audioExportOptions.loops=0;
@@ -8489,8 +8491,7 @@ void FurnaceGUI::commitState(DivConfig& conf) {
84898491
conf.set("followOrders",followOrders);
84908492
conf.set("followPattern",followPattern);
84918493
conf.set("orderEditMode",orderEditMode);
8492-
conf.set("noteInputPoly",noteInputPoly);
8493-
conf.set("noteInputChord",noteInputChord);
8494+
conf.set("noteInputMode",(int)noteInputMode);
84948495
conf.set("filePlayerSync",filePlayerSync);
84958496
if (settings.persistFadeOut) {
84968497
conf.set("exportLoops",audioExportOptions.loops);
@@ -8665,8 +8666,7 @@ FurnaceGUI::FurnaceGUI():
86658666
preserveChanPos(false),
86668667
sysDupCloneChannels(true),
86678668
sysDupEnd(false),
8668-
noteInputPoly(true),
8669-
noteInputChord(false),
8669+
noteInputMode(GUI_NOTE_INPUT_POLY),
86708670
notifyWaveChange(false),
86718671
notifySampleChange(false),
86728672
recalcTimestamps(true),

src/gui/gui.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,12 @@ struct CSDisAsmIns {
16731673
}
16741674
};
16751675

1676+
enum NoteInputModes: unsigned char {
1677+
GUI_NOTE_INPUT_MONO=0,
1678+
GUI_NOTE_INPUT_POLY,
1679+
GUI_NOTE_INPUT_CHORD
1680+
};
1681+
16761682
struct FurnaceCV;
16771683

16781684
class FurnaceGUI {
@@ -1723,7 +1729,8 @@ class FurnaceGUI {
17231729
bool vgmExportDirectStream, displayInsTypeList, displayWaveSizeList;
17241730
bool portrait, injectBackUp, mobileMenuOpen, warnColorPushed;
17251731
bool wantCaptureKeyboard, oldWantCaptureKeyboard, displayMacroMenu;
1726-
bool displayNew, displayExport, displayPalette, fullScreen, preserveChanPos, sysDupCloneChannels, sysDupEnd, noteInputPoly, noteInputChord;
1732+
bool displayNew, displayExport, displayPalette, fullScreen, preserveChanPos, sysDupCloneChannels, sysDupEnd;
1733+
unsigned char noteInputMode;
17271734
bool notifyWaveChange, notifySampleChange;
17281735
bool recalcTimestamps;
17291736
bool wantScrollListIns, wantScrollListWave, wantScrollListSample;

0 commit comments

Comments
 (0)