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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "evoral/Note.hpp"
|
2013-04-04 00:32:52 -04:00
|
|
|
#include "canvas/group.h"
|
|
|
|
#include "canvas/rectangle.h"
|
|
|
|
#include "canvas/wave_view.h"
|
2007-06-29 13:13:09 -04:00
|
|
|
#include "ardour_ui.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"
|
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
|
|
|
|
2009-07-09 13:58:13 -04:00
|
|
|
GhostRegion::GhostRegion (ArdourCanvas::Group* 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
|
|
|
{
|
2013-04-04 00:32:52 -04:00
|
|
|
group = new ArdourCanvas::Group (parent);
|
|
|
|
group->set_position (ArdourCanvas::Duple (initial_pos, 0));
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
base_rect = new ArdourCanvas::Rectangle (group);
|
|
|
|
base_rect->set_x0 (0);
|
|
|
|
base_rect->set_y0 (0);
|
|
|
|
base_rect->set_y1 (trackview.current_height());
|
|
|
|
base_rect->set_outline_what (0);
|
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()) {
|
2013-04-04 00:32:52 -04:00
|
|
|
base_rect->set_outline_color (ARDOUR_UI::config()->canvasvar_GhostTrackBase.get());
|
|
|
|
base_rect->set_fill_color (ARDOUR_UI::config()->canvasvar_GhostTrackBase.get());
|
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-04 00:32:52 -04:00
|
|
|
AudioGhostRegion::set_frames_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-04 00:32:52 -04:00
|
|
|
(*i)->set_frames_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()) {
|
2008-02-10 13:16:25 -05:00
|
|
|
fill_color = ARDOUR_UI::config()->canvasvar_GhostTrackWaveFill.get();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fill_color = source_track_color(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t n=0; n < waves.size(); ++n) {
|
2013-04-04 00:32:52 -04:00
|
|
|
waves[n]->set_outline_color (ARDOUR_UI::config()->canvasvar_GhostTrackWave.get());
|
|
|
|
waves[n]->set_fill_color (fill_color);
|
2008-02-10 13:16:25 -05:00
|
|
|
waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWaveClip.get();
|
|
|
|
waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_GhostTrackZeroLine.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-04-04 18:45:27 -04:00
|
|
|
MidiGhostRegion::GhostEvent::GhostEvent (NoteBase* e, ArdourCanvas::Group* g)
|
2011-11-17 17:15:56 -05:00
|
|
|
: event (e)
|
2008-02-21 20:45:29 -05:00
|
|
|
{
|
2013-04-04 18:45:27 -04:00
|
|
|
rect = new ArdourCanvas::Rectangle (g, ArdourCanvas::Rect (e->x0(), e->y0(), e->x1(), e->y1()));
|
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 */
|
2011-02-27 23:14:23 -05:00
|
|
|
delete rect;
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-04-04 00:32:52 -04:00
|
|
|
MidiGhostRegion::set_frames_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
|
|
|
guint fill = source_track_color(200);
|
|
|
|
|
|
|
|
GhostRegion::set_colors();
|
|
|
|
|
2008-02-21 20:45:29 -05:00
|
|
|
for (EventList::iterator it = events.begin(); it != events.end(); ++it) {
|
2013-04-04 18:45:27 -04:00
|
|
|
(*it)->rect->set_fill_color (fill);
|
|
|
|
(*it)->rect->set_outline_color (ARDOUR_UI::config()->canvasvar_GhostTrackMidiOutline.get());
|
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;
|
|
|
|
}
|
|
|
|
|
2010-12-30 13:35:16 -05:00
|
|
|
double const h = trackview.current_height() / double (mv->contents_note_range ());
|
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()) {
|
|
|
|
(*it)->rect->hide();
|
|
|
|
} else {
|
|
|
|
(*it)->rect->show();
|
|
|
|
double const y = trackview.current_height() - (note_num + 1 - mv->lowest_note()) * h + 1;
|
2013-04-04 18:45:27 -04:00
|
|
|
(*it)->rect->set_y0 (y);
|
|
|
|
(*it)->rect->set_y1 (y + 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
|
|
|
|
2013-04-04 18:45:27 -04:00
|
|
|
event->rect->set_fill_color (source_track_color(200));
|
|
|
|
event->rect->set_outline_color (ARDOUR_UI::config()->canvasvar_GhostTrackMidiOutline.get());
|
2008-02-10 13:16:25 -05:00
|
|
|
|
|
|
|
MidiStreamView* mv = midi_view();
|
|
|
|
|
2008-02-21 20:45:29 -05:00
|
|
|
if (mv) {
|
|
|
|
const uint8_t note_num = n->note()->note();
|
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()) {
|
2011-11-17 17:15:56 -05:00
|
|
|
event->rect->hide();
|
2008-02-21 20:45:29 -05:00
|
|
|
} else {
|
|
|
|
const double y = mv->note_to_y(note_num);
|
2013-04-04 18:45:27 -04:00
|
|
|
event->rect->set_y0 (y);
|
|
|
|
event->rect->set_y1 (y + mv->note_height());
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
double const x1 = parent->x0 ();
|
|
|
|
double const x2 = parent->x1 ();
|
|
|
|
ev->rect->set_x0 (x1);
|
|
|
|
ev->rect->set_x1 (x2);
|
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;
|
|
|
|
}
|