(1) remove almost-never used block/unlock_property_changes() methods from PBD::Statef...
[ardour.git] / gtk2_ardour / audio_streamview.cc
1 /*
2     Copyright (C) 2001, 2006 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <cmath>
20 #include <cassert>
21 #include <utility>
22
23 #include <gtkmm.h>
24
25 #include <gtkmm2ext/gtk_ui.h>
26
27 #include "pbd/stacktrace.h"
28
29 #include "ardour/audioplaylist.h"
30 #include "ardour/audioregion.h"
31 #include "ardour/audiofilesource.h"
32 #include "ardour/audio_track.h"
33 #include "ardour/source.h"
34 #include "ardour/region_factory.h"
35 #include "ardour/profile.h"
36 #include "ardour/rc_configuration.h"
37 #include "ardour/session.h"
38
39 #include "audio_streamview.h"
40 #include "audio_region_view.h"
41 #include "tape_region_view.h"
42 #include "audio_time_axis.h"
43 #include "canvas-waveview.h"
44 #include "canvas-simplerect.h"
45 #include "region_selection.h"
46 #include "selection.h"
47 #include "public_editor.h"
48 #include "ardour_ui.h"
49 #include "crossfade_view.h"
50 #include "rgb_macros.h"
51 #include "gui_thread.h"
52 #include "utils.h"
53
54 #include "i18n.h"
55
56 using namespace std;
57 using namespace ARDOUR;
58 using namespace PBD;
59 using namespace Editing;
60
61 AudioStreamView::AudioStreamView (AudioTimeAxisView& tv)
62         : StreamView (tv)
63 {
64         crossfades_visible = tv.session()->config.get_xfades_visible ();
65         color_handler ();
66         _amplitude_above_axis = 1.0;
67
68         Config->ParameterChanged.connect (*this, invalidator (*this), ui_bind (&AudioStreamView::parameter_changed, this, _1), gui_context());
69 }
70
71 AudioStreamView::~AudioStreamView ()
72 {
73 }
74
75 int
76 AudioStreamView::set_samples_per_unit (gdouble spp)
77 {
78         StreamView::set_samples_per_unit(spp);
79
80         for (CrossfadeViewList::iterator xi = crossfade_views.begin(); xi != crossfade_views.end(); ++xi) {
81                 xi->second->set_samples_per_unit (spp);
82         }
83
84         return 0;
85 }
86
87 int
88 AudioStreamView::set_amplitude_above_axis (gdouble app)
89 {
90         RegionViewList::iterator i;
91
92         if (app < 1.0) {
93                 return -1;
94         }
95
96         _amplitude_above_axis = app;
97
98         for (i = region_views.begin(); i != region_views.end(); ++i) {
99                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
100                 if (arv)
101                         arv->set_amplitude_above_axis (app);
102         }
103
104         return 0;
105 }
106
107 RegionView*
108 AudioStreamView::create_region_view (boost::shared_ptr<Region> r, bool wait_for_waves, bool recording)
109 {
110         AudioRegionView *region_view = 0;
111         boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (r);
112
113         if (region == 0) {
114                 return 0;
115         }
116
117         switch (_trackview.audio_track()->mode()) {
118
119         case NonLayered:
120         case Normal:
121                 if (recording) {
122                         region_view = new AudioRegionView (_canvas_group, _trackview, region,
123                                         _samples_per_unit, region_color, recording, TimeAxisViewItem::Visibility(
124                                                         TimeAxisViewItem::ShowFrame | 
125                                                         TimeAxisViewItem::HideFrameRight |
126                                                         TimeAxisViewItem::HideFrameLeft |
127                                                         TimeAxisViewItem::HideFrameTB));
128                 } else {
129                         region_view = new AudioRegionView (_canvas_group, _trackview, region,
130                                         _samples_per_unit, region_color);
131                 }
132                 break;
133         case Destructive:
134                 region_view = new TapeAudioRegionView (_canvas_group, _trackview, region,
135                                 _samples_per_unit, region_color);
136                 break;
137         default:
138                 fatal << string_compose (_("programming error: %1"), "illegal track mode in ::add_region_view_internal") << endmsg;
139                 /*NOTREACHED*/
140
141         }
142
143         region_view->init (region_color, wait_for_waves);
144         region_view->set_amplitude_above_axis(_amplitude_above_axis);
145         region_view->set_height (child_height ());
146
147         /* if its the special single-sample length that we use for rec-regions, make it
148            insensitive to events
149         */
150
151         if (region->length() == 1) {
152                 region_view->set_sensitive (false);
153         }
154
155         region_view->set_waveform_scale (Config->get_waveform_scale ());
156         region_view->set_waveform_shape (Config->get_waveform_shape ());
157         region_view->set_waveform_visible (Config->get_show_waveforms ());
158
159         return region_view;
160 }
161
162 RegionView*
163 AudioStreamView::add_region_view_internal (boost::shared_ptr<Region> r, bool wait_for_waves, bool recording)
164 {
165         RegionView *region_view = create_region_view (r, wait_for_waves, recording);
166         
167         if (region_view == 0) {
168                 return 0;
169         }
170
171 //      if(!recording){
172 //              for (list<RegionView *>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
173 //                      if ((*i)->region() == r) {
174 //                              cerr << "audio_streamview in add_region_view_internal region found" << endl;
175                                 /* great. we already have a AudioRegionView for this Region. use it again. */
176
177 //                              (*i)->set_valid (true);
178
179                                 // this might not be necessary
180 //                              AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
181
182 //                              if (arv) {
183 //                                      arv->set_waveform_scale (_waveform_scale);
184 //                                      arv->set_waveform_shape (_waveform_shape);
185 //                              }
186
187 //                              return NULL;
188 //                      }
189 //              }
190 //      }
191
192         region_views.push_front (region_view);
193
194         /* catch region going away */
195
196         r->DropReferences.connect (*this, invalidator (*this), boost::bind (&AudioStreamView::remove_region_view, this, boost::weak_ptr<Region> (r)), gui_context());
197
198         RegionViewAdded (region_view);
199
200         return region_view;
201 }
202
203 void
204 AudioStreamView::remove_region_view (boost::weak_ptr<Region> weak_r)
205 {
206         ENSURE_GUI_THREAD (*this, &AudioStreamView::remove_region_view, weak_r);
207
208         boost::shared_ptr<Region> r (weak_r.lock());
209
210         if (!r) {
211                 return;
212         }
213
214         if (!_trackview.session()->deletion_in_progress()) {
215
216                 for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end();) {
217                         CrossfadeViewList::iterator tmp;
218
219                         tmp = i;
220                         ++tmp;
221
222                         boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion>(r);
223                         if (ar && i->second->crossfade->involves (ar)) {
224                                 delete i->second;
225                                 crossfade_views.erase (i);
226                         }
227
228                         i = tmp;
229                 }
230         }
231
232         StreamView::remove_region_view(r);
233 }
234
235 void
236 AudioStreamView::undisplay_track ()
237 {
238         StreamView::undisplay_track ();
239
240         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
241                 delete i->second;
242         }
243
244         crossfade_views.clear ();
245 }
246
247 void
248 AudioStreamView::playlist_layered (boost::weak_ptr<Track> wtr)
249 {
250         boost::shared_ptr<Track> tr (wtr.lock());
251
252         if (!tr) {
253                 return;
254         }
255
256         StreamView::playlist_layered (wtr);
257
258         /* make sure xfades are on top and all the regionviews are stacked correctly. */
259
260         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
261                 i->second->get_canvas_group()->raise_to_top();
262         }
263 }
264
265 void
266 AudioStreamView::playlist_switched (boost::weak_ptr<Track> wtr)
267 {
268         boost::shared_ptr<Track> tr (wtr.lock());
269
270         if (!tr) {
271                 return;
272         }
273
274         playlist_connections.drop_connections ();
275
276         StreamView::playlist_switched (tr);
277
278         boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist> (tr->playlist());
279
280         if (apl) {
281                 apl->NewCrossfade.connect (playlist_connections, invalidator (*this), ui_bind (&AudioStreamView::add_crossfade, this, _1), gui_context());
282         }
283 }
284
285 void
286 AudioStreamView::add_crossfade (boost::weak_ptr<Crossfade> wc)
287 {
288         boost::shared_ptr<Crossfade> crossfade (wc.lock());
289
290         if (!crossfade) {
291                 return;
292         }
293
294         AudioRegionView* lview = 0;
295         AudioRegionView* rview = 0;
296
297         /* first see if we already have a CrossfadeView for this Crossfade */
298
299         CrossfadeViewList::iterator i = crossfade_views.find (crossfade);
300         if (i != crossfade_views.end()) {
301                 if (!crossfades_visible) {
302                         i->second->hide();
303                 } else {
304                         i->second->show ();
305                 }
306                 i->second->set_valid (true);
307                 return;
308         }
309
310         /* create a new one */
311
312         for (list<RegionView *>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
313                 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(*i);
314
315                 if (!lview && arv && (arv->region() == crossfade->out())) {
316                         lview = arv;
317                 }
318                 if (!rview && arv && (arv->region() == crossfade->in())) {
319                         rview = arv;
320                 }
321         }
322
323         CrossfadeView *cv = new CrossfadeView (_trackview.canvas_display (),
324                                                _trackview,
325                                                 crossfade,
326                                                _samples_per_unit,
327                                                region_color,
328                                                *lview, *rview);
329         cv->set_valid (true);
330         crossfade->Invalidated.connect (*this, invalidator (*this), ui_bind (&AudioStreamView::remove_crossfade, this, _1), gui_context());
331         crossfade_views[cv->crossfade] = cv;
332         if (!crossfades_visible) {
333                 cv->hide ();
334         }
335
336         update_content_height (cv);
337 }
338
339 void
340 AudioStreamView::remove_crossfade (boost::shared_ptr<Region> r)
341 {
342         ENSURE_GUI_THREAD (*this, &AudioStreamView::remove_crossfade, r)
343
344         boost::shared_ptr<Crossfade> xfade = boost::dynamic_pointer_cast<Crossfade> (r);
345
346         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
347                 if (i->second->crossfade == xfade) {
348                         delete i->second;
349                         crossfade_views.erase (i);
350                         break;
351                 }
352         }
353 }
354
355 void
356 AudioStreamView::redisplay_track ()
357 {
358         list<RegionView *>::iterator i;
359         CrossfadeViewList::iterator xi, tmpx;
360
361         // Flag region views as invalid and disable drawing
362         for (i = region_views.begin(); i != region_views.end(); ++i) {
363                 (*i)->set_valid (false);
364                 (*i)->enable_display (false);
365         }
366
367         // Flag crossfade views as invalid
368         for (xi = crossfade_views.begin(); xi != crossfade_views.end(); ++xi) {
369                 xi->second->set_valid (false);
370                 if (xi->second->visible()) {
371                         xi->second->show ();
372                 }
373         }
374
375         // Add and display region and crossfade views, and flag them as valid
376
377         if (_trackview.is_audio_track()) {
378                 _trackview.track()->playlist()->foreach_region(
379                         sigc::hide_return (sigc::mem_fun (*this, &StreamView::add_region_view))
380                         );
381
382                 boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist>(
383                                 _trackview.track()->playlist()
384                         );
385
386                 if (apl) {
387                         apl->foreach_crossfade (sigc::mem_fun (*this, &AudioStreamView::add_crossfade));
388                 }
389         }
390
391         // Remove invalid crossfade views
392         for (xi = crossfade_views.begin(); xi != crossfade_views.end();) {
393                 tmpx = xi;
394                 tmpx++;
395
396                 if (!xi->second->valid()) {
397                         delete xi->second;
398                         crossfade_views.erase (xi);
399                 }
400
401                 xi = tmpx;
402         }
403
404         // Stack regions by layer, and remove invalid regions
405         layer_regions();
406 }
407
408 void
409 AudioStreamView::set_show_waveforms (bool yn)
410 {
411         for (list<RegionView *>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
412                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
413                 if (arv) {
414                         arv->set_waveform_visible (yn);
415                 }
416         }
417 }
418
419 void
420 AudioStreamView::set_waveform_shape (WaveformShape shape)
421 {
422         for (RegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) {
423                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
424                 if (arv)
425                         arv->set_waveform_shape (shape);
426         }
427 }
428
429 void
430 AudioStreamView::set_waveform_scale (WaveformScale scale)
431 {
432         for (RegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) {
433                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
434                 if (arv) {
435                         arv->set_waveform_scale (scale);
436                 }
437         }
438 }
439
440 void
441 AudioStreamView::setup_rec_box ()
442 {
443         //cerr << _trackview.name() << " streamview SRB region_views.size() = " << region_views.size() << endl;
444
445         if (_trackview.session()->transport_rolling()) {
446
447                 // cerr << "\trolling\n";
448
449                 if (!rec_active &&
450                     _trackview.session()->record_status() == Session::Recording &&
451                     _trackview.track()->record_enabled()) {
452                         if (_trackview.audio_track()->mode() == Normal && Config->get_show_waveforms_while_recording() && rec_regions.size() == rec_rects.size()) {
453
454                                 /* add a new region, but don't bother if they set show-waveforms-while-recording mid-record */
455
456                                 SourceList sources;
457
458                                 rec_data_ready_connections.drop_connections ();
459                                 boost::shared_ptr<AudioTrack> tr = _trackview.audio_track();
460
461                                 for (uint32_t n = 0; n < tr->n_channels().n_audio(); ++n) {
462                                         boost::shared_ptr<AudioFileSource> src = tr->write_source (n);
463                                         if (src) {
464                                                 sources.push_back (src);
465                                                 src->PeakRangeReady.connect (rec_data_ready_connections,
466                                                                              invalidator (*this),
467                                                                              ui_bind (&AudioStreamView::rec_peak_range_ready, this, _1, _2, boost::weak_ptr<Source>(src)),
468                                                                              gui_context());
469                                         }
470                                 }
471
472                                 // handle multi
473
474                                 nframes_t start = 0;
475                                 if (rec_regions.size() > 0) {
476                                         start = rec_regions.back().first->start()
477                                                         + _trackview.track()->get_captured_frames(rec_regions.size()-1);
478                                 }
479
480                                 PropertyList plist; 
481                                 
482                                 plist.add (Properties::start, start);
483                                 plist.add (Properties::length, 1);
484                                 plist.add (Properties::name, string());
485                                 plist.add (Properties::layer, 0);
486
487                                 boost::shared_ptr<AudioRegion> region (
488                                         boost::dynamic_pointer_cast<AudioRegion>(RegionFactory::create (sources, plist, false)));
489
490                                 assert(region);
491                                 region->suspend_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                         nframes_t frame_pos = at->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_what() = 0x0;
529                         rec_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeAxisFrame.get();
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.track()->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.track()->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 (Config->get_show_waveforms_while_recording ()) {
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                         
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.track()->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.track()->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.track()->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         if (_layer_display == Overlaid) {
799
800                 cv->set_y (0);
801                 cv->set_height (height);
802
803         } else {
804
805                 layer_t const inl = cv->crossfade->in()->layer ();
806                 layer_t const outl = cv->crossfade->out()->layer ();
807
808                 layer_t const high = max (inl, outl);
809                 layer_t const low = min (inl, outl);
810
811                 const double h = child_height ();
812
813                 cv->set_y ((_layers - high - 1) * h);
814                 cv->set_height ((high - low + 1) * h);
815
816         }
817 }
818
819 void
820 AudioStreamView::parameter_changed (string const & p)
821 {
822         if (p == "show-waveforms") {
823                 set_show_waveforms (Config->get_show_waveforms ());
824         } else if (p == "waveform-scale") {
825                 set_waveform_scale (Config->get_waveform_scale ());
826         } else if (p == "waveform-shape") {
827                 set_waveform_shape (Config->get_waveform_shape ());
828         }
829 }