[SCM] calf/master: + Fluidsynth: add master volume control, return current soundfont name, preset name and preset list as status (does not prevent multiple updates yet)

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:39:28 UTC 2013


The following commit has been merged in the master branch:
commit ddbae027a0740dd7aff09a29b11b2d49792aff81
Author: Krzysztof Foltman <wdev at foltman.com>
Date:   Mon Mar 16 00:01:48 2009 +0000

    + Fluidsynth: add master volume control, return current soundfont name, preset name and preset list as status (does not prevent multiple updates yet)

diff --git a/gui/gui-fluidsynth.xml b/gui/gui-fluidsynth.xml
index 6181291..f49cc83 100644
--- a/gui/gui-fluidsynth.xml
+++ b/gui/gui-fluidsynth.xml
@@ -1,11 +1,11 @@
-<table rows="2" cols="3">
-    <!--
+<table rows="3" cols="3">
     <align attach-x="0" attach-y="0"   align-x="1"><label param="master"  /></align>
     <knob attach-x="1" attach-w="1" attach-y="0" shrink-x="1" param="master"  />
     <value param="master"  attach-x="2" attach-y="0" pad-x="10" />
-    -->
 
     <align attach-x="0" attach-y="1"   align-x="1"><label param="soundfont"  /></align>
     <filechooser attach-x="1" attach-w="2" attach-y="1" key="soundfont" title="Select a soundfont" width_chars="30"/>
+    <align attach-x="0" attach-y="2"   align-x="1"><label text="SF Name" /></align>
+    <value attach-x="1" attach-w="2" attach-y="2" key="preset_name" width="30"/>
 </table>
 
diff --git a/src/calf/modules_dev.h b/src/calf/modules_dev.h
index 5b26aba..530b8d4 100644
--- a/src/calf/modules_dev.h
+++ b/src/calf/modules_dev.h
@@ -39,20 +39,37 @@ public:
     float *ins[in_count]; 
     float *outs[out_count];
     float *params[param_count];
+
+protected:
+    /// Current sample rate
     uint32_t srate;
+    /// FluidSynth Settings object
     fluid_settings_t *settings;
+    /// FluidSynth Synth object
     fluid_synth_t *synth;
+    /// Soundfont filename
     std::string soundfont;
+    /// Soundfont filename (as received from Fluidsynth)
+    std::string soundfont_name;
+    /// TAB-separated preset list (preset+128*bank TAB preset name LF)
+    std::string soundfont_preset_list;
+    /// FluidSynth assigned SoundFont ID
     int sfid;
+    /// Map of preset+128*bank to preset name
+    std::map<uint32_t, std::string> sf_preset_names;
+    /// Last selected preset+128*bank
+    uint32_t last_selected_preset;
 
-    /// Constructor to initialize handles to NULL
-    fluidsynth_audio_module();
-
+    /// Update last_selected_preset based on synth object state
+    void update_preset_num();
     /// Create a fluidsynth object and load the current soundfont
     fluid_synth_t *create_synth(int &new_sfid);
+public:
+    /// Constructor to initialize handles to NULL
+    fluidsynth_audio_module();
 
     void post_instantiate();
-    void set_sample_rate(uint32_t sr) {}
+    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);
     /// Handle MIDI Note Off message (by sending it to fluidsynth)
@@ -81,6 +98,7 @@ public:
     /// DSSI-style configure function for handling string port data
     char *configure(const char *key, const char *value);
     void send_configures(send_configure_iface *sci);
+    int send_status_updates(send_updates_iface *sui, int last_serial);
     uint32_t message_run(const void *valid_inputs, void *output_ports) { 
         // silence a default printf (which is kind of a warning about unhandled message_run)
         return 0;
diff --git a/src/fluidsynth.cpp b/src/fluidsynth.cpp
index aa5f798..30d3360 100644
--- a/src/fluidsynth.cpp
+++ b/src/fluidsynth.cpp
@@ -73,6 +73,23 @@ fluid_synth_t *fluidsynth_audio_module::create_synth(int &new_sfid)
         fluid_synth_bank_select(s, 0, 0);
         fluid_synth_program_change(s, 0, 0);
         new_sfid = sid;
+
+        fluid_sfont_t* sfont = fluid_synth_get_sfont(s, 0);
+        soundfont_name = (*sfont->get_name)(sfont);
+
+        sfont->iteration_start(sfont);
+        
+        string preset_list;
+        fluid_preset_t tmp;
+        while(sfont->iteration_next(sfont, &tmp))
+        {
+            string pname = tmp.get_name(&tmp);
+            int bank = tmp.get_banknum(&tmp);
+            int num = tmp.get_num(&tmp);
+            sf_preset_names[num + 128 * bank] = pname;
+            preset_list += calf_utils::i2s(num + 128 * bank) + "\t" + pname + "\n";
+        }
+        soundfont_preset_list = preset_list;
     }
     else
         new_sfid = -1;
@@ -92,15 +109,31 @@ void fluidsynth_audio_module::note_off(int note, int vel)
 void fluidsynth_audio_module::control_change(int controller, int value)
 {
     fluid_synth_cc(synth, 0, controller, value);
+
+    if (controller == 0 || controller == 32)
+        update_preset_num();
 }
 
 void fluidsynth_audio_module::program_change(int program)
 {
     fluid_synth_program_change(synth, 0, program);
+
+    update_preset_num();
+}
+
+
+void fluidsynth_audio_module::update_preset_num()
+{
+    fluid_preset_t *p = fluid_synth_get_channel_preset(synth, 0);
+    if (p)
+        last_selected_preset = p->get_num(p) + 128 * p->get_banknum(p);
+    else
+        last_selected_preset = 0;
 }
 
 uint32_t fluidsynth_audio_module::process(uint32_t offset, uint32_t nsamples, uint32_t inputs_mask, uint32_t outputs_mask)
 {
+    fluid_synth_set_gain(synth, *params[par_master]);
     fluid_synth_write_float(synth, nsamples, outs[0], offset, 1, outs[1], offset, 1);
     return 3;
 }
@@ -118,6 +151,7 @@ char *fluidsynth_audio_module::configure(const char *key, const char *value)
         {
             synth = new_synth;
             sfid = newsfid;
+            update_preset_num();
         }
         else
             return strdup("Cannot load a soundfont");
@@ -131,6 +165,19 @@ void fluidsynth_audio_module::send_configures(send_configure_iface *sci)
     sci->send_configure("soundfont", soundfont.c_str());
 }
 
+int fluidsynth_audio_module::send_status_updates(send_updates_iface *sui, int last_serial)
+{
+    sui->send_status("sf_name", soundfont_name.c_str());
+    sui->send_status("preset_list", soundfont_preset_list.c_str());
+
+    map<uint32_t, string>::const_iterator i = sf_preset_names.find(last_selected_preset);
+    if (i == sf_preset_names.end())
+        sui->send_status("preset_name", "");
+    else
+        sui->send_status("preset_name", i->second.c_str());
+    return last_serial + 1;
+}
+
 fluidsynth_audio_module::~fluidsynth_audio_module()
 {
     if (synth) {

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list