Merge branch 'master' of https://github.com/tildearrow/furnace into SID3

This commit is contained in:
LTVA1 2024-08-24 19:15:27 +03:00
commit 12bd2d3829
28 changed files with 541 additions and 76 deletions

View file

@ -35,6 +35,7 @@ const char* aboutLine[]={
_N("-- program --"),
"tildearrow",
_N("A M 4 N (intro tune)"),
"Adam Lederer",
"akumanatt",
"cam900",
"djtuBIG-MaliceX",

View file

@ -161,6 +161,8 @@ void FurnaceGUI::drawCSPlayer() {
ImGui::TableNextColumn();
ImGui::Text(_("vols"));
ImGui::TableNextColumn();
ImGui::Text(_("volst"));
ImGui::TableNextColumn();
ImGui::Text(_("vib"));
ImGui::TableNextColumn();
ImGui::Text(_("porta"));
@ -189,6 +191,8 @@ void FurnaceGUI::drawCSPlayer() {
ImGui::TableNextColumn();
ImGui::Text("%+d",state->volSpeed);
ImGui::TableNextColumn();
ImGui::Text("%+d",state->volSpeedTarget);
ImGui::TableNextColumn();
ImGui::Text("%d/%d (%d)",state->vibratoDepth,state->vibratoRate,state->vibratoPos);
ImGui::TableNextColumn();
ImGui::Text("-> %d (%d)",state->portaTarget,state->portaSpeed);

View file

@ -145,6 +145,7 @@ void FurnaceGUI::drawDebug() {
ImGui::Text("- portaNote = %d",ch->portaNote);
ImGui::Text("- volume = %.4x",ch->volume);
ImGui::Text("- volSpeed = %d",ch->volSpeed);
ImGui::Text("- volSpeedTarget = %d",ch->volSpeedTarget);
ImGui::Text("- cut = %d",ch->cut);
ImGui::Text("- rowDelay = %d",ch->rowDelay);
ImGui::Text("- volMax = %.4x",ch->volMax);

View file

@ -73,6 +73,8 @@ void FurnaceGUI::doAction(int what) {
case GUI_ACTION_UNDO:
if (curWindow==GUI_WINDOW_SAMPLE_EDIT) {
doUndoSample();
} else if (curWindow==GUI_WINDOW_INS_EDIT) {
doUndoInstrument();
} else {
doUndo();
}
@ -80,6 +82,8 @@ void FurnaceGUI::doAction(int what) {
case GUI_ACTION_REDO:
if (curWindow==GUI_WINDOW_SAMPLE_EDIT) {
doRedoSample();
} else if (curWindow==GUI_WINDOW_INS_EDIT) {
doRedoInstrument();
} else {
doRedo();
}
@ -677,30 +681,7 @@ void FurnaceGUI::doAction(int what) {
latchNibble=false;
break;
case GUI_ACTION_PAT_ABSORB_INSTRUMENT: {
DivPattern* pat=e->curPat[cursor.xCoarse].getPattern(e->curOrders->ord[cursor.xCoarse][curOrder],false);
if (!pat) break;
bool foundIns=false;
bool foundOctave=false;
for (int i=cursor.y; i>=0 && !(foundIns && foundOctave); i--) {
// absorb most recent instrument
if (!foundIns && pat->data[i][2] >= 0) {
curIns=pat->data[i][2];
foundIns=true;
}
// absorb most recent octave (i.e. set curOctave such that the "main row" (QWERTY) of notes
// will result in an octave number equal to the previous note).
if (!foundOctave && pat->data[i][0] != 0) {
// decode octave data (was signed cast to unsigned char)
int octave=pat->data[i][1];
if (octave>128) octave-=256;
// @NOTE the special handling when note==12, which is really an octave above what's
// stored in the octave data. without this handling, if you press Q, then
// "ABSORB_INSTRUMENT", then Q again, you'd get a different octave!
if (pat->data[i][0]==12) octave++;
curOctave=CLAMP(octave-1, GUI_EDIT_OCTAVE_MIN, GUI_EDIT_OCTAVE_MAX);
foundOctave=true;
}
}
doAbsorbInstrument();
break;
}

View file

@ -508,7 +508,7 @@ void FurnaceGUI::drawMobileControls() {
mobileMenuOpen=false;
doAction(GUI_ACTION_SAVE_AS);
}
ImGui::SameLine();
if (ImGui::Button(_("Export"))) {
doAction(GUI_ACTION_EXPORT);
}
@ -533,6 +533,10 @@ void FurnaceGUI::drawMobileControls() {
drawSpeed(true);
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem(_("Comments"))) {
drawNotes(true);
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
break;

View file

@ -1823,6 +1823,52 @@ void FurnaceGUI::doExpandSong(int multiplier) {
if (e->isPlaying()) e->play();
}
void FurnaceGUI::doAbsorbInstrument() {
bool foundIns=false;
bool foundOctave=false;
auto foundAll = [&]() { return foundIns && foundOctave; };
// search this order and all prior until we find all the data we need
int orderIdx=curOrder;
for (; orderIdx>=0 && !foundAll(); orderIdx--) {
DivPattern* pat=e->curPat[cursor.xCoarse].getPattern(e->curOrders->ord[cursor.xCoarse][orderIdx],false);
if (!pat) continue;
// start on current row when searching current order, but start from end when searching
// prior orders.
int searchStartRow=orderIdx==curOrder ? cursor.y : e->curSubSong->patLen-1;
for (int i=searchStartRow; i>=0 && !foundAll(); i--) {
// absorb most recent instrument
if (!foundIns && pat->data[i][2] >= 0) {
foundIns=true;
curIns=pat->data[i][2];
}
// absorb most recent octave (i.e. set curOctave such that the "main row" (QWERTY) of
// notes will result in an octave number equal to the previous note).
if (!foundOctave && pat->data[i][0] != 0) {
foundOctave=true;
// decode octave data (was signed cast to unsigned char)
int octave=pat->data[i][1];
if (octave>128) octave-=256;
// @NOTE the special handling when note==12, which is really an octave above what's
// stored in the octave data. without this handling, if you press Q, then
// "ABSORB_INSTRUMENT", then Q again, you'd get a different octave!
if (pat->data[i][0]==12) octave++;
curOctave=CLAMP(octave-1, GUI_EDIT_OCTAVE_MIN, GUI_EDIT_OCTAVE_MAX);
}
}
}
// if no instrument has been set at this point, the only way to match it is to use "none"
if (!foundIns) curIns=-1;
logD("doAbsorbInstrument -- searched %d orders", curOrder-orderIdx);
}
void FurnaceGUI::doDrag() {
int len=dragEnd.xCoarse-dragStart.xCoarse+1;

View file

@ -3739,6 +3739,7 @@ bool FurnaceGUI::loop() {
ImGui::GetIO().AddKeyEvent(ImGuiKey_Backspace,false);
injectBackUp=false;
}
while (SDL_PollEvent(&ev)) {
WAKE_UP;
ImGui_ImplSDL2_ProcessEvent(&ev);
@ -3755,13 +3756,16 @@ bool FurnaceGUI::loop() {
}
case SDL_MOUSEBUTTONUP:
pointUp(ev.button.x,ev.button.y,ev.button.button);
insEditMayBeDirty=true;
break;
case SDL_MOUSEBUTTONDOWN:
pointDown(ev.button.x,ev.button.y,ev.button.button);
insEditMayBeDirty=true;
break;
case SDL_MOUSEWHEEL:
wheelX+=ev.wheel.x;
wheelY+=ev.wheel.y;
insEditMayBeDirty=true;
break;
case SDL_WINDOWEVENT:
switch (ev.window.event) {
@ -3838,12 +3842,14 @@ bool FurnaceGUI::loop() {
if (!ImGui::GetIO().WantCaptureKeyboard) {
keyDown(ev);
}
insEditMayBeDirty=true;
#ifdef IS_MOBILE
injectBackUp=true;
#endif
break;
case SDL_KEYUP:
// for now
insEditMayBeDirty=true;
break;
case SDL_DROPFILE:
if (ev.drop.file!=NULL) {
@ -4482,7 +4488,7 @@ bool FurnaceGUI::loop() {
} else {
if (ImGui::BeginMenu(_("add chip..."))) {
exitDisabledTimer=1;
DivSystem picked=systemPicker();
DivSystem picked=systemPicker(false);
if (picked!=DIV_SYSTEM_NULL) {
if (!e->addSystem(picked)) {
showError(fmt::sprintf(_("cannot add chip! (%s)"),e->getLastError()));
@ -4513,7 +4519,7 @@ bool FurnaceGUI::loop() {
ImGui::Checkbox(_("Preserve channel positions"),&preserveChanPos);
for (int i=0; i<e->song.systemLen; i++) {
if (ImGui::BeginMenu(fmt::sprintf("%d. %s##_SYSC%d",i+1,getSystemName(e->song.system[i]),i).c_str())) {
DivSystem picked=systemPicker();
DivSystem picked=systemPicker(false);
if (picked!=DIV_SYSTEM_NULL) {
if (e->changeSystem(i,picked,preserveChanPos)) {
MARK_MODIFIED;
@ -5856,6 +5862,7 @@ bool FurnaceGUI::loop() {
centerNextWindow(_("Rendering..."),canvasW,canvasH);
if (ImGui::BeginPopupModal(_("Rendering..."),NULL,ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) {
WAKE_UP;
if(audioExportOptions.mode != DIV_EXPORT_MODE_MANY_CHAN)
{
ImGui::Text(_("Please wait..."));
@ -5916,7 +5923,7 @@ bool FurnaceGUI::loop() {
ImGui::Text(_("Channel %d of %d"), curFile + 1, totalFiles);
}
ImGui::ProgressBar(curProgress,ImVec2(-FLT_MIN,0), fmt::sprintf("%.2f%%", curProgress * 100.0f).c_str());
ImGui::ProgressBar(curProgress,ImVec2(320.0f*dpiScale,0), fmt::sprintf("%.2f%%", curProgress * 100.0f).c_str());
if (ImGui::Button(_("Abort"))) {
if (e->haltAudioFile()) {
@ -7241,6 +7248,11 @@ bool FurnaceGUI::loop() {
willCommit=false;
}
// To check for instrument editor modification, we need an up-to-date `insEditMayBeDirty`
// (based on incoming user input events), and we want any possible instrument modifications
// to already have been made.
checkRecordInstrumentUndoStep();
if (shallDetectScale) {
if (--shallDetectScale<1) {
if (settings.dpiScale<0.5f) {
@ -8414,6 +8426,8 @@ FurnaceGUI::FurnaceGUI():
localeRequiresChineseTrad(false),
localeRequiresKorean(false),
prevInsData(NULL),
cachedCurInsPtr(NULL),
insEditMayBeDirty(false),
pendingLayoutImport(NULL),
pendingLayoutImportLen(0),
pendingLayoutImportStep(0),

View file

@ -2270,6 +2270,9 @@ class FurnaceGUI {
std::vector<ImWchar> localeExtraRanges;
DivInstrument* prevInsData;
DivInstrument cachedCurIns;
DivInstrument* cachedCurInsPtr;
bool insEditMayBeDirty;
unsigned char* pendingLayoutImport;
size_t pendingLayoutImportLen;
@ -2834,7 +2837,7 @@ class FurnaceGUI {
void drawMemory();
void drawCompatFlags();
void drawPiano();
void drawNotes();
void drawNotes(bool asChild=false);
void drawChannels();
void drawPatManager();
void drawSysManager();
@ -2924,13 +2927,14 @@ class FurnaceGUI {
void doExpand(int multiplier, const SelectionPoint& sStart, const SelectionPoint& sEnd);
void doCollapseSong(int divider);
void doExpandSong(int multiplier);
void doAbsorbInstrument();
void doUndo();
void doRedo();
void doFind();
void doReplace();
void doDrag();
void editOptions(bool topMenu);
DivSystem systemPicker();
DivSystem systemPicker(bool fullWidth);
void noteInput(int num, int key, int vol=-1);
void valueInput(int num, bool direct=false, int target=-1);
void orderInput(int num);
@ -2940,6 +2944,10 @@ class FurnaceGUI {
void doUndoSample();
void doRedoSample();
void checkRecordInstrumentUndoStep();
void doUndoInstrument();
void doRedoInstrument();
void play(int row=0);
void setOrder(unsigned char order, bool forced=false);
void stop();

View file

@ -474,8 +474,8 @@ const FurnaceGUIColors fxColors[256]={
GUI_COLOR_PATTERN_EFFECT_INVALID,
GUI_COLOR_PATTERN_EFFECT_INVALID,
GUI_COLOR_PATTERN_EFFECT_INVALID,
GUI_COLOR_PATTERN_EFFECT_INVALID,
GUI_COLOR_PATTERN_EFFECT_INVALID,
GUI_COLOR_PATTERN_EFFECT_VOLUME,
GUI_COLOR_PATTERN_EFFECT_VOLUME,
GUI_COLOR_PATTERN_EFFECT_INVALID,
GUI_COLOR_PATTERN_EFFECT_INVALID,
GUI_COLOR_PATTERN_EFFECT_INVALID,

View file

@ -6438,6 +6438,7 @@ void FurnaceGUI::drawInsEdit() {
ImGui::SetNextWindowSizeConstraints(ImVec2(440.0f*dpiScale,400.0f*dpiScale),ImVec2(canvasW,canvasH));
}
if (ImGui::Begin("Instrument Editor",&insEditOpen,globalWinFlags|(settings.allowEditDocking?0:ImGuiWindowFlags_NoDocking),_("Instrument Editor"))) {
DivInstrument* ins=NULL;
if (curIns==-2) {
ImGui::SetCursorPosY(ImGui::GetCursorPosY()+(ImGui::GetContentRegionAvail().y-ImGui::GetFrameHeightWithSpacing()+ImGui::GetStyle().ItemSpacing.y)*0.5f);
CENTER_TEXT(_("waiting..."));
@ -6465,6 +6466,7 @@ void FurnaceGUI::drawInsEdit() {
curIns=i;
wavePreviewInit=true;
updateFMPreview=true;
ins = e->song.ins[curIns];
}
}
ImGui::EndCombo();
@ -6487,7 +6489,7 @@ void FurnaceGUI::drawInsEdit() {
ImGui::EndTable();
}
} else {
DivInstrument* ins=e->song.ins[curIns];
ins=e->song.ins[curIns];
if (updateFMPreview) {
renderFMPreview(ins);
updateFMPreview=false;
@ -8146,6 +8148,8 @@ void FurnaceGUI::drawInsEdit() {
macroList.push_back(FurnaceGUIMacroDesc(_("Noise"),&ins->std.dutyMacro,0,8,160,uiColors[GUI_COLOR_MACRO_NOISE]));
}
macroList.push_back(FurnaceGUIMacroDesc(_("Waveform"),&ins->std.waveMacro,0,waveCount,160,uiColors[GUI_COLOR_MACRO_WAVE],false,NULL,NULL,false,NULL));
macroList.push_back(FurnaceGUIMacroDesc(_("Panning (left)"),&ins->std.panLMacro,0,15,46,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL));
macroList.push_back(FurnaceGUIMacroDesc(_("Panning (right)"),&ins->std.panRMacro,0,15,46,uiColors[GUI_COLOR_MACRO_OTHER]));
macroList.push_back(FurnaceGUIMacroDesc(_("Pitch"),&ins->std.pitchMacro,-2048,2047,160,uiColors[GUI_COLOR_MACRO_PITCH],true,macroRelativeMode));
macroList.push_back(FurnaceGUIMacroDesc(_("Phase Reset"),&ins->std.phaseResetMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true));
break;
@ -8703,6 +8707,63 @@ void FurnaceGUI::drawInsEdit() {
ImGui::EndPopup();
}
}
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_INS_EDIT;
ImGui::End();
}
void FurnaceGUI::checkRecordInstrumentUndoStep() {
if (insEditOpen && curIns>=0 && curIns<(int)e->song.ins.size()) {
DivInstrument* ins=e->song.ins[curIns];
// invalidate cachedCurIns/any possible changes if the cachedCurIns was referencing a different
// instrument altgoether
bool insChanged=ins!=cachedCurInsPtr;
if (insChanged) {
insEditMayBeDirty=false;
cachedCurInsPtr=ins;
cachedCurIns=*ins;
}
cachedCurInsPtr=ins;
// check against the last cached to see if diff -- note that modifications to instruments
// happen outside drawInsEdit (e.g. cursor inputs are processed and can directly modify
// macro data). but don't check until we think the user input is complete.
bool delayDiff=ImGui::IsMouseDown(ImGuiMouseButton_Left) || ImGui::IsMouseDown(ImGuiMouseButton_Right) || ImGui::GetIO().WantCaptureKeyboard;
if (!delayDiff && insEditMayBeDirty) {
bool hasChange=ins->recordUndoStepIfChanged(e->processTime, &cachedCurIns);
if (hasChange) {
cachedCurIns=*ins;
}
insEditMayBeDirty=false;
}
} else {
cachedCurInsPtr=NULL;
insEditMayBeDirty=false;
}
}
void FurnaceGUI::doUndoInstrument() {
if (!insEditOpen) return;
if (curIns<0 || curIns>=(int)e->song.ins.size()) return;
DivInstrument* ins=e->song.ins[curIns];
// is locking the engine necessary? copied from doUndoSample
e->lockEngine([this,ins]() {
ins->undo();
cachedCurInsPtr=ins;
cachedCurIns=*ins;
});
}
void FurnaceGUI::doRedoInstrument() {
if (!insEditOpen) return;
if (curIns<0 || curIns>=(int)e->song.ins.size()) return;
DivInstrument* ins=e->song.ins[curIns];
// is locking the engine necessary? copied from doRedoSample
e->lockEngine([this,ins]() {
ins->redo();
cachedCurInsPtr=ins;
cachedCurIns=*ins;
});
}

View file

@ -1507,6 +1507,7 @@ void FurnaceGUI::drawPattern() {
i.cmd==DIV_CMD_HINT_PORTA ||
i.cmd==DIV_CMD_HINT_LEGATO ||
i.cmd==DIV_CMD_HINT_VOL_SLIDE ||
i.cmd==DIV_CMD_HINT_VOL_SLIDE_TARGET ||
i.cmd==DIV_CMD_HINT_ARPEGGIO ||
i.cmd==DIV_CMD_HINT_PITCH ||
i.cmd==DIV_CMD_HINT_VIBRATO ||

View file

@ -1084,15 +1084,19 @@ void FurnaceGUI::drawSettings() {
ImGui::PushID(i);
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x-ImGui::CalcTextSize(_("Invert")).x-ImGui::GetFrameHeightWithSpacing()*2.0-ImGui::GetStyle().ItemSpacing.x*2.0);
if (ImGui::BeginCombo("##System",getSystemName(sysID))) {
for (int j=0; availableSystems[j]; j++) {
if (ImGui::Selectable(getSystemName((DivSystem)availableSystems[j]),sysID==availableSystems[j])) {
sysID=(DivSystem)availableSystems[j];
settings.initialSys.set(fmt::sprintf("id%d",i),(int)e->systemToFileFur(sysID));
settings.initialSys.set(fmt::sprintf("flags%d",i),"");
settingsChanged=true;
}
if (ImGui::BeginCombo("##System",getSystemName(sysID),ImGuiComboFlags_HeightLargest)) {
sysID=systemPicker(true);
if (sysID!=DIV_SYSTEM_NULL)
{
settings.initialSys.set(fmt::sprintf("id%d",i),(int)e->systemToFileFur(sysID));
settings.initialSys.set(fmt::sprintf("flags%d",i),"");
settingsChanged=true;
ImGui::CloseCurrentPopup();
}
ImGui::EndCombo();
}

View file

@ -22,18 +22,23 @@
// NOTE: please don't ask me to enable text wrap.
// Dear ImGui doesn't have that feature. D:
void FurnaceGUI::drawNotes() {
void FurnaceGUI::drawNotes(bool asChild) {
if (nextWindow==GUI_WINDOW_NOTES) {
notesOpen=true;
ImGui::SetNextWindowFocus();
nextWindow=GUI_WINDOW_NOTHING;
}
if (!notesOpen) return;
if (ImGui::Begin("Song Comments",&notesOpen,globalWinFlags,_("Song Comments"))) {
if (!notesOpen && !asChild) return;
bool began=asChild?ImGui::BeginChild("Song Info##Song Information"):ImGui::Begin("Song Comments",&notesOpen,globalWinFlags,_("Song Comments"));
if (began) {
if (ImGui::InputTextMultiline("##SongNotes",&e->song.notes,ImGui::GetContentRegionAvail(),ImGuiInputTextFlags_UndoRedo)) {
MARK_MODIFIED;
}
}
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_NOTES;
ImGui::End();
if (!asChild && ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_NOTES;
if (asChild) {
ImGui::EndChild();
} else {
ImGui::End();
}
}

View file

@ -102,7 +102,7 @@ void FurnaceGUI::drawSysManager() {
ImGui::SameLine();
ImGui::Button(_("Change##SysChange"));
if (ImGui::BeginPopupContextItem("SysPickerC",ImGuiPopupFlags_MouseButtonLeft)) {
DivSystem picked=systemPicker();
DivSystem picked=systemPicker(false);
if (picked!=DIV_SYSTEM_NULL) {
if (e->changeSystem(i,picked,preserveChanPos)) {
MARK_MODIFIED;
@ -138,7 +138,7 @@ void FurnaceGUI::drawSysManager() {
ImGui::TableNextColumn();
ImGui::Button(ICON_FA_PLUS "##SysAdd");
if (ImGui::BeginPopupContextItem("SysPickerA",ImGuiPopupFlags_MouseButtonLeft)) {
DivSystem picked=systemPicker();
DivSystem picked=systemPicker(false);
if (picked!=DIV_SYSTEM_NULL) {
if (!e->addSystem(picked)) {
showError(fmt::sprintf(_("cannot add chip! (%s)"),e->getLastError()));

View file

@ -23,7 +23,7 @@
#include "guiConst.h"
#include <imgui.h>
DivSystem FurnaceGUI::systemPicker() {
DivSystem FurnaceGUI::systemPicker(bool fullWidth) {
DivSystem ret=DIV_SYSTEM_NULL;
DivSystem hoveredSys=DIV_SYSTEM_NULL;
bool reissueSearch=false;
@ -61,7 +61,7 @@ DivSystem FurnaceGUI::systemPicker() {
}
}
}
if (ImGui::BeginTable("SysList",1,ImGuiTableFlags_ScrollY,ImVec2(500.0f*dpiScale,200.0*dpiScale))) {
if (ImGui::BeginTable("SysList",1,ImGuiTableFlags_ScrollY,ImVec2(fullWidth ? ImGui::GetContentRegionAvail().x : 500.0f*dpiScale,200.0f*dpiScale))) {
if (sysSearchQuery.empty()) {
// display chip list
for (int j=0; curSysSection[j]; j++) {

View file

@ -392,7 +392,7 @@ void FurnaceGUI::drawUserPresets() {
tempID=fmt::sprintf("%s##USystem",getSystemName(chip.sys));
ImGui::Button(tempID.c_str(),ImVec2(ImGui::GetContentRegionAvail().x-ImGui::CalcTextSize(_("Invert")).x-ImGui::GetFrameHeightWithSpacing()*2.0-ImGui::GetStyle().ItemSpacing.x*2.0,0));
if (ImGui::BeginPopupContextItem("SysPickerCU",ImGuiPopupFlags_MouseButtonLeft)) {
DivSystem picked=systemPicker();
DivSystem picked=systemPicker(false);
if (picked!=DIV_SYSTEM_NULL) {
chip.sys=picked;
mustBake=true;
@ -456,7 +456,7 @@ void FurnaceGUI::drawUserPresets() {
ImGui::Button(ICON_FA_PLUS "##SysAddU");
if (ImGui::BeginPopupContextItem("SysPickerU",ImGuiPopupFlags_MouseButtonLeft)) {
DivSystem picked=systemPicker();
DivSystem picked=systemPicker(false);
if (picked!=DIV_SYSTEM_NULL) {
preset->orig.push_back(FurnaceGUISysDefChip(picked,1.0f,0.0f,""));
mustBake=true;