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 "gtkmm2ext/utils.h"
21 #include "script_selector.h"
26 using namespace ARDOUR;
28 ScriptSelector::ScriptSelector (std::string title, LuaScriptInfo::ScriptType type)
29 : ArdourDialog (title)
30 , _type ("", Gtk::ALIGN_START, Gtk::ALIGN_CENTER)
31 , _author ("", Gtk::ALIGN_START, Gtk::ALIGN_CENTER)
32 , _description ("", Gtk::ALIGN_START, Gtk::ALIGN_START)
33 , _scripts (LuaScripting::instance ().scripts (type))
38 Table* t = manage (new Table (3, 2));
43 l = manage (new Label (_("<b>Type:</b>"), Gtk::ALIGN_END, Gtk::ALIGN_CENTER, false));
45 t->attach (*l, 0, 1, ty, ty+1);
46 t->attach (_type, 1, 2, ty, ty+1);
49 l = manage (new Label (_("<b>Author:</b>"), Gtk::ALIGN_END, Gtk::ALIGN_CENTER, false));
51 t->attach (*l, 0, 1, ty, ty+1);
52 t->attach (_author, 1, 2, ty, ty+1);
55 l = manage (new Label (_("<b>Description:</b>"), Gtk::ALIGN_END, Gtk::ALIGN_CENTER, false));
57 t->attach (*l, 0, 1, ty, ty+1);
58 t->attach (_description, 1, 2, ty, ty+1);
61 _description.set_line_wrap();
63 get_vbox()->set_spacing (6);
64 get_vbox()->pack_start (_script_combo, false, false);
65 get_vbox()->pack_start (*t, true, true);
67 Button *r = Gtk::manage (new Gtk::Button (Stock::REFRESH));
68 r->signal_clicked().connect (sigc::mem_fun (*this, &ScriptSelector::refresh));
69 get_action_area()->pack_start(*r);
71 add_button (Stock::CANCEL, RESPONSE_CANCEL);
72 _add = add_button (Stock::ADD, RESPONSE_ACCEPT);
73 set_default_response (RESPONSE_ACCEPT);
75 _add->set_sensitive (false);
76 _combocon = _script_combo.signal_changed().connect (sigc::mem_fun (*this, &ScriptSelector::script_combo_changed));
83 ScriptSelector::setup_list ()
86 vector<string> script_names;
87 for (LuaScriptList::const_iterator s = _scripts.begin(); s != _scripts.end(); ++s) {
88 script_names.push_back ((*s)->name);
91 Gtkmm2ext::set_popdown_strings (_script_combo, script_names);
92 if (script_names.size() > 0) {
93 _script_combo.set_active(0);
94 script_combo_changed ();
100 ScriptSelector::script_combo_changed ()
102 int i = _script_combo.get_active_row_number();
103 _script = _scripts[i];
105 _type.set_text(LuaScriptInfo::type2str (_script->type));
106 _author.set_text (_script->author);
107 _description.set_text (_script->description);
109 _add->set_sensitive (Glib::file_test(_script->path, Glib::FILE_TEST_EXISTS));
113 ScriptSelector::refresh ()
115 LuaScripting::instance ().refresh ();
117 _scripts = LuaScripting::instance ().scripts (_script_type);
121 ///////////////////////////////////////////////////////////////////////////////
123 SessionScriptManager::SessionScriptManager (std::string title, const std::vector<std::string> &names)
124 : ArdourDialog (title)
126 assert (names.size() > 0);
127 Gtkmm2ext::set_popdown_strings (_names_combo, names);
128 _names_combo.set_active(0);
131 l = manage (new Label (_("Select Script to unload")));
133 get_vbox()->set_spacing (6);
134 get_vbox()->pack_start (*l, false, false);
135 get_vbox()->pack_start (_names_combo, false, false);
137 add_button (Stock::CANCEL, RESPONSE_CANCEL);
138 add_button (Stock::REMOVE, RESPONSE_ACCEPT);
139 set_default_response (RESPONSE_CANCEL);
144 ///////////////////////////////////////////////////////////////////////////////
147 ScriptParameterDialog::ScriptParameterDialog (std::string title,
148 const LuaScriptInfoPtr& spi,
149 const std::vector<std::string> &names,
150 LuaScriptParamList& lsp)
151 : ArdourDialog (title)
152 , _existing_names (names)
157 Table* t = manage (new Table (4, 3));
160 _name_entry.set_text (spi->name);
161 _name_entry.signal_changed().connect (sigc::mem_fun (*this, &ScriptParameterDialog::update_sensitivity));
165 l = manage (new Label (_("<b>Name:</b>"), Gtk::ALIGN_END, Gtk::ALIGN_CENTER, false));
166 l->set_use_markup ();
167 t->attach (*l, 0, 1, ty, ty+1);
168 t->attach (_name_entry, 1, 2, ty, ty+1);
171 if (_lsp.size () > 0) {
172 l = manage (new Label (_("<b>Instance Parameters</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
173 l->set_use_markup ();
174 t->attach (*l, 0, 2, ty, ty+1);
178 for (size_t i = 0; i < _lsp.size (); ++i) {
179 CheckButton* c = manage (new CheckButton (_lsp[i]->title));
180 Entry* e = manage (new Entry());
181 c->set_active (!_lsp[i]->optional); // also if default ??
182 c->set_sensitive (_lsp[i]->optional);
183 e->set_text (_lsp[i]->dflt);
184 e->set_sensitive (c->get_active ());
186 c->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &ScriptParameterDialog::active_changed), i, c, e));
187 e->signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &ScriptParameterDialog::value_changed), i, e));
189 t->attach (*c, 0, 1, ty, ty+1);
190 t->attach (*e, 1, 2, ty, ty+1);
194 add_button (Stock::CANCEL, RESPONSE_CANCEL);
195 _add = add_button (Stock::ADD, RESPONSE_ACCEPT);
196 set_default_response (RESPONSE_ACCEPT);
198 get_vbox()->pack_start (*t, true, true);
200 update_sensitivity ();
204 ScriptParameterDialog::update_sensitivity ()
206 std::string n = _name_entry.get_text ();
207 if (n.empty() || std::find (_existing_names.begin(), _existing_names.end(), n) != _existing_names.end()) {
208 _add->set_sensitive (false);
212 for (size_t i = 0; i < _lsp.size(); ++i) {
213 if (!_lsp[i]->optional && _lsp[i]->value.empty()) {
214 _add->set_sensitive (false);
219 _add->set_sensitive (true);
223 ScriptParameterDialog::active_changed (int i, Gtk::CheckButton* c, Gtk::Entry* e)
225 bool en = c->get_active ();
226 _lsp[i]->is_set = en;
227 e->set_sensitive (en);
231 ScriptParameterDialog::value_changed (int i, Gtk::Entry* e)
233 _lsp[i]->value = e->get_text ();