commit cd44afdb066aadaeeddeeb6512dd51bf3303e09e
parent 20bc87380975a317703ae740d72cbbe1daacb577
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Sun, 29 Sep 2024 13:55:36 +0200
load rom cache if available
Diffstat:
2 files changed, 56 insertions(+), 28 deletions(-)
diff --git a/source/xtJucePlugin/weData.cpp b/source/xtJucePlugin/weData.cpp
@@ -2,14 +2,16 @@
#include "xtController.h"
+#include "synthLib/midiToSysex.h"
#include "synthLib/os.h"
#include "xtLib/xtState.h"
namespace xtJucePlugin
{
- WaveEditorData::WaveEditorData(Controller& _controller, std::string _cacheDir) : m_controller(_controller), m_cacheDir(std::move(_cacheDir))
+ WaveEditorData::WaveEditorData(Controller& _controller, const std::string& _cacheDir) : m_controller(_controller), m_cacheDir(synthLib::validatePath(_cacheDir))
{
+ loadRomCache();
}
void WaveEditorData::requestData()
@@ -237,32 +239,7 @@ namespace xtJucePlugin
void WaveEditorData::onAllDataReceived() const
{
- const auto romWaves = synthLib::validatePath(m_cacheDir) + "romWaves.syx";
-
- std::vector<uint8_t> data;
-
- for(uint16_t i=0; i<static_cast<uint16_t>(m_romWaves.size()); ++i)
- {
- auto& romWave = m_romWaves[i];
- assert(romWave);
- if(!romWave)
- continue;
- auto sysex = xt::State::createWaveData(*romWave, i, false);
- data.insert(data.end(), sysex.begin(), sysex.end());
- }
-
- assert(xt::Wave::g_firstRamTableIndex < m_tables.size());
-
- for(uint16_t i=0; i<xt::Wave::g_firstRamTableIndex; ++i)
- {
- auto& table = m_tables[i];
- assert(table || isAlgorithmicTable(xt::TableId(i)));
- if(!table)
- continue;
- auto sysex = xt::State::createTableData(*table, i, false);
- data.insert(data.end(), sysex.begin(), sysex.end());
- }
- synthLib::writeFile(romWaves, data);
+ saveRomCache();
}
xt::SysexCommand WaveEditorData::toCommand(const std::vector<uint8_t>& _sysex)
@@ -326,6 +303,53 @@ namespace xtJucePlugin
}
}
+ std::string WaveEditorData::getRomCacheFilename() const
+ {
+ return m_cacheDir + "romWaves.syx";
+ }
+
+ void WaveEditorData::saveRomCache() const
+ {
+ const auto romWaves = getRomCacheFilename();
+
+ std::vector<uint8_t> data;
+
+ for(uint16_t i=0; i<static_cast<uint16_t>(m_romWaves.size()); ++i)
+ {
+ auto& romWave = m_romWaves[i];
+ assert(romWave);
+ if(!romWave)
+ continue;
+ auto sysex = xt::State::createWaveData(*romWave, i, false);
+ data.insert(data.end(), sysex.begin(), sysex.end());
+ }
+
+ assert(xt::Wave::g_firstRamTableIndex < m_tables.size());
+
+ for(uint16_t i=0; i<xt::Wave::g_firstRamTableIndex; ++i)
+ {
+ auto& table = m_tables[i];
+ assert(table || isAlgorithmicTable(xt::TableId(i)));
+ if(!table)
+ continue;
+ auto sysex = xt::State::createTableData(*table, i, false);
+ data.insert(data.end(), sysex.begin(), sysex.end());
+ }
+ synthLib::writeFile(romWaves, data);
+ }
+
+ void WaveEditorData::loadRomCache()
+ {
+ std::vector<uint8_t> data;
+ if(!synthLib::readFile(data, getRomCacheFilename()))
+ return;
+
+ std::vector<std::vector<uint8_t>> sysexMessages;
+ synthLib::MidiToSysex::splitMultipleSysex(sysexMessages, data);
+ for (const auto& sysex : sysexMessages)
+ parseMidi(sysex);
+ }
+
bool WaveEditorData::isAlgorithmicTable(const xt::TableId _index)
{
for (const uint32_t i : xt::Wave::g_algorithmicWavetables)
diff --git a/source/xtJucePlugin/weData.h b/source/xtJucePlugin/weData.h
@@ -21,7 +21,7 @@ namespace xtJucePlugin
pluginLib::Event<xt::WaveId> onWaveChanged;
pluginLib::Event<xt::TableId> onTableChanged;
- WaveEditorData(Controller& _controller, std::string _cacheDir);
+ WaveEditorData(Controller& _controller, const std::string& _cacheDir);
void requestData();
@@ -62,6 +62,10 @@ namespace xtJucePlugin
static uint16_t toIndex(const std::vector<uint8_t>& _sysex);
bool parseMidi(const std::vector<uint8_t>& _sysex);
+ std::string getRomCacheFilename() const;
+ void saveRomCache() const;
+ void loadRomCache();
+
Controller& m_controller;
const std::string m_cacheDir;