Skip to content

Commit

Permalink
Add Playmode MOno and Legato
Browse files Browse the repository at this point in the history
  • Loading branch information
baconpaul committed Dec 23, 2024
1 parent 0f0254c commit 2240f89
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/clap/six-sines-clap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ struct SixSinesClap : public plugHelper_t, sst::clap_juce_shim::EditorProvider

auto data = std::string(buffer.data());
engine->patch.fromState(data);
engine->doFullRefresh = true;
engine->postLoad();
_host.paramsRequestFlush();
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/synth/patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool Patch::fromState(const std::string &idata)
auto it = paramMap.find(idv);
if (it == paramMap.end())
{
SXSNLOG("Ignoring vestigal param " << idv);
// SXSNLOG("Ignoring vestigal param " << idv);
}
else
{
Expand Down
59 changes: 12 additions & 47 deletions src/synth/patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,65 +470,22 @@ struct Patch
.withGroupName(name(idx))
.withName(name(idx) + " Level")
.withID(id(0, idx))
.withDefault(0)),
targetLevels(sst::cpputils::make_array_lambda<Param, numTargetsPerMacro>(
[this, idx](auto i)
{
return Param(floatMd()
.withGroupName(name(idx))
.withName(name(idx) + " Depth " + std::to_string(i + 1))
.withID(id(i + 2, idx))
.asPercentBipolar()
.withDefault(0));
})),
targets(sst::cpputils::make_array_lambda<Param, numTargetsPerMacro>(
[this, idx](auto i)
{
// expliciltly non-automatable
return Param(md_t()
.asInt()
.withRange(0, std::numeric_limits<uint32_t>::max())
.withGroupName(name(idx))
.withName(name(idx) + " Target " + std::to_string(i + 1))
.withID(id(i + numTargetsPerMacro + 4, idx))
.withDefault(OutputNode::idBase));
})),
// again non-automatable on purpose
midiCC(md_t()
.asInt()
.withRange(0, 127)
.withName(name(idx) + " Midi CC")
.withGroupName(name(idx))
.withID(id(2 * numTargetsPerMacro + 8, idx)))
.withDefault(0))
{
}

std::string name(int idx) const { return "Macro " + std::to_string(idx + 1); }
uint32_t id(int f, int idx) const { return idBase + idStride * idx + f; }

Param level;
std::array<Param, numTargetsPerMacro> targetLevels;
std::array<Param, numTargetsPerMacro> targets;
Param midiCC;

std::vector<Param *> params()
{
std::vector<Param *> res{&level};
for (auto &p : targetLevels)
res.push_back(&p);
for (auto &p : targets)
res.push_back(&p);

res.push_back(&midiCC);
return res;
}
};

struct MIDIRouting
{
static constexpr uint32_t idBase{50000};
};

struct OutputNode : public DAHDSRMixin
{
static constexpr uint32_t idBase{500};
Expand All @@ -544,18 +501,26 @@ struct Patch
.withName(name() + " Velocity Sensitivity")
.withGroupName(name())
.withDefault(0.2)
.withID(id(12)))
.withID(id(12))),
playMode(md_t()
.asInt()
.withRange(0, 2)
.withName(name() + " Play Mode")
.withGroupName(name())
.withDefault(0)
.withID(id(13))
.withUnorderedMapFormatting({{0, "Poly"}, {1, "Mono"}, {2, "Legato"}}))
{
}

std::string name() const { return "Main"; }
uint32_t id(int f) const { return idBase + f; }

Param level, velSensitivity;
Param level, velSensitivity, playMode;

std::vector<Param *> params()
{
std::vector<Param *> res{&level, &velSensitivity};
std::vector<Param *> res{&level, &velSensitivity, &playMode};
appendDAHDSRParams(res);
return res;
}
Expand Down
32 changes: 31 additions & 1 deletion src/synth/synth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ void Synth::processUIQueue(const clap_output_events_t *outq)
case UIToAudioMsg::SET_PARAM:
{
auto dest = patch.paramMap.at(uiM->paramId);
lagHandler.setNewDestination(&(dest->value), uiM->value);
if (dest->meta.type == md_t::FLOAT)
lagHandler.setNewDestination(&(dest->value), uiM->value);
else
dest->value = uiM->value;

clap_event_param_value_t p;
p.header.size = sizeof(clap_event_param_value_t);
Expand All @@ -195,6 +198,14 @@ void Synth::processUIQueue(const clap_output_events_t *outq)
p.value = uiM->value;

outq->try_push(outq, &p.header);

/*
* Some params have other side effects
*/
if (dest->meta.id == patch.output.playMode.meta.id)
{
resetPlaymode();
}
}
break;
case UIToAudioMsg::BEGIN_EDIT:
Expand Down Expand Up @@ -228,6 +239,25 @@ void Synth::processUIQueue(const clap_output_events_t *outq)
}
}

void Synth::resetPlaymode()
{
auto val = (int)std::round(patch.output.playMode.value);
if (val == 1)
{
voiceManager->setPlaymode(0, voiceManager_t::PlayMode::MONO_NOTES,
(int)voiceManager_t::MonoPlayModeFeatures::NATURAL_MONO);
}
else if (val == 2)
{
voiceManager->setPlaymode(0, voiceManager_t::PlayMode::MONO_NOTES,
(int)voiceManager_t::MonoPlayModeFeatures::NATURAL_LEGATO);
}
else
{
voiceManager->setPlaymode(0, voiceManager_t::PlayMode::POLY_VOICES);
}
}

