plugin selection via menu, along with "favorites"
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 24 Apr 2008 17:59:08 +0000 (17:59 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 24 Apr 2008 17:59:08 +0000 (17:59 +0000)
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@3284 d708f5d6-7413-0410-9779-e7cbd77b26cf

13 files changed:
gtk2_ardour/plugin_selector.cc
gtk2_ardour/plugin_selector.h
gtk2_ardour/redirect_box.cc
gtk2_ardour/redirect_box.h
libs/ardour/SConscript
libs/ardour/ardour/plugin_manager.h
libs/ardour/plugin_manager.cc
libs/ardour/route.cc
libs/ardour/session.cc
libs/libsndfile/SConscript
libs/midi++2/SConscript
libs/pbd/SConscript
libs/sigc++2/SConscript

index c7d456cc4d6a95fd57cc5ced5a8ac8c2d89cfe9c..41bcd18af1da405c545622d3ec8e737672901a89 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <cstdio>
 #include <lrdf.h>
+#include <map>
 
 #include <algorithm>
 
@@ -64,9 +65,15 @@ PluginSelector::PluginSelector (PluginManager *mgr)
 
        manager = mgr;
        session = 0;
-       
+       _menu = 0;
+       in_row_change = false;
+
        plugin_model = Gtk::ListStore::create (plugin_columns);
        plugin_display.set_model (plugin_model);
+       /* XXX translators: try to convert "Fav" into a short term
+          related to "favorite"
+       */
+       plugin_display.append_column (_("Fav"), plugin_columns.favorite);
        plugin_display.append_column (_("Available Plugins"), plugin_columns.name);
        plugin_display.append_column (_("Type"), plugin_columns.type_name);
        plugin_display.append_column (_("Category"), plugin_columns.category);
@@ -76,6 +83,13 @@ PluginSelector::PluginSelector (PluginManager *mgr)
        plugin_display.set_headers_visible (true);
        plugin_display.set_headers_clickable (true);
        plugin_display.set_reorderable (false);
+       plugin_display.set_rules_hint (true);
+
+       CellRendererToggle* fav_cell = dynamic_cast<CellRendererToggle*>(plugin_display.get_column_cell_renderer (0));
+       fav_cell->property_activatable() = true;
+       fav_cell->property_radio() = false;
+       fav_cell->signal_toggled().connect (mem_fun (*this, &PluginSelector::favorite_changed));
+
        scroller.set_border_width(10);
        scroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
        scroller.add(plugin_display);
@@ -222,6 +236,8 @@ PluginSelector::refill ()
 {
        std::string filterstr;
 
+       in_row_change = true;
+
        plugin_model->clear ();
 
        setup_filter_string (filterstr);
@@ -230,6 +246,8 @@ PluginSelector::refill ()
        lv2_refiller (filterstr);
        vst_refiller (filterstr);
        au_refiller (filterstr);
+
+       in_row_change = false;
 }
 
 void
@@ -242,11 +260,11 @@ PluginSelector::refiller (const PluginInfoList& plugs, const::std::string& filte
                if (show_this_plugin (*i, filterstr)) {
 
                        TreeModel::Row newrow = *(plugin_model->append());
+                       newrow[plugin_columns.favorite] = manager->is_a_favorite_plugin (*i);
                        newrow[plugin_columns.name] = (*i)->name;
                        newrow[plugin_columns.type_name] = type;
                        newrow[plugin_columns.category] = (*i)->category;
 
-
                        string creator = (*i)->creator;
                        string::size_type pos = 0;
 
@@ -433,3 +451,115 @@ PluginSelector::on_show ()
        ArdourDialog::on_show ();
        filter_entry.grab_focus ();
 }
+
+Gtk::Menu&
+PluginSelector::plugin_menu()
+{
+       using namespace Menu_Helpers;
+
+       typedef std::map<Glib::ustring,Gtk::Menu*> SubmenuMap;
+       SubmenuMap submenu_map;
+
+       if (!_menu) {
+               _menu = new Menu();
+       } 
+
+       MenuList& items = _menu->items();
+       Menu* favs = new Menu();
+
+       items.clear ();
+       items.push_back (MenuElem (_("Favorites"), *favs));
+       items.push_back (MenuElem (_("Plugin Manager"), mem_fun (*this, &PluginSelector::show_manager)));
+       items.push_back (SeparatorElem ());
+
+       PluginInfoList all_plugs;
+
+       all_plugs.insert (all_plugs.end(), manager->ladspa_plugin_info().begin(), manager->ladspa_plugin_info().end());
+#ifdef VST_SUPPORT
+       all_plugs.insert (all_plugs.end(), manager->vst_plugin_info().begin(), manager->vst_plugin_info().end());
+#endif
+#ifdef HAVE_AUDIOUNITS
+       all_plugs.insert (all_plugs.end(), manager->au_plugin_info().begin(), manager->au_plugin_info().end());
+#endif
+#ifdef HAVE_SLV2
+       all_plugs.insert (all_plugs.end(), manager->lv2_plugin_info().begin(), manager->lv2_plugin_info().end());
+#endif
+
+       for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
+               SubmenuMap::iterator x;
+               Gtk::Menu* submenu;
+
+               string creator = (*i)->creator;
+               string::size_type pos = 0;
+
+               if (manager->is_a_favorite_plugin (*i)) {
+                       favs->items().push_back (MenuElem ((*i)->name, (bind (mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i))));
+               }
+               
+               /* stupid LADSPA creator strings */
+               
+               while (pos < creator.length() && (isalnum (creator[pos]) || isspace (creator[pos]))) ++pos;
+               creator = creator.substr (0, pos);
+
+               if ((x = submenu_map.find (creator)) != submenu_map.end()) {
+                       submenu = x->second;
+               } else {
+                       submenu = new Gtk::Menu;
+                       items.push_back (MenuElem (creator, *submenu));
+                       submenu_map.insert (pair<Glib::ustring,Menu*> (creator, submenu));
+               }
+               
+               submenu->items().push_back (MenuElem ((*i)->name, (bind (mem_fun (*this, &PluginSelector::plugin_chosen_from_menu), *i))));
+       }
+       
+       return *_menu;
+}
+
+void
+PluginSelector::plugin_chosen_from_menu (const PluginInfoPtr& pi)
+{
+       use_plugin (pi);
+}
+
+void 
+PluginSelector::favorite_changed (const Glib::ustring& path)
+{
+       PluginInfoPtr pi;
+
+       if (in_row_change) {
+               return;
+       }
+
+       in_row_change = true;
+       
+       TreeModel::iterator iter = plugin_model->get_iter (path);
+       
+       if (iter) {
+
+               bool favorite = !(*iter)[plugin_columns.favorite];
+
+               /* change state */
+
+               (*iter)[plugin_columns.favorite] = favorite;
+
+               /* save new favorites list */
+
+               pi = (*iter)[plugin_columns.plugin];
+               
+               if (favorite) {
+                       manager->add_favorite (pi->type, pi->unique_id);
+               } else {
+                       manager->remove_favorite (pi->type, pi->unique_id);
+               }
+               
+               manager->save_favorites ();
+       }
+       in_row_change = false;
+}
+
+void
+PluginSelector::show_manager ()
+{
+       show_all();
+       run ();
+}
index 70c9ba3c3e3ffbfff6d9b17d9f2130ca789eba93..77d8c462a6552ac08bd4cae8698b88872aace74e 100644 (file)
@@ -43,6 +43,8 @@ class PluginSelector : public ArdourDialog
        void set_session (ARDOUR::Session*);
        void on_show ();
 
+       Gtk::Menu& plugin_menu ();
+
   private:
        ARDOUR::Session* session;
        Gtk::ScrolledWindow scroller;  // Available plugins
@@ -58,6 +60,7 @@ class PluginSelector : public ArdourDialog
        
        struct PluginColumns : public Gtk::TreeModel::ColumnRecord {
                PluginColumns () {
+                       add (favorite);
                        add (name);
                        add (type_name);
                        add (category);
@@ -66,6 +69,7 @@ class PluginSelector : public ArdourDialog
                        add (outs);
                        add (plugin);
                }
+               Gtk::TreeModelColumn<bool> favorite;
                Gtk::TreeModelColumn<std::string> name;
                Gtk::TreeModelColumn<std::string> type_name;
                Gtk::TreeModelColumn<std::string> category;
@@ -112,6 +116,13 @@ class PluginSelector : public ArdourDialog
        void cleanup ();
        bool show_this_plugin (const ARDOUR::PluginInfoPtr&, const std::string&);
        void setup_filter_string (std::string&);
+
+       void favorite_changed (const Glib::ustring& path);
+       bool in_row_change;
+
+       void plugin_chosen_from_menu (const ARDOUR::PluginInfoPtr&);
+       Gtk::Menu* _menu;
+       void show_manager ();
 };
 
 #endif // __ardour_plugin_selector_h__
index 050ffdef555b30101e25a6f3cac75b1b63e93c45..8e7e97a8165304001ab3fafef8eabd26c57a8afc 100644 (file)
@@ -385,10 +385,9 @@ RedirectBox::deselect_all_redirects ()
 void
 RedirectBox::choose_plugin ()
 {
-       sigc::connection newplug_connection = _plugin_selector.PluginCreated.connect (mem_fun(*this,&RedirectBox::insert_plugin_chosen));
-       _plugin_selector.show_all();
-       _plugin_selector.run ();
-       newplug_connection.disconnect();
+       newplug_connection = _plugin_selector.PluginCreated.connect (mem_fun(*this,&RedirectBox::insert_plugin_chosen));
+       Gtk::Menu& m = _plugin_selector.plugin_menu();
+       m.popup (1, 0);
 }
 
 void
@@ -409,6 +408,8 @@ RedirectBox::insert_plugin_chosen (boost::shared_ptr<Plugin> plugin)
                        redirect->active_changed.connect (bind (mem_fun (*this, &RedirectBox::show_redirect_active_r), boost::weak_ptr<Redirect>(redirect)));
                }
        }
