cleanup up cleanup at session destruction; clarify the meaning of 3 signals (DropRefe...
[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, ui_bind (&AudioStreamView::parameter_changed, this, _1), gui_context());
70 }
71
72 AudioStreamView::~AudioStreamView ()
73 {
74 }
75
76 int
77 AudioStreamView::set_samples_per_unit (gdouble spp)
78 {
79         StreamView::set_samples_per_unit(spp);
80
81         for (CrossfadeViewList::iterator xi = crossfade_views.begin(); xi != crossfade_views.end(); ++xi) {
82                 xi->second->set_samples_per_unit (spp);
83         }
84
85         return 0;
86 }
87
88 int
89 AudioStreamView::set_amplitude_above_axis (gdouble app)
90 {
91         RegionViewList::iterator i;
92
93         if (app < 1.0) {
94                 return -1;
95         }
96
97         _amplitude_above_axis = app;
98
99         for (i = region_views.begin(); i != region_views.end(); ++i) {
100                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
101                 if (arv)
102                         arv->set_amplitude_above_axis (app);
103         }
104
105         return 0;
106 }
107
108 RegionView*
109 AudioStreamView::create_region_view (boost::shared_ptr<Region> r, bool wait_for_waves, bool recording)
110 {
111         AudioRegionView *region_view = 0;
112         boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (r);
113
114         if (region == 0) {
115                 return 0;
116         }
117
118         switch (_trackview.audio_track()->mode()) {
119
120         case NonLayered:
121         case Normal:
122                 if (recording) {
123                         region_view = new AudioRegionView (canvas_group, _trackview, region,
124                                         _samples_per_unit, region_color, recording, TimeAxisViewItem::Visibility(
125                                                         TimeAxisViewItem::ShowFrame | TimeAxisViewItem::HideFrameRight));
126                 } else {
127                         region_view = new AudioRegionView (canvas_group, _trackview, region,
128                                         _samples_per_unit, region_color);
129                 }
130                 break;
131         case Destructive:
132                 region_view = new TapeAudioRegionView (canvas_group, _trackview, region,
133                                 _samples_per_unit, region_color);
134                 break;
135         default:
136                 fatal << string_compose (_("programming error: %1"), "illegal track mode in ::add_region_view_internal") << endmsg;
137                 /*NOTREACHED*/
138
139         }
140
141         region_view->init (region_color, wait_for_waves);
142         region_view->set_amplitude_above_axis(_amplitude_above_axis);
143         region_view->set_height (child_height ());
144
145         /* if its the special single-sample length that we use for rec-regions, make it
146            insensitive to events
147         */
148
149         if (region->length() == 1) {
150                 region_view->set_sensitive (false);
151         }
152
153         region_view->set_waveform_scale (Config->get_waveform_scale ());
154         region_view->set_waveform_shape (Config->get_waveform_shape ());
155         region_view->set_waveform_visible (Config->get_show_waveforms ());
156
157         return region_view;
158 }
159
160 RegionView*
161 AudioStreamView::add_region_view_internal (boost::shared_ptr<Region> r, bool wait_for_waves, bool recording)
162 {
163         RegionView *region_view = create_region_view (r, wait_for_waves, recording);
164         if (region_view == 0) {
165                 return 0;
166         }
167
168 //      if(!recording){
169 //              for (list<RegionView *>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
170 //                      if ((*i)->region() == r) {
171 //                              cerr << "audio_streamview in add_region_view_internal region found" << endl;
172                                 /* great. we already have a AudioRegionView for this Region. use it again. */
173
174 //                              (*i)->set_valid (true);
175
176                                 // this might not be necessary
177 //                              AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
178
179 //                              if (arv) {
180 //                                      arv->set_waveform_scale (_waveform_scale);
181 //                                      arv->set_waveform_shape (_waveform_shape);
182 //                              }
183
184 //                              return NULL;
185 //                      }
186 //              }
187 //      }
188
189         region_views.push_front (region_view);
190
191         /* catch region going away */
192
193         r->DropReferences.connect (*this, boost::bind (&AudioStreamView::remove_region_view, this, boost::weak_ptr<Region> (r)), gui_context());
194
195         RegionViewAdded (region_view);
196
197         return region_view;
198 }
199
200 void
201 AudioStreamView::remove_region_view (boost::weak_ptr<Region> weak_r)
202 {
203         ENSURE_GUI_THREAD (*this, &AudioStreamView::remove_region_view, weak_r);
204
205         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, ui_bind (&AudioStreamView::add_crossfade, this, _1), gui_context());
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, ui_bind (&AudioStreamView::remove_crossfade, this, _1), gui_context());
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                                                 src->PeakRangeReady.connect (rec_data_ready_connections,
486                                                                              ui_bind (&AudioStreamView::rec_peak_range_ready, this, _1, _2, boost::weak_ptr<Source>(src)),
487                                                                              gui_context());
488                                         }
489                                 }
490
491                                 // handle multi
492
493                                 nframes_t start = 0;
494                                 if (rec_regions.size() > 0) {
495                                         start = rec_regions.back().first->start()
496                                                         + _trackview.get_diskstream()->get_captured_frames(rec_regions.size()-1);
497                                 }
498
499                                 boost::shared_ptr<AudioRegion> region (boost::dynamic_pointer_cast<AudioRegion>(
500                                                 RegionFactory::create (sources, start, 1, "", 0, Region::DefaultFlags, false)));
501                                 assert(region);
502                                 region->block_property_changes ();
503                                 region->set_position (_trackview.session()->transport_frame(), this);
504                                 rec_regions.push_back (make_pair(region, (RegionView*)0));
505                         }
506
507                         /* start a new rec box */
508
509                         boost::shared_ptr<AudioTrack> at;
510
511                         at = _trackview.audio_track(); /* we know what it is already */
512                         boost::shared_ptr<AudioDiskstream> ds = at->audio_diskstream();
513                         nframes_t frame_pos = ds->current_capture_start ();
514                         gdouble xstart = _trackview.editor().frame_to_pixel (frame_pos);
515                         gdouble xend;
516                         uint32_t fill_color;
517
518                         switch (_trackview.audio_track()->mode()) {
519                         case Normal:
520                         case NonLayered:
521                                 xend = xstart;
522                                 fill_color = ARDOUR_UI::config()->canvasvar_RecordingRect.get();
523                                 break;
524
525                         case Destructive:
526                                 xend = xstart + 2;
527                                 fill_color = ARDOUR_UI::config()->canvasvar_RecordingRect.get();
528                                 /* make the recording rect translucent to allow
529                                    the user to see the peak data coming in, etc.
530                                 */
531                                 fill_color = UINT_RGBA_CHANGE_A (fill_color, 120);
532                                 break;
533                         }
534
535                         ArdourCanvas::SimpleRect * rec_rect = new Gnome::Canvas::SimpleRect (*canvas_group);
536                         rec_rect->property_x1() = xstart;
537                         rec_rect->property_y1() = 1.0;
538                         rec_rect->property_x2() = xend;
539                         rec_rect->property_y2() = child_height ();
540                         rec_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeAxisFrame.get();
541                         rec_rect->property_outline_what() = 0x1 | 0x2 | 0x4 | 0x8;
542                         rec_rect->property_fill_color_rgba() = fill_color;
543                         rec_rect->lower_to_bottom();
544
545                         RecBoxInfo recbox;
546                         recbox.rectangle = rec_rect;
547                         recbox.start = _trackview.session()->transport_frame();
548                         recbox.length = 0;
549
550                         rec_rects.push_back (recbox);
551
552                         screen_update_connection.disconnect();
553                         screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect (
554                                         sigc::mem_fun (*this, &AudioStreamView::update_rec_box));
555                         rec_updating = true;
556                         rec_active = true;
557
558                 } else if (rec_active &&
559                            (_trackview.session()->record_status() != Session::Recording ||
560                             !_trackview.get_diskstream()->record_enabled())) {
561                         screen_update_connection.disconnect();
562                         rec_active = false;
563                         rec_updating = false;
564                 }
565
566         } else {
567
568                 // cerr << "\tNOT rolling, rec_rects = " << rec_rects.size() << " rec_regions = " << rec_regions.size() << endl;
569
570                 if (!rec_rects.empty() || !rec_regions.empty()) {
571
572                         /* disconnect rapid update */
573                         screen_update_connection.disconnect();
574                         rec_data_ready_connections.drop_connections ();
575                         rec_updating = false;
576                         rec_active = false;
577
578                         /* remove temp regions */
579
580                         for (list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator iter = rec_regions.begin(); iter != rec_regions.end(); ) {
581                                 list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator tmp;
582
583                                 tmp = iter;
584                                 ++tmp;
585
586                                 (*iter).first->drop_references ();
587
588                                 iter = tmp;
589                         }
590
591                         rec_regions.clear();
592
593                         // cerr << "\tclear " << rec_rects.size() << " rec rects\n";
594
595                         /* transport stopped, clear boxes */
596                         for (vector<RecBoxInfo>::iterator iter=rec_rects.begin(); iter != rec_rects.end(); ++iter) {
597                                 RecBoxInfo &rect = (*iter);
598                                 delete rect.rectangle;
599                         }
600
601                         rec_rects.clear();
602
603                 }
604         }
605 }
606
607 void
608 AudioStreamView::foreach_crossfadeview (void (CrossfadeView::*pmf)(void))
609 {
610         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
611                 (i->second->*pmf) ();
612         }
613 }
614
615 void
616 AudioStreamView::rec_peak_range_ready (nframes_t start, nframes_t cnt, boost::weak_ptr<Source> weak_src)
617 {
618         ENSURE_GUI_THREAD (*this, &AudioStreamView::rec_peak_range_ready, start, cnt, weak_src)
619
620         boost::shared_ptr<Source> src (weak_src.lock());
621
622         if (!src) {
623                 return;
624         }
625
626         // this is called from the peak building thread
627
628         if (rec_data_ready_map.size() == 0 || start + cnt > last_rec_data_frame) {
629                 last_rec_data_frame = start + cnt;
630         }
631
632         rec_data_ready_map[src] = true;
633
634         if (rec_data_ready_map.size() == _trackview.get_diskstream()->n_channels().n_audio()) {
635                 this->update_rec_regions ();
636                 rec_data_ready_map.clear();
637         }
638 }
639
640 void
641 AudioStreamView::update_rec_regions ()
642 {
643         if (use_rec_regions) {
644                 uint32_t n = 0;
645
646                 for (list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator iter = rec_regions.begin();
647                                 iter != rec_regions.end(); n++) {
648
649                         list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator tmp = iter;
650                         ++tmp;
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                         if (!region) {
660                                 iter = tmp;
661                                 continue;
662                         }
663
664                         nframes_t origlen = region->length();
665
666                         if (region == rec_regions.back().first && rec_active) {
667
668                                 if (last_rec_data_frame > region->start()) {
669
670                                         nframes_t nlen = last_rec_data_frame - region->start();
671
672                                         if (nlen != region->length()) {
673
674                                                 region->freeze ();
675                                                 region->set_position (_trackview.get_diskstream()->get_capture_start_frame(n), this);
676                                                 region->set_length (nlen, this);
677                                                 region->thaw ("updated");
678
679                                                 if (origlen == 1) {
680                                                         /* our special initial length */
681                                                         add_region_view_internal (region, false, true);
682                                                 }
683
684                                                 /* also update rect */
685                                                 ArdourCanvas::SimpleRect * rect = rec_rects[n].rectangle;
686                                                 gdouble xend = _trackview.editor().frame_to_pixel (region->position() + region->length());
687                                                 rect->property_x2() = xend;
688                                         }
689                                 }
690
691                         } else {
692
693                                 nframes_t nlen = _trackview.get_diskstream()->get_captured_frames(n);
694
695                                 if (nlen != region->length()) {
696
697                                         if (region->source_length(0) >= region->start() + nlen) {
698
699                                                 region->freeze ();
700                                                 region->set_position (_trackview.get_diskstream()->get_capture_start_frame(n), this);
701                                                 region->set_length (nlen, this);
702                                                 region->thaw ("updated");
703
704                                                 if (origlen == 1) {
705                                                         /* our special initial length */
706                                                         add_region_view_internal (region, false, true);
707                                                 }
708
709                                                 /* also hide rect */
710                                                 ArdourCanvas::Item * rect = rec_rects[n].rectangle;
711                                                 rect->hide();
712
713                                         }
714                                 }
715                         }
716
717                         iter = tmp;
718                 }
719         }
720 }
721
722 void
723 AudioStreamView::show_all_fades ()
724 {
725         for (list<RegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
726                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
727                 if (arv) {
728                         arv->set_fade_visibility (true);
729                 }
730         }
731 }
732
733 void
734 AudioStreamView::hide_all_fades ()
735 {
736         for (list<RegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
737                 AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
738                 if (arv) {
739                         arv->set_fade_visibility (false);
740                 }
741         }
742 }
743
744 void
745 AudioStreamView::show_all_xfades ()
746 {
747         foreach_crossfadeview (&CrossfadeView::show);
748         crossfades_visible = true;
749 }
750
751 void
752 AudioStreamView::hide_all_xfades ()
753 {
754         foreach_crossfadeview (&CrossfadeView::hide);
755         crossfades_visible = false;
756 }
757
758 void
759 AudioStreamView::hide_xfades_involving (AudioRegionView& rv)
760 {
761         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
762                 if (i->second->crossfade->involves (rv.audio_region())) {
763                         i->second->fake_hide ();
764                 }
765         }
766 }
767
768 void
769 AudioStreamView::reveal_xfades_involving (AudioRegionView& rv)
770 {
771         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
772                 if (i->second->crossfade->involves (rv.audio_region()) && i->second->visible()) {
773                         i->second->show ();
774                 }
775         }
776 }
777
778 void
779 AudioStreamView::color_handler ()
780 {
781         //case cAudioTrackBase:
782         if (_trackview.is_track()) {
783                 canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_AudioTrackBase.get();
784         }
785
786         //case cAudioBusBase:
787         if (!_trackview.is_track()) {
788                 if (Profile->get_sae() && _trackview.route()->is_master()) {
789                         canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_AudioMasterBusBase.get();
790                 } else {
791                         canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_AudioBusBase.get();
792                 }
793         }
794 }
795
796 void
797 AudioStreamView::update_contents_height ()
798 {
799         StreamView::update_contents_height ();
800
801         for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) {
802                 update_content_height (i->second);
803         }
804 }
805
806 void
807 AudioStreamView::update_content_height (CrossfadeView* cv)
808 {
809         cv->show ();
810
811         if (_layer_display == Overlaid) {
812
813                 cv->set_y (0);
814                 cv->set_height (height);
815
816         } else {
817
818                 layer_t const inl = cv->crossfade->in()->layer ();
819                 layer_t const outl = cv->crossfade->out()->layer ();
820
821                 layer_t const high = max (inl, outl);
822                 layer_t const low = min (inl, outl);
823
824                 const double h = child_height ();
825
826                 cv->set_y ((_layers - high - 1) * h);
827                 cv->set_height ((high - low + 1) * h);
828
829         }
830 }
831
832 void
833 AudioStreamView::parameter_changed (string const & p)
834 {
835         if (p == "show-waveforms") {
836                 set_show_waveforms (Config->get_show_waveforms ());
837         } else if (p == "waveform-scale") {
838                 set_waveform_scale (Config->get_waveform_scale ());
839         } else if (p == "waveform-shape") {
840                 set_waveform_shape (Config->get_waveform_shape ());
841         }
842 }