From 56adff66e1c8209d98a84e5715e157852925eb13 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Sat, 4 Feb 2017 16:12:18 +0000 Subject: [PATCH] Reimplemented MIDI controller 120 and 123 with event-cue-flushing. --- src/dexed.cpp | 54 +++++++++++++++++++++------------------------------ src/dexed.h | 4 +--- src/dexed.mk | 2 +- 3 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/dexed.cpp b/src/dexed.cpp index c5fbdae..e3eb539 100644 --- a/src/dexed.cpp +++ b/src/dexed.cpp @@ -83,7 +83,6 @@ Dexed::Dexed(double rate) : lvtk::Synth(p_n_ports, p_midi_in) lfo.reset(data+137); - //normalizeDxVelocity = false; setMonoMode(false); @@ -369,13 +368,12 @@ void Dexed::run (uint32_t sample_count) const LV2_Atom_Sequence* seq = p (p_midi_in); float* output = p(p_audio_out); uint32_t last_frame = 0, num_this_time = 0; + bool drop_next_events=false; Plugin::run(sample_count); if(++_k_rate_counter%16) - { set_params(); // pre_process: copy actual voice params - } for (LV2_Atom_Event* ev = lv2_atom_sequence_begin (&seq->body); !lv2_atom_sequence_is_end(&seq->body, seq->atom.size, ev); @@ -386,7 +384,9 @@ void Dexed::run (uint32_t sample_count) // If it's midi, send it to the engine if (ev->body.type == m_midi_type) { - ProcessMidiMessage((uint8_t*) LV2_ATOM_BODY (&ev->body),ev->body.size); + drop_next_events|=ProcessMidiMessage((uint8_t*) LV2_ATOM_BODY (&ev->body),ev->body.size); + if(drop_next_events==true) + continue; } // render audio from the last frame until the timestamp of this event @@ -396,7 +396,7 @@ void Dexed::run (uint32_t sample_count) // j is the index of the plugin's float output buffer which will be the timestamp // of the last processed atom event. for (uint32_t i = 0, j = last_frame; i < num_this_time; ++i, ++j) - output[j]=outbuf_[i]; + output[j]=outbuf_[i]; last_frame = ev->time.frames; } @@ -411,7 +411,7 @@ void Dexed::run (uint32_t sample_count) num_this_time = sample_count - last_frame; GetSamples (num_this_time, outbuf_); for (uint32_t i = 0, j = last_frame; i < num_this_time; ++i, ++j) - output[j] = outbuf_[i]; + output[j] = outbuf_[i]; } fx.process(output, sample_count); @@ -468,18 +468,16 @@ void Dexed::GetSamples(uint32_t n_samples, float* buffer) if(f<-1) f=-1; sumbuf[j]+=f; audiobuf.get()[j]=0; - //sumbuf[j]+=static_cast(audiobuf.get()[j]); } } } uint32_t jmax = n_samples - i; for (uint32_t j = 0; j < N; ++j) { - if (j < jmax) { + if (j < jmax) buffer[i + j] = sumbuf[j]; - } else { + else extra_buf_[j - jmax] = sumbuf[j]; - } } } extra_buf_size_ = i - n_samples; @@ -527,7 +525,7 @@ void Dexed::GetSamples(uint32_t n_samples, float* buffer) } } -void Dexed::ProcessMidiMessage(const uint8_t *buf, uint32_t buf_size) { +bool Dexed::ProcessMidiMessage(const uint8_t *buf, uint32_t buf_size) { TRACE("Hi"); uint8_t cmd = buf[0]; @@ -536,12 +534,12 @@ void Dexed::ProcessMidiMessage(const uint8_t *buf, uint32_t buf_size) { case 0x80 : TRACE("MIDI keyup event: %d",buf[1]); keyup(buf[1]); - return; + return(false); break; case 0x90 : TRACE("MIDI keydown event: %d %d",buf[1],buf[2]); keydown(buf[1], buf[2]); - return; + return(false); break; case 0xb0 : { uint8_t ctrl = buf[1]; @@ -575,13 +573,18 @@ void Dexed::ProcessMidiMessage(const uint8_t *buf, uint32_t buf_size) { } } break; - case 123: - TRACE("MIDI all-notes-off: %d %d",ctrl,value); - panic(); - break; case 120: TRACE("MIDI all-sound-off: %d %d",ctrl,value); - all_sound_off(); + panic(); + return(true); + break; + case 123: + TRACE("MIDI all-notes-off: %d %d",ctrl,value); + for(uint8_t note=0; notekeyup(); + } + return(true); break; } break; @@ -608,8 +611,8 @@ void Dexed::ProcessMidiMessage(const uint8_t *buf, uint32_t buf_size) { break; } - TRACE("Bye"); + return(false); } void Dexed::keydown(uint8_t pitch, uint8_t velo) { @@ -622,10 +625,6 @@ TRACE("pitch=%d, velo=%d\n",pitch,velo); pitch += data[144] - 24; - //if ( normalizeDxVelocity ) { - // velo = ((float)velo) * 0.7874015; // 100/127 - //} - uint8_t note = currentNote; uint8_t keydown_counter=0; @@ -842,15 +841,6 @@ void Dexed::panic(void) { } } -void Dexed::all_sound_off(void) { - for(uint8_t i=0;iinit(data, 0, 0, feedback_bitdepth); - if ( voices[i].dx7_note != NULL ) { - voices[i].dx7_note->oscSync(); - } - } -} - //============================================================================== DexedVoice::DexedVoice(double rate) : m_key(lvtk::INVALID_KEY), m_rate(rate) diff --git a/src/dexed.h b/src/dexed.h index 69a5a68..7e04b9e 100644 --- a/src/dexed.h +++ b/src/dexed.h @@ -91,12 +91,11 @@ class Dexed : public lvtk::Synth VoiceStatus voiceStatus; protected: - void ProcessMidiMessage(const uint8_t *buf, uint32_t buf_size); + bool ProcessMidiMessage(const uint8_t *buf, uint32_t buf_size); void onParam(uint8_t param_num,float param_val); void keyup(uint8_t pitch); void keydown(uint8_t pitch, uint8_t velo); void panic(void); - void all_sound_off(void); static const uint8_t MAX_ACTIVE_NOTES = 32; uint8_t max_notes=MAX_ACTIVE_NOTES; @@ -105,7 +104,6 @@ class Dexed : public lvtk::Synth bool sustain; bool monoMode; bool refreshVoice; - //bool normalizeDxVelocity; uint8_t engineType; uint8_t feedback_bitdepth; PluginFx fx; diff --git a/src/dexed.mk b/src/dexed.mk index 1548062..3427080 100644 --- a/src/dexed.mk +++ b/src/dexed.mk @@ -5,7 +5,7 @@ ###################################### DEXED_DEPENDENCIES = lvtk -DEXED_VERSION = d8fcf2d029401bcebb2326a34d01b263dc555c48 +DEXED_VERSION = da0fabe3de43de10c1e36899e751791888a7f4e3 DEXED_BUNDLES = dexed.lv2 DEXED_SITE = $(call github,dcoredump,dexed,$(DEXED_VERSION)) DEXED_TARGET_MAKE = $(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) MOD=1