fix some missing color definitions
[ardour.git] / gtk2_ardour / note_base.h
1 /*
2     Copyright (C) 2007 Paul Davis
3     Author: David 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_note_base_h__
21 #define __gtk_ardour_note_base_h__
22
23 #include <boost/shared_ptr.hpp>
24
25 #include "canvas/types.h"
26 #include "evoral/types.hpp"
27
28 #include "rgb_macros.h"
29 #include "ardour_ui.h"
30 #include "ui_config.h"
31
32 class Editor;
33 class MidiRegionView;
34
35 namespace Evoral {
36         template<typename T> class Note;
37 }
38
39 namespace ArdourCanvas {
40         class Item;
41         class Text;
42 }
43
44 /** This manages all the event handling for any MIDI event on the canvas.
45  *
46  * This is not actually a canvas item itself to avoid the dreaded diamond
47  * inheritance pattern, since various types of canvas items (Note (rect), Hit
48  * (diamond), etc) need to share this functionality but can't share an
49  * ancestor. 
50  *
51  * Note: Because of this, derived classes need to manually bounce events to
52  * on_event, it won't happen automatically.
53  */
54
55 class NoteBase : public sigc::trackable
56 {
57   public:
58         typedef Evoral::Note<Evoral::MusicalTime> NoteType;
59
60         NoteBase (MidiRegionView& region, bool, const boost::shared_ptr<NoteType> note = boost::shared_ptr<NoteType>());
61         virtual ~NoteBase ();
62
63         void set_item (ArdourCanvas::Item *);
64         ArdourCanvas::Item* item() const { return _item; }
65
66         static PBD::Signal1<void, NoteBase*> NoteBaseDeleted;
67
68         virtual void show() = 0;
69         virtual void hide() = 0;
70
71         bool valid() const { return _valid; }
72         void invalidate ();
73         void validate ();
74
75         bool selected() const { return _selected; }
76         void set_selected(bool yn);
77
78         virtual void move_event(double dx, double dy) = 0;
79
80         uint32_t base_color();
81
82         void show_velocity();
83         void hide_velocity();
84
85         /** Channel changed for this specific event */
86         void on_channel_change(uint8_t channel);
87
88         /** Channel selection changed */
89         void on_channel_selection_change(uint16_t selection);
90
91         virtual void set_outline_color(uint32_t c) = 0;
92         virtual void set_fill_color(uint32_t c) = 0;
93
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;
98
99         float mouse_x_fraction() const { return _mouse_x_fraction; }
100         float mouse_y_fraction() const { return _mouse_y_fraction; }
101
102         const boost::shared_ptr<NoteType> note() const { return _note; }
103         MidiRegionView& region_view() const { return _region; }
104
105         inline static uint32_t meter_style_fill_color(uint8_t vel, bool selected) {
106                 if (selected) {
107                         if (vel < 64) {
108                                 return UINT_INTERPOLATE(
109                                         ARDOUR_UI::config()->color_mod ("selected midi note min", "selected midi note"),
110                                         ARDOUR_UI::config()->color_mod ("selected midi note mid", "selected midi note"),
111                                         (vel / (double)63.0));
112                         } else {
113                                 return UINT_INTERPOLATE(
114                                         ARDOUR_UI::config()->color_mod ("selected midi note mid", "selected midi note"),
115                                         ARDOUR_UI::config()->color_mod ("selected midi note max", "selected midi note"),
116                                         ((vel-64) / (double)63.0));
117                         }
118                 } else {
119                         if (vel < 64) {
120                                 return UINT_INTERPOLATE(
121                                         ARDOUR_UI::config()->color_mod ("midi note min", "midi note"),
122                                         ARDOUR_UI::config()->color_mod ("midi note mid", "midi note"),
123                                         (vel / (double)63.0));
124                         } else {
125                                 return UINT_INTERPOLATE(
126                                         ARDOUR_UI::config()->color_mod ("midi note mid", "midi note"),
127                                         ARDOUR_UI::config()->color_mod ("midi note max", " midi note"),
128                                         ((vel-64) / (double)63.0));
129                         }
130                 }
131         }
132
133         /// calculate outline colors from fill colors of notes
134         inline static uint32_t calculate_outline(uint32_t color) {
135                 return UINT_INTERPOLATE(color, 0x000000ff, 0.5);
136         }
137
138         /// hue circle divided into 16 equal-looking parts, courtesy Thorsten Wilms
139         static const uint32_t midi_channel_colors[16];
140
141         bool mouse_near_ends () const;
142         virtual bool big_enough_to_trim () const;
143
144 protected:
145         enum State { None, Pressed, Dragging };
146
147         MidiRegionView&                   _region;
148         ArdourCanvas::Item*               _item;
149         ArdourCanvas::Text*               _text;
150         State                             _state;
151         const boost::shared_ptr<NoteType> _note;
152         bool                              _with_events;
153         bool                              _own_note;
154         bool                              _selected;
155         bool                              _valid;
156         float                             _mouse_x_fraction;
157         float                             _mouse_y_fraction;
158         
159         void set_mouse_fractions (GdkEvent*);
160
161 private:
162         bool event_handler (GdkEvent *);
163 };
164
165 #endif /* __gtk_ardour_note_h__ */