X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Faudio_streamview.cc;h=75974a7dbe2ad916f5f535486f964c81e263142a;hb=4e4cb140a0713cabec624f13e86eaf9b375ab6c5;hp=c0b3ba4c391a4c1e99c3a3c8154d47f68dbb48b2;hpb=ce234f363e95c38fc92728e520bf5ba240a89aa7;p=ardour.git diff --git a/gtk2_ardour/audio_streamview.cc b/gtk2_ardour/audio_streamview.cc index c0b3ba4c39..75974a7dbe 100644 --- a/gtk2_ardour/audio_streamview.cc +++ b/gtk2_ardour/audio_streamview.cc @@ -18,6 +18,7 @@ #include #include +#include #include @@ -25,7 +26,7 @@ #include #include -#include +#include #include #include #include @@ -48,6 +49,9 @@ #include "utils.h" #include "color.h" +#include "i18n.h" + +using namespace std; using namespace ARDOUR; using namespace PBD; using namespace Editing; @@ -56,40 +60,25 @@ AudioStreamView::AudioStreamView (AudioTimeAxisView& tv) : StreamView (tv) { crossfades_visible = true; - - if (tv.is_audio_track()) - stream_base_color = color_map[cAudioTrackBase]; + _waveform_scale = LinearWaveform; + _waveform_shape = Traditional; + + if (tv.is_track()) + stream_base_color = ARDOUR_UI::config()->canvasvar_AudioTrackBase.get(); else - stream_base_color = color_map[cAudioBusBase]; + stream_base_color = ARDOUR_UI::config()->canvasvar_AudioBusBase.get(); canvas_rect->property_fill_color_rgba() = stream_base_color; - canvas_rect->property_outline_color_rgba() = color_map[cAudioTrackOutline]; + canvas_rect->property_outline_color_rgba() = RGBA_BLACK; _amplitude_above_axis = 1.0; use_rec_regions = tv.editor.show_waveforms_recording (); - last_rec_peak_frame = 0; -} -AudioStreamView::~AudioStreamView () -{ } -int -AudioStreamView::set_height (gdouble h) +AudioStreamView::~AudioStreamView () { - /* limit the values to something sane-ish */ - if (h < 10.0 || h > 1000.0) { - return -1; - } - - StreamView::set_height(h); - - for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) { - (*i)->set_height (h); - } - - return 0; } int @@ -124,30 +113,35 @@ AudioStreamView::set_amplitude_above_axis (gdouble app) return 0; } -void +RegionView* AudioStreamView::add_region_view_internal (boost::shared_ptr r, bool wait_for_waves) { - ENSURE_GUI_THREAD (bind (mem_fun (*this, &AudioStreamView::add_region_view), r)); + AudioRegionView *region_view = 0; boost::shared_ptr region = boost::dynamic_pointer_cast (r); if (region == 0) { - return; + return NULL; } - AudioRegionView *region_view; - list::iterator i; - - for (i = region_views.begin(); i != region_views.end(); ++i) { + for (list::iterator i = region_views.begin(); i != region_views.end(); ++i) { if ((*i)->region() == r) { /* great. we already have a AudioRegionView for this Region. use it again. */ - + (*i)->set_valid (true); - return; + + // this might not be necessary + AudioRegionView* const arv = dynamic_cast(*i); + if (arv) { + arv->set_waveform_scale (_waveform_scale); + arv->set_waveform_shape (_waveform_shape); + } + + return NULL; } } - + switch (_trackview.audio_track()->mode()) { case Normal: region_view = new AudioRegionView (canvas_group, _trackview, region, @@ -157,41 +151,85 @@ AudioStreamView::add_region_view_internal (boost::shared_ptr r, bool wai region_view = new TapeAudioRegionView (canvas_group, _trackview, region, _samples_per_unit, region_color); break; + default: + fatal << string_compose (_("programming error: %1"), "illegal track mode in ::add_region_view_internal") << endmsg; + /*NOTREACHED*/ + } region_view->init (region_color, wait_for_waves); region_view->set_amplitude_above_axis(_amplitude_above_axis); region_views.push_front (region_view); + + + /* if its the special single-sample length that we use for rec-regions, make it + insensitive to events + */ + + if (region->length() == 1) { + region_view->set_sensitive (false); + } + + /* if this was the first one, then lets query the waveform scale and shape. + otherwise, we set it to the current value */ + + if (region_views.size() == 1) { + if (region_view->waveform_logscaled()) { + _waveform_scale = LogWaveform; + } else { + _waveform_scale = LinearWaveform; + } + + if (region_view->waveform_rectified()) { + _waveform_shape = Rectified; + } else { + _waveform_shape = Traditional; + } + } + else { + region_view->set_waveform_scale(_waveform_scale); + region_view->set_waveform_shape(_waveform_shape); + } /* follow global waveform setting */ region_view->set_waveform_visible(_trackview.editor.show_waveforms()); /* catch regionview going away */ + region->GoingAway.connect (bind (mem_fun (*this, &AudioStreamView::remove_region_view), boost::weak_ptr (r))); - region->GoingAway.connect (bind (mem_fun (*this, &AudioStreamView::remove_region_view), region)); - RegionViewAdded (region_view); + + return region_view; } void -AudioStreamView::remove_region_view (boost::shared_ptr r) +AudioStreamView::remove_region_view (boost::weak_ptr weak_r) { - ENSURE_GUI_THREAD (bind (mem_fun (*this, &AudioStreamView::remove_region_view), r)); + ENSURE_GUI_THREAD (bind (mem_fun (*this, &AudioStreamView::remove_region_view), weak_r)); - for (list::iterator i = crossfade_views.begin(); i != crossfade_views.end();) { - list::iterator tmp; - - tmp = i; - ++tmp; - - boost::shared_ptr ar = boost::dynamic_pointer_cast(r); - if (ar && (*i)->crossfade.involves (ar)) { - delete *i; - crossfade_views.erase (i); + boost::shared_ptr r (weak_r.lock()); + + if (!r) { + return; + } + + if (!_trackview.session().deletion_in_progress()) { + + for (list::iterator i = crossfade_views.begin(); i != crossfade_views.end();) { + list::iterator tmp; + + tmp = i; + ++tmp; + + boost::shared_ptr ar = boost::dynamic_pointer_cast(r); + if (ar && (*i)->crossfade->involves (ar)) { + delete *i; + crossfade_views.erase (i); + } + + i = tmp; } - - i = tmp; } StreamView::remove_region_view(r); @@ -210,15 +248,25 @@ AudioStreamView::undisplay_diskstream () } void -AudioStreamView::playlist_modified () +AudioStreamView::playlist_modified_weak (boost::weak_ptr ds) +{ + boost::shared_ptr sp (ds.lock()); + if (!sp) { + return; + } + + playlist_modified (sp); +} + +void +AudioStreamView::playlist_modified (boost::shared_ptr ds) { - ENSURE_GUI_THREAD (mem_fun (*this, &AudioStreamView::playlist_modified)); + /* we do not allow shared_ptr to be bound to slots */ + ENSURE_GUI_THREAD (bind (mem_fun (*this, &AudioStreamView::playlist_modified_weak), ds)); - StreamView::playlist_modified(); + StreamView::playlist_modified (ds); - /* if the playlist is modified, make sure xfades are on top and all the regionviews are stacked - correctly. - */ + /* make sure xfades are on top and all the regionviews are stacked correctly. */ for (list::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) { (*i)->get_canvas_group()->raise_to_top(); @@ -232,24 +280,38 @@ AudioStreamView::playlist_changed (boost::shared_ptr ds) StreamView::playlist_changed(ds); - AudioPlaylist* apl = dynamic_cast(ds->playlist()); + boost::shared_ptr apl = boost::dynamic_pointer_cast(ds->playlist()); if (apl) playlist_connections.push_back (apl->NewCrossfade.connect (mem_fun (*this, &AudioStreamView::add_crossfade))); } void -AudioStreamView::add_crossfade (Crossfade *crossfade) +AudioStreamView::add_crossfade_weak (boost::weak_ptr crossfade) +{ + boost::shared_ptr sp (crossfade.lock()); + + if (!sp) { + return; + } + + add_crossfade (sp); +} + +void +AudioStreamView::add_crossfade (boost::shared_ptr crossfade) { AudioRegionView* lview = 0; AudioRegionView* rview = 0; - ENSURE_GUI_THREAD (bind (mem_fun (*this, &AudioStreamView::add_crossfade), crossfade)); + /* we do not allow shared_ptr to be bound to slots */ + + ENSURE_GUI_THREAD (bind (mem_fun (*this, &AudioStreamView::add_crossfade_weak), boost::weak_ptr (crossfade))); /* first see if we already have a CrossfadeView for this Crossfade */ for (list::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) { - if (&(*i)->crossfade == crossfade) { - if (!crossfades_visible) { + if ((*i)->crossfade == crossfade) { + if (!crossfades_visible || layer_display == Stacked) { (*i)->hide(); } else { (*i)->show (); @@ -274,7 +336,7 @@ AudioStreamView::add_crossfade (Crossfade *crossfade) CrossfadeView *cv = new CrossfadeView (_trackview.canvas_display, _trackview, - *crossfade, + crossfade, _samples_per_unit, region_color, *lview, *rview); @@ -282,18 +344,20 @@ AudioStreamView::add_crossfade (Crossfade *crossfade) crossfade->Invalidated.connect (mem_fun (*this, &AudioStreamView::remove_crossfade)); crossfade_views.push_back (cv); - if (!crossfades_visible) { + if (!Config->get_xfades_visible() || !crossfades_visible || layer_display == Stacked) { cv->hide (); } } void -AudioStreamView::remove_crossfade (Crossfade *xfade) +AudioStreamView::remove_crossfade (boost::shared_ptr r) { - ENSURE_GUI_THREAD (bind (mem_fun (*this, &AudioStreamView::remove_crossfade), xfade)); + ENSURE_GUI_THREAD (bind (mem_fun (*this, &AudioStreamView::remove_crossfade), r)); + + boost::shared_ptr xfade = boost::dynamic_pointer_cast (r); for (list::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) { - if (&(*i)->crossfade == xfade) { + if ((*i)->crossfade == xfade) { delete *i; crossfade_views.erase (i); break; @@ -307,21 +371,21 @@ AudioStreamView::redisplay_diskstream () list::iterator i, tmp; list::iterator xi, tmpx; - for (i = region_views.begin(); i != region_views.end(); ++i) { (*i)->set_valid (false); } for (xi = crossfade_views.begin(); xi != crossfade_views.end(); ++xi) { (*xi)->set_valid (false); - if ((*xi)->visible()) { + if ((*xi)->visible() && layer_display != Stacked) { (*xi)->show (); } } if (_trackview.is_audio_track()) { _trackview.get_diskstream()->playlist()->foreach_region (static_cast(this), &StreamView::add_region_view); - AudioPlaylist* apl = dynamic_cast(_trackview.get_diskstream()->playlist()); + + boost::shared_ptr apl = boost::dynamic_pointer_cast(_trackview.get_diskstream()->playlist()); if (apl) apl->foreach_crossfade (this, &AudioStreamView::add_crossfade); } @@ -352,7 +416,9 @@ AudioStreamView::redisplay_diskstream () /* now fix layering */ - playlist_modified (); + for (RegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) { + region_layered (*i); + } } void @@ -373,8 +439,20 @@ AudioStreamView::set_waveform_shape (WaveformShape shape) if (arv) arv->set_waveform_shape (shape); } + _waveform_shape = shape; } - + +void +AudioStreamView::set_waveform_scale (WaveformScale scale) +{ + for (RegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) { + AudioRegionView* const arv = dynamic_cast(*i); + if (arv) + arv->set_waveform_scale (scale); + } + _waveform_scale = scale; +} + void AudioStreamView::setup_rec_box () { @@ -394,47 +472,47 @@ AudioStreamView::setup_rec_box () SourceList sources; - for (list::iterator prc = peak_ready_connections.begin(); prc != peak_ready_connections.end(); ++prc) { + for (list::iterator prc = rec_data_ready_connections.begin(); prc != rec_data_ready_connections.end(); ++prc) { (*prc).disconnect(); } - peak_ready_connections.clear(); + rec_data_ready_connections.clear(); // FIXME boost::shared_ptr ads = boost::dynamic_pointer_cast(_trackview.get_diskstream()); assert(ads); - for (uint32_t n=0; n < ads->n_channels(); ++n) { - AudioSource *src = (AudioSource *) ads->write_source (n); + for (uint32_t n=0; n < ads->n_channels().n_audio(); ++n) { + boost::shared_ptr src = boost::static_pointer_cast (ads->write_source (n)); if (src) { sources.push_back (src); - peak_ready_connections.push_back (src->PeakRangeReady.connect (bind (mem_fun (*this, &AudioStreamView::rec_peak_range_ready), src))); + + rec_data_ready_connections.push_back (src->PeakRangeReady.connect (bind + (mem_fun (*this, &AudioStreamView::rec_peak_range_ready), boost::weak_ptr(src)))); } } // handle multi - jack_nframes_t start = 0; + nframes_t start = 0; if (rec_regions.size() > 0) { - start = rec_regions.back()->start() + _trackview.get_diskstream()->get_captured_frames(rec_regions.size()-1); + start = rec_regions.back().first->start() + _trackview.get_diskstream()->get_captured_frames(rec_regions.size()-1); } boost::shared_ptr region (boost::dynamic_pointer_cast (RegionFactory::create (sources, start, 1 , "", 0, (Region::Flag)(Region::DefaultFlags | Region::DoNotSaveState), false))); + assert(region); region->set_position (_trackview.session().transport_frame(), this); - rec_regions.push_back (region); - /* catch it if it goes away */ - region->GoingAway.connect (bind (mem_fun (*this, &AudioStreamView::remove_rec_region), region)); - /* we add the region later */ + rec_regions.push_back (make_pair(region, (RegionView*)0)); } /* start a new rec box */ - AudioTrack* at; + boost::shared_ptr at; at = _trackview.audio_track(); /* we know what it is already */ boost::shared_ptr ds = at->audio_diskstream(); - jack_nframes_t frame_pos = ds->current_capture_start (); + nframes_t frame_pos = ds->current_capture_start (); gdouble xstart = _trackview.editor.frame_to_pixel (frame_pos); gdouble xend; uint32_t fill_color; @@ -442,12 +520,12 @@ AudioStreamView::setup_rec_box () switch (_trackview.audio_track()->mode()) { case Normal: xend = xstart; - fill_color = color_map[cRecordingRectFill]; + fill_color = ARDOUR_UI::config()->canvasvar_RecordingRect.get(); break; case Destructive: xend = xstart + 2; - fill_color = color_map[cRecordingRectFill]; + fill_color = ARDOUR_UI::config()->canvasvar_RecordingRect.get(); /* make the recording rect translucent to allow the user to see the peak data coming in, etc. */ @@ -460,8 +538,9 @@ AudioStreamView::setup_rec_box () rec_rect->property_y1() = 1.0; rec_rect->property_x2() = xend; rec_rect->property_y2() = (double) _trackview.height - 1; - rec_rect->property_outline_color_rgba() = color_map[cRecordingRectOutline]; + rec_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RecordingRect.get(); rec_rect->property_fill_color_rgba() = fill_color; + rec_rect->lower_to_bottom(); RecBoxInfo recbox; recbox.rectangle = rec_rect; @@ -494,17 +573,27 @@ AudioStreamView::setup_rec_box () /* disconnect rapid update */ screen_update_connection.disconnect(); - for (list::iterator prc = peak_ready_connections.begin(); prc != peak_ready_connections.end(); ++prc) { + for (list::iterator prc = rec_data_ready_connections.begin(); prc != rec_data_ready_connections.end(); ++prc) { (*prc).disconnect(); } - peak_ready_connections.clear(); + rec_data_ready_connections.clear(); rec_updating = false; rec_active = false; - last_rec_peak_frame = 0; /* remove temp regions */ - + + for (list,RegionView*> >::iterator iter = rec_regions.begin(); iter != rec_regions.end(); ) { + list,RegionView*> >::iterator tmp; + + tmp = iter; + ++tmp; + + (*iter).first->drop_references (); + + iter = tmp; + } + rec_regions.clear(); // cerr << "\tclear " << rec_rects.size() << " rec rects\n"; @@ -530,21 +619,27 @@ AudioStreamView::foreach_crossfadeview (void (CrossfadeView::*pmf)(void)) } void -AudioStreamView::rec_peak_range_ready (jack_nframes_t start, jack_nframes_t cnt, Source * src) +AudioStreamView::rec_peak_range_ready (nframes_t start, nframes_t cnt, boost::weak_ptr weak_src) { - // this is called from the peak building thread - - ENSURE_GUI_THREAD(bind (mem_fun (*this, &AudioStreamView::rec_peak_range_ready), start, cnt, src)); + ENSURE_GUI_THREAD(bind (mem_fun (*this, &AudioStreamView::rec_peak_range_ready), start, cnt, weak_src)); - if (rec_peak_ready_map.size() == 0 || start+cnt > last_rec_peak_frame) { - last_rec_peak_frame = start + cnt; - } + boost::shared_ptr src (weak_src.lock()); - rec_peak_ready_map[src] = true; + if (!src) { + return; + } - if (rec_peak_ready_map.size() == _trackview.get_diskstream()->n_channels()) { + // this is called from the peak building thread + + if (rec_data_ready_map.size() == 0 || start+cnt > last_rec_data_frame) { + last_rec_data_frame = start + cnt; + } + + rec_data_ready_map[src] = true; + + if (rec_data_ready_map.size() == _trackview.get_diskstream()->n_channels().n_audio()) { this->update_rec_regions (); - rec_peak_ready_map.clear(); + rec_data_ready_map.clear(); } } @@ -555,9 +650,9 @@ AudioStreamView::update_rec_regions () uint32_t n = 0; - for (list >::iterator iter = rec_regions.begin(); iter != rec_regions.end(); n++) { + for (list,RegionView*> >::iterator iter = rec_regions.begin(); iter != rec_regions.end(); n++) { - list >::iterator tmp; + list,RegionView*> >::iterator tmp; tmp = iter; ++tmp; @@ -568,17 +663,18 @@ AudioStreamView::update_rec_regions () continue; } - // FIXME - boost::shared_ptr region = boost::dynamic_pointer_cast(*iter); - assert(region); + boost::shared_ptr region = boost::dynamic_pointer_cast(iter->first); + if (!region) { + continue; + } - jack_nframes_t origlen = region->length(); + nframes_t origlen = region->length(); - if (region == rec_regions.back() && rec_active) { + if (region == rec_regions.back().first && rec_active) { - if (last_rec_peak_frame > region->start()) { + if (last_rec_data_frame > region->start()) { - jack_nframes_t nlen = last_rec_peak_frame - region->start(); + nframes_t nlen = last_rec_data_frame - region->start(); if (nlen != region->length()) { @@ -601,11 +697,11 @@ AudioStreamView::update_rec_regions () } else { - jack_nframes_t nlen = _trackview.get_diskstream()->get_captured_frames(n); + nframes_t nlen = _trackview.get_diskstream()->get_captured_frames(n); if (nlen != region->length()) { - if (region->source(0).length() >= region->start() + nlen) { + if (region->source(0)->length() >= region->start() + nlen) { region->freeze (); region->set_position (_trackview.get_diskstream()->get_capture_start_frame(n), this); @@ -648,7 +744,7 @@ void AudioStreamView::hide_xfades_involving (AudioRegionView& rv) { for (list::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) { - if ((*i)->crossfade.involves (rv.audio_region())) { + if ((*i)->crossfade->involves (rv.audio_region())) { (*i)->fake_hide (); } } @@ -658,32 +754,38 @@ void AudioStreamView::reveal_xfades_involving (AudioRegionView& rv) { for (list::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) { - if ((*i)->crossfade.involves (rv.audio_region()) && (*i)->visible()) { + if ((*i)->crossfade->involves (rv.audio_region()) && (*i)->visible() && layer_display != Stacked) { (*i)->show (); } } } void -AudioStreamView::color_handler (ColorID id, uint32_t val) +AudioStreamView::color_handler () { - switch (id) { - case cAudioTrackBase: - if (_trackview.is_track()) { - canvas_rect->property_fill_color_rgba() = val; - } - break; - case cAudioBusBase: - if (!_trackview.is_track()) { - canvas_rect->property_fill_color_rgba() = val; - } - break; - case cAudioTrackOutline: - canvas_rect->property_outline_color_rgba() = val; - break; - - default: - break; + //case cAudioTrackBase: + if (_trackview.is_track()) { + canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_AudioTrackBase.get(); + } + + //case cAudioBusBase: + if (!_trackview.is_track()) { + canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_AudioBusBase.get(); } + } +void +AudioStreamView::update_contents_y_position_and_height () +{ + StreamView::update_contents_y_position_and_height (); + + for (CrossfadeViewList::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) { + if (layer_display == Overlaid) { + (*i)->show (); + (*i)->set_y_position_and_height (0, height); + } else { + (*i)->hide (); + } + } +}