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 ();
116 _scripts = LuaScripting::instance ().scripts (_script_type);
120 ///////////////////////////////////////////////////////////////////////////////
122 SessionScriptManager::SessionScriptManager (std::string title, const std::vector<std::string> &names)
123 : ArdourDialog (title)
125 assert (names.size() > 0);
126 Gtkmm2ext::set_popdown_strings (_names_combo, names);
127 _names_combo.set_active(0);
130 l = manage (new Label (_("Select Script to unload")));
132 get_vbox()->set_spacing (6);
133 get_vbox()->pack_start (*l, false, false);
134 get_vbox()->pack_start (_names_combo, false, false);
136 add_button (Stock::CANCEL, RESPONSE_CANCEL);
137 add_button (Stock::REMOVE, RESPONSE_ACCEPT);
138 set_default_response (RESPONSE_CANCEL);
143 ///////////////////////////////////////////////////////////////////////////////
146 ScriptParameterDialog::ScriptParameterDialog (std::string title,
147 const LuaScriptInfoPtr& spi,
148 const std::vector<std::string> &names,
149 LuaScriptParamList& lsp)
150 : ArdourDialog (title)
151 , _existing_names (names)
156 Table* t = manage (new Table (4, 3));
159 _name_entry.set_text (spi->name);
160 _name_entry.signal_changed().connect (sigc::mem_fun (*this, &ScriptParameterDialog::update_sensitivity));
164 l = manage (new Label (_("<b>Name:</b>"), Gtk::ALIGN_END, Gtk::ALIGN_CENTER, false));
165 l->set_use_markup ();
166 t->attach (*l, 0, 1, ty, ty+1);
167 t->attach (_name_entry, 1, 2, ty, ty+1);
170 if (_lsp.size () > 0) {
171 l = manage (new Label (_("<b>Instance Parameters</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
172 l->set_use_markup ();
173 t->attach (*l, 0, 2, ty, ty+1);
177 for (size_t i = 0; i < _lsp.size (); ++i) {
178 CheckButton* c = manage (new CheckButton (_lsp[i]->title));
179 Entry* e = manage (new Entry());
180 c->set_active (!_lsp[i]->optional); // also if default ??
181 c->set_sensitive (_lsp[i]->optional);
182 e->set_text (_lsp[i]->dflt);
183 e->set_sensitive (c->get_active ());
185 c->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &ScriptParameterDialog::active_changed), i, c, e));
186 e->signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &ScriptParameterDialog::value_changed), i, e));
188 t->attach (*c, 0, 1, ty, ty+1);
189 t->attach (*e, 1, 2, ty, ty+1);
193 add_button (Stock::CANCEL, RESPONSE_CANCEL);
194 _add = add_button (Stock::ADD, RESPONSE_ACCEPT);
195 set_default_response (RESPONSE_ACCEPT);
197 get_vbox()->pack_start (*t, true, true);
199 update_sensitivity ();
203 ScriptParameterDialog::update_sensitivity ()
205 std::string n = _name_entry.get_text ();
206 if (n.empty() || std::find (_existing_names.begin(), _existing_names.end(), n) != _existing_names.end()) {
207 _add->set_sensitive (false);
211 for (size_t i = 0; i < _lsp.size(); ++i) {
212 if (!_lsp[i]->optional && _lsp[i]->value.empty()) {
213 _add->set_sensitive (false);
218 _add->set_sensitive (true);
222 ScriptParameterDialog::active_changed (int i, Gtk::CheckButton* c, Gtk::Entry* e)
224 bool en = c->get_active ();
225 _lsp[i]->is_set = en;
226 e->set_sensitive (en);
230 ScriptParameterDialog::value_changed (int i, Gtk::Entry* e)
232 _lsp[i]->value = e->get_text ();