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>
25 #include "canvas/types.h"
26 #include "evoral/types.hpp"
28 #include "rgb_macros.h"
29 #include "ui_config.h"
35 template<typename T> class Note;
38 namespace ArdourCanvas {
43 /** Base class for canvas notes (sustained note rectangles and hit diamonds).
45 * This is not actually a canvas item itself to avoid the dreaded diamond
46 * inheritance pattern, since various types of canvas items (Note (rect), Hit
47 * (diamond), etc) need to share this functionality but can't share an
50 * Note: Because of this, derived classes need to manually bounce events to
51 * on_event, it won't happen automatically.
53 class NoteBase : public sigc::trackable
56 typedef Evoral::Note<Evoral::Beats> NoteType;
58 NoteBase (MidiRegionView& region, bool, const boost::shared_ptr<NoteType> note = boost::shared_ptr<NoteType>());
61 void set_item (ArdourCanvas::Item *);
62 ArdourCanvas::Item* item() const { return _item; }
64 static PBD::Signal1<void, NoteBase*> NoteBaseDeleted;
66 virtual void show() = 0;
67 virtual void hide() = 0;
69 bool valid() const { return _valid; }
73 bool selected() const { return _selected; }
74 void set_selected(bool yn);
76 virtual void move_event(double dx, double dy) = 0;
78 uint32_t base_color();
83 /** Channel changed for this specific event */
84 void on_channel_change(uint8_t channel);
86 /** Channel selection changed */
87 void on_channel_selection_change(uint16_t selection);
89 virtual void set_outline_color(uint32_t c) = 0;
90 virtual void set_fill_color(uint32_t c) = 0;
92 virtual void set_ignore_events(bool ignore) = 0;
94 virtual ArdourCanvas::Coord x0 () const = 0;
95 virtual ArdourCanvas::Coord y0 () const = 0;
96 virtual ArdourCanvas::Coord x1 () const = 0;
97 virtual ArdourCanvas::Coord y1 () const = 0;
99 float mouse_x_fraction() const { return _mouse_x_fraction; }
100 float mouse_y_fraction() const { return _mouse_y_fraction; }
102 const boost::shared_ptr<NoteType> note() const { return _note; }
103 MidiRegionView& region_view() const { return _region; }
105 inline static uint32_t meter_style_fill_color(uint8_t vel, bool selected) {
107 return UIConfiguration::instance().color_mod ("midi note selected", "midi note");
108 } else if (vel < 64) {
109 return UINT_INTERPOLATE(
110 UIConfiguration::instance().color_mod ("midi note min", "midi note"),
111 UIConfiguration::instance().color_mod ("midi note mid", "midi note"),
112 (vel / (double)63.0));
114 return UINT_INTERPOLATE(
115 UIConfiguration::instance().color_mod ("midi note mid", "midi note"),
116 UIConfiguration::instance().color_mod ("midi note max", "midi note"),
117 ((vel-64) / (double)63.0));
121 /// calculate outline colors from fill colors of notes
122 inline static uint32_t calculate_outline(uint32_t color, bool selected=false) {
124 return UIConfiguration::instance().color ("midi note selected outline");
126 return UINT_INTERPOLATE(color, 0x000000ff, 0.5);
130 /// hue circle divided into 16 equal-looking parts, courtesy Thorsten Wilms
131 static const uint32_t midi_channel_colors[16];
133 bool mouse_near_ends () const;
134 virtual bool big_enough_to_trim () const;
137 enum State { None, Pressed, Dragging };
139 MidiRegionView& _region;
140 ArdourCanvas::Item* _item;
141 ArdourCanvas::Text* _text;
143 const boost::shared_ptr<NoteType> _note;
148 float _mouse_x_fraction;
149 float _mouse_y_fraction;
151 void set_mouse_fractions (GdkEvent*);
154 bool event_handler (GdkEvent *);
157 #endif /* __gtk_ardour_note_h__ */