option editor and some prompters, misc stuff. this commit message contains no apostro...
[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                         gnome_canvas_item_show (playhead_cursor->canvas_item);
165
166                         if (frame != last_update_frame) {
167
168                                 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
169                                         
170                                         if (session->transport_speed() < 0) {
171                                                 if (frame > (current_page_frames()/2)) {
172                                                         center_screen (frame-(current_page_frames()/2));
173                                                 } else {
174                                                         center_screen (current_page_frames()/2);
175                                                 }
176                                         } else {
177                                                 center_screen (frame+(current_page_frames()/2));
178                                         }
179                                 }
180
181                                 playhead_cursor->set_position (frame);
182                         }
183
184                 } else {
185                         
186                         if (frame != last_update_frame) {
187                                 if (frame < leftmost_frame || frame > leftmost_frame + current_page_frames()) {
188                                         gnome_canvas_item_hide (playhead_cursor->canvas_item);
189                                 } else {
190                                         playhead_cursor->set_position (frame);
191                                 }
192                         }
193                 }
194
195                 last_update_frame = frame;
196
197                 if (current_mixer_strip) {
198                         current_mixer_strip->fast_update ();
199                 }
200                 
201         }
202 }
203
204 void
205 Editor::update_slower ()
206 {
207                 if (current_mixer_strip) {
208                         current_mixer_strip->update ();
209                 }
210 }
211
212 void
213 Editor::current_mixer_strip_removed ()
214 {
215         if (current_mixer_strip) {
216                 /* it is being deleted */
217                 current_mixer_strip = 0;
218         }
219 }
220
221 void
222 Editor::current_mixer_strip_hidden ()
223 {
224         for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
225                 
226                 AudioTimeAxisView* tmp;
227                 
228                 if ((tmp = dynamic_cast<AudioTimeAxisView*>(*i)) != 0) {
229                         if (&(tmp->route()) == &(current_mixer_strip->route())) {
230                                 (*i)->set_selected (false);
231                                 break;
232                         }
233                 }
234         }
235         global_hpacker.remove (*current_mixer_strip);
236 }
237
238 void
239 Editor::session_going_away ()
240 {
241         for (vector<sigc::connection>::iterator i = session_connections.begin(); i != session_connections.end(); ++i) {
242                 (*i).disconnect ();
243         }
244
245         stop_scrolling ();
246         selection->clear ();
247         cut_buffer->clear ();
248
249         clicked_regionview = 0;
250         clicked_trackview = 0;
251         clicked_audio_trackview = 0;
252         clicked_crossfadeview = 0;
253         entered_regionview = 0;
254         entered_track = 0;
255         latest_regionview = 0;
256         last_update_frame = 0;
257         drag_info.item = 0;
258         last_audition_region = 0;
259
260         /* hide all tracks */
261
262         hide_all_tracks (false);
263
264         /* rip everything out of the list displays */
265
266         region_list_clear (); // no clear() method in gtkmm 1.2 
267         route_display_model.clear ();
268         named_selection_model.clear ();
269         group_model.clear ();
270
271         edit_cursor_clock.set_session (0);
272         selection_start_clock.set_session (0);
273         selection_end_clock.set_session (0);
274         zoom_range_clock.set_session (0);
275         nudge_clock.set_session (0);
276
277         /* put editor/mixer toggle button in off position and disable until a new session is loaded */
278
279         editor_mixer_button.set_active(false);
280         editor_mixer_button.set_sensitive(false);
281         /* clear tempo/meter rulers */
282
283         remove_metric_marks ();
284         hide_measures ();
285         clear_marker_display ();
286
287         if (current_bbt_points) {
288                 delete current_bbt_points;
289                 current_bbt_points = 0;
290         }
291
292         if (embed_audio_item) {
293                 embed_audio_item->set_sensitive (false);
294         } 
295
296         if (import_audio_item) {
297                 import_audio_item->set_sensitive (false);
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 }