Skip to content

Commit

Permalink
A few tweaks for MTS support
Browse files Browse the repository at this point in the history
  • Loading branch information
FigBug committed Oct 12, 2024
1 parent c90a502 commit 796228e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ file (GLOB_RECURSE source_files CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/plugin/*.cc
${CMAKE_CURRENT_SOURCE_DIR}/plugin/*.h)

target_sources (${PLUGIN_NAME} PRIVATE ${source_files} ${CMAKE_CURRENT_SOURCE_DIR}/modules/MTS-ESP/Client/libMTSClient.cpp)
target_sources (${PLUGIN_NAME} PRIVATE
${source_files}
${CMAKE_CURRENT_SOURCE_DIR}/modules/MTS-ESP/Client/libMTSClient.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/MTS-ESP/Client/libMTSClient.cpp)
source_group (TREE ${CMAKE_CURRENT_SOURCE_DIR}/plugin PREFIX Source FILES ${source_files})

file (GLOB_RECURSE asset_files CONFIGURE_DEPENDS
Expand Down
8 changes: 8 additions & 0 deletions plugin/Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ WavetableAudioProcessor::WavetableAudioProcessor()
extractProgram (BinaryData::originalFilenames[i], data, sz);
}

mtsClient = MTS_RegisterClient();
enableLegacyMode();
setVoiceStealingEnabled (true);

Expand Down Expand Up @@ -577,6 +578,8 @@ WavetableAudioProcessor::WavetableAudioProcessor()

WavetableAudioProcessor::~WavetableAudioProcessor()
{
MTS_DeregisterClient (mtsClient);
mtsClient = nullptr;
}

void WavetableAudioProcessor::reloadWavetables()
Expand Down Expand Up @@ -844,6 +847,11 @@ void WavetableAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, ju
if (buffer.getNumChannels() != 2)
return;

if (mtsClient)
for (auto itr : midi)
if (auto m = itr.getMessage(); m.isSysEx())
MTS_ParseMIDIDataU (mtsClient, itr.data, itr.numBytes);

if (blockMissed || presetLoaded || lastMono != globalParams.mono->isOn())
{
blockMissed = presetLoaded = false;
Expand Down
2 changes: 2 additions & 0 deletions plugin/Source/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ class WavetableAudioProcessor : public gin::Processor,
juce::CriticalSection dspLock;
juce::Random rng;

MTSClient* mtsClient = nullptr;

private:
bool isParamLocked (gin::Parameter* p) override;
float getSmoothingTime (gin::Parameter*);
Expand Down
12 changes: 5 additions & 7 deletions plugin/Source/WavetableVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ WavetableVoice::WavetableVoice (WavetableAudioProcessor& p)
, sub (proc.analogTables)
{
filter.setNumChannels (2);
mtsClient = MTS_RegisterClient();
}

WavetableVoice::~WavetableVoice()
{
MTS_DeregisterClient (mtsClient);
}

void WavetableVoice::noteStarted()
Expand Down Expand Up @@ -247,17 +245,17 @@ void WavetableVoice::updateParams (int blockSize)

proc.modMatrix.setPolyValue (*this, proc.modSrcNote, note.initialNote / 127.0f);

double retune_semitones = 0.0;
if (mtsClient)
retune_semitones = MTS_RetuningInSemitones (mtsClient, note.initialNote, -1);
double retuneSemitones = 0.0;
if (proc.mtsClient)
retuneSemitones = MTS_RetuningInSemitones (proc.mtsClient, note.initialNote, -1);

for (int i = 0; i < Cfg::numOSCs; i++)
{
if (! proc.oscParams[i].enable->isOn()) continue;

currentMidiNotes[i] = noteSmoother.getCurrentValue() * 127.0f;
if (glideInfo.glissando) currentMidiNotes[i] = (float) juce::roundToInt (currentMidiNotes[i]);
currentMidiNotes[i] += float (retune_semitones);
currentMidiNotes[i] += float (retuneSemitones);
currentMidiNotes[i] += float (note.totalPitchbendInSemitones);
currentMidiNotes[i] += getValue (proc.oscParams[i].tune) + getValue (proc.oscParams[i].finetune) / 100.0f;

Expand All @@ -275,7 +273,7 @@ void WavetableVoice::updateParams (int blockSize)
{
subNote = noteSmoother.getCurrentValue() * 127.0f;
if (glideInfo.glissando) subNote = (float) juce::roundToInt (subNote);
subNote += retune_semitones;
subNote += float (retuneSemitones);
subNote += float (note.totalPitchbendInSemitones);
subNote += getValue (proc.subParams.tune);

Expand Down
4 changes: 1 addition & 3 deletions plugin/Source/WavetableVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,5 @@ class WavetableVoice : public gin::SynthesiserVoice,

gin::EasedValueSmoother<float> noteSmoother;

float ampKeyTrack = 1.0f;

MTSClient* mtsClient = nullptr;
float ampKeyTrack = 1.0f;
};

0 comments on commit 796228e

Please sign in to comment.