Fix crash when X11 is not available for VST UIs
[ardour.git] / gtk2_ardour / location_ui.h
1 /*
2  * Copyright (C) 2005-2018 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
4  * Copyright (C) 2008-2011 David Robillard <d@drobilla.net>
5  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
6  * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #ifndef __ardour_location_ui_h__
24 #define __ardour_location_ui_h__
25
26 #include <gtkmm/box.h>
27 #include <gtkmm/checkbutton.h>
28 #include <gtkmm/button.h>
29 #include <gtkmm/table.h>
30 #include <gtkmm/entry.h>
31 #include <gtkmm/label.h>
32 #include <gtkmm/scrolledwindow.h>
33
34 #include "pbd/signals.h"
35
36 #include "ardour/location.h"
37 #include "ardour/session_handle.h"
38
39 #include "widgets/ardour_button.h"
40 #include "widgets/pane.h"
41
42 #include "ardour_window.h"
43 #include "audio_clock.h"
44
45 namespace ARDOUR {
46         class Location;
47 }
48
49 class ClockGroup;
50
51 class LocationEditRow  : public Gtk::HBox, public ARDOUR::SessionHandlePtr
52 {
53 public:
54         LocationEditRow (ARDOUR::Session *sess=0, ARDOUR::Location *loc=0, int32_t num=-1);
55         virtual ~LocationEditRow();
56
57         void set_location (ARDOUR::Location*);
58         ARDOUR::Location * get_location() { return location; }
59
60         void set_session (ARDOUR::Session *);
61
62         void set_number (int);
63         void focus_name();
64         void set_clock_group (ClockGroup&);
65         void unset_clock_group () { _clock_group = 0; }
66
67         sigc::signal<void,ARDOUR::Location*> remove_requested;
68         sigc::signal<void> redraw_ranges;
69
70 protected:
71
72         enum LocationPart {
73                 LocStart,
74                 LocEnd,
75                 LocLength
76         };
77
78         ARDOUR::Location *location;
79
80         Gtk::Table    item_table;
81
82         Gtk::Entry    name_entry;
83         Gtk::Label    name_label;
84         Gtk::Label    number_label;
85         Gtk::Label    date_label;
86
87         Gtk::HBox     start_hbox;
88         AudioClock    start_clock;
89         ArdourWidgets::ArdourButton start_to_playhead_button;
90         ArdourWidgets::ArdourButton locate_to_start_button;
91
92         Gtk::HBox     end_hbox;
93         AudioClock    end_clock;
94         ArdourWidgets::ArdourButton end_to_playhead_button;
95         ArdourWidgets::ArdourButton locate_to_end_button;
96
97         AudioClock    length_clock;
98         Gtk::CheckButton cd_check_button;
99         Gtk::CheckButton hide_check_button;
100         Gtk::CheckButton lock_check_button;
101         Gtk::CheckButton glue_check_button;
102
103         ArdourWidgets::ArdourButton remove_button;
104
105         Gtk::HBox     cd_track_details_hbox;
106         Gtk::Entry    isrc_entry;
107         Gtk::Label    isrc_label;
108
109
110         Gtk::Label    performer_label;
111         Gtk::Entry    performer_entry;
112         Gtk::Label    composer_label;
113         Gtk::Entry    composer_entry;
114         Gtk::CheckButton   scms_check_button;
115         Gtk::Label         scms_label;
116         Gtk::CheckButton   preemph_check_button;
117         Gtk::Label         preemph_label;
118         ClockGroup* _clock_group;
119
120         guint32 i_am_the_modifier;
121         int   number;
122
123         void name_entry_changed ();
124         void isrc_entry_changed ();
125         void performer_entry_changed ();
126         void composer_entry_changed ();
127
128         void to_playhead_button_pressed (LocationPart part);
129         void locate_button_pressed (LocationPart part);
130
131         void clock_changed (LocationPart part);
132         bool locate_to_clock (GdkEventButton*, AudioClock*);
133
134         void cd_toggled ();
135         void hide_toggled ();
136         void lock_toggled ();
137         void glue_toggled ();
138         void remove_button_pressed ();
139
140         void scms_toggled ();
141         void preemph_toggled ();
142
143         void end_changed ();
144         void start_changed ();
145         void name_changed ();
146         void location_changed ();
147         void flags_changed ();
148         void lock_changed ();
149         void position_lock_style_changed ();
150
151         void set_clock_editable_status ();
152         void show_cd_track_details ();
153
154         PBD::ScopedConnectionList connections;
155 };
156
157 class LocationUI : public Gtk::HBox, public ARDOUR::SessionHandlePtr
158 {
159 public:
160         LocationUI (std::string state_node_name = "LocationUI");
161         ~LocationUI ();
162
163         void set_session (ARDOUR::Session *);
164
165         void add_new_location();
166         void add_new_range();
167
168         void refresh_location_list ();
169
170         XMLNode & get_state () const;
171         int set_state (const XMLNode&);
172
173 private:
174         /** set to the location that has just been created with the LocationUI `add' button
175             (if Config->get_name_new_markers() is true); if it is non-0, the name entry of
176             the location is given the focus by location_added().
177         */
178         ARDOUR::Location *newest_location;
179
180         void session_going_away ();
181
182         LocationEditRow      loop_edit_row;
183         LocationEditRow      punch_edit_row;
184         Gtk::VBox loop_punch_box;
185
186         ArdourWidgets::VPane loc_range_panes;
187
188         Gtk::VBox  loc_frame_box;
189         Gtk::Button add_location_button;
190         Gtk::ScrolledWindow  location_rows_scroller;
191         Gtk::VBox            location_rows;
192
193         Gtk::VBox  range_frame_box;
194         Gtk::Button add_range_button;
195         Gtk::ScrolledWindow  range_rows_scroller;
196         Gtk::VBox            range_rows;
197
198         /* When any location changes it start
199            or end points, it sends a signal that is caught
200            by one of these functions
201         */
202
203         void location_remove_requested (ARDOUR::Location *);
204
205         void location_redraw_ranges ();
206
207         gint do_location_remove (ARDOUR::Location *);
208
209         guint32 i_am_the_modifier;
210
211         void location_removed (ARDOUR::Location *);
212         void location_added (ARDOUR::Location *);
213         void map_locations (const ARDOUR::Locations::LocationList&);
214
215         ClockGroup* _clock_group;
216         AudioClock::Mode clock_mode_from_session_instant_xml ();
217
218         AudioClock::Mode _mode;
219         bool _mode_set;
220
221         std::string _state_node_name;
222 };
223
224 class LocationUIWindow : public ArdourWindow
225 {
226 public:
227         LocationUIWindow ();
228         ~LocationUIWindow ();
229
230         void on_map ();
231         void set_session (ARDOUR::Session *);
232
233         LocationUI& ui() { return _ui; }
234
235 protected:
236         LocationUI _ui;
237         bool on_delete_event (GdkEventAny*);
238         void session_going_away();
239 };
240
241 #endif // __ardour_location_ui_h__