the Properties & 64bit region commit
[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                                 PropertyList plist; 
487                                 
488                                 plist.add (Properties::start, start);
489                                 plist.add (Properties::length, 1);
490                                 plist.add (Properties::name, string());
491                                 plist.add (Properties::layer, 0);
492
493                                 boost::shared_ptr<AudioRegion> region (
494                                         boost::dynamic_pointer_cast<AudioRegion>(RegionFactory::create (sources, plist, false)));
495
496                                 assert(region);
497                                 region->block_property_changes ();
498                                 region->set_position (_trackview.session()->transport_frame(), this);
499                                 rec_regions.push_back (make_pair(region, (RegionView*)0));
500                         }
501
502                         /* start a new rec box */
503
504                         boost::shared_ptr<AudioTrack> at;
505
506                         at = _trackview.audio_track(); /* we know what it is already */
507                         boost::shared_ptr<AudioDiskstream> ds = at->audio_diskstream();
508                         nframes_t frame_pos = ds->current_capture_start ();
509                         gdouble xstart = _trackview.editor().frame_to_pixel (frame_pos);
510                         gdouble xend;
511                         uint32_t fill_color;
512
513                         switch (_trackview.audio_track()->mode()) {
514                         case Normal:
515                         case NonLayered:
516                                 xend = xstart;
517                                 fill_color = ARDOUR_UI::config()->canvasvar_RecordingRect.get();
518                                 break;
519
520                         case Destructive:
521                                 xend = xstart + 2;
522                                 fill_color = ARDOUR_UI::config()->canvasvar_RecordingRect.get();
523                                 /* make the recording rect translucent to allow
524                                    the user to see the peak data coming in, etc.
525                                 */
526                                 fill_color = UINT_RGBA_CHANGE_A (fill_color, 120);
527                                 break;
528                         }
529
530                         ArdourCanvas::SimpleRect * rec_rect = new Gnome::Canvas::SimpleRect (*canvas_group);
531                         rec_rect->property_x1() = xstart;
532                         rec_rect->property_y1() = 1.0;
533                         rec_rect->property_x2() = xend;
534                         rec_rect->property_y2() = child_height ();
535                         rec_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeAxisFrame.get();
536                         rec_rect->property_outline_what() = 0x1 | 0x2 | 0x4 | 0x8;
537                         rec_rect->property_fill_color_rgba() = fill_color;
538                         rec_rect->lower_to_bottom();
539
540                         RecBoxInfo recbox;
541                         recbox.rectangle = rec_rect;
542                         recbox.start = _trackview.session()->transport_frame();
543                         recbox.length = 0;
544
545                         rec_rects.push_back (recbox);
546
547                         screen_update_connection.disconnect();
548                         screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect (
549                                         sigc::mem_fun (*this, &AudioStreamView::update_rec_box));
550                         rec_updating = true;
551                         rec_active = true;
552
553                 } else if (rec_active &&
554                            (_trackview.session()->record_status() != Session::Recording ||
555                             !_trackview.get_diskstream()->record_enabled())) {
556                         screen_update_connection.disconnect();
557                         rec_active = false;
558                         rec_updating = false;
559                 }
560
561         } else {
562
563                 // cerr << "\tNOT rolling, rec_rects = " << rec_rects.size() << " rec_regions = " << rec_regions.size() << endl;
564
565                 if (!rec_rects.empty() || !rec_regions.empty()) {
566
567                         /* disconnect rapid update */
568                         screen_update_connection.disconnect();
569                         rec_data_ready_connections.drop_connections ();
570                         rec_updating = false;
571                         rec_active = false;
572
573                         /* remove temp regions */
574
575                         for (list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator iter = rec_regions.begin(); iter != rec_regions.end(); ) {
576                                 list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator tmp;
577
578                                 tmp = iter;
579                                 ++tmp;
580
581                                 (*iter).first->drop_references ();
582
583                                 iter = tmp;
584                         }
585
586                         rec_regions.clear();
587
588                         // cerr << "\tclear " << rec_rects.size() << " rec rects\n";
589
590                         /* transport stopped, clear boxes */
591                         for (vector<RecBoxInfo>::iterator iter=rec_rects.begin(); iter != rec_rects.end(); ++iter) {
592                                 RecBoxInfo &rect = (*iter);
593                                 delete rect.rectangle;
594                         }
595
596                         rec_rects.clear();
597
598                 }
599         }
600 }
601
602 void
603 AudioStreamView::foreach_crossfadeview (void (CrossfadeView::*pmf)(void))
604 {
605         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
606                 (i->second->*pmf) ();
607         }
608 }
609
610 void
611 AudioStreamView::rec_peak_range_ready (nframes_t start, nframes_t cnt, boost::weak_ptr<Source> weak_src)
612 {
613         ENSURE_GUI_THREAD (*this, &AudioStreamView::rec_peak_range_ready, start, cnt, weak_src)
614
615         boost::shared_ptr<Source> src (weak_src.lock());
616
617         if (!src) {
618                 return;
619         }
620
621         // this is called from the peak building thread
622
623         if (rec_data_ready_map.size() == 0 || start + cnt > last_rec_data_frame) {
624                 last_rec_data_frame = start + cnt;
625         }
626
627         rec_data_ready_map[src] = true;
628
629         if (rec_data_ready_map.size() == _trackview.get_diskstream()->n_channels().n_audio()) {
630                 this->update_rec_regions ();
631                 rec_data_ready_map.clear();
632         }
633 }
634
635 void
636 AudioStreamView::update_rec_regions ()
637 {
638         if (use_rec_regions) {
639                 uint32_t n = 0;
640
641                 for (list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator iter = rec_regions.begin();
642                                 iter != rec_regions.end(); n++) {
643
644                         list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator tmp = iter;
645                         ++tmp;
646
647                         if (!canvas_item_visible (rec_rects[n].rectangle)) {
648                                 /* rect already hidden, this region is done */
649                                 iter = tmp;
650                                 continue;
651                         }
652
653                         boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion>(iter->first);
654                         if (!region) {
655                                 iter = tmp;
656                                 continue;
657                         }
658
659                         nframes_t origlen = region->length();
660
661                         if (region == rec_regions.back().first && rec_active) {
662
663                                 if (last_rec_data_frame > region->start()) {
664
665                                         nframes_t nlen = last_rec_data_frame - region->start();
666
667                                         if (nlen != region->length()) {
668
669                                                 region->freeze ();
670                                                 region->set_position (_trackview.get_diskstream()->get_capture_start_frame(n), this);
671                                                 region->set_length (nlen, this);
672                                                 region->thaw ();
673
674                                                 if (origlen == 1) {
675                                                         /* our special initial length */
676                                                         add_region_view_internal (region, false, true);
677                                                 }
678
679                                                 /* also update rect */
680                                                 ArdourCanvas::SimpleRect * rect = rec_rects[n].rectangle;
681                                                 gdouble xend = _trackview.editor().frame_to_pixel (region->position() + region->length());
682                                                 rect->property_x2() = xend;
683                                         }
684                                 }
685
686                         } else {
687
688                                 nframes_t nlen = _trackview.get_diskstream()->get_captured_frames(n);
689
690                                 if (nlen != region->length()) {
691
692                                         if (region->source_length(0) >= region->start() + nlen) {
693
694                                                 region->freeze ();
695                                                 region->set_position (_trackview.get_diskstream()->get_capture_start_frame(n), this);
696                                                 region->set_length (nlen, this);
697                                                 region->thaw ();
698
699                                                 if (origlen == 1) {
700                                                         /* our special initial length */
701                                                         add_region_view_internal (region, false, true);
702                                                 }
703
704                                                 /* also hide rect */
705                                                 ArdourCanvas::Item * rect = rec_rects[n].rectangle;
706                                                 rect->hide();
707
708                                         }
709                                 }
710                         }
711
712                         iter = tmp;
713                 }
714         }
715 }
716
717 void
718 AudioStreamView::show_all_fades ()
719 {
720         for (list<RegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
721                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
722                 if (arv) {
723                         arv->set_fade_visibility (true);
724                 }
725         }
726 }
727
728 void
729 AudioStreamView::hide_all_fades ()
730 {
731         for (list<RegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
732                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
733                 if (arv) {
734                         arv->set_fade_visibility (false);
735                 }
736         }
737 }
738
739 void
740 AudioStreamView::show_all_xfades ()
741 {
742         foreach_crossfadeview (&CrossfadeView::show);
743         crossfades_visible = true;
744 }
745
746 void
747 AudioStreamView::hide_all_xfades ()
748 {
749         foreach_crossfadeview (&CrossfadeView::hide);
750         crossfades_visible = false;
751 }
752
753 void
754 AudioStreamView::hide_xfades_involving (AudioRegionView& rv)
755 {
756         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
757                 if (i->second->crossfade->involves (rv.audio_region())) {
758                         i->second->fake_hide ();
759                 }
760         }
761 }
762
763 void
764 AudioStreamView::reveal_xfades_involving (AudioRegionView& rv)
765 {
766         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
767                 if (i->second->crossfade->involves (rv.audio_region()) && i->second->visible()) {
768                         i->second->show ();
769                 }
770         }
771 }
772
773 void
774 AudioStreamView::color_handler ()
775 {
776         //case cAudioTrackBase:
777         if (_trackview.is_track()) {
778                 canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_AudioTrackBase.get();
779         }
780
781         //case cAudioBusBase:
782         if (!_trackview.is_track()) {
783                 if (Profile->get_sae() && _trackview.route()->is_master()) {
784                         canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_AudioMasterBusBase.get();
785                 } else {
786                         canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_AudioBusBase.get();
787                 }
788         }
789 }
790
791 void
792 AudioStreamView::update_contents_height ()
793 {
794         StreamView::update_contents_height ();
795
796         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
797                 update_content_height (i->second);
798         }
799 }
800
801 void
802 AudioStreamView::update_content_height (CrossfadeView* cv)
803 {
804         cv->show ();
805
806         if (_layer_display == Overlaid) {
807
808                 cv->set_y (0);
809                 cv->set_height (height);
810
811         } else {
812
813                 layer_t const inl = cv->crossfade->in()->layer ();
814                 layer_t const outl = cv->crossfade->out()->layer ();
815
816                 layer_t const high = max (inl, outl);
817                 layer_t const low = min (inl, outl);
818
819                 const double h = child_height ();
820
821                 cv->set_y ((_layers - high - 1) * h);
822                 cv->set_height ((high - low + 1) * h);
823
824         }
825 }
826
827 void
828 AudioStreamView::parameter_changed (string const & p)
829 {
830         if (p == "show-waveforms") {
831                 set_show_waveforms (Config->get_show_waveforms ());
832         } else if (p == "waveform-scale") {
833                 set_waveform_scale (Config->get_waveform_scale ());
834         } else if (p == "waveform-shape") {
835                 set_waveform_shape (Config->get_waveform_shape ());
836         }
837 }