Fix MIDI rec regions.
[ardour.git] / gtk2_ardour / midi_streamview.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 __ardour_midi_streamview_h__
20 #define __ardour_midi_streamview_h__
21
22 #include <list>
23 #include <cmath>
24
25 #include "ardour/location.h"
26 #include "enums.h"
27 #include "streamview.h"
28 #include "time_axis_view_item.h"
29 #include "route_time_axis.h"
30 #include "canvas.h"
31
32 namespace Gdk {
33         class Color;
34 }
35
36 namespace ARDOUR {
37         class Route;
38         class Diskstream;
39         class Crossfade;
40         class PeakData;
41         class MidiRegion;
42         class Source;
43         class MidiModel;
44 }
45
46 class PublicEditor;
47 class Selectable;
48 class MidiTimeAxisView;
49 class MidiRegionView;
50 class RegionSelection;
51 class CrossfadeView;
52 class Selection;
53
54 class MidiStreamView : public StreamView
55 {
56   public:
57         MidiStreamView (MidiTimeAxisView&);
58         ~MidiStreamView ();
59
60         void set_selected_regionviews (RegionSelection&);
61         void get_selectables (nframes_t start, nframes_t end, std::list<Selectable* >&);
62         void get_inverted_selectables (Selection&, std::list<Selectable* >& results);
63
64         enum VisibleNoteRange {
65                 FullRange,
66                 ContentsRange
67         };
68
69         Gtk::Adjustment note_range_adjustment;
70         ArdourCanvas::Group* midi_underlay_group;
71
72         void set_note_range(VisibleNoteRange r);
73
74         inline uint8_t lowest_note()  const { return _lowest_note; }
75         inline uint8_t highest_note() const { return _highest_note; }
76
77         void update_note_range(uint8_t note_num);
78
79         void redisplay_diskstream ();
80
81         inline double contents_height() const
82         { return (_trackview.current_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 2); }
83
84         inline double note_to_y(uint8_t note) const
85                 { return contents_height()
86                         - (note + 1 - lowest_note()) * note_height() + 1; }
87
88         inline uint8_t y_to_note(double y) const
89                 { return (uint8_t)((contents_height() - y - 1)
90                                 / contents_height() * (double)contents_note_range())
91                                 + lowest_note(); }
92
93         inline double note_height() const
94                 { return contents_height() / (double)contents_note_range(); }
95
96         inline uint8_t contents_note_range() const
97                 { return highest_note() - lowest_note() + 1; }
98
99         sigc::signal<void> NoteRangeChanged;
100
101         RegionView* create_region_view (boost::shared_ptr<ARDOUR::Region>, bool, bool);
102
103   private:
104         void setup_rec_box ();
105
106         void rec_data_range_ready (
107                         nframes_t start,
108                         nframes_t dur,
109                         boost::weak_ptr<ARDOUR::Source> src);
110
111         void update_rec_regions (
112                         boost::shared_ptr<ARDOUR::MidiModel> data,
113                         nframes_t start,
114                         nframes_t dur);
115
116         RegionView* add_region_view_internal (
117                         boost::shared_ptr<ARDOUR::Region>,
118                         bool wait_for_waves,
119                         bool recording = false);
120
121         void display_region(MidiRegionView* region_view, bool load_model);
122         void display_diskstream (boost::shared_ptr<ARDOUR::Diskstream> ds);
123
124         void update_contents_height ();
125         void draw_note_lines();
126         void apply_note_range(uint8_t lowest, uint8_t highest, bool to_region_views);
127         bool update_data_note_range(uint8_t min, uint8_t max);
128         void update_contents_metrics(boost::shared_ptr<ARDOUR::Region> r);
129
130         void color_handler ();
131
132         void note_range_adjustment_changed();
133
134         bool                      _range_dirty;
135         double                    _range_sum_cache;
136         uint8_t                   _lowest_note;   ///< currently visible
137         uint8_t                   _highest_note;  ///< currently visible
138         uint8_t                   _data_note_min; ///< in data
139         uint8_t                   _data_note_max; ///< in data
140         ArdourCanvas::LineSet*    _note_lines;
141 };
142
143 #endif /* __ardour_midi_streamview_h__ */