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