2 Copyright (C) 2007 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <gtkmm/stock.h>
21 #include <gtkmm/button.h>
22 #include <gtkmm/label.h>
23 #include <gtkmm/entry.h>
24 #include <gtkmm/table.h>
25 #include <gtkmm/comboboxtext.h>
26 #include <gtkmm/alignment.h>
27 #include "ardour/session.h"
28 #include "ardour/user_bundle.h"
29 #include "ardour/audioengine.h"
30 #include "bundle_manager.h"
33 BundleEditorMatrix::BundleEditorMatrix (
34 ARDOUR::Session& session, boost::shared_ptr<ARDOUR::Bundle> bundle
37 session, bundle->type(), bundle->ports_are_inputs(),
38 PortGroupList::Mask (PortGroupList::SYSTEM | PortGroupList::OTHER)
41 _bundle = boost::dynamic_pointer_cast<ARDOUR::UserBundle> (bundle);
42 assert (_bundle != 0);
46 BundleEditorMatrix::set_state (int r, std::string const & p, bool s)
49 _bundle->add_port_to_channel (r, p);
51 _bundle->remove_port_from_channel (r, p);
56 BundleEditorMatrix::get_state (int r, std::string const & p) const
58 return _bundle->port_attached_to_channel (r, p);
62 BundleEditorMatrix::n_rows () const
64 return _bundle->nchannels ().n_total();
68 BundleEditorMatrix::maximum_rows () const
70 /* 65536 channels in a bundle ought to be enough for anyone (TM) */
75 BundleEditorMatrix::minimum_rows () const
81 BundleEditorMatrix::row_name (int r) const
89 BundleEditorMatrix::add_row ()
91 _bundle->add_channel ();
96 BundleEditorMatrix::remove_row (int r)
98 _bundle->remove_channel (r);
103 BundleEditorMatrix::row_descriptor () const
108 BundleEditor::BundleEditor (ARDOUR::Session& session, boost::shared_ptr<ARDOUR::UserBundle> bundle, bool add)
109 : ArdourDialog (_("Edit Bundle")), _matrix (session, bundle), _bundle (bundle)
111 Gtk::Table* t = new Gtk::Table (3, 2);
114 Gtk::Alignment* a = new Gtk::Alignment (1, 0.5, 0, 1);
115 a->add (*Gtk::manage (new Gtk::Label (_("Name:"))));
116 t->attach (*Gtk::manage (a), 0, 1, 0, 1, Gtk::FILL, Gtk::FILL);
117 t->attach (_name, 1, 2, 0, 1);
119 _name.set_text (_bundle->name ());
120 _name.signal_changed().connect (sigc::mem_fun (*this, &BundleEditor::name_changed));
122 a = new Gtk::Alignment (1, 0.5, 0, 1);
123 a->add (*Gtk::manage (new Gtk::Label (_("Direction:"))));
124 t->attach (*Gtk::manage (a), 0, 1, 1, 2, Gtk::FILL, Gtk::FILL);
125 a = new Gtk::Alignment (0, 0.5, 0, 1);
126 a->add (_input_or_output);
127 t->attach (*Gtk::manage (a), 1, 2, 1, 2);
129 _input_or_output.append_text (_("Input"));
130 _input_or_output.append_text (_("Output"));
132 if (bundle->ports_are_inputs()) {
133 _input_or_output.set_active_text (_("Output"));
135 _input_or_output.set_active_text (_("Input"));
138 _input_or_output.signal_changed().connect (sigc::mem_fun (*this, &BundleEditor::input_or_output_changed));
140 a = new Gtk::Alignment (1, 0.5, 0, 1);
141 a->add (*Gtk::manage (new Gtk::Label (_("Type:"))));
142 t->attach (*Gtk::manage (a), 0, 1, 2, 3, Gtk::FILL, Gtk::FILL);
143 a = new Gtk::Alignment (0, 0.5, 0, 1);
145 t->attach (*Gtk::manage (a), 1, 2, 2, 3);
147 _type.append_text (_("Audio"));
148 _type.append_text (_("MIDI"));
150 switch (bundle->type ()) {
151 case ARDOUR::DataType::AUDIO:
152 _type.set_active_text (_("Audio"));
154 case ARDOUR::DataType::MIDI:
155 _type.set_active_text (_("MIDI"));
159 _type.signal_changed().connect (sigc::mem_fun (*this, &BundleEditor::type_changed));
161 get_vbox()->pack_start (*Gtk::manage (t), false, false);
163 get_vbox()->pack_start (_matrix);
165 get_vbox()->set_spacing (4);
168 add_button (Gtk::Stock::CANCEL, 1);
169 add_button (Gtk::Stock::ADD, 0);
171 add_button (Gtk::Stock::CLOSE, 0);
178 BundleEditor::name_changed ()
180 _bundle->set_name (_name.get_text ());
184 BundleEditor::input_or_output_changed ()
186 if (_input_or_output.get_active_text() == _("Output")) {
187 _bundle->set_ports_are_inputs ();
188 _matrix.set_offer_inputs (true);
190 _bundle->set_ports_are_outputs ();
191 _matrix.set_offer_inputs (false);
196 BundleEditor::type_changed ()
198 ARDOUR::DataType const t = _type.get_active_text() == _("Audio") ?
199 ARDOUR::DataType::AUDIO : ARDOUR::DataType::MIDI;
201 _bundle->set_type (t);
202 _matrix.set_type (t);
206 BundleEditor::on_map ()
208 _matrix.redisplay ();
213 BundleManager::BundleManager (ARDOUR::Session& session)
214 : ArdourDialog (_("Bundle manager")), _session (session), edit_button (_("Edit")), delete_button (_("Delete"))
216 _list_model = Gtk::ListStore::create (_list_model_columns);
217 _tree_view.set_model (_list_model);
218 _tree_view.append_column (_("Name"), _list_model_columns.name);
219 _tree_view.set_headers_visible (false);
221 _session.foreach_bundle (sigc::mem_fun (*this, &BundleManager::add_bundle));
223 /* New / Edit / Delete buttons */
224 Gtk::VBox* buttons = new Gtk::VBox;
225 buttons->set_spacing (8);
226 Gtk::Button* b = new Gtk::Button (_("New"));
227 b->set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::NEW, Gtk::ICON_SIZE_BUTTON)));
228 b->signal_clicked().connect (sigc::mem_fun (*this, &BundleManager::new_clicked));
229 buttons->pack_start (*Gtk::manage (b), false, false);
230 edit_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::EDIT, Gtk::ICON_SIZE_BUTTON)));
231 edit_button.signal_clicked().connect (sigc::mem_fun (*this, &BundleManager::edit_clicked));
232 buttons->pack_start (edit_button, false, false);
233 delete_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::DELETE, Gtk::ICON_SIZE_BUTTON)));
234 delete_button.signal_clicked().connect (sigc::mem_fun (*this, &BundleManager::delete_clicked));
235 buttons->pack_start (delete_button, false, false);
237 Gtk::HBox* h = new Gtk::HBox;
239 h->set_border_width (8);
240 h->pack_start (_tree_view);
241 h->pack_start (*Gtk::manage (buttons), false, false);
243 get_vbox()->set_spacing (8);
244 get_vbox()->pack_start (*Gtk::manage (h));
246 set_default_size (480, 240);
248 _tree_view.get_selection()->signal_changed().connect (
249 sigc::mem_fun (*this, &BundleManager::set_button_sensitivity)
252 set_button_sensitivity ();
258 BundleManager::set_button_sensitivity ()
260 bool const sel = (_tree_view.get_selection()->get_selected() != 0);
261 edit_button.set_sensitive (sel);
262 delete_button.set_sensitive (sel);
267 BundleManager::new_clicked ()
269 boost::shared_ptr<ARDOUR::UserBundle> b (new ARDOUR::UserBundle (""));
271 /* Start off with a single channel */
274 BundleEditor e (_session, b, true);
276 _session.add_bundle (b);
282 BundleManager::edit_clicked ()
284 Gtk::TreeModel::iterator i = _tree_view.get_selection()->get_selected();
286 boost::shared_ptr<ARDOUR::UserBundle> b = (*i)[_list_model_columns.bundle];
287 BundleEditor e (_session, b, false);
294 BundleManager::delete_clicked ()
296 Gtk::TreeModel::iterator i = _tree_view.get_selection()->get_selected();
298 boost::shared_ptr<ARDOUR::UserBundle> b = (*i)[_list_model_columns.bundle];
299 _session.remove_bundle (b);
300 _list_model->erase (i);
305 BundleManager::add_bundle (boost::shared_ptr<ARDOUR::Bundle> b)
307 boost::shared_ptr<ARDOUR::UserBundle> u = boost::dynamic_pointer_cast<ARDOUR::UserBundle> (b);
312 Gtk::TreeModel::iterator i = _list_model->append ();
313 (*i)[_list_model_columns.name] = u->name ();
314 (*i)[_list_model_columns.bundle] = u;
316 u->NameChanged.connect (sigc::bind (sigc::mem_fun (*this, &BundleManager::bundle_name_changed), u));
320 BundleManager::bundle_name_changed (boost::shared_ptr<ARDOUR::UserBundle> b)
322 Gtk::TreeModel::iterator i = _list_model->children().begin ();
323 while (i != _list_model->children().end()) {
324 boost::shared_ptr<ARDOUR::UserBundle> t = (*i)[_list_model_columns.bundle];
331 if (i != _list_model->children().end()) {
332 (*i)[_list_model_columns.name] = b->name ();