make all of dialog visible for add_route_dialog
[ardour.git] / gtk2_ardour / editor_mixer.cc
1 /*
2     Copyright (C) 2003-2004 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     $Id$
19 */
20
21 #include <gtkmm2ext/utils.h>
22 #include <ardour/audioengine.h>
23
24 #include "editor.h"
25 #include "mixer_strip.h"
26 #include "ardour_ui.h"
27 #include "selection.h"
28 #include "audio_time_axis.h"
29
30 #include "i18n.h"
31
32 void
33 Editor::editor_mixer_button_toggled ()
34 {
35         show_editor_mixer (editor_mixer_button.get_active());
36 }
37
38 void
39 Editor::cms_deleted ()
40 {
41         current_mixer_strip = 0;
42 }
43
44 void
45 Editor::show_editor_mixer (bool yn)
46 {
47         if (yn) {
48
49                 if (current_mixer_strip == 0) {
50
51                         if (selection->tracks.empty()) {
52                                 
53                                 if (track_views.empty()) {
54                                         return;
55                                 }
56                                 
57                                 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
58                                         AudioTimeAxisView* atv;
59
60                                         if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) != 0) {
61                                                 
62                                                 current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
63                                                                                       *session,
64                                                                                       atv->route(), false);
65
66                                                 current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::cms_deleted));                                          
67                                                 break;
68                                         }
69                                 }
70
71                         } else {
72                                 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
73                                         AudioTimeAxisView* atv;
74
75                                         if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) != 0) {
76
77                                                 current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
78                                                                                       *session,
79                                                                                       atv->route(), false);
80                                                 current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::cms_deleted));                                          
81                                                 break;
82                                         }
83                                 }
84
85                         }
86
87                         if (current_mixer_strip == 0) {
88                                 return;
89                         }               
90                 }
91                 
92                 if (current_mixer_strip->get_parent() == 0) {
93
94                         current_mixer_strip->set_embedded (true);
95                         current_mixer_strip->Hiding.connect (mem_fun(*this, &Editor::current_mixer_strip_hidden));
96                         current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::current_mixer_strip_removed));
97                         current_mixer_strip->set_width (editor_mixer_strip_width);
98                         current_mixer_strip->show_all ();
99                         
100                         global_hpacker.pack_start (*current_mixer_strip, false, false);
101                         global_hpacker.reorder_child (*current_mixer_strip, 0);
102                 }
103
104         } else {
105
106                 if (current_mixer_strip) {
107                         editor_mixer_strip_width = current_mixer_strip->get_width ();
108                         if (current_mixer_strip->get_parent() != 0) {
109                                 global_hpacker.remove (*current_mixer_strip);
110                         }
111                 }
112         }
113 }
114
115 void
116 Editor::set_selected_mixer_strip (TimeAxisView& view)
117 {
118         AudioTimeAxisView* at;
119         bool show = false;
120
121         if (!session || (at = dynamic_cast<AudioTimeAxisView*>(&view)) == 0) {
122                 return;
123         }
124         
125         if (current_mixer_strip) {
126
127                 /* might be nothing to do */
128
129                 if (&current_mixer_strip->route() == &at->route()) {
130                         return;
131                 }
132
133                 if (current_mixer_strip->get_parent()) {
134                         show = true;
135                 }
136
137                 delete current_mixer_strip;
138                 current_mixer_strip = 0;
139         }
140
141         current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
142                                               *session,
143                                               at->route());
144         current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::cms_deleted));
145         
146         if (show) {
147                 show_editor_mixer (true);
148         }
149 }
150
151 void
152 Editor::update_current_screen ()
153 {
154         if (session && engine.running()) {
155
156                 jack_nframes_t frame;
157
158                 frame = session->audible_frame();
159
160                 /* only update if the playhead is on screen or we are following it */
161
162                 if (_follow_playhead) {
163
164                   playhead_cursor->canvas_item.show();
165                         if (frame != last_update_frame) {
166
167                                 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
168                                         
169                                         if (session->transport_speed() < 0) {
170                                                 if (frame > (current_page_frames()/2)) {
171                                                         center_screen (frame-(current_page_frames()/2));
172                                                 } else {
173                                                         center_screen (current_page_frames()/2);
174                                                 }
175                                         } else {
176                                                 center_screen (frame+(current_page_frames()/2));
177                                         }
178                                 }
179
180                                 playhead_cursor->set_position (frame);
181                         }
182
183                 } else {
184                         
185                         if (frame != last_update_frame) {
186                                 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
187                                         playhead_cursor->canvas_item.hide();
188                                 } else {
189                                         playhead_cursor->set_position (frame);
190                                 }
191                         }
192                 }
193
194                 last_update_frame = frame;
195
196                 if (current_mixer_strip) {
197                         current_mixer_strip->fast_update ();
198                 }
199                 
200         }
201 }
202
203 void
204 Editor::update_slower ()
205 {
206                 if (current_mixer_strip) {
207                         current_mixer_strip->update ();
208                 }
209 }
210
211 void
212 Editor::current_mixer_strip_removed ()
213 {
214         if (current_mixer_strip) {
215                 /* it is being deleted */
216                 current_mixer_strip = 0;
217         }
218 }
219
220 void
221 Editor::current_mixer_strip_hidden ()
222 {
223         for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
224                 
225                 AudioTimeAxisView* tmp;
226                 
227                 if ((tmp = dynamic_cast<AudioTimeAxisView*>(*i)) != 0) {
228                         if (&(tmp->route()) == &(current_mixer_strip->route())) {
229                                 (*i)->set_selected (false);
230                                 break;
231                         }
232                 }
233         }
234         global_hpacker.remove (*current_mixer_strip);
235 }
236
237 void
238 Editor::session_going_away ()
239 {
240         for (vector<sigc::connection>::iterator i = session_connections.begin(); i != session_connections.end(); ++i) {
241                 (*i).disconnect ();
242         }
243
244         stop_scrolling ();
245         selection->clear ();
246         cut_buffer->clear ();
247
248         clicked_regionview = 0;
249         clicked_trackview = 0;
250         clicked_audio_trackview = 0;
251         clicked_crossfadeview = 0;
252         entered_regionview = 0;
253         entered_track = 0;
254         latest_regionview = 0;
255         last_update_frame = 0;
256         drag_info.item = 0;
257         last_audition_region = 0;
258
259         /* hide all tracks */
260
261         hide_all_tracks (false);
262
263         /* rip everything out of the list displays */
264
265         region_list_clear (); // no clear() method in gtkmm 1.2 
266         route_display_model->clear ();
267         named_selection_model->clear ();
268         group_model->clear ();
269
270         edit_cursor_clock.set_session (0);
271         selection_start_clock.set_session (0);
272         selection_end_clock.set_session (0);
273         zoom_range_clock.set_session (0);
274         nudge_clock.set_session (0);
275
276         /* put editor/mixer toggle button in off position and disable until a new session is loaded */
277
278         editor_mixer_button.set_active(false);
279         editor_mixer_button.set_sensitive(false);
280         /* clear tempo/meter rulers */
281
282         remove_metric_marks ();
283         hide_measures ();
284         clear_marker_display ();
285
286         if (current_bbt_points) {
287                 delete current_bbt_points;
288                 current_bbt_points = 0;
289         }
290
291         /* mixer strip will be deleted all by itself 
292            when its route is deleted.
293         */
294
295         current_mixer_strip = 0;
296
297         set_title (_("ardour: editor"));
298
299         session = 0;
300 }