Unconditionally save instant.xml on session-close
[ardour.git] / gtk2_ardour / route_ui.h
1 /*
2  * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2005 Karsten Wiese <fzuuzf@googlemail.com>
4  * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
5  * Copyright (C) 2006-2011 David Robillard <d@drobilla.net>
6  * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
7  * Copyright (C) 2013-2017 Robin Gareus <robin@gareus.org>
8  * Copyright (C) 2014-2015 Ben Loftis <ben@harrisonconsoles.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #ifndef __ardour_route_ui__
26 #define __ardour_route_ui__
27
28 #include <list>
29
30 #include "pbd/xml++.h"
31 #include "pbd/signals.h"
32
33 #include <gtkmm/textview.h>
34 #include <gtkmm/colorselection.h>
35
36 #include "gtkmm2ext/widget_state.h"
37
38 #include "ardour/ardour.h"
39 #include "ardour/mute_master.h"
40 #include "ardour/session.h"
41 #include "ardour/session_event.h"
42 #include "ardour/session_handle.h"
43 #include "ardour/route.h"
44 #include "ardour/route_group.h"
45 #include "ardour/track.h"
46
47 #include "axis_view.h"
48 #include "selectable.h"
49 #include "stripable_colorpicker.h"
50 #include "window_manager.h"
51
52 namespace ARDOUR {
53         class AudioTrack;
54         class MidiTrack;
55 }
56
57 namespace Gtk {
58         class Menu;
59         class CheckMenuItem;
60         class Widget;
61 }
62
63 namespace ArdourWidgets {
64         class ArdourButton;
65         class Prompter;
66 }
67
68 class ArdourWindow;
69 class IOSelectorWindow;
70 class ControlSlaveUI;
71 class PatchChangeGridDialog;
72 class SaveTemplateDialog;
73
74 class RoutePinWindowProxy : public WM::ProxyBase
75 {
76 public:
77         RoutePinWindowProxy (std::string const &, boost::shared_ptr<ARDOUR::Route>);
78         ~RoutePinWindowProxy();
79
80         Gtk::Window* get (bool create = false);
81         ARDOUR::SessionHandlePtr* session_handle();
82
83 private:
84         boost::weak_ptr<ARDOUR::Route> _route;
85
86         void route_going_away ();
87         PBD::ScopedConnection going_away_connection;
88 };
89
90 class RouteUI : public virtual Selectable, public virtual ARDOUR::SessionHandlePtr, public virtual PBD::ScopedConnectionList, public virtual sigc::trackable
91 {
92 public:
93         RouteUI (ARDOUR::Session*);
94
95         virtual ~RouteUI();
96
97         boost::shared_ptr<ARDOUR::Stripable> stripable() const;
98
99         virtual void set_route (boost::shared_ptr<ARDOUR::Route>);
100         virtual void set_button_names () = 0;
101
102         bool is_track() const;
103         bool is_audio_track() const;
104         bool is_midi_track() const;
105         bool has_audio_outputs () const;
106
107         boost::shared_ptr<ARDOUR::Route> route() const { return _route; }
108         ARDOUR::RouteGroup* route_group() const;
109
110         boost::shared_ptr<ARDOUR::Track>      track() const;
111         boost::shared_ptr<ARDOUR::AudioTrack> audio_track() const;
112         boost::shared_ptr<ARDOUR::MidiTrack>  midi_track() const;
113
114         // protected: XXX sigh this should be here
115
116         boost::shared_ptr<ARDOUR::Route> _route;
117
118         virtual void set_color (uint32_t c);
119         Gdk::Color route_color () const;
120         void choose_color ();
121
122         void select_midi_patch ();
123
124         bool ignore_toggle;
125         bool wait_for_release;
126         bool multiple_mute_change;
127         bool multiple_solo_change;
128
129         Gtk::HBox _invert_button_box;
130         ArdourWidgets::ArdourButton* mute_button;
131         ArdourWidgets::ArdourButton* solo_button;
132         ArdourWidgets::ArdourButton* rec_enable_button; /* audio tracks */
133         ArdourWidgets::ArdourButton* show_sends_button; /* busses */
134         ArdourWidgets::ArdourButton* monitor_input_button;
135         ArdourWidgets::ArdourButton* monitor_disk_button;
136
137         Glib::RefPtr<Gdk::Pixbuf> solo_safe_pixbuf;
138
139         ArdourWidgets::ArdourButton* solo_safe_led;
140         ArdourWidgets::ArdourButton* solo_isolated_led;
141
142
143         Gtk::Label monitor_input_button_label;
144         Gtk::Label monitor_disk_button_label;
145
146         void send_blink (bool);
147         sigc::connection send_blink_connection;
148
149         sigc::connection rec_blink_connection;
150
151         Gtk::Menu* mute_menu;
152         Gtk::Menu* solo_menu;
153         Gtk::Menu* sends_menu;
154
155         boost::shared_ptr<ARDOUR::Delivery> _current_delivery;
156
157         bool mute_press(GdkEventButton*);
158         bool mute_release(GdkEventButton*);
159         bool solo_press(GdkEventButton*);
160         bool solo_release(GdkEventButton*);
161         bool rec_enable_press(GdkEventButton*);
162         bool rec_enable_release(GdkEventButton*);
163         bool show_sends_press(GdkEventButton*);
164         bool show_sends_release(GdkEventButton*);
165
166         bool monitor_release(GdkEventButton*, ARDOUR::MonitorChoice);
167         bool monitor_input_press(GdkEventButton*);
168         bool monitor_input_release(GdkEventButton*);
169         bool monitor_disk_press(GdkEventButton*);
170         bool monitor_disk_release(GdkEventButton*);
171         void update_monitoring_display ();
172
173         void edit_input_configuration ();
174         void edit_output_configuration ();
175
176         void build_sends_menu ();
177         void set_sends_gain_from_track ();
178         void set_sends_gain_to_zero ();
179         void set_sends_gain_to_unity ();
180         void create_sends (ARDOUR::Placement, bool);
181         void create_selected_sends (ARDOUR::Placement, bool);
182
183         void solo_changed(bool, void*);
184         void solo_changed_so_update_mute ();
185         void listen_changed(void*);
186         virtual void processors_changed (ARDOUR::RouteProcessorChange) {}
187         void route_rec_enable_changed();
188         void session_rec_enable_changed();
189
190         void build_solo_menu ();
191
192         void solo_isolated_toggle (void*, Gtk::CheckMenuItem*);
193         void toggle_solo_isolated (Gtk::CheckMenuItem*);
194
195         bool solo_isolate_button_release (GdkEventButton*);
196         bool solo_safe_button_release (GdkEventButton*);
197
198         void solo_safe_toggle (void*, Gtk::CheckMenuItem*);
199         void toggle_solo_safe (Gtk::CheckMenuItem*);
200
201         Gtk::CheckMenuItem* pre_fader_mute_check;
202         Gtk::CheckMenuItem* post_fader_mute_check;
203         Gtk::CheckMenuItem* listen_mute_check;
204         Gtk::CheckMenuItem* main_mute_check;
205         Gtk::CheckMenuItem* solo_safe_check;
206         Gtk::CheckMenuItem* solo_isolated_check;
207
208         void toggle_mute_menu(ARDOUR::MuteMaster::MutePoint, Gtk::CheckMenuItem*);
209         void muting_change ();
210         void build_mute_menu(void);
211         void init_mute_menu(ARDOUR::MuteMaster::MutePoint, Gtk::CheckMenuItem*);
212
213         int  set_color_from_route ();
214
215         void route_rename();
216
217         void manage_pins ();
218         void maybe_add_route_print_mgr ();
219         void fan_out (bool to_busses = true, bool group = true);
220
221         virtual void route_property_changed (const PBD::PropertyChange&) = 0;
222         void route_removed ();
223
224         virtual void route_active_changed () {}
225         void set_route_active (bool, bool);
226         void duplicate_selected_routes ();
227
228         Gtk::Menu* record_menu;
229         void build_record_menu ();
230
231         Gtk::CheckMenuItem *step_edit_item;
232         void toggle_step_edit ();
233         virtual void step_edit_changed (bool);
234
235         Gtk::CheckMenuItem *rec_safe_item;
236         void toggle_rec_safe ();
237
238         virtual void polarity_changed ();
239
240         Gtk::CheckMenuItem *denormal_menu_item;
241         void toggle_denormal_protection();
242         virtual void denormal_protection_changed ();
243
244         void disconnect_input ();
245         void disconnect_output ();
246
247         virtual void blink_rec_display (bool onoff);
248         void update_mute_display ();
249
250         void update_solo_display ();
251
252         virtual void map_frozen ();
253
254         void save_as_template_dialog_response (int response, SaveTemplateDialog* d);
255         void save_as_template ();
256
257         static Gtkmm2ext::ActiveState solo_active_state (boost::shared_ptr<ARDOUR::Stripable>);
258         static Gtkmm2ext::ActiveState solo_isolate_active_state (boost::shared_ptr<ARDOUR::Stripable>);
259         static Gtkmm2ext::ActiveState solo_safe_active_state (boost::shared_ptr<ARDOUR::Stripable>);
260         static Gtkmm2ext::ActiveState mute_active_state (ARDOUR::Session*, boost::shared_ptr<ARDOUR::Stripable>);
261
262         /** Emitted when a bus has been set or unset from `display sends to this bus' mode
263          *  by a click on the `Sends' button.  The parameter is the route that the sends are
264          *  to, or 0 if no route is now in this mode.
265          */
266         static PBD::Signal1<void, boost::shared_ptr<ARDOUR::Route> > BusSendDisplayChanged;
267
268         void comment_editor_done_editing ();
269         void setup_comment_editor ();
270         void open_comment_editor ();
271         void toggle_comment_editor ();
272
273         gint comment_key_release_handler (GdkEventKey*);
274         void comment_changed ();
275         void comment_edited ();
276         bool ignore_comment_edit;
277
278         void set_disk_io_point (ARDOUR::DiskIOPoint);
279
280 protected:
281
282         ArdourWindow*  comment_window;
283         Gtk::TextView* comment_area;
284         IOSelectorWindow *input_selector;
285         IOSelectorWindow *output_selector;
286
287         PBD::ScopedConnectionList route_connections;
288         bool self_destruct;
289
290         void init ();
291         void reset ();
292
293         void self_delete ();
294         virtual void start_step_editing () {}
295         virtual void stop_step_editing() {}
296
297         void set_invert_sensitive (bool);
298         bool verify_new_route_name (const std::string& name);
299
300         void route_gui_changed (PBD::PropertyChange const&);
301         virtual void route_color_changed () {}
302
303         void check_rec_enable_sensitivity ();
304
305         virtual void bus_send_display_changed (boost::shared_ptr<ARDOUR::Route>);
306
307         static std::string program_port_prefix;
308
309         bool mark_hidden (bool yn);
310
311         PatchChangeGridDialog* patch_change_dialog () const;
312
313 private:
314         void parameter_changed (std::string const&);
315         void relabel_solo_button ();
316         void track_mode_changed ();
317         void delete_patch_change_dialog ();
318
319         std::string route_state_id () const;
320
321 protected:
322         struct SoloMuteRelease {
323                 SoloMuteRelease (bool was_active)
324                         : active (was_active)
325                         , exclusive (false)
326                 {}
327
328                 boost::shared_ptr<ARDOUR::RouteList> routes;
329                 boost::shared_ptr<ARDOUR::RouteList> routes_on;
330                 boost::shared_ptr<ARDOUR::RouteList> routes_off;
331                 boost::shared_ptr<ARDOUR::Route> route;
332                 bool active;
333                 bool exclusive;
334         };
335
336         SoloMuteRelease* _solo_release;
337         SoloMuteRelease* _mute_release;
338
339         ControlSlaveUI* csu;
340
341 private:
342         void setup_invert_buttons ();
343         void set_invert_button_state ();
344         void invert_menu_toggled (uint32_t);
345         bool invert_press (GdkEventButton *);
346         bool invert_release (GdkEventButton *, uint32_t i);
347
348         int _i_am_the_modifier;
349         std::vector<ArdourWidgets::ArdourButton*> _invert_buttons;
350         Gtk::Menu* _invert_menu;
351
352         StripableColorDialog _color_picker;
353
354         static void set_showing_sends_to (boost::shared_ptr<ARDOUR::Route>);
355         static boost::weak_ptr<ARDOUR::Route> _showing_sends_to;
356
357         static uint32_t _max_invert_buttons;
358 };
359
360 #endif /* __ardour_route_ui__ */