mirror of
https://github.com/tildearrow/furnace.git
synced 2024-12-31 20:11:29 +00:00
parent
6db9d312ec
commit
93c4ab0cc8
2 changed files with 83 additions and 45 deletions
111
src/gui/gui.cpp
111
src/gui/gui.cpp
|
@ -287,12 +287,11 @@ void FurnaceGUI::drawEditControls() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::Button(ICON_FA_PLAY "##Play")) {
|
if (ImGui::Button(ICON_FA_PLAY "##Play")) {
|
||||||
e->play();
|
play();
|
||||||
curNibble=false;
|
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button(ICON_FA_STOP "##Stop")) {
|
if (ImGui::Button(ICON_FA_STOP "##Stop")) {
|
||||||
e->stop();
|
stop();
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Checkbox("Edit",&edit);
|
ImGui::Checkbox("Edit",&edit);
|
||||||
|
@ -342,13 +341,13 @@ void FurnaceGUI::drawSongInfo() {
|
||||||
ImGui::SetNextItemWidth(120.0f*dpiScale);
|
ImGui::SetNextItemWidth(120.0f*dpiScale);
|
||||||
if (ImGui::InputScalar("##Speed1",ImGuiDataType_U8,&e->song.speed1,&_ONE,&_THREE)) {
|
if (ImGui::InputScalar("##Speed1",ImGuiDataType_U8,&e->song.speed1,&_ONE,&_THREE)) {
|
||||||
if (e->song.speed1<1) e->song.speed1=1;
|
if (e->song.speed1<1) e->song.speed1=1;
|
||||||
if (e->isPlaying()) e->play();
|
if (e->isPlaying()) play();
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetNextItemWidth(120.0f*dpiScale);
|
ImGui::SetNextItemWidth(120.0f*dpiScale);
|
||||||
if (ImGui::InputScalar("##Speed2",ImGuiDataType_U8,&e->song.speed2,&_ONE,&_THREE)) {
|
if (ImGui::InputScalar("##Speed2",ImGuiDataType_U8,&e->song.speed2,&_ONE,&_THREE)) {
|
||||||
if (e->song.speed2<1) e->song.speed2=1;
|
if (e->song.speed2<1) e->song.speed2=1;
|
||||||
if (e->isPlaying()) e->play();
|
if (e->isPlaying()) play();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Text("Highlight");
|
ImGui::Text("Highlight");
|
||||||
|
@ -2698,6 +2697,60 @@ void FurnaceGUI::doRedo() {
|
||||||
redoHist.pop_back();
|
redoHist.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FurnaceGUI::play() {
|
||||||
|
e->play();
|
||||||
|
curNibble=false;
|
||||||
|
activeNotes.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FurnaceGUI::stop() {
|
||||||
|
e->stop();
|
||||||
|
curNibble=false;
|
||||||
|
activeNotes.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FurnaceGUI::previewNote(int refChan, int note) {
|
||||||
|
bool chanBusy[DIV_MAX_CHANS];
|
||||||
|
memset(chanBusy,0,DIV_MAX_CHANS*sizeof(bool));
|
||||||
|
for (ActiveNote& i: activeNotes) {
|
||||||
|
if (i.chan<0 || i.chan>=DIV_MAX_CHANS) continue;
|
||||||
|
chanBusy[i.chan]=true;
|
||||||
|
}
|
||||||
|
int chanCount=e->getTotalChannelCount();
|
||||||
|
int i=refChan;
|
||||||
|
do {
|
||||||
|
if (!chanBusy[i]) {
|
||||||
|
e->noteOn(i,curIns,note);
|
||||||
|
activeNotes.push_back(ActiveNote(i,note));
|
||||||
|
//printf("PUSHING: %d NOTE %d\n",i,note);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
if (i>=chanCount) i=0;
|
||||||
|
} while (i!=refChan);
|
||||||
|
//printf("FAILED TO FIND CHANNEL!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void FurnaceGUI::stopPreviewNote(SDL_Scancode scancode) {
|
||||||
|
if (activeNotes.empty()) return;
|
||||||
|
try {
|
||||||
|
int key=noteKeys.at(scancode);
|
||||||
|
int num=12*curOctave+key;
|
||||||
|
|
||||||
|
if (key==100) return;
|
||||||
|
|
||||||
|
for (size_t i=0; i<activeNotes.size(); i++) {
|
||||||
|
if (activeNotes[i].note==num) {
|
||||||
|
e->noteOff(activeNotes[i].chan);
|
||||||
|
//printf("REMOVING %d\n",activeNotes[i].chan);
|
||||||
|
activeNotes.erase(activeNotes.begin()+i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (std::out_of_range& e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FurnaceGUI::keyDown(SDL_Event& ev) {
|
void FurnaceGUI::keyDown(SDL_Event& ev) {
|
||||||
// GLOBAL KEYS
|
// GLOBAL KEYS
|
||||||
if (ev.key.keysym.mod&KMOD_CTRL) {
|
if (ev.key.keysym.mod&KMOD_CTRL) {
|
||||||
|
@ -2713,27 +2766,23 @@ void FurnaceGUI::keyDown(SDL_Event& ev) {
|
||||||
} else switch (ev.key.keysym.sym) {
|
} else switch (ev.key.keysym.sym) {
|
||||||
case SDLK_F5:
|
case SDLK_F5:
|
||||||
if (!e->isPlaying()) {
|
if (!e->isPlaying()) {
|
||||||
e->play();
|
play();
|
||||||
curNibble=false;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDLK_F6:
|
case SDLK_F6:
|
||||||
e->play();
|
play();
|
||||||
curNibble=false;
|
|
||||||
break;
|
break;
|
||||||
case SDLK_F7:
|
case SDLK_F7:
|
||||||
e->play();
|
play();
|
||||||
curNibble=false;
|
|
||||||
break;
|
break;
|
||||||
case SDLK_F8:
|
case SDLK_F8:
|
||||||
e->stop();
|
stop();
|
||||||
break;
|
break;
|
||||||
case SDLK_RETURN:
|
case SDLK_RETURN:
|
||||||
if (e->isPlaying()) {
|
if (e->isPlaying()) {
|
||||||
e->stop();
|
stop();
|
||||||
} else {
|
} else {
|
||||||
e->play();
|
play();
|
||||||
curNibble=false;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2829,20 +2878,14 @@ void FurnaceGUI::keyDown(SDL_Event& ev) {
|
||||||
pat->data[cursor.y][1]--;
|
pat->data[cursor.y][1]--;
|
||||||
}
|
}
|
||||||
pat->data[cursor.y][2]=curIns;
|
pat->data[cursor.y][2]=curIns;
|
||||||
e->noteOn(cursor.xCoarse,curIns,num);
|
previewNote(cursor.xCoarse,num);
|
||||||
noteOffOnRelease=true;
|
|
||||||
noteOffOnReleaseKey=ev.key.keysym.scancode;
|
|
||||||
noteOffOnReleaseChan=cursor.xCoarse;
|
|
||||||
}
|
}
|
||||||
makeUndo(GUI_ACTION_PATTERN_EDIT);
|
makeUndo(GUI_ACTION_PATTERN_EDIT);
|
||||||
editAdvance();
|
editAdvance();
|
||||||
curNibble=false;
|
curNibble=false;
|
||||||
} else {
|
} else {
|
||||||
if (key!=100) {
|
if (key!=100) {
|
||||||
e->noteOn(cursor.xCoarse,curIns,num);
|
previewNote(cursor.xCoarse,num);
|
||||||
noteOffOnRelease=true;
|
|
||||||
noteOffOnReleaseKey=ev.key.keysym.scancode;
|
|
||||||
noteOffOnReleaseChan=cursor.xCoarse;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (std::out_of_range& e) {
|
} catch (std::out_of_range& e) {
|
||||||
|
@ -2899,10 +2942,7 @@ void FurnaceGUI::keyDown(SDL_Event& ev) {
|
||||||
int key=noteKeys.at(ev.key.keysym.scancode);
|
int key=noteKeys.at(ev.key.keysym.scancode);
|
||||||
int num=12*curOctave+key;
|
int num=12*curOctave+key;
|
||||||
if (key!=100) {
|
if (key!=100) {
|
||||||
e->noteOn(cursor.xCoarse,curIns,num);
|
previewNote(cursor.xCoarse,num);
|
||||||
noteOffOnRelease=true;
|
|
||||||
noteOffOnReleaseKey=ev.key.keysym.scancode;
|
|
||||||
noteOffOnReleaseChan=cursor.xCoarse;
|
|
||||||
}
|
}
|
||||||
} catch (std::out_of_range& e) {
|
} catch (std::out_of_range& e) {
|
||||||
}
|
}
|
||||||
|
@ -2930,12 +2970,7 @@ void FurnaceGUI::keyDown(SDL_Event& ev) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FurnaceGUI::keyUp(SDL_Event& ev) {
|
void FurnaceGUI::keyUp(SDL_Event& ev) {
|
||||||
if (noteOffOnRelease) {
|
stopPreviewNote(ev.key.keysym.scancode);
|
||||||
if (ev.key.keysym.scancode==noteOffOnReleaseKey) {
|
|
||||||
noteOffOnRelease=false;
|
|
||||||
e->noteOff(noteOffOnReleaseChan);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (wavePreviewOn) {
|
if (wavePreviewOn) {
|
||||||
if (ev.key.keysym.scancode==wavePreviewKey) {
|
if (ev.key.keysym.scancode==wavePreviewKey) {
|
||||||
wavePreviewOn=false;
|
wavePreviewOn=false;
|
||||||
|
@ -3277,12 +3312,7 @@ bool FurnaceGUI::loop() {
|
||||||
if (!ImGui::GetIO().WantCaptureKeyboard) {
|
if (!ImGui::GetIO().WantCaptureKeyboard) {
|
||||||
keyUp(ev);
|
keyUp(ev);
|
||||||
} else {
|
} else {
|
||||||
if (noteOffOnRelease) {
|
stopPreviewNote(ev.key.keysym.scancode);
|
||||||
if (ev.key.keysym.scancode==noteOffOnReleaseKey) {
|
|
||||||
noteOffOnRelease=false;
|
|
||||||
e->noteOff(noteOffOnReleaseChan);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (wavePreviewOn) {
|
if (wavePreviewOn) {
|
||||||
if (ev.key.keysym.scancode==wavePreviewKey) {
|
if (ev.key.keysym.scancode==wavePreviewKey) {
|
||||||
wavePreviewOn=false;
|
wavePreviewOn=false;
|
||||||
|
@ -3877,9 +3907,6 @@ FurnaceGUI::FurnaceGUI():
|
||||||
followPattern(true),
|
followPattern(true),
|
||||||
changeAllOrders(false),
|
changeAllOrders(false),
|
||||||
curWindow(GUI_WINDOW_NOTHING),
|
curWindow(GUI_WINDOW_NOTHING),
|
||||||
noteOffOnRelease(false),
|
|
||||||
noteOffOnReleaseKey((SDL_Scancode)0),
|
|
||||||
noteOffOnReleaseChan(0),
|
|
||||||
wavePreviewOn(false),
|
wavePreviewOn(false),
|
||||||
wavePreviewKey((SDL_Scancode)0),
|
wavePreviewKey((SDL_Scancode)0),
|
||||||
wavePreviewNote(0),
|
wavePreviewNote(0),
|
||||||
|
|
|
@ -219,9 +219,14 @@ class FurnaceGUI {
|
||||||
bool selecting, curNibble, extraChannelButtons, followOrders, followPattern, changeAllOrders;
|
bool selecting, curNibble, extraChannelButtons, followOrders, followPattern, changeAllOrders;
|
||||||
FurnaceGUIWindows curWindow;
|
FurnaceGUIWindows curWindow;
|
||||||
|
|
||||||
bool noteOffOnRelease;
|
struct ActiveNote {
|
||||||
SDL_Scancode noteOffOnReleaseKey;
|
int chan;
|
||||||
int noteOffOnReleaseChan;
|
int note;
|
||||||
|
ActiveNote(int c, int n):
|
||||||
|
chan(c),
|
||||||
|
note(n) {}
|
||||||
|
};
|
||||||
|
std::vector<ActiveNote> activeNotes;
|
||||||
|
|
||||||
bool wavePreviewOn;
|
bool wavePreviewOn;
|
||||||
SDL_Scancode wavePreviewKey;
|
SDL_Scancode wavePreviewKey;
|
||||||
|
@ -303,6 +308,12 @@ class FurnaceGUI {
|
||||||
void doUndo();
|
void doUndo();
|
||||||
void doRedo();
|
void doRedo();
|
||||||
|
|
||||||
|
void play();
|
||||||
|
void stop();
|
||||||
|
|
||||||
|
void previewNote(int refChan, int note);
|
||||||
|
void stopPreviewNote(SDL_Scancode scancode);
|
||||||
|
|
||||||
void keyDown(SDL_Event& ev);
|
void keyDown(SDL_Event& ev);
|
||||||
void keyUp(SDL_Event& ev);
|
void keyUp(SDL_Event& ev);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue