[SCM] calf/master: Add channel number to internal MIDI API. Fix stack overflow in Calf Organ.

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:40:32 UTC 2013


The following commit has been merged in the master branch:
commit 8619763d02016ef490771c6d9da12c9e7fc2f07f
Author: Krzysztof Foltman <wdev at foltman.com>
Date:   Tue Dec 28 18:26:16 2010 +0000

    Add channel number to internal MIDI API. Fix stack overflow in Calf Organ.

diff --git a/src/calf/giface.h b/src/calf/giface.h
index f930a0a..f64908b 100644
--- a/src/calf/giface.h
+++ b/src/calf/giface.h
@@ -388,19 +388,19 @@ extern const char *load_gui_xml(const std::string &plugin_id);
 struct audio_module_iface
 {
     /// Handle MIDI Note On
-    virtual void note_on(int note, int velocity) = 0;
+    virtual void note_on(int channel, int note, int velocity) = 0;
     /// Handle MIDI Note Off
-    virtual void note_off(int note, int velocity) = 0;
+    virtual void note_off(int channel, int note, int velocity) = 0;
     /// Handle MIDI Program Change
-    virtual void program_change(int program) = 0;
+    virtual void program_change(int channel, int program) = 0;
     /// Handle MIDI Control Change
-    virtual void control_change(int controller, int value) = 0;
+    virtual void control_change(int channel, int controller, int value) = 0;
     /// Handle MIDI Pitch Bend
     /// @param value pitch bend value (-8192 to 8191, defined as in MIDI ie. 8191 = 200 ct by default)
-    virtual void pitch_bend(int value) = 0;
+    virtual void pitch_bend(int channel, int value) = 0;
     /// Handle MIDI Channel Pressure
     /// @param value channel pressure (0 to 127)
-    virtual void channel_pressure(int value) = 0;
+    virtual void channel_pressure(int channel, int value) = 0;
     /// Called when params are changed (before processing)
     virtual void params_changed() = 0;
     /// LADSPA-esque activate function, except it is called after ports are connected, not before
@@ -427,9 +427,9 @@ struct audio_module_iface
     virtual const plugin_metadata_iface *get_metadata_iface() const = 0;
     /// Set the progress report interface to communicate progress to
     virtual void set_progress_report_iface(progress_report_iface *iface) = 0;
-    /// Clear a part of output buffers that have 0s at mask
-    virtual void process_slice(uint32_t offset, uint32_t end) = 0;
-    /// The audio processing loop
+    /// Clear a part of output buffers that have 0s at mask; subdivide the buffer so that no runs > MAX_SAMPLE_RUN are fed to process function
+    virtual uint32_t process_slice(uint32_t offset, uint32_t end) = 0;
+    /// The audio processing loop; assumes numsamples <= MAX_SAMPLE_RUN, for larger buffers, call process_slice
     virtual uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask) = 0;
     /// Message port processing function
     virtual uint32_t message_run(const void *valid_ports, void *output_ports) = 0;
@@ -461,19 +461,19 @@ public:
     }
 
     /// Handle MIDI Note On
-    void note_on(int note, int velocity) {}
+    void note_on(int channel, int note, int velocity) {}
     /// Handle MIDI Note Off
-    void note_off(int note, int velocity) {}
+    void note_off(int channel, int note, int velocity) {}
     /// Handle MIDI Program Change
-    void program_change(int program) {}
+    void program_change(int channel, int program) {}
     /// Handle MIDI Control Change
-    void control_change(int controller, int value) {}
+    void control_change(int channel, int controller, int value) {}
     /// Handle MIDI Pitch Bend
     /// @param value pitch bend value (-8192 to 8191, defined as in MIDI ie. 8191 = 200 ct by default)
-    void pitch_bend(int value) {}
+    void pitch_bend(int channel, int value) {}
     /// Handle MIDI Channel Pressure
     /// @param value channel pressure (0 to 127)
-    void channel_pressure(int value) {}
+    void channel_pressure(int channel, int value) {}
     /// Called when params are changed (before processing)
     void params_changed() {}
     /// LADSPA-esque activate function, except it is called after ports are connected, not before
@@ -522,15 +522,18 @@ public:
         }
     }
     /// utility function: call process, and if it returned zeros in output masks, zero out the relevant output port buffers
-    void process_slice(uint32_t offset, uint32_t end)
+    uint32_t process_slice(uint32_t offset, uint32_t end)
     {
+        uint32_t total_out_mask = 0;
         while(offset < end)
         {
             uint32_t newend = std::min(offset + MAX_SAMPLE_RUN, end);
             uint32_t out_mask = process(offset, newend - offset, -1, -1);
+            total_out_mask |= out_mask;
             zero_by_mask(out_mask, offset, newend - offset);
             offset = newend;
         }
+        return total_out_mask;
     }
     /// @return line_graph_iface if any
     virtual const line_graph_iface *get_line_graph_iface() const { return dynamic_cast<const line_graph_iface *>(this); }
diff --git a/src/calf/lv2wrap.h b/src/calf/lv2wrap.h
index 7729330..11239c8 100644
--- a/src/calf/lv2wrap.h
+++ b/src/calf/lv2wrap.h
@@ -130,14 +130,15 @@ struct lv2_instance: public plugin_ctl_iface, public progress_report_iface
             if (item->type == midi_event_type) 
             {
                 // printf("Midi message %x %x %x %x %d\n", item->data[0], item->data[1], item->data[2], item->data[3], item->size);
+                int channel = item->data[0] & 15;
                 switch(item->data[0] >> 4)
                 {
-                case 8: module->note_off(item->data[1], item->data[2]); break;
-                case 9: module->note_on(item->data[1], item->data[2]); break;
-                case 11: module->control_change(item->data[1], item->data[2]); break;
-                case 12: module->program_change(item->data[1]); break;
-                case 13: module->channel_pressure(item->data[1]); break;
-                case 14: module->pitch_bend(item->data[1] + 128 * item->data[2] - 8192); break;
+                case 8: module->note_off(channel, item->data[1], item->data[2]); break;
+                case 9: module->note_on(channel, item->data[1], item->data[2]); break;
+                case 11: module->control_change(channel, item->data[1], item->data[2]); break;
+                case 12: module->program_change(channel, item->data[1]); break;
+                case 13: module->channel_pressure(channel, item->data[1]); break;
+                case 14: module->pitch_bend(channel, item->data[1] + 128 * item->data[2] - 8192); break;
                 }
             }
             else
diff --git a/src/calf/modules.h b/src/calf/modules.h
index b9395c6..19d67e2 100644
--- a/src/calf/modules.h
+++ b/src/calf/modules.h
@@ -230,8 +230,8 @@ public:
     void deactivate();
   
     /// MIDI control
-    virtual void note_on(int note, int vel);
-    virtual void note_off(int note, int vel);
+    virtual void note_on(int channel, int note, int vel);
+    virtual void note_off(int channel, int note, int vel);
     
     bool get_graph(int index, int subindex, float *data, int points, cairo_iface *context) const;
     
diff --git a/src/calf/modules_dev.h b/src/calf/modules_dev.h
index 727e5ec..628fcd5 100644
--- a/src/calf/modules_dev.h
+++ b/src/calf/modules_dev.h
@@ -69,18 +69,18 @@ public:
     void post_instantiate();
     void set_sample_rate(uint32_t sr) { srate = sr; }
     /// Handle MIDI Note On message (by sending it to fluidsynth)
-    void note_on(int note, int vel);
+    void note_on(int channel, int note, int vel);
     /// Handle MIDI Note Off message (by sending it to fluidsynth)
-    void note_off(int note, int vel);
+    void note_off(int channel, int note, int vel);
     /// Handle pitch bend message.
-    inline void pitch_bend(int value)
+    inline void pitch_bend(int channel, int value)
     {
         fluid_synth_pitch_bend(synth, 0, value + 0x2000);
     }
     /// Handle control change messages.
-    void control_change(int controller, int value);
+    void control_change(int channel, int controller, int value);
     /// Handle program change messages.
-    void program_change(int program);
+    void program_change(int channel, int program);
 
     /// Update variables from control ports.
     void params_changed() {
diff --git a/src/calf/modules_mod.h b/src/calf/modules_mod.h
index 7824491..6b57b0b 100644
--- a/src/calf/modules_mod.h
+++ b/src/calf/modules_mod.h
@@ -128,7 +128,7 @@ public:
     /// Increase or decrease aspeed towards raspeed, with required negative and positive rate
     bool incr_towards(float &aspeed, float raspeed, float delta_decc, float delta_acc);
     uint32_t process(uint32_t offset, uint32_t nsamples, uint32_t inputs_mask, uint32_t outputs_mask);
-    virtual void control_change(int ctl, int val);
+    virtual void control_change(int channel, int ctl, int val);
 };
 
 /// A multitap stereo chorus thing
