Fix invalid error message during MIDI recording (or files with stuck notes).
[ardour.git] / gtk2_ardour / canvas-note-event.h
1 /*
2     Copyright (C) 2007 Paul Davis 
3     Author: Dave Robillard
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __gtk_ardour_canvas_midi_event_h__
21 #define __gtk_ardour_canvas_midi_event_h__
22
23 #include "simplerect.h"
24 #include "midi_channel_selector.h"
25 #include <libgnomecanvasmm/text.h>
26 #include <libgnomecanvasmm/widget.h>
27 #include <ardour/midi_model.h>
28
29 class Editor;
30 class MidiRegionView;
31
32 namespace Gnome {
33 namespace Canvas {
34
35
36 /** This manages all the event handling for any MIDI event on the canvas.
37  *
38  * This is not actually a canvas item itself to avoid the dreaded diamond,
39  * since various types of canvas items (Note (rect), Hit (diamond), etc)
40  * need to share this functionality but can't share an ancestor.
41  *
42  * Note: Because of this, derived classes need to manually bounce events to
43  * on_event, it won't happen automatically.
44  *
45  * A newer, better canvas should remove the need for all the ugly here.
46  */
47 class CanvasNoteEvent : public sigc::trackable {
48 public:
49         CanvasNoteEvent(
50                         MidiRegionView&                       region,
51                         Item*                                 item,
52                         const boost::shared_ptr<ARDOUR::Note> note = boost::shared_ptr<ARDOUR::Note>());
53
54         virtual ~CanvasNoteEvent();
55
56         bool on_event(GdkEvent* ev);
57
58         bool selected() const { return _selected; }
59         void selected(bool yn);
60
61         void move_event(double dx, double dy);
62         
63         void show_velocity();
64         void hide_velocity();
65         
66         /**
67          * This slot is called, when a new channel is selected for the single event
68          * */
69         void on_channel_change(uint8_t channel);
70         void on_channel_selection_change(uint16_t selection);
71         
72         void show_channel_selector();
73         
74         void hide_channel_selector();
75
76         virtual void set_outline_color(uint32_t c) = 0;
77         virtual void set_fill_color(uint32_t c) = 0;
78         
79         virtual double x1() = 0;
80         virtual double y1() = 0;
81         virtual double x2() = 0;
82         virtual double y2() = 0;
83
84         const boost::shared_ptr<ARDOUR::Note> note() const { return _note; }
85
86 protected:
87         enum State { None, Pressed, Dragging };
88
89         MidiRegionView&                       _region;
90         Item* const                           _item;
91         Text*                                 _text;
92         Widget*                               _channel_selector_widget;
93         State                                 _state;
94         const boost::shared_ptr<ARDOUR::Note> _note;
95         bool                                  _own_note;
96         bool                                  _selected;
97 };
98
99 } // namespace Gnome
100 } // namespace Canvas
101
102 #endif /* __gtk_ardour_canvas_midi_event_h__ */