2007-09-05 22:30:39 -04:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 2001-2007 Paul Davis
|
2007-09-05 22:30:39 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2014-11-16 17:04:27 -05:00
|
|
|
#include <cmath>
|
|
|
|
#include <list>
|
2007-09-05 22:30:39 -04:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include <gtkmm.h>
|
|
|
|
|
2014-01-10 12:08:17 -05:00
|
|
|
#include "gtkmm2ext/gtk_ui.h"
|
|
|
|
|
|
|
|
#include "pbd/compose.h"
|
|
|
|
#include "canvas/debug.h"
|
2007-09-05 22:30:39 -04:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/midi_region.h"
|
|
|
|
#include "ardour/midi_source.h"
|
2007-09-05 22:30:39 -04:00
|
|
|
|
2014-12-16 00:05:45 -05:00
|
|
|
#include "ardour_ui.h"
|
2007-09-05 22:30:39 -04:00
|
|
|
#include "automation_region_view.h"
|
2014-12-16 00:05:45 -05:00
|
|
|
#include "automation_streamview.h"
|
2007-09-05 22:30:39 -04:00
|
|
|
#include "automation_time_axis.h"
|
2014-12-16 00:05:45 -05:00
|
|
|
#include "global_signals.h"
|
|
|
|
#include "gui_thread.h"
|
2007-09-05 22:30:39 -04:00
|
|
|
#include "public_editor.h"
|
2014-12-16 00:05:45 -05:00
|
|
|
#include "region_selection.h"
|
|
|
|
#include "region_view.h"
|
2007-09-05 22:30:39 -04:00
|
|
|
#include "rgb_macros.h"
|
2014-12-16 00:05:45 -05:00
|
|
|
#include "selection.h"
|
2007-09-05 22:30:39 -04:00
|
|
|
|
2014-12-17 19:43:09 -05:00
|
|
|
#include "i18n.h"
|
|
|
|
|
2007-09-05 22:30:39 -04:00
|
|
|
using namespace std;
|
|
|
|
using namespace ARDOUR;
|
2014-12-16 00:05:45 -05:00
|
|
|
using namespace ARDOUR_UI_UTILS;
|
2007-09-05 22:30:39 -04:00
|
|
|
using namespace PBD;
|
|
|
|
using namespace Editing;
|
|
|
|
|
2009-07-09 13:58:13 -04:00
|
|
|
AutomationStreamView::AutomationStreamView (AutomationTimeAxisView& tv)
|
2014-01-10 12:08:17 -05:00
|
|
|
: StreamView (*dynamic_cast<RouteTimeAxisView*>(tv.get_parent()),
|
|
|
|
tv.canvas_display())
|
2007-09-05 22:30:39 -04:00
|
|
|
, _automation_view(tv)
|
2010-06-25 16:47:09 -04:00
|
|
|
, _pending_automation_state (Off)
|
2007-09-05 22:30:39 -04:00
|
|
|
{
|
2014-01-10 12:08:17 -05:00
|
|
|
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()));
|
|
|
|
|
2014-12-16 00:05:45 -05:00
|
|
|
color_handler ();
|
|
|
|
|
|
|
|
ColorsChanged.connect(sigc::mem_fun(*this, &AutomationStreamView::color_handler));
|
2007-09-05 22:30:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
AutomationStreamView::~AutomationStreamView ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RegionView*
|
2014-01-10 12:08:17 -05:00
|
|
|
AutomationStreamView::add_region_view_internal (boost::shared_ptr<Region> region, bool wait_for_data, bool /*recording*/)
|
2007-09-05 22:30:39 -04:00
|
|
|
{
|
2014-12-17 19:43:09 -05:00
|
|
|
if (!region) {
|
|
|
|
return 0;
|
|
|
|
}
|
2007-09-05 22:30:39 -04:00
|
|
|
|
2014-01-10 12:08:17 -05:00
|
|
|
if (wait_for_data) {
|
2007-09-05 22:30:39 -04:00
|
|
|
boost::shared_ptr<MidiRegion> mr = boost::dynamic_pointer_cast<MidiRegion>(region);
|
2010-12-12 15:14:19 -05:00
|
|
|
if (mr) {
|
2014-12-17 16:05:27 -05:00
|
|
|
Source::Lock lock(mr->midi_source()->mutex());
|
|
|
|
mr->midi_source()->load_model(lock);
|
2010-12-12 15:14:19 -05:00
|
|
|
}
|
2007-09-05 22:30:39 -04:00
|
|
|
}
|
|
|
|
|
2010-06-25 16:47:09 -04:00
|
|
|
const boost::shared_ptr<AutomationControl> control = boost::dynamic_pointer_cast<AutomationControl> (
|
2011-02-17 11:18:27 -05:00
|
|
|
region->control (_automation_view.parameter(), true)
|
2010-06-25 16:47:09 -04:00
|
|
|
);
|
2007-09-05 22:30:39 -04:00
|
|
|
|
2007-09-10 23:14:32 -04:00
|
|
|
boost::shared_ptr<AutomationList> list;
|
2008-09-19 02:30:49 -04:00
|
|
|
if (control) {
|
2008-09-18 20:47:49 -04:00
|
|
|
list = boost::dynamic_pointer_cast<AutomationList>(control->list());
|
2014-12-17 19:43:09 -05:00
|
|
|
if (control->list() && !list) {
|
|
|
|
error << _("unable to display automation region for control without list") << endmsg;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-09-19 02:30:49 -04:00
|
|
|
}
|
2007-09-05 22:30:39 -04:00
|
|
|
|
|
|
|
AutomationRegionView *region_view;
|
|
|
|
std::list<RegionView *>::iterator i;
|
|
|
|
|
|
|
|
for (i = region_views.begin(); i != region_views.end(); ++i) {
|
|
|
|
if ((*i)->region() == region) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-21 12:17:02 -04:00
|
|
|
/* great. we already have an AutomationRegionView for this Region. use it again. */
|
|
|
|
AutomationRegionView* arv = dynamic_cast<AutomationRegionView*>(*i);;
|
2007-09-05 22:30:39 -04:00
|
|
|
|
2011-07-10 11:28:36 -04:00
|
|
|
if (arv->line()) {
|
2008-09-21 12:35:55 -04:00
|
|
|
arv->line()->set_list (list);
|
2011-07-10 11:28:36 -04:00
|
|
|
}
|
2007-09-05 22:30:39 -04:00
|
|
|
(*i)->set_valid (true);
|
2014-01-10 12:08:17 -05:00
|
|
|
(*i)->enable_display (wait_for_data);
|
2008-09-21 12:17:02 -04:00
|
|
|
display_region(arv);
|
2007-09-05 22:30:39 -04:00
|
|
|
|
2011-02-17 11:18:15 -05:00
|
|
|
return 0;
|
2007-09-05 22:30:39 -04:00
|
|
|
}
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-02-17 11:18:27 -05:00
|
|
|
region_view = new AutomationRegionView (
|
|
|
|
_canvas_group, _automation_view, region,
|
|
|
|
_automation_view.parameter (), list,
|
2013-04-12 11:31:50 -04:00
|
|
|
_samples_per_pixel, region_color
|
2011-02-17 11:18:27 -05:00
|
|
|
);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2014-06-09 23:28:32 -04:00
|
|
|
region_view->init (false);
|
2007-09-05 22:30:39 -04:00
|
|
|
region_views.push_front (region_view);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-09-05 22:30:39 -04:00
|
|
|
/* follow global waveform setting */
|
|
|
|
|
2014-01-10 12:08:17 -05:00
|
|
|
if (wait_for_data) {
|
2007-09-05 22:30:39 -04:00
|
|
|
region_view->enable_display(true);
|
2014-01-10 12:08:17 -05:00
|
|
|
// region_view->midi_region()->midi_source(0)->load_model();
|
2007-09-05 22:30:39 -04:00
|
|
|
}
|
|
|
|
|
2014-01-10 12:08:17 -05:00
|
|
|
display_region (region_view);
|
2007-09-05 22:30:39 -04:00
|
|
|
|
|
|
|
/* catch regionview going away */
|
2010-03-30 11:18:43 -04:00
|
|
|
region->DropReferences.connect (*this, invalidator (*this), boost::bind (&AutomationStreamView::remove_region_view, this, boost::weak_ptr<Region>(region)), gui_context());
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-06-25 16:47:09 -04:00
|
|
|
/* setup automation state for this region */
|
|
|
|
boost::shared_ptr<AutomationLine> line = region_view->line ();
|
|
|
|
if (line && line->the_list()) {
|
|
|
|
line->the_list()->set_automation_state (automation_state ());
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2007-09-05 22:30:39 -04:00
|
|
|
RegionViewAdded (region_view);
|
|
|
|
|
|
|
|
return region_view;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AutomationStreamView::display_region(AutomationRegionView* region_view)
|
|
|
|
{
|
|
|
|
region_view->line().reset();
|
|
|
|
}
|
|
|
|
|
2008-09-21 12:17:02 -04:00
|
|
|
void
|
|
|
|
AutomationStreamView::set_automation_state (AutoState state)
|
|
|
|
{
|
2010-08-09 18:23:23 -04:00
|
|
|
/* Setting the automation state for this view sets the state of all regions' lists to the same thing */
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-06-25 16:47:09 -04:00
|
|
|
if (region_views.empty()) {
|
|
|
|
_pending_automation_state = state;
|
|
|
|
} else {
|
2010-08-05 09:35:43 -04:00
|
|
|
list<boost::shared_ptr<AutomationLine> > lines = get_lines ();
|
|
|
|
|
|
|
|
for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
|
|
|
|
if ((*i)->the_list()) {
|
|
|
|
(*i)->the_list()->set_automation_state (state);
|
2010-06-25 16:47:09 -04:00
|
|
|
}
|
2010-05-21 21:33:13 -04:00
|
|
|
}
|
2008-09-21 12:17:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-05 22:30:39 -04:00
|
|
|
void
|
2010-04-21 16:42:22 -04:00
|
|
|
AutomationStreamView::redisplay_track ()
|
2007-09-05 22:30:39 -04:00
|
|
|
{
|
2009-02-15 15:31:05 -05:00
|
|
|
// Flag region views as invalid and disable drawing
|
2011-02-17 11:18:15 -05:00
|
|
|
for (list<RegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
|
2007-09-05 22:30:39 -04:00
|
|
|
(*i)->set_valid (false);
|
2009-02-15 15:31:05 -05:00
|
|
|
(*i)->enable_display(false);
|
2009-01-27 23:55:31 -05:00
|
|
|
}
|
2009-02-15 15:31:05 -05:00
|
|
|
|
|
|
|
// Add and display region views, and flag them as valid
|
2009-07-09 13:58:13 -04:00
|
|
|
if (_trackview.is_track()) {
|
2010-04-21 16:42:22 -04:00
|
|
|
_trackview.track()->playlist()->foreach_region (
|
2009-06-08 15:28:51 -04:00
|
|
|
sigc::hide_return (sigc::mem_fun (*this, &StreamView::add_region_view))
|
2009-06-02 20:23:34 -04:00
|
|
|
);
|
2007-09-05 22:30:39 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-02-15 15:31:05 -05:00
|
|
|
// Stack regions by layer, and remove invalid regions
|
|
|
|
layer_regions();
|
2007-09-05 22:30:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
AutomationStreamView::setup_rec_box ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AutomationStreamView::color_handler ()
|
|
|
|
{
|
2014-12-16 00:05:45 -05:00
|
|
|
if (_trackview.is_midi_track()) {
|
|
|
|
canvas_rect->set_fill_color (ARDOUR_UI::config()->color_mod ("midi track base", "midi track base"));
|
|
|
|
} else {
|
|
|
|
canvas_rect->set_fill_color (ARDOUR_UI::config()->color ("midi bus base"));
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2007-09-05 22:30:39 -04:00
|
|
|
}
|
|
|
|
|
2010-05-21 21:33:13 -04:00
|
|
|
AutoState
|
|
|
|
AutomationStreamView::automation_state () const
|
|
|
|
{
|
|
|
|
if (region_views.empty()) {
|
2010-06-25 16:47:09 -04:00
|
|
|
return _pending_automation_state;
|
2010-05-21 21:33:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<AutomationLine> line = ((AutomationRegionView*) region_views.front())->line ();
|
|
|
|
if (!line || !line->the_list()) {
|
|
|
|
return Off;
|
|
|
|
}
|
|
|
|
|
|
|
|
return line->the_list()->automation_state ();
|
|
|
|
}
|
2010-05-25 11:51:32 -04:00
|
|
|
|
|
|
|
bool
|
|
|
|
AutomationStreamView::has_automation () const
|
|
|
|
{
|
2010-08-05 09:35:43 -04:00
|
|
|
list<boost::shared_ptr<AutomationLine> > lines = get_lines ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-08-05 09:35:43 -04:00
|
|
|
for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
|
|
|
|
if ((*i)->npoints() > 0) {
|
2010-05-25 11:51:32 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-13 20:58:15 -04:00
|
|
|
/** Our parent AutomationTimeAxisView calls this when the user requests a particular
|
|
|
|
* InterpolationStyle; tell the AutomationLists in our regions.
|
|
|
|
*/
|
2010-05-25 12:40:35 -04:00
|
|
|
void
|
|
|
|
AutomationStreamView::set_interpolation (AutomationList::InterpolationStyle s)
|
|
|
|
{
|
2010-08-05 09:35:43 -04:00
|
|
|
list<boost::shared_ptr<AutomationLine> > lines = get_lines ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-08-05 09:35:43 -04:00
|
|
|
for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
|
|
|
|
(*i)->the_list()->set_interpolation (s);
|
2010-07-13 20:58:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AutomationList::InterpolationStyle
|
|
|
|
AutomationStreamView::interpolation () const
|
|
|
|
{
|
|
|
|
if (region_views.empty()) {
|
|
|
|
return AutomationList::Linear;
|
2010-05-25 12:40:35 -04:00
|
|
|
}
|
2010-07-13 20:58:15 -04:00
|
|
|
|
|
|
|
AutomationRegionView* v = dynamic_cast<AutomationRegionView*> (region_views.front());
|
2013-01-19 02:00:43 -05:00
|
|
|
if (v) {
|
|
|
|
return v->line()->the_list()->interpolation ();
|
|
|
|
}
|
2013-01-19 03:55:19 -05:00
|
|
|
return AutomationList::Linear;
|
2010-05-25 12:40:35 -04:00
|
|
|
}
|
2010-07-30 20:44:26 -04:00
|
|
|
|
|
|
|
/** Clear all automation displayed in this view */
|
|
|
|
void
|
|
|
|
AutomationStreamView::clear ()
|
|
|
|
{
|
2010-08-05 09:35:43 -04:00
|
|
|
list<boost::shared_ptr<AutomationLine> > lines = get_lines ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-08-05 09:35:43 -04:00
|
|
|
for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
|
|
|
|
(*i)->clear ();
|
2010-07-30 20:44:26 -04:00
|
|
|
}
|
|
|
|
}
|
2010-08-04 11:41:55 -04:00
|
|
|
|
2010-08-05 09:36:38 -04:00
|
|
|
/** @param start Start position in session frames.
|
|
|
|
* @param end End position in session frames.
|
2010-08-06 19:28:44 -04:00
|
|
|
* @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.
|
2010-08-05 09:36:38 -04:00
|
|
|
*/
|
2010-08-04 11:41:55 -04:00
|
|
|
void
|
2010-08-05 09:36:38 -04:00
|
|
|
AutomationStreamView::get_selectables (framepos_t start, framepos_t end, double botfrac, double topfrac, list<Selectable*>& results)
|
2010-08-04 11:41:55 -04:00
|
|
|
{
|
|
|
|
for (list<RegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
|
|
|
|
AutomationRegionView* arv = dynamic_cast<AutomationRegionView*> (*i);
|
2014-12-17 19:43:09 -05:00
|
|
|
if (arv) {
|
|
|
|
arv->line()->get_selectables (start, end, botfrac, topfrac, results);
|
|
|
|
}
|
2010-08-04 11:41:55 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AutomationStreamView::set_selected_points (PointSelection& ps)
|
|
|
|
{
|
2010-08-05 09:35:43 -04:00
|
|
|
list<boost::shared_ptr<AutomationLine> > lines = get_lines ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-08-05 09:35:43 -04:00
|
|
|
for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
|
|
|
|
(*i)->set_selected_points (ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list<boost::shared_ptr<AutomationLine> >
|
|
|
|
AutomationStreamView::get_lines () const
|
|
|
|
{
|
|
|
|
list<boost::shared_ptr<AutomationLine> > lines;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-08-05 09:35:43 -04:00
|
|
|
for (list<RegionView*>::const_iterator i = region_views.begin(); i != region_views.end(); ++i) {
|
2010-08-04 11:41:55 -04:00
|
|
|
AutomationRegionView* arv = dynamic_cast<AutomationRegionView*> (*i);
|
2014-12-17 19:43:09 -05:00
|
|
|
if (arv) {
|
|
|
|
lines.push_back (arv->line());
|
|
|
|
}
|
2010-08-04 11:41:55 -04:00
|
|
|
}
|
2010-08-05 09:35:43 -04:00
|
|
|
|
|
|
|
return lines;
|
2010-08-04 11:41:55 -04:00
|
|
|
}
|
2010-08-05 09:36:38 -04:00
|
|
|
|
2014-11-16 17:04:27 -05:00
|
|
|
bool
|
|
|
|
AutomationStreamView::paste (framepos_t pos,
|
|
|
|
unsigned paste_count,
|
|
|
|
float times,
|
|
|
|
boost::shared_ptr<ARDOUR::AutomationList> alist)
|
2010-08-05 09:36:38 -04:00
|
|
|
{
|
|
|
|
/* XXX: not sure how best to pick this; for now, just use the last region which starts before pos */
|
|
|
|
|
|
|
|
if (region_views.empty()) {
|
2014-11-16 17:04:27 -05:00
|
|
|
return false;
|
2010-08-05 09:36:38 -04:00
|
|
|
}
|
|
|
|
|
2014-12-16 14:37:40 -05:00
|
|
|
region_views.sort (RegionView::PositionOrder());
|
2010-08-05 09:36:38 -04:00
|
|
|
|
|
|
|
list<RegionView*>::const_iterator prev = region_views.begin ();
|
|
|
|
|
|
|
|
for (list<RegionView*>::const_iterator i = region_views.begin(); i != region_views.end(); ++i) {
|
|
|
|
if ((*i)->region()->position() > pos) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<Region> r = (*prev)->region ();
|
|
|
|
|
|
|
|
/* If *prev doesn't cover pos, it's no good */
|
|
|
|
if (r->position() > pos || ((r->position() + r->length()) < pos)) {
|
2014-12-06 12:19:52 -05:00
|
|
|
return false;
|
2010-08-05 09:36:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
AutomationRegionView* arv = dynamic_cast<AutomationRegionView*> (*prev);
|
2014-11-16 17:04:27 -05:00
|
|
|
return arv ? arv->paste(pos, paste_count, times, alist) : false;
|
2010-08-05 09:36:38 -04:00
|
|
|
}
|