add theme files to default target, and install using target names
[ardour.git] / gtk2_ardour / midi_region_view.h
1 /*
2     Copyright (C) 2001-2006 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 #ifndef __gtk_ardour_midi_region_view_h__
20 #define __gtk_ardour_midi_region_view_h__
21
22 #include <vector>
23
24 #include <libgnomecanvasmm.h>
25 #include <libgnomecanvasmm/polygon.h>
26 #include <ardour/midi_region.h>
27 #include <ardour/midi_model.h>
28 #include <ardour/types.h>
29
30 #include "region_view.h"
31 #include "midi_time_axis.h"
32 #include "time_axis_view_item.h"
33 #include "automation_line.h"
34 #include "enums.h"
35 #include "canvas.h"
36 #include "canvas-note.h"
37 #include "canvas-midi-event.h"
38
39 namespace ARDOUR {
40         class MidiRegion;
41         class MidiModel;
42 };
43
44 class MidiTimeAxisView;
45 class GhostRegion;
46 class AutomationTimeAxisView;
47
48 class MidiRegionView : public RegionView
49 {
50   public:
51         MidiRegionView (ArdourCanvas::Group *, 
52                         RouteTimeAxisView&,
53                         boost::shared_ptr<ARDOUR::MidiRegion>,
54                         double initial_samples_per_unit,
55                         Gdk::Color& basic_color);
56
57         ~MidiRegionView ();
58         
59         virtual void init (Gdk::Color& basic_color, bool wfd);
60         
61         inline const boost::shared_ptr<ARDOUR::MidiRegion> midi_region() const
62                 { return boost::dynamic_pointer_cast<ARDOUR::MidiRegion>(_region); }
63
64         inline MidiTimeAxisView* midi_view() const
65                 { return dynamic_cast<MidiTimeAxisView*>(&trackview); }
66
67         inline MidiStreamView* midi_stream_view() const
68                 { return midi_view()->midi_view(); }
69         
70         inline uint8_t contents_note_range() const
71                 { return midi_stream_view()->highest_note() - midi_stream_view()->lowest_note() + 1; }
72
73         inline double footer_height() const
74                 { return name_highlight->property_y2() - name_highlight->property_y1(); }
75
76         inline double contents_height() const
77                 { return (trackview.height - footer_height() - 5.0); }
78         
79         inline double note_height() const
80                 { return contents_height() / (double)contents_note_range(); }
81                         
82         inline double note_to_y(uint8_t note) const
83                 { return trackview.height
84                                 - (contents_height() * (note - midi_stream_view()->lowest_note() + 1))
85                                 - footer_height() - 3.0; }
86         
87         inline uint8_t y_to_note(double y) const
88                 { return (uint8_t)floor((contents_height() - y)
89                                 / contents_height() * (double)contents_note_range()); }
90         
91         void set_y_position_and_height (double, double);
92     
93     void show_region_editor ();
94
95     GhostRegion* add_ghost (AutomationTimeAxisView&);
96
97         void add_event(const ARDOUR::MidiEvent& ev);
98         void add_note(const ARDOUR::MidiModel::Note& note);
99
100         void begin_write();
101         void end_write();
102         void extend_active_notes();
103
104         void create_note_at(double x, double y);
105
106         void display_model(boost::shared_ptr<ARDOUR::MidiModel> model);
107
108         /* This stuff is a bit boilerplatey ATM.  Work in progress. */
109
110         inline void start_remove_command() {
111                 _command_mode = Remove;
112                 if (!_delta_command)
113                         _delta_command = _model->new_delta_command();
114         }
115         
116         inline void start_delta_command() {
117                 _command_mode = Delta;
118                 if (!_delta_command)
119                         _delta_command = _model->new_delta_command();
120         }
121
122         void command_remove_note(ArdourCanvas::CanvasMidiEvent* ev) {
123                 if (_delta_command && ev->note()) {
124                         _delta_command->remove(*ev->note());
125                         ev->selected(true);
126                 }
127         }
128         
129         void command_add_note(ARDOUR::MidiModel::Note& note) {
130                 if (_delta_command) {
131                         _delta_command->add(note);
132                 }
133         }
134
135         void note_entered(ArdourCanvas::CanvasMidiEvent* ev) {
136                 if (_command_mode == Remove && _delta_command && ev->note())
137                         _delta_command->remove(*ev->note());
138         }
139
140         //ARDOUR::MidiModel::DeltaCommand* delta_command() { return _delta_command; }
141
142         void abort_command() {
143                 delete _delta_command;
144                 _delta_command = NULL;
145                 _command_mode = None;
146         }
147
148         void apply_command() {
149                 if (_delta_command) {
150                         _model->apply_command(_delta_command);
151                         _delta_command = NULL;
152                 }
153                 _command_mode = None;
154         }
155
156   protected:
157
158     /* this constructor allows derived types
159        to specify their visibility requirements
160        to the TimeAxisViewItem parent class
161     */
162     
163     MidiRegionView (ArdourCanvas::Group *, 
164                         RouteTimeAxisView&,
165                         boost::shared_ptr<ARDOUR::MidiRegion>,
166                         double samples_per_unit,
167                         Gdk::Color& basic_color,
168                         TimeAxisViewItem::Visibility);
169     
170     void region_resized (ARDOUR::Change);
171
172     void set_flags (XMLNode *);
173     void store_flags ();
174     
175         void reset_width_dependent_items (double pixel_width);
176
177   private:
178
179         void redisplay_model();
180         void clear_events();
181
182         bool canvas_event(GdkEvent* ev);
183         bool note_canvas_event(GdkEvent* ev);
184
185         boost::shared_ptr<ARDOUR::MidiModel> _model;
186         std::vector<ArdourCanvas::Item*>     _events;
187         ArdourCanvas::CanvasNote**           _active_notes;
188         ARDOUR::MidiModel::DeltaCommand*     _delta_command;
189         
190         enum CommandMode { None, Remove, Delta };
191         CommandMode _command_mode;
192
193 };
194
195 #endif /* __gtk_ardour_midi_region_view_h__ */