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)
45 BundleEditorMatrix::set_state (
46 boost::shared_ptr<ARDOUR::Bundle> ab,
48 boost::shared_ptr<ARDOUR::Bundle> bb,
54 ARDOUR::Bundle::PortList const& pl = bb->channel_ports (bc);
55 for (ARDOUR::Bundle::PortList::const_iterator i = pl.begin(); i != pl.end(); ++i) {
57 ab->add_port_to_channel (ac, *i);
59 ab->remove_port_from_channel (ac, *i);
65 BundleEditorMatrix::get_state (
66 boost::shared_ptr<ARDOUR::Bundle> ab,
68 boost::shared_ptr<ARDOUR::Bundle> bb,
72 ARDOUR::Bundle::PortList const& pl = bb->channel_ports (bc);
73 for (ARDOUR::Bundle::PortList::const_iterator i = pl.begin(); i != pl.end(); ++i) {
74 if (!ab->port_attached_to_channel (ac, *i)) {
83 BundleEditorMatrix::add_channel (boost::shared_ptr<ARDOUR::Bundle> b)
86 d.set_position (Gtk::WIN_POS_MOUSE);
88 if (d.run () != Gtk::RESPONSE_ACCEPT) {
92 _our_bundle->add_channel (d.get_name());
97 BundleEditorMatrix::remove_channel (boost::shared_ptr<ARDOUR::Bundle> b, uint32_t c)
99 _our_bundle->remove_channel (c);
104 BundleEditorMatrix::rename_channel (boost::shared_ptr<ARDOUR::Bundle> b, uint32_t c)
106 NameChannelDialog d (b, c);
107 d.set_position (Gtk::WIN_POS_MOUSE);
109 if (d.run () != Gtk::RESPONSE_ACCEPT) {
113 b->set_channel_name (c, d.get_name ());
116 BundleEditor::BundleEditor (ARDOUR::Session& session, boost::shared_ptr<ARDOUR::UserBundle> bundle, bool add)
117 : ArdourDialog (_("Edit Bundle")), _matrix (session, bundle), _bundle (bundle)
119 Gtk::Table* t = new Gtk::Table (3, 2);
123 Gtk::Alignment* a = new Gtk::Alignment (1, 0.5, 0, 1);
124 a->add (*Gtk::manage (new Gtk::Label (_("Name:"))));
125 t->attach (*Gtk::manage (a), 0, 1, 0, 1, Gtk::FILL, Gtk::FILL);
126 t->attach (_name, 1, 2, 0, 1);
127 _name.set_text (_bundle->name ());
128 _name.signal_changed().connect (sigc::mem_fun (*this, &BundleEditor::name_changed));
130 /* Direction (input or output) */
131 a = new Gtk::Alignment (1, 0.5, 0, 1);
132 a->add (*Gtk::manage (new Gtk::Label (_("Direction:"))));
133 t->attach (*Gtk::manage (a), 0, 1, 1, 2, Gtk::FILL, Gtk::FILL);
134 a = new Gtk::Alignment (0, 0.5, 0, 1);
135 a->add (_input_or_output);
136 t->attach (*Gtk::manage (a), 1, 2, 1, 2);
137 _input_or_output.append_text (_("Input"));
138 _input_or_output.append_text (_("Output"));
140 if (bundle->ports_are_inputs()) {
141 _input_or_output.set_active_text (_("Output"));
143 _input_or_output.set_active_text (_("Input"));
146 _input_or_output.signal_changed().connect (sigc::mem_fun (*this, &BundleEditor::input_or_output_changed));
148 /* Type (audio or MIDI) */
149 a = new Gtk::Alignment (1, 0.5, 0, 1);
150 a->add (*Gtk::manage (new Gtk::Label (_("Type:"))));
151 t->attach (*Gtk::manage (a), 0, 1, 2, 3, Gtk::FILL, Gtk::FILL);
152 a = new Gtk::Alignment (0, 0.5, 0, 1);
154 t->attach (*Gtk::manage (a), 1, 2, 2, 3);
156 _type.append_text (_("Audio"));
157 _type.append_text (_("MIDI"));
159 switch (bundle->type ()) {
160 case ARDOUR::DataType::AUDIO:
161 _type.set_active_text (_("Audio"));
163 case ARDOUR::DataType::MIDI:
164 _type.set_active_text (_("MIDI"));
168 _type.signal_changed().connect (sigc::mem_fun (*this, &BundleEditor::type_changed));
170 get_vbox()->pack_start (*Gtk::manage (t), false, false);
171 get_vbox()->pack_start (_matrix);
172 get_vbox()->set_spacing (4);
174 /* Add Channel button */
175 Gtk::Button* add_channel_button = Gtk::manage (new Gtk::Button (_("Add Channel")));
176 add_channel_button->set_name ("IOSelectorButton");
177 add_channel_button->set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::ADD, Gtk::ICON_SIZE_BUTTON)));
178 get_action_area()->pack_start (*add_channel_button, false, false);
179 add_channel_button->signal_clicked().connect (sigc::bind (sigc::mem_fun (_matrix, &BundleEditorMatrix::add_channel), boost::shared_ptr<ARDOUR::Bundle> ()));
182 add_button (Gtk::Stock::CANCEL, 1);
183 add_button (Gtk::Stock::ADD, 0);
185 add_button (Gtk::Stock::CLOSE, 0);
192 BundleEditor::name_changed ()
194 _bundle->set_name (_name.get_text ());
198 BundleEditor::input_or_output_changed ()
200 if (_input_or_output.get_active_text() == _("Output")) {
201 _bundle->set_ports_are_inputs ();
202 _matrix.set_offer_inputs (true);
204 _bundle->set_ports_are_outputs ();
205 _matrix.set_offer_inputs (false);
210 BundleEditor::type_changed ()
212 ARDOUR::DataType const t = _type.get_active_text() == _("Audio") ?
213 ARDOUR::DataType::AUDIO : ARDOUR::DataType::MIDI;
215 _bundle->set_type (t);
216 _matrix.set_type (t);
220 BundleEditor::on_map ()
227 BundleManager::BundleManager (ARDOUR::Session& session)
228 : ArdourDialog (_("Bundle manager")), _session (session), edit_button (_("Edit")), delete_button (_("Delete"))
230 _list_model = Gtk::ListStore::create (_list_model_columns);
231 _tree_view.set_model (_list_model);
232 _tree_view.append_column (_("Name"), _list_model_columns.name);
233 _tree_view.set_headers_visible (false);
235 _session.foreach_bundle (sigc::mem_fun (*this, &BundleManager::add_bundle));
237 /* New / Edit / Delete buttons */
238 Gtk::VBox* buttons = new Gtk::VBox;
239 buttons->set_spacing (8);
240 Gtk::Button* b = new Gtk::Button (_("New"));
241 b->set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::NEW, Gtk::ICON_SIZE_BUTTON)));
242 b->signal_clicked().connect (sigc::mem_fun (*this, &BundleManager::new_clicked));
243 buttons->pack_start (*Gtk::manage (b), false, false);
244 edit_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::EDIT, Gtk::ICON_SIZE_BUTTON)));
245 edit_button.signal_clicked().connect (sigc::mem_fun (*this, &BundleManager::edit_clicked));
246 buttons->pack_start (edit_button, false, false);
247 delete_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::DELETE, Gtk::ICON_SIZE_BUTTON)));
248 delete_button.signal_clicked().connect (sigc::mem_fun (*this, &BundleManager::delete_clicked));
249 buttons->pack_start (delete_button, false, false);
251 Gtk::HBox* h = new Gtk::HBox;
253 h->set_border_width (8);
254 h->pack_start (_tree_view);
255 h->pack_start (*Gtk::manage (buttons), false, false);
257 get_vbox()->set_spacing (8);
258 get_vbox()->pack_start (*Gtk::manage (h));
260 set_default_size (480, 240);
262 _tree_view.get_selection()->signal_changed().connect (
263 sigc::mem_fun (*this, &BundleManager::set_button_sensitivity)
266 set_button_sensitivity ();
272 BundleManager::set_button_sensitivity ()
274 bool const sel = (_tree_view.get_selection()->get_selected() != 0);
275 edit_button.set_sensitive (sel);
276 delete_button.set_sensitive (sel);
281 BundleManager::new_clicked ()
283 boost::shared_ptr<ARDOUR::UserBundle> b (new ARDOUR::UserBundle (""));
285 /* Start off with a single channel */
288 BundleEditor e (_session, b, true);
290 _session.add_bundle (b);
296 BundleManager::edit_clicked ()
298 Gtk::TreeModel::iterator i = _tree_view.get_selection()->get_selected();
300 boost::shared_ptr<ARDOUR::UserBundle> b = (*i)[_list_model_columns.bundle];
301 BundleEditor e (_session, b, false);
308 BundleManager::delete_clicked ()
310 Gtk::TreeModel::iterator i = _tree_view.get_selection()->get_selected();
312 boost::shared_ptr<ARDOUR::UserBundle> b = (*i)[_list_model_columns.bundle];
313 _session.remove_bundle (b);
314 _list_model->erase (i);
319 BundleManager::add_bundle (boost::shared_ptr<ARDOUR::Bundle> b)
321 boost::shared_ptr<ARDOUR::UserBundle> u = boost::dynamic_pointer_cast<ARDOUR::UserBundle> (b);
326 Gtk::TreeModel::iterator i = _list_model->append ();
327 (*i)[_list_model_columns.name] = u->name ();
328 (*i)[_list_model_columns.bundle] = u;
330 u->NameChanged.connect (sigc::bind (sigc::mem_fun (*this, &BundleManager::bundle_name_changed), u));
334 BundleManager::bundle_name_changed (boost::shared_ptr<ARDOUR::UserBundle> b)
336 Gtk::TreeModel::iterator i = _list_model->children().begin ();
337 while (i != _list_model->children().end()) {
338 boost::shared_ptr<ARDOUR::UserBundle> t = (*i)[_list_model_columns.bundle];
345 if (i != _list_model->children().end()) {
346 (*i)[_list_model_columns.name] = b->name ();
351 NameChannelDialog::NameChannelDialog ()
352 : ArdourDialog (_("Add channel")),
358 NameChannelDialog::NameChannelDialog (boost::shared_ptr<ARDOUR::Bundle> b, uint32_t c)
359 : ArdourDialog (_("Rename channel")),
364 _name.set_text (b->channel_name (c));
370 NameChannelDialog::setup ()
372 Gtk::HBox* box = Gtk::manage (new Gtk::HBox ());
374 box->pack_start (*Gtk::manage (new Gtk::Label (_("Name"))));
375 box->pack_start (_name);
377 get_vbox ()->pack_end (*box);
380 add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
382 add_button (Gtk::Stock::ADD, Gtk::RESPONSE_ACCEPT);
384 add_button (Gtk::Stock::APPLY, Gtk::RESPONSE_ACCEPT);
386 set_default_response (Gtk::RESPONSE_ACCEPT);
390 NameChannelDialog::get_name () const
392 return _name.get_text ();