2023-09-30 13:09:01 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2023 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "ardour/session.h"
|
|
|
|
|
2024-09-20 22:00:46 -04:00
|
|
|
#include "editor_automation_line.h"
|
2023-10-18 18:46:32 -04:00
|
|
|
#include "editing_context.h"
|
2023-09-30 13:09:01 -04:00
|
|
|
#include "mergeable_line.h"
|
|
|
|
#include "route_time_axis.h"
|
|
|
|
#include "selectable.h"
|
|
|
|
#include "ui_config.h"
|
|
|
|
|
|
|
|
#include "pbd/i18n.h"
|
|
|
|
|
|
|
|
using namespace ARDOUR;
|
|
|
|
|
|
|
|
void
|
2023-10-18 18:46:32 -04:00
|
|
|
MergeableLine::merge_drawn_line (EditingContext& e, Session& s, Evoral::ControlList::OrderedPoints& points, bool thin)
|
2023-09-30 13:09:01 -04:00
|
|
|
{
|
|
|
|
if (points.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_line) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<AutomationList> list = _line->the_list ();
|
|
|
|
|
|
|
|
if (list->in_write_pass()) {
|
|
|
|
/* do not allow the GUI to add automation events during an
|
|
|
|
automation write pass.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode& before = list->get_state();
|
|
|
|
std::list<Selectable*> results;
|
|
|
|
|
|
|
|
/* If necessary convert all point times. This is necessary
|
|
|
|
for region-based automation data, because the time values for the
|
|
|
|
points drawn are in absolute time, but the ControlList expects data
|
|
|
|
in source-reference time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (time_filter) {
|
|
|
|
for (auto & p : points) {
|
|
|
|
p.when = time_filter (p.when);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Temporal::timepos_t earliest = points.front().when;
|
|
|
|
Temporal::timepos_t latest = points.back().when;
|
|
|
|
|
|
|
|
if (earliest > latest) {
|
|
|
|
std::swap (earliest, latest);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert each point's "value" from geometric coordinate space to
|
|
|
|
* value space for the control
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (auto & dp : points) {
|
|
|
|
/* compute vertical fractional position */
|
|
|
|
dp.value = 1.0 - (dp.value / _line->height());
|
|
|
|
/* map using line */
|
|
|
|
_line->view_to_model_coord_y (dp.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
list->freeze ();
|
2024-07-11 18:48:14 -04:00
|
|
|
list->editor_add_ordered (points, true);
|
2023-09-30 13:09:01 -04:00
|
|
|
if (thin) {
|
|
|
|
list->thin (Config->get_automation_thinning_factor());
|
|
|
|
}
|
|
|
|
list->thaw ();
|
|
|
|
|
2023-10-02 15:23:52 -04:00
|
|
|
if (automation_state_callback && _control && _control->automation_state () == ARDOUR::Off) {
|
2023-09-30 13:09:01 -04:00
|
|
|
automation_state_callback (ARDOUR::Play);
|
|
|
|
}
|
|
|
|
|
2023-10-02 15:23:52 -04:00
|
|
|
if (control_touched_callback && UIConfiguration::instance().get_automation_edit_cancels_auto_hide () && _control == s.recently_touched_controllable ()) {
|
2023-09-30 13:09:01 -04:00
|
|
|
control_touched_callback ();
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode& after = list->get_state();
|
|
|
|
e.begin_reversible_command (_("draw automation"));
|
2024-10-07 18:28:54 -04:00
|
|
|
e.add_command (new MementoCommand<ARDOUR::AutomationList> (*list.get (), &before, &after));
|
2023-09-30 13:09:01 -04:00
|
|
|
|
2024-04-14 13:37:09 -04:00
|
|
|
_line->end_draw_merge ();
|
|
|
|
|
2023-09-30 13:09:01 -04:00
|
|
|
_line->get_selectables (earliest, latest, 0.0, 1.0, results);
|
|
|
|
e.get_selection ().set (results);
|
|
|
|
|
|
|
|
e.commit_reversible_command ();
|
|
|
|
s.set_dirty ();
|
|
|
|
}
|