X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fautomation_streamview.cc;h=60c8912114cc732613dd91200507eafbdc437aec;hb=4f86da854475e1ef6081ad5ebec166f734a6f570;hp=146cdc7b8918077f672e772b115533b00ff84fdb;hpb=593b421180290f46f39efcb21ed8192b624bbc73;p=ardour.git diff --git a/gtk2_ardour/automation_streamview.cc b/gtk2_ardour/automation_streamview.cc index 146cdc7b89..60c8912114 100644 --- a/gtk2_ardour/automation_streamview.cc +++ b/gtk2_ardour/automation_streamview.cc @@ -17,51 +17,50 @@ */ #include -#include +#include #include #include -#include +#include "gtkmm2ext/gtk_ui.h" + +#include "pbd/compose.h" +#include "canvas/debug.h" -#include "ardour/midi_playlist.h" #include "ardour/midi_region.h" #include "ardour/midi_source.h" -#include "ardour/midi_diskstream.h" -#include "ardour/midi_track.h" -#include "ardour/smf_source.h" -#include "ardour/region_factory.h" -#include "automation_streamview.h" -#include "region_view.h" #include "automation_region_view.h" +#include "automation_streamview.h" #include "automation_time_axis.h" -#include "canvas-simplerect.h" -#include "region_selection.h" -#include "selection.h" +#include "gui_thread.h" #include "public_editor.h" -#include "ardour_ui.h" +#include "region_selection.h" +#include "region_view.h" #include "rgb_macros.h" -#include "gui_thread.h" -#include "utils.h" -#include "simplerect.h" -#include "simpleline.h" +#include "selection.h" +#include "ui_config.h" + +#include "pbd/i18n.h" using namespace std; using namespace ARDOUR; +using namespace ARDOUR_UI_UTILS; using namespace PBD; using namespace Editing; AutomationStreamView::AutomationStreamView (AutomationTimeAxisView& tv) : StreamView (*dynamic_cast(tv.get_parent()), - new ArdourCanvas::Group(*tv.canvas_background()), - new ArdourCanvas::Group(*tv.canvas_display())) - , _controller(tv.controller()) + tv.canvas_display()) , _automation_view(tv) , _pending_automation_state (Off) { - //canvas_rect->property_fill_color_rgba() = stream_base_color; - canvas_rect->property_outline_color_rgba() = RGBA_BLACK; + CANVAS_DEBUG_NAME (_canvas_group, string_compose ("SV canvas group auto %1", tv.name())); + CANVAS_DEBUG_NAME (canvas_rect, string_compose ("SV canvas rectangle auto %1", tv.name())); + + color_handler (); + + UIConfiguration::instance().ColorsChanged.connect(sigc::mem_fun(*this, &AutomationStreamView::color_handler)); } AutomationStreamView::~AutomationStreamView () @@ -70,27 +69,31 @@ AutomationStreamView::~AutomationStreamView () RegionView* -AutomationStreamView::add_region_view_internal (boost::shared_ptr region, bool wfd, bool /*recording*/) +AutomationStreamView::add_region_view_internal (boost::shared_ptr region, bool wait_for_data, bool /*recording*/) { - if ( ! region) { - cerr << "No region" << endl; - return NULL; + if (!region) { + return 0; } - if (wfd) { + if (wait_for_data) { boost::shared_ptr mr = boost::dynamic_pointer_cast(region); - if (mr) - mr->midi_source()->load_model(); + if (mr) { + Source::Lock lock(mr->midi_source()->mutex()); + mr->midi_source()->load_model(lock); + } } const boost::shared_ptr control = boost::dynamic_pointer_cast ( - region->control (_controller->controllable()->parameter(), true) + region->control (_automation_view.parameter(), true) ); boost::shared_ptr list; if (control) { list = boost::dynamic_pointer_cast(control->list()); - assert(!control->list() || list); + if (control->list() && !list) { + error << _("unable to display automation region for control without list") << endmsg; + return 0; + } } AutomationRegionView *region_view; @@ -102,31 +105,34 @@ AutomationStreamView::add_region_view_internal (boost::shared_ptr region /* great. we already have an AutomationRegionView for this Region. use it again. */ AutomationRegionView* arv = dynamic_cast(*i);; - if (arv->line()) + if (arv->line()) { arv->line()->set_list (list); + } (*i)->set_valid (true); - (*i)->enable_display(wfd); + (*i)->enable_display (wait_for_data); display_region(arv); - return NULL; + return 0; } } - region_view = new AutomationRegionView (_canvas_group, _automation_view, region, - _controller->controllable()->parameter(), list, - _samples_per_unit, region_color); + region_view = new AutomationRegionView ( + _canvas_group, _automation_view, region, + _automation_view.parameter (), list, + _samples_per_pixel, region_color + ); - region_view->init (region_color, false); + region_view->init (false); region_views.push_front (region_view); /* follow global waveform setting */ - if (wfd) { + if (wait_for_data) { region_view->enable_display(true); - //region_view->midi_region()->midi_source(0)->load_model(); + // region_view->midi_region()->midi_source(0)->load_model(); } - display_region(region_view); + display_region (region_view); /* catch regionview going away */ region->DropReferences.connect (*this, invalidator (*this), boost::bind (&AutomationStreamView::remove_region_view, this, boost::weak_ptr(region)), gui_context()); @@ -136,7 +142,7 @@ AutomationStreamView::add_region_view_internal (boost::shared_ptr region if (line && line->the_list()) { line->the_list()->set_automation_state (automation_state ()); } - + RegionViewAdded (region_view); return region_view; @@ -151,17 +157,16 @@ AutomationStreamView::display_region(AutomationRegionView* region_view) void AutomationStreamView::set_automation_state (AutoState state) { - /* XXX: not sure if this is right, but for now the automation state is basically held by - the regions' AutomationLists. Each region is always set to have the same AutoState. - */ - + /* Setting the automation state for this view sets the state of all regions' lists to the same thing */ + if (region_views.empty()) { _pending_automation_state = state; } else { - for (std::list::iterator i = region_views.begin(); i != region_views.end(); ++i) { - boost::shared_ptr line = dynamic_cast(*i)->line(); - if (line && line->the_list()) { - line->the_list()->set_automation_state (state); + list > lines = get_lines (); + + for (list >::iterator i = lines.begin(); i != lines.end(); ++i) { + if ((*i)->the_list()) { + (*i)->the_list()->set_automation_state (state); } } } @@ -170,10 +175,8 @@ AutomationStreamView::set_automation_state (AutoState state) void AutomationStreamView::redisplay_track () { - list::iterator i, tmp; - // Flag region views as invalid and disable drawing - for (i = region_views.begin(); i != region_views.end(); ++i) { + for (list::iterator i = region_views.begin(); i != region_views.end(); ++i) { (*i)->set_valid (false); (*i)->enable_display(false); } @@ -198,13 +201,11 @@ AutomationStreamView::setup_rec_box () void AutomationStreamView::color_handler () { - /*if (_trackview.is_midi_track()) { - canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MidiTrackBase.get(); + if (_trackview.is_midi_track()) { + canvas_rect->set_fill_color (UIConfiguration::instance().color_mod ("midi track base", "midi track base")); + } else { + canvas_rect->set_fill_color (UIConfiguration::instance().color ("midi bus base")); } - - if (!_trackview.is_midi_track()) { - canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MidiBusBase.get();; - }*/ } AutoState @@ -225,13 +226,12 @@ AutomationStreamView::automation_state () const bool AutomationStreamView::has_automation () const { - list::const_iterator i = region_views.begin (); - while (i != region_views.end()) { - AutomationRegionView* rv = static_cast (*i); - if (rv->line() && rv->line()->npoints() > 0) { + list > lines = get_lines (); + + for (list >::iterator i = lines.begin(); i != lines.end(); ++i) { + if ((*i)->npoints() > 0) { return true; } - ++i; } return false; @@ -243,10 +243,10 @@ AutomationStreamView::has_automation () const void AutomationStreamView::set_interpolation (AutomationList::InterpolationStyle s) { - for (list::const_iterator i = region_views.begin(); i != region_views.end(); ++i) { - AutomationRegionView* arv = dynamic_cast (*i); - assert (arv); - arv->line()->the_list()->set_interpolation (s); + list > lines = get_lines (); + + for (list >::iterator i = lines.begin(); i != lines.end(); ++i) { + (*i)->the_list()->set_interpolation (s); } } @@ -258,7 +258,96 @@ AutomationStreamView::interpolation () const } AutomationRegionView* v = dynamic_cast (region_views.front()); - assert (v); + if (v) { + return v->line()->the_list()->interpolation (); + } + return AutomationList::Linear; +} + +/** Clear all automation displayed in this view */ +void +AutomationStreamView::clear () +{ + list > lines = get_lines (); + + for (list >::iterator i = lines.begin(); i != lines.end(); ++i) { + (*i)->clear (); + } +} + +/** @param start Start position in session samples. + * @param end End position in session samples. + * @param bot Bottom position expressed as a fraction of track height where 0 is the bottom of the track. + * @param top Top position expressed as a fraction of track height where 0 is the bottom of the track. + * NOTE: this y system is different to that for the StreamView method that this overrides, which is a little + * confusing. + */ +void +AutomationStreamView::get_selectables (samplepos_t start, samplepos_t end, double botfrac, double topfrac, list& results, bool /*within*/) +{ + for (list::iterator i = region_views.begin(); i != region_views.end(); ++i) { + AutomationRegionView* arv = dynamic_cast (*i); + if (arv) { + arv->line()->get_selectables (start, end, botfrac, topfrac, results); + } + } +} + +void +AutomationStreamView::set_selected_points (PointSelection& ps) +{ + list > lines = get_lines (); + + for (list >::iterator i = lines.begin(); i != lines.end(); ++i) { + (*i)->set_selected_points (ps); + } +} + +list > +AutomationStreamView::get_lines () const +{ + list > lines; + + for (list::const_iterator i = region_views.begin(); i != region_views.end(); ++i) { + AutomationRegionView* arv = dynamic_cast (*i); + if (arv) { + lines.push_back (arv->line()); + } + } + + return lines; +} + +bool +AutomationStreamView::paste (samplepos_t pos, + unsigned paste_count, + float times, + boost::shared_ptr alist) +{ + /* XXX: not sure how best to pick this; for now, just use the last region which starts before pos */ + + if (region_views.empty()) { + return false; + } + + region_views.sort (RegionView::PositionOrder()); + + list::const_iterator prev = region_views.begin (); + + for (list::const_iterator i = region_views.begin(); i != region_views.end(); ++i) { + if ((*i)->region()->position() > pos) { + break; + } + prev = i; + } + + boost::shared_ptr r = (*prev)->region (); + + /* If *prev doesn't cover pos, it's no good */ + if (r->position() > pos || ((r->position() + r->length()) < pos)) { + return false; + } - return v->line()->the_list()->interpolation (); + AutomationRegionView* arv = dynamic_cast (*prev); + return arv ? arv->paste(pos, paste_count, times, alist) : false; }