Make VST preset files pre-preset rather than global. Clean up VST preset handling...
authorCarl Hetherington <carl@carlh.net>
Wed, 15 Dec 2010 02:21:25 +0000 (02:21 +0000)
committerCarl Hetherington <carl@carlh.net>
Wed, 15 Dec 2010 02:21:25 +0000 (02:21 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@8279 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/plugin_ui.cc
gtk2_ardour/plugin_ui.h
gtk2_ardour/vst_pluginui.cc
libs/ardour/ardour/vst_plugin.h
libs/ardour/vst_plugin.cc

index 165108ae196794388bf881b999b8f3725e1d7acb..dc26e49d8284688bd8adbf94b1aaca6dbe3a031b 100644 (file)
@@ -687,7 +687,9 @@ PlugUIBase::update_presets ()
 void
 PlugUIBase::update_sensitivity ()
 {
-       bool const have_preset = !preset_combo.get_model()->children().empty();
-       save_button.set_sensitive (have_preset);
-       delete_button.set_sensitive (have_preset);
+       bool const have_user_preset =
+               !preset_combo.get_model()->children().empty() && preset_combo.get_active_row_number() >= plugin->first_user_preset_index();
+       
+       save_button.set_sensitive (have_user_preset);
+       delete_button.set_sensitive (have_user_preset);
 }
index e1d9cfafce008cbe8de5839068728f366fc1f2f8..9fe2ab4921a9f84e3bb8d5f70e272ecd2efa2ba0 100644 (file)
@@ -121,7 +121,7 @@ class PlugUIBase : public virtual sigc::trackable
        Gtk::Image* focus_in_image;
        bool no_load_preset;
 
-       void setting_selected();
+       virtual void setting_selected ();
        void add_plugin_setting ();
        void save_plugin_setting ();
        void delete_plugin_setting ();
@@ -311,24 +311,10 @@ class VSTPluginUI : public PlugUIBase, public Gtk::VBox
        Gtk::Socket socket;
        Gtk::HBox   preset_box;
        Gtk::VBox   vpacker;
-       Gtk::ComboBox vst_preset_combo;
-       Glib::RefPtr<Gtk::ListStore> preset_model;
-
-       struct PresetModelColumns : public Gtk::TreeModel::ColumnRecord {
-           PresetModelColumns() { 
-                   add (name);
-                   add (number);
-           }
-           Gtk::TreeModelColumn<std::string> name;
-           Gtk::TreeModelColumn<int> number;
-       };
-
-       PresetModelColumns preset_columns;
 
        bool configure_handler (GdkEventConfigure*, Gtk::Socket*);
        void save_plugin_setting ();
-       void preset_chosen ();
-       void update_presets ();
+       void setting_selected ();
 };
 #endif // VST_SUPPORT
 
index 134ae6f2c1c3196a2e9a745b502bb9ef0cdaffd2..8de5ebe63b48cf5e9244c2120d79c2b2267bd0ee 100644 (file)
@@ -35,13 +35,6 @@ VSTPluginUI::VSTPluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<
        : PlugUIBase (pi),
          vst (vp)
 {
-       preset_model = ListStore::create (preset_columns);
-
-       CellRenderer* renderer = manage (new CellRendererText());
-       vst_preset_combo.pack_start (*renderer, true);
-       vst_preset_combo.add_attribute (*renderer, "text", 0);
-       vst_preset_combo.set_model (preset_model);
-
        update_presets ();
 
        fst_run_editor (vst->fst());
@@ -49,12 +42,10 @@ VSTPluginUI::VSTPluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<
        preset_box.set_spacing (6);
        preset_box.set_border_width (6);
        preset_box.pack_end (bypass_button, false, false, 10);
-       preset_box.pack_end (edit_button, false, false);
+       preset_box.pack_end (delete_button, false, false);
        preset_box.pack_end (save_button, false, false);
        preset_box.pack_end (add_button, false, false);
-       preset_box.pack_end (vst_preset_combo, false, false);
-
-       vst_preset_combo.signal_changed().connect (sigc::mem_fun (*this, &VSTPluginUI::preset_chosen));
+       preset_box.pack_end (preset_combo, false, false);
 
        bypass_button.set_active (!insert->active());
 
@@ -70,9 +61,9 @@ VSTPluginUI::~VSTPluginUI ()
 }
 
 void
