From 2f26855c27aaffee0472edf43dbc5ac5ca1a5162 Mon Sep 17 00:00:00 2001 From: JP Cimalando Date: Tue, 19 Jun 2018 21:15:45 +0200 Subject: allow portamento to be updated by MIDI::Tick --- src/adlmidi_midiplay.cpp | 66 +++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 26 deletions(-) (limited to 'src/adlmidi_midiplay.cpp') diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp index 6dad2a9..f52d936 100644 --- a/src/adlmidi_midiplay.cpp +++ b/src/adlmidi_midiplay.cpp @@ -680,8 +680,10 @@ bool MIDIplay::buildTrackData() MIDIplay::MIDIplay(unsigned long sampleRate): cmf_percussion_mode(false), - m_arpeggioCounter(0), - m_audioTickCounter(0) + m_arpeggioCounter(0) +#if defined(ADLMIDI_AUDIO_TICK_HANDLER) + , m_audioTickCounter(0) +#endif #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER , fullSongTimeLength(0.0), postSongWaitDelay(1.0), @@ -825,6 +827,9 @@ double MIDIplay::Tick(double s, double granularity) UpdateVibrato(s); UpdateArpeggio(s); +#if !defined(ADLMIDI_AUDIO_TICK_HANDLER) + UpdateGlide(s); +#endif if(CurrentPositionNew.wait < 0.0)//Avoid negative delay value! return 0.0; @@ -839,6 +844,9 @@ void MIDIplay::TickIteratos(double s) ch[c].AddAge(static_cast(s * 1000.0)); UpdateVibrato(s); UpdateArpeggio(s); +#if !defined(ADLMIDI_AUDIO_TICK_HANDLER) + UpdateGlide(s); +#endif } #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER @@ -1454,6 +1462,7 @@ void MIDIplay::realTime_panic() KillSustainingNotes(-1, -1); } +#if defined(ADLMIDI_AUDIO_TICK_HANDLER) void MIDIplay::AudioTick(uint32_t chipId, uint32_t rate) { if(chipId != 0) // do first chip ticks only @@ -1467,32 +1476,10 @@ void MIDIplay::AudioTick(uint32_t chipId, uint32_t rate) if(tickNumber % portamentoInterval == 0) { double portamentoDelta = timeDelta * portamentoInterval; - - for(unsigned channel = 0; channel < 16; ++channel) - { - MIDIchannel &midiChan = Ch[channel]; - for(MIDIchannel::activenoteiterator it = midiChan.activenotes_begin(); - it; ++it) - { - double finalTone = it->noteTone; - double previousTone = it->currentTone; - - bool directionUp = previousTone < finalTone; - double toneIncr = portamentoDelta * (directionUp ? +it->glideRate : -it->glideRate); - - double currentTone = previousTone + toneIncr; - bool glideFinished = !(directionUp ? (currentTone < finalTone) : (currentTone > finalTone)); - currentTone = glideFinished ? finalTone : currentTone; - - if(currentTone != previousTone) - { - it->currentTone = currentTone; - NoteUpdate(channel, it, Upd_Pitch); - } - } - } + UpdateGlide(portamentoDelta); } } +#endif void MIDIplay::NoteUpdate(uint16_t MidCh, MIDIplay::MIDIchannel::activenoteiterator i, @@ -2601,6 +2588,33 @@ retry_arpeggio: } } +void MIDIplay::UpdateGlide(double amount) +{ + for(unsigned channel = 0; channel < 16; ++channel) + { + MIDIchannel &midiChan = Ch[channel]; + for(MIDIchannel::activenoteiterator it = midiChan.activenotes_begin(); + it; ++it) + { + double finalTone = it->noteTone; + double previousTone = it->currentTone; + + bool directionUp = previousTone < finalTone; + double toneIncr = amount * (directionUp ? +it->glideRate : -it->glideRate); + + double currentTone = previousTone + toneIncr; + bool glideFinished = !(directionUp ? (currentTone < finalTone) : (currentTone > finalTone)); + currentTone = glideFinished ? finalTone : currentTone; + + if(currentTone != previousTone) + { + it->currentTone = currentTone; + NoteUpdate(channel, it, Upd_Pitch); + } + } + } +} + #ifndef ADLMIDI_DISABLE_CPP_EXTRAS -- cgit v1.2.3