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