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