Make GhostRegion a sigc::trackable as MidiGhostRegion connects to signals. Fixes...
[ardour.git] / gtk2_ardour / ghostregion.h
1 /*
2     Copyright (C) 2004 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __ardour_gtk_ghost_region_h__
21 #define __ardour_gtk_ghost_region_h__
22
23 #include <vector>
24 #include <libgnomecanvasmm.h>
25 #include "pbd/signals.h"
26 #include "canvas.h"
27
28 namespace Gnome {
29         namespace Canvas {
30                 class CanvasNoteEvent;
31                 class CanvasNote;
32                 class CanvasHit;
33                 class Diamond;
34         }
35 }
36
37 class MidiStreamView;
38 class TimeAxisView;
39
40 class GhostRegion : public sigc::trackable
41 {
42 public:
43         GhostRegion(ArdourCanvas::Group* parent, TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos);
44         virtual ~GhostRegion();
45
46         virtual void set_samples_per_unit(double spu) = 0;
47         virtual void set_height();
48         virtual void set_colors();
49
50         void set_duration(double units);
51
52         guint source_track_color(unsigned char alpha = 0xff);
53         bool is_automation_ghost();
54
55         /** TimeAxisView that is the AutomationTimeAxisView that we are on */
56         TimeAxisView& trackview;
57         /** TimeAxisView that we are a ghost for */
58         TimeAxisView& source_trackview;
59         ArdourCanvas::Group* group;
60         ArdourCanvas::SimpleRect* base_rect;
61
62         static PBD::Signal1<void,GhostRegion*> CatchDeletion;
63 };
64
65 class AudioGhostRegion : public GhostRegion {
66 public:
67         AudioGhostRegion(TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos);
68
69         void set_samples_per_unit(double spu);
70         void set_height();
71         void set_colors();
72
73         std::vector<ArdourCanvas::WaveView*> waves;
74 };
75
76 class MidiGhostRegion : public GhostRegion {
77 public:
78         class Event : public sigc::trackable {
79         public:
80                 Event(ArdourCanvas::CanvasNoteEvent*);
81                 virtual ~Event() {}
82
83                 ArdourCanvas::CanvasNoteEvent* event;
84         };
85
86         class Note : public Event {
87         public:
88                 Note(ArdourCanvas::CanvasNote*, ArdourCanvas::Group*);
89                 ~Note();
90
91                 ArdourCanvas::SimpleRect* rect;
92         };
93
94         MidiGhostRegion(TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos);
95         MidiGhostRegion(MidiStreamView& msv, TimeAxisView& source_tv, double initial_unit_pos);
96         ~MidiGhostRegion();
97
98         MidiStreamView* midi_view();
99
100         void set_height();
101         void set_samples_per_unit(double spu);
102         void set_colors();
103
104         void update_range();
105
106         void add_note(ArdourCanvas::CanvasNote*);
107         void update_note (ArdourCanvas::CanvasNote *);
108
109         void clear_events();
110
111 private:
112
113         MidiGhostRegion::Event* find_event (ArdourCanvas::CanvasNote *);
114
115         typedef std::list<MidiGhostRegion::Event*> EventList;
116         EventList events;
117         EventList::iterator _optimization_iterator;
118 };
119
120 #endif /* __ardour_gtk_ghost_region_h__ */