Tidy up a bit in the case where the port matrix has nothing to display.
[ardour.git] / gtk2_ardour / port_group.h
1 /*
2     Copyright (C) 2002-2009 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef  __gtk_ardour_port_group_h__
21 #define  __gtk_ardour_port_group_h__
22
23 #include <vector>
24 #include <string>
25 #include <set>
26 #include <gtkmm/widget.h>
27 #include <gtkmm/checkbutton.h>
28 #include <boost/shared_ptr.hpp>
29 #include "ardour/data_type.h"
30 #include "ardour/types.h"
31
32 namespace ARDOUR {
33         class Session;
34         class Bundle;
35         class Processor;
36         class IO;
37 }
38
39 class PortMatrix;
40 class RouteBundle;
41 class PublicEditor;
42
43 /** A list of bundles and ports, grouped by some aspect of their
44  *  type e.g. busses, tracks, system.  Each group has 0 or more bundles
45  *  and 0 or more ports, where the ports are not in the bundles.
46  */
47 class PortGroup : public sigc::trackable
48 {
49 public:
50         PortGroup (std::string const & n);
51
52         void add_bundle (boost::shared_ptr<ARDOUR::Bundle>, bool allow_dups = false);
53         void add_bundle (boost::shared_ptr<ARDOUR::Bundle>, boost::shared_ptr<ARDOUR::IO> io);
54         void add_bundle (boost::shared_ptr<ARDOUR::Bundle>, boost::shared_ptr<ARDOUR::IO>, Gdk::Color);
55         void remove_bundle (boost::shared_ptr<ARDOUR::Bundle>);
56         boost::shared_ptr<ARDOUR::Bundle> only_bundle ();
57         void clear ();
58         uint32_t total_channels () const;
59         boost::shared_ptr<ARDOUR::IO> io_from_bundle (boost::shared_ptr<ARDOUR::Bundle>) const;
60
61         std::string name; ///< name for the group
62
63         bool visible () const {
64                 return _visible;
65         }
66
67         void set_visible (bool v) {
68                 _visible = v;
69                 Changed ();
70         }
71
72         bool has_port (std::string const &) const;
73
74         sigc::signal<void> Changed;
75         sigc::signal<void, ARDOUR::Bundle::Change> BundleChanged;
76
77         struct BundleRecord {
78                 boost::shared_ptr<ARDOUR::Bundle> bundle;
79                 /** IO whose ports are in the bundle, or 0.  This is so that we can do things like adding
80                     ports to the IO from matrix editor menus. */
81                 boost::shared_ptr<ARDOUR::IO> io; 
82                 Gdk::Color colour;
83                 bool has_colour;
84                 sigc::connection changed_connection;
85         };
86
87         typedef std::list<BundleRecord> BundleList;
88
89         BundleList const & bundles () const {
90                 return _bundles;
91         }
92
93 private:
94         void bundle_changed (ARDOUR::Bundle::Change);
95         void add_bundle_internal (boost::shared_ptr<ARDOUR::Bundle>, boost::shared_ptr<ARDOUR::IO>, bool, Gdk::Color, bool);
96
97         BundleList _bundles;
98         bool _visible; ///< true if the group is visible in the UI
99 };
100
101 /// A list of PortGroups
102 class PortGroupList : public sigc::trackable
103 {
104   public:
105         PortGroupList ();
106
107         typedef std::vector<boost::shared_ptr<PortGroup> > List;
108
109         void add_group (boost::shared_ptr<PortGroup>);
110         void set_type (ARDOUR::DataType);
111         void gather (ARDOUR::Session &, bool, bool);
112         PortGroup::BundleList const & bundles () const;
113         void clear ();
114         void remove_bundle (boost::shared_ptr<ARDOUR::Bundle>);
115         uint32_t total_visible_channels () const;
116         uint32_t size () const {
117                 return _groups.size();
118         }
119         boost::shared_ptr<ARDOUR::IO> io_from_bundle (boost::shared_ptr<ARDOUR::Bundle>) const;
120
121         void suspend_signals ();
122         void resume_signals ();
123
124         List::const_iterator begin () const {
125                 return _groups.begin ();
126         }
127
128         List::const_iterator end () const {
129                 return _groups.end ();
130         }
131
132         bool empty () const;
133
134         sigc::signal<void> Changed;
135         sigc::signal<void, ARDOUR::Bundle::Change> BundleChanged;
136
137   private:
138         bool port_has_prefix (std::string const &, std::string const &) const;
139         std::string common_prefix (std::vector<std::string> const &) const;
140         std::string common_prefix_before (std::vector<std::string> const &, std::string const &) const;
141         void emit_changed ();
142         void emit_bundle_changed (ARDOUR::Bundle::Change);
143         boost::shared_ptr<ARDOUR::Bundle> make_bundle_from_ports (std::vector<std::string> const &, bool) const;
144         void maybe_add_processor_to_bundle (boost::weak_ptr<ARDOUR::Processor>, boost::shared_ptr<RouteBundle>, bool, std::set<boost::shared_ptr<ARDOUR::IO> > &);
145
146         ARDOUR::DataType _type;
147         mutable PortGroup::BundleList _bundles;
148         List _groups;
149         std::vector<sigc::connection> _bundle_changed_connections;
150         bool _signals_suspended;
151         bool _pending_change;
152         ARDOUR::Bundle::Change _pending_bundle_change;
153 };
154
155
156 class RouteBundle : public ARDOUR::Bundle
157 {
158 public:
159         RouteBundle (boost::shared_ptr<ARDOUR::Bundle>);
160
161         void add_processor_bundle (boost::shared_ptr<ARDOUR::Bundle>);
162
163 private:
164         void reread_component_bundles ();
165
166         boost::shared_ptr<ARDOUR::Bundle> _route;
167         std::vector<boost::shared_ptr<ARDOUR::Bundle> > _processor;
168 };
169
170 #endif /* __gtk_ardour_port_group_h__ */