note display performance.
[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 <boost/unordered_map.hpp>
25 #include "pbd/signals.h"
26
27 namespace ArdourCanvas {
28         class WaveView;
29 }
30
31 class NoteBase;
32 class Note;
33 class Hit;
34 class MidiStreamView;
35 class TimeAxisView;
36 class RegionView;
37
38 class GhostRegion : public sigc::trackable
39 {
40 public:
41         GhostRegion(RegionView& rv,
42                     ArdourCanvas::Container* parent,
43                     TimeAxisView& tv,
44                     TimeAxisView& source_tv,
45                     double initial_unit_pos);
46
47         virtual ~GhostRegion();
48
49         virtual void set_samples_per_pixel (double) = 0;
50         virtual void set_height();
51         virtual void set_colors();
52
53         void set_duration(double units);
54
55         guint source_track_color(unsigned char alpha = 0xff);
56         bool is_automation_ghost();
57
58         RegionView& parent_rv;
59         /** TimeAxisView that is the AutomationTimeAxisView that we are on */
60         TimeAxisView& trackview;
61         /** TimeAxisView that we are a ghost for */
62         TimeAxisView& source_trackview;
63         ArdourCanvas::Container* group;
64         ArdourCanvas::Rectangle* base_rect;
65 };
66
67 class AudioGhostRegion : public GhostRegion {
68 public:
69         AudioGhostRegion(RegionView& rv,
70                          TimeAxisView& tv,
71                          TimeAxisView& source_tv,
72                          double initial_unit_pos);
73
74         void set_samples_per_pixel (double);
75         void set_height();
76         void set_colors();
77
78         std::vector<ArdourCanvas::WaveView*> waves;
79 };
80
81 class MidiGhostRegion : public GhostRegion {
82 public:
83         class GhostEvent : public sigc::trackable {
84           public:
85             GhostEvent(::NoteBase *, ArdourCanvas::Container *);
86             virtual ~GhostEvent ();
87
88             NoteBase* event;
89             ArdourCanvas::Item* item;
90             bool is_hit;
91         };
92
93         MidiGhostRegion(RegionView& rv,
94                         TimeAxisView& tv,
95                         TimeAxisView& source_tv,
96                         double initial_unit_pos);
97
98         MidiGhostRegion(RegionView& rv,
99                         MidiStreamView& msv,
100                         TimeAxisView& source_tv,
101                         double initial_unit_pos);
102
103         ~MidiGhostRegion();
104
105         MidiStreamView* midi_view();
106
107         void set_height();
108         void set_samples_per_pixel (double spu);
109         void set_colors();
110
111         void update_contents_height();
112
113         void add_note(NoteBase*);
114         void update_note (Note* note,  bool hide);
115         void update_hit (Hit* hit, bool hide);
116         void remove_note (NoteBase*);
117
118         void clear_events();
119
120 private:
121         ArdourCanvas::Container* _note_group;
122         ArdourCanvas::Color _outline;
123         ArdourCanvas::Rectangle* _tmp_rect;
124         ArdourCanvas::Polygon* _tmp_poly;
125
126         typedef Evoral::Note<Evoral::Beats> NoteType;
127         MidiGhostRegion::GhostEvent* find_event (boost::shared_ptr<NoteType>);
128
129         typedef boost::unordered_map<boost::shared_ptr<NoteType>, MidiGhostRegion::GhostEvent* > EventList;
130         EventList events;
131         EventList::iterator _optimization_iterator;
132 };
133
134 #endif /* __ardour_gtk_ghost_region_h__ */