diff --git a/src/calf/modules_synths.h b/src/calf/modules_synths.h
index 2e8dc8e..1611668 100644
--- a/src/calf/modules_synths.h
+++ b/src/calf/modules_synths.h
@@ -127,20 +127,20 @@ public:
     void end_note();
     /// Handle MIDI Note On message (does not immediately trigger a note, as it must start on
     /// boundary of step_size samples).
-    void note_on(int note, int vel);
+    void note_on(int channel, int note, int vel);
     /// Handle MIDI Note Off message
-    void note_off(int note, int vel);
+    void note_off(int channel, int note, int vel);
     /// Handle MIDI Channel Pressure
-    void channel_pressure(int value);
+    void channel_pressure(int channel, int value);
     /// Handle pitch bend message.
-    inline void pitch_bend(int value)
+    inline void pitch_bend(int /*channel*/, int value)
     {
         inertia_pitchbend.set_inertia(pow(2.0, (value * *params[par_pwhlrange]) / (1200.0 * 8192.0)));
     }
     /// Update oscillator frequency based on base frequency, detune amount, pitch bend scaling factor and sample rate.
     void set_frequency();
     /// Handle control change messages.
-    void control_change(int controller, int value);
+    void control_change(int channel, int controller, int value);
     /// Update variables from control ports.
     void params_changed();
     void activate();
diff --git a/src/calf/organ.h b/src/calf/organ.h
index efb3913..ac41599 100644
--- a/src/calf/organ.h
+++ b/src/calf/organ.h
@@ -321,10 +321,10 @@ public:
     uint32_t message_run(const void *valid_inputs, void *output_ports);
 public:
     // overrides
-    virtual void note_on(int note, int velocity) { dsp::drawbar_organ::note_on(note, velocity); }
-    virtual void note_off(int note, int velocity) { dsp::drawbar_organ::note_off(note, velocity); }
-    virtual void control_change(int controller, int value) { dsp::drawbar_organ::control_change(controller, value); }
-    virtual void pitch_bend(int value) { dsp::drawbar_organ::pitch_bend(value); }
+    virtual void note_on(int /*channel*/, int note, int velocity) { dsp::drawbar_organ::note_on(note, velocity); }
+    virtual void note_off(int /*channel*/, int note, int velocity) { dsp::drawbar_organ::note_off(note, velocity); }
+    virtual void control_change(int /*channel*/, int controller, int value) { dsp::drawbar_organ::control_change(controller, value); }
+    virtual void pitch_bend(int /*channel*/, int value) { dsp::drawbar_organ::pitch_bend(value); }
 };
 
 };
diff --git a/src/calf/wavetable.h b/src/calf/wavetable.h
index 5c4492c..836585a 100644
--- a/src/calf/wavetable.h
+++ b/src/calf/wavetable.h
@@ -149,10 +149,13 @@ public:
         inertia_pitchbend.ramp.set_length(crate / 30); // 1/30s    
         inertia_pressure.ramp.set_length(crate / 30); // 1/30s - XXXKF monosynth needs that too
     }
+    virtual void note_on(int /*channel*/, int note, int velocity) { dsp::basic_synth::note_on(note, velocity); }
+    virtual void note_off(int /*channel*/, int note, int velocity) { dsp::basic_synth::note_off(note, velocity); }
+    virtual void control_change(int /*channel*/, int controller, int value) { dsp::basic_synth::control_change(controller, value); }
     /// Handle MIDI Channel Pressure
-    void channel_pressure(int value);
+    virtual void channel_pressure(int channel, int value);
     /// Handle pitch bend message.
-    inline void pitch_bend(int value)
+    virtual void pitch_bend(int channel, int value)
     {
         inertia_pitchbend.set_inertia(pow(2.0, (value * *params[par_pwhlrange]) / (1200.0 * 8192.0)));
     }
diff --git a/src/fluidsynth.cpp b/src/fluidsynth.cpp
index 6279434..bd4dc4d 100644
--- a/src/fluidsynth.cpp
+++ b/src/fluidsynth.cpp
@@ -101,27 +101,27 @@ fluid_synth_t *fluidsynth_audio_module::create_synth(int &new_sfid)
     return s;
 }
 
