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