ardour
note_base.h
Go to the documentation of this file.
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 
54 class NoteBase : public sigc::trackable
55 {
56  public:
58 
60  virtual ~NoteBase ();
61 
62  void set_item (ArdourCanvas::Item *);
63  ArdourCanvas::Item* item() const { return _item; }
64 
65  static PBD::Signal1<void, NoteBase*> NoteBaseDeleted;
66 
67  virtual void show() = 0;
68  virtual void hide() = 0;
69 
70  bool valid() const { return _valid; }
71  void invalidate ();
72  void validate ();
73 
74  bool selected() const { return _selected; }
75  void set_selected(bool yn);
76 
77  virtual void move_event(double dx, double dy) = 0;
78 
79  uint32_t base_color();
80 
81  void show_velocity();
82  void hide_velocity();
83 
85  void on_channel_change(uint8_t channel);
86 
88  void on_channel_selection_change(uint16_t selection);
89 
90  virtual void set_outline_color(uint32_t c) = 0;
91  virtual void set_fill_color(uint32_t c) = 0;
92 
93  virtual void set_ignore_events(bool ignore) = 0;
94 
95  virtual ArdourCanvas::Coord x0 () const = 0;
96  virtual ArdourCanvas::Coord y0 () const = 0;
97  virtual ArdourCanvas::Coord x1 () const = 0;
98  virtual ArdourCanvas::Coord y1 () const = 0;
99 
100  float mouse_x_fraction() const { return _mouse_x_fraction; }
101  float mouse_y_fraction() const { return _mouse_y_fraction; }
102 
103  const boost::shared_ptr<NoteType> note() const { return _note; }
104  MidiRegionView& region_view() const { return _region; }
105 
106  inline static uint32_t meter_style_fill_color(uint8_t vel, bool selected) {
107  if (selected) {
108  return ARDOUR_UI::config()->color_mod ("midi note selected", "midi note");
109  } else if (vel < 64) {
110  return UINT_INTERPOLATE(
111  ARDOUR_UI::config()->color_mod ("midi note min", "midi note"),
112  ARDOUR_UI::config()->color_mod ("midi note mid", "midi note"),
113  (vel / (double)63.0));
114  } else {
115  return UINT_INTERPOLATE(
116  ARDOUR_UI::config()->color_mod ("midi note mid", "midi note"),
117  ARDOUR_UI::config()->color_mod ("midi note max", "midi note"),
118  ((vel-64) / (double)63.0));
119  }
120  }
121 
123  inline static uint32_t calculate_outline(uint32_t color, bool selected=false) {
124  if (selected) {
125  return ARDOUR_UI::config()->color ("midi note selected outline");
126  } else {
127  return UINT_INTERPOLATE(color, 0x000000ff, 0.5);
128  }
129  }
130 
132  static const uint32_t midi_channel_colors[16];
133 
134  bool mouse_near_ends () const;
135  virtual bool big_enough_to_trim () const;
136 
137 protected:
139 
141  ArdourCanvas::Item* _item;
142  ArdourCanvas::Text* _text;
146  bool _own_note;
147  bool _selected;
148  bool _valid;
151 
152  void set_mouse_fractions (GdkEvent*);
153 
154 private:
155  bool event_handler (GdkEvent *);
156 };
157 
158 #endif /* __gtk_ardour_note_h__ */
float _mouse_y_fraction
Definition: note_base.h:150
ArdourCanvas::Color color(const std::string &, bool *failed=0) const
Definition: ui_config.cc:567
virtual ArdourCanvas::Coord x1() const =0
virtual ~NoteBase()
Definition: note_base.cc:63
static const uint32_t midi_channel_colors[16]
hue circle divided into 16 equal-looking parts, courtesy Thorsten Wilms
Definition: note_base.h:132
void on_channel_selection_change(uint16_t selection)
Definition: note_base.cc:120
static uint32_t calculate_outline(uint32_t color, bool selected=false)
calculate outline colors from fill colors of notes
Definition: note_base.h:123
MidiRegionView & _region
Definition: note_base.h:140
Definition: note.h:32
bool valid() const
Definition: note_base.h:70
static PBD::Signal1< void, NoteBase * > NoteBaseDeleted
Definition: note_base.h:65
virtual ArdourCanvas::Coord x0() const =0
virtual ArdourCanvas::Coord y1() const =0
virtual ArdourCanvas::Coord y0() const =0
void validate()
Definition: note_base.cc:88
NoteBase(MidiRegionView &region, bool, const boost::shared_ptr< NoteType > note=boost::shared_ptr< NoteType >())
Definition: note_base.cc:49
virtual void set_outline_color(uint32_t c)=0
virtual void show()=0
bool _with_events
Definition: note_base.h:145
float _mouse_x_fraction
Definition: note_base.h:149
MidiRegionView & region_view() const
Definition: note_base.h:104
virtual void hide()=0
ArdourCanvas::Item * item() const
Definition: note_base.h:63
float mouse_x_fraction() const
Definition: note_base.h:100
void show_velocity()
Definition: note_base.cc:94
uint32_t base_color()
Definition: note_base.cc:159
static uint32_t meter_style_fill_color(uint8_t vel, bool selected)
Definition: note_base.h:106
void set_selected(bool yn)
Definition: note_base.cc:144
State _state
Definition: note_base.h:143
void hide_velocity()
Definition: note_base.cc:113
virtual void set_fill_color(uint32_t c)=0
ArdourCanvas::Item * _item
Definition: note_base.h:141
const boost::shared_ptr< NoteType > note() const
Definition: note_base.h:103
float mouse_y_fraction() const
Definition: note_base.h:101
ArdourCanvas::Text * _text
Definition: note_base.h:142
Evoral::Note< Evoral::Beats > NoteType
Definition: note_base.h:57
virtual void move_event(double dx, double dy)=0
bool event_handler(GdkEvent *)
Definition: note_base.cc:255
bool mouse_near_ends() const
Definition: note_base.cc:293
Definition: editor.h:134
bool _own_note
Definition: note_base.h:146
virtual void set_ignore_events(bool ignore)=0
ArdourCanvas::Color color_mod(std::string const &color, std::string const &modifier) const
Definition: ui_config.cc:555
static UIConfiguration * config()
Definition: ardour_ui.h:188
bool _valid
Definition: note_base.h:148
void invalidate()
Definition: note_base.cc:82
bool selected() const
Definition: note_base.h:74
bool _selected
Definition: note_base.h:147
#define UINT_INTERPOLATE(c1, c2, t)
Definition: rgb_macros.h:70
const boost::shared_ptr< NoteType > _note
Definition: note_base.h:144
void on_channel_change(uint8_t channel)
Definition: note_base.cc:137
virtual bool big_enough_to_trim() const
Definition: note_base.cc:300
void set_item(ArdourCanvas::Item *)
Definition: note_base.cc:71
void set_mouse_fractions(GdkEvent *)
Definition: note_base.cc:189
LIBARDOUR_API PBD::PropertyDescriptor< bool > color
Definition: route_group.cc:50