X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Faudio_streamview.cc;h=08ac532319ffa6f65d9e160f9da35548b56fa9d7;hb=a606a83d2ec43d9fbf9b65969afb3b3c46c546fa;hp=279130ad381ee919573249401c945e751f199293;hpb=87726495c30f90554b5204b5385d17274a8fe93e;p=ardour.git diff --git a/gtk2_ardour/audio_streamview.cc b/gtk2_ardour/audio_streamview.cc index 279130ad38..08ac532319 100644 --- a/gtk2_ardour/audio_streamview.cc +++ b/gtk2_ardour/audio_streamview.cc @@ -18,6 +18,7 @@ #include #include +#include #include @@ -46,10 +47,10 @@ #include "rgb_macros.h" #include "gui_thread.h" #include "utils.h" -#include "color.h" #include "i18n.h" +using namespace std; using namespace ARDOUR; using namespace PBD; using namespace Editing; @@ -61,42 +62,23 @@ AudioStreamView::AudioStreamView (AudioTimeAxisView& tv) _waveform_scale = LinearWaveform; _waveform_shape = Traditional; - if (tv.is_audio_track()) - stream_base_color = color_map[cAudioTrackBase]; + 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) -{ - /* 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 AudioStreamView::set_samples_per_unit (gdouble spp) { @@ -129,17 +111,15 @@ AudioStreamView::set_amplitude_above_axis (gdouble app) return 0; } -void +RegionView* AudioStreamView::add_region_view_internal (boost::shared_ptr r, bool wait_for_waves) { AudioRegionView *region_view = 0; - ENSURE_GUI_THREAD (bind (mem_fun (*this, &AudioStreamView::add_region_view), r)); - boost::shared_ptr region = boost::dynamic_pointer_cast (r); if (region == 0) { - return; + return NULL; } for (list::iterator i = region_views.begin(); i != region_views.end(); ++i) { @@ -156,7 +136,7 @@ AudioStreamView::add_region_view_internal (boost::shared_ptr r, bool wai arv->set_waveform_shape (_waveform_shape); } - return; + return NULL; } } @@ -217,6 +197,8 @@ AudioStreamView::add_region_view_internal (boost::shared_ptr r, bool wai region->GoingAway.connect (bind (mem_fun (*this, &AudioStreamView::remove_region_view), boost::weak_ptr (r))); RegionViewAdded (region_view); + + return region_view; } void @@ -248,7 +230,6 @@ AudioStreamView::remove_region_view (boost::weak_ptr weak_r) } } - StreamView::remove_region_view(r); } @@ -265,11 +246,23 @@ AudioStreamView::undisplay_diskstream () } void -AudioStreamView::playlist_modified () +AudioStreamView::playlist_modified_weak (boost::weak_ptr ds) { - ENSURE_GUI_THREAD (mem_fun (*this, &AudioStreamView::playlist_modified)); + boost::shared_ptr sp (ds.lock()); + if (!sp) { + return; + } + + playlist_modified (sp); +} + +void +AudioStreamView::playlist_modified (boost::shared_ptr ds) +{ + /* 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); /* make sure xfades are on top and all the regionviews are stacked correctly. */ @@ -316,7 +309,8 @@ AudioStreamView::add_crossfade (boost::shared_ptr crossfade) for (list::iterator i = crossfade_views.begin(); i != crossfade_views.end(); ++i) { if ((*i)->crossfade == crossfade) { - if (!crossfades_visible) { + + if (!crossfades_visible || layer_display == Stacked) { (*i)->hide(); } else { (*i)->show (); @@ -345,19 +339,20 @@ AudioStreamView::add_crossfade (boost::shared_ptr crossfade) _samples_per_unit, region_color, *lview, *rview); - + cv->set_valid (true); crossfade->Invalidated.connect (mem_fun (*this, &AudioStreamView::remove_crossfade)); crossfade_views.push_back (cv); - - if (!Config->get_xfades_visible() || !crossfades_visible) { + if (!Config->get_xfades_visible() || !crossfades_visible || layer_display == Stacked) { cv->hide (); } } void -AudioStreamView::remove_crossfade (boost::shared_ptr 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) { @@ -380,7 +375,7 @@ AudioStreamView::redisplay_diskstream () 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 (); } } @@ -393,6 +388,8 @@ AudioStreamView::redisplay_diskstream () apl->foreach_crossfade (this, &AudioStreamView::add_crossfade); } + RegionViewList copy; + for (i = region_views.begin(); i != region_views.end(); ) { tmp = i; tmp++; @@ -400,9 +397,47 @@ AudioStreamView::redisplay_diskstream () if (!(*i)->is_valid()) { delete *i; region_views.erase (i); - } + i = tmp; + continue; + } else { + (*i)->enable_display(true); + } + + /* + sort regionviews by layer so that when we call region_layered () + the canvas layering works out (in non-stacked mode). + */ + + if (copy.size() == 0) { + copy.push_front((*i)); + i = tmp; + continue; + } + + RegionViewList::iterator k = copy.begin(); + RegionViewList::iterator l = copy.end(); + l--; + + if ((*i)->region()->layer() <= (*k)->region()->layer()) { + copy.push_front((*i)); + i = tmp; + continue; + } else if ((*i)->region()->layer() >= (*l)->region()->layer()) { + copy.push_back((*i)); + i = tmp; + continue; + } + + for (RegionViewList::iterator j = copy.begin(); j != copy.end(); ++j) { + + if ((*j)->region()->layer() >= (*i)->region()->layer()) { + copy.insert(j, (*i)); + break; + } + } i = tmp; + } for (xi = crossfade_views.begin(); xi != crossfade_views.end();) { @@ -417,10 +452,12 @@ AudioStreamView::redisplay_diskstream () xi = tmpx; } - /* now fix layering */ - - for (RegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) { - region_layered (*i); + /* now fix canvas layering */ + + for (RegionViewList::iterator j = copy.begin(); j != copy.end(); ++j) { + (*j)->enable_display(true); + (*j)->set_y_position_and_height(0, height); + region_layered (*j); } } @@ -429,8 +466,9 @@ AudioStreamView::set_show_waveforms (bool yn) { for (list::iterator i = region_views.begin(); i != region_views.end(); ++i) { AudioRegionView* const arv = dynamic_cast(*i); - if (arv) + if (arv) { arv->set_waveform_visible (yn); + } } } @@ -475,20 +513,22 @@ 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) { + 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), boost::weak_ptr(src)))); + + rec_data_ready_connections.push_back (src->PeakRangeReady.connect (bind + (mem_fun (*this, &AudioStreamView::rec_peak_range_ready), boost::weak_ptr(src)))); } } @@ -496,19 +536,20 @@ AudioStreamView::setup_rec_box () 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); + 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(); @@ -520,12 +561,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. */ @@ -538,8 +579,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; @@ -572,24 +614,23 @@ 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 >::iterator iter = rec_regions.begin(); iter != rec_regions.end(); ) { - list >::iterator tmp; + for (list,RegionView*> >::iterator iter = rec_regions.begin(); iter != rec_regions.end(); ) { + list,RegionView*> >::iterator tmp; tmp = iter; ++tmp; - (*iter)->drop_references (); + (*iter).first->drop_references (); iter = tmp; } @@ -631,15 +672,15 @@ AudioStreamView::rec_peak_range_ready (nframes_t start, nframes_t cnt, boost::we // this is called from the peak building thread - if (rec_peak_ready_map.size() == 0 || start+cnt > last_rec_peak_frame) { - last_rec_peak_frame = start + cnt; + if (rec_data_ready_map.size() == 0 || start+cnt > last_rec_data_frame) { + last_rec_data_frame = start + cnt; } - rec_peak_ready_map[src] = true; + rec_data_ready_map[src] = true; - if (rec_peak_ready_map.size() == _trackview.get_diskstream()->n_channels()) { + 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(); } } @@ -650,9 +691,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; @@ -663,18 +704,18 @@ AudioStreamView::update_rec_regions () continue; } - boost::shared_ptr region = boost::dynamic_pointer_cast(*iter); + boost::shared_ptr region = boost::dynamic_pointer_cast(iter->first); if (!region) { continue; } 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()) { - nframes_t nlen = last_rec_peak_frame - region->start(); + nframes_t nlen = last_rec_data_frame - region->start(); if (nlen != region->length()) { @@ -754,32 +795,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; + //case cAudioTrackBase: + if (_trackview.is_track()) { + canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_AudioTrackBase.get(); + } - default: - break; + //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 (); + } + } +}