2 Copyright (C) 2007 Paul Davis
3 Author: David Robillard
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_note_base_h__
21 #define __gtk_ardour_note_base_h__
23 #include <boost/shared_ptr.hpp>
24 #include "canvas/types.h"
25 #include "ardour/midi_model.h"
27 #include "rgb_macros.h"
28 #include "ardour_ui.h"
29 #include "ui_config.h"
35 template<typename T> class Note;
38 namespace ArdourCanvas {
43 /** This manages all the event handling for any MIDI event on the canvas.
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.
49 * Note: Because of this, derived classes need to manually bounce events to
50 * on_event, it won't happen automatically.
52 * A newer, better canvas should remove the need for all the ugly here.
54 class NoteBase : public sigc::trackable
57 typedef Evoral::Note<ARDOUR::MidiModel::TimeType> NoteType;
60 MidiRegionView& region,
62 const boost::shared_ptr<NoteType> note = boost::shared_ptr<NoteType>()
67 void set_item (ArdourCanvas::Item *);
69 static PBD::Signal1<void, NoteBase*> NoteBaseDeleted;
71 virtual void show() = 0;
72 virtual void hide() = 0;
74 bool valid() const { return _valid; }
78 bool selected() const { return _selected; }
79 void set_selected(bool yn);
81 virtual void move_event(double dx, double dy) = 0;
83 uint32_t base_color();
88 /** Channel changed for this specific event */
89 void on_channel_change(uint8_t channel);
91 /** Channel selection changed */
92 void on_channel_selection_change(uint16_t selection);
94 virtual void set_outline_color(uint32_t c) = 0;
95 virtual void set_fill_color(uint32_t c) = 0;
97 virtual ArdourCanvas::Coord x0 () const = 0;
98 virtual ArdourCanvas::Coord y0 () const = 0;
99 virtual ArdourCanvas::Coord x1 () const = 0;
100 virtual ArdourCanvas::Coord y1 () const = 0;
102 float mouse_x_fraction() const { return _mouse_x_fraction; }
103 float mouse_y_fraction() const { return _mouse_y_fraction; }
105 const boost::shared_ptr<NoteType> note() const { return _note; }
106 MidiRegionView& region_view() const { return _region; }
108 inline static uint32_t meter_style_fill_color(uint8_t vel, bool selected) {
111 return UINT_INTERPOLATE(
112 ARDOUR_UI::config()->get_canvasvar_SelectedMidiNoteColorBase(),
113 ARDOUR_UI::config()->get_canvasvar_SelectedMidiNoteColorMid(),
114 (vel / (double)63.0));
116 return UINT_INTERPOLATE(
117 ARDOUR_UI::config()->get_canvasvar_SelectedMidiNoteColorMid(),
118 ARDOUR_UI::config()->get_canvasvar_SelectedMidiNoteColorTop(),
119 ((vel-64) / (double)63.0));
123 return UINT_INTERPOLATE(
124 ARDOUR_UI::config()->get_canvasvar_MidiNoteColorBase(),
125 ARDOUR_UI::config()->get_canvasvar_MidiNoteColorMid(),
126 (vel / (double)63.0));
128 return UINT_INTERPOLATE(
129 ARDOUR_UI::config()->get_canvasvar_MidiNoteColorMid(),
130 ARDOUR_UI::config()->get_canvasvar_MidiNoteColorTop(),
131 ((vel-64) / (double)63.0));
136 /// calculate outline colors from fill colors of notes
137 inline static uint32_t calculate_outline(uint32_t color) {
138 return UINT_INTERPOLATE(color, 0x000000ff, 0.5);
141 /// hue circle divided into 16 equal-looking parts, courtesy Thorsten Wilms
142 static const uint32_t midi_channel_colors[16];
144 bool mouse_near_ends () const;
145 bool big_enough_to_trim () const;
148 enum State { None, Pressed, Dragging };
150 MidiRegionView& _region;
151 ArdourCanvas::Item* _item;
152 ArdourCanvas::Text* _text;
154 const boost::shared_ptr<NoteType> _note;
159 float _mouse_x_fraction;
160 float _mouse_y_fraction;
162 void set_mouse_fractions (GdkEvent*);
165 bool event_handler (GdkEvent *);
168 #endif /* __gtk_ardour_note_h__ */