(1) remove most uses of MementoCommand for Playlist and Region (2) move frozen state...
[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, 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, 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         cerr << "a region went way, it appears to be ours (" << this << ")\n";
214
215         if (!_trackview.session()->deletion_in_progress()) {
216
217                 for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end();) {
218                         CrossfadeViewList::iterator tmp;
219
220                         tmp = i;
221                         ++tmp;
222
223                         boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion>(r);
224                         if (ar && i->second->crossfade->involves (ar)) {
225                                 delete i->second;
226                                 crossfade_views.erase (i);
227                         }
228
229                         i = tmp;
230                 }
231         }
232
233         StreamView::remove_region_view(r);
234 }
235
236 void
237 AudioStreamView::undisplay_diskstream ()
238 {
239         StreamView::undisplay_diskstream();
240
241         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
242                 delete i->second;
243         }
244
245         crossfade_views.clear ();
246 }
247
248 void
249 AudioStreamView::playlist_layered (boost::weak_ptr<Diskstream> wds)
250 {
251         boost::shared_ptr<Diskstream> ds (wds.lock());
252
253         if (!ds) {
254                 return;
255         }
256
257         StreamView::playlist_layered (wds);
258
259         /* make sure xfades are on top and all the regionviews are stacked correctly. */
260
261         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
262                 i->second->get_canvas_group()->raise_to_top();
263         }
264 }
265
266 void
267 AudioStreamView::playlist_switched (boost::weak_ptr<Diskstream> wds)
268 {
269         boost::shared_ptr<Diskstream> ds (wds.lock());
270
271         if (!ds) {
272                 return;
273         }
274
275         playlist_connections.drop_connections ();
276
277         StreamView::playlist_switched (ds);
278
279         boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist>(ds->playlist());
280
281         if (apl) {
282                 apl->NewCrossfade.connect (playlist_connections, ui_bind (&AudioStreamView::add_crossfade, this, _1), gui_context());
283         }
284 }
285
286 void
287 AudioStreamView::add_crossfade (boost::weak_ptr<Crossfade> wc)
288 {
289         boost::shared_ptr<Crossfade> crossfade (wc.lock());
290
291         if (!crossfade) {
292                 return;
293         }
294
295         AudioRegionView* lview = 0;
296         AudioRegionView* rview = 0;
297
298         /* first see if we already have a CrossfadeView for this Crossfade */
299
300         CrossfadeViewList::iterator i = crossfade_views.find (crossfade);
301         if (i != crossfade_views.end()) {
302                 if (!crossfades_visible) {
303                         i->second->hide();
304                 } else {
305                         i->second->show ();
306                 }
307                 i->second->set_valid (true);
308                 return;
309         }
310
311         /* create a new one */
312
313         for (list<RegionView *>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
314                 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(*i);
315
316                 if (!lview && arv && (arv->region() == crossfade->out())) {
317                         lview = arv;
318                 }
319                 if (!rview && arv && (arv->region() == crossfade->in())) {
320                         rview = arv;
321                 }
322         }
323
324         CrossfadeView *cv = new CrossfadeView (_trackview.canvas_display (),
325                                                _trackview,
326                                                 crossfade,
327                                                _samples_per_unit,
328                                                region_color,
329                                                *lview, *rview);
330         cv->set_valid (true);
331         crossfade->Invalidated.connect (*this, ui_bind (&AudioStreamView::remove_crossfade, this, _1), gui_context());
332         crossfade_views[cv->crossfade] = cv;
333         if (!_trackview.session()->config.get_xfades_visible() || !crossfades_visible) {
334                 cv->hide ();
335         }
336
337         update_content_height (cv);
338 }
339
340 void
341 AudioStreamView::remove_crossfade (boost::shared_ptr<Region> r)
342 {
343         ENSURE_GUI_THREAD (*this, &AudioStreamView::remove_crossfade, r)
344
345         boost::shared_ptr<Crossfade> xfade = boost::dynamic_pointer_cast<Crossfade> (r);
346
347         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
348                 if (i->second->crossfade == xfade) {
349                         delete i->second;
350                         crossfade_views.erase (i);
351                         break;
352                 }
353         }
354 }
355
356 void
357 AudioStreamView::redisplay_diskstream ()
358 {
359         list<RegionView *>::iterator i;
360         CrossfadeViewList::iterator xi, tmpx;
361
362         // Flag region views as invalid and disable drawing
363         for (i = region_views.begin(); i != region_views.end(); ++i) {
364                 (*i)->set_valid (false);
365                 (*i)->enable_display (false);
366         }
367
368         // Flag crossfade views as invalid
369         for (xi = crossfade_views.begin(); xi != crossfade_views.end(); ++xi) {
370                 xi->second->set_valid (false);
371                 if (xi->second->visible()) {
372                         xi->second->show ();
373                 }
374         }
375
376         // Add and display region and crossfade views, and flag them as valid
377
378         if (_trackview.is_audio_track()) {
379                 _trackview.get_diskstream()->playlist()->foreach_region(
380                         sigc::hide_return (sigc::mem_fun (*this, &StreamView::add_region_view))
381                         );
382
383                 boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist>(
384                                 _trackview.get_diskstream()->playlist()
385                         );
386
387                 if (apl) {
388                         apl->foreach_crossfade (sigc::mem_fun (*this, &AudioStreamView::add_crossfade));
389                 }
390         }
391
392         // Remove invalid crossfade views
393         for (xi = crossfade_views.begin(); xi != crossfade_views.end();) {
394                 tmpx = xi;
395                 tmpx++;
396
397                 if (!xi->second->valid()) {
398                         delete xi->second;
399                         crossfade_views.erase (xi);
400                 }
401
402                 xi = tmpx;
403         }
404
405         // Stack regions by layer, and remove invalid regions
406         layer_regions();
407 }
408
409 void
410 AudioStreamView::set_show_waveforms (bool yn)
411 {
412         for (list<RegionView *>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
413                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
414                 if (arv) {
415                         arv->set_waveform_visible (yn);
416                 }
417         }
418 }
419
420 void
421 AudioStreamView::set_waveform_shape (WaveformShape shape)
422 {
423         for (RegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) {
424                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
425                 if (arv)
426                         arv->set_waveform_shape (shape);
427         }
428 }
429
430 void
431 AudioStreamView::set_waveform_scale (WaveformScale scale)
432 {
433         for (RegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) {
434                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
435                 if (arv) {
436                         arv->set_waveform_scale (scale);
437                 }
438         }
439 }
440
441 void
442 AudioStreamView::setup_rec_box ()
443 {
444         //cerr << _trackview.name() << " streamview SRB region_views.size() = " << region_views.size() << endl;
445
446         if (_trackview.session()->transport_rolling()) {
447
448                 // cerr << "\trolling\n";
449
450                 if (!rec_active &&
451                     _trackview.session()->record_status() == Session::Recording &&
452                     _trackview.get_diskstream()->record_enabled()) {
453                         if (_trackview.audio_track()->mode() == Normal && use_rec_regions && rec_regions.size() == rec_rects.size()) {
454
455                                 /* add a new region, but don't bother if they set use_rec_regions mid-record */
456
457                                 SourceList sources;
458
459                                 rec_data_ready_connections.drop_connections ();
460                                 boost::shared_ptr<AudioDiskstream> ads = _trackview.audio_track()->audio_diskstream();
461
462                                 for (uint32_t n=0; n < ads->n_channels().n_audio(); ++n) {
463                                         boost::shared_ptr<AudioFileSource> src = ads->write_source (n);
464                                         if (src) {
465                                                 sources.push_back (src);
466                                                 src->PeakRangeReady.connect (rec_data_ready_connections,
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.get_diskstream()->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->block_property_changes ();
492                                 region->set_position (_trackview.session()->transport_frame(), this);
493                                 rec_regions.push_back (make_pair(region, (RegionView*)0));
494                         }
495
496                         /* start a new rec box */
497
498                         boost::shared_ptr<AudioTrack> at;
499
500                         at = _trackview.audio_track(); /* we know what it is already */
501                         boost::shared_ptr<AudioDiskstream> ds = at->audio_diskstream();
502                         nframes_t frame_pos = ds->current_capture_start ();
503                         gdouble xstart = _trackview.editor().frame_to_pixel (frame_pos);
504                         gdouble xend;
505                         uint32_t fill_color;
506
507                         switch (_trackview.audio_track()->mode()) {
508                         case Normal:
509                         case NonLayered:
510                                 xend = xstart;
511                                 fill_color = ARDOUR_UI::config()->canvasvar_RecordingRect.get();
512                                 break;
513
514                         case Destructive:
515                                 xend = xstart + 2;
516                                 fill_color = ARDOUR_UI::config()->canvasvar_RecordingRect.get();
517                                 /* make the recording rect translucent to allow
518                                    the user to see the peak data coming in, etc.
519                                 */
520                                 fill_color = UINT_RGBA_CHANGE_A (fill_color, 120);
521                                 break;
522                         }
523
524                         ArdourCanvas::SimpleRect * rec_rect = new Gnome::Canvas::SimpleRect (*canvas_group);
525                         rec_rect->property_x1() = xstart;
526                         rec_rect->property_y1() = 1.0;
527                         rec_rect->property_x2() = xend;
528                         rec_rect->property_y2() = child_height ();
529                         rec_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeAxisFrame.get();
530                         rec_rect->property_outline_what() = 0x1 | 0x2 | 0x4 | 0x8;
531                         rec_rect->property_fill_color_rgba() = fill_color;
532                         rec_rect->lower_to_bottom();
533
534                         RecBoxInfo recbox;
535                         recbox.rectangle = rec_rect;
536                         recbox.start = _trackview.session()->transport_frame();
537                         recbox.length = 0;
538
539                         rec_rects.push_back (recbox);
540
541                         screen_update_connection.disconnect();
542                         screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect (
543                                         sigc::mem_fun (*this, &AudioStreamView::update_rec_box));
544                         rec_updating = true;
545                         rec_active = true;
546
547                 } else if (rec_active &&
548                            (_trackview.session()->record_status() != Session::Recording ||
549                             !_trackview.get_diskstream()->record_enabled())) {
550                         screen_update_connection.disconnect();
551                         rec_active = false;
552                         rec_updating = false;
553                 }
554
555         } else {
556
557                 // cerr << "\tNOT rolling, rec_rects = " << rec_rects.size() << " rec_regions = " << rec_regions.size() << endl;
558
559                 if (!rec_rects.empty() || !rec_regions.empty()) {
560
561                         /* disconnect rapid update */
562                         screen_update_connection.disconnect();
563                         rec_data_ready_connections.drop_connections ();
564                         rec_updating = false;
565                         rec_active = false;
566
567                         /* remove temp regions */
568
569                         for (list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator iter = rec_regions.begin(); iter != rec_regions.end(); ) {
570                                 list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator tmp;
571
572                                 tmp = iter;
573                                 ++tmp;
574
575                                 (*iter).first->drop_references ();
576
577                                 iter = tmp;
578                         }
579
580                         rec_regions.clear();
581
582                         // cerr << "\tclear " << rec_rects.size() << " rec rects\n";
583
584                         /* transport stopped, clear boxes */
585                         for (vector<RecBoxInfo>::iterator iter=rec_rects.begin(); iter != rec_rects.end(); ++iter) {
586                                 RecBoxInfo &rect = (*iter);
587                                 delete rect.rectangle;
588                         }
589
590                         rec_rects.clear();
591
592                 }
593         }
594 }
595
596 void
597 AudioStreamView::foreach_crossfadeview (void (CrossfadeView::*pmf)(void))
598 {
599         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
600                 (i->second->*pmf) ();
601         }
602 }
603
604 void
605 AudioStreamView::rec_peak_range_ready (nframes_t start, nframes_t cnt, boost::weak_ptr<Source> weak_src)
606 {
607         ENSURE_GUI_THREAD (*this, &AudioStreamView::rec_peak_range_ready, start, cnt, weak_src)
608
609         boost::shared_ptr<Source> src (weak_src.lock());
610
611         if (!src) {
612                 return;
613         }
614
615         // this is called from the peak building thread
616
617         if (rec_data_ready_map.size() == 0 || start + cnt > last_rec_data_frame) {
618                 last_rec_data_frame = start + cnt;
619         }
620
621         rec_data_ready_map[src] = true;
622
623         if (rec_data_ready_map.size() == _trackview.get_diskstream()->n_channels().n_audio()) {
624                 this->update_rec_regions ();
625                 rec_data_ready_map.clear();
626         }
627 }
628
629 void
630 AudioStreamView::update_rec_regions ()
631 {
632         if (use_rec_regions) {
633                 uint32_t n = 0;
634
635                 for (list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator iter = rec_regions.begin();
636                                 iter != rec_regions.end(); n++) {
637
638                         list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator tmp = iter;
639                         ++tmp;
640
641                         if (!canvas_item_visible (rec_rects[n].rectangle)) {
642                                 /* rect already hidden, this region is done */
643                                 iter = tmp;
644                                 continue;
645                         }
646
647                         boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion>(iter->first);
648                         if (!region) {
649                                 iter = tmp;
650                                 continue;
651                         }
652
653                         nframes_t origlen = region->length();
654
655                         if (region == rec_regions.back().first && rec_active) {
656
657                                 if (last_rec_data_frame > region->start()) {
658
659                                         nframes_t nlen = last_rec_data_frame - region->start();
660
661                                         if (nlen != region->length()) {
662
663                                                 region->suspend_property_changes ();
664                                                 region->set_position (_trackview.get_diskstream()->get_capture_start_frame(n), this);
665                                                 region->set_length (nlen, this);
666                                                 region->resume_property_changes ();
667
668                                                 if (origlen == 1) {
669                                                         /* our special initial length */
670                                                         add_region_view_internal (region, false, true);
671                                                 }
672
673                                                 /* also update rect */
674                                                 ArdourCanvas::SimpleRect * rect = rec_rects[n].rectangle;
675                                                 gdouble xend = _trackview.editor().frame_to_pixel (region->position() + region->length());
676                                                 rect->property_x2() = xend;
677                                         }
678                                 }
679
680                         } else {
681
682                                 nframes_t nlen = _trackview.get_diskstream()->get_captured_frames(n);
683
684                                 if (nlen != region->length()) {
685
686                                         if (region->source_length(0) >= region->start() + nlen) {
687
688                                                 region->suspend_property_changes ();
689                                                 region->set_position (_trackview.get_diskstream()->get_capture_start_frame(n), this);
690                                                 region->set_length (nlen, this);
691                                                 region->resume_property_changes ();
692
693                                                 if (origlen == 1) {
694                                                         /* our special initial length */
695                                                         add_region_view_internal (region, false, true);
696                                                 }
697
698                                                 /* also hide rect */
699                                                 ArdourCanvas::Item * rect = rec_rects[n].rectangle;
700                                                 rect->hide();
701
702                                         }
703                                 }
704                         }
705
706                         iter = tmp;
707                 }
708         }
709 }
710
711 void
712 AudioStreamView::show_all_fades ()
713 {
714         for (list<RegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
715                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
716                 if (arv) {
717                         arv->set_fade_visibility (true);
718                 }
719         }
720 }
721
722 void
723 AudioStreamView::hide_all_fades ()
724 {
725         for (list<RegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
726                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
727                 if (arv) {
728                         arv->set_fade_visibility (false);
729                 }
730         }
731 }
732
733 void
734 AudioStreamView::show_all_xfades ()
735 {
736         foreach_crossfadeview (&CrossfadeView::show);
737         crossfades_visible = true;
738 }
739
740 void
741 AudioStreamView::hide_all_xfades ()
742 {
743         foreach_crossfadeview (&CrossfadeView::hide);
744         crossfades_visible = false;
745 }
746
747 void
748 AudioStreamView::hide_xfades_involving (AudioRegionView& rv)
749 {
750         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
751                 if (i->second->crossfade->involves (rv.audio_region())) {
752                         i->second->fake_hide ();
753                 }
754         }
755 }
756
757 void
758 AudioStreamView::reveal_xfades_involving (AudioRegionView& rv)
759 {
760         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
761                 if (i->second->crossfade->involves (rv.audio_region()) && i->second->visible()) {
762                         i->second->show ();
763                 }
764         }
765 }
766
767 void
768 AudioStreamView::color_handler ()
769 {
770         //case cAudioTrackBase:
771         if (_trackview.is_track()) {
772                 canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_AudioTrackBase.get();
773         }
774
775         //case cAudioBusBase:
776         if (!_trackview.is_track()) {
777                 if (Profile->get_sae() && _trackview.route()->is_master()) {
778                         canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_AudioMasterBusBase.get();
779                 } else {
780                         canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_AudioBusBase.get();
781                 }
782         }
783 }
784
785 void
786 AudioStreamView::update_contents_height ()
787 {
788         StreamView::update_contents_height ();
789
790         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
791                 update_content_height (i->second);
792         }
793 }
794
795 void
796 AudioStreamView::update_content_height (CrossfadeView* cv)
797 {
798         cv->show ();
799
800         if (_layer_display == Overlaid) {
801
802                 cv->set_y (0);
803                 cv->set_height (height);
804
805         } else {
806
807                 layer_t const inl = cv->crossfade->in()->layer ();
808                 layer_t const outl = cv->crossfade->out()->layer ();
809
810                 layer_t const high = max (inl, outl);
811                 layer_t const low = min (inl, outl);
812
813                 const double h = child_height ();
814
815                 cv->set_y ((_layers - high - 1) * h);
816                 cv->set_height ((high - low + 1) * h);
817
818         }
819 }
820
821 void
822 AudioStreamView::parameter_changed (string const & p)
823 {
824         if (p == "show-waveforms") {
825                 set_show_waveforms (Config->get_show_waveforms ());
826         } else if (p == "waveform-scale") {
827                 set_waveform_scale (Config->get_waveform_scale ());
828         } else if (p == "waveform-shape") {
829                 set_waveform_shape (Config->get_waveform_shape ());
830         }
831 }