-VSTPluginUI::preset_chosen ()
+VSTPluginUI::setting_selected ()
 {
-       int const r = vst_preset_combo.get_active_row_number ();
+       int const r = preset_combo.get_active_row_number ();
 
        if (r < vst->first_user_preset_index()) {
                /* This is a plugin-provided preset.
@@ -81,11 +72,11 @@ VSTPluginUI::preset_chosen ()
                vst->fst()->want_program = r;
        } else {
                /* This is a user preset.  This method knows about the direct dispatch restriction, too */
-               TreeModel::iterator i = vst_preset_combo.get_active ();
-               plugin->load_preset ((*i)[preset_columns.name]);
+               plugin->load_preset (preset_combo.get_active_text());
        }
        
        socket.grab_focus ();
+       update_sensitivity ();
 }
 
 int
@@ -157,31 +148,6 @@ VSTPluginUI::configure_handler (GdkEventConfigure* ev, Gtk::Socket *socket)
        return false;
 }
 
-void
-VSTPluginUI::update_presets ()
-{
-       std::vector<Plugin::PresetRecord> presets = plugin->get_presets ();
-
-       preset_model->clear ();
-
-       int j = 0;
-       for (std::vector<Plugin::PresetRecord>::const_iterator i = presets.begin(); i != presets.end(); ++i) {
-               TreeModel::Row row = *(preset_model->append ());
-               row[preset_columns.name] = i->label;
-               row[preset_columns.number] = j++;
-       }
-
-       if (presets.size() > 0) {
-               vst->fst()->plugin->dispatcher (vst->fst()->plugin, effSetProgram, 0, 0, NULL, 0);
-       }
-
-       if (vst->fst()->current_program != -1) {
-               vst_preset_combo.set_active (vst->fst()->current_program);
-       } else {
-               vst_preset_combo.set_active (0);
-       }
-}
-
 typedef int (*error_handler_t)( Display *, XErrorEvent *);
 static Display *the_gtk_display;
 static error_handler_t wine_error_handler;
index b6e2a027561acc3e1efccff8666730f3741d47c3..e9a2c4abdf1a9d7716e1c40421711d78f227a16d 100644 (file)
@@ -97,6 +97,7 @@ private:
        gchar* get_chunk (bool);
        int set_chunk (gchar const *, bool);
        XMLTree * presets_tree () const;
+       std::string presets_file () const;
        
        FSTHandle* handle;
        FST*       _fst;
index e77fc483ed0fd2e6155c1718fe76f2c08622b8f7..625e4482b3790b4b6424313e13384b5d8006ad12 100644 (file)
@@ -425,8 +425,9 @@ VSTPlugin::do_save_preset (string name)
 
                sys::path f = ARDOUR::user_config_directory ();
                f /= "presets";
-               f /= "vst";
+               f /= presets_file ();
 
+               cout << "Write presets to " << f.to_string () << "\n";
                t->write (f.to_string ());
                delete t;
                return uri;
@@ -449,8 +450,9 @@ VSTPlugin::do_remove_preset (string name)
 
                sys::path f = ARDOUR::user_config_directory ();
                f /= "presets";
-               f /= "vst";
+               f /= presets_file ();
 
+               cout << "Write presets to " << f.to_string () << "\n";
                t->write (f.to_string ());
                delete t;
        }
@@ -711,7 +713,7 @@ VSTPlugin::presets_tree () const
                create_directory (p);
        }
 
-       p /= "vst";
+       p /= presets_file ();
 
        if (!exists (p)) {
                t->set_root (new XMLNode (X_("VSTPresets")));
@@ -734,7 +736,14 @@ VSTPlugin::first_user_preset_index () const
        return _plugin->numPrograms;
 }
 
+string
+VSTPlugin::presets_file () const
+{
+       return string_compose ("vst-%1", unique_id ());
+}
+
 VSTPluginInfo::VSTPluginInfo()
 {
        type = ARDOUR::VST;
 }
+