the big Route structure refactor. !!!! THIS WILL ***NOT LOAD*** PRIOR 3.0 or 2.X...
[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 <gtkmm/widget.h>
26 #include <gtkmm/checkbutton.h>
27 #include <boost/shared_ptr.hpp>
28 #include "ardour/data_type.h"
29 #include "ardour/types.h"
30
31 namespace ARDOUR {
32         class Session;
33         class Bundle;
34         class Processor;
35 }
36
37 class PortMatrix;
38 class RouteBundle;
39
40 /** A list of bundles and ports, grouped by some aspect of their
41  *  type e.g. busses, tracks, system.  Each group has 0 or more bundles
42  *  and 0 or more ports, where the ports are not in the bundles.
43  */
44 class PortGroup : public sigc::trackable
45 {
46 public:
47         PortGroup (std::string const & n);
48
49         void add_bundle (boost::shared_ptr<ARDOUR::Bundle>);
50         void remove_bundle (boost::shared_ptr<ARDOUR::Bundle>);
51         boost::shared_ptr<ARDOUR::Bundle> only_bundle ();
52         void clear ();
53         uint32_t total_channels () const;
54
55         std::string name; ///< name for the group
56
57         ARDOUR::BundleList const & bundles () const {
58                 return _bundles;
59         }
60         
61         bool visible () const {
62                 return _visible;
63         }
64
65         void set_visible (bool v) {
66                 _visible = v;
67                 Modified ();
68         }
69
70         bool has_port (std::string const &) const;
71
72         sigc::signal<void> Modified;
73         sigc::signal<void, ARDOUR::Bundle::Change> BundleChanged;
74
75 private:
76         void bundle_changed (ARDOUR::Bundle::Change);
77         
78         ARDOUR::BundleList _bundles;
79
80         typedef std::map<boost::shared_ptr<ARDOUR::Bundle>, sigc::connection> ConnectionList;
81         ConnectionList _bundle_changed_connections;
82         
83         bool _visible; ///< true if the group is visible in the UI
84 };
85
86 /// A list of PortGroups
87 class PortGroupList : public sigc::trackable
88 {
89   public:
90         PortGroupList ();
91
92         typedef std::vector<boost::shared_ptr<PortGroup> > List;
93
94         void add_group (boost::shared_ptr<PortGroup>);
95         void set_type (ARDOUR::DataType);
96         void gather (ARDOUR::Session &, bool);
97         ARDOUR::BundleList const & bundles () const;
98         void clear ();
99         void remove_bundle (boost::shared_ptr<ARDOUR::Bundle>);
100         uint32_t total_visible_channels () const;
101         uint32_t size () const {
102                 return _groups.size();
103         }
104
105         void suspend_signals ();
106         void resume_signals ();
107
108         List::const_iterator begin () const {
109                 return _groups.begin();
110         }
111
112         List::const_iterator end () const {
113                 return _groups.end();
114         }
115
116         sigc::signal<void> Changed;
117
118   private:
119         bool port_has_prefix (std::string const &, std::string const &) const;
120         std::string common_prefix (std::vector<std::string> const &) const;
121         std::string common_prefix_before (std::vector<std::string> const &, std::string const &) const;
122         void emit_changed ();
123         boost::shared_ptr<ARDOUR::Bundle> make_bundle_from_ports (std::vector<std::string> const &, bool) const;
124         void maybe_add_processor_to_bundle (boost::weak_ptr<ARDOUR::Processor>, boost::shared_ptr<RouteBundle>, bool);
125
126         ARDOUR::DataType _type;
127         mutable ARDOUR::BundleList _bundles;
128         List _groups;
129         std::vector<sigc::connection> _bundle_changed_connections;
130         bool _signals_suspended;
131         bool _pending_change;
132 };
133
134
135 class RouteBundle : public ARDOUR::Bundle
136 {
137 public:
138         RouteBundle (boost::shared_ptr<ARDOUR::Bundle>);
139
140         void add_processor_bundle (boost::shared_ptr<ARDOUR::Bundle>);
141
142 private:
143         void reread_component_bundles ();
144         
145         boost::shared_ptr<ARDOUR::Bundle> _route;
146         std::vector<boost::shared_ptr<ARDOUR::Bundle> > _processor;
147 };
148
149 #endif /* __gtk_ardour_port_group_h__ */