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