Gather all ardour: ports so that a few more things are found to put in the port matrix.
[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
30 namespace ARDOUR {
31         class Session;
32         class Bundle;
33 }
34
35 class PortMatrix;
36
37 /** A list of bundles and ports, grouped by some aspect of their
38  *  type e.g. busses, tracks, system.  Each group has 0 or more bundles
39  *  and 0 or more ports, where the ports are not in the bundles.
40  */
41 class PortGroup : public sigc::trackable
42 {
43 public:
44         /** PortGroup constructor.
45          * @param n Name.
46          * @param v true if group should be visible in the UI, otherwise false.
47          */
48         PortGroup (std::string const & n, bool v)
49                 : name (n), _visible (v) {}
50
51         void add_bundle (boost::shared_ptr<ARDOUR::Bundle>);
52         void add_port (std::string const &);
53         void clear ();
54
55         std::string name; ///< name for the group
56         std::vector<boost::shared_ptr<ARDOUR::Bundle> > bundles;
57         std::vector<std::string> ports;
58         bool visible () const {
59                 return _visible;
60         }
61
62         void set_visible (bool v) {
63                 _visible = v;
64                 VisibilityChanged ();
65         }
66
67         bool has_port (std::string const &) const;
68
69         sigc::signal<void> VisibilityChanged;
70
71 private:        
72         bool _visible; ///< true if the group is visible in the UI
73 };
74
75 /// The UI for a PortGroup
76 class PortGroupUI
77 {
78   public:
79         PortGroupUI (PortMatrix*, PortGroup*);
80
81         Gtk::Widget& visibility_checkbutton () {
82                 return _visibility_checkbutton;
83         }
84
85   private:
86         void visibility_checkbutton_toggled ();
87         void setup_visibility_checkbutton ();
88
89         PortMatrix* _port_matrix; ///< the PortMatrix that we are working for
90         PortGroup* _port_group; ///< the PortGroup that we are representing
91         Gtk::CheckButton _visibility_checkbutton;
92 };
93
94 /// A list of PortGroups
95 class PortGroupList : public std::list<PortGroup*>, public sigc::trackable
96 {
97   public:
98         enum Mask {
99                 BUSS = 0x1,
100                 TRACK = 0x2,
101                 SYSTEM = 0x4,
102                 OTHER = 0x8
103         };
104
105         PortGroupList (ARDOUR::Session &, ARDOUR::DataType, bool, Mask);
106
107         void refresh ();
108         void set_type (ARDOUR::DataType);
109         void set_offer_inputs (bool);
110         std::vector<boost::shared_ptr<ARDOUR::Bundle> > bundles ();
111         void take_visibility_from (PortGroupList const &);
112
113         sigc::signal<void> VisibilityChanged;
114         
115   private:
116         void maybe_add_session_bundle (boost::shared_ptr<ARDOUR::Bundle>);
117         bool port_has_prefix (std::string const &, std::string const &) const;
118         std::string common_prefix (std::vector<std::string> const &) const;
119         void visibility_changed ();
120         
121         ARDOUR::Session& _session;
122         ARDOUR::DataType _type;
123         bool _offer_inputs;
124
125         PortGroup _buss;
126         PortGroup _track;
127         PortGroup _system;
128         PortGroup _other;
129 };
130
131 #endif /* __gtk_ardour_port_group_h__ */