aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mdaDX10.cpp131
-rw-r--r--src/mdaDX10.h9
-rw-r--r--src/mdaEPiano.cpp119
-rw-r--r--src/mdaEPiano.h9
-rw-r--r--src/mdaJX10.cpp219
-rw-r--r--src/mdaJX10.h8
-rw-r--r--src/mdaPiano.cpp108
-rw-r--r--src/mdaPiano.h9
8 files changed, 85 insertions, 527 deletions
diff --git a/src/mdaDX10.cpp b/src/mdaDX10.cpp
index bc4c8d1..8e8a5ca 100644
--- a/src/mdaDX10.cpp
+++ b/src/mdaDX10.cpp
@@ -18,6 +18,8 @@
#include "mdaDX10.h"
+#include "lv2/lv2plug.in/ns/ext/atom/util.h"
+
#include <stdio.h>
#include <stdlib.h> //rand()
#include <math.h>
@@ -90,7 +92,6 @@ mdaDX10::mdaDX10(audioMasterCallback audioMaster) : AudioEffectX(audioMaster, NP
voice[i].mod0 = voice[i].mod1 = voice[i].dmod = 0.0f;
voice[i].cdec = 0.99f; //all notes off
}
- notes[0] = EVENTS_DONE;
lfo0 = dlfo = modwhl = 0.0f;
lfo1 = pbend = 1.0f;
volume = 0.0035f;
@@ -240,7 +241,7 @@ bool mdaDX10::copyProgram(int32_t destination)
}
-int32_t mdaDX10::canDo(char* text)
+int32_t mdaDX10::canDo(const char* text)
{
if(strcmp(text, "receiveLvzEvents") == 0) return 1;
if(strcmp(text, "receiveLvzMidiEvent") == 0) return 1;
@@ -304,101 +305,22 @@ void mdaDX10::getParameterLabel(int32_t index, char *label)
}
}
-
-void mdaDX10::process(float **inputs, float **outputs, int32_t sampleFrames)
-{
- float* out1 = outputs[0];
- float* out2 = outputs[1];
- int32_t event=0, frame=0, frames, v;
- float o, x, e, mw=MW, w=rich, m=modmix;
- int32_t k=K;
-
- if(activevoices>0 || notes[event]<sampleFrames) //detect & bypass completely empty blocks
- {
- while(frame<sampleFrames)
- {
- frames = notes[event++];
- if(frames>sampleFrames) frames = sampleFrames;
- frames -= frame;
- frame += frames;
-
- while(--frames>=0) //would be faster with voice loop outside frame loop!
- { //but then each voice would need it's own LFO...
- VOICE *V = voice;
- o = 0.0f;
-
- if(--k<0)
- {
- lfo0 += dlfo * lfo1; //sine LFO
- lfo1 -= dlfo * lfo0;
- mw = lfo1 * (modwhl + vibrato);
- k=100;
- }
-
- for(v=0; v<NVOICES; v++) //for each voice
- {
- e = V->env;
- if(e > SILENCE) //**** this is the synth ****
- {
- V->env = e * V->cdec; //decay & release
- V->cenv += V->catt * (e - V->cenv); //attack
-
- x = V->dmod * V->mod0 - V->mod1; //could add more modulator blocks like
- V->mod1 = V->mod0; //this for a wider range of FM sounds
- V->mod0 = x;
- V->menv += V->mdec * (V->mlev - V->menv);
-
- x = V->car + V->dcar + x * V->menv + mw; //carrier phase
- while(x > 1.0f) x -= 2.0f; //wrap phase
- while(x < -1.0f) x += 2.0f;
- V->car = x;
- o += V->cenv * (m * V->mod1 + (x + x * x * x * (w * x * x - 1.0f - w)));
- } //amp env //mod thru-mix //5th-order sine approximation
- V++;
- }
- *out1++ += o;
- *out2++ += o;
- }
-
- if(frame<sampleFrames) //next note on/off
- {
- int32_t note = notes[event++];
- int32_t vel = notes[event++];
- noteOn(note, vel);
- }
- }
-
- activevoices = NVOICES;
- for(v=0; v<NVOICES; v++)
- {
- if(voice[v].env < SILENCE) //choke voices that have finished
- {
- voice[v].env = voice[v].cenv = 0.0f;
- activevoices--;
- }
- if(voice[v].menv < SILENCE) voice[v].menv = voice[v].mlev = 0.0f;
- }
- }
-
- K=k; MW=mw; //remember these so vibrato speed not buffer size dependant!
- notes[0] = EVENTS_DONE;
-}
-
-
void mdaDX10::processReplacing(float **inputs, float **outputs, int32_t sampleFrames)
{
float* out1 = outputs[0];
float* out2 = outputs[1];
- int32_t event=0, frame=0, frames, v;
+ int32_t frame=0, frames, v;
float o, x, e, mw=MW, w=rich, m=modmix;
int32_t k=K;
- if(activevoices>0 || notes[event]<sampleFrames) //detect & bypass completely empty blocks
+ LV2_Atom_Event* ev = lv2_atom_sequence_begin(&eventInput->body);
+ bool end = lv2_atom_sequence_is_end(&eventInput->body, eventInput->atom.size, ev);
+ if(activevoices>0 || !end) //detect & bypass completely empty blocks
{
while(frame<sampleFrames)
{
- frames = notes[event++];
- if(frames>sampleFrames) frames = sampleFrames;
+ end = lv2_atom_sequence_is_end(&eventInput->body, eventInput->atom.size, ev);
+ frames = end ? sampleFrames : ev->time.frames;
frames -= frame;
frame += frames;
@@ -444,11 +366,10 @@ void mdaDX10::processReplacing(float **inputs, float **outputs, int32_t sampleFr
*out2++ = o;
}
- if(frame<sampleFrames) //next note on/off
+ if(!end) //next note on/off
{
- int32_t note = notes[event++];
- int32_t vel = notes[event++];
- noteOn(note, vel);
+ processEvent(ev);
+ ev = lv2_atom_sequence_next(ev);
}
}
@@ -472,7 +393,6 @@ void mdaDX10::processReplacing(float **inputs, float **outputs, int32_t sampleFr
}
}
K=k; MW=mw; //remember these so vibrato speed not buffer size dependant!
- notes[0] = EVENTS_DONE;
}
@@ -528,28 +448,21 @@ void mdaDX10::noteOn(int32_t note, int32_t velocity)
}
-int32_t mdaDX10::processEvents(LvzEvents* ev)
+int32_t mdaDX10::processEvent(const LV2_Atom_Event* ev)
{
- int32_t npos=0;
+ if (ev->body.type != midiEventType)
+ return 0;
- for (int32_t i=0; i<ev->numEvents; 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
@@ -567,9 +480,7 @@ int32_t mdaDX10::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);
}
break;
@@ -596,10 +507,6 @@ int32_t mdaDX10::processEvents(LvzEvents* ev)
default: break;
}
- if(npos>EVENTBUFFER) npos -= 3; //discard events if buffer full!!
- event++;
- }
- notes[npos] = EVENTS_DONE;
return 1;
}
diff --git a/src/mdaDX10.h b/src/mdaDX10.h
index 02cfe38..8b3ab64 100644
--- a/src/mdaDX10.h
+++ b/src/mdaDX10.h
@@ -62,9 +62,7 @@ public:
mdaDX10(audioMasterCallback audioMaster);
~mdaDX10();
- virtual void process(float **inputs, float **outputs, int32_t sampleframes);
virtual void processReplacing(float **inputs, float **outputs, int32_t sampleframes);
- virtual int32_t processEvents(LvzEvents* events);
virtual void setProgram(int32_t program);
virtual void setProgramName(char *name);
@@ -85,11 +83,12 @@ public:
virtual bool getVendorString (char* text);
virtual bool getProductString (char* text);
virtual int32_t getVendorVersion () {return 1;}
- virtual int32_t canDo (char* text);
+ virtual int32_t canDo (const char* text);
virtual int32_t getNumMidiInputChannels () { return 1; }
private:
+ int32_t processEvent(const LV2_Atom_Event* ev);
void update(); //my parameter update
void noteOn(int32_t note, int32_t velocity);
void fillpatch(int32_t p, const char *name,
@@ -100,10 +99,6 @@ private:
mdaDX10Program* programs;
float Fs;
- #define EVENTBUFFER 120
- #define EVENTS_DONE 99999999
- int32_t notes[EVENTBUFFER + 8]; //list of delta|note|velocity for current block
-
///global internal variables
VOICE voice[NVOICES];
#define SUSTAIN 128
diff --git a/src/mdaEPiano.cpp b/src/mdaEPiano.cpp
index a1866bd..69d5889 100644
--- a/src/mdaEPiano.cpp
+++ b/src/mdaEPiano.cpp
@@ -19,6 +19,8 @@
#include "mdaEPianoData.h"
#include "mdaEPiano.h"
+#include "lv2/lv2plug.in/ns/ext/atom/util.h"
+
#include <stdio.h>
#include <math.h>
@@ -132,7 +134,6 @@ mdaEPiano::mdaEPiano(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;
sustain = activevoices = 0;
@@ -263,7 +264,7 @@ bool mdaEPiano::copyProgram(int32_t destination)
}
-int32_t mdaEPiano::canDo(char* text)
+int32_t mdaEPiano::canDo(const char* text)
{
if(strcmp(text, "receiveLvzEvents") == 0) return 1;
if(strcmp(text, "receiveLvzMidiEvent") == 0) return 1;
@@ -344,87 +345,19 @@ void mdaEPiano::guiGetDisplay(int32_t index, char *label)
}
-void mdaEPiano::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, od=overdrive;
- int32_t i;
-
- while(frame<sampleFrames)
- {
- frames = notes[event++];
- if(frames>sampleFrames) frames = sampleFrames;
- frames -= frame;
- frame += frames;
-
- while(--frames>=0)
- {
- VOICE *V = voice;
- l = r = 0.0f;
-
- for(v=0; v<activevoices; v++)
- {
- V->frac += 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
-
- if(x>0.0f) { x -= od * x * x; if(x < -V->env) x = -V->env; } //+= 0.5f * x * x; } //overdrive
-
- l += V->outl * x;
- r += V->outr * x;
-
- V++;
- }
- tl += tfrq * (l - tl); //treble boost
- tr += tfrq * (r - tr);
- r += treb * (r - tr);
- l += treb * (l - tl);
-
- lfo0 += dlfo * lfo1; //LFO for tremolo and autopan
- lfo1 -= dlfo * lfo0;
- l += l * lmod * lfo1;
- r += r * rmod * lfo1; //worth making all these local variables?
-
- *out0++ += l;
- *out1++ += r;
- }
-
- if(frame<sampleFrames)
- {
- if(activevoices == 0 && programs[curProgram].param[4] > 0.5f)
- { lfo0 = -0.7071f; lfo1 = 0.7071f; } //reset LFO phase - good idea?
- int32_t note = notes[event++];
- int32_t vel = notes[event++];
- noteOn(note, vel);
- }
- }
- if(fabs(tl)<1.0e-10) tl = 0.0f; //anti-denormal
- if(fabs(tr)<1.0e-10) tr = 0.0f;
-
- for(v=0; v<activevoices; v++) if(voice[v].env < SILENCE) voice[v] = voice[--activevoices];
- notes[0] = EVENTS_DONE; //mark events buffer as done
-}
-
-
void mdaEPiano::processReplacing(float **inputs, float **outputs, int32_t sampleFrames)
{
float* out0 = outputs[0];
float* out1 = outputs[1];
- int32_t event=0, frame=0, frames, v;
+ int32_t frame=0, frames, v;
float x, l, r, od=overdrive;
int32_t i;
+ LV2_Atom_Event* ev = lv2_atom_sequence_begin(&eventInput->body);
while(frame<sampleFrames)
{
- frames = notes[event++];
- if(frames>sampleFrames) 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;
@@ -473,16 +406,18 @@ void mdaEPiano::processReplacing(float **inputs, float **outputs, int32_t sample
{
if(activevoices == 0 && programs[curProgram].param[4] > 0.5f)
{ lfo0 = -0.7071f; lfo1 = 0.7071f; } //reset LFO phase - good idea?
- int32_t note = notes[event++];
- int32_t vel = notes[event++];
- noteOn(note, vel);
+
+ if (!end) {
+ processEvent(ev);
+ ev = lv2_atom_sequence_next(ev);
+ }
+
}
}
if(fabs(tl)<1.0e-10) tl = 0.0f; //anti-denormal
if(fabs(tr)<1.0e-10) tr = 0.0f;
for(v=0; v<activevoices; v++) if(voice[v].env < SILENCE) voice[v] = voice[--activevoices];
- notes[0] = EVENTS_DONE; //mark events buffer as done
}
@@ -561,29 +496,23 @@ void mdaEPiano::noteOn(int32_t note, int32_t velocity)
}
-int32_t mdaEPiano::processEvents(LvzEvents* ev)
+int32_t mdaEPiano::processEvent(const LV2_Atom_Event* ev)
{
float * param = programs[curProgram].param;
- int32_t npos=0;
- for (int32_t i=0; i<ev->numEvents; i++)
- {
- if((ev->events[i])->type != kLvzMidiType) continue;
- LvzMidiEvent* event = (LvzMidiEvent*)ev->events[i];
- char* midiData = event->midiData;
+ if (ev->body.type != midiEventType)
+ return 0;
+
+ 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
@@ -608,9 +537,7 @@ int32_t mdaEPiano::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;
@@ -632,10 +559,6 @@ int32_t mdaEPiano::processEvents(LvzEvents* ev)
default: break;
}
- if(npos>EVENTBUFFER) npos -= 3; //discard events if buffer full!!
- event++; //?
- }
- notes[npos] = EVENTS_DONE;
return 1;
}
diff --git a/src/mdaEPiano.h b/src/mdaEPiano.h
index b24c7ce..26056a3 100644
--- a/src/mdaEPiano.h
+++ b/src/mdaEPiano.h
@@ -76,9 +76,7 @@ public:
mdaEPiano(audioMasterCallback audioMaster);
~mdaEPiano();
- virtual void process(float **inputs, float **outputs, int32_t sampleframes);
virtual void processReplacing(float **inputs, float **outputs, int32_t sampleframes);
- virtual int32_t processEvents(LvzEvents* events);
virtual void setProgram(int32_t program);
virtual void setProgramName(char *name);
@@ -98,7 +96,7 @@ public:
virtual bool getVendorString (char* text);
virtual bool getProductString (char* text);
virtual int32_t getVendorVersion () {return 1;}
- virtual int32_t canDo (char* text);
+ virtual int32_t canDo (const char* text);
virtual int32_t getNumMidiInputChannels () { return 1; }
@@ -106,6 +104,7 @@ public:
void guiGetDisplay(int32_t index, char *label);
private:
+ int32_t processEvent(const LV2_Atom_Event* ev);
void update(); //my parameter update
void noteOn(int32_t note, int32_t velocity);
void fillpatch(int32_t p, const char *name, float p0, float p1, float p2, float p3, float p4,
@@ -114,10 +113,6 @@ private:
mdaEPianoProgram* programs;
float Fs, iFs;
- #define EVENTBUFFER 120
- #define EVENTS_DONE 99999999
- int32_t notes[EVENTBUFFER + 8]; //list of delta|note|velocity for current block
-
///global internal variables
KGRP kgrp[34];
VOICE voice[NVOICES];
diff --git a/src/mdaJX10.cpp b/src/mdaJX10.cpp
index 2432fae..c51c946 100644
--- a/src/mdaJX10.cpp
+++ b/src/mdaJX10.cpp
@@ -18,6 +18,8 @@
#include "mdaJX10.h"
+#include "lv2/lv2plug.in/ns/ext/atom/util.h"
+
#include <stdio.h>
#include <stdlib.h> //rand()
#include <math.h>
@@ -154,7 +156,6 @@ mdaJX10::mdaJX10(audioMasterCallback audioMaster) : AudioEffectX(audioMaster, NP
voice[v].f0 = voice[v].f1 = voice[v].f2 = 0.0f;
voice[v].note = 0;
}
- notes[0] = EVENTS_DONE;
lfo = modwhl = filtwhl = press = fzip = 0.0f;
rezwhl = pbend = ipbend = 1.0f;
volume = 0.0005f;
@@ -332,7 +333,7 @@ bool mdaJX10::copyProgram(int32_t destination)
}
-int32_t mdaJX10::canDo(char* text)
+int32_t mdaJX10::canDo(const char* text)
{
if(!strcmp (text, "receiveLvzEvents")) return 1;
if(!strcmp (text, "receiveLvzMidiEvent")) return 1;
@@ -430,178 +431,11 @@ void mdaJX10::getParameterLabel(int32_t index, char *label)
}
}
-
-void mdaJX10::process(float **inputs, float **outputs, int32_t sampleFrames)
-{
- float* out1 = outputs[0];
- float* out2 = outputs[1];
- int32_t event=0, frame=0, frames, v;
- float o, e, vib, pwm, pb=pbend, ipb=ipbend, gl=glide;
- float x, y, hpf=0.997f, min=1.0f, w=0.0f, ww=noisemix;
- float ff, fe=filtenv, fq=filtq * rezwhl, fx=1.97f-0.85f*fq, fz=fzip;
- int32_t k=K;
- unsigned int r;
-
- vib = (float)sin(lfo);
- ff = filtf + filtwhl + (filtlfo + press) * vib; //have to do again here as way that
- pwm = 1.0f + vib * (modwhl + pwmdep); //below triggers on k was too cheap!
- vib = 1.0f + vib * (modwhl + vibrato);
-
- if(activevoices>0 || notes[event]<sampleFrames)
- {
- while(frame<sampleFrames)
- {
- frames = notes[event++];
- if(frames>sampleFrames) frames = sampleFrames;
- frames -= frame;
- frame += frames;
-
- while(--frames>=0)
- {
- VOICE *V = voice;
- o = 0.0f;
-
- noise = (noise * 196314165) + 907633515;
- r = (noise & 0x7FFFFF) + 0x40000000; //generate noise + fast convert to float
- w = *(float *)&r;
- w = ww * (w - 3.0f);
-
- if(--k<0)
- {
- lfo += dlfo;
- if(lfo>PI) lfo -= TWOPI;
- vib = (float)sin(lfo);
- ff = filtf + filtwhl + (filtlfo + press) * vib;
- pwm = 1.0f + vib * (modwhl + pwmdep);
- vib = 1.0f + vib * (modwhl + vibrato);
- k = KMAX;
- }
-
- for(v=0; v<NVOICES; v++) //for each voice
- {
- e = V->env;
- if(e > SILENCE)
- { //Sinc-Loop Oscillator
- x = V->p + V->dp;
- if(x > min)
- {
- if(x > V->pmax)
- {
- x = V->pmax + V->pmax - x;
- V->dp = -V->dp;
- }
- V->p = x;
- x = V->sin0 * V->sinx - V->sin1; //sine osc
- V->sin1 = V->sin0;
- V->sin0 = x;
- x = x / V->p;
- }
- else
- {
- V->p = x = - x;
- V->dp = V->period * vib * pb; //set period for next cycle
- V->pmax = (float)floor(0.5f + V->dp) - 0.5f;
- V->dc = -0.5f * V->lev / V->pmax;
- V->pmax *= PI;
- V->dp = V->pmax / V->dp;
- V->sin0 = V->lev * (float)sin(x);
- V->sin1 = V->lev * (float)sin(x - V->dp);
- V->sinx = 2.0f * (float)cos(V->dp);
- if(x*x > .1f) x = V->sin0 / x; else x = V->lev; //was 0.01f;
- }
-
- y = V->p2 + V->dp2; //osc2
- if(y > min)
- {
- if(y > V->pmax2)
- {
- y = V->pmax2 + V->pmax2 - y;
- V->dp2 = -V->dp2;
- }
- V->p2 = y;
- y = V->sin02 * V->sinx2 - V->sin12;
- V->sin12 = V->sin02;
- V->sin02 = y;
- y = y / V->p2;
- }
- else
- {
- V->p2 = y = - y;
- V->dp2 = V->period * V->detune * pwm * pb;
- V->pmax2 = (float)floor(0.5f + V->dp2) - 0.5f;
- V->dc2 = -0.5f * V->lev2 / V->pmax2;
- V->pmax2 *= PI;
- V->dp2 = V->pmax2 / V->dp2;
- V->sin02 = V->lev2 * (float)sin(y);
- V->sin12 = V->lev2 * (float)sin(y - V->dp2);
- V->sinx2 = 2.0f * (float)cos(V->dp2);
- if(y*y > .1f) y = V->sin02 / y; else y = V->lev2;
- }
- V->saw = V->saw * hpf + V->dc + x - V->dc2 - y; //integrated sinc = saw
- x = V->saw + w;
- V->env += V->envd * (V->envl - V->env);
-
- if(k==KMAX) //filter freq update at LFO rate
- {
- if((V->env+V->envl)>3.0f) { V->envd=dec; V->envl=sus; } //envelopes
- V->fenv += V->fenvd * (V->fenvl - V->fenv);
- if((V->fenv+V->fenvl)>3.0f) { V->fenvd=fdec; V->fenvl=fsus; }
-
- fz += 0.005f * (ff - fz); //filter zipper noise filter
- y = V->fc * (float)exp(fz + fe * V->fenv) * ipb; //filter cutoff
- if(y<0.005f) y=0.005f;
- V->ff = y;
-
- V->period += gl * (V->target - V->period); //glide
- if(V->target < V->period) V->period += gl * (V->target - V->period);
- }
-
- if(V->ff > fx) V->ff = fx; //stability limit
-
- V->f0 += V->ff * V->f1; //state-variable filter
- V->f1 -= V->ff * (V->f0 + fq * V->f1 - x - V->f2);
- V->f1 -= 0.2f * V->f1 * V->f1 * V->f1; //soft limit //was 0.08f
- V->f2 = x;
-
- o += V->env * V->f0;
- }
- V++;
- }
-
- *out1++ += o;
- *out2++ += o;
- }
-
- if(frame<sampleFrames)
- {
- int32_t note = notes[event++];
- int32_t vel = notes[event++];
- noteOn(note, vel);
- }
- }
-
- activevoices = NVOICES;
- for(v=0; v<NVOICES; v++)
- {
- if(voice[v].env<SILENCE) //choke voices
- {
- voice[v].env = voice[v].envl = 0.0f;
- voice[v].f0 = voice[v].f1 = voice[v].f2 = 0.0f;
- activevoices--;
- }
- }
- }
- notes[0] = EVENTS_DONE; //mark events buffer as done
- fzip = fz;
- K = k;
-}
-
-
void mdaJX10::processReplacing(float **inputs, float **outputs, int32_t sampleFrames)
{
float* out1 = outputs[0];
float* out2 = outputs[1];
- int32_t event=0, frame=0, frames, v;
+ int32_t frame=0, frames, v;
float o, e, vib, pwm, pb=pbend, ipb=ipbend, gl=glide;
float x, y, hpf=0.997f, min=1.0f, w=0.0f, ww=noisemix;
float ff, fe=filtenv, fq=filtq * rezwhl, fx=1.97f-0.85f*fq, fz=fzip;
@@ -613,12 +447,14 @@ void mdaJX10::processReplacing(float **inputs, float **outputs, int32_t sampleFr
pwm = 1.0f + vib * (modwhl + pwmdep); //below triggers on k was too cheap!
vib = 1.0f + vib * (modwhl + vibrato);
- if(activevoices>0 || notes[event]<sampleFrames)
+ LV2_Atom_Event* ev = lv2_atom_sequence_begin(&eventInput->body);
+ bool end = lv2_atom_sequence_is_end(&eventInput->body, eventInput->atom.size, ev);
+ if(activevoices>0 || !end)
{
while(frame<sampleFrames)
{
- frames = notes[event++];
- if(frames>sampleFrames) frames = sampleFrames;
+ end = lv2_atom_sequence_is_end(&eventInput->body, eventInput->atom.size, ev);
+ frames = end ? sampleFrames : ev->time.frames;
frames -= frame;
frame += frames;
@@ -739,11 +575,10 @@ void mdaJX10::processReplacing(float **inputs, float **outputs, int32_t sampleFr
*out2++ = o;
}
- if(frame<sampleFrames)
+ if(!end)
{
- int32_t note = notes[event++];
- int32_t vel = notes[event++];
- noteOn(note, vel);
+ processEvent(ev);
+ ev = lv2_atom_sequence_next(ev);
}
}
@@ -766,7 +601,6 @@ void mdaJX10::processReplacing(float **inputs, float **outputs, int32_t sampleFr
*out2++ = 0.0f;
}
}
- notes[0] = EVENTS_DONE; //mark events buffer as done
fzip = fz;
K = k;
}
@@ -912,28 +746,21 @@ void mdaJX10::noteOn(int32_t note, int32_t velocity)
}
-int32_t mdaJX10::processEvents(LvzEvents* ev)
+int32_t mdaJX10::processEvent(const LV2_Atom_Event* ev)
{
- int32_t npos=0;
-
- for (int32_t i=0; i<ev->numEvents; i++)
- {
- if((ev->events[i])->type != kLvzMidiType) continue;
- LvzMidiEvent* event = (LvzMidiEvent*)ev->events[i];
- char* midiData = event->midiData;
+ if (ev->body.type != midiEventType)
+ return 0;
+
+ 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
@@ -963,9 +790,7 @@ int32_t mdaJX10::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);
}
break;
@@ -1001,10 +826,6 @@ int32_t mdaJX10::processEvents(LvzEvents* ev)
default: break;
}
- if(npos>EVENTBUFFER) npos -= 3; //discard events if buffer full!!
- event++;
- }
- notes[npos] = EVENTS_DONE;
return 1;
}
diff --git a/src/mdaJX10.h b/src/mdaJX10.h
index 932ca6d..b918115 100644
--- a/src/mdaJX10.h
+++ b/src/mdaJX10.h
@@ -94,9 +94,7 @@ public:
mdaJX10(audioMasterCallback audioMaster);
~mdaJX10();
- virtual void process(float **inputs, float **outputs, int32_t sampleframes);
virtual void processReplacing(float **inputs, float **outputs, int32_t sampleframes);
- virtual int32_t processEvents(LvzEvents* events);
virtual void setProgram(int32_t program);
virtual void setProgramName(char *name);
@@ -118,9 +116,10 @@ public:
virtual bool getVendorString (char* text);
virtual bool getProductString (char* text);
virtual int32_t getVendorVersion () {return 1;}
- virtual int32_t canDo (char* text);
+ virtual int32_t canDo (const char* text);
private:
+ int32_t processEvent(const LV2_Atom_Event* ev);
void update(); //my parameter update
void noteOn(int32_t note, int32_t velocity);
void fillpatch(int32_t p, const char *name,
@@ -132,9 +131,6 @@ private:
mdaJX10Program* programs;
float Fs;
- #define EVENTBUFFER 120
- #define EVENTS_DONE 99999999
- int32_t notes[EVENTBUFFER + 8]; //list of delta|note|velocity for current block
#define KMAX 32
///global internal variables
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 <stdio.h>
#include <math.h>
@@ -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(frame<sampleFrames)
- {
- frames = notes[event++];
- if(frames>sampleFrames) frames = sampleFrames;
- frames -= frame;
- frame += frames;
-
- while(--frames>=0)
- {
- VOICE *V = voice;
- l = r = 0.0f;
-
- for(v=0; v<activevoices; v++)
- {
- V->frac += 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(frame<sampleFrames)
- {
- int32_t note = notes[event++];
- int32_t vel = notes[event++];
- noteOn(note, vel);
- }
- }
- for(v=0; v<activevoices; v++) if(voice[v].env < SILENCE) voice[v] = voice[--activevoices];
- notes[0] = EVENTS_DONE; //mark events buffer as done
-}
-
-
void mdaPiano::processReplacing(float **inputs, float **outputs, int32_t sampleFrames)
{
float* out0 = outputs[0];
float* out1 = outputs[1];
- int32_t event=0, frame=0, frames, v;
+ int32_t frame=0, frames, v;
float x, l, r;
int32_t i;
+ LV2_Atom_Event* ev = lv2_atom_sequence_begin(&eventInput->body);
while(frame<sampleFrames)
{
- frames = notes[event++];
- if(frames>sampleFrames) 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(frame<sampleFrames)
+ if(!end)
{
- int32_t note = notes[event++];
- int32_t vel = notes[event++];
- noteOn(note, vel);
+ processEvent(ev);
+ ev = lv2_atom_sequence_next(ev);
}
}
for(v=0; v<activevoices; v++) if(voice[v].env < SILENCE) voice[v] = voice[--activevoices];
- notes[0] = EVENTS_DONE; //mark events buffer as done
}
@@ -518,28 +457,21 @@ void mdaPiano::noteOn(int32_t note, int32_t velocity)
}
-int32_t mdaPiano::processEvents(LvzEvents* ev)
+int32_t mdaPiano::processEvent(const LV2_Atom_Event* ev)
{
- int32_t npos=0;
+ if (ev->body.type != midiEventType)
+ return 0;
- for (int32_t i=0; i<ev->numEvents; 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;
}
diff --git a/src/mdaPiano.h b/src/mdaPiano.h
index 1885671..bd6f82a 100644
--- a/src/mdaPiano.h
+++ b/src/mdaPiano.h
@@ -80,9 +80,7 @@ public:
mdaPiano(audioMasterCallback audioMaster);
~mdaPiano();
- virtual void process(float **inputs, float **outputs, int32_t sampleframes);
virtual void processReplacing(float **inputs, float **outputs, int32_t sampleframes);
- virtual int32_t processEvents(LvzEvents* events);
virtual void setProgram(int32_t program);
virtual void setProgramName(char *name);
@@ -102,7 +100,7 @@ public:
virtual bool getVendorString (char* text);
virtual bool getProductString (char* text);
virtual int32_t getVendorVersion () {return 1;}
- virtual int32_t canDo (char* text);
+ virtual int32_t canDo (const char* text);
virtual int32_t getNumMidiInputChannels () { return 1; }
@@ -110,6 +108,7 @@ public:
void guiGetDisplay(int32_t index, char *label);
private:
+ int32_t processEvent(const LV2_Atom_Event* ev);
void update(); //my parameter update
void noteOn(int32_t note, int32_t velocity);
void fillpatch(int32_t p, const char *name, float p0, float p1, float p2, float p3, float p4,
@@ -119,10 +118,6 @@ private:
mdaPianoProgram* programs;
float Fs, iFs;
- #define EVENTBUFFER 120
- #define EVENTS_DONE 99999999
- int32_t notes[EVENTBUFFER + 8]; //list of delta|note|velocity for current block
-
///global internal variables
KGRP kgrp[16];
VOICE voice[NVOICES];