Skip to content

Commit

Permalink
some refactoring of new stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
dantrueman committed Oct 22, 2024
1 parent 5bd9287 commit eb07460
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
18 changes: 9 additions & 9 deletions source/synthesis/framework/Synthesiser/BKSynthesiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,18 @@ void BKSynthesiser::noteOn (const int midiChannel,
stopVoice (voice, 1.0f, true);


for (auto transpOffset : midiNoteOffsets)
for (auto transp : midiNoteTranspositions)
{
// DBG("num noteOn sounds = " + juce::String(sounds->size()));
for (auto* sound : *sounds)
{
//DBG("noteOn velocity = " + juce::String(velocity));
if (sound->appliesToNote (std::round(midiNoteNumber + transpOffset)) && sound->appliesToChannel (midiChannel) && sound->appliesToVelocity (velocity))
if (sound->appliesToNote (std::round(midiNoteNumber + transp)) && sound->appliesToChannel (midiChannel) && sound->appliesToVelocity (velocity))
{
// 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
* moved loop below up out of the transp loop, to avoid voice handling problems with multiple transpositions
*/
/*
for (auto* voice : voices)
Expand All @@ -295,7 +295,7 @@ void BKSynthesiser::noteOn (const int midiChannel,
midiChannel,
midiNoteNumber,
velocity,
transpOffset);
transp);

break;
}
Expand All @@ -308,12 +308,12 @@ void BKSynthesiser::startVoice (BKSamplerVoice* const voice,
const int midiChannel,
const int midiNoteNumber,
const float velocity,
const float tuningOffset)
const float transposition)
{

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(transposition) + " size = " + juce::String(playingVoicesByNote[midiNoteNumber].size()));

//if (voice != nullptr && sound != nullptr)
{
Expand All @@ -329,7 +329,7 @@ void BKSynthesiser::startVoice (BKSamplerVoice* const voice,
voice->setSostenutoPedalDown (false);
voice->setSustainPedalDown (sustainPedalsDown[midiChannel]);

voice->startNote (midiNoteNumber, velocity, tuningOffset, sound,
voice->startNote (midiNoteNumber, velocity, transposition, sound,
lastPitchWheelValues [midiChannel - 1]);


Expand Down Expand Up @@ -371,7 +371,7 @@ void BKSynthesiser::noteOff (const int midiChannel,


/*
for (auto transpOffset : midiNoteOffsets) // need to take into account that this might have changed in the meantime...
for (auto transpOffset : midiNoteTranspositions) // need to take into account that this might have changed in the meantime...
{
//DBG("noteOff for transpOffset " + juce::String(midiNoteNumber) + " " + juce::String(transpOffset));
Expand All @@ -384,7 +384,7 @@ void BKSynthesiser::noteOff (const int midiChannel,
if (auto sound = voice->getCurrentlyPlayingSound())
{
//DBG("noteOff for transpOffset " + juce::String(midiNoteNumber) + " " + juce::String(transpOffset));
//for (auto transpOffset : midiNoteOffsets)
//for (auto transpOffset : midiNoteTranspositions)
{
if (sound->appliesToNote (std::round (midiNoteNumber + transpOffset))
&& sound->appliesToChannel (midiChannel))
Expand Down
8 changes: 4 additions & 4 deletions source/synthesis/framework/Synthesiser/BKSynthesiser.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class BKSynthesiser
}

void updateMidiNoteOffsets(juce::Array<float> newOffsets) {
midiNoteOffsets = newOffsets;
midiNoteTranspositions = newOffsets;
}

juce::ADSR::Parameters globalADSR;
Expand Down Expand Up @@ -358,7 +358,7 @@ class BKSynthesiser
int midiChannel,
int midiNoteNumber,
float velocity,
float tuningOffset);
float transposition);

/** Stops a given voice.
You should never need to call this, it's used internally by noteOff, but is protected
Expand Down Expand Up @@ -386,7 +386,7 @@ class BKSynthesiser
bool sustainPedalAlreadyDown = false; // to avoid re-triggering of pedalDown sounds

/**
* midiNoteOffsets is an arrays of tuning offsets, in MidiNoteCents (.01 = 1 cent)
* midiNoteTranspositions is an arrays of tuning offsets, in MidiNoteCents (.01 = 1 cent)
* - these offsets are set by transposition controls in Direct, Nostalgic, and Synchronic
*
* by default, there is only one offset in each subarray, with value 0., for regular un-transposed notes
Expand All @@ -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.}; // needs to be set via UI
juce::Array<float> midiNoteTranspositions = { 0.}; // needs to be set via UI
juce::HashMap<int, juce::Array<BKSamplerVoice*>> playingVoicesByNote; // Hash of current voices playing for a particular midiNoteNumber

template <typename floatType>
Expand Down
6 changes: 3 additions & 3 deletions source/synthesis/framework/Synthesiser/Sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ class BKSamplerVoice : public BKSynthesiserVoice

virtual void startNote (int midiNoteNumber,
float velocity,
float tuningOffset,
float transposition,
BKSamplerSound<juce::AudioFormatReader> * _sound,
int currentPitchWheelPosition)
{
Expand All @@ -640,10 +640,10 @@ class BKSamplerVoice : public BKSynthesiserVoice
//DBG("gain from velocity = " + juce::String(velocity) + ":" + juce::String(samplerSound->getGainMultiplierFromVelocity(velocity)));

/**
* tuningOffset is from Transposition sliders in Direct/Nostalgic/Synchronic
* transposition is from Transposition sliders in Direct/Nostalgic/Synchronic
* NOT from the Tuning preparation
*/
frequency.setTargetValue(mtof(midiNoteNumber + tuningOffset)); // need to sort out A440 reference freq as well...
frequency.setTargetValue(mtof(midiNoteNumber + transposition)); // need to sort out A440 reference freq as well...
//melatonin::printSparkline(m_Buffer);

auto loopPoints = samplerSound->getLoopPointsInSeconds();
Expand Down

0 comments on commit eb07460

Please sign in to comment.