+
+       newplug_connection.disconnect();
 }
 
 void
index cb126dc13f4be3cbb8c0b44b246a358f9dfd4f67..cc5b87d62a4ef54328fbf3ce5e488415b2f4c1cb 100644 (file)
@@ -145,6 +145,7 @@ class RedirectBox : public Gtk::HBox
        void choose_insert ();
        void choose_plugin ();
        void insert_plugin_chosen (boost::shared_ptr<ARDOUR::Plugin>);
+       sigc::connection newplug_connection;
 
        bool no_redirect_redisplay;
        bool ignore_delete;
index dce3432065e13a146d9e16d5e0c07d97d2c379c6..d671387e664d25455614574176f4da4c39b5645a 100644 (file)
@@ -6,7 +6,7 @@ import glob
 
 Import('env final_prefix install_prefix final_config_prefix libraries i18n')
 
-ardour = env.Copy()
+ardour = env.Clone()
 
 #
 # this defines the version number of libardour
@@ -317,7 +317,7 @@ env['BUILDERS']['SharedAsmObject'] = Builder (action = '$CXX -c -fPIC $SOURCE -o
 
 
 always_sse_objects = []
-sse_env = ardour.Copy()
+sse_env = ardour.Clone()
 sse_env.Append (CXXFLAGS="-msse")
 
 if env['FPU_OPTIMIZATION']:
index 892c8bd75ac7572b1de095ae5f13b5d792908841..858decd0e5faf819e931b92b710f3b9d43ac16ee 100644 (file)
@@ -23,6 +23,7 @@
 #include <list>
 #include <map>
 #include <string>
+#include <set>
 
 #include <ardour/types.h>
 #include <ardour/plugin.h>
@@ -54,7 +55,31 @@ class PluginManager {
 
        static PluginManager* the_manager() { return _manager; }
 
+       void load_favorites ();
+       void save_favorites ();
+       void add_favorite (ARDOUR::PluginType type, std::string unique_id);
+       void remove_favorite (ARDOUR::PluginType type, std::string unique_id);
+       bool is_a_favorite_plugin (const PluginInfoPtr&);
+       
   private:
+       struct FavoritePlugin {
+           ARDOUR::PluginType type;
+           std::string unique_id;
+
+           FavoritePlugin (ARDOUR::PluginType t, std::string id) 
+           : type (t), unique_id (id) {}
+           
+           bool operator==(const FavoritePlugin& other) const {
+                   return other.type == type && other.unique_id == unique_id;
+           }
+
+           bool operator<(const FavoritePlugin& other) const {
+                   return other.type < type || other.unique_id < unique_id;
+           }
+       };
+       typedef std::set<FavoritePlugin> FavoritePluginList;
+       FavoritePluginList favorites;
+
        ARDOUR::PluginInfoList _vst_plugin_info;
        ARDOUR::PluginInfoList _ladspa_plugin_info;
        ARDOUR::PluginInfoList _lv2_plugin_info;
index 336763faa1d7761717074ba37b1d3f58025a755a..2157774cac12e9ad5c47e315ed7c7d574fa10c1d 100644 (file)
@@ -21,6 +21,8 @@
 #include <cstdio>
 #include <lrdf.h>
 #include <dlfcn.h>
+#include <cstdlib>
+#include <fstream>
 
 #ifdef VST_SUPPORT
 #include <fst.h>
@@ -56,6 +58,7 @@
 
 using namespace ARDOUR;
 using namespace PBD;
+using namespace std;
 
 PluginManager* PluginManager::_manager = 0;
 
@@ -64,6 +67,8 @@ PluginManager::PluginManager ()
        char* s;
        string lrdf_path;
 
+       load_favorites ();
+
        if ((s = getenv ("LADSPA_RDF_PATH"))){
                lrdf_path = s;
        }
@@ -484,3 +489,111 @@ PluginManager::vst_discover (string path)
 }
 
 #endif // VST_SUPPORT
+
+bool
+PluginManager::is_a_favorite_plugin (const PluginInfoPtr& pi)
+{
+       FavoritePlugin fp (pi->type, pi->unique_id);
+       return find (favorites.begin(), favorites.end(), fp) !=  favorites.end();
+}
+
+void
+PluginManager::save_favorites ()
+{
+       Glib::ustring path = get_user_ardour_path ();
+       path += '/';
+       path += "favorite_plugins";
+
+       ofstream ofs;
+
+       ofs.open (path.c_str(), ios_base::openmode (ios::out|ios::trunc));
+
+       if (!ofs) {
+               return;
+       }
+
+       for (FavoritePluginList::iterator i = favorites.begin(); i != favorites.end(); ++i) {
+               switch ((*i).type) {
+               case LADSPA:
+                       ofs << "LADSPA";
+                       break;
+               case AudioUnit:
+                       ofs << "AudioUnit";
+                       break;
+               case LV2:
+                       ofs << "LV2";
+                       break;
+               case VST:
+                       ofs << "VST";
+                       break;
+               }
+               
+               ofs << ' ' << (*i).unique_id << endl;
+       }
+
+       ofs.close ();
+}
+
+void
+PluginManager::load_favorites ()
+{
+       Glib::ustring path = get_user_ardour_path ();
+       path += '/';
+       path += "favorite_plugins";
+
+       ifstream ifs (path.c_str());
+
+       if (!ifs) {
+               return;
+       }
+       
+       std::string stype;
+       std::string id;
+       PluginType type;
+
+       while (ifs) {
+
+               ifs >> stype;
+               if (!ifs) {
+                       break;
+
+               }
+               ifs >> id;
+               if (!ifs) {
+                       break;
+               }
+
+               if (stype == "LADSPA") {
+                       type = LADSPA;
+               } else if (stype == "AudioUnit") {
+                       type = AudioUnit;
+               } else if (stype == "LV2") {
+                       type = LV2;
+               } else if (stype == "VST") {
+                       type = VST;
+               } else {
+                       error << string_compose (_("unknown favorite plugin type \"%1\" - ignored"), stype)
+                             << endmsg;
+                       continue;
+               }
+               
+               add_favorite (type, id);
+       }
+       
+       ifs.close ();
+}
+
+void
+PluginManager::add_favorite (PluginType t, string id)
+{
+       FavoritePlugin fp (t, id);
+       pair<FavoritePluginList::iterator,bool> res = favorites.insert (fp);
+       cerr << "Added " << t << " " << id << " success ? " << res.second << endl;
+}
+
+void
+PluginManager::remove_favorite (PluginType t, string id)
+{
+       FavoritePlugin fp (t, id);
+       favorites.erase (fp);
+}
index dcf78b5e2e43aad249f798b244e91baabae5bd36..8daeed2eebe2235fa9dad8f158a8822444b3b1d4 100644 (file)
@@ -2419,6 +2419,7 @@ Route::update_total_latency ()
                }
        }
 
