Fix some messed up code (spacey tabs).
[ardour.git] / gtk2_ardour / audio_streamview.cc
1 /*
2     Copyright (C) 2001, 2006 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 #include <cmath>
20 #include <cassert>
21 #include <utility>
22
23 #include <gtkmm.h>
24
25 #include <gtkmm2ext/gtk_ui.h>
26
27 #include "pbd/stacktrace.h"
28
29 #include "ardour/audioplaylist.h"
30 #include "ardour/audioregion.h"
31 #include "ardour/audiofilesource.h"
32 #include "ardour/audio_track.h"
33 #include "ardour/source.h"
34 #include "ardour/region_factory.h"
35 #include "ardour/profile.h"
36 #include "ardour/rc_configuration.h"
37 #include "ardour/session.h"
38
39 #include "audio_streamview.h"
40 #include "audio_region_view.h"
41 #include "tape_region_view.h"
42 #include "audio_time_axis.h"
43 #include "canvas-waveview.h"
44 #include "canvas-simplerect.h"
45 #include "region_selection.h"
46 #include "selection.h"
47 #include "public_editor.h"
48 #include "ardour_ui.h"
49 #include "crossfade_view.h"
50 #include "rgb_macros.h"
51 #include "gui_thread.h"
52 #include "utils.h"
53
54 #include "i18n.h"
55
56 using namespace std;
57 using namespace ARDOUR;
58 using namespace PBD;
59 using namespace Editing;
60
61 AudioStreamView::AudioStreamView (AudioTimeAxisView& tv)
62         : StreamView (tv)
63 {
64         crossfades_visible = tv.session()->config.get_xfades_visible ();
65         color_handler ();
66         _amplitude_above_axis = 1.0;
67
68         Config->ParameterChanged.connect (*this, invalidator (*this), ui_bind (&AudioStreamView::parameter_changed, this, _1), gui_context());
69 }
70
71 AudioStreamView::~AudioStreamView ()
72 {
73 }
74
75 int
76 AudioStreamView::set_samples_per_unit (gdouble spp)
77 {
78         StreamView::set_samples_per_unit(spp);
79
80         for (CrossfadeViewList::iterator xi = crossfade_views.begin(); xi != crossfade_views.end(); ++xi) {
81                 xi->second->set_samples_per_unit (spp);
82         }
83
84         return 0;
85 }
86
87 int
88 AudioStreamView::set_amplitude_above_axis (gdouble app)
89 {
90         RegionViewList::iterator i;
91
92         if (app < 1.0) {
93                 return -1;
94         }
95
96         _amplitude_above_axis = app;
97
98         for (i = region_views.begin(); i != region_views.end(); ++i) {
99                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
100                 if (arv)
101                         arv->set_amplitude_above_axis (app);
102         }
103
104         return 0;
105 }
106
107 RegionView*
108 AudioStreamView::create_region_view (boost::shared_ptr<Region> r, bool wait_for_waves, bool recording)
109 {
110         AudioRegionView *region_view = 0;
111         boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (r);
112
113         if (region == 0) {
114                 return 0;
115         }
116
117         switch (_trackview.audio_track()->mode()) {
118
119         case NonLayered:
120         case Normal:
121                 if (recording) {
122                         region_view = new AudioRegionView (_canvas_group, _trackview, region,
123                                         _samples_per_unit, region_color, recording, TimeAxisViewItem::Visibility(
124                                                         TimeAxisViewItem::ShowFrame | 
125                                                         TimeAxisViewItem::HideFrameRight |
126                                                         TimeAxisViewItem::HideFrameLeft |
127                                                         TimeAxisViewItem::HideFrameTB));
128                 } else {
129                         region_view = new AudioRegionView (_canvas_group, _trackview, region,
130                                         _samples_per_unit, region_color);
131                 }
132                 break;
133         case Destructive:
134                 region_view = new TapeAudioRegionView (_canvas_group, _trackview, region,
135                                 _samples_per_unit, region_color);
136                 break;
137         default:
138                 fatal << string_compose (_("programming error: %1"), "illegal track mode in ::add_region_view_internal") << endmsg;
139                 /*NOTREACHED*/
140
141         }
142
143         region_view->init (region_color, wait_for_waves);
144         region_view->set_amplitude_above_axis(_amplitude_above_axis);
145         region_view->set_height (child_height ());
146
147         /* if its the special single-sample length that we use for rec-regions, make it
148            insensitive to events
149         */
150
151         if (region->length() == 1) {
152                 region_view->set_sensitive (false);
153         }
154
155         region_view->set_waveform_scale (Config->get_waveform_scale ());
156         region_view->set_waveform_shape (Config->get_waveform_shape ());
157         region_view->set_waveform_visible (Config->get_show_waveforms ());
158
159         return region_view;
160 }
161
162 RegionView*
163 AudioStreamView::add_region_view_internal (boost::shared_ptr<Region> r, bool wait_for_waves, bool recording)
164 {
165         RegionView *region_view = create_region_view (r, wait_for_waves, recording);
166         
167         if (region_view == 0) {
168                 return 0;
169         }
170
171 //      if(!recording){
172 //              for (list<RegionView *>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
173 //                      if ((*i)->region() == r) {
174 //                              cerr << "audio_streamview in add_region_view_internal region found" << endl;
175                                 /* great. we already have a AudioRegionView for this Region. use it again. */
176
177 //                              (*i)->set_valid (true);
178
179                                 // this might not be necessary
180 //                              AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
181
182 //                              if (arv) {
183 //                                      arv->set_waveform_scale (_waveform_scale);
184 //                                      arv->set_waveform_shape (_waveform_shape);
185 //                              }
186
187 //                              return NULL;
188 //                      }
189 //              }
190 //      }
191
192         region_views.push_front (region_view);
193
194         /* catch region going away */
195
196         r->DropReferences.connect (*this, invalidator (*this), boost::bind (&AudioStreamView::remove_region_view, this, boost::weak_ptr<Region> (r)), gui_context());
197
198         RegionViewAdded (region_view);
199
200         return region_view;
201 }
202
203 void
204 AudioStreamView::remove_region_view (boost::weak_ptr<Region> weak_r)
205 {
206         ENSURE_GUI_THREAD (*this, &AudioStreamView::remove_region_view, weak_r);
207
208         boost::shared_ptr<Region> r (weak_r.lock());
209
210         if (!r) {
211                 return;
212         }
213
214         if (!_trackview.session()->deletion_in_progress()) {
215
216                 for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end();) {
217                         CrossfadeViewList::iterator tmp;
218
219                         tmp = i;
220                         ++tmp;
221
222                         boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion>(r);
223                         if (ar && i->second->crossfade->involves (ar)) {
224                                 delete i->second;
225                                 crossfade_views.erase (i);
226                         }
227
228                         i = tmp;
229                 }
230         }
231
232         StreamView::remove_region_view(r);
233 }
234
235 void
236 AudioStreamView::undisplay_track ()
237 {
238         StreamView::undisplay_track ();
239
240         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
241                 delete i->second;
242         }
243
244         crossfade_views.clear ();
245 }
246
247 void
248 AudioStreamView::playlist_layered (boost::weak_ptr<Track> wtr)
249 {
250         boost::shared_ptr<Track> tr (wtr.lock());
251
252         if (!tr) {
253                 return;
254         }
255
256         StreamView::playlist_layered (wtr);
257
258         /* make sure xfades are on top and all the regionviews are stacked correctly. */
259
260         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
261                 i->second->get_canvas_group()->raise_to_top();
262         }
263 }
264
265 void
266 AudioStreamView::playlist_switched (boost::weak_ptr<Track> wtr)
267 {
268         boost::shared_ptr<Track> tr (wtr.lock());
269
270         if (!tr) {
271                 return;
272         }
273
274         playlist_connections.drop_connections ();
275
276         StreamView::playlist_switched (tr);
277
278         boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist> (tr->playlist());
279
280         if (apl) {
281                 apl->NewCrossfade.connect (playlist_connections, invalidator (*this), ui_bind (&AudioStreamView::add_crossfade, this, _1), gui_context());
282         }
283 }
284
285 void
286 AudioStreamView::add_crossfade (boost::weak_ptr<Crossfade> wc)
287 {
288         boost::shared_ptr<Crossfade> crossfade (wc.lock());
289
290         if (!crossfade) {
291                 return;
292         }
293
294         AudioRegionView* lview = 0;
295         AudioRegionView* rview = 0;
296
297         /* first see if we already have a CrossfadeView for this Crossfade */
298
299         CrossfadeViewList::iterator i = crossfade_views.find (crossfade);
300         if (i != crossfade_views.end()) {
301                 if (!crossfades_visible) {
302                         i->second->hide();
303                 } else {
304                         i->second->show ();
305                 }
306                 i->second->set_valid (true);
307                 return;
308         }
309
310         /* create a new one */
311
312         for (list<RegionView *>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
313                 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(*i);
314
315                 if (!lview && arv && (arv->region() == crossfade->out())) {
316                         lview = arv;
317                 }
318                 if (!rview && arv && (arv->region() == crossfade->in())) {
319                         rview = arv;
320                 }
321         }
322
323         CrossfadeView *cv = new CrossfadeView (_trackview.canvas_display (),
324                                                _trackview,
325                                                 crossfade,
326                                                _samples_per_unit,
327                                                region_color,
328                                                *lview, *rview);
329         cv->set_valid (true);
330         crossfade->Invalidated.connect (*this, invalidator (*this), ui_bind (&AudioStreamView::remove_crossfade, this, _1), gui_context());
331         crossfade_views[cv->crossfade] = cv;
332         if (!crossfades_visible) {
333                 cv->hide ();
334         }
335
336         update_content_height (cv);
337 }
338
339 void
340 AudioStreamView::remove_crossfade (boost::shared_ptr<Region> r)
341 {
342         ENSURE_GUI_THREAD (*this, &AudioStreamView::remove_crossfade, r)
343
344         boost::shared_ptr<Crossfade> xfade = boost::dynamic_pointer_cast<Crossfade> (r);
345
346         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
347                 if (i->second->crossfade == xfade) {
348                         delete i->second;
349                         crossfade_views.erase (i);
350                         break;
351                 }
352         }
353 }
354
355 void
356 AudioStreamView::redisplay_track ()
357 {
358         list<RegionView *>::iterator i;
359         CrossfadeViewList::iterator xi, tmpx;
360
361         // Flag region views as invalid and disable drawing
362         for (i = region_views.begin(); i != region_views.end(); ++i) {
363                 (*i)->set_valid (false);
364                 (*i)->enable_display (false);
365         }
366
367         // Flag crossfade views as invalid
368         for (xi = crossfade_views.begin(); xi != crossfade_views.end(); ++xi) {
369                 xi->second->set_valid (false);
370                 if (xi->second->visible()) {
371                         xi->second->show ();
372                 }
373         }
374
375         // Add and display region and crossfade views, and flag them as valid
376
377         if (_trackview.is_audio_track()) {
378                 _trackview.track()->playlist()->foreach_region(
379                         sigc::hide_return (sigc::mem_fun (*this, &StreamView::add_region_view))
380                         );
381
382                 boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist>(
383                                 _trackview.track()->playlist()
384                         );
385
386                 if (apl) {
387                         apl->foreach_crossfade (sigc::mem_fun (*this, &AudioStreamView::add_crossfade));
388                 }
389         }
390
391         // Remove invalid crossfade views
392         for (xi = crossfade_views.begin(); xi != crossfade_views.end();) {
393                 tmpx = xi;
394                 tmpx++;
395
396                 if (!xi->second->valid()) {
397                         delete xi->second;
398                         crossfade_views.erase (xi);
399                 }
400
401                 xi = tmpx;
402         }
403
404         // Stack regions by layer, and remove invalid regions
405         layer_regions();
406 }
407
408 void
409 AudioStreamView::set_show_waveforms (bool yn)
410 {
411         for (list<RegionView *>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
412                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
413                 if (arv) {
414                         arv->set_waveform_visible (yn);
415                 }
416         }
417 }
418
419 void
420 AudioStreamView::set_waveform_shape (WaveformShape shape)
421 {
422         for (RegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) {
423                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
424                 if (arv)
425                         arv->set_waveform_shape (shape);
426         }
427 }
428
429 void
430 AudioStreamView::set_waveform_scale (WaveformScale scale)
431 {
432         for (RegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) {
433                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
434                 if (arv) {
435                         arv->set_waveform_scale (scale);
436                 }
437         }
438 }
439
440 void
441 AudioStreamView::setup_rec_box ()
442 {
443         //cerr << _trackview.name() << " streamview SRB region_views.size() = " << region_views.size() << endl;
444
445         if (_trackview.session()->transport_rolling()) {
446
447                 // cerr << "\trolling\n";
448
449                 if (!rec_active &&
450                     _trackview.session()->record_status() == Session::Recording &&
451                     _trackview.track()->record_enabled()) {
452                         if (_trackview.audio_track()->mode() == Normal && Config->get_show_waveforms_while_recording() && rec_regions.size() == rec_rects.size()) {
453
454                                 /* add a new region, but don't bother if they set show-waveforms-while-recording mid-record */
455
456                                 SourceList sources;
457
458                                 rec_data_ready_connections.drop_connections ();
459                                 boost::shared_ptr<AudioTrack> tr = _trackview.audio_track();
460
461                                 for (uint32_t n = 0; n < tr->n_channels().n_audio(); ++n) {
462                                         boost::shared_ptr<AudioFileSource> src = tr->write_source (n);
463                                         if (src) {
464                                                 sources.push_back (src);
465                                                 src->PeakRangeReady.connect (rec_data_ready_connections,
466                                                                              invalidator (*this),
467                                                                              ui_bind (&AudioStreamView::rec_peak_range_ready, this, _1, _2, boost::weak_ptr<Source>(src)),
468                                                                              gui_context());
469                                         }
470                                 }
471
472                                 // handle multi
473
474                                 nframes_t start = 0;
475                                 if (rec_regions.size() > 0) {
476                                         start = rec_regions.back().first->start()
477                                                         + _trackview.track()->get_captured_frames(rec_regions.size()-1);
478                                 }
479
480                                 PropertyList plist; 
481                                 
482                                 plist.add (Properties::start, start);
483                                 plist.add (Properties::length, 1);
484                                 plist.add (Properties::name, string());
485                                 plist.add (Properties::layer, 0);
486
487                                 boost::shared_ptr<AudioRegion> region (
488                                         boost::dynamic_pointer_cast<AudioRegion>(RegionFactory::create (sources, plist, false)));
489
490                                 assert(region);
491                                 region->set_position (_trackview.session()->transport_frame(), this);
492                                 rec_regions.push_back (make_pair(region, (RegionView*) 0));
493                         }
494
495                         /* start a new rec box */
496
497                         boost::shared_ptr<AudioTrack> at;
498
499                         at = _trackview.audio_track(); /* we know what it is already */
500                         framepos_t const frame_pos = at->current_capture_start ();
501                         gdouble xstart = _trackview.editor().frame_to_pixel (frame_pos);
502                         gdouble xend;
503                         uint32_t fill_color;
504
505                         switch (_trackview.audio_track()->mode()) {
506                         case Normal:
507                         case NonLayered:
508                                 xend = xstart;
509                                 fill_color = ARDOUR_UI::config()->canvasvar_RecordingRect.get();
510                                 break;
511
512                         case Destructive:
513                                 xend = xstart + 2;
514                                 fill_color = ARDOUR_UI::config()->canvasvar_RecordingRect.get();
515                                 /* make the recording rect translucent to allow
516                                    the user to see the peak data coming in, etc.
517                                 */
518                                 fill_color = UINT_RGBA_CHANGE_A (fill_color, 120);
519                                 break;
520                         }
521
522                         ArdourCanvas::SimpleRect * rec_rect = new Gnome::Canvas::SimpleRect (*_canvas_group);
523                         rec_rect->property_x1() = xstart;
524                         rec_rect->property_y1() = 1.0;
525                         rec_rect->property_x2() = xend;
526                         rec_rect->property_y2() = child_height ();
527                         rec_rect->property_outline_what() = 0x0;
528                         rec_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeAxisFrame.get();
529                         rec_rect->property_fill_color_rgba() = fill_color;
530                         rec_rect->lower_to_bottom();
531
532                         RecBoxInfo recbox;
533                         recbox.rectangle = rec_rect;
534                         recbox.start = _trackview.session()->transport_frame();
535                         recbox.length = 0;
536
537                         rec_rects.push_back (recbox);
538
539                         screen_update_connection.disconnect();
540                         screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect (
541                                         sigc::mem_fun (*this, &AudioStreamView::update_rec_box));
542                         rec_updating = true;
543                         rec_active = true;
544
545                 } else if (rec_active &&
546                            (_trackview.session()->record_status() != Session::Recording ||
547                             !_trackview.track()->record_enabled())) {
548                         screen_update_connection.disconnect();
549                         rec_active = false;
550                         rec_updating = false;
551                 }
552
553         } else {
554
555                 // cerr << "\tNOT rolling, rec_rects = " << rec_rects.size() << " rec_regions = " << rec_regions.size() << endl;
556
557                 if (!rec_rects.empty() || !rec_regions.empty()) {
558
559                         /* disconnect rapid update */
560                         screen_update_connection.disconnect();
561                         rec_data_ready_connections.drop_connections ();
562                         rec_updating = false;
563                         rec_active = false;
564
565                         /* remove temp regions */
566
567                         for (list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator iter = rec_regions.begin(); iter != rec_regions.end(); ) {
568                                 list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator tmp;
569
570                                 tmp = iter;
571                                 ++tmp;
572
573                                 (*iter).first->drop_references ();
574
575                                 iter = tmp;
576                         }
577
578                         rec_regions.clear();
579
580                         // cerr << "\tclear " << rec_rects.size() << " rec rects\n";
581
582                         /* transport stopped, clear boxes */
583                         for (vector<RecBoxInfo>::iterator iter=rec_rects.begin(); iter != rec_rects.end(); ++iter) {
584                                 RecBoxInfo &rect = (*iter);
585                                 delete rect.rectangle;
586                         }
587
588                         rec_rects.clear();
589
590                 }
591         }
592 }
593
594 void
595 AudioStreamView::foreach_crossfadeview (void (CrossfadeView::*pmf)(void))
596 {
597         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
598                 (i->second->*pmf) ();
599         }
600 }
601
602 void
603 AudioStreamView::rec_peak_range_ready (nframes_t start, nframes_t cnt, boost::weak_ptr<Source> weak_src)
604 {
605         ENSURE_GUI_THREAD (*this, &AudioStreamView::rec_peak_range_ready, start, cnt, weak_src)
606
607         boost::shared_ptr<Source> src (weak_src.lock());
608
609         if (!src) {
610                 return;
611         }
612
613         // this is called from the peak building thread
614
615         if (rec_data_ready_map.size() == 0 || start + cnt > last_rec_data_frame) {
616                 last_rec_data_frame = start + cnt;
617         }
618
619         rec_data_ready_map[src] = true;
620
621         if (rec_data_ready_map.size() == _trackview.track()->n_channels().n_audio()) {
622                 update_rec_regions (start, cnt);
623                 rec_data_ready_map.clear();
624         }
625 }
626
627 void
628 AudioStreamView::update_rec_regions (framepos_t start, framecnt_t cnt)
629 {
630         if (!Config->get_show_waveforms_while_recording ()) {
631                 return;
632         }
633         
634         uint32_t n = 0;
635         
636         for (list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator iter = rec_regions.begin(); iter != rec_regions.end(); n++) {
637                 
638                 list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator tmp = iter;
639                 ++tmp;
640
641                 assert (n < rec_rects.size());
642                 
643                 if (!canvas_item_visible (rec_rects[n].rectangle)) {
644                         /* rect already hidden, this region is done */
645                         iter = tmp;
646                         continue;
647                 }
648                 
649                 boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion>(iter->first);
650                 
651                 if (!region) {
652                         iter = tmp;
653                         continue;
654                 }
655                 
656                 nframes_t origlen = region->length();
657
658                 if (region == rec_regions.back().first && rec_active) {
659                         
660                         if (last_rec_data_frame > region->start()) {
661                                 
662                                 nframes_t nlen = last_rec_data_frame - region->start();
663                                 
664                                 if (nlen != region->length()) {
665
666                                         region->suspend_property_changes ();
667                                         region->set_position (_trackview.track()->get_capture_start_frame(n), this);
668                                         region->set_length (nlen, this);
669                                         region->resume_property_changes ();
670                                         
671                                         if (origlen == 1) {
672                                                 /* our special initial length */
673                                                 add_region_view_internal (region, false, true);
674                                                 setup_new_rec_layer_time (region);
675                                         }
676
677                                         check_record_layers (region, (region->position() - region->start() + start + cnt));
678                                         
679                                         /* also update rect */
680                                         ArdourCanvas::SimpleRect * rect = rec_rects[n].rectangle;
681                                         gdouble xend = _trackview.editor().frame_to_pixel (region->position() + region->length());
682                                         rect->property_x2() = xend;
683                                 }
684
685                         } else {
686                                 
687                                 nframes_t nlen = _trackview.track()->get_captured_frames(n);
688                                 
689                                 if (nlen != region->length()) {
690                                         
691                                         if (region->source_length(0) >= region->start() + nlen) {
692
693                                                 region->suspend_property_changes ();
694                                                 region->set_position (_trackview.track()->get_capture_start_frame(n), this);
695                                                 region->set_length (nlen, this);
696                                                 region->resume_property_changes ();
697
698                                                 if (origlen == 1) {
699                                                         /* our special initial length */
700                                                         add_region_view_internal (region, false, true);
701                                                 }
702
703                                                 /* also hide rect */
704                                                 ArdourCanvas::Item * rect = rec_rects[n].rectangle;
705                                                 rect->hide();
706
707                                         }
708                                 }
709                         }
710                 }
711
712                 iter = tmp;
713         }
714 }
715
716 void
717 AudioStreamView::show_all_fades ()
718 {
719         for (list<RegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
720                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
721                 if (arv) {
722                         arv->set_fade_visibility (true);
723                 }
724         }
725 }
726
727 void
728 AudioStreamView::hide_all_fades ()
729 {
730         for (list<RegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
731                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
732                 if (arv) {
733                         arv->set_fade_visibility (false);
734                 }
735         }
736 }
737
738 void
739 AudioStreamView::show_all_xfades ()
740 {
741         foreach_crossfadeview (&CrossfadeView::show);
742         crossfades_visible = true;
743 }
744
745 void
746 AudioStreamView::hide_all_xfades ()
747 {
748         foreach_crossfadeview (&CrossfadeView::hide);
749         crossfades_visible = false;
750 }
751
752 void
753 AudioStreamView::hide_xfades_involving (AudioRegionView& rv)
754 {
755         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
756                 if (i->second->crossfade->involves (rv.audio_region())) {
757                         i->second->fake_hide ();
758                 }
759         }
760 }
761
762 void
763 AudioStreamView::reveal_xfades_involving (AudioRegionView& rv)
764 {
765         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
766                 if (i->second->crossfade->involves (rv.audio_region()) && i->second->visible()) {
767                         i->second->show ();
768                 }
769         }
770 }
771
772 void
773 AudioStreamView::color_handler ()
774 {
775         //case cAudioTrackBase:
776         if (_trackview.is_track()) {
777                 canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_AudioTrackBase.get();
778         }
779
780         //case cAudioBusBase:
781         if (!_trackview.is_track()) {
782                 if (Profile->get_sae() && _trackview.route()->is_master()) {
783                         canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_AudioMasterBusBase.get();
784                 } else {
785                         canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_AudioBusBase.get();
786                 }
787         }
788 }
789
790 void
791 AudioStreamView::update_contents_height ()
792 {
793         StreamView::update_contents_height ();
794
795         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
796                 update_content_height (i->second);
797         }
798 }
799
800 void
801 AudioStreamView::update_content_height (CrossfadeView* cv)
802 {
803         if (_layer_display == Overlaid) {
804
805                 cv->set_y (0);
806                 cv->set_height (height);
807
808         } else {
809
810                 layer_t const inl = cv->crossfade->in()->layer ();
811                 layer_t const outl = cv->crossfade->out()->layer ();
812
813                 layer_t const high = max (inl, outl);
814                 layer_t const low = min (inl, outl);
815
816                 const double h = child_height ();
817
818                 cv->set_y ((_layers - high - 1) * h);
819                 cv->set_height ((high - low + 1) * h);
820
821         }
822 }
823
824 void
825 AudioStreamView::parameter_changed (string const & p)
826 {
827         if (p == "show-waveforms") {
828                 set_show_waveforms (Config->get_show_waveforms ());
829         } else if (p == "waveform-scale") {
830                 set_waveform_scale (Config->get_waveform_scale ());
831         } else if (p == "waveform-shape") {
832                 set_waveform_shape (Config->get_waveform_shape ());
833         }
834 }
835
836 void
837 AudioStreamView::horizontal_position_changed ()
838 {
839         /* we only `draw' the bit of the curve that is visible, so we need to update here */
840         
841         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
842                 i->second->horizontal_position_changed ();
843         }
844 }
845