Only show user-presets in favorite sidebar
[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 "temporal/beats.h"
26 #include "canvas/types.h"
27 #include "gtkmm2ext/colors.h"
28
29 #include "rgb_macros.h"
30 #include "ui_config.h"
31
32 class Editor;
33 class MidiRegionView;
34
35 namespace Evoral {
36         template<typename T> class Note;
37         class Beats;
38 }
39
40 namespace ArdourCanvas {
41         class Item;
42         class Text;
43 }
44
45 /** Base class for canvas notes (sustained note rectangles and hit diamonds).
46  *
47  * This is not actually a canvas item itself to avoid the dreaded diamond
48  * inheritance pattern, since various types of canvas items (Note (rect), Hit
49  * (diamond), etc) need to share this functionality but can't share an
50  * ancestor.
51  *
52  * Note: Because of this, derived classes need to manually bounce events to
53  * on_event, it won't happen automatically.
54  */
55 class NoteBase : public sigc::trackable
56 {
57 public:
58         typedef Evoral::Note<Temporal::Beats> 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         virtual void show() = 0;
67         virtual void hide() = 0;
68
69         bool valid() const { return _valid; }
70         void invalidate ();
71         void validate ();
72
73         bool selected() const { return _selected; }
74         void set_selected(bool yn);
75
76         virtual void move_event(double dx, double dy) = 0;
77
78         uint32_t base_color();
79
80         void show_velocity();
81         void hide_velocity();
82
83         /** Channel changed for this specific event */
84         void on_channel_change(uint8_t channel);
85
86         /** Channel selection changed */
87         void on_channel_selection_change(uint16_t selection);
88
89         virtual void set_outline_color(uint32_t c) = 0;
90         virtual void set_fill_color(uint32_t c) = 0;
91
92         virtual void set_ignore_events(bool ignore) = 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         static void set_colors ();
106
107         static Gtkmm2ext::Color meter_style_fill_color(uint8_t vel, bool selected);
108
109         /// calculate outline colors from fill colors of notes
110         inline static uint32_t calculate_outline(uint32_t color, bool selected=false) {
111                 if (selected) {
112                         return _selected_col;
113                 } else {
114                         return UINT_INTERPOLATE(color, 0x000000ff, 0.5);
115                 }
116         }
117
118         /// hue circle divided into 16 equal-looking parts, courtesy Thorsten Wilms
119         static const uint32_t midi_channel_colors[16];
120
121         bool mouse_near_ends () const;
122         virtual bool big_enough_to_trim () const;
123
124 protected:
125         enum State { None, Pressed, Dragging };
126
127         MidiRegionView&                   _region;
128         ArdourCanvas::Item*               _item;
129         ArdourCanvas::Text*               _text;
130         State                             _state;
131         const boost::shared_ptr<NoteType> _note;
132         bool                              _with_events;
133         bool                              _own_note;
134         bool                              _selected;
135         bool                              _valid;
136         float                             _mouse_x_fraction;
137         float                             _mouse_y_fraction;
138
139         void set_mouse_fractions (GdkEvent*);
140
141 private:
142         bool event_handler (GdkEvent *);
143
144         static Gtkmm2ext::Color _selected_col;
145         static Gtkmm2ext::SVAModifier color_modifier;
146         static Gtkmm2ext::Color velocity_color_table[128];
147         static bool _color_init;
148 };
149
150 #endif /* __gtk_ardour_note_h__ */