+#define DEBUG_LATENCY
 #ifdef DEBUG_LATENCY
        cerr << _name << ": internal redirect latency = " << _own_latency << endl;
 #endif
index 5b8d2f850677abea63df09685b996c7960d0e8f7..a97a613ea40ea6e147428299e3e4503bdde870ff 100644 (file)
@@ -284,6 +284,7 @@ Session::Session (AudioEngine &eng,
          diskstreams (new DiskstreamList),
          routes (new RouteList),
          auditioner ((Auditioner*) 0),
+         _total_free_4k_blocks (0),
          _click_io ((IO*) 0),
          main_outs (0)
 {
@@ -346,6 +347,7 @@ Session::Session (AudioEngine &eng,
          midi_requests (16),
          diskstreams (new DiskstreamList),
          routes (new RouteList),
+         _total_free_4k_blocks (0),
          main_outs (0)
 
 {
index 150b820f55d99726ff37f9c7e097214fe06ce4cc..6f0651007e11351843ddc93bb49a4d83a051809f 100644 (file)
@@ -7,7 +7,7 @@ import glob
 sndfile_files = glob.glob('src/*.c') + glob.glob('src/GSM610/*.c') + glob.glob('src/G72x/*.c')
 
 Import('env install_prefix libraries use_flac')
-sndfile = env.Copy()
+sndfile = env.Clone()
 sndfile.Merge([libraries['flac'] ])
 
 domain = 'libsndfile'
index ce7db6c2637b96e5547413d6f27218b27def52fc..21356da53b88bd11bf45b0eca2d3ff897b78b762 100644 (file)
@@ -6,7 +6,7 @@ import glob
 
 Import('env libraries install_prefix')
 
-midi2 = env.Copy()
+midi2 = env.Clone()
 midi2.Merge([ libraries['sigc2'], libraries['xml'], libraries['glibmm2'], libraries['glib2'], libraries['pbd'] ])
 
 if midi2['IS_OSX']:
index a0065f09bd50c855c51d33d75f5f6063e2dca554..f51ddd5a3636a063fc2d9237be2f46ee0eaa85c9 100644 (file)
@@ -6,7 +6,7 @@ import glob
 
 Import('env libraries i18n install_prefix')
 
-pbd = env.Copy()
+pbd = env.Clone()
 
 domain = 'libpbd'
 
index b29aefb0cd807a028e71b621de377ed0f91e1812..9ac1ef48ee49de7c64e77df336e33b30b4f7f2fa 100644 (file)
@@ -7,7 +7,7 @@ import glob
 sigc2_files = glob.glob('sigc++/*.cc') + glob.glob('sigc++/functors/*.cc') + glob.glob('sigc++/adaptors/lambda/*.cc')
 
 Import('env install_prefix')
-sigc2 = env.Copy()
+sigc2 = env.Clone()
 
 libsigc2 = sigc2.SharedLibrary('sigc++2', sigc2_files)