2 Copyright (C) 2000-2007 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "evoral/Note.hpp"
21 #include "ardour_ui.h"
22 #include "automation_time_axis.h"
23 #include "canvas-hit.h"
24 #include "canvas-note.h"
25 #include "ghostregion.h"
26 #include "midi_streamview.h"
27 #include "midi_time_axis.h"
28 #include "rgb_macros.h"
29 #include "simplerect.h"
33 using namespace Editing
;
34 using namespace ArdourCanvas
;
35 using namespace ARDOUR
;
37 PBD::Signal1
<void,GhostRegion
*> GhostRegion::CatchDeletion
;
39 GhostRegion::GhostRegion (ArdourCanvas::Group
* parent
, TimeAxisView
& tv
, TimeAxisView
& source_tv
, double initial_pos
)
41 , source_trackview (source_tv
)
43 group
= new ArdourCanvas::Group (*parent
);
44 group
->property_x() = initial_pos
;
45 group
->property_y() = 0.0;
47 base_rect
= new ArdourCanvas::SimpleRect (*group
);
48 base_rect
->property_x1() = (double) 0.0;
49 base_rect
->property_y1() = (double) 0.0;
50 base_rect
->property_y2() = (double) trackview
.current_height();
51 base_rect
->property_outline_what() = (guint32
) 0;
53 if (!is_automation_ghost()) {
57 GhostRegion::set_colors();
59 /* the parent group of a ghostregion is a dedicated group for ghosts,
60 so the new ghost would want to get to the top of that group*/
61 group
->raise_to_top ();
64 GhostRegion::~GhostRegion ()
72 GhostRegion::set_duration (double units
)
74 base_rect
->property_x2() = units
;
78 GhostRegion::set_height ()
80 base_rect
->property_y2() = (double) trackview
.current_height();
84 GhostRegion::set_colors ()
86 if (is_automation_ghost()) {
87 base_rect
->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_GhostTrackBase
.get();
88 base_rect
->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_GhostTrackBase
.get();
93 GhostRegion::source_track_color(unsigned char alpha
)
95 Gdk::Color color
= source_trackview
.color();
96 return RGBA_TO_UINT (color
.get_red() / 256, color
.get_green() / 256, color
.get_blue() / 256, alpha
);
100 GhostRegion::is_automation_ghost()
102 return (dynamic_cast<AutomationTimeAxisView
*>(&trackview
)) != 0;
105 AudioGhostRegion::AudioGhostRegion(TimeAxisView
& tv
, TimeAxisView
& source_tv
, double initial_unit_pos
)
106 : GhostRegion(tv
.ghost_group(), tv
, source_tv
, initial_unit_pos
)
112 AudioGhostRegion::set_samples_per_unit (double spu
)
114 for (vector
<WaveView
*>::iterator i
= waves
.begin(); i
!= waves
.end(); ++i
) {
115 (*i
)->property_samples_per_unit() = spu
;
120 AudioGhostRegion::set_height ()
123 vector
<WaveView
*>::iterator i
;
126 GhostRegion::set_height();
128 ht
= ((trackview
.current_height()) / (double) waves
.size());
130 for (n
= 0, i
= waves
.begin(); i
!= waves
.end(); ++i
, ++n
) {
131 gdouble yoff
= n
* ht
;
132 (*i
)->property_height() = ht
;
133 (*i
)->property_y() = yoff
;
138 AudioGhostRegion::set_colors ()
140 GhostRegion::set_colors();
143 if (is_automation_ghost()) {
144 fill_color
= ARDOUR_UI::config()->canvasvar_GhostTrackWaveFill
.get();
147 fill_color
= source_track_color(200);
150 for (uint32_t n
=0; n
< waves
.size(); ++n
) {
151 waves
[n
]->property_wave_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWave
.get();
152 waves
[n
]->property_fill_color() = fill_color
;
153 waves
[n
]->property_clip_color() = ARDOUR_UI::config()->canvasvar_GhostTrackWaveClip
.get();
154 waves
[n
]->property_zero_color() = ARDOUR_UI::config()->canvasvar_GhostTrackZeroLine
.get();
158 /** The general constructor; called when the destination timeaxisview doesn't have
161 * @param tv TimeAxisView that this ghost region is on.
162 * @param source_tv TimeAxisView that we are the ghost for.
164 MidiGhostRegion::MidiGhostRegion(TimeAxisView
& tv
, TimeAxisView
& source_tv
, double initial_unit_pos
)
165 : GhostRegion(tv
.ghost_group(), tv
, source_tv
, initial_unit_pos
)
167 base_rect
->lower_to_bottom();
170 midi_view()->NoteRangeChanged
.connect (sigc::mem_fun (*this, &MidiGhostRegion::update_range
));
174 * @param msv MidiStreamView that this ghost region is on.
175 * @param source_tv TimeAxisView that we are the ghost for.
177 MidiGhostRegion::MidiGhostRegion(MidiStreamView
& msv
, TimeAxisView
& source_tv
, double initial_unit_pos
)
178 : GhostRegion(msv
.midi_underlay_group
, msv
.trackview(), source_tv
, initial_unit_pos
)
180 base_rect
->lower_to_bottom();
183 midi_view()->NoteRangeChanged
.connect (sigc::mem_fun (*this, &MidiGhostRegion::update_range
));
186 MidiGhostRegion::~MidiGhostRegion()
191 MidiGhostRegion::Event::Event(ArdourCanvas::CanvasNoteEvent
* e
)
196 MidiGhostRegion::Note::Note(ArdourCanvas::CanvasNote
* n
, ArdourCanvas::Group
* g
)
199 rect
= new ArdourCanvas::SimpleRect(*g
, n
->x1(), n
->y1(), n
->x2(), n
->y2());
202 MidiGhostRegion::Note::~Note()
208 MidiGhostRegion::Note::x_changed()
210 rect
->property_x1() = event
->x1();
211 rect
->property_x2() = event
->x2();
214 MidiGhostRegion::Hit::Hit(ArdourCanvas::CanvasHit
* h
, ArdourCanvas::Group
*)
217 cerr
<< "Hit ghost item does not work yet" << endl
;
220 MidiGhostRegion::Hit::~Hit()
225 MidiGhostRegion::Hit::x_changed()
230 MidiGhostRegion::set_samples_per_unit (double /*spu*/)
234 /** @return MidiStreamView that we are providing a ghost for */
236 MidiGhostRegion::midi_view ()
238 StreamView
* sv
= source_trackview
.view ();
240 MidiStreamView
* msv
= dynamic_cast<MidiStreamView
*> (sv
);
247 MidiGhostRegion::set_height ()
249 GhostRegion::set_height();
254 MidiGhostRegion::set_colors()
256 MidiGhostRegion::Note
* note
;
257 guint fill
= source_track_color(200);
259 GhostRegion::set_colors();
261 for (EventList::iterator it
= events
.begin(); it
!= events
.end(); ++it
) {
262 if ((note
= dynamic_cast<MidiGhostRegion::Note
*>(*it
)) != 0) {
263 note
->rect
->property_fill_color_rgba() = fill
;
264 note
->rect
->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_GhostTrackMidiOutline
.get();
270 MidiGhostRegion::update_range ()
272 MidiStreamView
* mv
= midi_view();
278 MidiGhostRegion::Note
* note
;
279 double const h
= trackview
.current_height() / double (mv
->contents_note_range ());
281 for (EventList::iterator it
= events
.begin(); it
!= events
.end(); ++it
) {
282 if ((note
= dynamic_cast<MidiGhostRegion::Note
*>(*it
)) != 0) {
283 uint8_t const note_num
= note
->event
->note()->note();
285 if (note_num
< mv
->lowest_note() || note_num
> mv
->highest_note()) {
289 double const y
= trackview
.current_height() - (note_num
+ 1 - mv
->lowest_note()) * h
+ 1;
290 note
->rect
->property_y1() = y
;
291 note
->rect
->property_y2() = y
+ h
;
298 MidiGhostRegion::add_note(ArdourCanvas::CanvasNote
* n
)
300 Note
* note
= new Note(n
, group
);
301 events
.push_back(note
);
303 note
->rect
->property_fill_color_rgba() = source_track_color(200);
304 note
->rect
->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_GhostTrackMidiOutline
.get();
306 MidiStreamView
* mv
= midi_view();
309 const uint8_t note_num
= n
->note()->note();
311 if (note_num
< mv
->lowest_note() || note_num
> mv
->highest_note()) {
314 const double y
= mv
->note_to_y(note_num
);
315 note
->rect
->property_y1() = y
;
316 note
->rect
->property_y2() = y
+ mv
->note_height();
322 MidiGhostRegion::add_hit(ArdourCanvas::CanvasHit
* /*h*/)
324 //events.push_back(new Hit(h, group));
328 MidiGhostRegion::clear_events()
330 for (EventList::iterator it
= events
.begin(); it
!= events
.end(); ++it
) {