void Synth::handleParamValue(Param *p, uint32_t pid, float value)
{
if (!p)
Expand Down
21 changes: 19 additions & 2 deletions src/synth/synth.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,18 @@ struct Synth
std::function<void(Voice *)> doVoiceEndCallback = [](auto) {};
void setVoiceEndCallback(std::function<void(Voice *)> f) { doVoiceEndCallback = f; }
void retriggerVoiceWithNewNoteID(Voice *, int32_t, float) { assert(false); }
void moveVoice(Voice *, uint16_t, uint16_t, uint16_t, float) { assert(false); }
void moveAndRetriggerVoice(Voice *, uint16_t, uint16_t, uint16_t, float) { assert(false); }
void moveVoice(Voice *v, uint16_t p, uint16_t c, uint16_t k, float ve)
{
v->key = k;
v->velocity = ve;
}
void moveAndRetriggerVoice(Voice *v, uint16_t p, uint16_t c, uint16_t k, float ve)
{
v->key = k;
v->velocity = ve;
v->gated = true;
v->retriggerAllEnvelopes();
}

int32_t beginVoiceCreationTransaction(
typename sst::voicemanager::VoiceBeginBufferEntry<VMConfig>::buffer_t &buffer, uint16_t,
Expand Down Expand Up @@ -197,6 +207,13 @@ struct Synth
sst::basic_blocks::tables::EqualTuningProvider tuningProvider;

void pushFullUIRefresh();
void postLoad()
{
doFullRefresh = true;
resetPlaymode();
}

void resetPlaymode();

sst::basic_blocks::dsp::VUPeak vuPeak;
int32_t updateVuEvery{(int32_t)(gSampleRate / 60 / blockSize)};
Expand Down
21 changes: 21 additions & 0 deletions src/synth/voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,25 @@ static_assert(numOps == 6, "Rebuild this table if not");
OpSource &Voice::sourceAtMatrix(size_t pos) { return src[MatrixIndex::sourceIndexAt(pos)]; }
OpSource &Voice::targetAtMatrix(size_t pos) { return src[MatrixIndex::targetIndexAt(pos)]; }

void Voice::retriggerAllEnvelopes()
{
for (auto &s : src)
if (s.active)
s.envAttack();

for (auto &s : selfNode)
if (s.active)
s.envAttack();

for (auto &s : mixerNode)
if (s.active)
s.envAttack();

for (auto &s : matrixNode)
if (s.active)
s.envAttack();

out.envAttack();
}

} // namespace baconpaul::six_sines
2 changes: 2 additions & 0 deletions src/synth/voice.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ struct Voice
OpSource &sourceAtMatrix(size_t pos);
OpSource &targetAtMatrix(size_t pos);

void retriggerAllEnvelopes();

std::array<MixerNode, numOps> mixerNode;

OutputNode out;
Expand Down
10 changes: 8 additions & 2 deletions src/ui/main-sub-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ MainSubPanel::MainSubPanel(SixSinesEditor &e) : HasEditor(e), DAHDSRComponents()
createComponent(editor, *this, e.patchCopy.output.velSensitivity.meta.id, velSen, velSenD);
addAndMakeVisible(*velSen);
velSenL = std::make_unique<jcmp::Label>();
velSenL->setText("Sens");
velSenL->setText("Vel Sens");
addAndMakeVisible(*velSenL);

velTitle = std::make_unique<RuledLabel>();
velTitle->setText("Vel");
velTitle->setText("Play");
addAndMakeVisible(*velTitle);

createComponent(editor, *this, e.patchCopy.output.playMode.meta.id, playMode, playModeD);
playMode->direction = sst::jucegui::components::MultiSwitch::VERTICAL;
addAndMakeVisible(*playMode);
};
MainSubPanel::~MainSubPanel() {}

Expand All @@ -47,6 +51,8 @@ void MainSubPanel::resized()
depx += xtraW;
depy += uicTitleLabelHeight;
positionKnobAndLabel(depx, depy, velSen, velSenL);
auto bx = velSen->getBounds().translated(0, uicLabeledKnobHeight + uicMargin);
playMode->setBounds(bx);
}

} // namespace baconpaul::six_sines::ui
4 changes: 4 additions & 0 deletions src/ui/main-sub-panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <juce_gui_basics/juce_gui_basics.h>
#include "sst/jucegui/components/Knob.h"
#include "sst/jucegui/components/MultiSwitch.h"
#include "patch-data-bindings.h"
#include "six-sines-editor.h"
#include "dahdsr-components.h"
Expand All @@ -37,6 +38,9 @@ struct MainSubPanel : juce::Component, HasEditor, DAHDSRComponents<MainSubPanel,
std::unique_ptr<PatchContinuous> velSenD;
std::unique_ptr<jcmp::Label> velSenL;

std::unique_ptr<jcmp::MultiSwitch> playMode;
std::unique_ptr<PatchDiscrete> playModeD;

std::unique_ptr<RuledLabel> velTitle;
};
} // namespace baconpaul::six_sines::ui
Expand Down

0 comments on commit 2240f89

Please sign in to comment.