From 943f88b306b46721d0e9d46d6b198bd6ee66bd92 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 13 Jan 2022 13:55:33 -0500 Subject: [PATCH] add four more macros they eventually will be used --- papers/format.md | 20 ++++++-- src/engine/engine.cpp | 38 +++++++++++++++ src/engine/engine.h | 4 +- src/engine/instrument.h | 26 +++++++++-- src/engine/macroInt.cpp | 100 ++++++++++++++++++++++++++++++++++++++++ src/engine/macroInt.h | 36 ++++++++++++--- 6 files changed, 208 insertions(+), 16 deletions(-) diff --git a/papers/format.md b/papers/format.md index a0241b47a..16db54423 100644 --- a/papers/format.md +++ b/papers/format.md @@ -12,7 +12,7 @@ size | description -----|------------------------------------ 16 | "-Furnace module-" format magic 2 | format version - | - should be 15 for Furnace 0.3 + | - should be 17 for Furnace 0.4 2 | reserved 4 | song info pointer 8 | reserved @@ -157,18 +157,30 @@ size | description 4 | arp macro length 4 | duty macro length 4 | wave macro length + 4 | pitch macro length (>=17) + 4 | extra 1 macro length (>=17) + 4 | extra 2 macro length (>=17) + 4 | extra 3 macro length (>=17) 4 | volume macro loop 4 | arp macro loop 4 | duty macro loop 4 | wave macro loop + 4 | pitch macro loop (>=17) + 4 | extra 1 macro loop (>=17) + 4 | extra 2 macro loop (>=17) + 4 | extra 3 macro loop (>=17) 1 | arp macro mode - 1 | volume macro height (>=15) - 1 | duty macro height (>=15) - 1 | wave macro height (>=15) + 1 | volume macro height (>=15) or reserved + 1 | duty macro height (>=15) or reserved + 1 | wave macro height (>=15) or reserved 4?? | volume macro 4?? | arp macro 4?? | duty macro 4?? | wave macro + 4?? | pitch macro (>=17) + 4?? | extra 1 macro (>=17) + 4?? | extra 2 macro (>=17) + 4?? | extra 3 macro (>=17) # wavetable diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index fd99aa5c2..73a7e7a67 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -1209,10 +1209,22 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { ins->std.arpMacroLen=reader.readI(); ins->std.dutyMacroLen=reader.readI(); ins->std.waveMacroLen=reader.readI(); + if (ds.version>=17) { + ins->std.pitchMacroLen=reader.readI(); + ins->std.ex1MacroLen=reader.readI(); + ins->std.ex2MacroLen=reader.readI(); + ins->std.ex3MacroLen=reader.readI(); + } ins->std.volMacroLoop=reader.readI(); ins->std.arpMacroLoop=reader.readI(); ins->std.dutyMacroLoop=reader.readI(); ins->std.waveMacroLoop=reader.readI(); + if (ds.version>=17) { + ins->std.pitchMacroLoop=reader.readI(); + ins->std.ex1MacroLoop=reader.readI(); + ins->std.ex2MacroLoop=reader.readI(); + ins->std.ex3MacroLoop=reader.readI(); + } ins->std.arpMacroMode=reader.readC(); ins->std.volMacroHeight=reader.readC(); ins->std.dutyMacroHeight=reader.readC(); @@ -1224,6 +1236,12 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { reader.read(ins->std.arpMacro,4*ins->std.arpMacroLen); reader.read(ins->std.dutyMacro,4*ins->std.dutyMacroLen); reader.read(ins->std.waveMacro,4*ins->std.waveMacroLen); + if (ds.version>=17) { + reader.read(ins->std.pitchMacro,4*ins->std.pitchMacroLen); + reader.read(ins->std.ex1Macro,4*ins->std.ex1MacroLen); + reader.read(ins->std.ex2Macro,4*ins->std.ex2MacroLen); + reader.read(ins->std.ex3Macro,4*ins->std.ex3MacroLen); + } ds.ins.push_back(ins); } @@ -1665,10 +1683,18 @@ SafeWriter* DivEngine::saveFur() { w->writeI(ins->std.arpMacroLen); w->writeI(ins->std.dutyMacroLen); w->writeI(ins->std.waveMacroLen); + w->writeI(ins->std.pitchMacroLen); + w->writeI(ins->std.ex1MacroLen); + w->writeI(ins->std.ex2MacroLen); + w->writeI(ins->std.ex3MacroLen); w->writeI(ins->std.volMacroLoop); w->writeI(ins->std.arpMacroLoop); w->writeI(ins->std.dutyMacroLoop); w->writeI(ins->std.waveMacroLoop); + w->writeI(ins->std.pitchMacroLoop); + w->writeI(ins->std.ex1MacroLoop); + w->writeI(ins->std.ex2MacroLoop); + w->writeI(ins->std.ex3MacroLoop); w->writeC(ins->std.arpMacroMode); w->writeC(ins->std.volMacroHeight); w->writeC(ins->std.dutyMacroHeight); @@ -1685,6 +1711,18 @@ SafeWriter* DivEngine::saveFur() { for (int j=0; jstd.waveMacroLen; j++) { w->writeI(ins->std.waveMacro[j]); } + for (int j=0; jstd.pitchMacroLen; j++) { + w->writeI(ins->std.pitchMacro[j]); + } + for (int j=0; jstd.ex1MacroLen; j++) { + w->writeI(ins->std.ex1Macro[j]); + } + for (int j=0; jstd.ex2MacroLen; j++) { + w->writeI(ins->std.ex2Macro[j]); + } + for (int j=0; jstd.ex3MacroLen; j++) { + w->writeI(ins->std.ex3Macro[j]); + } } /// WAVETABLE diff --git a/src/engine/engine.h b/src/engine/engine.h index 7fb251efd..4334504b2 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -9,8 +9,8 @@ #include #include -#define DIV_VERSION "0.3.1" -#define DIV_ENGINE_VERSION 16 +#define DIV_VERSION "0.4pre1" +#define DIV_ENGINE_VERSION 17 enum DivStatusView { DIV_STATUS_NOTHING=0, diff --git a/src/engine/instrument.h b/src/engine/instrument.h index 196ae314d..1cfd929d2 100644 --- a/src/engine/instrument.h +++ b/src/engine/instrument.h @@ -7,7 +7,9 @@ enum DivInstrumentType { DIV_INS_FM=1, DIV_INS_GB=2, DIV_INS_C64=3, - DIV_INS_AMIGA=4 + DIV_INS_AMIGA=4, + DIV_INS_PCE=5, + DIV_INS_AY=6 }; struct DivInstrumentFM { @@ -84,10 +86,14 @@ struct DivInstrumentSTD { int arpMacro[256]; int dutyMacro[256]; int waveMacro[256]; + int pitchMacro[256]; + int ex1Macro[256]; + int ex2Macro[256]; + int ex3Macro[256]; bool arpMacroMode; unsigned char volMacroHeight, dutyMacroHeight, waveMacroHeight; - unsigned char volMacroLen, arpMacroLen, dutyMacroLen, waveMacroLen; - signed char volMacroLoop, arpMacroLoop, dutyMacroLoop, waveMacroLoop; + unsigned char volMacroLen, arpMacroLen, dutyMacroLen, waveMacroLen, pitchMacroLen, ex1MacroLen, ex2MacroLen, ex3MacroLen; + signed char volMacroLoop, arpMacroLoop, dutyMacroLoop, waveMacroLoop, pitchMacroLoop, ex1MacroLoop, ex2MacroLoop, ex3MacroLoop; DivInstrumentSTD(): arpMacroMode(false), volMacroHeight(15), @@ -97,14 +103,26 @@ struct DivInstrumentSTD { arpMacroLen(0), dutyMacroLen(0), waveMacroLen(0), + pitchMacroLen(0), + ex1MacroLen(0), + ex2MacroLen(0), + ex3MacroLen(0), volMacroLoop(-1), arpMacroLoop(-1), dutyMacroLoop(-1), - waveMacroLoop(-1) { + waveMacroLoop(-1), + pitchMacroLoop(-1), + ex1MacroLoop(-1), + ex2MacroLoop(-1), + ex3MacroLoop(-1) { memset(volMacro,0,256*sizeof(int)); memset(arpMacro,0,256*sizeof(int)); memset(dutyMacro,0,256*sizeof(int)); memset(waveMacro,0,256*sizeof(int)); + memset(pitchMacro,0,256*sizeof(int)); + memset(ex1Macro,0,256*sizeof(int)); + memset(ex2Macro,0,256*sizeof(int)); + memset(ex3Macro,0,256*sizeof(int)); } }; diff --git a/src/engine/macroInt.cpp b/src/engine/macroInt.cpp index d70b26fbf..a7abda2c6 100644 --- a/src/engine/macroInt.cpp +++ b/src/engine/macroInt.cpp @@ -66,6 +66,70 @@ void DivMacroInt::next() { } } } + + if (finishedPitch) finishedPitch=false; + if (hadPitch!=hasPitch) { + finishedPitch=true; + } + hadPitch=hasPitch; + if (hasPitch) { + pitch=ins->std.pitchMacro[pitchPos++]; + if (pitchPos>=ins->std.pitchMacroLen && ins->std.pitchMacroLoopstd.pitchMacroLen) { + if (ins->std.pitchMacroLoop>=0) { + pitchPos=ins->std.pitchMacroLoop; + } else { + hasPitch=false; + } + } + } + + if (finishedEx1) finishedEx1=false; + if (hadEx1!=hasEx1) { + finishedEx1=true; + } + hadEx1=hasEx1; + if (hasEx1) { + ex1=ins->std.ex1Macro[ex1Pos++]; + if (ex1Pos>=ins->std.ex1MacroLen && ins->std.ex1MacroLoopstd.ex1MacroLen) { + if (ins->std.ex1MacroLoop>=0) { + ex1Pos=ins->std.ex1MacroLoop; + } else { + hasEx1=false; + } + } + } + + if (finishedEx2) finishedEx2=false; + if (hadEx2!=hasEx2) { + finishedEx2=true; + } + hadEx2=hasEx2; + if (hasEx2) { + ex2=ins->std.ex2Macro[ex2Pos++]; + if (ex2Pos>=ins->std.ex2MacroLen && ins->std.ex2MacroLoopstd.ex2MacroLen) { + if (ins->std.ex2MacroLoop>=0) { + ex2Pos=ins->std.ex2MacroLoop; + } else { + hasEx2=false; + } + } + } + + if (finishedEx3) finishedEx3=false; + if (hadEx3!=hasEx3) { + finishedEx3=true; + } + hadEx3=hasEx3; + if (hasEx3) { + ex3=ins->std.ex3Macro[ex3Pos++]; + if (ex3Pos>=ins->std.ex3MacroLen && ins->std.ex3MacroLoopstd.ex3MacroLen) { + if (ins->std.ex3MacroLoop>=0) { + ex3Pos=ins->std.ex3MacroLoop; + } else { + hasEx3=false; + } + } + } } void DivMacroInt::init(DivInstrument* which) { @@ -74,18 +138,34 @@ void DivMacroInt::init(DivInstrument* which) { arpPos=0; dutyPos=0; wavePos=0; + pitchPos=0; + ex1Pos=0; + ex2Pos=0; + ex3Pos=0; hasVol=false; hasArp=false; hasDuty=false; hasWave=false; + hasPitch=false; + hasEx1=false; + hasEx2=false; + hasEx3=false; hadVol=false; hadArp=false; hadDuty=false; hadWave=false; + hadPitch=false; + hadEx1=false; + hadEx2=false; + hadEx3=false; willVol=false; willArp=false; willDuty=false; willWave=false; + willPitch=false; + willEx1=false; + willEx2=false; + willEx3=false; arpMode=false; if (ins==NULL) return; @@ -110,6 +190,26 @@ void DivMacroInt::init(DivInstrument* which) { hasWave=true; willWave=true; } + if (ins->std.pitchMacroLen>0) { + hadPitch=true; + hasPitch=true; + willPitch=true; + } + if (ins->std.ex1MacroLen>0) { + hadEx1=true; + hasEx1=true; + willEx1=true; + } + if (ins->std.ex2MacroLen>0) { + hadEx2=true; + hasEx2=true; + willEx2=true; + } + if (ins->std.ex3MacroLen>0) { + hadEx3=true; + hasEx3=true; + willEx3=true; + } if (ins->std.arpMacroMode) { arpMode=true; diff --git a/src/engine/macroInt.h b/src/engine/macroInt.h index 599f0ca0d..b486b4e3b 100644 --- a/src/engine/macroInt.h +++ b/src/engine/macroInt.h @@ -5,15 +5,15 @@ class DivMacroInt { DivInstrument* ins; - int volPos, arpPos, dutyPos, wavePos; + int volPos, arpPos, dutyPos, wavePos, pitchPos, ex1Pos, ex2Pos, ex3Pos; public: int vol; int arp; - int duty, wave; - bool hasVol, hasArp, hasDuty, hasWave; - bool hadVol, hadArp, hadDuty, hadWave; - bool finishedVol, finishedArp, finishedDuty, finishedWave; - bool willVol, willArp, willDuty, willWave; + int duty, wave, pitch, ex1, ex2, ex3; + bool hasVol, hasArp, hasDuty, hasWave, hasPitch, hasEx1, hasEx2, hasEx3; + bool hadVol, hadArp, hadDuty, hadWave, hadPitch, hadEx1, hadEx2, hadEx3; + bool finishedVol, finishedArp, finishedDuty, finishedWave, finishedPitch, finishedEx1, finishedEx2, finishedEx3; + bool willVol, willArp, willDuty, willWave, willPitch, willEx1, willEx2, willEx3; bool arpMode; void next(); void init(DivInstrument* which); @@ -23,26 +23,50 @@ class DivMacroInt { arpPos(0), dutyPos(0), wavePos(0), + pitchPos(0), + ex1Pos(0), + ex2Pos(0), + ex3Pos(0), vol(0), arp(0), duty(0), wave(0), + pitch(0), + ex1(0), + ex2(0), + ex3(0), hasVol(false), hasArp(false), hasDuty(false), hasWave(false), + hasPitch(false), + hasEx1(false), + hasEx2(false), + hasEx3(false), hadVol(false), hadArp(false), hadDuty(false), hadWave(false), + hadPitch(false), + hadEx1(false), + hadEx2(false), + hadEx3(false), finishedVol(false), finishedArp(false), finishedDuty(false), finishedWave(false), + finishedPitch(false), + finishedEx1(false), + finishedEx2(false), + finishedEx3(false), willVol(false), willArp(false), willDuty(false), willWave(false), + willPitch(false), + willEx1(false), + willEx2(false), + willEx3(false), arpMode(false) {} };