switch to using boost::signals2 instead of sigc++, at least for libardour. not finish...
[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 <boost/shared_ptr.hpp>
27 #include <boost/signals2.hpp>
28
29 #include <gtkmm/widget.h>
30 #include <gtkmm/checkbutton.h>
31
32 #include "ardour/data_type.h"
33 #include "ardour/types.h"
34
35 namespace ARDOUR {
36         class Session;
37         class Bundle;
38         class Processor;
39         class IO;
40 }
41
42 class PortMatrix;
43 class RouteBundle;
44 class PublicEditor;
45
46 /** A list of bundles grouped by some aspect of their type e.g. busses, tracks, system.
47  *  A group has 0 or more bundles.
48  */
49 class PortGroup : public sigc::trackable
50 {
51 public:
52         PortGroup (std::string const & n);
53         ~PortGroup ();
54
55         void add_bundle (boost::shared_ptr<ARDOUR::Bundle>, bool allow_dups = false);
56         void add_bundle (boost::shared_ptr<ARDOUR::Bundle>, boost::shared_ptr<ARDOUR::IO> io);
57         void add_bundle (boost::shared_ptr<ARDOUR::Bundle>, boost::shared_ptr<ARDOUR::IO>, Gdk::Color);
58         void remove_bundle (boost::shared_ptr<ARDOUR::Bundle>);
59         boost::shared_ptr<ARDOUR::Bundle> only_bundle ();
60         void clear ();
61         uint32_t total_channels () const;
62         boost::shared_ptr<ARDOUR::IO> io_from_bundle (boost::shared_ptr<ARDOUR::Bundle>) const;
63
64         std::string name; ///< name for the group
65
66         bool has_port (std::string const &) const;
67
68         /** The bundle list has changed in some way; a bundle has been added or removed, or the list cleared etc. */
69         sigc::signal<void> Changed;
70
71         /** An individual bundle on our list has changed in some way */
72         boost::signals2::signal<void(ARDOUR::Bundle::Change)> BundleChanged;
73
74         struct BundleRecord {
75             boost::shared_ptr<ARDOUR::Bundle> bundle;
76             /** IO whose ports are in the bundle, or 0.  This is so that we can do things like adding
77                 ports to the IO from matrix editor menus. */
78             boost::shared_ptr<ARDOUR::IO> io; 
79             Gdk::Color colour;
80             bool has_colour;
81             boost::signals2::scoped_connection changed_connection;
82
83             BundleRecord (boost::shared_ptr<ARDOUR::Bundle>, boost::shared_ptr<ARDOUR::IO>, Gdk::Color, bool has_colour);
84         };
85
86         typedef std::list<BundleRecord*> BundleList;
87
88         BundleList const & bundles () const {
89                 return _bundles;
90         }
91
92 private:
93         void bundle_changed (ARDOUR::Bundle::Change);
94         void add_bundle_internal (boost::shared_ptr<ARDOUR::Bundle>, boost::shared_ptr<ARDOUR::IO>, bool, Gdk::Color, bool);
95
96         BundleList _bundles;
97 };
98
99 /// A list of PortGroups
100 class PortGroupList : public sigc::trackable
101 {
102   public:
103         PortGroupList ();
104         ~PortGroupList();
105
106         typedef std::vector<boost::shared_ptr<PortGroup> > List;
107
108         void add_group (boost::shared_ptr<PortGroup>);
109         void add_group_if_not_empty (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_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         /** The group list has changed in some way; a group has been added or removed, or the list cleared etc. */
135         boost::signals2::signal<void()> Changed;
136
137         /** A bundle in one of our groups has changed */
138         boost::signals2::signal<void(ARDOUR::Bundle::Change)> BundleChanged;
139
140   private:
141         bool port_has_prefix (std::string const &, std::string const &) const;
142         std::string common_prefix (std::vector<std::string> const &) const;
143         std::string common_prefix_before (std::vector<std::string> const &, std::string const &) const;
144         void emit_changed ();
145         void emit_bundle_changed (ARDOUR::Bundle::Change);
146         boost::shared_ptr<ARDOUR::Bundle> make_bundle_from_ports (std::vector<std::string> const &, bool) const;
147         void maybe_add_processor_to_list (
148                 boost::weak_ptr<ARDOUR::Processor>, std::list<boost::shared_ptr<ARDOUR::Bundle> > *, bool, std::set<boost::shared_ptr<ARDOUR::IO> > &
149                 );
150
151         ARDOUR::DataType _type;
152         mutable PortGroup::BundleList _bundles;
153         List _groups;
154         PBD::ScopedConnectionList _bundle_changed_connections;
155         bool _signals_suspended;
156         bool _pending_change;
157         ARDOUR::Bundle::Change _pending_bundle_change;
158 };
159
160 #endif /* __gtk_ardour_port_group_h__ */