2007-04-26 16:54:31 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2000-2007 Paul Davis
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2005-11-22 00:10:12 -05:00
|
|
|
#include "simplerect.h"
|
|
|
|
#include "waveview.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
#include "ghostregion.h"
|
2008-02-10 13:16:25 -05:00
|
|
|
#include "midi_time_axis.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
#include "automation_time_axis.h"
|
2008-02-10 13:16:25 -05:00
|
|
|
#include "midi_streamview.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
#include "rgb_macros.h"
|
2007-06-29 13:13:09 -04:00
|
|
|
#include "ardour_ui.h"
|
2008-02-10 13:16:25 -05:00
|
|
|
#include "canvas-hit.h"
|
|
|
|
#include "canvas-note.h"
|
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
|
|
|
|
2008-02-10 13:16:25 -05:00
|
|
|
GhostRegion::GhostRegion (ArdourCanvas::Group* parent, TimeAxisView& tv, TimeAxisView& source_tv, double initial_pos)
|
|
|
|
: 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;
|
2008-09-10 11:03:30 -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 ()
|
|
|
|
{
|
2008-02-21 20:45:29 -05:00
|
|
|
/*GoingAway (this);
|
2005-11-22 00:10:12 -05:00
|
|
|
delete base_rect;
|
2008-02-21 20:45:29 -05: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
|
|
|
{
|
2008-09-10 11:03:30 -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
|
|
|
|
GhostRegion::source_track_color(unsigned char alpha) {
|
|
|
|
Gdk::Color color = source_trackview.color();
|
|
|
|
unsigned char r,g,b ;
|
|
|
|
r = color.get_red()/256;
|
|
|
|
g = color.get_green()/256;
|
|
|
|
b = color.get_blue()/256;
|
|
|
|
return RGBA_TO_UINT(r, g, b, alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GhostRegion::is_automation_ghost() {
|
|
|
|
return (dynamic_cast<AutomationTimeAxisView*>(&trackview)) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioGhostRegion::AudioGhostRegion(TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos)
|
|
|
|
: GhostRegion(tv.ghost_group, tv, source_tv, initial_unit_pos) {
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
ht = ((trackview.current_height()) / (double) waves.size());
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
for (n = 0, i = waves.begin(); i != waves.end(); ++i, ++n) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the general constructor, and is called when the destination timeaxisview doesn't have
|
|
|
|
* a midistreamview. But what to do when positioning the midi ghost here? For example, there is
|
|
|
|
* no range controller in these tracks. maybe show the whole range.
|
|
|
|
*/
|
|
|
|
MidiGhostRegion::MidiGhostRegion(TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos)
|
2008-02-21 20:45:29 -05:00
|
|
|
: GhostRegion(tv.ghost_group, tv, source_tv, initial_unit_pos)
|
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
|
|
|
|
base_rect->lower_to_bottom();
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
base_rect->lower_to_bottom();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
MidiGhostRegion::set_samples_per_unit (double spu)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MidiStreamView*
|
2008-02-21 20:45:29 -05:00
|
|
|
MidiGhostRegion::midi_view()
|
|
|
|
{
|
2008-02-10 13:16:25 -05:00
|
|
|
MidiTimeAxisView* mtv;
|
|
|
|
|
2008-02-21 20:45:29 -05:00
|
|
|
if ((mtv = dynamic_cast<MidiTimeAxisView*>(&trackview)) != 0) {
|
2008-02-10 13:16:25 -05:00
|
|
|
return mtv->midi_view();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-21 20:45:29 -05:00
|
|
|
MidiGhostRegion::set_height()
|
|
|
|
{
|
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
|
2008-02-21 20:45:29 -05:00
|
|
|
MidiGhostRegion::update_range()
|
|
|
|
{
|
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;
|
|
|
|
uint8_t note_num;
|
|
|
|
double y;
|
|
|
|
|
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_num = note->event->note()->note();
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
note->rect->show();
|
|
|
|
y = mv->note_to_y(note_num);
|
|
|
|
note->rect->property_y1() = y;
|
|
|
|
note->rect->property_y2() = y + mv->note_height();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2008-02-21 20:45:29 -05:00
|
|
|
MidiGhostRegion::add_hit(ArdourCanvas::CanvasHit* h)
|
|
|
|
{
|
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
|
|
|
|