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