fix redrawing of canvas with an optimized build
[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 "pbd/signals.h"
25
26 namespace ArdourCanvas {
27         class WaveView;
28 }
29
30 class NoteBase;
31 class Note;
32 class Hit;
33 class MidiStreamView;
34 class TimeAxisView;
35
36 class GhostRegion : public sigc::trackable
37 {
38 public:
39         GhostRegion(ArdourCanvas::Group* parent, TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos);
40         virtual ~GhostRegion();
41
42         virtual void set_samples_per_pixel (double) = 0;
43         virtual void set_height();
44         virtual void set_colors();
45
46         void set_duration(double units);
47
48         guint source_track_color(unsigned char alpha = 0xff);
49         bool is_automation_ghost();
50
51         /** TimeAxisView that is the AutomationTimeAxisView that we are on */
52         TimeAxisView& trackview;
53         /** TimeAxisView that we are a ghost for */
54         TimeAxisView& source_trackview;
55         ArdourCanvas::Group* group;
56         ArdourCanvas::Rectangle* base_rect;
57
58         static PBD::Signal1<void,GhostRegion*> CatchDeletion;
59 };
60
61 class AudioGhostRegion : public GhostRegion {
62 public:
63         AudioGhostRegion(TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos);
64
65         void set_samples_per_pixel (double);
66         void set_height();
67         void set_colors();
68
69         std::vector<ArdourCanvas::WaveView*> waves;
70 };
71
72 class MidiGhostRegion : public GhostRegion {
73 public:
74         class GhostEvent : public sigc::trackable {
75           public:
76             GhostEvent(::NoteBase *, ArdourCanvas::Group *);
77             virtual ~GhostEvent ();
78             
79             NoteBase* event;
80             ArdourCanvas::Rectangle* rect;
81         };
82
83         MidiGhostRegion(TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos);
84         MidiGhostRegion(MidiStreamView& msv, TimeAxisView& source_tv, double initial_unit_pos);
85         ~MidiGhostRegion();
86
87         MidiStreamView* midi_view();
88
89         void set_height();
90         void set_samples_per_pixel (double spu);
91         void set_colors();
92
93         void update_range();
94
95         void add_note(NoteBase*);
96         void update_note (NoteBase*);
97         void remove_note (NoteBase*);
98
99         void clear_events();
100
101 private:
102
103         MidiGhostRegion::GhostEvent* find_event (NoteBase*);
104
105         typedef std::list<MidiGhostRegion::GhostEvent*> EventList;
106         EventList events;
107         EventList::iterator _optimization_iterator;
108 };
109
110 #endif /* __ardour_gtk_ghost_region_h__ */