Fix multiple creation of identical automation tracks. Fixes #3482.
[ardour.git] / gtk2_ardour / route_ui.h
1 /*
2     Copyright (C) 2002 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_route_ui__
21 #define __ardour_route_ui__
22
23 #include <list>
24
25 #include "pbd/xml++.h"
26 #include "pbd/signals.h"
27
28 #include "ardour/ardour.h"
29 #include "ardour/mute_master.h"
30 #include "ardour/session_event.h"
31 #include "ardour/session.h"
32 #include "ardour/route.h"
33 #include "ardour/route_group.h"
34 #include "ardour/track.h"
35
36 #include "axis_view.h"
37
38 namespace ARDOUR {
39         class AudioTrack;
40         class MidiTrack;
41 }
42
43 namespace Gtk {
44         class Menu;
45         class CheckMenuItem;
46         class Widget;
47 }
48
49 class BindableToggleButton;
50 class LED;
51
52 class RouteUI : public virtual AxisView
53 {
54   public:
55         RouteUI(ARDOUR::Session*);
56         RouteUI(boost::shared_ptr<ARDOUR::Route>, ARDOUR::Session*);
57
58         virtual ~RouteUI();
59
60         virtual void set_route (boost::shared_ptr<ARDOUR::Route>);
61         virtual void set_button_names () = 0;
62
63         bool is_track() const;
64         bool is_audio_track() const;
65         bool is_midi_track() const;
66         bool has_audio_outputs () const;
67
68         boost::shared_ptr<ARDOUR::Route> route() const { return _route; }
69
70         boost::shared_ptr<ARDOUR::Track>      track() const;
71         boost::shared_ptr<ARDOUR::AudioTrack> audio_track() const;
72         boost::shared_ptr<ARDOUR::MidiTrack>  midi_track() const;
73
74         std::string name() const;
75
76         // protected: XXX sigh this should be here
77
78         boost::shared_ptr<ARDOUR::Route> _route;
79
80         void set_color (const Gdk::Color & c);
81         bool choose_color ();
82
83         bool ignore_toggle;
84         bool wait_for_release;
85         bool multiple_mute_change;
86         bool multiple_solo_change;
87
88         Gtk::HBox _invert_button_box;
89         BindableToggleButton* mute_button;
90         BindableToggleButton* solo_button;
91         BindableToggleButton* rec_enable_button; /* audio tracks */
92         BindableToggleButton* show_sends_button; /* busses */
93
94         LED* solo_safe_led;
95         LED* solo_isolated_led;
96
97         Gtk::Label solo_button_label;
98         Gtk::Label mute_button_label;
99         Gtk::Label rec_enable_button_label;
100
101         void send_blink (bool);
102         sigc::connection send_blink_connection;
103
104         virtual std::string solo_button_name () const { return "SoloButton"; }
105         virtual std::string safe_solo_button_name () const { return "SafeSoloButton"; }
106
107         Gtk::Menu* mute_menu;
108         Gtk::Menu* solo_menu;
109         Gtk::Menu* sends_menu;
110
111         XMLNode *xml_node;
112         void ensure_xml_node ();
113         int _xml_node_version;
114
115         virtual XMLNode* get_automation_child_xml_node (Evoral::Parameter);
116
117         bool mute_press(GdkEventButton*);
118         bool mute_release(GdkEventButton*);
119         bool solo_press(GdkEventButton*);
120         bool solo_release(GdkEventButton*);
121         bool rec_enable_press(GdkEventButton*);
122         bool rec_enable_release(GdkEventButton*);
123         bool show_sends_press(GdkEventButton*);
124         bool show_sends_release(GdkEventButton*);
125
126         void step_gain_up ();
127         void step_gain_down ();
128         void page_gain_up ();
129         void page_gain_down ();
130
131         void build_sends_menu ();
132         void set_sends_gain_from_track ();
133         void set_sends_gain_to_zero ();
134         void set_sends_gain_to_unity ();
135         void create_sends (ARDOUR::Placement);
136         void create_selected_sends (ARDOUR::Placement);
137
138         void solo_changed(bool, void*);
139         void solo_changed_so_update_mute ();
140         void mute_changed(void*);
141         void listen_changed(void*);
142         virtual void processors_changed (ARDOUR::RouteProcessorChange) {}
143         void route_rec_enable_changed();
144         void session_rec_enable_changed();
145
146         void build_solo_menu ();
147
148         void solo_isolated_toggle (void*, Gtk::CheckMenuItem*);
149         void toggle_solo_isolated (Gtk::CheckMenuItem*);
150
151         bool solo_isolate_button_release (GdkEventButton*);
152         bool solo_safe_button_release (GdkEventButton*);
153
154         void solo_safe_toggle (void*, Gtk::CheckMenuItem*);
155         void toggle_solo_safe (Gtk::CheckMenuItem*);
156
157         Gtk::CheckMenuItem* pre_fader_mute_check;
158         Gtk::CheckMenuItem* post_fader_mute_check;
159         Gtk::CheckMenuItem* listen_mute_check;
160         Gtk::CheckMenuItem* main_mute_check;
161         Gtk::CheckMenuItem* solo_safe_check;
162         Gtk::CheckMenuItem* solo_isolated_check;
163
164         void toggle_mute_menu(ARDOUR::MuteMaster::MutePoint, Gtk::CheckMenuItem*);
165         void muting_change ();
166         void build_mute_menu(void);
167         void init_mute_menu(ARDOUR::MuteMaster::MutePoint, Gtk::CheckMenuItem*);
168
169         int  set_color_from_route ();
170
171         void remove_this_route ();
172         static gint idle_remove_this_route (RouteUI *);
173
174         void route_rename();
175
176         virtual void property_changed (const PBD::PropertyChange&);
177         void route_removed ();
178
179         Gtk::CheckMenuItem *route_active_menu_item;
180         void toggle_route_active ();
181         virtual void route_active_changed ();
182
183         Gtk::Menu* record_menu;
184         void build_record_menu ();
185
186         Gtk::CheckMenuItem *step_edit_item;
187         void toggle_step_edit ();
188         virtual void step_edit_changed (bool);
189         
190         virtual void polarity_changed ();
191
192         Gtk::CheckMenuItem *denormal_menu_item;
193         void toggle_denormal_protection();
194         virtual void denormal_protection_changed ();
195
196         void disconnect_input ();
197         void disconnect_output ();
198
199         virtual void update_rec_display ();
200         void update_mute_display ();
201
202         void update_solo_display ();
203
204         virtual void map_frozen ();
205
206         void adjust_latency ();
207         void save_as_template ();
208         void open_remote_control_id_dialog ();
209
210         static int solo_visual_state (boost::shared_ptr<ARDOUR::Route>);
211         static int solo_visual_state_with_isolate (boost::shared_ptr<ARDOUR::Route>);
212         static int solo_isolate_visual_state (boost::shared_ptr<ARDOUR::Route>);
213         static int solo_safe_visual_state (boost::shared_ptr<ARDOUR::Route>);
214         static int mute_visual_state (ARDOUR::Session*, boost::shared_ptr<ARDOUR::Route>);
215
216    protected:
217         PBD::ScopedConnectionList route_connections;
218         bool self_destruct;
219
220         void init ();
221         void reset ();
222
223         void self_delete ();
224         virtual void start_step_editing () {}
225         virtual void stop_step_editing() {}
226
227   private:
228         void check_rec_enable_sensitivity ();
229         void parameter_changed (std::string const &);
230         void relabel_solo_button ();
231
232         struct SoloMuteRelease {
233             SoloMuteRelease (bool was_active) 
234             : active (was_active)
235             , exclusive (false) {}
236             
237             boost::shared_ptr<ARDOUR::RouteList> routes;
238             boost::shared_ptr<ARDOUR::RouteList> routes_on;
239             boost::shared_ptr<ARDOUR::RouteList> routes_off;
240             boost::shared_ptr<ARDOUR::Route> route;
241             bool active;
242             bool exclusive;
243         };
244
245         SoloMuteRelease* _solo_release;
246         SoloMuteRelease* _mute_release;
247
248         void setup_invert_buttons ();
249         void set_invert_button_state ();
250         void invert_toggled (uint32_t, BindableToggleButton *);
251         void invert_menu_toggled (uint32_t);
252         bool invert_press (GdkEventButton *);
253         
254         int _i_am_the_modifier;
255         std::list<BindableToggleButton*> _invert_buttons;
256         Gtk::Menu* _invert_menu;
257
258         static uint32_t _max_invert_buttons;
259 };
260
261 #endif /* __ardour_route_ui__ */