first part of MIDI cut/copy/paste ; fix for input/output_streams of an IOProcessor...
[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 <boost/shared_ptr.hpp>
24 #include <libgnomecanvasmm/text.h>
25 #include <libgnomecanvasmm/widget.h>
26
27 #include "ardour/midi_model.h"
28
29 #include "rgb_macros.h"
30 #include "ardour_ui.h"
31 #include "ui_config.h"
32 #include "interactive-item.h"
33
34 class Editor;
35 class MidiRegionView;
36
37 namespace Evoral { template<typename T> class Note; }
38
39 namespace Gnome {
40 namespace Canvas {
41
42
43 /** This manages all the event handling for any MIDI event on the canvas.
44  *
45  * This is not actually a canvas item itself to avoid the dreaded diamond,
46  * since various types of canvas items (Note (rect), Hit (diamond), etc)
47  * need to share this functionality but can't share an ancestor.
48  *
49  * Note: Because of this, derived classes need to manually bounce events to
50  * on_event, it won't happen automatically.
51  *
52  * A newer, better canvas should remove the need for all the ugly here.
53  */
54 class CanvasNoteEvent : virtual public sigc::trackable, public InteractiveItem {
55 public:
56         typedef Evoral::Note<ARDOUR::MidiModel::TimeType> NoteType;
57
58         CanvasNoteEvent(
59                         MidiRegionView&                   region,
60                         Item*                             item,
61                         const boost::shared_ptr<NoteType> note = boost::shared_ptr<NoteType>());
62
63         virtual ~CanvasNoteEvent();
64
65         virtual void show() = 0;
66         virtual void hide() = 0;
67         virtual bool on_event(GdkEvent* ev);
68
69         bool selected() const { return _selected; }
70         void selected(bool yn);
71
72         void move_event(double dx, double dy);
73         
74         uint32_t base_color();
75         
76         void show_velocity();
77         void hide_velocity();
78         
79         /** Channel changed for this specific event */
80         void on_channel_change(uint8_t channel);
81
82         /** Channel selection changed */
83         void on_channel_selection_change(uint16_t selection);
84         
85         void show_channel_selector();
86         void hide_channel_selector();
87
88         virtual void set_outline_color(uint32_t c) = 0;
89         virtual void set_fill_color(uint32_t c) = 0;
90         
91         virtual double x1() = 0;
92         virtual double y1() = 0;
93         virtual double x2() = 0;
94         virtual double y2() = 0;
95
96         const boost::shared_ptr<NoteType> note() const { return _note; }
97         
98         inline static uint32_t meter_style_fill_color(uint8_t vel) {
99                 if (vel < 64) {
100                         return UINT_INTERPOLATE(
101                                         ARDOUR_UI::config()->canvasvar_MidiNoteMeterColorBase.get(),
102                                         ARDOUR_UI::config()->canvasvar_MidiNoteMeterColorMid.get(),
103                                         (vel / (double)63.0));
104                 } else {
105                         return UINT_INTERPOLATE(
106                                         ARDOUR_UI::config()->canvasvar_MidiNoteMeterColorMid.get(),
107                                         ARDOUR_UI::config()->canvasvar_MidiNoteMeterColorTop.get(),
108                                         ((vel-64) / (double)63.0));
109                 }
110         }
111         
112         /// calculate outline colors from fill colors of notes
113         inline static uint32_t calculate_outline(uint32_t color) {
114                 return UINT_INTERPOLATE(color, 0x000000ff, 0.5);
115         }
116         
117         /// hue circle divided into 16 equal-looking parts, courtesy Thorsten Wilms
118         static const uint32_t midi_channel_colors[16];
119
120 protected:
121         enum State { None, Pressed, Dragging };
122
123         MidiRegionView&                   _region;
124         Item* const                       _item;
125         InteractiveText*                  _text;
126         Widget*                           _channel_selector_widget;
127         State                             _state;
128         const boost::shared_ptr<NoteType> _note;
129         bool                              _own_note;
130         bool                              _selected;
131 };
132
133 } // namespace Gnome
134 } // namespace Canvas
135
136 #endif /* __gtk_ardour_canvas_midi_event_h__ */