2007-04-26 16:54:31 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2005-2018 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2005 Karsten Wiese <fzuuzf@googlemail.com>
|
|
|
|
* Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
|
|
|
|
* Copyright (C) 2007 Doug McLain <doug@nostar.net>
|
|
|
|
* Copyright (C) 2008-2014 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
* Copyright (C) 2016-2017 Nick Mainsbridge <mainsbridge@gmail.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.
|
|
|
|
*/
|
2007-04-26 16:54:31 -04:00
|
|
|
|
2019-10-25 15:13:51 -04:00
|
|
|
#include "evoral/Note.h"
|
2017-07-17 14:12:33 -04:00
|
|
|
|
2015-01-02 09:44:54 -05:00
|
|
|
#include "ardour/parameter_descriptor.h"
|
|
|
|
|
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"
|
2013-04-24 15:42:14 -04:00
|
|
|
#include "canvas/debug.h"
|
|
|
|
|
2017-07-17 14:12:33 -04:00
|
|
|
#include "waveview/wave_view.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"
|
2015-10-22 07:56:02 -04:00
|
|
|
#include "region_view.h"
|
2017-01-29 09:46:38 -05:00
|
|
|
#include "midi_region_view.h"
|
2009-02-15 18:47:09 -05:00
|
|
|
#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;
|
2007-06-15 18:08:27 -04:00
|
|
|
using namespace ARDOUR;
|
2018-07-03 11:21:53 -04:00
|
|
|
using ArdourCanvas::Duple;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
GhostRegion::GhostRegion (RegionView& rv,
|
|
|
|
ArdourCanvas::Container* parent,
|
|
|
|
TimeAxisView& tv,
|
|
|
|
TimeAxisView& source_tv,
|
|
|
|
double initial_pos)
|
|
|
|
: parent_rv(rv)
|
|
|
|
, 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 ()
|
|
|
|
{
|
2015-10-22 07:56:02 -04:00
|
|
|
parent_rv.remove_ghost(this);
|
|
|
|
trackview.erase_ghost(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
|
|
|
}
|
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
AudioGhostRegion::AudioGhostRegion (RegionView& rv,
|
|
|
|
TimeAxisView& tv,
|
|
|
|
TimeAxisView& source_tv,
|
|
|
|
double initial_unit_pos)
|
|
|
|
: GhostRegion(rv, tv.ghost_group(), tv, source_tv, initial_unit_pos)
|
2010-12-30 13:35:16 -05:00
|
|
|
{
|
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
|
|
|
{
|
2017-07-17 14:12:33 -04:00
|
|
|
for (vector<ArdourWaveView::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
|
|
|
{
|
2017-07-17 14:12:33 -04:00
|
|
|
vector<ArdourWaveView::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.
|
|
|
|
*
|
2015-10-22 07:56:02 -04:00
|
|
|
* @param rv The parent RegionView that is being ghosted.
|
2010-12-30 13:35:16 -05:00
|
|
|
* @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
|
|
|
*/
|
2017-01-29 09:46:38 -05:00
|
|
|
MidiGhostRegion::MidiGhostRegion(MidiRegionView& rv,
|
2015-10-22 07:56:02 -04:00
|
|
|
TimeAxisView& tv,
|
|
|
|
TimeAxisView& source_tv,
|
|
|
|
double initial_unit_pos)
|
2019-04-13 11:48:27 -04:00
|
|
|
: GhostRegion(rv, tv.ghost_group(), tv, source_tv, initial_unit_pos)
|
|
|
|
, _note_group (new ArdourCanvas::Container (group))
|
|
|
|
, parent_mrv (rv)
|
|
|
|
, _optimization_iterator(events.end())
|
2008-02-21 20:45:29 -05:00
|
|
|
{
|
2016-12-11 07:57:50 -05:00
|
|
|
_outline = UIConfiguration::instance().color ("ghost track midi outline");
|
2016-11-24 12:50:46 -05:00
|
|
|
|
2008-02-10 13:16:25 -05:00
|
|
|
base_rect->lower_to_bottom();
|
|
|
|
}
|
|
|
|
|
2010-12-30 13:35:16 -05:00
|
|
|
/**
|
2015-10-22 07:56:02 -04:00
|
|
|
* @param rv The parent RegionView being ghosted.
|
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.
|
|
|
|
*/
|
2017-01-29 09:46:38 -05:00
|
|
|
MidiGhostRegion::MidiGhostRegion(MidiRegionView& rv,
|
2015-10-22 07:56:02 -04:00
|
|
|
MidiStreamView& msv,
|
|
|
|
TimeAxisView& source_tv,
|
|
|
|
double initial_unit_pos)
|
2019-04-13 11:48:27 -04:00
|
|
|
: GhostRegion (rv,
|
|
|
|
msv.midi_underlay_group,
|
|
|
|
msv.trackview(),
|
|
|
|
source_tv,
|
|
|
|
initial_unit_pos)
|
|
|
|
, _note_group (new ArdourCanvas::Container (group))
|
|
|
|
, parent_mrv (rv)
|
|
|
|
, _optimization_iterator(events.end())
|
2008-02-21 20:45:29 -05:00
|
|
|
{
|
2016-12-11 07:57:50 -05:00
|
|
|
_outline = UIConfiguration::instance().color ("ghost track midi outline");
|
2016-11-24 12:50:46 -05:00
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
base_rect->lower_to_bottom();
|
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 ();
|
2016-12-23 10:14:43 -05:00
|
|
|
delete _note_group;
|
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
|
|
|
{
|
2016-12-23 06:20:08 -05:00
|
|
|
|
2014-12-28 21:31:33 -05:00
|
|
|
if (dynamic_cast<Note*>(e)) {
|
|
|
|
item = new ArdourCanvas::Rectangle(
|
|
|
|
g, ArdourCanvas::Rect(e->x0(), e->y0(), e->x1(), e->y1()));
|
2016-12-29 09:55:41 -05:00
|
|
|
is_hit = false;
|
2016-12-23 06:20:08 -05:00
|
|
|
} else {
|
|
|
|
Hit* hit = dynamic_cast<Hit*>(e);
|
|
|
|
if (!hit) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-28 21:31:33 -05:00
|
|
|
ArdourCanvas::Polygon* poly = new ArdourCanvas::Polygon(g);
|
|
|
|
poly->set(Hit::points(e->y1() - e->y0()));
|
|
|
|
poly->set_position(hit->position());
|
|
|
|
item = poly;
|
2016-12-29 09:55:41 -05:00
|
|
|
is_hit = true;
|
2014-12-28 21:31:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2016-12-22 08:51:34 -05:00
|
|
|
update_contents_height ();
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-21 20:45:29 -05:00
|
|
|
MidiGhostRegion::set_colors()
|
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
GhostRegion::set_colors();
|
2016-11-24 12:50:46 -05:00
|
|
|
_outline = UIConfiguration::instance().color ("ghost track midi outline");
|
2008-02-10 13:16:25 -05:00
|
|
|
|
2008-02-21 20:45:29 -05:00
|
|
|
for (EventList::iterator it = events.begin(); it != events.end(); ++it) {
|
2016-12-29 07:22:06 -05:00
|
|
|
it->second->item->set_fill_color (UIConfiguration::instance().color_mod((*it).second->event->base_color(), "ghost track midi fill"));
|
|
|
|
it->second->item->set_outline_color (_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
|
2016-12-22 08:51:34 -05:00
|
|
|
MidiGhostRegion::update_contents_height ()
|
2016-12-21 12:39:53 -05:00
|
|
|
{
|
|
|
|
MidiStreamView* mv = midi_view();
|
|
|
|
|
|
|
|
if (!mv) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
double const h = note_height(trackview, mv);
|
|
|
|
|
|
|
|
for (EventList::iterator it = events.begin(); it != events.end(); ++it) {
|
2016-12-29 07:22:06 -05:00
|
|
|
uint8_t const note_num = it->second->event->note()->note();
|
2016-12-21 12:39:53 -05:00
|
|
|
|
|
|
|
double const y = note_y(trackview, mv, note_num);
|
2016-12-22 13:44:29 -05:00
|
|
|
|
2016-12-29 09:55:41 -05:00
|
|
|
if (!it->second->is_hit) {
|
|
|
|
_tmp_rect = static_cast<ArdourCanvas::Rectangle*>(it->second->item);
|
2016-12-22 13:44:29 -05:00
|
|
|
_tmp_rect->set (ArdourCanvas::Rect (_tmp_rect->x0(), y, _tmp_rect->x1(), y + h));
|
2016-12-29 09:55:41 -05:00
|
|
|
} else {
|
|
|
|
_tmp_poly = static_cast<ArdourCanvas::Polygon*>(it->second->item);
|
2018-07-03 11:21:53 -04:00
|
|
|
ArdourCanvas::Duple position = _tmp_poly->position();
|
2016-12-22 13:44:29 -05:00
|
|
|
position.y = y;
|
|
|
|
_tmp_poly->set_position(position);
|
|
|
|
_tmp_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
|
|
|
{
|
2016-12-23 10:01:37 -05:00
|
|
|
GhostEvent* event = new GhostEvent (n, _note_group);
|
2016-12-20 11:30:32 -05:00
|
|
|
events.insert (make_pair (n->note(), event));
|
2008-02-10 13:16:25 -05:00
|
|
|
|
2016-11-24 12:50:46 -05:00
|
|
|
event->item->set_fill_color (UIConfiguration::instance().color_mod(n->base_color(), "ghost track midi fill"));
|
2016-06-19 11:01:26 -04:00
|
|
|
event->item->set_outline_color (_outline);
|
2008-02-10 13:16:25 -05:00
|
|
|
|
|
|
|
MidiStreamView* mv = midi_view();
|
|
|
|
|
2008-02-21 20:45:29 -05:00
|
|
|
if (mv) {
|
2016-12-29 10:21:12 -05:00
|
|
|
|
|
|
|
if (!n->item()->visible()) {
|
2014-12-28 21:31:33 -05:00
|
|
|
event->item->hide();
|
2008-02-21 20:45:29 -05:00
|
|
|
} else {
|
2017-01-26 08:58:09 -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);
|
2016-12-29 09:55:41 -05:00
|
|
|
if (!event->is_hit) {
|
|
|
|
_tmp_rect = static_cast<ArdourCanvas::Rectangle*>(event->item);
|
2016-12-21 12:39:53 -05:00
|
|
|
_tmp_rect->set (ArdourCanvas::Rect (_tmp_rect->x0(), y, _tmp_rect->x1(), y + h));
|
2016-12-29 09:55:41 -05:00
|
|
|
} else {
|
|
|
|
_tmp_poly = static_cast<ArdourCanvas::Polygon*>(event->item);
|
2016-12-21 12:39:53 -05:00
|
|
|
Duple position = _tmp_poly->position();
|
2014-12-28 21:31:33 -05:00
|
|
|
position.y = y;
|
2016-12-21 12:39:53 -05:00
|
|
|
_tmp_poly->set_position(position);
|
|
|
|
_tmp_poly->set(Hit::points(h));
|
2014-12-28 21:31:33 -05:00
|
|
|
}
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-21 20:45:29 -05:00
|
|
|
MidiGhostRegion::clear_events()
|
|
|
|
{
|
2016-12-23 10:01:37 -05:00
|
|
|
_note_group->clear (true);
|
|
|
|
events.clear ();
|
|
|
|
_optimization_iterator = events.end();
|
2007-04-11 09:07:51 -04:00
|
|
|
}
|
2008-02-21 20:45:29 -05:00
|
|
|
|
2017-01-29 09:46:38 -05:00
|
|
|
/** Update the positions of our representation of a note.
|
|
|
|
* @param ev The GhostEvent from the parent MidiRegionView.
|
2011-02-27 23:00:38 -05:00
|
|
|
*/
|
|
|
|
void
|
2017-01-29 09:46:38 -05:00
|
|
|
MidiGhostRegion::update_note (GhostEvent* ev)
|
2011-02-27 23:00:38 -05:00
|
|
|
{
|
2016-12-21 12:39:53 -05:00
|
|
|
MidiStreamView* mv = midi_view();
|
|
|
|
|
|
|
|
if (!mv) {
|
2016-12-20 11:30:32 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-29 09:46:38 -05:00
|
|
|
_tmp_rect = static_cast<ArdourCanvas::Rectangle*>(ev->item);
|
2016-12-20 11:30:32 -05:00
|
|
|
|
2017-01-29 09:46:38 -05:00
|
|
|
uint8_t const note_num = ev->event->note()->note();
|
|
|
|
double const y = note_y(trackview, mv, note_num);
|
|
|
|
double const h = note_height(trackview, mv);
|
2016-12-29 09:55:41 -05:00
|
|
|
|
2017-01-29 09:46:38 -05:00
|
|
|
_tmp_rect->set (ArdourCanvas::Rect (ev->event->x0(), y, ev->event->x1(), y + h));
|
2016-10-15 12:11:05 -04:00
|
|
|
}
|
2016-12-20 11:30:32 -05:00
|
|
|
|
2017-01-29 09:46:38 -05:00
|
|
|
/** Update the positions of our representation of a parent's hit.
|
|
|
|
* @param ev The GhostEvent from the parent MidiRegionView.
|
2016-10-15 12:11:05 -04:00
|
|
|
*/
|
|
|
|
void
|
2017-01-29 09:46:38 -05:00
|
|
|
MidiGhostRegion::update_hit (GhostEvent* ev)
|
2016-10-15 12:11:05 -04:00
|
|
|
{
|
2016-12-21 12:39:53 -05:00
|
|
|
MidiStreamView* mv = midi_view();
|
|
|
|
|
|
|
|
if (!mv) {
|
2016-12-20 11:30:32 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-29 09:46:38 -05:00
|
|
|
_tmp_poly = static_cast<ArdourCanvas::Polygon*>(ev->item);
|
2017-01-26 08:58:09 -05:00
|
|
|
|
2017-01-29 09:46:38 -05:00
|
|
|
uint8_t const note_num = ev->event->note()->note();
|
|
|
|
double const h = note_height(trackview, mv);
|
|
|
|
double const y = note_y(trackview, mv, note_num);
|
2017-01-26 08:58:09 -05:00
|
|
|
|
2017-01-29 09:46:38 -05:00
|
|
|
ArdourCanvas::Duple ppos = ev->item->position();
|
|
|
|
ArdourCanvas::Duple gpos = _tmp_poly->position();
|
|
|
|
gpos.x = ppos.x;
|
|
|
|
gpos.y = y;
|
2016-12-29 09:55:41 -05:00
|
|
|
|
2017-01-29 09:46:38 -05:00
|
|
|
_tmp_poly->set_position(gpos);
|
|
|
|
_tmp_poly->set(Hit::points(h));
|
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
|
|
|
{
|
2016-12-20 11:30:32 -05:00
|
|
|
EventList::iterator f = events.find (note->note());
|
|
|
|
if (f == events.end()) {
|
2011-11-17 17:15:50 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-29 07:22:06 -05:00
|
|
|
delete f->second;
|
2016-12-20 11:30:32 -05:00
|
|
|
events.erase (f);
|
|
|
|
|
2011-11-17 17:15:50 -05:00
|
|
|
_optimization_iterator = events.end ();
|
|
|
|
}
|
2022-04-02 00:24:01 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
MidiGhostRegion::view_changed ()
|
|
|
|
{
|
|
|
|
model_changed();
|
|
|
|
}
|
|
|
|
|
2017-01-29 09:46:38 -05:00
|
|
|
void
|
2022-04-02 00:24:01 -04:00
|
|
|
MidiGhostRegion::model_changed ()
|
2017-01-29 09:46:38 -05:00
|
|
|
{
|
|
|
|
/* we rely on the parent MRV having removed notes not in the model */
|
|
|
|
for (EventList::iterator i = events.begin(); i != events.end(); ) {
|
|
|
|
|
|
|
|
boost::shared_ptr<NoteType> note = i->first;
|
|
|
|
GhostEvent* cne = i->second;
|
|
|
|
const bool visible = (note->note() >= parent_mrv._current_range_min) &&
|
|
|
|
(note->note() <= parent_mrv._current_range_max);
|
|
|
|
|
|
|
|
if (visible) {
|
|
|
|
if (cne->is_hit) {
|
|
|
|
update_hit (cne);
|
|
|
|
} else {
|
|
|
|
update_note (cne);
|
|
|
|
}
|
|
|
|
cne->item->show ();
|
|
|
|
} else {
|
|
|
|
cne->item->hide ();
|
|
|
|
}
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
2011-11-17 17:15:50 -05:00
|
|
|
|
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 *
|
2017-01-03 08:19:31 -05:00
|
|
|
MidiGhostRegion::find_event (boost::shared_ptr<NoteType> 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;
|
2017-01-03 08:19:31 -05:00
|
|
|
if (_optimization_iterator != events.end() && _optimization_iterator->first == parent) {
|
2016-12-29 07:22:06 -05:00
|
|
|
return _optimization_iterator->second;
|
2016-12-28 10:36:58 -05:00
|
|
|
}
|
2011-02-27 23:00:38 -05:00
|
|
|
}
|
|
|
|
|
2017-01-03 08:19:31 -05:00
|
|
|
_optimization_iterator = events.find (parent);
|
2016-12-21 12:23:58 -05:00
|
|
|
if (_optimization_iterator != events.end()) {
|
2016-12-29 07:22:06 -05:00
|
|
|
return _optimization_iterator->second;
|
2011-02-27 23:00:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|