1 /*
2  * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2008-2010 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2014 David Robillard <d@drobilla.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef __ardour_ui_bundle_manager_h__
22 #define __ardour_ui_bundle_manager_h__
23 
24 #include <gtkmm/entry.h>
25 #include <gtkmm/liststore.h>
26 #include <gtkmm/treeview.h>
27 
28 #include "ardour/user_bundle.h"
29 
30 #include "ardour_dialog.h"
31 #include "port_matrix.h"
32 
33 namespace ARDOUR {
34 	class Session;
35 	class Bundle;
36 }
37 
38 class BundleEditorMatrix : public PortMatrix
39 {
40 public:
41 	BundleEditorMatrix (Gtk::Window *, ARDOUR::Session *, boost::shared_ptr<ARDOUR::Bundle>);
42 
43 	void set_state (ARDOUR::BundleChannel c[2], bool s);
44 	PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const;
45 
46 	bool can_add_channels (boost::shared_ptr<ARDOUR::Bundle>) const;
47 	bool can_add_port (boost::shared_ptr<ARDOUR::Bundle>, ARDOUR::DataType t) const;
48 
49 	void add_channel (boost::shared_ptr<ARDOUR::Bundle>, ARDOUR::DataType);
50 	bool can_remove_channels (boost::shared_ptr<ARDOUR::Bundle>) const;
51 	void remove_channel (ARDOUR::BundleChannel);
52 	bool can_rename_channels (boost::shared_ptr<ARDOUR::Bundle>) const;
53 	void rename_channel (ARDOUR::BundleChannel);
54 	void setup_ports (int);
55 	bool list_is_global (int) const;
56 
57 	std::string disassociation_verb () const;
58 
59 private:
60 	enum {
61 		OTHER = 0,
62 		OURS = 1
63 	};
64 
65 	boost::shared_ptr<PortGroup> _port_group;
66 	boost::shared_ptr<ARDOUR::Bundle> _bundle;
67 };
68 
69 class BundleEditor : public ArdourDialog
70 {
71 public:
72 	BundleEditor (ARDOUR::Session *, boost::shared_ptr<ARDOUR::UserBundle>);
73 
74 protected:
75 	void on_map ();
76 
77 private:
78 	void name_changed ();
79 	void input_or_output_changed ();
80 	void on_show ();
81 
82 	BundleEditorMatrix _matrix;
83 	boost::shared_ptr<ARDOUR::UserBundle> _bundle;
84 	Gtk::Entry _name;
85 	Gtk::ComboBoxText _input_or_output;
86 };
87 
88 class BundleManager : public ArdourDialog
89 {
90 public:
91 	BundleManager (ARDOUR::Session *);
92 
93 private:
94 
95 	void new_clicked ();
96 	void edit_clicked ();
97 	void delete_clicked ();
98 	void add_bundle (boost::shared_ptr<ARDOUR::Bundle>);
99 	void bundle_changed (ARDOUR::Bundle::Change, boost::weak_ptr<ARDOUR::UserBundle>);
100 	void set_button_sensitivity ();
101 	void row_activated (Gtk::TreeModel::Path const & p, Gtk::TreeViewColumn* c);
102 
103 	class ModelColumns : public Gtk::TreeModelColumnRecord
104 	{
105 	public:
ModelColumns()106 		ModelColumns () {
107 			add (name);
108 			add (bundle);
109 		}
110 
111 		Gtk::TreeModelColumn<std::string> name;
112 		Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::UserBundle> > bundle;
113 	};
114 
115 	Gtk::TreeView _tree_view;
116 	Glib::RefPtr<Gtk::ListStore> _list_model;
117 	ModelColumns _list_model_columns;
118 	Gtk::Button edit_button;
119 	Gtk::Button delete_button;
120 	PBD::ScopedConnectionList bundle_connections;
121 };
122 
123 class NameChannelDialog : public ArdourDialog
124 {
125 public:
126 	NameChannelDialog ();
127 	NameChannelDialog (boost::shared_ptr<ARDOUR::Bundle>, uint32_t);
128 
129 	std::string get_name () const;
130 
131 private:
132 
133 	void setup ();
134 
135 	boost::shared_ptr<ARDOUR::Bundle> _bundle;
136 	Gtk::Entry _name;
137 	bool _adding;
138 };
139 
140 #endif
141