Skip to content

Commit

Permalink
fix singles with user waves not correctly applied / request table & w…
Browse files Browse the repository at this point in the history
…ave when a single with user table is received
  • Loading branch information
dsp56300 committed Nov 30, 2024
1 parent 35081aa commit d93e83f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
35 changes: 32 additions & 3 deletions source/xtJucePlugin/xtController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,14 @@ namespace xtJucePlugin

if(m_waveEditor)
{
// send waves first, then table. otherwise the device doesn't refresh correctly
const auto& table = splitResults[1];
m_waveEditor->getData().onReceiveTable(table, true);

for(size_t i=2; i<splitResults.size(); ++i)
{
const auto& wave = splitResults[i];
m_waveEditor->getData().onReceiveWave(wave, true);
}

m_waveEditor->getData().onReceiveTable(table, true);
}

data = single;
Expand Down Expand Up @@ -265,6 +263,20 @@ namespace xtJucePlugin
if(prog + 1 < m_singleEditBuffers.size())
requestSingle(xt::LocationH::SingleEditBufferMultiMode, prog + 1);
}
else
return;

// if the single that was received contains a user table, request it from the device as it might not match what we have in the editor
if (m_waveEditor)
{
const auto tableId = xt::TableId(xt::State::getWavetableFromSingleDump(patch.data));

if (!xt::wave::isReadOnly(tableId))
{
if (requestTable(tableId.rawId()))
m_requestWavesForTables.insert(tableId);
}
}

onProgramChanged(prog);
}
Expand Down Expand Up @@ -381,6 +393,23 @@ namespace xtJucePlugin
{
if(m_waveEditor)
m_waveEditor->onReceiveTable(data, _msg);

const auto tableId = xt::TableId(static_cast<uint16_t>(_msg[xt::SysexIndex::IdxWaveIndexH] << 7 | _msg[xt::SysexIndex::IdxWaveIndexL]));

if (m_requestWavesForTables.find(tableId) != m_requestWavesForTables.end())
{
xt::TableData table;

if (xt::State::parseTableData(table, _msg))
{
for (const auto& wave : table)
{
if (!xt::wave::isReadOnly(wave))
requestWave(wave.rawId());
}
}
m_requestWavesForTables.erase(tableId);
}
}
else
{
Expand Down
4 changes: 3 additions & 1 deletion source/xtJucePlugin/xtController.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#pragma once

#include "jucePluginLib/controller.h"

#include "jucePluginLib/event.h"

#include "xtLib/xtId.h"

namespace xt
{
enum class GlobalParameter;
Expand Down Expand Up @@ -129,5 +130,6 @@ namespace xtJucePlugin
uint32_t m_currentSingle = 0;
xtJucePlugin::FrontPanel* m_frontPanel = nullptr;
xtJucePlugin::WaveEditor* m_waveEditor = nullptr;
std::set<xt::TableId> m_requestWavesForTables;
};
}
27 changes: 17 additions & 10 deletions source/xtLib/xtState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,7 @@ namespace xt

sendSysex(_data);

const auto cmd = getCommand(_data);

switch (cmd)
switch (getCommand(_data))
{
case SysexCommand::WaveDump:
// there is an annoying bug in the XT
Expand Down Expand Up @@ -819,16 +817,18 @@ namespace xt
}

// send the modified table to the device
const auto modifiedTableSysex = createTableData(table, tableId.rawId(), false);
auto modifiedTableSysex = createTableData(table, tableId.rawId(), false);

sendSysex(modifiedTableSysex);
sendSysex(std::move(modifiedTableSysex));

// after 1 second, send the original table again
constexpr auto delaySamples = 40000;
// after a delay, send the original table again
constexpr auto delaySamples = static_cast<uint32_t>(40000 * 0.8f);

m_delayedCalls.emplace_back(delaySamples, [this, w = std::move(originalTableSysex)]
m_delayedCalls.emplace_back(delaySamples, [this, tableId]
{
sendSysex(w);
const auto& t = m_tables[tableId.rawId()];
SysEx s = SysEx(t.begin(), t.end());
sendSysex(std::move(s));
});
}
}
Expand Down Expand Up @@ -867,7 +867,7 @@ namespace xt
checksum += data[i];
data.push_back(checksum & 0x7f);
data.push_back(0xf7);
sendSysex(data);
sendSysex(std::move(data));
}

void State::sendGlobalParameter(GlobalParameter _param, uint8_t _value)
Expand Down Expand Up @@ -903,6 +903,13 @@ namespace xt
m_xt.sendMidiEvent(e);
}

void State::sendSysex(SysEx&& _data) const
{
synthLib::SMidiEvent e(synthLib::MidiEventSource::Internal);
e.sysex = std::move(_data);
m_xt.sendMidiEvent(e);
}

void State::createSequencerMultiData(std::vector<uint8_t>& _data)
{
assert(false);
Expand Down
1 change: 1 addition & 0 deletions source/xtLib/xtState.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ namespace xt
void sendMultiParameter(uint8_t _instrument, MultiParameter _param, uint8_t _value);
void sendSysex(const std::initializer_list<uint8_t>& _data) const;
void sendSysex(const SysEx& _data) const;
void sendSysex(SysEx&& _data) const;

void onPlayModeChanged();

Expand Down

0 comments on commit d93e83f

Please sign in to comment.