-void fluidsynth_audio_module::note_on(int note, int vel)
+void fluidsynth_audio_module::note_on(int channel, int note, int vel)
 {
-    fluid_synth_noteon(synth, 0, note, vel);
+    fluid_synth_noteon(synth, channel, note, vel);
 }
 
-void fluidsynth_audio_module::note_off(int note, int vel)
+void fluidsynth_audio_module::note_off(int channel, int note, int vel)
 {
-    fluid_synth_noteoff(synth, 0, note);
+    fluid_synth_noteoff(synth, channel, note);
 }
 
-void fluidsynth_audio_module::control_change(int controller, int value)
+void fluidsynth_audio_module::control_change(int channel, int controller, int value)
 {
-    fluid_synth_cc(synth, 0, controller, value);
+    fluid_synth_cc(synth, channel, controller, value);
 
     if (controller == 0 || controller == 32)
         update_preset_num();
 }
 
-void fluidsynth_audio_module::program_change(int program)
+void fluidsynth_audio_module::program_change(int channel, int program)
 {
-    fluid_synth_program_change(synth, 0, program);
+    fluid_synth_program_change(synth, channel, program);
 
     update_preset_num();
 }
diff --git a/src/jackhost.cpp b/src/jackhost.cpp
index d717d8a..c20431a 100644
--- a/src/jackhost.cpp
+++ b/src/jackhost.cpp
@@ -130,30 +130,31 @@ void jack_host::create_ports() {
 
 void jack_host::handle_event(uint8_t *buffer, uint32_t size)
 {
+    int channel = buffer[0] & 15;
     int value;
     switch(buffer[0] >> 4)
     {
     case 8:
-        module->note_off(buffer[1], buffer[2]);
+        module->note_off(channel, buffer[1], buffer[2]);
         break;
     case 9:
         if (!buffer[2])
-            module->note_off(buffer[1], 0);
+            module->note_off(channel, buffer[1], 0);
         else
-            module->note_on(buffer[1], buffer[2]);
+            module->note_on(channel, buffer[1], buffer[2]);
         break;
     case 11:
-        module->control_change(buffer[1], buffer[2]);
+        module->control_change(channel, buffer[1], buffer[2]);
         break;
     case 12:
-        module->program_change(buffer[1]);
+        module->program_change(channel, buffer[1]);
         break;
     case 13:
-        module->channel_pressure(buffer[1]);
+        module->channel_pressure(channel, buffer[1]);
         break;
     case 14:
         value = buffer[1] + 128 * buffer[2] - 8192;
-        module->pitch_bend(value);
+        module->pitch_bend(channel, value);
         break;
     }
 }
@@ -181,7 +182,7 @@ void jack_host::process_part(unsigned int time, unsigned int len)
         return;
     for (int i = 0; i < in_count; i++)
         inputs[i].meter.update(ins[i] + time, len);
-    unsigned int mask = module->process(time, len, -1, -1);
+    unsigned int mask = module->process_slice(time, time + len);
     for (int i = 0; i < out_count; i++)
     {
         if (!(mask & (1 << i))) {
diff --git a/src/modules.cpp b/src/modules.cpp
index ab2d44e..c10e0e0 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -380,7 +380,7 @@ void filterclavier_audio_module::deactivate()
 }
 
 
-void filterclavier_audio_module::note_on(int note, int vel)
+void filterclavier_audio_module::note_on(int channel, int note, int vel)
 {
     last_note     = note;
     last_velocity = vel;
@@ -401,7 +401,7 @@ void filterclavier_audio_module::note_on(int note, int vel)
     inertia_filter_module::calculate_filter();
 }
 
-void filterclavier_audio_module::note_off(int note, int vel)
+void filterclavier_audio_module::note_off(int channel, int note, int vel)
 {
     if (note == last_note) {
         inertia_filter_module::inertia_resonance.set_inertia(param_props[par_max_resonance].min);
diff --git a/src/modules_mod.cpp b/src/modules_mod.cpp
index f9716c2..063027e 100644
--- a/src/modules_mod.cpp
+++ b/src/modules_mod.cpp
@@ -231,7 +231,7 @@ void rotary_speaker_audio_module::deactivate()
 {
 }
 
-void rotary_speaker_audio_module::control_change(int ctl, int val)
+void rotary_speaker_audio_module::control_change(int /*channel*/, int ctl, int val)
 {
     if (vibrato_mode == 3 && ctl == 64)
     {
diff --git a/src/monosynth.cpp b/src/monosynth.cpp
index a277ae1..97248c2 100644
--- a/src/monosynth.cpp
+++ b/src/monosynth.cpp
@@ -607,7 +607,7 @@ void monosynth_audio_module::apply_fadeout()
     }
 }
 
-void monosynth_audio_module::note_on(int note, int vel)
+void monosynth_audio_module::note_on(int /*channel*/, int note, int vel)
 {
     queue_note_on = note;
     queue_note_on_and_off = false;
@@ -616,7 +616,7 @@ void monosynth_audio_module::note_on(int note, int vel)
     stack.push(note);
 }
 
-void monosynth_audio_module::note_off(int note, int vel)
+void monosynth_audio_module::note_off(int /*channel*/, int note, int vel)
 {
     stack.pop(note);
     if (note == queue_note_on)
@@ -653,12 +653,12 @@ void monosynth_audio_module::end_note()
     envelope2.note_off();
 }
 
-void monosynth_audio_module::channel_pressure(int value)
+void monosynth_audio_module::channel_pressure(int /*channel*/, int value)
 {
     inertia_pressure.set_inertia(value * (1.0 / 127.0));
 }
 
-void monosynth_audio_module::control_change(int controller, int value)
+void monosynth_audio_module::control_change(int /*channel*/, int controller, int value)
 {
     switch(controller)
     {
diff --git a/src/organ.cpp b/src/organ.cpp
index c885eaf..3435607 100644
--- a/src/organ.cpp
+++ b/src/organ.cpp
@@ -994,7 +994,7 @@ void organ_audio_module::deactivate()
 
 void drawbar_organ::render_separate(float *output[], int nsamples)
 {
-    float buf[4096][2];
+    float buf[MAX_SAMPLE_RUN][2];
     dsp::zero(&buf[0][0], 2 * nsamples);
     basic_synth::render_to(buf, nsamples);
     if (dsp::fastf2i_drm(parameters->lfo_mode) == organ_voice_base::lfomode_global)
diff --git a/src/plugin.cpp b/src/plugin.cpp
index 1c86636..2f78bc9 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -189,22 +189,22 @@ void ladspa_instance::process_dssi_event(snd_seq_event_t &event)
 {
     switch(event.type) {
         case SND_SEQ_EVENT_NOTEON:
-            module->note_on(event.data.note.note, event.data.note.velocity);
+            module->note_on(event.data.note.channel, event.data.note.note, event.data.note.velocity);
             break;
         case SND_SEQ_EVENT_NOTEOFF:
-            module->note_off(event.data.note.note, event.data.note.velocity);
+            module->note_off(event.data.note.channel, event.data.note.note, event.data.note.velocity);
             break;
         case SND_SEQ_EVENT_PGMCHANGE:
-            module->program_change(event.data.control.value);
+            module->program_change(event.data.control.channel, event.data.control.value);
             break;
         case SND_SEQ_EVENT_CONTROLLER:
-            module->control_change(event.data.control.param, event.data.control.value);
+            module->control_change(event.data.control.channel, event.data.control.param, event.data.control.value);
             break;
         case SND_SEQ_EVENT_PITCHBEND:
-            module->pitch_bend(event.data.control.value);
+            module->pitch_bend(event.data.control.channel, event.data.control.value);
             break;
         case SND_SEQ_EVENT_CHANPRESS:
-            module->channel_pressure(event.data.control.value);
+            module->channel_pressure(event.data.control.channel, event.data.control.value);
             break;
     }
 }
diff --git a/src/wavetable.cpp b/src/wavetable.cpp
index e5ef259..271fc3e 100644
--- a/src/wavetable.cpp
+++ b/src/wavetable.cpp
@@ -544,7 +544,7 @@ wavetable_audio_module::wavetable_audio_module()
     }
 }
 
-void wavetable_audio_module::channel_pressure(int value)
+void wavetable_audio_module::channel_pressure(int /*channel*/, int value)
 {
     inertia_pressure.set_inertia(value * (1.0 / 127.0));
 }

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list