2 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include <gtkmm/frame.h>
20 #include <gtkmm/stock.h>
21 #include <gtkmm/table.h>
23 #include "gtkmm2ext/utils.h"
25 #include "script_selector.h"
30 using namespace ARDOUR;
32 ScriptSelector::ScriptSelector (std::string title, LuaScriptInfo::ScriptType type)
33 : ArdourDialog (title)
34 , _type_label ("<b>Type:</b>", Gtk::ALIGN_END, Gtk::ALIGN_CENTER)
35 , _type ("", Gtk::ALIGN_START, Gtk::ALIGN_CENTER)
36 , _author_label ("<b>Author:</b>", Gtk::ALIGN_END, Gtk::ALIGN_CENTER)
37 , _author ("", Gtk::ALIGN_START, Gtk::ALIGN_CENTER)
38 , _description ("", Gtk::ALIGN_START, Gtk::ALIGN_START)
39 , _scripts (LuaScripting::instance ().scripts (type))
42 Table* t = manage (new Table (3, 2));
47 _type_label.set_use_markup ();
48 t->attach (_type_label, 0, 1, ty, ty+1, FILL|EXPAND, SHRINK);
49 t->attach (_type, 1, 2, ty, ty+1, FILL|EXPAND, SHRINK);
52 _author_label.set_use_markup ();
53 t->attach (_author_label, 0, 1, ty, ty+1, FILL|EXPAND, SHRINK);
54 t->attach (_author, 1, 2, ty, ty+1, FILL|EXPAND, SHRINK);
57 Frame* f = manage(new Frame (_("Description")));
58 f->add (_description);
59 t->attach (*f, 0, 2, ty, ty+1);
62 _description.set_padding (5, 5);
63 _description.set_line_wrap();
65 get_vbox()->set_spacing (6);
66 get_vbox()->pack_start (_script_combo, false, false);
67 get_vbox()->pack_start (*t, true, true);
69 Button *r = Gtk::manage (new Gtk::Button (Stock::REFRESH));
70 r->signal_clicked().connect (sigc::mem_fun (*this, &ScriptSelector::refresh));
71 get_action_area()->pack_start(*r);
73 add_button (Stock::CANCEL, RESPONSE_CANCEL);
74 _add = add_button (Stock::ADD, RESPONSE_ACCEPT);
75 set_default_response (RESPONSE_ACCEPT);
77 _add->set_sensitive (false);
78 _combocon = _script_combo.signal_changed().connect (sigc::mem_fun (*this, &ScriptSelector::script_combo_changed));
83 script_combo_changed();
87 ScriptSelector::script_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk::TreeModel::iterator &i)
89 _script_combo.set_active (i);
91 return _script_combo.get_active_text () == "separator";
95 ScriptSelector::setup_list ()
99 vector<string> script_names;
100 for (LuaScriptList::const_iterator s = _scripts.begin(); s != _scripts.end(); ++s) {
101 if ((*s)->name != "Shortcut") {
102 script_names.push_back ((*s)->name);
106 _script_combo.clear();
107 _script_combo.set_row_separator_func (sigc::mem_fun (*this, &ScriptSelector::script_separator));
109 _script_combo.append_text ("Shortcut");
110 _script_combo.append_text ("separator");
112 vector<string>::const_iterator i;
113 for (i = script_names.begin(); i != script_names.end(); ++i) {
114 _script_combo.append_text (*i);
117 _script_combo.set_active(0);
118 script_combo_changed ();
124 ScriptSelector::script_combo_changed ()
126 std::string nm = _script_combo.get_active_text();
128 for (LuaScriptList::const_iterator s = _scripts.begin(); s != _scripts.end(); ++s) {
129 if ((*s)->name == nm) {
136 if (_script->name == "Shortcut") {
140 _author_label.hide();
141 _description.set_text (_script->description);
146 _author_label.show();
147 _type.set_text(LuaScriptInfo::type2str (_script->type));
148 _author.set_text (_script->author);
149 _description.set_text (_script->description);
152 _add->set_sensitive (Glib::file_test(_script->path, Glib::FILE_TEST_EXISTS));
157 ScriptSelector::refresh ()
159 LuaScripting::instance ().refresh ();
161 _scripts = LuaScripting::instance ().scripts (_script_type);
165 ///////////////////////////////////////////////////////////////////////////////
167 SessionScriptManager::SessionScriptManager (std::string title, const std::vector<std::string> &names)
168 : ArdourDialog (title)
170 assert (names.size() > 0);
171 Gtkmm2ext::set_popdown_strings (_names_combo, names);
172 _names_combo.set_active(0);
175 l = manage (new Label (_("Select Script to unload")));
177 get_vbox()->set_spacing (6);
178 get_vbox()->pack_start (*l, false, false);
179 get_vbox()->pack_start (_names_combo, false, false);
181 add_button (Stock::CANCEL, RESPONSE_CANCEL);
182 add_button (Stock::REMOVE, RESPONSE_ACCEPT);
183 set_default_response (RESPONSE_CANCEL);
188 ///////////////////////////////////////////////////////////////////////////////
191 ScriptParameterDialog::ScriptParameterDialog (std::string title,
192 const LuaScriptInfoPtr& spi,
193 const std::vector<std::string> &names,
194 LuaScriptParamList& lsp)
195 : ArdourDialog (title)
196 , _existing_names (names)
201 Table* t = manage (new Table (4, 3));
204 _name_entry.set_text (spi->name);
206 for (size_t i = 0; i < _lsp.size(); ++i) {
207 if (_lsp[i]->preseeded && _lsp[i]->name == "x-script-name" && !_lsp[i]->value.empty ()) {
208 _name_entry.set_text (_lsp[i]->value);
212 _name_entry.signal_changed().connect (sigc::mem_fun (*this, &ScriptParameterDialog::update_sensitivity));
216 l = manage (new Label (_("<b>Name:</b>"), Gtk::ALIGN_END, Gtk::ALIGN_CENTER, false));
217 l->set_use_markup ();
218 t->attach (*l, 0, 1, ty, ty+1);
219 t->attach (_name_entry, 1, 2, ty, ty+1);
222 if (_lsp.size () > 0) {
223 l = manage (new Label (_("<b>Instance Parameters</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
224 l->set_use_markup ();
225 t->attach (*l, 0, 2, ty, ty+1);
229 for (size_t i = 0; i < _lsp.size (); ++i) {
230 Entry* e = manage (new Entry());
231 if (_lsp[i]->optional) {
232 CheckButton* c = manage (new CheckButton (_lsp[i]->title));
233 c->set_active (!_lsp[i]->dflt.empty());
234 c->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &ScriptParameterDialog::active_changed), i, c, e));
235 t->attach (*c, 0, 1, ty, ty+1);
237 Label* l = manage (new Label (_lsp[i]->title, Gtk::ALIGN_LEFT));
238 t->attach (*l, 0, 1, ty, ty+1);
241 e->set_text (_lsp[i]->dflt);
242 e->set_sensitive (!_lsp[i]->dflt.empty());
243 e->signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &ScriptParameterDialog::value_changed), i, e));
245 t->attach (*e, 1, 2, ty, ty+1);
249 add_button (Stock::CANCEL, RESPONSE_CANCEL);
250 _add = add_button (Stock::ADD, RESPONSE_ACCEPT);
251 set_default_response (RESPONSE_ACCEPT);
253 get_vbox()->pack_start (*t, true, true);
255 update_sensitivity ();
259 ScriptParameterDialog::need_interation () const
261 if (!parameters_ok ()) {
264 for (size_t i = 0; i < _lsp.size(); ++i) {
265 if (!_lsp[i]->optional && !_lsp[i]->preseeded) {
273 ScriptParameterDialog::parameters_ok () const
275 std::string n = _name_entry.get_text ();
276 if (n.empty() || std::find (_existing_names.begin(), _existing_names.end(), n) != _existing_names.end()) {
280 for (size_t i = 0; i < _lsp.size(); ++i) {
281 if (!_lsp[i]->optional && _lsp[i]->value.empty()) {
289 ScriptParameterDialog::update_sensitivity ()
291 _add->set_sensitive (parameters_ok ());
295 ScriptParameterDialog::active_changed (int i, Gtk::CheckButton* c, Gtk::Entry* e)
297 bool en = c->get_active ();
298 _lsp[i]->is_set = en;
299 e->set_sensitive (en);
303 ScriptParameterDialog::value_changed (int i, Gtk::Entry* e)
305 _lsp[i]->value = e->get_text ();