Skip to content

Commit

Permalink
more voice handling stuff for Transpositions in BKSynthesizer. Seems …
Browse files Browse the repository at this point in the history
…to work at the moment
  • Loading branch information
dantrueman committed Oct 22, 2024
1 parent 26f2b23 commit 6a3a290
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
27 changes: 23 additions & 4 deletions source/synthesis/framework/Synthesiser/BKSynthesiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,17 @@ void BKSynthesiser::noteOn (const int midiChannel,
{
const juce::ScopedLock sl (lock);

/**
* moved this out of the loop below because it was messing up voice handling with multiple transpositions
* however, this move might break something else in the future, we'll have to see..
*/
// If hitting a note that's still ringing, stop it first (it could be
// still playing because of the sustain or sostenuto pedal).
for (auto* voice : voices)
if (voice->getCurrentlyPlayingNote() == midiNoteNumber && voice->isPlayingChannel (midiChannel))
stopVoice (voice, 1.0f, true);


for (auto transpOffset : midiNoteOffsets)
{
// DBG("num noteOn sounds = " + juce::String(sounds->size()));
Expand All @@ -270,16 +281,22 @@ void BKSynthesiser::noteOn (const int midiChannel,
{
// If hitting a note that's still ringing, stop it first (it could be
// still playing because of the sustain or sostenuto pedal).
/**
* moved loop below up out of the transpOffset loop, to avoid voice handling problems with multiple transpositions
*/
/*
for (auto* voice : voices)
if (voice->getCurrentlyPlayingNote() == midiNoteNumber && voice->isPlayingChannel (midiChannel))
stopVoice (voice, 1.0f, true);
*/

startVoice (findFreeVoice (sound, midiChannel, midiNoteNumber, shouldStealNotes),
sound,
midiChannel,
midiNoteNumber,
velocity,
transpOffset);

break;
}
}
Expand All @@ -296,7 +313,7 @@ void BKSynthesiser::startVoice (BKSamplerVoice* const voice,

playingVoicesByNote.getReference(midiNoteNumber).addIfNotAlreadyThere(voice);
//playingVoicesByNote[midiNoteNumber].addIfNotAlreadyThere(voice);
DBG("playingVoicesByNote[midiNoteNumber] adding = " + juce::String(midiNoteNumber) + " " + juce::String(tuningOffset) + " size = " + juce::String(playingVoicesByNote[midiNoteNumber].size()));
//DBG("playingVoicesByNote[midiNoteNumber] adding = " + juce::String(midiNoteNumber) + " " + juce::String(tuningOffset) + " size = " + juce::String(playingVoicesByNote[midiNoteNumber].size()));

//if (voice != nullptr && sound != nullptr)
{
Expand Down Expand Up @@ -337,8 +354,8 @@ void BKSynthesiser::noteOff (const int midiChannel,
{
const juce::ScopedLock sl (lock);

/*
DBG("playingVoicesByNote[midiNoteNumber] size = " + juce::String(midiNoteNumber) + " " + juce::String(playingVoicesByNote[midiNoteNumber].size()));

//DBG("playingVoicesByNote[midiNoteNumber] size = " + juce::String(midiNoteNumber) + " " + juce::String(playingVoicesByNote[midiNoteNumber].size()));
for (auto* voice : playingVoicesByNote[midiNoteNumber])
{
voice->setKeyDown (false);
Expand All @@ -351,7 +368,7 @@ void BKSynthesiser::noteOff (const int midiChannel,
}
}
playingVoicesByNote[midiNoteNumber].clear();
*/


/*
for (auto transpOffset : midiNoteOffsets) // need to take into account that this might have changed in the meantime...
Expand Down Expand Up @@ -391,6 +408,7 @@ void BKSynthesiser::noteOff (const int midiChannel,
} */


/* orig
for (auto* voice : voices)
{
if (voice->getCurrentlyPlayingNote() == midiNoteNumber
Expand All @@ -413,6 +431,7 @@ void BKSynthesiser::noteOff (const int midiChannel,
}
}
}
*/
}

void BKSynthesiser::allNotesOff (const int midiChannel, const bool allowTailOff)
Expand Down
2 changes: 1 addition & 1 deletion source/synthesis/framework/Synthesiser/BKSynthesiser.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ class BKSynthesiser
*
* the "un-transposed" midiNoteNumber is the midi note played by the performer, and used for voice tracking
*/
juce::Array<float> midiNoteOffsets = { 0.};
juce::Array<float> midiNoteOffsets = { 0., 6, 15};
juce::HashMap<int, juce::Array<BKSamplerVoice*>> playingVoicesByNote; // Hash of current voices playing for a particular midiNoteNumber

template <typename floatType>
Expand Down

0 comments on commit 6a3a290

Please sign in to comment.