[SCM] calf/master: + framework: refactored event handling (now handled by separate functions note_on, note_off, control_change, program_change, pitch_bend)
js at users.alioth.debian.org
js at users.alioth.debian.org
Tue May 7 15:36:44 UTC 2013
The following commit has been merged in the master branch:
commit 2e10a6b8c05b1360433647a5307b3deff7c8e953
Author: kfoltman <kfoltman at 78b06b96-2940-0410-b7fc-879d825d01d8>
Date: Fri Dec 14 21:45:21 2007 +0000
+ framework: refactored event handling (now handled by separate functions note_on, note_off, control_change, program_change, pitch_bend)
git-svn-id: https://calf.svn.sourceforge.net/svnroot/calf/trunk@20 78b06b96-2940-0410-b7fc-879d825d01d8
diff --git a/src/calf/giface.h b/src/calf/giface.h
index 0dd32d6..0869687 100644
--- a/src/calf/giface.h
+++ b/src/calf/giface.h
@@ -319,19 +319,21 @@ struct ladspa_wrapper
static void process_dssi_event(Module *module, snd_seq_event_t &event)
{
- uint8_t data[4];
switch(event.type) {
case SND_SEQ_EVENT_NOTEON:
- data[0] = 0x90 + event.data.note.channel;
- data[1] = event.data.note.note;
- data[2] = event.data.note.velocity;
- module->handle_event(data, 3);
+ module->note_on(event.data.note.note, event.data.note.velocity);
break;
case SND_SEQ_EVENT_NOTEOFF:
- data[0] = 0x80 + event.data.note.channel;
- data[1] = event.data.note.note;
- data[2] = event.data.note.velocity;
- module->handle_event(data, 3);
+ module->note_off(event.data.note.note, event.data.note.velocity);
+ break;
+ case SND_SEQ_EVENT_PGMCHANGE:
+ module->program_change(event.data.control.value);
+ break;
+ case SND_SEQ_EVENT_CONTROLLER:
+ module->control_change(event.data.control.param, event.data.control.value);
+ break;
+ case SND_SEQ_EVENT_PITCHBEND:
+ module->pitch_bend(event.data.control.value);
break;
}
}
diff --git a/src/calf/jackhost.h b/src/calf/jackhost.h
index d7b9f6a..85dccd1 100644
--- a/src/calf/jackhost.h
+++ b/src/calf/jackhost.h
@@ -155,8 +155,31 @@ public:
module.params_changed();
}
- virtual synth::parameter_properties* get_param_props(int param_no) { return Module::param_props; }
+ virtual synth::parameter_properties* get_param_props(int param_no) { return Module::param_props + param_no; }
+ static void handle_event(Module *module, uint8_t *buffer, uint32_t size)
+ {
+ int value;
+ switch(buffer[0] >> 4)
+ {
+ case 8:
+ module->note_off(buffer[1], buffer[2]);
+ break;
+ case 9:
+ module->note_on(buffer[1], buffer[2]);
+ break;
+ case 10:
+ module->program_change(buffer[1]);
+ break;
+ case 11:
+ module->control_change(buffer[1], buffer[2]);
+ break;
+ case 14:
+ value = buffer[1] + 128 * buffer[2] - 8192;
+ module->pitch_bend(value);
+ break;
+ }
+ }
static int do_jack_process(jack_nframes_t nframes, void *p) {
jack_host *host = (jack_host *)p;
Module *module = &host->module;
@@ -193,7 +216,7 @@ public:
dsp::zero(module->outs[i] + time, event.time - time);
}
- module->handle_event(event.buffer, event.size);
+ handle_event(module, event.buffer, event.size);
time = event.time;
}
diff --git a/src/calf/modules.h b/src/calf/modules.h
index ea8d813..b7b5da5 100644
--- a/src/calf/modules.h
+++ b/src/calf/modules.h
@@ -30,16 +30,21 @@ namespace synth {
using namespace dsp;
-inline void default_handle_event(uint8_t *data, int len, float *params[], unsigned int param_count)
+class null_audio_module
{
- if (data[0] == 0x7F && len >= 8) {
- midi_event *p = (midi_event *)data;
- if (p->param2 < param_count)
- *params[p->param2] = p->param3;
- }
-}
+public:
+ inline void note_on(int note, int velocity) {}
+ inline void note_off(int note, int velocity) {}
+ inline void program_change(int program) {}
+ inline void control_change(int controller, int value) {}
+ inline void pitch_bend(int value) {} // -8192 to 8191
+ inline void params_changed() {}
+ inline void activate() {}
+ inline void deactivate() {}
+ inline void set_sample_rate(uint32_t sr) { }
+};
-class amp_audio_module
+class amp_audio_module: public null_audio_module
{
public:
enum { in_count = 2, out_count = 2, param_count = 1, support_midi = false, rt_capable = true };
@@ -49,17 +54,6 @@ public:
uint32_t srate;
static const char *param_names[];
static parameter_properties param_props[];
- void set_sample_rate(uint32_t sr) {
- }
- void handle_event(uint8_t *data, int len) {
- default_handle_event(data, len, params, param_count);
- }
- void params_changed() {
- }
- void activate() {
- }
- void deactivate() {
- }
uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask) {
if (!inputs_mask)
return 0;
@@ -73,7 +67,7 @@ public:
}
};
-class flanger_audio_module
+class flanger_audio_module: public null_audio_module
{
public:
enum { par_delay, par_depth, par_rate, par_fb, par_amount, param_count };
@@ -90,9 +84,6 @@ public:
left.setup(sr);
right.setup(sr);
}
- void handle_event(uint8_t *data, int len) {
- default_handle_event(data, len, params, param_count);
- }
void params_changed() {
float dry = 1.0;
float wet = *params[par_amount];
@@ -120,7 +111,7 @@ public:
}
};
-class reverb_audio_module
+class reverb_audio_module: public null_audio_module
{
public:
enum { par_decay, par_hfdamp, par_amount, param_count };
@@ -144,9 +135,6 @@ public:
}
void deactivate() {
}
- void handle_event(uint8_t *data, int len) {
- default_handle_event(data, len, params, param_count);
- }
void set_sample_rate(uint32_t sr) {
srate = sr;
reverb.setup(sr);
@@ -165,7 +153,7 @@ public:
}
};
-class filter_audio_module
+class filter_audio_module: public null_audio_module
{
public:
enum { par_cutoff, par_resonance, par_mode, par_inertia, param_count };
@@ -235,9 +223,6 @@ public:
}
void deactivate() {
}
- void handle_event(uint8_t *data, int len) {
- default_handle_event(data, len, params, param_count);
- }
void set_sample_rate(uint32_t sr) {
srate = sr;
params_changed();
diff --git a/src/calf/modules_dev.h b/src/calf/modules_dev.h
index 54cb481..b9c2d89 100644
--- a/src/calf/modules_dev.h
+++ b/src/calf/modules_dev.h
@@ -36,7 +36,7 @@ using namespace dsp;
/// Monosynth-in-making. Parameters may change at any point, so don't make songs with it!
/// It lacks inertia for parameters, even for those that really need it.
-class monosynth_audio_module
+class monosynth_audio_module: public null_audio_module
{
public:
enum { wave_saw, wave_sqr, wave_pulse, wave_sine, wave_triangle, wave_count };
@@ -72,7 +72,7 @@ public:
crate = sr / step_size;
odcr = (float)(1.0 / crate);
}
- void note_on()
+ void delayed_note_on()
{
freq = 440 * pow(2.0, (queue_note_on - 69) / 12.0);
ampctl = 1.0 + (queue_vel - 1.0) * *params[par_vel2amp];
@@ -119,28 +119,20 @@ public:
voice_age = 0;
queue_note_on = -1;
}
- void handle_event(uint8_t *data, int len) {
- switch(*data >> 4)
- {
- case 9:
- if (data[2]) {
- queue_note_on = data[1];
- last_key = data[1];
- queue_vel = data[2] / 127.f;
- }
- // printf("note on %d %d\n", data[1], data[2]);
- break;
- case 8:
- // printf("note off %d %d\n", data[1], data[2]);
- if (data[1] == last_key)
- gate = false;
- break;
- case 14:
- float value = data[1] + 128 *data[2] - 8192;
- pitchbend = pow(2.0, value / 8192.0);
- break;
- }
- default_handle_event(data, len, params, param_count);
+ void note_on(int note, int vel)
+ {
+ queue_note_on = note;
+ last_key = note;
+ queue_vel = vel / 127.f;
+ }
+ void note_off(int note, int vel)
+ {
+ if (note == last_key)
+ gate = false;
+ }
+ void pitch_bend(int value)
+ {
+ pitchbend = pow(2.0, value / 8192.0);
}
void set_frequency()
{
@@ -252,7 +244,7 @@ public:
}
void calculate_step() {
if (queue_note_on != -1)
- note_on();
+ delayed_note_on();
else if (stopping)
{
running = false;
@@ -373,9 +365,12 @@ public:
}
};
-struct organ_audio_module: public drawbar_organ
+struct organ_audio_module: public null_audio_module, public drawbar_organ
{
public:
+ using drawbar_organ::note_on;
+ using drawbar_organ::note_off;
+ using drawbar_organ::control_change;
enum { par_drawbar1, par_drawbar2, par_drawbar3, par_drawbar4, par_drawbar5, par_drawbar6, par_drawbar7, par_drawbar8, par_drawbar9, par_foldover,
par_percmode, par_percharm, par_vibrato, par_master, param_count };
enum { in_count = 0, out_count = 2, support_midi = true, rt_capable = true };
@@ -394,21 +389,6 @@ public:
void set_sample_rate(uint32_t sr) {
srate = sr;
}
- void handle_event(uint8_t *data, int len) {
- switch(*data >> 4)
- {
- case 9:
- note_on(data[1], data[2]);
- break;
- case 8:
- note_off(data[1], data[2]);
- break;
- case 11:
- control_change(data[1], data[2]);
- break;
- }
- default_handle_event(data, len, params, param_count);
- }
void params_changed() {
for (int i = 0; i < param_count; i++)
((float *)&par_values)[i] = *params[i];
--
calf audio plugins packaging
More information about the pkg-multimedia-commits
mailing list