2007-04-26 16:54:31 -04:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 2000-2007 Paul Davis
|
2007-04-26 16:54:31 -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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2015-01-02 09:44:54 -05:00
|
|
|
#include "ardour/parameter_descriptor.h"
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "evoral/Note.hpp"
|
2014-06-22 11:41:05 -04:00
|
|
|
#include "canvas/container.h"
|
2014-12-28 21:31:33 -05:00
|
|
|
#include "canvas/polygon.h"
|
2013-04-04 00:32:52 -04:00
|
|
|
#include "canvas/rectangle.h"
|
|
|
|
#include "canvas/wave_view.h"
|
2013-04-24 15:42:14 -04:00
|
|
|
#include "canvas/debug.h"
|
|
|
|
|
2009-02-15 18:47:09 -05:00
|
|
|
#include "automation_time_axis.h"
|
|
|
|
#include "ghostregion.h"
|
|
|
|
#include "midi_streamview.h"
|
|
|
|
#include "midi_time_axis.h"
|
|
|
|
#include "rgb_macros.h"
|
2013-04-04 00:32:52 -04:00
|
|
|
#include "note.h"
|
2014-12-28 21:31:33 -05:00
|
|
|
#include "hit.h"
|
2015-01-02 09:44:54 -05:00
|
|
|
#include "ui_config.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2009-05-12 13:03:42 -04:00
|
|
|
using namespace std;
|
2005-09-25 14:42:24 -04:00
|
|
|
using namespace Editing;
|
2005-11-22 00:10:12 -05:00
|
|
|
using namespace ArdourCanvas;
|
2007-06-15 18:08:27 -04:00
|
|
|
using namespace ARDOUR;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2009-12-22 15:21:43 -05:00
|
|
|
PBD::Signal1<void,GhostRegion*> GhostRegion::CatchDeletion;
|
2009-12-17 13:24:23 -05:00
|
|
|
|
2014-06-22 11:41:05 -04:00
|
|
|
GhostRegion::GhostRegion (ArdourCanvas::Container* parent, TimeAxisView& tv, TimeAxisView& source_tv, double initial_pos)
|
2008-02-10 13:16:25 -05:00
|
|
|
: trackview (tv)
|
|
|
|
, source_trackview (source_tv)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2014-06-22 11:41:05 -04:00
|
|
|
group = new ArdourCanvas::Container (parent);
|
2013-11-03 10:07:00 -05:00
|
|
|
CANVAS_DEBUG_NAME (group, "ghost region");
|
2014-09-04 10:14:01 -04:00
|
|
|
group->set_position (ArdourCanvas::Duple (initial_pos, 0));
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2015-02-11 21:56:44 -05:00
|
|
|
base_rect = new ArdourCanvas::Rectangle (group);
|
2013-04-24 15:42:14 -04:00
|
|
|
CANVAS_DEBUG_NAME (base_rect, "ghost region rect");
|
2013-04-04 00:32:52 -04:00
|
|
|
base_rect->set_x0 (0);
|
2014-11-07 12:57:22 -05:00
|
|
|
base_rect->set_y0 (1.0);
|
|
|
|
base_rect->set_y1 (trackview.current_height());
|
|
|
|
base_rect->set_outline (false);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2008-02-21 20:45:29 -05:00
|
|
|
if (!is_automation_ghost()) {
|
2008-02-10 13:16:25 -05:00
|
|
|
base_rect->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
GhostRegion::set_colors();
|
|
|
|
|
|
|
|
/* the parent group of a ghostregion is a dedicated group for ghosts,
|
|
|
|
so the new ghost would want to get to the top of that group*/
|
|
|
|
group->raise_to_top ();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
GhostRegion::~GhostRegion ()
|
|
|
|
{
|
2009-12-22 15:21:43 -05:00
|
|
|
CatchDeletion (this);
|
2005-11-22 00:10:12 -05:00
|
|
|
delete base_rect;
|
2008-10-02 16:25:28 -04:00
|
|
|
delete group;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-10 13:16:25 -05:00
|
|
|
GhostRegion::set_duration (double units)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2013-04-04 00:32:52 -04:00
|
|
|
base_rect->set_x1 (units);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-10 13:16:25 -05:00
|
|
|
GhostRegion::set_height ()
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2013-04-04 00:32:52 -04:00
|
|
|
base_rect->set_y1 (trackview.current_height());
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-10 13:16:25 -05:00
|
|
|
GhostRegion::set_colors ()
|
|
|
|
{
|
2008-02-21 20:45:29 -05:00
|
|
|
if (is_automation_ghost()) {
|
2015-01-02 09:44:54 -05:00
|
|
|
base_rect->set_fill_color (UIConfiguration::instance().color_mod ("ghost track base", "ghost track base"));
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
guint
|
2010-12-30 13:35:16 -05:00
|
|
|
GhostRegion::source_track_color(unsigned char alpha)
|
|
|
|
{
|
2009-07-09 13:58:13 -04:00
|
|
|
Gdk::Color color = source_trackview.color();
|
2010-12-30 13:35:16 -05:00
|
|
|
return RGBA_TO_UINT (color.get_red() / 256, color.get_green() / 256, color.get_blue() / 256, alpha);
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-12-30 13:35:16 -05:00
|
|
|
GhostRegion::is_automation_ghost()
|
|
|
|
{
|
2009-07-09 13:58:13 -04:00
|
|
|
return (dynamic_cast<AutomationTimeAxisView*>(&trackview)) != 0;
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
2009-07-09 13:58:13 -04:00
|
|
|
AudioGhostRegion::AudioGhostRegion(TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos)
|
2010-12-30 13:35:16 -05:00
|
|
|
: GhostRegion(tv.ghost_group(), tv, source_tv, initial_unit_pos)
|
|
|
|
{
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
2013-04-04 18:45:27 -04:00
|
|
|
void
|
2013-04-12 11:31:50 -04:00
|
|
|
AudioGhostRegion::set_samples_per_pixel (double fpp)
|
2008-02-10 13:16:25 -05:00
|
|
|
{
|
|
|
|
for (vector<WaveView*>::iterator i = waves.begin(); i != waves.end(); ++i) {
|
2013-04-12 11:31:50 -04:00
|
|
|
(*i)->set_samples_per_pixel (fpp);
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioGhostRegion::set_height ()
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2005-11-22 00:10:12 -05:00
|
|
|
vector<WaveView*>::iterator i;
|
2005-09-25 14:42:24 -04:00
|
|
|
uint32_t n;
|
|
|
|
|
2008-02-10 13:16:25 -05:00
|
|
|
GhostRegion::set_height();
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
double const ht = ((trackview.current_height()) / (double) waves.size());
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
for (n = 0, i = waves.begin(); i != waves.end(); ++i, ++n) {
|
2013-04-04 00:32:52 -04:00
|
|
|
(*i)->set_height (ht);
|
|
|
|
(*i)->set_y_position (n * ht);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-11 09:07:51 -04:00
|
|
|
void
|
2008-02-10 13:16:25 -05:00
|
|
|
AudioGhostRegion::set_colors ()
|
2007-04-11 09:07:51 -04:00
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
GhostRegion::set_colors();
|
|
|
|
guint fill_color;
|
|
|
|
|
2008-02-21 20:45:29 -05:00
|
|
|
if (is_automation_ghost()) {
|
2015-01-02 09:44:54 -05:00
|
|
|
fill_color = UIConfiguration::instance().color ("ghost track wave fill");
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
fill_color = source_track_color(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t n=0; n < waves.size(); ++n) {
|
2015-01-02 09:44:54 -05:00
|
|
|
waves[n]->set_outline_color (UIConfiguration::instance().color ("ghost track wave"));
|
2013-04-04 00:32:52 -04:00
|
|
|
waves[n]->set_fill_color (fill_color);
|
2015-01-02 09:44:54 -05:00
|
|
|
waves[n]->set_clip_color (UIConfiguration::instance().color ("ghost track wave clip"));
|
|
|
|
waves[n]->set_zero_color (UIConfiguration::instance().color ("ghost track zero line"));
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-30 13:35:16 -05:00
|
|
|
/** The general constructor; called when the destination timeaxisview doesn't have
|
|
|
|
* a midistreamview.
|
|
|
|
*
|
|
|
|
* @param tv TimeAxisView that this ghost region is on.
|
|
|
|
* @param source_tv TimeAxisView that we are the ghost for.
|
2008-02-10 13:16:25 -05:00
|
|
|
*/
|
2009-07-09 13:58:13 -04:00
|
|
|
MidiGhostRegion::MidiGhostRegion(TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos)
|
|
|
|
: GhostRegion(tv.ghost_group(), tv, source_tv, initial_unit_pos)
|
2011-02-27 23:00:38 -05:00
|
|
|
, _optimization_iterator (events.end ())
|
2008-02-21 20:45:29 -05:00
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
base_rect->lower_to_bottom();
|
2010-12-30 13:35:16 -05:00
|
|
|
update_range ();
|
|
|
|
|
|
|
|
midi_view()->NoteRangeChanged.connect (sigc::mem_fun (*this, &MidiGhostRegion::update_range));
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
2010-12-30 13:35:16 -05:00
|
|
|
/**
|
|
|
|
* @param msv MidiStreamView that this ghost region is on.
|
|
|
|
* @param source_tv TimeAxisView that we are the ghost for.
|
|
|
|
*/
|
2009-07-09 13:58:13 -04:00
|
|
|
MidiGhostRegion::MidiGhostRegion(MidiStreamView& msv, TimeAxisView& source_tv, double initial_unit_pos)
|
2008-02-21 20:45:29 -05:00
|
|
|
: GhostRegion(msv.midi_underlay_group, msv.trackview(), source_tv, initial_unit_pos)
|
2011-02-27 23:00:38 -05:00
|
|
|
, _optimization_iterator (events.end ())
|
2008-02-21 20:45:29 -05:00
|
|
|
{
|
2009-10-14 12:10:01 -04:00
|
|
|
base_rect->lower_to_bottom();
|
2010-12-30 13:35:16 -05:00
|
|
|
update_range ();
|
|
|
|
|
|
|
|
midi_view()->NoteRangeChanged.connect (sigc::mem_fun (*this, &MidiGhostRegion::update_range));
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
2008-02-21 20:45:29 -05:00
|
|
|
MidiGhostRegion::~MidiGhostRegion()
|
|
|
|
{
|
2011-02-27 23:14:23 -05:00
|
|
|
clear_events ();
|
2008-02-21 20:45:29 -05:00
|
|
|
}
|
|
|
|
|
2014-06-22 11:41:05 -04:00
|
|
|
MidiGhostRegion::GhostEvent::GhostEvent (NoteBase* e, ArdourCanvas::Container* g)
|
2011-11-17 17:15:56 -05:00
|
|
|
: event (e)
|
2008-02-21 20:45:29 -05:00
|
|
|
{
|
2014-12-28 21:31:33 -05:00
|
|
|
Hit* hit = NULL;
|
|
|
|
if (dynamic_cast<Note*>(e)) {
|
|
|
|
item = new ArdourCanvas::Rectangle(
|
|
|
|
g, ArdourCanvas::Rect(e->x0(), e->y0(), e->x1(), e->y1()));
|
|
|
|
} else if ((hit = dynamic_cast<Hit*>(e))) {
|
|
|
|
ArdourCanvas::Polygon* poly = new ArdourCanvas::Polygon(g);
|
|
|
|
poly->set(Hit::points(e->y1() - e->y0()));
|
|
|
|
poly->set_position(hit->position());
|
|
|
|
item = poly;
|
|
|
|
}
|
|
|
|
|
|
|
|
CANVAS_DEBUG_NAME (item, "ghost note item");
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
2013-04-04 18:45:27 -04:00
|
|
|
MidiGhostRegion::GhostEvent::~GhostEvent ()
|
2008-02-21 20:45:29 -05:00
|
|
|
{
|
2011-11-17 17:15:56 -05:00
|
|
|
/* event is not ours to delete */
|
2014-12-28 21:31:33 -05:00
|
|
|
delete item;
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-04-12 11:31:50 -04:00
|
|
|
MidiGhostRegion::set_samples_per_pixel (double /*spu*/)
|
2008-02-10 13:16:25 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-12-30 13:35:16 -05:00
|
|
|
/** @return MidiStreamView that we are providing a ghost for */
|
2008-02-10 13:16:25 -05:00
|
|
|
MidiStreamView*
|
2010-12-30 13:35:16 -05:00
|
|
|
MidiGhostRegion::midi_view ()
|
2008-02-21 20:45:29 -05:00
|
|
|
{
|
2010-12-30 13:35:16 -05:00
|
|
|
StreamView* sv = source_trackview.view ();
|
|
|
|
assert (sv);
|
|
|
|
MidiStreamView* msv = dynamic_cast<MidiStreamView*> (sv);
|
|
|
|
assert (msv);
|
2008-02-10 13:16:25 -05:00
|
|
|
|
2010-12-30 13:35:16 -05:00
|
|
|
return msv;
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-12-30 13:35:16 -05:00
|
|
|
MidiGhostRegion::set_height ()
|
2008-02-21 20:45:29 -05:00
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
GhostRegion::set_height();
|
|
|
|
update_range();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-21 20:45:29 -05:00
|
|
|
MidiGhostRegion::set_colors()
|
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
GhostRegion::set_colors();
|
|
|
|
|
2008-02-21 20:45:29 -05:00
|
|
|
for (EventList::iterator it = events.begin(); it != events.end(); ++it) {
|
2015-01-02 09:44:54 -05:00
|
|
|
(*it)->item->set_fill_color (UIConfiguration::instance().color_mod((*it)->event->base_color(), "ghost track midi fill"));
|
|
|
|
(*it)->item->set_outline_color (UIConfiguration::instance().color ("ghost track midi outline"));
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-28 21:31:33 -05:00
|
|
|
static double
|
|
|
|
note_height(TimeAxisView& trackview, MidiStreamView* mv)
|
|
|
|
{
|
|
|
|
const double tv_height = trackview.current_height();
|
|
|
|
const double note_range = mv->contents_note_range();
|
|
|
|
|
|
|
|
return std::max(1.0, floor(tv_height / note_range - 1.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
static double
|
|
|
|
note_y(TimeAxisView& trackview, MidiStreamView* mv, uint8_t note_num)
|
|
|
|
{
|
|
|
|
const double tv_height = trackview.current_height();
|
|
|
|
const double note_range = mv->contents_note_range();
|
|
|
|
const double s = tv_height / note_range;
|
|
|
|
|
|
|
|
return tv_height - (note_num + 1 - mv->lowest_note()) * s;
|
|
|
|
}
|
|
|
|
|
2008-02-10 13:16:25 -05:00
|
|
|
void
|
2010-12-30 13:35:16 -05:00
|
|
|
MidiGhostRegion::update_range ()
|
2008-02-21 20:45:29 -05:00
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
MidiStreamView* mv = midi_view();
|
|
|
|
|
2008-02-21 20:45:29 -05:00
|
|
|
if (!mv) {
|
2008-02-10 13:16:25 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-28 21:31:33 -05:00
|
|
|
double const h = note_height(trackview, mv);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-02-21 20:45:29 -05:00
|
|
|
for (EventList::iterator it = events.begin(); it != events.end(); ++it) {
|
2011-11-17 17:15:56 -05:00
|
|
|
uint8_t const note_num = (*it)->event->note()->note();
|
|
|
|
|
|
|
|
if (note_num < mv->lowest_note() || note_num > mv->highest_note()) {
|
2014-12-28 21:31:33 -05:00
|
|
|
(*it)->item->hide();
|
2011-11-17 17:15:56 -05:00
|
|
|
} else {
|
2014-12-28 21:31:33 -05:00
|
|
|
(*it)->item->show();
|
|
|
|
double const y = note_y(trackview, mv, note_num);
|
|
|
|
ArdourCanvas::Rectangle* rect = NULL;
|
|
|
|
ArdourCanvas::Polygon* poly = NULL;
|
|
|
|
if ((rect = dynamic_cast<ArdourCanvas::Rectangle*>((*it)->item))) {
|
|
|
|
rect->set_y0 (y);
|
|
|
|
rect->set_y1 (y + h);
|
|
|
|
} else if ((poly = dynamic_cast<ArdourCanvas::Polygon*>((*it)->item))) {
|
|
|
|
Duple position = poly->position();
|
|
|
|
position.y = y;
|
|
|
|
poly->set_position(position);
|
|
|
|
poly->set(Hit::points(h));
|
|
|
|
}
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-04-04 18:45:27 -04:00
|
|
|
MidiGhostRegion::add_note (NoteBase* n)
|
2008-02-21 20:45:29 -05:00
|
|
|
{
|
2013-04-04 18:45:27 -04:00
|
|
|
GhostEvent* event = new GhostEvent (n, group);
|
2011-11-17 17:15:56 -05:00
|
|
|
events.push_back (event);
|
2008-02-10 13:16:25 -05:00
|
|
|
|
2015-01-02 09:44:54 -05:00
|
|
|
event->item->set_fill_color (UIConfiguration::instance().color_mod(n->base_color(), "ghost track midi fill"));
|
|
|
|
event->item->set_outline_color (UIConfiguration::instance().color ("ghost track midi outline"));
|
2008-02-10 13:16:25 -05:00
|
|
|
|
|
|
|
MidiStreamView* mv = midi_view();
|
|
|
|
|
2008-02-21 20:45:29 -05:00
|
|
|
if (mv) {
|
2014-12-28 21:31:33 -05:00
|
|
|
uint8_t const note_num = n->note()->note();
|
|
|
|
double const h = note_height(trackview, mv);
|
|
|
|
double const y = note_y(trackview, mv, note_num);
|
2008-02-10 13:16:25 -05:00
|
|
|
|
2008-02-21 20:45:29 -05:00
|
|
|
if (note_num < mv->lowest_note() || note_num > mv->highest_note()) {
|
2014-12-28 21:31:33 -05:00
|
|
|
event->item->hide();
|
2008-02-21 20:45:29 -05:00
|
|
|
} else {
|
2014-12-28 21:31:33 -05:00
|
|
|
ArdourCanvas::Rectangle* rect = NULL;
|
|
|
|
ArdourCanvas::Polygon* poly = NULL;
|
|
|
|
if ((rect = dynamic_cast<ArdourCanvas::Rectangle*>(event->item))) {
|
|
|
|
rect->set_y0 (y);
|
|
|
|
rect->set_y1 (y + h);
|
|
|
|
} else if ((poly = dynamic_cast<ArdourCanvas::Polygon*>(event->item))) {
|
|
|
|
Duple position = poly->position();
|
|
|
|
position.y = y;
|
|
|
|
poly->set_position(position);
|
|
|
|
poly->set(Hit::points(h));
|
|
|
|
}
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-21 20:45:29 -05:00
|
|
|
MidiGhostRegion::clear_events()
|
|
|
|
{
|
|
|
|
for (EventList::iterator it = events.begin(); it != events.end(); ++it) {
|
2008-02-10 13:16:25 -05:00
|
|
|
delete *it;
|
|
|
|
}
|
2007-04-11 09:07:51 -04:00
|
|
|
|
2008-02-10 13:16:25 -05:00
|
|
|
events.clear();
|
2011-11-17 17:15:50 -05:00
|
|
|
_optimization_iterator = events.end ();
|
2007-04-11 09:07:51 -04:00
|
|
|
}
|
2008-02-21 20:45:29 -05:00
|
|
|
|
2011-02-27 23:00:38 -05:00
|
|
|
/** Update the x positions of our representation of a parent's note.
|
|
|
|
* @param parent The CanvasNote from the parent MidiRegionView.
|
|
|
|
*/
|
|
|
|
void
|
2013-04-04 18:45:27 -04:00
|
|
|
MidiGhostRegion::update_note (NoteBase* parent)
|
2011-02-27 23:00:38 -05:00
|
|
|
{
|
2013-04-04 18:45:27 -04:00
|
|
|
GhostEvent* ev = find_event (parent);
|
2011-02-27 23:00:38 -05:00
|
|
|
if (!ev) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-28 21:31:33 -05:00
|
|
|
Note* note = NULL;
|
|
|
|
ArdourCanvas::Rectangle* rect = NULL;
|
|
|
|
Hit* hit = NULL;
|
|
|
|
ArdourCanvas::Polygon* poly = NULL;
|
|
|
|
if ((note = dynamic_cast<Note*>(parent))) {
|
|
|
|
if ((rect = dynamic_cast<ArdourCanvas::Rectangle*>(ev->item))) {
|
|
|
|
double const x1 = parent->x0 ();
|
|
|
|
double const x2 = parent->x1 ();
|
|
|
|
rect->set_x0 (x1);
|
|
|
|
rect->set_x1 (x2);
|
|
|
|
}
|
|
|
|
} else if ((hit = dynamic_cast<Hit*>(parent))) {
|
|
|
|
if ((poly = dynamic_cast<ArdourCanvas::Polygon*>(ev->item))) {
|
|
|
|
ArdourCanvas::Duple ppos = hit->position();
|
|
|
|
ArdourCanvas::Duple gpos = poly->position();
|
|
|
|
gpos.x = ppos.x;
|
|
|
|
poly->set_position(gpos);
|
|
|
|
}
|
|
|
|
}
|
2011-02-27 23:00:38 -05:00
|
|
|
}
|
|
|
|
|
2011-11-17 17:15:50 -05:00
|
|
|
void
|
2013-04-04 18:45:27 -04:00
|
|
|
MidiGhostRegion::remove_note (NoteBase* note)
|
2011-11-17 17:15:50 -05:00
|
|
|
{
|
2013-04-04 18:45:27 -04:00
|
|
|
GhostEvent* ev = find_event (note);
|
2011-11-17 17:15:50 -05:00
|
|
|
if (!ev) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
events.remove (ev);
|
|
|
|
delete ev;
|
|
|
|
_optimization_iterator = events.end ();
|
|
|
|
}
|
|
|
|
|
2011-02-27 23:00:38 -05:00
|
|
|
/** Given a note in our parent region (ie the actual MidiRegionView), find our
|
|
|
|
* representation of it.
|
|
|
|
* @return Our Event, or 0 if not found.
|
|
|
|
*/
|
|
|
|
|
2013-04-04 18:45:27 -04:00
|
|
|
MidiGhostRegion::GhostEvent *
|
|
|
|
MidiGhostRegion::find_event (NoteBase* parent)
|
2011-02-27 23:00:38 -05:00
|
|
|
{
|
|
|
|
/* we are using _optimization_iterator to speed up the common case where a caller
|
|
|
|
is going through our notes in order.
|
|
|
|
*/
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-27 23:00:38 -05:00
|
|
|
if (_optimization_iterator != events.end()) {
|
|
|
|
++_optimization_iterator;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_optimization_iterator != events.end() && (*_optimization_iterator)->event == parent) {
|
|
|
|
return *_optimization_iterator;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (_optimization_iterator = events.begin(); _optimization_iterator != events.end(); ++_optimization_iterator) {
|
|
|
|
if ((*_optimization_iterator)->event == parent) {
|
|
|
|
return *_optimization_iterator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|