From 8bf9abb2b8b1b10160e87f1925219402df9ae16e Mon Sep 17 00:00:00 2001 From: z3phyr2 <354930554+z3phyr2@users.noreply.github.com> Date: Sun, 22 Nov 2026 22:01:56 +0100 Subject: [PATCH 1/2] feat: add MIDI glide for instrument & synth tracks The Glide FX (G) now also affects MIDI instrument tracks M01-M16 and synth tracks S1-S3. New config option Config > MIDI > "MIDI Glide": - Off (default): no behavior change - Legato: defer the previous note-off until after the new note-on, so synths with portamento trigger their native glide - Bend: emulate the glide with a linear pitch-bend ramp sent before the note-on; RPN 0,0 widens the bend range to the interval when needed (MIDI tracks only); the ramp starts from the current bend value to avoid a jump when the previous ramp is unfinished - Both: legato reordering + pitch-bend ramp Glide only applies when the previous note on the same channel is still held, G=0 keeps the original behavior, chords are excluded. Sample tracks are unaffected; the sample glide time mapping is now shared with the MIDI path via glideFxValueToMs(). --- core/AudioEngine/mtAudioSequencer.cpp | 12 +- core/interface/configEditor/configMenu.cpp | 6 + core/interface/configEditor/configMenuDefs.h | 7 + core/source/mtConfig.cpp | 6 + core/source/mtSequencer.cpp | 261 ++++++++++++++++++- core/source/mtSequencer.h | 14 + core/source/mtStructs.h | 30 +++ 7 files changed, 318 insertions(+), 18 deletions(-) diff --git a/core/AudioEngine/mtAudioSequencer.cpp b/core/AudioEngine/mtAudioSequencer.cpp index 37af98090..a215d81ae 100644 --- a/core/AudioEngine/mtAudioSequencer.cpp +++ b/core/AudioEngine/mtAudioSequencer.cpp @@ -200,25 +200,17 @@ void playerEngine::fxGlide(uint8_t fx_val, uint8_t fx_n) uint8_t otherFx_n = !fx_n; uint8_t maxFxGlide = sequencer.getFxMax(Sequencer::strFxConsts::FX_TYPE_GLIDE); - uint8_t minFxGlide = sequencer.getFxMin(Sequencer::strFxConsts::FX_TYPE_GLIDE); - uint8_t halfFxGlide = maxFxGlide / 2; if (fx_n == MOST_SIGNIFICANT_FX) { - currentSeqModValues.glide = - (fx_val > halfFxGlide) - ? mapClamped(fx_val, halfFxGlide, maxFxGlide, 1000, GLIDE_MAX) - : mapClamped(fx_val, minFxGlide, halfFxGlide, GLIDE_MIN, 1000); + currentSeqModValues.glide = glideFxValueToMs(fx_val, maxFxGlide); } else if (fx_n == LEAST_SIGNIFICANT_FX) { if (!trackControlParameter[(int)controlType::sequencerMode + otherFx_n] [(int)parameterList::glide]) { - currentSeqModValues.glide = - (fx_val > halfFxGlide) - ? mapClamped(fx_val, halfFxGlide, maxFxGlide, 1000, GLIDE_MAX) - : mapClamped(fx_val, minFxGlide, halfFxGlide, GLIDE_MIN, 1000); + currentSeqModValues.glide = glideFxValueToMs(fx_val, maxFxGlide); } } trackControlParameter[(int)controlType::sequencerMode + fx_n][(int)parameterList::glide] = 1; diff --git a/core/interface/configEditor/configMenu.cpp b/core/interface/configEditor/configMenu.cpp index 30c5a6410..a26add1ff 100644 --- a/core/interface/configEditor/configMenu.cpp +++ b/core/interface/configEditor/configMenu.cpp @@ -204,6 +204,7 @@ const strItemTypeListText programChangeInChannelSetup{ &mtConfig.midi.programCha 17, notesChannel }; const strItemTypeListText middleCSetup{ &mtConfig.midi.middleC, 4, middleC }; +const strItemTypeListText midiGlideModeSetup{ &mtConfig.midi.glideMode, 4, midiGlideMode }; const strItemTypeListTextWithAction slaveClockCompSetup{ &mtConfig.midi.slaveClockComp, std::size(slaveClockComp), slaveClockComp, setSlaveClockCompValue }; cMenuItem melClockIn(menuMidi, "Clock in", nullptr, menuTypeItemListText, &clockInSetup); @@ -225,6 +226,11 @@ cMenuItem melNotesInChannel(menuMidi, menuTypeItemListText, ¬esInChanneletup); cMenuItem melNotsOutMode(menuMidi, "MIDI out", nullptr, menuTypeItemListText, ¬esOutModeSetup); +cMenuItem melMidiGlideMode(menuMidi, + "MIDI Glide", + nullptr, + menuTypeItemListText, + &midiGlideModeSetup); cMenuItem melCCInMode(menuMidi, "CC in", supportedCcInDesc, menuTypeItemListText, &ccInModeSetup); cMenuItem melCCInChannel(menuMidi, "CC in channel", diff --git a/core/interface/configEditor/configMenuDefs.h b/core/interface/configEditor/configMenuDefs.h index a16c98efa..3aa81588d 100644 --- a/core/interface/configEditor/configMenuDefs.h +++ b/core/interface/configEditor/configMenuDefs.h @@ -229,6 +229,13 @@ const char* const notesChannel[17] = { "CH9", "CH10", "CH11", "CH12", "CH13", "CH14", "CH15", "CH16", }; +const char* const midiGlideMode[4] = { + "Off", + "Legato", + "Bend", + "Both", +}; + const char* const slaveClockComp[kExternalClockCompMaxVal + 1] = { "-6", "-5", "-4", "-3", "-2", "-1", "0", "1", "2", "3", "4", "5", "6", }; diff --git a/core/source/mtConfig.cpp b/core/source/mtConfig.cpp index 95068645b..260fec101 100644 --- a/core/source/mtConfig.cpp +++ b/core/source/mtConfig.cpp @@ -338,6 +338,11 @@ void checkConfig() mtConfig.midi.programChangeInChannel = 0; } + if (mtConfig.midi.glideMode > 3) + { + mtConfig.midi.glideMode = 0; + } + if (mtConfig.midi.middleC > 3) { mtConfig.midi.middleC = 2; @@ -533,6 +538,7 @@ void resetConfig() mtConfig.midi.slaveClockComp = kExternalClockCompDefaultVal; mtConfig.midi.programChangeInMode = 0; mtConfig.midi.programChangeInChannel = 0; + mtConfig.midi.glideMode = MIDI_GLIDE_MODE_OFF; // values ---------------------------------------- mtConfig.values.padsLightBack = PADS_LIGHT_BACK_DEFAULT; diff --git a/core/source/mtSequencer.cpp b/core/source/mtSequencer.cpp index 8f8de5abb..778268c1f 100644 --- a/core/source/mtSequencer.cpp +++ b/core/source/mtSequencer.cpp @@ -94,6 +94,8 @@ AUDIO_CORE_RAM void Sequencer::tick(float intervalSeconds) updateExternalClockTempo((seqtimesec_t)intervalSeconds); + midiGlideStep(intervalSeconds); + if (isSetInternalClock() || player.selectionMode) { // Integer clock, same ticks and offsets as the double accumulator it replaced (internalTickClock.h) @@ -832,14 +834,15 @@ AUDIO_CORE_RAM void Sequencer::play_microStep(int row) { if (playerRow.stepOpen && playerRow.stepToSend.note >= 0) { - // looks weird but keeps logic from commit - // "Send NOTE OFF to held MIDI notes on track when track muted or sample played" - if (isMidiInstrument(playerRow.stepToSend.instrument) || - isSynthInstrument(playerRow.stepToSend.instrument) || - isMidiInstrument(playerRow.stepSent.instrument) || - isSynthInstrument(playerRow.stepSent.instrument)) + if (!midiGlidePrepare(row, &playerRow.stepSent, &playerRow.stepToSend)) { - sendNoteOff(row, &playerRow.stepSent); + if (isMidiInstrument(playerRow.stepToSend.instrument) || + isSynthInstrument(playerRow.stepToSend.instrument) || + isMidiInstrument(playerRow.stepSent.instrument) || + isSynthInstrument(playerRow.stepSent.instrument)) + { + sendNoteOff(row, &playerRow.stepSent); + } } playerRow.stepOpen = 0; @@ -1041,6 +1044,8 @@ AUDIO_CORE_RAM void Sequencer::play_microStep(int row) playerRow.stepSent = playerRow.stepToSend; } + + midiGlideFlushLegatoOff(row); } // ************************** @@ -1622,6 +1627,7 @@ void Sequencer::stop(StopContext context) songTimer.stop(); stopAllOpenNotes(); cancelFxes(); + midiGlideClearAll(); player.isPlay = 0; player.isStop = 1; @@ -2621,6 +2627,11 @@ void Sequencer::sendMidiChordOff([[maybe_unused]] uint8_t track, } } +static uint8_t midiGlideIndex(uint8_t channel, bool toSynth) +{ + return toSynth ? (uint8_t)(kMidiInstrumentsCount + channel - 1) : channel - 1; +} + AUDIO_CORE_RAM void Sequencer::sendNoteOn(uint8_t track, strPlayer::strPlayerTrack::strSendStep* step) { @@ -2629,6 +2640,8 @@ AUDIO_CORE_RAM void Sequencer::sendNoteOn(uint8_t track, if (toSynth && synthsMuteState == MuteState::kMuted) { + const uint8_t mutedChannel = instrumentIdxToMidiChannel(step->instrument); + midiGlide[midiGlideIndex(mutedChannel, true)].pending = false; return; } @@ -2656,6 +2669,73 @@ AUDIO_CORE_RAM void Sequencer::sendNoteOn(uint8_t track, velocity = clamp(velocity + deltaPerformanceVelocityFx, 0, kMaxMidiVelocity); + if (toMidi || toSynth) + { + const uint8_t channel = instrumentIdxToMidiChannel(step->instrument); + strMidiGlide& g = midiGlide[midiGlideIndex(channel, toSynth)]; + + if (g.pending) + { + g.pending = false; + + if (g.fromNote >= 0 && (uint8_t)g.fromNote != step->note) + { + uint8_t glideFxValue = 0; + if (step->fx[1].type == fx.FX_TYPE_GLIDE) + { + glideFxValue = step->fx[1].value; + } + else if (step->fx[0].type == fx.FX_TYPE_GLIDE) + { + glideFxValue = step->fx[0].value; + } + + const int32_t glideUs = (int32_t)glideFxValueToMs(glideFxValue) * 1000; + + if (glideUs > 0) + { + int32_t startCents; + if (g.rampNote >= 0 && g.remainingUs > 0) + { + startCents = (int32_t)g.bend * ((int32_t)g.rangeSemitones * 100) / 8192; + } + else + { + startCents = (int32_t)((int32_t)g.fromNote - (int32_t)step->note) * 100; + } + + int interval = (int)g.fromNote - (int)step->note; + if (interval < 0) + { + interval = -interval; + } + + if (toMidi && interval > g.rangeSemitones) + { + const uint8_t range = (uint8_t)clamp(interval, 2, 24); + sendCC(99, 0, channel, false); + sendCC(98, 0, channel, false); + sendCC(6, range, channel, false); + sendCC(38, 0, channel, false); + sendCC(101, 127, channel, false); + g.rangeSemitones = range; + } + + int32_t startRaw = startCents * 8192 / ((int32_t)g.rangeSemitones * 100); + startRaw = clamp(startRaw, -8192, 8191); + + g.bend = (int16_t)startRaw; + g.startBend = startRaw; + g.totalUs = glideUs; + g.remainingUs = glideUs; + g.rampNote = (int8_t)step->note; + + sendPitchbend((int16_t)startRaw, (int8_t)channel, toSynth); + } + } + } + } + sendMidiNoteOn( step->note, velocity, instrumentIdxToMidiChannel(step->instrument), toSynth); } @@ -2689,8 +2769,18 @@ AUDIO_CORE_RAM void Sequencer::sendNoteOff(uint8_t track, } else { + const uint8_t channel = instrumentIdxToMidiChannel(instrument); + strMidiGlide& g = midiGlide[midiGlideIndex(channel, isSynth)]; + + if (g.rampNote >= 0 && (uint8_t)g.rampNote == step->note) + { + g.rampNote = -1; + g.remainingUs = 0; + g.bend = 0; + sendPitchbend(0, (int8_t)channel, isSynth); + } - sendMidiNoteOff(step->note, 0, instrumentIdxToMidiChannel(instrument), isSynth); + sendMidiNoteOff(step->note, 0, channel, isSynth); } } else if (isSampleTrack(track)) @@ -2699,6 +2789,161 @@ AUDIO_CORE_RAM void Sequencer::sendNoteOff(uint8_t track, } } +AUDIO_CORE_RAM bool Sequencer::midiGlidePrepare(uint8_t row, + strPlayer::strPlayerTrack::strSendStep* oldStep, + strPlayer::strPlayerTrack::strSendStep* newStep) +{ + const uint8_t mode = mtConfig.midi.glideMode; + if (mode == MIDI_GLIDE_MODE_OFF) + { + return false; + } + + const bool oldIsMidi = isMidiInstrument(oldStep->instrument); + const bool oldIsSynth = isSynthInstrument(oldStep->instrument); + + if (oldStep->note < 0 || + (oldIsMidi && !isMidiInstrument(newStep->instrument)) || + (oldIsSynth && !isSynthInstrument(newStep->instrument))) + { + return false; + } + + if (oldStep->fx[0].type == fx.FX_TYPE_MIDI_CHORD || oldStep->fx[1].type == fx.FX_TYPE_MIDI_CHORD || + newStep->fx[0].type == fx.FX_TYPE_MIDI_CHORD || newStep->fx[1].type == fx.FX_TYPE_MIDI_CHORD) + { + return false; + } + + uint8_t glideFxValue = 0; + if (newStep->fx[1].type == fx.FX_TYPE_GLIDE) + { + glideFxValue = newStep->fx[1].value; + } + else if (newStep->fx[0].type == fx.FX_TYPE_GLIDE) + { + glideFxValue = newStep->fx[0].value; + } + + if (glideFxValue == 0) + { + return false; + } + + const uint8_t oldChannel = instrumentIdxToMidiChannel(oldStep->instrument); + const uint8_t newChannel = instrumentIdxToMidiChannel(newStep->instrument); + if (oldChannel != newChannel) + { + return false; + } + + if (mode == MIDI_GLIDE_MODE_BEND) + { + strMidiGlide& g = midiGlide[midiGlideIndex(newChannel, oldIsSynth)]; + g.pending = true; + g.fromNote = oldStep->note; + return false; + } + + strPlayer::strPlayerTrack& playerRow = player.track[row]; + playerRow.legatoOffPending = 1; + playerRow.legatoOffNote = oldStep->note; + playerRow.legatoOffChannel = oldChannel; + playerRow.legatoOffToSynth = oldIsSynth; + + if (mode == MIDI_GLIDE_MODE_BOTH) + { + strMidiGlide& g = midiGlide[midiGlideIndex(newChannel, oldIsSynth)]; + g.pending = true; + g.fromNote = oldStep->note; + } + + return true; +} + +AUDIO_CORE_RAM void Sequencer::midiGlideFlushLegatoOff(uint8_t row) +{ + strPlayer::strPlayerTrack& playerRow = player.track[row]; + + if (playerRow.legatoOffPending) + { + playerRow.legatoOffPending = 0; + sendMidiNoteOff(playerRow.legatoOffNote, 0, playerRow.legatoOffChannel, playerRow.legatoOffToSynth); + } +} + +AUDIO_CORE_RAM void Sequencer::midiGlideStep(float intervalSeconds) +{ + if (!player.isPlay) + { + return; + } + + const int32_t dtUs = (int32_t)(intervalSeconds * 1000000.0f); + + const uint8_t total = kMidiInstrumentsCount + kSynthInstrumentsCount; + + for (uint8_t idx = 0; idx < total; idx++) + { + strMidiGlide& g = midiGlide[idx]; + + if (g.rampNote < 0 || g.remainingUs <= 0) + { + continue; + } + + const bool toSynth = idx >= kMidiInstrumentsCount; + const int8_t channel = (int8_t)(toSynth ? idx - kMidiInstrumentsCount + 1 : idx + 1); + + g.remainingUs -= dtUs; + + if (g.remainingUs <= 0) + { + g.rampNote = -1; + g.remainingUs = 0; + g.bend = 0; + sendPitchbend(0, channel, toSynth); + } + else + { + const int32_t raw = (g.startBend * g.remainingUs) / g.totalUs; + if (raw != g.bend) + { + g.bend = (int16_t)raw; + sendPitchbend((int16_t)raw, channel, toSynth); + } + } + } +} + +AUDIO_CORE_RAM void Sequencer::midiGlideClearAll() +{ + const uint8_t total = kMidiInstrumentsCount + kSynthInstrumentsCount; + + for (uint8_t idx = 0; idx < total; idx++) + { + strMidiGlide& g = midiGlide[idx]; + + const bool toSynth = idx >= kMidiInstrumentsCount; + const int8_t channel = (int8_t)(toSynth ? idx - kMidiInstrumentsCount + 1 : idx + 1); + + if (g.rampNote >= 0 || g.bend != 0) + { + sendPitchbend(0, channel, toSynth); + } + + g.bend = 0; + g.rampNote = -1; + g.pending = false; + g.remainingUs = 0; + } + + for (uint8_t row = 0; row < kAllTracks; row++) + { + player.track[row].legatoOffPending = 0; + } +} + int8_t Sequencer::velocityToVolume(int8_t velo) { if (velo < 0) diff --git a/core/source/mtSequencer.h b/core/source/mtSequencer.h index e3173c1b3..ac9439634 100644 --- a/core/source/mtSequencer.h +++ b/core/source/mtSequencer.h @@ -460,6 +460,11 @@ class Sequencer uint8_t recOpen = 0; uint8_t recNoteOnStepIdx = 0; + bool legatoOffPending = 0; + int8_t legatoOffNote = -1; + uint8_t legatoOffChannel = 0; + bool legatoOffToSynth = 0; + int16_t noteSource = -1; uint16_t uStep = 0; // aktualny microstep @@ -1014,6 +1019,13 @@ class Sequencer void sendMidiChordOn(uint8_t track, strPlayer::strPlayerTrack::strSendStep* step); void sendMidiChordOff(uint8_t track, strPlayer::strPlayerTrack::strSendStep* step); + bool midiGlidePrepare(uint8_t row, + strPlayer::strPlayerTrack::strSendStep* oldStep, + strPlayer::strPlayerTrack::strSendStep* newStep); + void midiGlideFlushLegatoOff(uint8_t row); + void midiGlideStep(float intervalSeconds); + void midiGlideClearAll(); + uint16_t getChordBitmask(uint8_t chord); uint16_t getChordBitmaskForArp(uint8_t chord); @@ -1050,6 +1062,8 @@ class Sequencer strPlayer player; + strMidiGlide midiGlide[kMidiInstrumentsCount + kSynthInstrumentsCount]; + int externalClockPulses = 0; int externalClocksToPlay = 0; diff --git a/core/source/mtStructs.h b/core/source/mtStructs.h index 53df36097..b26735e6a 100644 --- a/core/source/mtStructs.h +++ b/core/source/mtStructs.h @@ -3,6 +3,7 @@ #include "config.h" #include "mtEnvelopeGenerator.h" +#include "util_math.h" #include //===================================================================== @@ -175,6 +176,34 @@ const uint16_t GLIDE_MAX = 15000; const uint8_t SEND_MIN = 0; const uint8_t SEND_MAX = 100; +inline uint16_t glideFxValueToMs(uint8_t fxVal, uint8_t maxFx = 100) +{ + const uint8_t half = maxFx / 2; + if (half == 0) + { + return 0; + } + return fxVal > half ? mapClamped(fxVal, half, maxFx, 1000, GLIDE_MAX) + : mapClamped(fxVal, 0, half, GLIDE_MIN, 1000); +} + +const uint8_t MIDI_GLIDE_MODE_OFF = 0; +const uint8_t MIDI_GLIDE_MODE_LEGATO = 1; +const uint8_t MIDI_GLIDE_MODE_BEND = 2; +const uint8_t MIDI_GLIDE_MODE_BOTH = 3; + +struct strMidiGlide +{ + int16_t bend = 0; + uint8_t rangeSemitones = 2; + int8_t rampNote = -1; + int32_t startBend = 0; + int32_t remainingUs = 0; + int32_t totalUs = 0; + bool pending = false; + int8_t fromNote = -1; +}; + const uint16_t ATTACK_MAX = 10000; // zastosowane jest dzielenie przez 100 bez floatow wiec wazne // zeby wartosci czasowe max env byly podzielne przez 100 const uint16_t DECAY_MAX = 10000; @@ -1100,6 +1129,7 @@ struct strMtConfig uint8_t slaveClockComp; uint8_t programChangeInMode; uint8_t programChangeInChannel; + uint8_t glideMode; } midi; struct strGlobalValues From 0bfa458e638560f21f4bd0727184d1f890503139 Mon Sep 17 00:00:00 2001 From: z3phyr2 <354930554+z3phyr2@users.noreply.github.com> Date: Sun, 22 Nov 2026 23:08:45 +0100 Subject: [PATCH 2/2] fix: make synth glide independent of MIDI Glide config Synth tracks (S1-S3) now always glide via the pitch-bend ramp when G > 0, matching the sample-track behavior. The "MIDI Glide" config option now only affects MIDI instrument tracks. --- core/source/mtSequencer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/source/mtSequencer.cpp b/core/source/mtSequencer.cpp index 778268c1f..0f935a4cd 100644 --- a/core/source/mtSequencer.cpp +++ b/core/source/mtSequencer.cpp @@ -2793,7 +2793,9 @@ AUDIO_CORE_RAM bool Sequencer::midiGlidePrepare(uint8_t row, strPlayer::strPlayerTrack::strSendStep* oldStep, strPlayer::strPlayerTrack::strSendStep* newStep) { - const uint8_t mode = mtConfig.midi.glideMode; + const uint8_t mode = isSynthInstrument(newStep->instrument) + ? MIDI_GLIDE_MODE_BEND + : mtConfig.midi.glideMode; if (mode == MIDI_GLIDE_MODE_OFF) { return false;