get rid of <list>

This commit is contained in:
tildearrow 2022-04-10 18:07:30 -05:00
parent 09dec38407
commit 4ae13c15e6
2 changed files with 63 additions and 73 deletions

View file

@ -21,7 +21,9 @@
#include "instrument.h" #include "instrument.h"
void DivMacroStruct::doMacro(DivInstrumentMacro& source, bool released) { void DivMacroStruct::doMacro(DivInstrumentMacro& source, bool released) {
if (finished) finished=false; if (finished) {
finished=false;
}
if (had!=has) { if (had!=has) {
finished=true; finished=true;
} }
@ -49,9 +51,9 @@ void DivMacroInt::next() {
if (ins==NULL) return; if (ins==NULL) return;
// run macros // run macros
// TODO: potentially get rid of list to avoid allocations // TODO: potentially get rid of list to avoid allocations
if (!macroList.empty()) { for (size_t i=0; i<macroListLen; i++) {
for (std::list<DivMacroExecList>::iterator iter = macroList.begin(); iter!= macroList.end(); iter++) { if (macroList[i]!=NULL && macroSource[i]!=NULL) {
iter->doMacro(released); macroList[i]->doMacro(*macroSource[i],released);
} }
} }
} }
@ -60,14 +62,17 @@ void DivMacroInt::release() {
released=true; released=true;
} }
#define ADD_MACRO(m,s) \
macroList[macroListLen]=&m; \
macroSource[macroListLen++]=&s;
void DivMacroInt::init(DivInstrument* which) { void DivMacroInt::init(DivInstrument* which) {
ins=which; ins=which;
// initialize // initialize
// TODO: potentially get rid of list to avoid allocations for (size_t i=0; i<macroListLen; i++) {
while (!macroList.empty()) { if (macroList[i]!=NULL) macroList[i]->init();
macroList.front().init();
macroList.pop_front();
} }
macroListLen=0;
released=false; released=false;
@ -75,65 +80,65 @@ void DivMacroInt::init(DivInstrument* which) {
// prepare common macro // prepare common macro
if (ins->std.volMacro.len>0) { if (ins->std.volMacro.len>0) {
macroList.push_back(DivMacroExecList(vol,ins->std.volMacro)); ADD_MACRO(vol,ins->std.volMacro);
} }
if (ins->std.arpMacro.len>0) { if (ins->std.arpMacro.len>0) {
macroList.push_back(DivMacroExecList(arp,ins->std.arpMacro)); ADD_MACRO(arp,ins->std.arpMacro);
} }
if (ins->std.dutyMacro.len>0) { if (ins->std.dutyMacro.len>0) {
macroList.push_back(DivMacroExecList(duty,ins->std.dutyMacro)); ADD_MACRO(duty,ins->std.dutyMacro);
} }
if (ins->std.waveMacro.len>0) { if (ins->std.waveMacro.len>0) {
macroList.push_back(DivMacroExecList(wave,ins->std.waveMacro)); ADD_MACRO(wave,ins->std.waveMacro);
} }
if (ins->std.pitchMacro.len>0) { if (ins->std.pitchMacro.len>0) {
macroList.push_back(DivMacroExecList(pitch,ins->std.pitchMacro)); ADD_MACRO(pitch,ins->std.pitchMacro);
} }
if (ins->std.ex1Macro.len>0) { if (ins->std.ex1Macro.len>0) {
macroList.push_back(DivMacroExecList(ex1,ins->std.ex1Macro)); ADD_MACRO(ex1,ins->std.ex1Macro);
} }
if (ins->std.ex2Macro.len>0) { if (ins->std.ex2Macro.len>0) {
macroList.push_back(DivMacroExecList(ex2,ins->std.ex2Macro)); ADD_MACRO(ex2,ins->std.ex2Macro);
} }
if (ins->std.ex3Macro.len>0) { if (ins->std.ex3Macro.len>0) {
macroList.push_back(DivMacroExecList(ex3,ins->std.ex3Macro)); ADD_MACRO(ex3,ins->std.ex3Macro);
} }
if (ins->std.algMacro.len>0) { if (ins->std.algMacro.len>0) {
macroList.push_back(DivMacroExecList(alg,ins->std.algMacro)); ADD_MACRO(alg,ins->std.algMacro);
} }
if (ins->std.fbMacro.len>0) { if (ins->std.fbMacro.len>0) {
macroList.push_back(DivMacroExecList(fb,ins->std.fbMacro)); ADD_MACRO(fb,ins->std.fbMacro);
} }
if (ins->std.fmsMacro.len>0) { if (ins->std.fmsMacro.len>0) {
macroList.push_back(DivMacroExecList(fms,ins->std.fmsMacro)); ADD_MACRO(fms,ins->std.fmsMacro);
} }
if (ins->std.amsMacro.len>0) { if (ins->std.amsMacro.len>0) {
macroList.push_back(DivMacroExecList(ams,ins->std.amsMacro)); ADD_MACRO(ams,ins->std.amsMacro);
} }
if (ins->std.panLMacro.len>0) { if (ins->std.panLMacro.len>0) {
macroList.push_back(DivMacroExecList(panL,ins->std.panLMacro)); ADD_MACRO(panL,ins->std.panLMacro);
} }
if (ins->std.panRMacro.len>0) { if (ins->std.panRMacro.len>0) {
macroList.push_back(DivMacroExecList(panR,ins->std.panRMacro)); ADD_MACRO(panR,ins->std.panRMacro);
} }
if (ins->std.phaseResetMacro.len>0) { if (ins->std.phaseResetMacro.len>0) {
macroList.push_back(DivMacroExecList(phaseReset,ins->std.phaseResetMacro)); ADD_MACRO(phaseReset,ins->std.phaseResetMacro);
} }
if (ins->std.ex4Macro.len>0) { if (ins->std.ex4Macro.len>0) {
macroList.push_back(DivMacroExecList(ex4,ins->std.ex4Macro)); ADD_MACRO(ex4,ins->std.ex4Macro);
} }
if (ins->std.ex5Macro.len>0) { if (ins->std.ex5Macro.len>0) {
macroList.push_back(DivMacroExecList(ex5,ins->std.ex5Macro)); ADD_MACRO(ex5,ins->std.ex5Macro);
} }
if (ins->std.ex6Macro.len>0) { if (ins->std.ex6Macro.len>0) {
macroList.push_back(DivMacroExecList(ex6,ins->std.ex6Macro)); ADD_MACRO(ex6,ins->std.ex6Macro);
} }
if (ins->std.ex7Macro.len>0) { if (ins->std.ex7Macro.len>0) {
macroList.push_back(DivMacroExecList(ex7,ins->std.ex7Macro)); ADD_MACRO(ex7,ins->std.ex7Macro);
} }
if (ins->std.ex8Macro.len>0) { if (ins->std.ex8Macro.len>0) {
macroList.push_back(DivMacroExecList(ex8,ins->std.ex8Macro)); ADD_MACRO(ex8,ins->std.ex8Macro);
} }
// prepare FM operator macros // prepare FM operator macros
@ -141,72 +146,70 @@ void DivMacroInt::init(DivInstrument* which) {
DivInstrumentSTD::OpMacro& m=ins->std.opMacros[i]; DivInstrumentSTD::OpMacro& m=ins->std.opMacros[i];
IntOp& o=op[i]; IntOp& o=op[i];
if (m.amMacro.len>0) { if (m.amMacro.len>0) {
macroList.push_back(DivMacroExecList(o.am,m.amMacro)); ADD_MACRO(o.am,m.amMacro);
} }
if (m.arMacro.len>0) { if (m.arMacro.len>0) {
macroList.push_back(DivMacroExecList(o.ar,m.arMacro)); ADD_MACRO(o.ar,m.arMacro);
} }
if (m.drMacro.len>0) { if (m.drMacro.len>0) {
macroList.push_back(DivMacroExecList(o.dr,m.drMacro)); ADD_MACRO(o.dr,m.drMacro);
} }
if (m.multMacro.len>0) { if (m.multMacro.len>0) {
macroList.push_back(DivMacroExecList(o.mult,m.multMacro)); ADD_MACRO(o.mult,m.multMacro);
} }
if (m.rrMacro.len>0) { if (m.rrMacro.len>0) {
macroList.push_back(DivMacroExecList(o.rr,m.rrMacro)); ADD_MACRO(o.rr,m.rrMacro);
} }
if (m.slMacro.len>0) { if (m.slMacro.len>0) {
macroList.push_back(DivMacroExecList(o.sl,m.slMacro)); ADD_MACRO(o.sl,m.slMacro);
} }
if (m.tlMacro.len>0) { if (m.tlMacro.len>0) {
macroList.push_back(DivMacroExecList(o.tl,m.tlMacro)); ADD_MACRO(o.tl,m.tlMacro);
} }
if (m.dt2Macro.len>0) { if (m.dt2Macro.len>0) {
macroList.push_back(DivMacroExecList(o.dt2,m.dt2Macro)); ADD_MACRO(o.dt2,m.dt2Macro);
} }
if (m.rsMacro.len>0) { if (m.rsMacro.len>0) {
macroList.push_back(DivMacroExecList(o.rs,m.rsMacro)); ADD_MACRO(o.rs,m.rsMacro);
} }
if (m.dtMacro.len>0) { if (m.dtMacro.len>0) {
macroList.push_back(DivMacroExecList(o.dt,m.dtMacro)); ADD_MACRO(o.dt,m.dtMacro);
} }
if (m.d2rMacro.len>0) { if (m.d2rMacro.len>0) {
macroList.push_back(DivMacroExecList(o.d2r,m.d2rMacro)); ADD_MACRO(o.d2r,m.d2rMacro);
} }
if (m.ssgMacro.len>0) { if (m.ssgMacro.len>0) {
macroList.push_back(DivMacroExecList(o.ssg,m.ssgMacro)); ADD_MACRO(o.ssg,m.ssgMacro);
} }
if (m.damMacro.len>0) { if (m.damMacro.len>0) {
macroList.push_back(DivMacroExecList(o.dam,m.damMacro)); ADD_MACRO(o.dam,m.damMacro);
} }
if (m.dvbMacro.len>0) { if (m.dvbMacro.len>0) {
macroList.push_back(DivMacroExecList(o.dvb,m.dvbMacro)); ADD_MACRO(o.dvb,m.dvbMacro);
} }
if (m.egtMacro.len>0) { if (m.egtMacro.len>0) {
macroList.push_back(DivMacroExecList(o.egt,m.egtMacro)); ADD_MACRO(o.egt,m.egtMacro);
} }
if (m.kslMacro.len>0) { if (m.kslMacro.len>0) {
macroList.push_back(DivMacroExecList(o.ksl,m.kslMacro)); ADD_MACRO(o.ksl,m.kslMacro);
} }
if (m.susMacro.len>0) { if (m.susMacro.len>0) {
macroList.push_back(DivMacroExecList(o.sus,m.susMacro)); ADD_MACRO(o.sus,m.susMacro);
} }
if (m.vibMacro.len>0) { if (m.vibMacro.len>0) {
macroList.push_back(DivMacroExecList(o.vib,m.vibMacro)); ADD_MACRO(o.vib,m.vibMacro);
} }
if (m.wsMacro.len>0) { if (m.wsMacro.len>0) {
macroList.push_back(DivMacroExecList(o.ws,m.wsMacro)); ADD_MACRO(o.ws,m.wsMacro);
} }
if (m.ksrMacro.len>0) { if (m.ksrMacro.len>0) {
macroList.push_back(DivMacroExecList(o.ksr,m.ksrMacro)); ADD_MACRO(o.ksr,m.ksrMacro);
} }
} }
if (!macroList.empty()) { for (size_t i=0; i<macroListLen; i++) {
for (std::list<DivMacroExecList>::iterator iter = macroList.begin(); iter!= macroList.end(); iter++) { macroList[i]->prepare(*macroSource[i]);
iter->prepare();
}
} }
} }

