2 Copyright (C) 2007 Paul Davis
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.
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.
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.
20 #ifndef __gtk_ardour_canvas_midi_event_h__
21 #define __gtk_ardour_canvas_midi_event_h__
24 #include <libgnomecanvasmm/text.h>
25 #include <libgnomecanvasmm/widget.h>
26 #include <ardour/midi_model.h>
28 #include "rgb_macros.h"
29 #include "ardour_ui.h"
30 #include "ui_config.h"
31 #include "simplerect.h"
32 #include "midi_channel_selector.h"
41 /** This manages all the event handling for any MIDI event on the canvas.
43 * This is not actually a canvas item itself to avoid the dreaded diamond,
44 * since various types of canvas items (Note (rect), Hit (diamond), etc)
45 * need to share this functionality but can't share an ancestor.
47 * Note: Because of this, derived classes need to manually bounce events to
48 * on_event, it won't happen automatically.
50 * A newer, better canvas should remove the need for all the ugly here.
52 class CanvasNoteEvent : public sigc::trackable {
55 MidiRegionView& region,
57 const boost::shared_ptr<Evoral::Note> note = boost::shared_ptr<Evoral::Note>());
59 virtual ~CanvasNoteEvent();
61 bool on_event(GdkEvent* ev);
63 bool selected() const { return _selected; }
64 void selected(bool yn);
66 void move_event(double dx, double dy);
72 * This slot is called, when a new channel is selected for the single event
74 void on_channel_change(uint8_t channel);
75 void on_channel_selection_change(uint16_t selection);
77 void show_channel_selector();
79 void hide_channel_selector();
81 virtual void set_outline_color(uint32_t c) = 0;
82 virtual void set_fill_color(uint32_t c) = 0;
84 virtual double x1() = 0;
85 virtual double y1() = 0;
86 virtual double x2() = 0;
87 virtual double y2() = 0;
89 const boost::shared_ptr<Evoral::Note> note() const { return _note; }
91 inline static uint32_t meter_style_fill_color(uint8_t vel)
94 return UINT_INTERPOLATE(
95 ARDOUR_UI::config()->canvasvar_MeterColorBase.get(),
96 ARDOUR_UI::config()->canvasvar_MeterColorMid.get(),
97 (vel / (double)63.0));
99 return UINT_INTERPOLATE(
100 ARDOUR_UI::config()->canvasvar_MeterColorMid.get(),
101 ARDOUR_UI::config()->canvasvar_MeterColorTop.get(),
102 ((vel-64) / (double)63.0));
106 inline static uint32_t meter_style_outline_color(uint8_t vel)
108 return calculate_outline(meter_style_fill_color(vel));
111 /// calculate outline colors from fill colors of notes
112 inline static uint32_t calculate_outline(uint32_t color)
114 return UINT_INTERPOLATE(color, 0x000000ff, 0.5);
117 /// dividing the hue circle in 16 parts, hand adjusted for equal look, courtesy Thorsten Wilms
118 static const uint32_t midi_channel_colors[16];
121 enum State { None, Pressed, Dragging };
123 MidiRegionView& _region;
126 Widget* _channel_selector_widget;
128 const boost::shared_ptr<Evoral::Note> _note;
134 } // namespace Canvas
136 #endif /* __gtk_ardour_canvas_midi_event_h__ */