Skip to content

Commit

Permalink
Porta-Gliss in MIDI and MTS mode hits scale notes
Browse files Browse the repository at this point in the history
Previously it hit the internal 12TET notes

Closes surge-synthesizer#5483
  • Loading branch information
baconpaul committed Nov 25, 2021
1 parent d2d6e5d commit d148991
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
66 changes: 56 additions & 10 deletions src/common/dsp/SurgeVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,7 @@ void SurgeVoice::legato(int key, int velocity, char detune)

state.porta_doretrigger = false;
if (scene->portamento.porta_retrigger)
if (floor(state.pkey + 0.5) != state.priorpkey)
{
state.priorpkey = floor(state.pkey + 0.5);
state.porta_doretrigger = true;
}
retriggerPortaIfKeyChanged();
}

state.key = key;
Expand All @@ -359,6 +355,60 @@ void SurgeVoice::legato(int key, int velocity, char detune)
state.fvel = velocity/127.f;*/
}

void SurgeVoice::retriggerPortaIfKeyChanged()
{
if (!storage->oddsound_mts_active &&
(storage->isStandardTuning || storage->tuningApplicationMode == SurgeStorage::RETUNE_ALL))
{
if (floor(state.pkey + 0.5) != state.priorpkey)
{
state.priorpkey = floor(state.pkey + 0.5);
state.porta_doretrigger = true;
}
}
else
{
std::function<float(int)> v4k = [this](int k) {
return storage->currentTuning.logScaledFrequencyForMidiNote(k) * 12;
};

if (storage->oddsound_mts_client && storage->oddsound_mts_active)
{
v4k = [this](int k) {
return log2f(MTS_NoteToFrequency(storage->oddsound_mts_client, k, state.channel) /
Tunings::MIDI_0_FREQ) *
12;
};
}

auto ckey = state.pkey;
auto start = state.priorpkey - 2;
auto prior = v4k(start);
while (prior > ckey && start > -250)
{
start -= 10;
prior = v4k(start);
}
for (int i = start; i < 256; ++i)
{
auto next = v4k(i);
if (next > state.pkey && prior <= state.pkey)
{
auto frac = (state.pkey - prior) / (next - prior);
ckey = i + frac;
break;
}
prior = next;
}

if (floor(ckey + 0.5) != state.priorpkey)
{
state.priorpkey = floor(ckey + 0.5);
state.porta_doretrigger = true;
}
}
}

void SurgeVoice::switch_toggled()
{
update_portamento();
Expand Down Expand Up @@ -551,11 +601,7 @@ void SurgeVoice::update_portamento()

state.porta_doretrigger = false;
if (scene->portamento.porta_retrigger)
if (floor(state.pkey + 0.5) != state.priorpkey)
{
state.priorpkey = floor(state.pkey + 0.5);
state.porta_doretrigger = true;
}
retriggerPortaIfKeyChanged();
}
else
state.pkey = state.getPitch(storage);
Expand Down
1 change: 1 addition & 0 deletions src/common/dsp/SurgeVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class alignas(16) SurgeVoice
void set_path(bool osc1, bool osc2, bool osc3, int FMmode, bool ring12, bool ring23,
bool noise);
int routefilter(int);
void retriggerPortaIfKeyChanged();

LFOModulationSource lfo[6];

Expand Down

0 comments on commit d148991

Please sign in to comment.