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