[SCM] calf/master: + GUI, LADSPA, DSSI, standalone: more cleanups, global preset lists changed to local static variables inside getter functions + Monosynth: do not leak waveforms

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:37:23 UTC 2013


The following commit has been merged in the master branch:
commit 4b76bec048af84c6674eea660b1f60fa38838909
Author: kfoltman <kfoltman at 78b06b96-2940-0410-b7fc-879d825d01d8>
Date:   Fri Jul 4 21:25:44 2008 +0000

    + GUI, LADSPA, DSSI, standalone: more cleanups, global preset lists changed to local static variables inside getter functions
    + Monosynth: do not leak waveforms
    
    
    git-svn-id: https://calf.svn.sourceforge.net/svnroot/calf/trunk@221 78b06b96-2940-0410-b7fc-879d825d01d8

diff --git a/src/calf/giface.h b/src/calf/giface.h
index ff8bf76..e9c54f5 100644
--- a/src/calf/giface.h
+++ b/src/calf/giface.h
@@ -260,6 +260,19 @@ struct ladspa_wrapper
     {
         init_descriptor(i);
     }
+    
+    ~ladspa_wrapper()
+    {
+        delete []descriptor.PortNames;
+        delete []descriptor.PortDescriptors;
+        delete []descriptor.PortRangeHints;
+#if USE_DSSI
+        presets->clear();
+        preset_descs->clear();
+        delete presets;
+        delete preset_descs;
+#endif
+    }
 
     void init_descriptor(ladspa_info &inf)
     {
diff --git a/src/calf/organ.h b/src/calf/organ.h
index 2201c82..82fcc84 100644
--- a/src/calf/organ.h
+++ b/src/calf/organ.h
@@ -131,8 +131,8 @@ public:
     typedef waveform_family<ORGAN_WAVE_BITS> small_wave_family;
     typedef waveform_family<ORGAN_BIG_WAVE_BITS> big_wave_family;
 protected:
-    static small_wave_family waves[wave_count_small];
-    static big_wave_family big_waves[wave_count_big];
+    static small_wave_family (*waves)[wave_count_small];
+    static big_wave_family (*big_waves)[wave_count_big];
 
     // dsp::sine_table<float, ORGAN_WAVE_SIZE, 1> sine_wave;
     int note;
@@ -150,10 +150,10 @@ protected:
 public:
     organ_parameters *parameters;
     static inline small_wave_family &get_wave(int wave) {
-        return waves[wave];
+        return (*waves)[wave];
     }
     static inline big_wave_family &get_big_wave(int wave) {
-        return big_waves[wave];
+        return (*big_waves)[wave];
     }
     static void precalculate_waves();
 };
@@ -285,7 +285,7 @@ public:
         int timbre = parameters->get_percussion_timbre();
         if (timbre < 0 || timbre >= (int)(sizeof(wave_ids) / sizeof(wave_ids[0])))
             return;
-        float *data = waves[wave_ids[timbre]].get_level(dphase.get());
+        float *data = (*waves)[wave_ids[timbre]].get_level(dphase.get());
         if (!data)
             return;
         if (timbre < 3)
diff --git a/src/calf/preset.h b/src/calf/preset.h
index e84b02c..8855cfd 100644
--- a/src/calf/preset.h
+++ b/src/calf/preset.h
@@ -97,7 +97,8 @@ protected:
     static void xml_end_element_handler(void *user_data, const char *name);
 };
 
-extern preset_list builtin_presets, user_presets;
+extern preset_list &get_builtin_presets();
+extern preset_list &get_user_presets();
 
 };
 
diff --git a/src/dssigui.cpp b/src/dssigui.cpp
index ac2d940..7d8bb46 100644
--- a/src/dssigui.cpp
+++ b/src/dssigui.cpp
@@ -252,8 +252,8 @@ struct dssi_osc_server: public osc_server, public osc_message_sink<osc_strstream
         plugin->gui = window->gui;
         gtk_signal_connect(GTK_OBJECT(window->toplevel), "destroy", G_CALLBACK(on_destroy), this);
         vector<plugin_preset> tmp_presets;
-        builtin_presets.get_for_plugin(presets, effect_name.c_str());
-        user_presets.get_for_plugin(tmp_presets, effect_name.c_str());
+        get_builtin_presets().get_for_plugin(presets, effect_name.c_str());
+        get_user_presets().get_for_plugin(tmp_presets, effect_name.c_str());
         presets.insert(presets.end(), tmp_presets.begin(), tmp_presets.end());
     }
     
