1 /*
2  * Copyright (C) 2005-2006 Doug McLain <doug@nostar.net>
3  * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
4  * Copyright (C) 2005-2011 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2006-2012 David Robillard <d@drobilla.net>
6  * Copyright (C) 2006 Nick Mainsbridge <mainsbridge@gmail.com>
7  * Copyright (C) 2009 Carl Hetherington <carl@carlh.net>
8  * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24 
25 #ifndef __ardour_plugin_selector_h__
26 #define __ardour_plugin_selector_h__
27 
28 #include <gtkmm/button.h>
29 #include <gtkmm/checkbutton.h>
30 #include <gtkmm/comboboxtext.h>
31 #include <gtkmm/entry.h>
32 #include <gtkmm/liststore.h>
33 #include <gtkmm/notebook.h>
34 #include <gtkmm/scrolledwindow.h>
35 #include <gtkmm/treemodel.h>
36 #include <gtkmm/treeview.h>
37 
38 #include "widgets/ardour_button.h"
39 #include "widgets/ardour_dropdown.h"
40 
41 #include "gtkmm2ext/dndtreeview.h"
42 
43 #include "ardour/plugin.h"
44 #include "ardour/plugin_manager.h"
45 #include "ardour/session_handle.h"
46 
47 #include "plugin_interest.h"
48 #include "ardour_dialog.h"
49 
50 namespace ARDOUR {
51 	class Session;
52 	class PluginManager;
53 }
54 
55 class PluginSelector : public ArdourDialog
56 {
57 public:
58 	PluginSelector (ARDOUR::PluginManager&);
59 	~PluginSelector ();
60 
61 	void set_interested_object (PluginInterestedObject&);
62 
63 	int run (); // XXX should we try not to overload the non-virtual Gtk::Dialog::run() ?
64 
65 	void on_show ();
66 
67 	Gtk::Menu* plugin_menu ();
68 	void show_manager ();
69 
70 private:
71 
72 	//search
73 	ArdourWidgets::ArdourButton* _search_name_checkbox;
74 	ArdourWidgets::ArdourButton* _search_tags_checkbox;
75 	ArdourWidgets::ArdourButton* _search_ignore_checkbox;
76 
77 	//radio-button filters
78 	Gtk::RadioButton *_fil_effects_radio;
79 	Gtk::RadioButton *_fil_instruments_radio;
80 	Gtk::RadioButton *_fil_utils_radio;
81 	Gtk::RadioButton *_fil_favorites_radio;
82 	Gtk::RadioButton *_fil_hidden_radio;
83 	Gtk::RadioButton *_fil_all_radio;
84 
85 	/* combobox filters */
86 	ArdourWidgets::ArdourDropdown _fil_type_combo;
87 	ArdourWidgets::ArdourDropdown _fil_creator_combo;
88 
89 	PluginInterestedObject* interested_object;
90 
91 	Gtk::ScrolledWindow scroller;   // Available plugins
92 	Gtk::ScrolledWindow ascroller;  // Added plugins
93 
94 	Gtk::Entry search_entry;
95 	Gtk::Button search_clear_button;
96 
97 	Gtk::Entry *tag_entry;
98 	Gtk::Button* tag_reset_button;
99 	void tag_reset_button_clicked ();
100 
101 	void set_sensitive_widgets();
102 
103 	void search_clear_button_clicked ();
104 	void search_entry_changed ();
105 
106 	void tag_entry_changed ();
107 	sigc::connection tag_entry_connection;
108 
109 	void tags_changed ( ARDOUR::PluginType t, std::string unique_id, std::string tag);
110 
111 	struct PluginColumns : public Gtk::TreeModel::ColumnRecord {
PluginColumnsPluginColumns112 		PluginColumns () {
113 			add (favorite);
114 			add (hidden);
115 			add (name);
116 			add (tags);
117 			add (creator);
118 			add (type_name);
119 			add (audio_io);
120 			add (midi_io);
121 			add (plugin);
122 		}
123 		Gtk::TreeModelColumn<bool> favorite;
124 		Gtk::TreeModelColumn<bool> hidden;
125 		Gtk::TreeModelColumn<std::string> name;
126 		Gtk::TreeModelColumn<std::string> type_name;
127 		Gtk::TreeModelColumn<std::string> creator;
128 		Gtk::TreeModelColumn<std::string> tags;
129 		Gtk::TreeModelColumn<std::string> audio_io;
130 		Gtk::TreeModelColumn<std::string> midi_io;
131 		Gtk::TreeModelColumn<ARDOUR::PluginInfoPtr> plugin;
132 	};
133 	PluginColumns plugin_columns;
134 	Glib::RefPtr<Gtk::ListStore> plugin_model;
135 	Gtkmm2ext::DnDTreeView<ARDOUR::PluginInfoPtr> plugin_display;
136 	Gtk::Button* btn_add;
137 	Gtk::Button* btn_remove;
138 
139 	struct AddedColumns : public Gtk::TreeModel::ColumnRecord {
AddedColumnsAddedColumns140 		AddedColumns () {
141 			add (text);
142 			add (plugin);
143 		}
144 		Gtk::TreeModelColumn<std::string> text;
145 		Gtk::TreeModelColumn<ARDOUR::PluginInfoPtr> plugin;
146 	};
147 	AddedColumns acols;
148 	Glib::RefPtr<Gtk::ListStore> amodel;
149 	Gtk::TreeView added_list;
150 
151 	void refill ();
152 	void refiller (const ARDOUR::PluginInfoList& plugs, const::std::string& filterstr, const char* type);
153 	void ladspa_refiller (const std::string&);
154 	void lv2_refiller (const std::string&);
155 	void vst_refiller (const std::string&);
156 	void lxvst_refiller (const std::string&);
157 	void mac_vst_refiller (const std::string&);
158 	void au_refiller (const std::string&);
159 	void lua_refiller (const std::string&);
160 	void vst3_refiller (const std::string&);
161 
162 	Gtk::Menu* _plugin_menu;
163 	ARDOUR::PluginManager& manager;
164 
165 	void row_activated(Gtk::TreeModel::Path path, Gtk::TreeViewColumn* col);
166 	void btn_add_clicked();
167 	void btn_remove_clicked();
168 	void added_list_selection_changed();
169 	void added_row_clicked(GdkEventButton* event);
170 	void display_selection_changed();
171 	void btn_apply_clicked();
172 	ARDOUR::PluginPtr load_plugin (ARDOUR::PluginInfoPtr);
173 	bool show_this_plugin (const ARDOUR::PluginInfoPtr&, const std::string&);
174 
175 	void favorite_changed (const std::string& path);
176 	void hidden_changed (const std::string& path);
177 	bool in_row_change;
178 
179 	void plugin_chosen_from_menu (const ARDOUR::PluginInfoPtr&);
180 
181 	void plugin_status_changed ( ARDOUR::PluginType t, std::string unique_id, ARDOUR::PluginManager::PluginStatusType s );
182 
183 	Gtk::Menu* create_favs_menu (ARDOUR::PluginInfoList&);
184 	Gtk::Menu* create_charts_menu (ARDOUR::PluginInfoList&);
185 	Gtk::Menu* create_by_creator_menu (ARDOUR::PluginInfoList&);
186 	Gtk::Menu* create_by_tags_menu (ARDOUR::PluginInfoList&);
187 	void build_plugin_menu ();
188 	PBD::ScopedConnectionList plugin_list_changed_connection;
189 
190 	bool _need_tag_save;
191 	bool _need_status_save;
192 	bool _need_menu_rebuild;
193 	bool _inhibit_refill;
194 };
195 
196 #endif // __ardour_plugin_selector_h__
197