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