remove all lines to avoid recompiles after commits
[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 */
19
20 #include <gtkmm2ext/utils.h>
21 #include <ardour/audioengine.h>
22
23 #include "editor.h"
24 #include "mixer_strip.h"
25 #include "ardour_ui.h"
26 #include "selection.h"
27 #include "audio_time_axis.h"
28 #include "actions.h"
29
30 #include "i18n.h"
31
32 void
33 Editor::editor_mixer_button_toggled ()
34 {
35         Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
36         if (act) {
37                 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
38                 show_editor_mixer (tact->get_active());
39         }
40 }
41
42 void
43 Editor::cms_deleted ()
44 {
45         current_mixer_strip = 0;
46 }
47
48 void
49 Editor::show_editor_mixer (bool yn)
50 {
51         show_editor_mixer_when_tracks_arrive = false;
52
53         if (yn) {
54
55                 if (current_mixer_strip == 0) {
56
57                         if (selection->tracks.empty()) {
58                                 
59                                 if (track_views.empty()) {      
60                                         show_editor_mixer_when_tracks_arrive = true;
61                                         return;
62                                 } 
63                                 
64                                 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
65                                         AudioTimeAxisView* atv;
66
67                                         if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) != 0) {
68                                                 
69                                                 current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
70                                                                                       *session,
71                                                                                       atv->route(), false);
72
73                                                 current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::cms_deleted));                                          
74                                                 break;
75                                         }
76                                 }
77
78                         } else {
79
80                                 sort_track_selection ();
81
82                                 for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
83                                         AudioTimeAxisView* atv;
84
85                                         if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) != 0) {
86
87                                                 current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
88                                                                                       *session,
89                                                                                       atv->route(), false);
90                                                 current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::cms_deleted));                                          
91                                                 break;
92                                         }
93                                 }
94
95                         }
96
97                         if (current_mixer_strip == 0) {
98                                 return;
99                         }               
100                 }
101                 
102                 if (current_mixer_strip->get_parent() == 0) {
103                         current_mixer_strip->set_embedded (true);
104                         current_mixer_strip->Hiding.connect (mem_fun(*this, &Editor::current_mixer_strip_hidden));
105                         current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::current_mixer_strip_removed));
106                         current_mixer_strip->set_width (editor_mixer_strip_width);
107                         
108                         global_hpacker.pack_start (*current_mixer_strip, Gtk::PACK_SHRINK );
109                         global_hpacker.reorder_child (*current_mixer_strip, 0);
110
111                         current_mixer_strip->show_all ();
112                 }
113
114         } else {
115
116                 if (current_mixer_strip) {
117                         editor_mixer_strip_width = current_mixer_strip->get_width ();
118                         if (current_mixer_strip->get_parent() != 0) {
119                                 global_hpacker.remove (*current_mixer_strip);
120                         }
121                 }
122         }
123 }
124
125 void
126 Editor::set_selected_mixer_strip (TimeAxisView& view)
127 {
128         AudioTimeAxisView* at;
129         bool show = false;
130
131         if (!session || (at = dynamic_cast<AudioTimeAxisView*>(&view)) == 0) {
132                 return;
133         }
134         
135         if (current_mixer_strip) {
136
137                 /* might be nothing to do */
138
139                 if (current_mixer_strip->route() == at->route()) {
140                         return;
141                 }
142
143                 if (current_mixer_strip->get_parent()) {
144                         show = true;
145                 }
146                 delete current_mixer_strip;
147                 current_mixer_strip = 0;
148         }
149
150         current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(),
151                                               *session,
152                                               at->route());
153         current_mixer_strip->GoingAway.connect (mem_fun(*this, &Editor::cms_deleted));
154         
155         if (show) {
156                 show_editor_mixer (true);
157         }
158 }
159
160 double current = 0.0;
161 bool currentInitialized = 0;
162
163 void
164 Editor::update_current_screen ()
165 {
166         if (session && engine.running()) {
167
168                 nframes_t frame;
169
170                 frame = session->audible_frame();
171
172                 if (_dragging_playhead) {
173                         goto almost_done;
174                 }
175
176                 /* only update if the playhead is on screen or we are following it */
177
178                 if (_follow_playhead) {
179
180                         playhead_cursor->canvas_item.show();
181
182                         if (frame != last_update_frame) {
183
184
185 #undef CONTINUOUS_SCROLL
186 #ifndef  CONTINUOUS_SCROLL
187                                 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
188                                         
189                                         if (session->transport_speed() < 0) {
190                                                 if (frame > (current_page_frames()/2)) {
191                                                         center_screen (frame-(current_page_frames()/2));
192                                                 } else {
193                                                         center_screen (current_page_frames()/2);
194                                                 }
195                                         } else {
196                                                 center_screen (frame+(current_page_frames()/2));
197                                         }
198                                 }
199
200                                 playhead_cursor->set_position (frame);
201
202 #else  // CONTINUOUS_SCROLL
203                                 
204                                 /* don't do continuous scroll till the new position is in the rightmost quarter of the 
205                                    editor canvas
206                                 */
207                                 
208                                 if (session->transport_speed()) {
209                                         double target = ((double)frame - (double)current_page_frames()/2.0) / frames_per_unit;
210                                         if (target <= 0.0) target = 0.0;
211                                         if ( fabs(target - current) < current_page_frames()/frames_per_unit ) {
212                                                 target = (target * 0.15) + (current * 0.85);
213                                         } else {
214                                                 /* relax */
215                                         }
216                                         //printf("frame: %d,  cpf: %d,  fpu: %6.6f, current: %6.6f, target : %6.6f\n", frame, current_page_frames(), frames_per_unit, current, target );
217                                         current = target;
218                                         horizontal_adjustment.set_value ( current );
219                                 }
220                                 
221                                 playhead_cursor->set_position (frame);
222
223 #endif // CONTINUOUS_SCROLL
224
225                         }
226
227                 } else {
228                         
229                         if (frame != last_update_frame) {
230                                 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
231                                         playhead_cursor->canvas_item.hide();
232                                 } else {
233                                         playhead_cursor->set_position (frame);
234                                 }
235                         }
236                 }
237
238           almost_done:
239                 last_update_frame = frame;
240
241                 if (current_mixer_strip) {
242                         current_mixer_strip->fast_update ();
243                 }
244                 
245         }
246 }
247
248 void
249 Editor::current_mixer_strip_removed ()
250 {
251         if (current_mixer_strip) {
252                 /* it is being deleted */
253                 current_mixer_strip = 0;
254         }
255 }
256
257 void
258 Editor::current_mixer_strip_hidden ()
259 {
260         for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
261                 
262                 AudioTimeAxisView* tmp;
263                 
264                 if ((tmp = dynamic_cast<AudioTimeAxisView*>(*i)) != 0) {
265                         if (tmp->route() == current_mixer_strip->route()) {
266                                 (*i)->set_selected (false);
267                                 break;
268                         }
269                 }
270         }
271
272         Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
273         if (act) {
274                 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
275                 tact->set_active (false);
276         }
277 }
278
279 void
280 Editor::session_going_away ()
281 {
282         for (vector<sigc::connection>::iterator i = session_connections.begin(); i != session_connections.end(); ++i) {
283                 (*i).disconnect ();
284         }
285
286         stop_scrolling ();
287         selection->clear ();
288         cut_buffer->clear ();
289
290         clicked_regionview = 0;
291         clicked_trackview = 0;
292         clicked_audio_trackview = 0;
293         clicked_crossfadeview = 0;
294         entered_regionview = 0;
295         entered_track = 0;
296         latest_regionview = 0;
297         last_update_frame = 0;
298         drag_info.item = 0;
299         last_canvas_frame = 0;
300
301         /* hide all tracks */
302
303         hide_all_tracks (false);
304
305         /* rip everything out of the list displays */
306
307         region_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
308         route_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
309         named_selection_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
310         edit_group_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
311
312         region_list_model->clear ();
313         route_display_model->clear ();
314         named_selection_model->clear ();
315         group_model->clear ();
316
317         region_list_display.set_model (region_list_model);
318         route_list_display.set_model (route_display_model);
319         named_selection_display.set_model (named_selection_model);
320         edit_group_display.set_model (group_model);
321
322         edit_cursor_clock.set_session (0);
323         zoom_range_clock.set_session (0);
324         nudge_clock.set_session (0);
325
326         /* put editor/mixer toggle button in off position and disable until a new session is loaded */
327
328         editor_mixer_button.set_active(false);
329         editor_mixer_button.set_sensitive(false);
330         /* clear tempo/meter rulers */
331
332         remove_metric_marks ();
333         hide_measures ();
334         clear_marker_display ();
335
336         if (current_bbt_points) {
337                 delete current_bbt_points;
338                 current_bbt_points = 0;
339         }
340
341         /* mixer strip will be deleted all by itself 
342            when its route is deleted.
343         */
344
345         current_mixer_strip = 0;
346
347         set_title (_("ardour: editor"));
348
349         session = 0;
350 }