partial patch/partial by-hand merge of 2.X commits 3169&3170 to 3.X codebase
[ardour.git] / gtk2_ardour / port_group.h
1 #ifndef  __gtk_ardour_port_group_h__ 
2 #define  __gtk_ardour_port_group_h__ 
3
4 #include <vector>
5 #include <string>
6
7 #include <gtkmm/widget.h>
8 #include <gtkmm/checkbutton.h>
9
10 #include <ardour/data_type.h>
11
12 namespace ARDOUR {
13         class Session;
14         class IO;
15         class PortInsert;
16 }
17
18 class PortMatrix;
19
20 /// A list of port names, grouped by some aspect of their type e.g. busses, tracks, system
21 class PortGroup
22 {
23   public:
24         /** PortGroup constructor.
25          * @param n Name.
26          * @param p Port name prefix.
27          * @param v true if group should be visible in the UI, otherwise false.
28          */
29         PortGroup (std::string const & n, std::string const & p, bool v) : name (n), prefix (p), visible (v) {}
30
31         void add (std::string const & p);
32
33         std::string name; ///< name for the group
34         std::string prefix; ///< prefix (before colon) e.g. "ardour:"
35         std::vector<std::string> ports; ///< port names
36         bool visible; ///< true if the group is visible in the UI
37 };
38
39 /// The UI for a PortGroup
40 class PortGroupUI
41 {
42   public:
43         PortGroupUI (PortMatrix&, PortGroup&);
44
45         Gtk::Widget& get_visibility_checkbutton ();
46         PortGroup& port_group () { return _port_group; }
47         void setup_visibility ();
48
49   private:
50         void port_checkbutton_toggled (Gtk::CheckButton*, int, int);
51         bool port_checkbutton_release (GdkEventButton* ev, Gtk::CheckButton* b, int r, int c);
52         void visibility_checkbutton_toggled ();
53
54         PortMatrix& _port_matrix; ///< the PortMatrix that we are working for
55         PortGroup& _port_group; ///< the PortGroup that we are representing
56         bool _ignore_check_button_toggle;
57         Gtk::CheckButton _visibility_checkbutton;
58 };
59
60 /// A list of PortGroups
61 class PortGroupList : public std::list<PortGroup*>
62 {
63   public:
64         enum Mask {
65                 BUSS = 0x1,
66                 TRACK = 0x2,
67                 SYSTEM = 0x4,
68                 OTHER = 0x8
69         };
70
71         PortGroupList (ARDOUR::Session &, ARDOUR::DataType, bool, Mask);
72
73         void refresh ();
74         int n_visible_ports () const;
75         std::string get_port_by_index (int, bool with_prefix = true) const;
76         void set_type (ARDOUR::DataType);
77         void set_offer_inputs (bool);
78         
79   private:
80         ARDOUR::Session& _session;
81         ARDOUR::DataType _type;
82         bool _offer_inputs;
83
84         PortGroup buss;
85         PortGroup track;
86         PortGroup system;
87         PortGroup other;
88 };
89
90 #endif /* __gtk_ardour_port_group_h__ */