612f531bdecd96f2b2e704678d21f234961e573f
[ardour.git] / gtk2_ardour / transport_masters_dialog.h
1 /*
2     Copyright (C) 2018 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 __ardour_gtk_transport_masters_dialog_h__
21 #define __ardour_gtk_transport_masters_dialog_h__
22
23 #include <vector>
24 #include <string>
25
26 #include <gtkmm/button.h>
27 #include <gtkmm/eventbox.h>
28 #include <gtkmm/radiobutton.h>
29 #include <gtkmm/label.h>
30 #include <gtkmm/table.h>
31 #include <gtkmm/entry.h>
32 #include <gtkmm/treestore.h>
33
34 #include "ardour_window.h"
35
36 namespace Gtk {
37         class Menu;
38 }
39
40 namespace ARDOUR {
41         class TransportMaster;
42 }
43
44 class FloatingTextEntry;
45
46 class TransportMastersWidget : public Gtk::VBox, public ARDOUR::SessionHandlePtr
47 {
48   public:
49         TransportMastersWidget ();
50         ~TransportMastersWidget ();
51
52         void update (ARDOUR::samplepos_t);
53         void set_transport_master (boost::shared_ptr<ARDOUR::TransportMaster>);
54
55   protected:
56         void on_map ();
57         void on_unmap ();
58
59   private:
60
61         struct AddTransportMasterDialog : public ArdourDialog {
62           public:
63                 AddTransportMasterDialog ();
64                 std::string get_name () const;
65                 ARDOUR::SyncSource get_type () const;
66
67           private:
68                 Gtk::Label name_label;
69                 Gtk::Label type_label;
70                 Gtk::HBox name_hbox;
71                 Gtk::HBox type_hbox;
72                 Gtk::Entry name_entry;
73                 Gtk::ComboBoxText type_combo;
74         };
75
76         struct Row : sigc::trackable, PBD::ScopedConnectionList {
77                 TransportMastersWidget& parent;
78                 Gtk::EventBox label_box;
79                 Gtk::Label label;
80                 Gtk::Label type;
81                 Gtk::Label format;
82                 Gtk::Label current;
83                 Gtk::Label last;
84                 Gtk::Label timestamp;
85                 Gtk::Label delta;
86                 Gtk::CheckButton collect_button;
87                 Gtk::RadioButton use_button;
88                 Gtk::ComboBoxText port_combo;
89                 Gtk::CheckButton sclock_synced_button;
90                 Gtk::CheckButton fr2997_button;
91                 Gtk::Button request_options;
92                 Gtk::Menu* request_option_menu;
93                 Gtk::Button remove_button;
94                 FloatingTextEntry* name_editor;
95                 samplepos_t save_when;
96
97                 void build_request_options();
98
99                 boost::shared_ptr<ARDOUR::TransportMaster> tm;
100
101                 void update (ARDOUR::Session*, ARDOUR::samplepos_t);
102
103                 Row (TransportMastersWidget& parent);
104                 ~Row ();
105
106                 struct PortColumns : public Gtk::TreeModel::ColumnRecord {
107                         PortColumns() {
108                                 add (short_name);
109                                 add (full_name);
110                         }
111                         Gtk::TreeModelColumn<std::string> short_name;
112                         Gtk::TreeModelColumn<std::string> full_name;
113                 };
114
115                 PortColumns port_columns;
116
117                 void populate_port_combo ();
118                 Glib::RefPtr<Gtk::ListStore> build_port_list (std::vector<std::string> const & ports);
119
120                 void use_button_toggled ();
121                 void collect_button_toggled ();
122                 void sync_button_toggled ();
123                 void fr2997_button_toggled ();
124                 void port_choice_changed ();
125                 void connection_handler ();
126                 bool request_option_press (GdkEventButton*);
127                 void prop_change (PBD::PropertyChange);
128                 void remove_clicked ();
129
130                 bool name_press (GdkEventButton*);
131                 void name_edited (std::string, int);
132
133                 PBD::ScopedConnection property_change_connection;
134                 bool ignore_active_change;
135         };
136
137         std::vector<Row*> rows;
138
139         Gtk::Table table;
140         Gtk::Label col_title[14];
141         Gtk::Button add_button;
142
143         sigc::connection update_connection;
144         PBD::ScopedConnection current_connection;
145         PBD::ScopedConnection add_connection;
146         PBD::ScopedConnection remove_connection;
147
148         void rebuild ();
149         void clear ();
150         void current_changed (boost::shared_ptr<ARDOUR::TransportMaster> old_master, boost::shared_ptr<ARDOUR::TransportMaster> new_master);
151         void add_master ();
152
153   public:
154         bool idle_remove (Row*);
155 };
156
157 class TransportMastersWindow : public ArdourWindow
158 {
159   public:
160         TransportMastersWindow ();
161
162         void set_session (ARDOUR::Session*);
163
164   protected:
165         void on_realize ();
166
167   private:
168         TransportMastersWidget w;
169 };
170
171
172 #endif /* __ardour_gtk_transport_masters_dialog_h__ */