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