diff --git a/sources/Application/Instruments/I_Instrument.cpp b/sources/Application/Instruments/I_Instrument.cpp index c2d707f05..9df850ca9 100644 --- a/sources/Application/Instruments/I_Instrument.cpp +++ b/sources/Application/Instruments/I_Instrument.cpp @@ -31,7 +31,7 @@ void I_Instrument::SaveContent(tinyxml2::XMLPrinter *printer) { } // Save all the instrument's parameters - for (auto it = Variables()->begin(); it != Variables()->end(); it++) { + for (auto it = Variables().begin(); it != Variables().end(); it++) { printer->OpenElement("PARAM"); printer->PushAttribute("NAME", (*it)->GetName()); printer->PushAttribute("VALUE", (*it)->GetString().c_str()); @@ -83,7 +83,7 @@ void I_Instrument::RestoreContent(PersistencyDocument *doc) { bool found = false; // Find the variable with this name and set its value - for (auto it = Variables()->begin(); it != Variables()->end(); it++) { + for (auto it = Variables().begin(); it != Variables().end(); it++) { if (!strcasecmp((*it)->GetName(), name)) { (*it)->SetString(value); // Trace::Log("I_INSTRUMENT", "Set parameter: %s = %s", name, @@ -114,7 +114,7 @@ void I_Instrument::RestoreContent(PersistencyDocument *doc) { } void I_Instrument::Purge() { - for (auto it = Variables()->begin(); it != Variables()->end(); it++) { + for (auto it = Variables().begin(); it != Variables().end(); it++) { (*it)->Reset(); } }; diff --git a/sources/Application/Instruments/I_Instrument.h b/sources/Application/Instruments/I_Instrument.h index a4ffcf766..eb66407f8 100644 --- a/sources/Application/Instruments/I_Instrument.h +++ b/sources/Application/Instruments/I_Instrument.h @@ -37,7 +37,7 @@ class I_Instrument : public VariableContainer, etl::string name_; public: - I_Instrument(etl::ilist *list, + I_Instrument(etl::array_view list, const char *nodeName = "INSTRUMENT", bool registerWithPersistence = false) : VariableContainer(list), @@ -113,7 +113,7 @@ class I_Instrument : public VariableContainer, virtual void GetTableState(TableSaveState &state) = 0; virtual void SetTableState(TableSaveState &state) = 0; - virtual etl::ilist *Variables() = 0; + virtual etl::array_view Variables() = 0; // Persistent implementation virtual void SaveContent(tinyxml2::XMLPrinter *printer) override; diff --git a/sources/Application/Instruments/InstrumentBank.cpp b/sources/Application/Instruments/InstrumentBank.cpp index aea614f73..b5f464ab5 100644 --- a/sources/Application/Instruments/InstrumentBank.cpp +++ b/sources/Application/Instruments/InstrumentBank.cpp @@ -252,8 +252,7 @@ unsigned short InstrumentBank::Clone(unsigned short i) { return NO_MORE_INSTRUMENT; } - for (auto it = src->Variables()->begin(); it != src->Variables()->end(); - it++) { + for (auto it = src->Variables().begin(); it != src->Variables().end(); it++) { Variable *dstV = dst->FindVariable((*it)->GetID()); if (dstV) { dstV->CopyFrom(**it); diff --git a/sources/Application/Instruments/MacroInstrument.cpp b/sources/Application/Instruments/MacroInstrument.cpp index a6a3f5d30..ad7aa40f4 100644 --- a/sources/Application/Instruments/MacroInstrument.cpp +++ b/sources/Application/Instruments/MacroInstrument.cpp @@ -21,23 +21,17 @@ #include MacroInstrument::MacroInstrument() - : I_Instrument(&variables_), + : I_Instrument(variables_), shape_(FourCC::MacroInstrumentShape, braids::algo_values, braids::MACRO_OSC_SHAPE_LAST - 2, 0), timbre_(FourCC::MacroInstrmentTimbre, 0x7f), color_(FourCC::MacroInstrumentColor, 0x7f), attack_(FourCC::MacroInstrumentAttack, 0), decay_(FourCC::MacroInstrumentDecay, 0x05), - signature_(FourCC::MacroInstrumentSignature, 0) { + signature_(FourCC::MacroInstrumentSignature, 0), + variables_{&shape_, &timbre_, &color_, &attack_, &decay_, &signature_} { running_ = false; - - variables_.insert(variables_.end(), &shape_); - variables_.insert(variables_.end(), &timbre_); - variables_.insert(variables_.end(), &color_); - variables_.insert(variables_.end(), &attack_); - variables_.insert(variables_.end(), &decay_); - variables_.insert(variables_.end(), &signature_); } MacroInstrument::~MacroInstrument() {} diff --git a/sources/Application/Instruments/MacroInstrument.h b/sources/Application/Instruments/MacroInstrument.h index 204a272b8..4341457e0 100644 --- a/sources/Application/Instruments/MacroInstrument.h +++ b/sources/Application/Instruments/MacroInstrument.h @@ -42,7 +42,7 @@ class MacroInstrument : public I_Instrument, I_Observer { virtual bool GetTableAutomation(); virtual void GetTableState(TableSaveState &state); virtual void SetTableState(TableSaveState &state); - etl::ilist *Variables() { return &variables_; }; + etl::array_view Variables() { return variables_; }; // Engine playback start callback virtual void OnStart(); @@ -52,8 +52,6 @@ class MacroInstrument : public I_Instrument, I_Observer { protected: private: - etl::list variables_; - bool running_; braids::MacroOscillator osc_; @@ -71,6 +69,8 @@ class MacroInstrument : public I_Instrument, I_Observer { Variable decay_; Variable signature_; + etl::array variables_; + uint16_t gain_lp_; uint16_t remain_; }; diff --git a/sources/Application/Instruments/MidiInstrument.cpp b/sources/Application/Instruments/MidiInstrument.cpp index a1e93fd71..6c89fef43 100644 --- a/sources/Application/Instruments/MidiInstrument.cpp +++ b/sources/Application/Instruments/MidiInstrument.cpp @@ -22,12 +22,14 @@ TimerService *MidiInstrument::timerSvc_ = 0; MidiInstrument::NoteOffInfo MidiInstrument::NoteOffInfo::current = {0, 0}; MidiInstrument::MidiInstrument() - : I_Instrument(&variables_), channel_(FourCC::MidiInstrumentChannel, 0), + : I_Instrument(variables_), channel_(FourCC::MidiInstrumentChannel, 0), noteLen_(FourCC::MidiInstrumentNoteLength, 0), volume_(FourCC::MidiInstrumentVolume, 255), table_(FourCC::MidiInstrumentTable, VAR_OFF), tableAuto_(FourCC::MidiInstrumentTableAutomation, false), - program_(FourCC::MidiInstrumentProgram, VAR_OFF) { + program_(FourCC::MidiInstrumentProgram, VAR_OFF), + variables_{&channel_, ¬eLen_, &volume_, + &table_, &tableAuto_, &program_} { if (svc_ == 0) { svc_ = MidiService::GetInstance(); @@ -36,14 +38,6 @@ MidiInstrument::MidiInstrument() if (timerSvc_ == 0) { timerSvc_ = TimerService::GetInstance(); }; - - // name_ is now an etl::string in the base class, not a Variable - variables_.insert(variables_.end(), &channel_); - variables_.insert(variables_.end(), ¬eLen_); - variables_.insert(variables_.end(), &volume_); - variables_.insert(variables_.end(), &table_); - variables_.insert(variables_.end(), &tableAuto_); - variables_.insert(variables_.end(), &program_); } MidiInstrument::~MidiInstrument(){}; diff --git a/sources/Application/Instruments/MidiInstrument.h b/sources/Application/Instruments/MidiInstrument.h index 9b550902a..1d2a26a1f 100644 --- a/sources/Application/Instruments/MidiInstrument.h +++ b/sources/Application/Instruments/MidiInstrument.h @@ -61,7 +61,7 @@ class MidiInstrument : public I_Instrument { virtual bool GetTableAutomation(); virtual void GetTableState(TableSaveState &state); virtual void SetTableState(TableSaveState &state); - etl::ilist *Variables() { return &variables_; }; + etl::array_view Variables() { return variables_; }; void SetChannel(int i); void SendProgramChange(int channel, int program); @@ -78,8 +78,6 @@ class MidiInstrument : public I_Instrument { }; private: - etl::list variables_; - etl::array lastNotes_[SONG_CHANNEL_COUNT]; int remainingTicks_; bool playing_; @@ -102,6 +100,9 @@ class MidiInstrument : public I_Instrument { Variable table_; Variable tableAuto_; Variable program_; + + etl::array variables_; + static MidiService *svc_; static TimerService *timerSvc_; }; diff --git a/sources/Application/Instruments/NoneInstrument.cpp b/sources/Application/Instruments/NoneInstrument.cpp index 46e764055..39920d926 100644 --- a/sources/Application/Instruments/NoneInstrument.cpp +++ b/sources/Application/Instruments/NoneInstrument.cpp @@ -11,7 +11,7 @@ #include "Application/Persistency/PersistenceConstants.h" #include "Externals/etl/include/etl/string.h" -NoneInstrument::NoneInstrument() : I_Instrument(&variables_) {} +NoneInstrument::NoneInstrument() : I_Instrument(variables_) {} NoneInstrument::~NoneInstrument(){}; diff --git a/sources/Application/Instruments/NoneInstrument.h b/sources/Application/Instruments/NoneInstrument.h index 81c8bb205..d05056679 100644 --- a/sources/Application/Instruments/NoneInstrument.h +++ b/sources/Application/Instruments/NoneInstrument.h @@ -45,9 +45,9 @@ class NoneInstrument : public I_Instrument { virtual bool GetTableAutomation(); virtual void GetTableState(TableSaveState &state); virtual void SetTableState(TableSaveState &state); - etl::ilist *Variables() { return &variables_; }; + etl::array_view Variables() { return variables_; }; private: - etl::list variables_; + etl::array variables_{}; }; #endif \ No newline at end of file diff --git a/sources/Application/Instruments/OpalInstrument.cpp b/sources/Application/Instruments/OpalInstrument.cpp index b3eedb56e..c66b93845 100644 --- a/sources/Application/Instruments/OpalInstrument.cpp +++ b/sources/Application/Instruments/OpalInstrument.cpp @@ -32,7 +32,7 @@ static const unsigned int noteFNumbers[] = {342, 363, 385, 408, 432, 458, 485, 514, 544, 577, 611, 647}; OpalInstrument::OpalInstrument() - : I_Instrument(&variables_), + : I_Instrument(variables_), algorithm_(FourCC::OPALInstrumentAlgorithm, algorithms, 6, 0), feedback_(FourCC::OPALInstrumentFeedback, 0), deepTremeloVibrato_(FourCC::OPALInstrumentDeepTremeloVibrato, 0), @@ -49,25 +49,12 @@ OpalInstrument::OpalInstrument() op2WaveShape_(FourCC::OPALInstrumentOp2WaveShape, waveShapes, 8, 0), op2TremVibSusKSR_(FourCC::OPALInstrumentOp2TremVibSusKSR, 0x2), op2KeyScaleLevel_(FourCC::OPALInstrumentOp2KeyScaleLevel, kslValues, 4, - 0) { - - // name_ is now an etl::string in the base class, not a Variable - variables_.insert(variables_.end(), &algorithm_); - variables_.insert(variables_.end(), &feedback_); - variables_.insert(variables_.end(), &deepTremeloVibrato_); - variables_.insert(variables_.end(), &op1Level_); - variables_.insert(variables_.end(), &op1Multiplier_); - variables_.insert(variables_.end(), &op1ADSR_); - variables_.insert(variables_.end(), &op1WaveShape_); - variables_.insert(variables_.end(), &op1KeyScaleLevel_); - variables_.insert(variables_.end(), &op1TremVibSusKSR_); - variables_.insert(variables_.end(), &op2Level_); - variables_.insert(variables_.end(), &op2Multiplier_); - variables_.insert(variables_.end(), &op2ADSR_); - variables_.insert(variables_.end(), &op2WaveShape_); - variables_.insert(variables_.end(), &op2KeyScaleLevel_); - variables_.insert(variables_.end(), &op2TremVibSusKSR_); -} + 0), + variables_{&algorithm_, &feedback_, &deepTremeloVibrato_, + &op1Level_, &op1Multiplier_, &op1ADSR_, + &op1WaveShape_, &op1KeyScaleLevel_, &op1TremVibSusKSR_, + &op2Level_, &op2Multiplier_, &op2ADSR_, + &op2WaveShape_, &op2KeyScaleLevel_, &op2TremVibSusKSR_} {} OpalInstrument::~OpalInstrument(){}; diff --git a/sources/Application/Instruments/OpalInstrument.h b/sources/Application/Instruments/OpalInstrument.h index 7052efaec..01f514e45 100644 --- a/sources/Application/Instruments/OpalInstrument.h +++ b/sources/Application/Instruments/OpalInstrument.h @@ -47,7 +47,7 @@ class OpalInstrument : public I_Instrument { virtual bool GetTableAutomation(); virtual void GetTableState(TableSaveState &state); virtual void SetTableState(TableSaveState &state); - etl::ilist *Variables() { return &variables_; }; + etl::array_view Variables() { return variables_; }; void setChannel(uint8_t channel); @@ -56,8 +56,6 @@ class OpalInstrument : public I_Instrument { uint8_t breg; - etl::list variables_; - Variable algorithm_; Variable feedback_; Variable deepTremeloVibrato_; @@ -76,6 +74,8 @@ class OpalInstrument : public I_Instrument { // Termelo(AM),Vibrato(VIB),SustainingVoice(EG),EnveloperScale(KSR) Variable op2TremVibSusKSR_; Variable op2KeyScaleLevel_; + + etl::array variables_; }; #endif diff --git a/sources/Application/Instruments/SIDInstrument.cpp b/sources/Application/Instruments/SIDInstrument.cpp index 09e1d219a..f899e204f 100644 --- a/sources/Application/Instruments/SIDInstrument.cpp +++ b/sources/Application/Instruments/SIDInstrument.cpp @@ -47,7 +47,7 @@ Variable SIDInstrument::fltmode2_(FourCC::SIDInstrument2FilterMode, Variable SIDInstrument::vol2_(FourCC::SIDInstrument2Volume, 0xF); SIDInstrument::SIDInstrument(SIDInstrumentInstance chip) - : I_Instrument(&variables_), chip_(chip), + : I_Instrument(variables_), chip_(chip), vpw_(FourCC::SIDInstrumentPulseWidth, 0x800), vwf_(FourCC::SIDInstrumentWaveform, sidWaveformText, DWF_LAST, 0x1), vsync_(FourCC::SIDInstrumentVSync, false), @@ -56,28 +56,11 @@ SIDInstrument::SIDInstrument(SIDInstrumentInstance chip) vfon_(FourCC::SIDInstrumentFilterOn, false), table_(FourCC::SIDInstrumentTable, -1), tableAuto_(FourCC::SIDInstrumentTableAutomation, false), - osc_(FourCC::SIDInstrumentOSCNumber, 0) { - - // name_ is now an etl::string in the base class, not a Variable - variables_.insert(variables_.end(), &vpw_); - variables_.insert(variables_.end(), &vwf_); - variables_.insert(variables_.end(), &vsync_); - variables_.insert(variables_.end(), &vring_); - variables_.insert(variables_.end(), &vadsr_); - variables_.insert(variables_.end(), &vfon_); - variables_.insert(variables_.end(), &table_); - variables_.insert(variables_.end(), &tableAuto_); - variables_.insert(variables_.end(), &osc_); - variables_.insert(variables_.end(), &fltcut1_); - variables_.insert(variables_.end(), &fltres1_); - variables_.insert(variables_.end(), &fltmode1_); - variables_.insert(variables_.end(), &vol1_); - - variables_.insert(variables_.end(), &fltcut2_); - variables_.insert(variables_.end(), &fltres2_); - variables_.insert(variables_.end(), &fltmode2_); - variables_.insert(variables_.end(), &vol2_); -} + osc_(FourCC::SIDInstrumentOSCNumber, 0), + variables_{&vpw_, &vwf_, &vsync_, &vring_, &vadsr_, + &vfon_, &table_, &tableAuto_, &osc_, &fltcut1_, + &fltres1_, &fltmode1_, &vol1_, &fltcut2_, &fltres2_, + &fltmode2_, &vol2_} {} SIDInstrument::~SIDInstrument(){}; diff --git a/sources/Application/Instruments/SIDInstrument.h b/sources/Application/Instruments/SIDInstrument.h index 1e6d7f8de..6a6f7d105 100644 --- a/sources/Application/Instruments/SIDInstrument.h +++ b/sources/Application/Instruments/SIDInstrument.h @@ -82,7 +82,7 @@ class SIDInstrument : public I_Instrument { virtual bool GetTableAutomation(); virtual void GetTableState(TableSaveState &state); virtual void SetTableState(TableSaveState &state); - etl::ilist *Variables() { return &variables_; }; + etl::array_view Variables() { return variables_; }; SIDInstrumentInstance GetChip() { return chip_; }; unsigned short GetOsc() { return osc_.GetInt(); }; @@ -92,8 +92,6 @@ class SIDInstrument : public I_Instrument { const char *GetChipName() { return (chip_ == SID1) ? "SID #1" : "SID #2"; }; private: - etl::list variables_; - SIDInstrumentInstance chip_; // SID1 or SID2 bool render_ = false; @@ -122,6 +120,8 @@ class SIDInstrument : public I_Instrument { Variable tableAuto_; Variable osc_; // 0, 1 or 2 + etl::array variables_; + // all these settings are shared by all oscillators on a single SID Chip static Variable fltcut1_; static Variable fltcut2_; diff --git a/sources/Application/Instruments/SampleInstrument.cpp b/sources/Application/Instruments/SampleInstrument.cpp index 78a9fd068..7bb073ec5 100644 --- a/sources/Application/Instruments/SampleInstrument.cpp +++ b/sources/Application/Instruments/SampleInstrument.cpp @@ -42,7 +42,7 @@ signed char SampleInstrument::lastMidiNote_[SONG_CHANNEL_COUNT]; #define KRATE_SAMPLE_COUNT 100 SampleInstrument::SampleInstrument() - : I_Instrument(&variables_), sample_(FourCC::SampleInstrumentSample), + : I_Instrument(variables_), sample_(FourCC::SampleInstrumentSample), volume_(FourCC::SampleInstrumentVolume, 0x80), interpolation_(FourCC::SampleInstrumentInterpolation, interpolationTypes, 2, 0), @@ -61,7 +61,12 @@ SampleInstrument::SampleInstrument() loopStart_(FourCC::SampleInstrumentLoopStart, 0), loopEnd_(FourCC::SampleInstrumentEnd, 0), table_(FourCC::SampleInstrumentTable, -1), - tableAuto_(FourCC::SampleInstrumentTableAutomation, false) { + tableAuto_(FourCC::SampleInstrumentTableAutomation, false), + variables_{&sample_, &volume_, &interpolation_, &crush_, + &drive_, &downsample_, &rootNote_, &fineTune_, + &pan_, &cutoff_, &reso_, &filterMix_, + &filterMode_, &start_, &loopMode_, &loopStart_, + &loopEnd_, &table_, &tableAuto_} { // Initialize MIDI notes for (int i = 0; i < SONG_CHANNEL_COUNT; i++) { @@ -73,33 +78,11 @@ SampleInstrument::SampleInstrument() dirty_ = false; running_ = false; - // Initialize exported variables - // name_ is now an etl::string in the base class, not a Variable - variables_.insert(variables_.end(), &sample_); sample_.AddObserver(*this); - - variables_.insert(variables_.end(), &volume_); - variables_.insert(variables_.end(), &interpolation_); - variables_.insert(variables_.end(), &crush_); - variables_.insert(variables_.end(), &drive_); - variables_.insert(variables_.end(), &downsample_); - variables_.insert(variables_.end(), &rootNote_); - variables_.insert(variables_.end(), &fineTune_); - variables_.insert(variables_.end(), &pan_); - variables_.insert(variables_.end(), &cutoff_); - variables_.insert(variables_.end(), &reso_); - variables_.insert(variables_.end(), &filterMix_); - variables_.insert(variables_.end(), &filterMode_); - variables_.insert(variables_.end(), &start_); start_.AddObserver(*this); - variables_.insert(variables_.end(), &loopMode_); loopMode_.SetInt(0); - variables_.insert(variables_.end(), &loopStart_); loopStart_.AddObserver(*this); - variables_.insert(variables_.end(), &loopEnd_); loopEnd_.AddObserver(*this); - variables_.insert(variables_.end(), &table_); - variables_.insert(variables_.end(), &tableAuto_); tableState_.Reset(); slicePoints_.fill(0); @@ -1540,7 +1523,7 @@ void SampleInstrument::RestoreContent(PersistencyDocument *doc) { setSliceFromString(name.c_str() + 2, value.c_str()); } else { bool found = false; - for (auto it = Variables()->begin(); it != Variables()->end(); it++) { + for (auto it = Variables().begin(); it != Variables().end(); it++) { if (!strcasecmp((*it)->GetName(), name.c_str())) { (*it)->SetString(value.c_str()); found = true; diff --git a/sources/Application/Instruments/SampleInstrument.h b/sources/Application/Instruments/SampleInstrument.h index 10cad916f..876422b88 100644 --- a/sources/Application/Instruments/SampleInstrument.h +++ b/sources/Application/Instruments/SampleInstrument.h @@ -53,7 +53,7 @@ class SampleInstrument : public I_Instrument, I_Observer { virtual bool GetTableAutomation(); virtual void GetTableState(TableSaveState &state); virtual void SetTableState(TableSaveState &state); - etl::ilist *Variables() { return &variables_; }; + etl::array_view Variables() { return variables_; }; bool IsMulti(); @@ -101,8 +101,6 @@ class SampleInstrument : public I_Instrument, I_Observer { void doKRateUpdate(int channel); private: - etl::list variables_; - SoundSource *source_; __attribute__((section(".DTCMRAM"))) static struct renderParams renderParams_[SONG_CHANNEL_COUNT]; @@ -131,6 +129,9 @@ class SampleInstrument : public I_Instrument, I_Observer { WatchedVariable loopEnd_; Variable table_; Variable tableAuto_; + + etl::array variables_; + // TODO (democloid): evaluate if this should be in DTCMRAM etl::array slicePoints_; diff --git a/sources/Application/Model/Config.cpp b/sources/Application/Model/Config.cpp index 51f109a7c..fdb32f16b 100644 --- a/sources/Application/Model/Config.cpp +++ b/sources/Application/Model/Config.cpp @@ -247,7 +247,7 @@ static const ConfigParam configParams[] = { }; Config::Config() - : VariableContainer(&variables_), + : VariableContainer(variables_), background_(FourCC::VarBGColor, static_cast(ThemeConstants::DEFAULT_BACKGROUND)), foreground_(FourCC::VarFGColor, @@ -285,32 +285,15 @@ Config::Config() outputVolume_(FourCC::VarOutputVolume, DEFAULT_OUTPUT_VOLUME), recordSource_(FourCC::VarRecordSource, recordSourceOptions, 4, 1), recordLineGain_(FourCC::VarRecordLineGain, DEFAULT_RECORD_LINE_GAIN_DB), - recordMicGain_(FourCC::VarRecordMicGain, DEFAULT_RECORD_MIC_GAIN_DB) { - - variables_.push_back(&background_); - variables_.push_back(&foreground_); - variables_.push_back(&hiColor1_); - variables_.push_back(&hiColor2_); - variables_.push_back(&consoleColor_); - variables_.push_back(&cursorColor_); - variables_.push_back(&infoColor_); - variables_.push_back(&warnColor_); - variables_.push_back(&errorColor_); - variables_.push_back(&accentColor_); - variables_.push_back(&accentAltColor_); - variables_.push_back(&emphasisColor_); - variables_.push_back(&lineOut_); - variables_.push_back(&midiDevice_); - variables_.push_back(&midiSync_); - variables_.push_back(&remoteUI_); - variables_.push_back(&importResampler_); - variables_.push_back(&uiFont_); - variables_.push_back(&themeName_); - variables_.push_back(&backlightLevel_); - variables_.push_back(&outputVolume_); - variables_.push_back(&recordSource_); - variables_.push_back(&recordLineGain_); - variables_.push_back(&recordMicGain_); + recordMicGain_(FourCC::VarRecordMicGain, DEFAULT_RECORD_MIC_GAIN_DB), + variables_{&background_, &foreground_, &hiColor1_, + &hiColor2_, &consoleColor_, &cursorColor_, + &infoColor_, &warnColor_, &errorColor_, + &accentColor_, &accentAltColor_, &emphasisColor_, + &lineOut_, &midiDevice_, &midiSync_, + &remoteUI_, &importResampler_, &uiFont_, + &themeName_, &backlightLevel_, &outputVolume_, + &recordSource_, &recordLineGain_, &recordMicGain_} { PersistencyDocument doc; diff --git a/sources/Application/Model/Config.h b/sources/Application/Model/Config.h index ae320c24a..d24784b36 100644 --- a/sources/Application/Model/Config.h +++ b/sources/Application/Model/Config.h @@ -36,7 +36,6 @@ class Config : public T_Singleton, public VariableContainer { bool ImportTheme(const char *themeName); private: - etl::list variables_; // Config variables (kept as members to avoid heap allocation) WatchedVariable background_; WatchedVariable foreground_; @@ -63,6 +62,8 @@ class Config : public T_Singleton, public VariableContainer { WatchedVariable recordLineGain_; WatchedVariable recordMicGain_; + etl::array variables_; + void SaveContent(tinyxml2::XMLPrinter *printer); void useDefaultConfig(); }; diff --git a/sources/Application/Model/Project.cpp b/sources/Application/Model/Project.cpp index 8b37f5b2b..b4a414ee1 100644 --- a/sources/Application/Model/Project.cpp +++ b/sources/Application/Model/Project.cpp @@ -35,7 +35,7 @@ #define DATA_UNUSED_VALUE 0xFF Project::Project(const char *name) - : Persistent("PROJECT"), VariableContainer(&variables_), song_(), + : Persistent("PROJECT"), VariableContainer(variables_), song_(), tempoNudge_(0), tempo_(FourCC::VarTempo, DEFAULT_TEMPO), masterVolume_(FourCC::VarMasterVolume, DEFAULT_MASTER_VOLUME), channelVolume1_(FourCC::VarChannel1Volume, DEFAULT_CHANNEL_VOLUME), @@ -50,29 +50,16 @@ Project::Project(const char *name) scale_(FourCC::VarScale, scaleNames, numScales, 0), scaleRoot_(FourCC::VarScaleRoot, noteNames, 12, 0), projectName_(FourCC::VarProjectName, name), - previewVolume_(FourCC::VarPreviewVolume, DEFAULT_PREVIEW_VOLUME) { - - this->variables_.insert(variables_.end(), &tempo_); - this->variables_.insert(variables_.end(), &masterVolume_); - - // Add individual channel volume variables to the container - this->variables_.insert(variables_.end(), &channelVolume1_); - this->variables_.insert(variables_.end(), &channelVolume2_); - this->variables_.insert(variables_.end(), &channelVolume3_); - this->variables_.insert(variables_.end(), &channelVolume4_); - this->variables_.insert(variables_.end(), &channelVolume5_); - this->variables_.insert(variables_.end(), &channelVolume6_); - this->variables_.insert(variables_.end(), &channelVolume7_); - this->variables_.insert(variables_.end(), &channelVolume8_); - - this->variables_.insert(variables_.end(), &wrap_); - this->variables_.insert(variables_.end(), &transpose_); - this->variables_.insert(variables_.end(), &scale_); + previewVolume_(FourCC::VarPreviewVolume, DEFAULT_PREVIEW_VOLUME), + variables_{&tempo_, &masterVolume_, &channelVolume1_, + &channelVolume2_, &channelVolume3_, &channelVolume4_, + &channelVolume5_, &channelVolume6_, &channelVolume7_, + &channelVolume8_, &wrap_, &transpose_, + &scale_, &scaleRoot_, &projectName_, + &previewVolume_} { + scale_.SetInt(0); - this->variables_.insert(variables_.end(), &scaleRoot_); scaleRoot_.SetInt(0); // Default to C (0) - this->variables_.insert(variables_.end(), &projectName_); - this->variables_.insert(variables_.end(), &previewVolume_); // Project name is now managed through the WatchedVariable diff --git a/sources/Application/Model/Project.h b/sources/Application/Model/Project.h index 544fe9f0d..f27a84ef4 100644 --- a/sources/Application/Model/Project.h +++ b/sources/Application/Model/Project.h @@ -67,8 +67,6 @@ class Project : public Persistent, public VariableContainer, I_Observer { virtual void RestoreContent(PersistencyDocument *doc); private: - etl::list variables_; - InstrumentBank instrumentBank_; int tempoNudge_; unsigned long lastTap_[MAX_TAP]; @@ -95,6 +93,8 @@ class Project : public Persistent, public VariableContainer, I_Observer { Variable scaleRoot_; StringWatchedVariable projectName_; Variable previewVolume_; + + etl::array variables_; }; #endif diff --git a/sources/Application/Views/FieldView.h b/sources/Application/Views/FieldView.h index 282e08b7e..04a169617 100644 --- a/sources/Application/Views/FieldView.h +++ b/sources/Application/Views/FieldView.h @@ -11,6 +11,7 @@ #define _FIELD_VIEW_H_ #include "BaseClasses/UIField.h" +#include "Externals/etl/include/etl/list.h" #include "ScreenView.h" class FieldView : public ScreenView { diff --git a/sources/Application/Views/InstrumentView.cpp b/sources/Application/Views/InstrumentView.cpp index c8a9e81e9..556a5bf72 100644 --- a/sources/Application/Views/InstrumentView.cpp +++ b/sources/Application/Views/InstrumentView.cpp @@ -1183,13 +1183,10 @@ bool InstrumentView::checkInstrumentModified() { } // Get the list of variables for this instrument - etl::ilist *variables = instrument->Variables(); - if (!variables) { - return false; - } + auto variables = instrument->Variables(); // Check if any variable has been modified from its default value - for (auto it = variables->begin(); it != variables->end(); ++it) { + for (auto it = variables.begin(); it != variables.end(); ++it) { Variable *var = *it; if (var && var->IsModified()) { return true; @@ -1208,13 +1205,10 @@ void InstrumentView::resetInstrumentToDefaults() { } // Get the list of variables for this instrument - etl::ilist *variables = instrument->Variables(); - if (!variables) { - return; - } + auto variables = instrument->Variables(); // Reset all variables to their default values - for (auto it = variables->begin(); it != variables->end(); ++it) { + for (auto it = variables.begin(); it != variables.end(); ++it) { Variable *var = *it; if (var) { var->Reset(); diff --git a/sources/Foundation/Variables/VariableContainer.cpp b/sources/Foundation/Variables/VariableContainer.cpp index bbdcd8657..3d5b52840 100644 --- a/sources/Foundation/Variables/VariableContainer.cpp +++ b/sources/Foundation/Variables/VariableContainer.cpp @@ -10,29 +10,25 @@ #include "VariableContainer.h" #include -VariableContainer::VariableContainer(etl::ilist *list) +VariableContainer::VariableContainer(etl::array_view list) : list_(list){}; VariableContainer::~VariableContainer(){}; Variable *VariableContainer::FindVariable(FourCC id) { - auto it = list_->begin(); - for (size_t i = 0; i < list_->size(); i++) { - if ((*it)->GetID() == id) { + for (auto it = list_.begin(); it != list_.end(); it++) { + if (*it && (*it)->GetID() == id) { return *it; } - it++; } return NULL; }; Variable *VariableContainer::FindVariable(const char *name) { - auto it = list_->begin(); - for (size_t i = 0; i < list_->size(); i++) { - if (!strcmp((*it)->GetName(), name)) { + for (auto it = list_.begin(); it != list_.end(); it++) { + if (*it && !strcmp((*it)->GetName(), name)) { return *it; } - it++; } return NULL; }; diff --git a/sources/Foundation/Variables/VariableContainer.h b/sources/Foundation/Variables/VariableContainer.h index a5bc04a44..356c63d5b 100644 --- a/sources/Foundation/Variables/VariableContainer.h +++ b/sources/Foundation/Variables/VariableContainer.h @@ -10,17 +10,17 @@ #ifndef _VARIABLE_CONTAINER_H_ #define _VARIABLE_CONTAINER_H_ -#include "Externals/etl/include/etl/list.h" +#include "Externals/etl/include/etl/array_view.h" #include "Variable.h" class VariableContainer { public: - VariableContainer(etl::ilist *list); + VariableContainer(etl::array_view list); virtual ~VariableContainer(); Variable *FindVariable(FourCC id); Variable *FindVariable(const char *name); private: - etl::ilist *list_; + etl::array_view list_; }; #endif