Skip to content

Commit

Permalink
Add a keytrack modulator to MIDI modulation section of voice (#1337)
Browse files Browse the repository at this point in the history
which reports tunedkey - rootkey / 12 as a float value

Closes #1251
  • Loading branch information
baconpaul authored Sep 17, 2024
1 parent c2f42bf commit 33e0017
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/modulation/voice_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ void MatrixEndpoints::Sources::bind(scxt::voice::modulation::Matrix &m, engine::
m.bindSourceValue(midiSources.modWheelSource,
z.parentGroup->parentPart->midiCCSmoothers[1].output);
m.bindSourceValue(midiSources.velocitySource, v.velocity);
m.bindSourceValue(midiSources.keytrackSource, v.keytrackPerOct);

for (int i = 0; i < scxt::numTransportPhasors; ++i)
{
Expand Down
6 changes: 4 additions & 2 deletions src/modulation/voice_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,14 @@ struct MatrixEndpoints
struct MIDISources
{
MIDISources(engine::Engine *e)
: modWheelSource{'zmid', 'modw'}, velocitySource{'zmid', 'velo'}
: modWheelSource{'zmid', 'modw'}, velocitySource{'zmid', 'velo'},
keytrackSource{'zmid', 'ktrk'}
{
registerVoiceModSource(e, modWheelSource, "MIDI", "Mod Wheel");
registerVoiceModSource(e, velocitySource, "MIDI", "Velocity");
registerVoiceModSource(e, keytrackSource, "MIDI", "KeyTrack");
}
SR modWheelSource, velocitySource;
SR modWheelSource, velocitySource, keytrackSource;
} midiSources;

TransportSourceBase<SR, 'ztsp', true, registerVoiceModSource> transportSources;
Expand Down
7 changes: 6 additions & 1 deletion src/voice/voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,12 @@ float Voice::calculateVoicePitch()
auto pitchMv = pitchWheel > 0 ? zone->mapping.pbUp : zone->mapping.pbDown;
fpitch += pitchWheel * pitchMv;

fpitch += zone->getEngine()->midikeyRetuner.retuneRemappedKey(channel, key, originalMidiKey);
auto retuner =
zone->getEngine()->midikeyRetuner.retuneRemappedKey(channel, key, originalMidiKey);

fpitch += retuner;

keytrackPerOct = (key + retuner - zone->mapping.rootKey) / 12.0;

return fpitch;
}
Expand Down
1 change: 1 addition & 0 deletions src/voice/voice.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ struct alignas(16) Voice : MoveableOnly<Voice>,
60}; // the actual physical key pressed not the one I resolved to after tuning
float velocity{1.f};
float velKeyFade{1.f};
float keytrackPerOct{0.f}; // resolvee key - pitch cnter / 12

scxt::voice::modulation::Matrix modMatrix;
std::unique_ptr<modulation::MatrixEndpoints> endpoints;
Expand Down

0 comments on commit 33e0017

Please sign in to comment.