2023-01-08 11:52:20 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2022 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 <utility>
|
|
|
|
|
|
|
|
#include "pbd/memento_command.h"
|
|
|
|
|
|
|
|
#include "ardour/automation_control.h"
|
|
|
|
#include "ardour/event_type_map.h"
|
|
|
|
#include "ardour/midi_automation_list_binder.h"
|
|
|
|
#include "ardour/midi_region.h"
|
|
|
|
#include "ardour/midi_track.h"
|
|
|
|
#include "ardour/session.h"
|
|
|
|
|
|
|
|
#include "gtkmm2ext/keyboard.h"
|
2023-06-22 19:31:53 -04:00
|
|
|
#include "gtkmm2ext/utils.h"
|
2023-01-08 11:52:20 -05:00
|
|
|
|
2023-01-10 23:41:47 -05:00
|
|
|
#include "canvas/lollipop.h"
|
|
|
|
|
2023-01-08 11:52:20 -05:00
|
|
|
#include "velocity_ghost_region.h"
|
|
|
|
#include "editing.h"
|
|
|
|
#include "editor.h"
|
|
|
|
#include "editor_drag.h"
|
|
|
|
#include "gui_thread.h"
|
|
|
|
#include "midi_automation_line.h"
|
2023-06-20 15:47:12 -04:00
|
|
|
#include "midi_region_view.h"
|
2023-01-10 23:41:47 -05:00
|
|
|
#include "note_base.h"
|
2023-01-08 11:52:20 -05:00
|
|
|
#include "public_editor.h"
|
|
|
|
#include "ui_config.h"
|
2023-06-21 19:32:52 -04:00
|
|
|
#include "verbose_cursor.h"
|
2023-01-08 11:52:20 -05:00
|
|
|
|
|
|
|
#include "pbd/i18n.h"
|
|
|
|
|
|
|
|
using namespace Temporal;
|
|
|
|
|
2023-01-11 13:51:03 -05:00
|
|
|
static double const lollipop_radius = 8.0;
|
|
|
|
|
2023-01-08 11:52:20 -05:00
|
|
|
VelocityGhostRegion::VelocityGhostRegion (MidiRegionView& mrv, TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos)
|
|
|
|
: MidiGhostRegion (mrv, tv, source_tv, initial_unit_pos)
|
2023-06-22 19:31:53 -04:00
|
|
|
, dragging (false)
|
2023-06-23 18:47:29 -04:00
|
|
|
, dragging_line (nullptr)
|
|
|
|
, last_drag_x (-1)
|
2023-06-24 14:42:30 -04:00
|
|
|
, drag_did_change (false)
|
2023-06-26 15:27:19 -04:00
|
|
|
, selected (false)
|
2023-01-08 11:52:20 -05:00
|
|
|
{
|
2023-07-10 19:32:18 -04:00
|
|
|
base_rect->set_data (X_("ghostregionview"), this);
|
2023-06-22 19:31:53 -04:00
|
|
|
base_rect->Event.connect (sigc::mem_fun (*this, &VelocityGhostRegion::base_event));
|
2023-06-25 15:09:39 -04:00
|
|
|
base_rect->set_fill_color (UIConfiguration::instance().color_mod ("ghost track base", "ghost track midi fill"));
|
2023-06-24 23:28:03 -04:00
|
|
|
base_rect->set_outline_color (UIConfiguration::instance().color ("automation track outline"));
|
|
|
|
base_rect->set_outline (true);
|
|
|
|
base_rect->set_outline_what (ArdourCanvas::Rectangle::What (ArdourCanvas::Rectangle::LEFT|ArdourCanvas::Rectangle::RIGHT));
|
2023-01-08 11:52:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VelocityGhostRegion::~VelocityGhostRegion ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-06-22 19:31:53 -04:00
|
|
|
bool
|
2023-07-10 19:32:18 -04:00
|
|
|
VelocityGhostRegion::line_draw_motion (ArdourCanvas::Duple const & d, ArdourCanvas::Rectangle const & r, double last_x)
|
2023-06-22 19:31:53 -04:00
|
|
|
{
|
|
|
|
std::vector<NoteBase*> affected_lollis;
|
|
|
|
MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (&parent_rv);
|
2023-07-10 19:32:18 -04:00
|
|
|
|
|
|
|
if (last_x < 0) {
|
|
|
|
lollis_close_to_x (d.x, 20., affected_lollis);
|
|
|
|
} else if (last_x < d.x) {
|
|
|
|
/* rightward, "later" motion */
|
|
|
|
lollis_between (last_x, d.x, affected_lollis);
|
|
|
|
} else {
|
|
|
|
/* leftward, "earlier" motion */
|
|
|
|
lollis_between (d.x, last_x, affected_lollis);
|
2023-06-22 19:31:53 -04:00
|
|
|
}
|
|
|
|
|
2023-07-10 19:32:18 -04:00
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if (!affected_lollis.empty()) {
|
|
|
|
int velocity = y_position_to_velocity (r.height() - (r.y1() - d.y));
|
|
|
|
ret = mrv->set_velocity_for_notes (affected_lollis, velocity);
|
|
|
|
mrv->mid_drag_edit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2023-06-26 15:27:19 -04:00
|
|
|
|
2023-07-10 19:32:18 -04:00
|
|
|
bool
|
|
|
|
VelocityGhostRegion::base_event (GdkEvent* ev)
|
|
|
|
{
|
|
|
|
return trackview.editor().canvas_velocity_base_event (ev, base_rect);
|
2023-06-22 19:31:53 -04:00
|
|
|
}
|
|
|
|
|
2023-01-08 11:52:20 -05:00
|
|
|
void
|
2023-01-10 23:41:47 -05:00
|
|
|
VelocityGhostRegion::update_contents_height ()
|
|
|
|
{
|
2023-01-12 19:06:43 -05:00
|
|
|
for (auto const & i : events) {
|
|
|
|
set_size_and_position (*i.second);
|
2023-01-10 23:41:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-12 19:06:43 -05:00
|
|
|
bool
|
|
|
|
VelocityGhostRegion::lollevent (GdkEvent* ev, MidiGhostRegion::GhostEvent* gev)
|
|
|
|
{
|
|
|
|
return trackview.editor().canvas_velocity_event (ev, gev->item);
|
|
|
|
}
|
|
|
|
|
2023-01-10 23:41:47 -05:00
|
|
|
void
|
2023-01-15 17:37:42 -05:00
|
|
|
VelocityGhostRegion::add_note (NoteBase* nb)
|
2023-01-08 11:52:20 -05:00
|
|
|
{
|
2023-01-10 23:41:47 -05:00
|
|
|
ArdourCanvas::Lollipop* l = new ArdourCanvas::Lollipop (_note_group);
|
2023-06-21 18:18:18 -04:00
|
|
|
l->set_bounding_parent (base_rect);
|
2023-01-12 19:06:43 -05:00
|
|
|
|
2023-01-15 17:37:42 -05:00
|
|
|
GhostEvent* event = new GhostEvent (nb, _note_group, l);
|
|
|
|
events.insert (std::make_pair (nb->note(), event));
|
2023-09-21 18:26:22 -04:00
|
|
|
_optimization_iterator = events.end();
|
2023-06-24 23:28:03 -04:00
|
|
|
|
2023-01-12 19:06:43 -05:00
|
|
|
l->Event.connect (sigc::bind (sigc::mem_fun (*this, &VelocityGhostRegion::lollevent), event));
|
2023-06-22 19:31:53 -04:00
|
|
|
l->set_ignore_events (true);
|
2023-01-12 19:06:43 -05:00
|
|
|
l->raise_to_top ();
|
2023-06-20 13:28:59 -04:00
|
|
|
l->set_data (X_("ghostregionview"), this);
|
|
|
|
l->set_data (X_("note"), nb);
|
2023-06-24 23:28:03 -04:00
|
|
|
l->set_fill_color (nb->base_color());
|
|
|
|
l->set_outline_color (_outline);
|
2023-01-10 23:41:47 -05:00
|
|
|
|
|
|
|
MidiStreamView* mv = midi_view();
|
|
|
|
|
|
|
|
if (mv) {
|
2023-01-15 17:37:42 -05:00
|
|
|
if (!nb->item()->visible()) {
|
2023-01-11 13:51:03 -05:00
|
|
|
l->hide();
|
2023-01-10 23:41:47 -05:00
|
|
|
} else {
|
2023-01-12 19:06:43 -05:00
|
|
|
set_size_and_position (*event);
|
2023-01-10 23:41:47 -05:00
|
|
|
}
|
|
|
|
}
|
2023-01-08 11:52:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-01-12 19:06:43 -05:00
|
|
|
VelocityGhostRegion::set_size_and_position (GhostEvent& ev)
|
|
|
|
{
|
|
|
|
ArdourCanvas::Lollipop* l = dynamic_cast<ArdourCanvas::Lollipop*> (ev.item);
|
2023-06-21 18:18:18 -04:00
|
|
|
const double available_height = base_rect->y1();
|
2023-01-12 19:06:43 -05:00
|
|
|
const double actual_height = (ev.event->note()->velocity() / 127.0) * available_height;
|
2023-09-08 18:16:15 -04:00
|
|
|
l->set (ArdourCanvas::Duple (ev.event->x0() + lollipop_radius, base_rect->y1() - actual_height), actual_height, lollipop_radius);
|
2023-01-12 19:06:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-06-21 19:32:52 -04:00
|
|
|
VelocityGhostRegion::update_note (GhostEvent* gev)
|
2023-01-08 11:52:20 -05:00
|
|
|
{
|
2023-06-21 19:32:52 -04:00
|
|
|
set_size_and_position (*gev);
|
|
|
|
gev->item->set_fill_color (gev->event->base_color());
|
2023-01-08 11:52:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-06-21 19:32:52 -04:00
|
|
|
VelocityGhostRegion::update_hit (GhostEvent* gev)
|
2023-01-08 11:52:20 -05:00
|
|
|
{
|
2023-06-21 19:32:52 -04:00
|
|
|
set_size_and_position (*gev);
|
|
|
|
gev->item->set_fill_color (gev->event->base_color());
|
2023-01-08 11:52:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-06-26 18:28:32 -04:00
|
|
|
VelocityGhostRegion::remove_note (NoteBase* nb)
|
2023-01-08 11:52:20 -05:00
|
|
|
{
|
2023-06-26 18:28:32 -04:00
|
|
|
MidiGhostRegion::remove_note (nb);
|
2023-01-08 11:52:20 -05:00
|
|
|
}
|
|
|
|
|
2023-01-11 13:51:03 -05:00
|
|
|
void
|
|
|
|
VelocityGhostRegion::set_colors ()
|
|
|
|
{
|
2023-06-27 11:19:29 -04:00
|
|
|
if (selected) {
|
|
|
|
base_rect->set_fill_color (UIConfiguration::instance().color ("ghost track base"));
|
|
|
|
} else {
|
|
|
|
base_rect->set_fill_color (UIConfiguration::instance().color_mod ("ghost track base", "ghost track midi fill"));
|
|
|
|
}
|
2023-06-21 19:32:52 -04:00
|
|
|
|
|
|
|
for (auto & gev : events) {
|
2023-06-27 11:19:29 -04:00
|
|
|
gev.second->item->set_fill_color (gev.second->event->base_color());
|
2023-06-21 19:32:52 -04:00
|
|
|
}
|
2023-01-11 13:51:03 -05:00
|
|
|
}
|
2023-06-20 13:28:59 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
VelocityGhostRegion::drag_lolli (ArdourCanvas::Lollipop* l, GdkEventMotion* ev)
|
|
|
|
{
|
2023-06-21 18:18:18 -04:00
|
|
|
ArdourCanvas::Rect r (base_rect->item_to_canvas (base_rect->get()));
|
2023-06-20 13:28:59 -04:00
|
|
|
|
2023-06-20 15:47:12 -04:00
|
|
|
/* translate event y-coord so that zero matches the top of base_rect
|
|
|
|
* (event coordinates use window coordinate space)
|
|
|
|
*/
|
2023-06-20 13:28:59 -04:00
|
|
|
|
|
|
|
ev->y -= r.y0;
|
|
|
|
|
|
|
|
/* clamp y to be within the range defined by the base_rect height minus
|
2023-06-20 15:47:12 -04:00
|
|
|
* the lollipop radius at top and bottom
|
2023-06-20 13:28:59 -04:00
|
|
|
*/
|
|
|
|
|
2023-06-21 18:18:18 -04:00
|
|
|
const double effective_y = std::max (0.0, std::min (r.height(), ev->y));
|
|
|
|
const double newlen = r.height() - effective_y;
|
2023-06-20 15:47:12 -04:00
|
|
|
const double delta = newlen - l->length();
|
2023-06-20 13:28:59 -04:00
|
|
|
|
2023-06-20 15:47:12 -04:00
|
|
|
MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (&parent_rv);
|
|
|
|
assert (mrv);
|
2023-06-20 16:42:43 -04:00
|
|
|
|
|
|
|
/* This will redraw the velocity bars for the selected notes, without
|
|
|
|
* changing the note velocities.
|
|
|
|
*/
|
|
|
|
|
2023-06-21 18:18:18 -04:00
|
|
|
const double factor = newlen / base_rect->height();
|
2023-06-20 16:42:43 -04:00
|
|
|
mrv->sync_velocity_drag (factor);
|
|
|
|
|
2023-06-20 15:47:12 -04:00
|
|
|
MidiRegionView::Selection const & sel (mrv->selection());
|
2023-06-21 19:32:52 -04:00
|
|
|
int verbose_velocity = -1;
|
|
|
|
GhostEvent* primary_ghost = 0;
|
2023-06-20 13:28:59 -04:00
|
|
|
|
2023-06-20 15:47:12 -04:00
|
|
|
for (auto & s : sel) {
|
|
|
|
GhostEvent* x = find_event (s->note());
|
2023-06-20 13:28:59 -04:00
|
|
|
|
2023-06-20 15:47:12 -04:00
|
|
|
if (x) {
|
2023-06-21 19:32:52 -04:00
|
|
|
ArdourCanvas::Lollipop* lolli = dynamic_cast<ArdourCanvas::Lollipop*> (x->item);
|
|
|
|
lolli->set (ArdourCanvas::Duple (lolli->x(), lolli->y0() - delta), lolli->length() + delta, lollipop_radius);
|
|
|
|
/* note: length is now set to the new value */
|
|
|
|
const int newvel = floor (127. * (l->length() / r.height()));
|
|
|
|
/* since we're not actually changing the note velocity
|
|
|
|
(yet), we have to use the static method to compute
|
|
|
|
the color.
|
|
|
|
*/
|
|
|
|
lolli->set_fill_color (NoteBase::base_color (newvel, mrv->color_mode(), mrv->midi_stream_view()->get_region_color(), x->event->note()->channel(), true));
|
|
|
|
|
|
|
|
if (l == lolli) {
|
|
|
|
/* This is the value we will display */
|
|
|
|
verbose_velocity = newvel;
|
|
|
|
primary_ghost = x;
|
|
|
|
}
|
2023-06-20 15:47:12 -04:00
|
|
|
}
|
|
|
|
}
|
2023-06-21 19:32:52 -04:00
|
|
|
|
|
|
|
assert (verbose_velocity >= 0);
|
|
|
|
char buf[128];
|
|
|
|
const int oldvel = primary_ghost->event->note()->velocity();
|
|
|
|
|
|
|
|
if (verbose_velocity > oldvel) {
|
|
|
|
snprintf (buf, sizeof (buf), "Velocity %d (+%d)", verbose_velocity, verbose_velocity - oldvel);
|
|
|
|
} else if (verbose_velocity == oldvel) {
|
|
|
|
snprintf (buf, sizeof (buf), "Velocity %d", verbose_velocity);
|
|
|
|
} else {
|
|
|
|
snprintf (buf, sizeof (buf), "Velocity %d (%d)", verbose_velocity, verbose_velocity - oldvel);
|
|
|
|
}
|
|
|
|
|
|
|
|
trackview.editor().verbose_cursor()->set (buf);
|
|
|
|
trackview.editor().verbose_cursor()->show ();
|
|
|
|
trackview.editor().verbose_cursor()->set_offset (ArdourCanvas::Duple (10., 10.));
|
2023-06-20 13:28:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
VelocityGhostRegion::y_position_to_velocity (double y) const
|
|
|
|
{
|
|
|
|
const ArdourCanvas::Rect r (base_rect->get());
|
|
|
|
int velocity;
|
|
|
|
|
2023-06-21 18:18:18 -04:00
|
|
|
if (y >= r.height()) {
|
2023-06-20 13:28:59 -04:00
|
|
|
velocity = 0;
|
2023-06-21 18:18:18 -04:00
|
|
|
} else if (y <= 0.) {
|
2023-06-20 13:28:59 -04:00
|
|
|
velocity = 127;
|
|
|
|
} else {
|
2023-06-21 18:18:18 -04:00
|
|
|
velocity = floor (127. * (1.0 - (y / r.height())));
|
2023-06-20 13:28:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return velocity;
|
|
|
|
}
|
2023-06-22 14:30:22 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
VelocityGhostRegion::note_selected (NoteBase* ev)
|
|
|
|
{
|
|
|
|
GhostEvent* gev = find_event (ev->note());
|
|
|
|
|
|
|
|
if (!gev) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArdourCanvas::Lollipop* lolli = dynamic_cast<ArdourCanvas::Lollipop*> (gev->item);
|
|
|
|
lolli->set_outline_color (ev->selected() ? UIConfiguration::instance().color ("midi note selected outline") : 0x000000ff);
|
2023-06-27 16:07:31 -04:00
|
|
|
lolli->raise_to_top();
|
2023-06-22 14:30:22 -04:00
|
|
|
}
|
|
|
|
|
2023-06-23 18:47:29 -04:00
|
|
|
void
|
|
|
|
VelocityGhostRegion::lollis_between (int x0, int x1, std::vector<NoteBase*>& within)
|
|
|
|
{
|
|
|
|
for (auto & gev : events) {
|
|
|
|
ArdourCanvas::Lollipop* l = dynamic_cast<ArdourCanvas::Lollipop*> (gev.second->item);
|
|
|
|
if (l) {
|
|
|
|
ArdourCanvas::Duple pos = l->item_to_canvas (ArdourCanvas::Duple (l->x(), l->y0()));
|
|
|
|
if (pos.x >= x0 && pos.x < x1) {
|
|
|
|
within.push_back (gev.second->event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-22 19:31:53 -04:00
|
|
|
void
|
|
|
|
VelocityGhostRegion::lollis_close_to_x (int x, double distance, std::vector<NoteBase*>& within)
|
|
|
|
{
|
|
|
|
for (auto & gev : events) {
|
|
|
|
ArdourCanvas::Lollipop* l = dynamic_cast<ArdourCanvas::Lollipop*> (gev.second->item);
|
|
|
|
if (l) {
|
|
|
|
ArdourCanvas::Duple pos = l->item_to_canvas (ArdourCanvas::Duple (l->x(), l->y0()));
|
|
|
|
if (std::abs (pos.x - x) < distance) {
|
|
|
|
within.push_back (gev.second->event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-10 19:32:18 -04:00
|
|
|
void
|
|
|
|
VelocityGhostRegion::start_line_drag ()
|
|
|
|
{
|
|
|
|
MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (&parent_rv);
|
|
|
|
mrv->begin_drag_edit (_("draw velocities"));
|
|
|
|
desensitize_lollis ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VelocityGhostRegion::end_line_drag (bool did_change)
|
|
|
|
{
|
|
|
|
MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (&parent_rv);
|
|
|
|
mrv->end_drag_edit (did_change);
|
|
|
|
sensitize_lollis ();
|
|
|
|
}
|
|
|
|
|
2023-06-22 19:31:53 -04:00
|
|
|
void
|
|
|
|
VelocityGhostRegion::desensitize_lollis ()
|
|
|
|
{
|
|
|
|
for (auto & gev : events) {
|
|
|
|
gev.second->item->set_ignore_events (true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VelocityGhostRegion::sensitize_lollis ()
|
|
|
|
{
|
|
|
|
for (auto & gev : events) {
|
|
|
|
gev.second->item->set_ignore_events (false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-26 15:27:19 -04:00
|
|
|
void
|
|
|
|
VelocityGhostRegion::set_selected (bool yn)
|
|
|
|
{
|
|
|
|
selected = yn;
|
|
|
|
set_colors ();
|
2023-06-27 11:19:29 -04:00
|
|
|
|
|
|
|
if (yn) {
|
|
|
|
group->raise_to_top ();
|
2023-07-10 19:32:18 -04:00
|
|
|
}
|
2023-06-26 15:27:19 -04:00
|
|
|
}
|