@@ -365,8 +365,8 @@ int main(int argc, char *argv[])
     }
 
     try {
-        builtin_presets.load_defaults(true);
-        user_presets.load_defaults(false);
+        get_builtin_presets().load_defaults(true);
+        get_user_presets().load_defaults(false);
     }
     catch(synth::preset_exception &e)
     {
diff --git a/src/gui.cpp b/src/gui.cpp
index 5c04dba..4aa56c5 100644
--- a/src/gui.cpp
+++ b/src/gui.cpp
@@ -880,7 +880,7 @@ plugin_gui_window::plugin_gui_window(main_window_iface *_main)
 string plugin_gui_window::make_gui_preset_list(GtkActionGroup *grp, bool builtin)
 {
     string preset_xml = string(general_preset_pre_xml) + (builtin ? builtin_preset_pre_xml : user_preset_pre_xml);
-    preset_vector &pvec = (builtin ? builtin_presets : user_presets).presets;
+    preset_vector &pvec = (builtin ? get_builtin_presets() : get_user_presets()).presets;
     GtkActionGroup *preset_actions = builtin ? builtin_preset_actions : user_preset_actions;
     for (unsigned int i = 0; i < pvec.size(); i++)
     {
diff --git a/src/jackhost.cpp b/src/jackhost.cpp
index 0f4515c..7e60862 100644
--- a/src/jackhost.cpp
+++ b/src/jackhost.cpp
@@ -261,7 +261,7 @@ void host_session::remove_plugin(plugin_ctl_iface *plugin)
 bool host_session::activate_preset(int plugin_no, const std::string &preset, bool builtin)
 {
     string cur_plugin = plugins[plugin_no]->get_id();
-    preset_vector &pvec = (builtin ? builtin_presets : user_presets).presets;
+    preset_vector &pvec = (builtin ? get_builtin_presets() : get_user_presets()).presets;
     for (unsigned int i = 0; i < pvec.size(); i++) {
         if (pvec[i].name == preset && pvec[i].plugin == cur_plugin)
         {
@@ -533,8 +533,8 @@ int main(int argc, char *argv[])
         }
     }
     try {
-        builtin_presets.load_defaults(true);
-        user_presets.load_defaults(false);
+        get_builtin_presets().load_defaults(true);
+        get_user_presets().load_defaults(false);
     }
     catch(synth::preset_exception &e)
     {
diff --git a/src/monosynth.cpp b/src/monosynth.cpp
index 49b321c..10f695d 100644
--- a/src/monosynth.cpp
+++ b/src/monosynth.cpp
@@ -250,7 +250,9 @@ void monosynth_audio_module::generate_waves()
     if (waves)
         return;
     
-    waves = new waveform_family<MONOSYNTH_WAVE_BITS>[wave_count];
+    static waveform_family<MONOSYNTH_WAVE_BITS> waves_data[wave_count];
+    waves = waves_data;
+    
     enum { S = 1 << MONOSYNTH_WAVE_BITS, HS = S / 2, QS = S / 4, QS3 = 3 * QS };
     float iQS = 1.0 / QS;
     
diff --git a/src/organ.cpp b/src/organ.cpp
index 7498447..d04c14e 100644
--- a/src/organ.cpp
+++ b/src/organ.cpp
@@ -491,8 +491,8 @@ parameter_properties organ_audio_module::param_props[] = {
 
 ////////////////////////////////////////////////////////////////////////////
 
-organ_voice_base::small_wave_family organ_voice_base::waves[organ_voice_base::wave_count_small];
-organ_voice_base::big_wave_family organ_voice_base::big_waves[organ_voice_base::wave_count_big];
+organ_voice_base::small_wave_family (*organ_voice_base::waves)[organ_voice_base::wave_count_small];
+organ_voice_base::big_wave_family (*organ_voice_base::big_waves)[organ_voice_base::wave_count_big];
 
 static void smoothen(bandlimiter<ORGAN_WAVE_BITS> &bl, float tmp[ORGAN_WAVE_SIZE])
 {
@@ -601,6 +601,11 @@ void organ_voice_base::precalculate_waves()
     static bool inited = false;
     if (!inited)
     {
+        static organ_voice_base::small_wave_family waves[organ_voice_base::wave_count_small];
+        static organ_voice_base::big_wave_family big_waves[organ_voice_base::wave_count_big];
+        organ_voice_base::waves = &waves;
+        organ_voice_base::big_waves = &big_waves;
+        
         float tmp[ORGAN_WAVE_SIZE];
         static bandlimiter<ORGAN_WAVE_BITS> bl;
         static bandlimiter<ORGAN_BIG_WAVE_BITS> blBig;
@@ -910,7 +915,7 @@ void organ_voice::render_block() {
         uint32_t rate = (dphase * hm).get();
         if (waveid >= wave_count_small)
         {
-            float *data = big_waves[waveid - wave_count_small].get_level(rate >> (ORGAN_BIG_WAVE_BITS - ORGAN_WAVE_BITS + ORGAN_BIG_WAVE_SHIFT));
+            float *data = (*big_waves)[waveid - wave_count_small].get_level(rate >> (ORGAN_BIG_WAVE_BITS - ORGAN_WAVE_BITS + ORGAN_BIG_WAVE_SHIFT));
             if (!data)
                 continue;
             hm.set(hm.get() >> ORGAN_BIG_WAVE_SHIFT);
@@ -937,7 +942,7 @@ void organ_voice::render_block() {
                 foldback++;
             }
             hm.set(hm.get() >> foldback);
-            data = waves[waveid].get_level(rate);
+            data = (*waves)[waveid].get_level(rate);
             if (!data)
                 continue;
             tphase.set((uint32_t)((phase * hm).get()) + parameters->phaseshift[h]);
diff --git a/src/preset.cpp b/src/preset.cpp
index af0b6d3..fd7b674 100644
--- a/src/preset.cpp
+++ b/src/preset.cpp
@@ -33,7 +33,17 @@
 using namespace synth;
 using namespace std;
 
-synth::preset_list synth::builtin_presets, synth::user_presets;
+extern synth::preset_list &synth::get_builtin_presets()
+{
+    static synth::preset_list plist;
+    return plist;
+}
+
+extern synth::preset_list &synth::get_user_presets()
+{
+    static synth::preset_list plist;
+    return plist;
+}
 
 std::string plugin_preset::to_xml()
 {
@@ -215,8 +225,11 @@ void preset_list::parse(const std::string &data)
     XML_SetUserData(parser, this);
     XML_SetElementHandler(parser, xml_start_element_handler, xml_end_element_handler);
     XML_Status status = XML_Parse(parser, data.c_str(), data.length(), 1);
-    if (status == XML_STATUS_ERROR)
-        throw preset_exception(string("Parse error: ") + XML_ErrorString(XML_GetErrorCode(parser))+ " in ", "string", errno);
+    if (status == XML_STATUS_ERROR) {
+        string err = string("Parse error: ") + XML_ErrorString(XML_GetErrorCode(parser))+ " in ";
+        XML_ParserFree(parser);
+        throw preset_exception(err, "string", errno);
+    }
     XML_ParserFree(parser);
 }
 
@@ -241,9 +254,13 @@ void preset_list::load(const char *filename)
             throw preset_exception(string("Parse error: ") + XML_ErrorString(XML_GetErrorCode(parser))+ " in ", filename, errno);
     } while(1);
     XML_Status status = XML_Parse(parser, buf, 0, 1);
-    if (status == XML_STATUS_ERROR)
-        throw preset_exception(string("Parse error: ") + XML_ErrorString(XML_GetErrorCode(parser))+ " in ", filename, errno);
     close(fd);
+    if (status == XML_STATUS_ERROR)
+    {
+        string err = string("Parse error: ") + XML_ErrorString(XML_GetErrorCode(parser))+ " in ";
+        XML_ParserFree(parser);
+        throw preset_exception(err, filename, errno);
+    }
     XML_ParserFree(parser);
 }
 
diff --git a/src/preset_gui.cpp b/src/preset_gui.cpp
index b859f22..6880767 100644
--- a/src/preset_gui.cpp
+++ b/src/preset_gui.cpp
@@ -53,7 +53,7 @@ void synth::store_preset(GtkWindow *toplevel, plugin_gui *gui)
     GtkTreeModel *model = GTK_TREE_MODEL(gtk_list_store_new(1, G_TYPE_STRING));
     gtk_combo_box_set_model(GTK_COMBO_BOX(preset_name_combo), model);
     gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(preset_name_combo), 0);
-    for(preset_vector::const_iterator i = user_presets.presets.begin(); i != user_presets.presets.end(); i++)
+    for(preset_vector::const_iterator i = get_user_presets().presets.begin(); i != get_user_presets().presets.end(); i++)
     {
         if (i->plugin != gui->effect_name)
             continue;
@@ -77,7 +77,7 @@ void synth::store_preset(GtkWindow *toplevel, plugin_gui *gui)
         }
         catch(...)
         {
-            tmp = user_presets;
+            tmp = get_user_presets();
         }
         bool found = false;
         for(preset_vector::const_iterator i = tmp.presets.begin(); i != tmp.presets.end(); i++)
@@ -98,8 +98,8 @@ void synth::store_preset(GtkWindow *toplevel, plugin_gui *gui)
                 return;
         }
         tmp.add(sp);
-        user_presets = tmp;
-        user_presets.save(tmp.get_preset_filename().c_str());
+        get_user_presets() = tmp;
+        get_user_presets().save(tmp.get_preset_filename().c_str());
         gui->window->main->refresh_all_presets(false);
     }
     //gtk_window_set_transient_for(GTK_WINDOW(store_preset_dlg), toplevel);
@@ -108,7 +108,7 @@ void synth::store_preset(GtkWindow *toplevel, plugin_gui *gui)
 void synth::activate_preset(GtkAction *action, activate_preset_params *params)
 {
     plugin_gui *gui = params->gui;
-    plugin_preset &p = (params->builtin ? builtin_presets : user_presets).presets[params->preset];
+    plugin_preset &p = (params->builtin ? get_builtin_presets() : get_user_presets()).presets[params->preset];
     if (p.plugin != gui->effect_name)
         return;
     if (!gui->plugin->activate_preset(p.bank, p.program))

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list