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"
|
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"
|
2008-02-10 13:16:25 -05:00
|
|
|
#include "canvas-hit.h"
|
|
|
|
#include "canvas-note.h"
|
2009-02-15 18:47:09 -05:00
|
|
|
#include "ghostregion.h"
|
|
|
|
#include "midi_streamview.h"
|
|
|
|
#include "midi_time_axis.h"
|
|
|
|
#include "rgb_macros.h"
|
|
|
|
#include "simplerect.h"
|
|
|
|
#include "waveview.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
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
group = new ArdourCanvas::Group (*parent);
|
2005-11-27 17:35:04 -05:00
|
|
|
group->property_x() = initial_pos;
|
|
|
|
group->property_y() = 0.0;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-11-23 12:21:12 -05:00
|
|
|
base_rect = new ArdourCanvas::SimpleRect (*group);
|
2005-11-27 17:35:04 -05:00
|
|
|
base_rect->property_x1() = (double) 0.0;
|
|
|
|
base_rect->property_y1() = (double) 0.0;
|
2009-07-09 13:58:13 -04:00
|
|
|
base_rect->property_y2() = (double) trackview.current_height();
|
2005-11-27 17:35:04 -05:00
|
|
|
base_rect->property_outline_what() = (guint32) 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
|
|
|
{
|
2008-02-21 20:45:29 -05:00
|
|
|
base_rect->property_x2() = 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
|
|
|
{
|
2009-07-09 13:58:13 -04:00
|
|
|
base_rect->property_y2() = (double) 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()) {
|
2008-02-10 13:16:25 -05:00
|
|
|
base_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_GhostTrackBase.get();
|
|
|
|
base_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_GhostTrackBase.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioGhostRegion::set_samples_per_unit (double spu)
|
|
|
|
{
|
|
|
|
for (vector<WaveView*>::iterator i = waves.begin(); i != waves.end(); ++i) {
|
|
|
|
(*i)->property_samples_per_unit() = spu;
|
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
|
|
|
{
|
|
|
|
gdouble ht;
|
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();
|
|
|
|
|
2009-07-09 13:58:13 -04:00
|
|
|
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) {
|
2009-07-09 13:58:13 -04:00
|
|
|
gdouble yoff = n * ht;
|
2005-11-27 15:07:16 -05:00
|
|
|
(*i)->property_height() = ht;
|
|
|
|
(*i)->property_y() = yoff;
|
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) {
|
|
|
|
waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWave.get();
|
|
|
|
waves[n]->property_fill_color() = fill_color;
|
|
|
|
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)
|
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)
|
|
|
|
{
|
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()
|
|
|
|
{
|
|
|
|
//clear_events();
|
|
|
|
}
|
|
|
|
|
2008-04-29 03:28:24 -04:00
|
|
|
MidiGhostRegion::Event::Event(ArdourCanvas::CanvasNoteEvent* e)
|
2008-02-21 20:45:29 -05:00
|
|
|
: event(e)
|
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
MidiGhostRegion::Note::Note(ArdourCanvas::CanvasNote* n, ArdourCanvas::Group* g)
|
2008-02-21 20:45:29 -05:00
|
|
|
: Event(n)
|
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
rect = new ArdourCanvas::SimpleRect(*g, n->x1(), n->y1(), n->x2(), n->y2());
|
|
|
|
}
|
2007-06-15 18:08:27 -04:00
|
|
|
|
2008-02-21 20:45:29 -05:00
|
|
|
MidiGhostRegion::Note::~Note()
|
|
|
|
{
|
|
|
|
//delete rect;
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-21 20:45:29 -05:00
|
|
|
MidiGhostRegion::Note::x_changed()
|
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
rect->property_x1() = event->x1();
|
|
|
|
rect->property_x2() = event->x2();
|
|
|
|
}
|
|
|
|
|
|
|
|
MidiGhostRegion::Hit::Hit(ArdourCanvas::CanvasHit* h, ArdourCanvas::Group*)
|
2008-02-21 20:45:29 -05:00
|
|
|
: Event(h)
|
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
cerr << "Hit ghost item does not work yet" << endl;
|
|
|
|
}
|
|
|
|
|
2008-02-21 20:45:29 -05:00
|
|
|
MidiGhostRegion::Hit::~Hit()
|
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-21 20:45:29 -05:00
|
|
|
MidiGhostRegion::Hit::x_changed()
|
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-21 11:55:17 -04:00
|
|
|
MidiGhostRegion::set_samples_per_unit (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
|
|
|
MidiGhostRegion::Note* note;
|
|
|
|
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) {
|
|
|
|
if ((note = dynamic_cast<MidiGhostRegion::Note*>(*it)) != 0) {
|
2008-02-10 13:16:25 -05:00
|
|
|
note->rect->property_fill_color_rgba() = fill;
|
|
|
|
note->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_GhostTrackMidiOutline.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
MidiGhostRegion::Note* note;
|
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) {
|
|
|
|
if ((note = dynamic_cast<MidiGhostRegion::Note*>(*it)) != 0) {
|
2010-12-30 13:35:16 -05:00
|
|
|
uint8_t const note_num = note->event->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()) {
|
2008-02-10 13:16:25 -05:00
|
|
|
note->rect->hide();
|
2010-12-30 13:35:16 -05:00
|
|
|
} else {
|
2008-02-10 13:16:25 -05:00
|
|
|
note->rect->show();
|
2010-12-30 13:35:16 -05:00
|
|
|
double const y = trackview.current_height() - (note_num + 1 - mv->lowest_note()) * h + 1;
|
2008-02-10 13:16:25 -05:00
|
|
|
note->rect->property_y1() = y;
|
2010-12-30 13:35:16 -05:00
|
|
|
note->rect->property_y2() = y + h;
|
2008-02-10 13:16:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-21 20:45:29 -05:00
|
|
|
MidiGhostRegion::add_note(ArdourCanvas::CanvasNote* n)
|
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
Note* note = new Note(n, group);
|
|
|
|
events.push_back(note);
|
|
|
|
|
|
|
|
note->rect->property_fill_color_rgba() = source_track_color(200);
|
|
|
|
note->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_GhostTrackMidiOutline.get();
|
|
|
|
|
|
|
|
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()) {
|
2008-02-10 13:16:25 -05:00
|
|
|
note->rect->hide();
|
2008-02-21 20:45:29 -05:00
|
|
|
} else {
|
|
|
|
const double y = mv->note_to_y(note_num);
|
2008-02-10 13:16:25 -05:00
|
|
|
note->rect->property_y1() = y;
|
|
|
|
note->rect->property_y2() = y + mv->note_height();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-21 11:55:17 -04:00
|
|
|
MidiGhostRegion::add_hit(ArdourCanvas::CanvasHit* /*h*/)
|
2008-02-21 20:45:29 -05:00
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
//events.push_back(new Hit(h, group));
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2007-04-11 09:07:51 -04:00
|
|
|
}
|
2008-02-21 20:45:29 -05:00
|
|
|
|