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