View file

@ -21,7 +21,6 @@
#define _MACROINT_H #define _MACROINT_H
#include "instrument.h" #include "instrument.h"
#include <list>
struct DivMacroStruct { struct DivMacroStruct {
int pos; int pos;
@ -47,26 +46,11 @@ struct DivMacroStruct {
mode(0) {} mode(0) {}
}; };
struct DivMacroExecList {
DivMacroStruct& macro;
DivInstrumentMacro& source;
void init() {
macro.init();
}
void prepare() {
macro.prepare(source);
}
void doMacro(bool released) {
macro.doMacro(source, released);
}
DivMacroExecList(DivMacroStruct& m, DivInstrumentMacro& s):
macro(m),
source(s) {}
};
class DivMacroInt { class DivMacroInt {
DivInstrument* ins; DivInstrument* ins;
std::list<DivMacroExecList> macroList; DivMacroStruct* macroList[128];
DivInstrumentMacro* macroSource[128];
size_t macroListLen;
bool released; bool released;
public: public:
// common macro // common macro
@ -130,7 +114,7 @@ class DivMacroInt {
DivMacroInt(): DivMacroInt():
ins(NULL), ins(NULL),
macroList(), macroListLen(0),
released(false), released(false),
vol(), vol(),
arp(), arp(),
@ -151,7 +135,10 @@ class DivMacroInt {
ex5(), ex5(),
ex6(), ex6(),
ex7(), ex7(),
ex8() {} ex8() {
memset(macroList,0,128*sizeof(void*));
memset(macroSource,0,128*sizeof(void*));
}
}; };
#endif #endif