Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions core/AudioEngine/mtAudioSequencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(fx_val, halfFxGlide, maxFxGlide, 1000, GLIDE_MAX)
: mapClamped<int>(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<int>(fx_val, halfFxGlide, maxFxGlide, 1000, GLIDE_MAX)
: mapClamped<int>(fx_val, minFxGlide, halfFxGlide, GLIDE_MIN, 1000);
currentSeqModValues.glide = glideFxValueToMs(fx_val, maxFxGlide);
}
}
trackControlParameter[(int)controlType::sequencerMode + fx_n][(int)parameterList::glide] = 1;
Expand Down
6 changes: 6 additions & 0 deletions core/interface/configEditor/configMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -225,6 +226,11 @@ cMenuItem melNotesInChannel(menuMidi,
menuTypeItemListText,
&notesInChanneletup);
cMenuItem melNotsOutMode(menuMidi, "MIDI out", nullptr, menuTypeItemListText, &notesOutModeSetup);
cMenuItem melMidiGlideMode(menuMidi,
"MIDI Glide",
nullptr,
menuTypeItemListText,
&midiGlideModeSetup);
cMenuItem melCCInMode(menuMidi, "CC in", supportedCcInDesc, menuTypeItemListText, &ccInModeSetup);
cMenuItem melCCInChannel(menuMidi,
"CC in channel",
Expand Down
7 changes: 7 additions & 0 deletions core/interface/configEditor/configMenuDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
Expand Down
6 changes: 6 additions & 0 deletions core/source/mtConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
255 changes: 242 additions & 13 deletions core/source/mtSequencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1041,6 +1044,8 @@ AUDIO_CORE_RAM void Sequencer::play_microStep(int row)

playerRow.stepSent = playerRow.stepToSend;
}

midiGlideFlushLegatoOff(row);
}

// **************************
Expand Down Expand Up @@ -1622,6 +1627,7 @@ void Sequencer::stop(StopContext context)
songTimer.stop();
stopAllOpenNotes();
cancelFxes();
midiGlideClearAll();

player.isPlay = 0;
player.isStop = 1;
Expand Down Expand Up @@ -2627,11 +2633,6 @@ AUDIO_CORE_RAM void Sequencer::sendNoteOn(uint8_t track,
bool toMidi = isMidiInstrument(step->instrument);
bool toSynth = isSynthInstrument(step->instrument);

if (toSynth && synthsMuteState == MuteState::kMuted)
{
return;
}

if (toMidi || toSynth)
{
if ((step->fx[0].type == fx.FX_TYPE_MIDI_CHORD && step->fx[1].type != fx.FX_TYPE_ARP) ||
Expand All @@ -2656,6 +2657,73 @@ AUDIO_CORE_RAM void Sequencer::sendNoteOn(uint8_t track,

velocity = clamp(velocity + deltaPerformanceVelocityFx, 0, kMaxMidiVelocity);

if (toMidi)
{
const uint8_t channel = instrumentIdxToMidiChannel(step->instrument);
strMidiGlide& g = midiGlide[channel - 1];

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 (interval > g.rangeSemitones)
{
const uint8_t range = (uint8_t)clamp<int>(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<int32_t>(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, false);
}
}
}
}

sendMidiNoteOn(
step->note, velocity, instrumentIdxToMidiChannel(step->instrument), toSynth);
}
Expand Down Expand Up @@ -2689,8 +2757,22 @@ AUDIO_CORE_RAM void Sequencer::sendNoteOff(uint8_t track,
}
else
{
const uint8_t channel = instrumentIdxToMidiChannel(instrument);

sendMidiNoteOff(step->note, 0, instrumentIdxToMidiChannel(instrument), isSynth);
if (isMidi)
{
strMidiGlide& g = midiGlide[channel - 1];

if (g.rampNote >= 0 && (uint8_t)g.rampNote == step->note)
{
g.rampNote = -1;
g.remainingUs = 0;
g.bend = 0;
sendPitchbend(0, (int8_t)channel, false);
}
}

sendMidiNoteOff(step->note, 0, channel, isSynth);
}
}
else if (isSampleTrack(track))
Expand All @@ -2699,6 +2781,153 @@ 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);

if (oldStep->note < 0 ||
!oldIsMidi ||
!isMidiInstrument(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[newChannel - 1];
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;

if (mode == MIDI_GLIDE_MODE_BOTH)
{
strMidiGlide& g = midiGlide[newChannel - 1];
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, false);
}
}

AUDIO_CORE_RAM void Sequencer::midiGlideStep(float intervalSeconds)
{
if (!player.isPlay)
{
return;
}

const int32_t dtUs = (int32_t)(intervalSeconds * 1000000.0f);

for (uint8_t idx = 0; idx < kMidiInstrumentsCount; idx++)
{
strMidiGlide& g = midiGlide[idx];

if (g.rampNote < 0 || g.remainingUs <= 0)
{
continue;
}

const int8_t channel = (int8_t)(idx + 1);

g.remainingUs -= dtUs;

if (g.remainingUs <= 0)
{
g.rampNote = -1;
g.remainingUs = 0;
g.bend = 0;
sendPitchbend(0, channel, false);
}
else
{
const int32_t raw = (int32_t)(((int64_t)g.startBend * g.remainingUs) / g.totalUs);
if (raw != g.bend)
{
g.bend = (int16_t)raw;
sendPitchbend((int16_t)raw, channel, false);
}
}
}
}

AUDIO_CORE_RAM void Sequencer::midiGlideClearAll()
{
for (uint8_t idx = 0; idx < kMidiInstrumentsCount; idx++)
{
strMidiGlide& g = midiGlide[idx];

const int8_t channel = (int8_t)(idx + 1);

if (g.rampNote >= 0 || g.bend != 0)
{
sendPitchbend(0, channel, false);
}

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)
Expand Down
Loading
Loading