From ba1917edea8f3b0eaf5aafdc2a7827ab076c61b4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 20 Apr 2012 18:52:14 +0000 Subject: Make instrument plugins work. git-svn-id: http://svn.drobilla.net/lad/trunk/plugins/mda.lv2@4215 a436a847-0d15-0410-975c-d299462d15a1 --- src/mdaPiano.cpp | 108 +++++++++---------------------------------------------- 1 file changed, 17 insertions(+), 91 deletions(-) (limited to 'src/mdaPiano.cpp') diff --git a/src/mdaPiano.cpp b/src/mdaPiano.cpp index 8f4fd76..f207079 100644 --- a/src/mdaPiano.cpp +++ b/src/mdaPiano.cpp @@ -19,6 +19,8 @@ #include "mdaPianoData.h" #include "mdaPiano.h" +#include "lv2/lv2plug.in/ns/ext/atom/util.h" + #include #include @@ -109,7 +111,6 @@ mdaPiano::mdaPiano(audioMasterCallback audioMaster) : AudioEffectX(audioMaster, voice[v].env = 0.0f; voice[v].dec = 0.99f; //all notes off } - notes[0] = EVENTS_DONE; volume = 0.2f; muff = 160.0f; cpos = sustain = activevoices = 0; @@ -240,7 +241,7 @@ bool mdaPiano::copyProgram(int32_t destination) } -int32_t mdaPiano::canDo(char* text) +int32_t mdaPiano::canDo(const char* text) { if(strcmp(text, "receiveLvzEvents") == 0) return 1; if(strcmp(text, "receiveLvzMidiEvent") == 0) return 1; @@ -313,79 +314,19 @@ void mdaPiano::guiGetDisplay(int32_t index, char *label) getParameterLabel(index, label + strlen(label)); } - - -void mdaPiano::process(float **inputs, float **outputs, int32_t sampleFrames) -{ - float* out0 = outputs[0]; - float* out1 = outputs[1]; - int32_t event=0, frame=0, frames, v; - float x, l, r; - int32_t i; - - while(framesampleFrames) frames = sampleFrames; - frames -= frame; - frame += frames; - - while(--frames>=0) - { - VOICE *V = voice; - l = r = 0.0f; - - for(v=0; vfrac += V->delta; //integer-based linear interpolation - V->pos += V->frac >> 16; - V->frac &= 0xFFFF; - if(V->pos > V->end) V->pos -= V->loop; - i = waves[V->pos]; - i = (i << 7) + (V->frac >> 9) * (waves[V->pos + 1] - i) + 0x40400000; - x = V->env * (*(float *)&i - 3.0f); //fast int->float - - V->env = V->env * V->dec; //envelope - V->f0 += V->ff * (x + V->f1 - V->f0); //muffle filter - V->f1 = x; - - l += V->outl * V->f0; - r += V->outr * V->f0; - - V++; - } - comb[cpos] = l + r; - ++cpos &= cmax; - x = cdep * comb[cpos]; //stereo simulator - - *out0++ += l + x; - *out1++ += r - x; - } - - if(framebody); while(framesampleFrames) frames = sampleFrames; + bool end = lv2_atom_sequence_is_end(&eventInput->body, eventInput->atom.size, ev); + frames = end ? sampleFrames : ev->time.frames; frames -= frame; frame += frames; @@ -432,15 +373,13 @@ if(!(r > -2.0f) || !(r < 2.0f)) *out1++ = r - x; } - if(framebody.type != midiEventType) + return 0; - for (int32_t i=0; inumEvents; i++) - { - if((ev->events[i])->type != kLvzMidiType) continue; - LvzMidiEvent* event = (LvzMidiEvent*)ev->events[i]; - char* midiData = event->midiData; + const uint8_t* midiData = (const uint8_t*)LV2_ATOM_BODY(&ev->body); switch(midiData[0] & 0xf0) //status byte (all channels) { case 0x80: //note off - notes[npos++] = event->deltaFrames; //delta - notes[npos++] = midiData[1] & 0x7F; //note - notes[npos++] = 0; //vel + noteOn(midiData[1] & 0x7F, 0); break; case 0x90: //note on - notes[npos++] = event->deltaFrames; //delta - notes[npos++] = midiData[1] & 0x7F; //note - notes[npos++] = midiData[2] & 0x7F; //vel + noteOn(midiData[1] & 0x7F, midiData[2] & 0x7F); break; case 0xB0: //controller @@ -559,9 +491,7 @@ int32_t mdaPiano::processEvents(LvzEvents* ev) sustain = midiData[2] & 0x40; if(sustain==0) { - notes[npos++] = event->deltaFrames; - notes[npos++] = SUSTAIN; //end all sustained notes - notes[npos++] = 0; + noteOn(SUSTAIN, 0); //end all sustained notes } break; @@ -583,10 +513,6 @@ int32_t mdaPiano::processEvents(LvzEvents* ev) default: break; } - if(npos>EVENTBUFFER) npos -= 3; //discard events if buffer full!! - event++; //? - } - notes[npos] = EVENTS_DONE; return 1; } -- cgit v1.2.1