* first working version of editing MIDI channels of individual notes, see: http:...
[ardour.git] / gtk2_ardour / canvas-midi-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 CanvasMidiEvent {
48 public:
49         CanvasMidiEvent(
50                         MidiRegionView&                       region,
51                         Item*                                 item,
52                         const boost::shared_ptr<ARDOUR::Note> note = boost::shared_ptr<ARDOUR::Note>());
53
54         virtual ~CanvasMidiEvent();
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 event
68          * */
69         void on_channel_change(uint8_t channel);
70         
71         void show_channel_selector();
72         
73         void hide_channel_selector();
74
75         virtual void set_outline_color(uint32_t c) = 0;
76         virtual void set_fill_color(uint32_t c) = 0;
77         
78         virtual double x1() = 0;
79         virtual double y1() = 0;
80         virtual double x2() = 0;
81         virtual double y2() = 0;
82
83         const boost::shared_ptr<ARDOUR::Note> note() { return _note; }
84
85 protected:
86         enum State { None, Pressed, Dragging };
87
88         MidiRegionView&                       _region;
89         Item* const                           _item;
90         Text*                                 _text;
91         Widget*                               _channel_selector_widget;
92         State                                 _state;
93         const boost::shared_ptr<ARDOUR::Note> _note;
94         bool                                  _own_note;
95         bool                                  _selected;
96 };
97
98 } // namespace Gnome
99 } // namespace Canvas
100
101 #endif /* __gtk_ardour_canvas_midi_event_h__ */