Ardour  8.12
note_base.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013-2018 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2014-2015 David Robillard <d@drobilla.net>
4  * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef __gtk_ardour_note_base_h__
22 #define __gtk_ardour_note_base_h__
23 
24 #include <memory>
25 
26 #include "temporal/beats.h"
27 #include "canvas/types.h"
28 #include "gtkmm2ext/colors.h"
29 
30 #include "ardour/types.h"
31 
32 #include "rgb_macros.h"
33 #include "ui_config.h"
34 
35 class Editor;
36 class MidiRegionView;
37 
38 namespace Evoral {
39  template<typename T> class Note;
40  class Beats;
41 }
42 
43 namespace ArdourCanvas {
44  class Item;
45  class Text;
46 }
47 
59 class NoteBase : public sigc::trackable
60 {
61  private:
62  enum Flags {
63  Selected = 0x1,
65  };
66 
67  public:
69 
70  NoteBase (MidiRegionView& region, bool, const std::shared_ptr<NoteType> note = std::shared_ptr<NoteType>());
71  virtual ~NoteBase ();
72 
74  ArdourCanvas::Item* item() const { return _item; }
75 
76  virtual void show() = 0;
77  virtual void hide() = 0;
78 
79  bool valid() const { return _valid; }
80  void invalidate ();
81  void validate ();
82 
83  bool selected() const { return _flags & Selected; }
84  void set_selected(bool yn);
85  void set_hide_selection (bool yn);
86 
87  virtual void move_event(double dx, double dy) = 0;
88 
89  uint32_t base_color();
90  static uint32_t base_color (int velocity, ARDOUR::ColorMode color_mode, Gtkmm2ext::Color, int channel, bool selected);
91 
92  void show_velocity();
93  void hide_velocity();
94 
96  void on_channel_change(uint8_t channel);
97 
100 
101  virtual void set_outline_color(uint32_t c) = 0;
102  virtual void set_fill_color(uint32_t c) = 0;
103 
104  virtual void set_ignore_events(bool ignore) = 0;
105 
106  virtual ArdourCanvas::Coord x0 () const = 0;
107  virtual ArdourCanvas::Coord y0 () const = 0;
108  virtual ArdourCanvas::Coord x1 () const = 0;
109  virtual ArdourCanvas::Coord y1 () const = 0;
110 
111  virtual void set_velocity (double) {}
112  virtual double visual_velocity() const = 0;
113 
114  float mouse_x_fraction() const { return _mouse_x_fraction; }
115  float mouse_y_fraction() const { return _mouse_y_fraction; }
116 
117  const std::shared_ptr<NoteType> note() const { return _note; }
118  MidiRegionView& region_view() const { return _region; }
119 
120  static void set_colors ();
121 
123 
125  inline static uint32_t calculate_outline(uint32_t color, bool showing_selection = false) {
126  if (showing_selection) {
127  return _selected_col;
128  } else {
129  return UINT_INTERPOLATE(color, 0x000000ff, 0.5);
130  }
131  }
132 
134  static const uint32_t midi_channel_colors[16];
135 
136  bool mouse_near_ends () const;
137  virtual bool big_enough_to_trim () const;
138 
139 protected:
141 
146  const std::shared_ptr<NoteType> _note;
148  bool _own_note;
150  bool _valid;
153 
155 
156 private:
158 
162  static bool _color_init;
163 };
164 
165 #endif /* __gtk_ardour_note_h__ */
Definition: editor.h:158
void set_mouse_fractions(GdkEvent *)
MidiRegionView & _region
Definition: note_base.h:142
float _mouse_x_fraction
Definition: note_base.h:151
void set_hide_selection(bool yn)
const std::shared_ptr< NoteType > _note
Definition: note_base.h:146
virtual ~NoteBase()
float mouse_y_fraction() const
Definition: note_base.h:115
static uint32_t base_color(int velocity, ARDOUR::ColorMode color_mode, Gtkmm2ext::Color, int channel, bool selected)
void set_item(ArdourCanvas::Item *)
bool mouse_near_ends() const
@ Dragging
Definition: note_base.h:140
bool _own_note
Definition: note_base.h:148
bool _valid
Definition: note_base.h:150
Flags _flags
Definition: note_base.h:149
virtual void show()=0
bool event_handler(GdkEvent *)
void hide_velocity()
void invalidate()
virtual void set_fill_color(uint32_t c)=0
void on_channel_selection_change(uint16_t selection)
ArdourCanvas::Item * _item
Definition: note_base.h:143
static Gtkmm2ext::Color meter_style_fill_color(uint8_t vel, bool selected)
State _state
Definition: note_base.h:145
void on_channel_change(uint8_t channel)
bool valid() const
Definition: note_base.h:79
static const uint32_t midi_channel_colors[16]
hue circle divided into 16 equal-looking parts, courtesy Thorsten Wilms
Definition: note_base.h:134
virtual bool big_enough_to_trim() const
virtual double visual_velocity() const =0
float _mouse_y_fraction
Definition: note_base.h:152
virtual ArdourCanvas::Coord x1() const =0
bool _with_events
Definition: note_base.h:147
static Gtkmm2ext::Color velocity_color_table[128]
Definition: note_base.h:161
uint32_t base_color()
static uint32_t calculate_outline(uint32_t color, bool showing_selection=false)
calculate outline colors from fill colors of notes
Definition: note_base.h:125
virtual void set_outline_color(uint32_t c)=0
float mouse_x_fraction() const
Definition: note_base.h:114
virtual void set_velocity(double)
Definition: note_base.h:111
@ HideSelection
Definition: note_base.h:64
@ Selected
Definition: note_base.h:63
static Gtkmm2ext::SVAModifier color_modifier
Definition: note_base.h:160
const std::shared_ptr< NoteType > note() const
Definition: note_base.h:117
MidiRegionView & region_view() const
Definition: note_base.h:118
virtual void hide()=0
static bool _color_init
Definition: note_base.h:162
void validate()
static void set_colors()
void set_selected(bool yn)
ArdourCanvas::Text * _text
Definition: note_base.h:144
Evoral::Note< Temporal::Beats > NoteType
Definition: note_base.h:68
NoteBase(MidiRegionView &region, bool, const std::shared_ptr< NoteType > note=std::shared_ptr< NoteType >())
virtual ArdourCanvas::Coord y1() const =0
ArdourCanvas::Item * item() const
Definition: note_base.h:74
static Gtkmm2ext::Color _selected_col
Definition: note_base.h:159
void show_velocity()
bool selected() const
Definition: note_base.h:83
virtual ArdourCanvas::Coord x0() const =0
virtual void set_ignore_events(bool ignore)=0
virtual ArdourCanvas::Coord y0() const =0
virtual void move_event(double dx, double dy)=0
#define UINT_INTERPOLATE(c1, c2, t)
PBD::PropertyDescriptor< uint32_t > color
Definition: editor.h:87
uint32_t Color
Definition: colors.h:33
DebugBits Beats
link region and track selection