Ardour  9.2-541-gc1841a13dd
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 #pragma once
22 
23 #include <memory>
24 #include <vector>
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 MidiView;
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 (MidiView& 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 pitch, int velocity, ARDOUR::ColorMode color_mode, Gtkmm2ext::Color, int channel, bool selected);
91 
92  void show_velocity();
93  void hide_velocity();
94 
97 
98  virtual void set_outline_color(uint32_t c) = 0;
99  virtual void set_fill_color(uint32_t c) = 0;
100 
101  virtual void set_ignore_events(bool ignore) = 0;
102 
103  virtual ArdourCanvas::Coord x0 () const = 0;
104  virtual ArdourCanvas::Coord y0 () const = 0;
105  virtual ArdourCanvas::Coord x1 () const = 0;
106  virtual ArdourCanvas::Coord y1 () const = 0;
107 
108  virtual void set_velocity (double) {}
109  virtual double visual_velocity() const = 0;
110 
111  float mouse_x_fraction() const { return _mouse_x_fraction; }
112  float mouse_y_fraction() const { return _mouse_y_fraction; }
113 
114  const std::shared_ptr<NoteType> note() const { return _note; }
115  MidiView& midi_view() const { return _view; }
116 
117  static void set_colors ();
118 
121 
123  inline static uint32_t calculate_outline(uint32_t color, bool showing_selection = false) {
124  if (showing_selection) {
125  return _selected_col;
126  } else {
127  return UINT_INTERPOLATE(color, 0x000000ff, 0.5);
128  }
129  }
130 
132  static const uint32_t midi_channel_colors[16];
133  static std::vector<uint32_t> pitch_colors;
134 
135  bool mouse_near_ends () const;
136  virtual bool big_enough_to_trim () const;
137 
138 protected:
140 
145  const std::shared_ptr<NoteType> _note;
147  bool _own_note;
149  bool _valid;
152 
154 
155 private:
157 
161  static bool _color_init;
162 };
163 
Definition: editor.h:157
void set_mouse_fractions(GdkEvent *)
float _mouse_x_fraction
Definition: note_base.h:150
void set_hide_selection(bool yn)
const std::shared_ptr< NoteType > _note
Definition: note_base.h:145
virtual ~NoteBase()
float mouse_y_fraction() const
Definition: note_base.h:112
void set_item(ArdourCanvas::Item *)
bool mouse_near_ends() const
@ Dragging
Definition: note_base.h:139
bool _own_note
Definition: note_base.h:147
bool _valid
Definition: note_base.h:149
Flags _flags
Definition: note_base.h:148
virtual void show()=0
bool event_handler(GdkEvent *)
MidiView & _view
Definition: note_base.h:141
void hide_velocity()
static uint32_t base_color(int pitch, int velocity, ARDOUR::ColorMode color_mode, Gtkmm2ext::Color, int channel, bool selected)
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:142
static Gtkmm2ext::Color meter_style_fill_color(uint8_t vel, bool selected)
MidiView & midi_view() const
Definition: note_base.h:115
State _state
Definition: note_base.h:144
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:132
virtual bool big_enough_to_trim() const
virtual double visual_velocity() const =0
float _mouse_y_fraction
Definition: note_base.h:151
virtual ArdourCanvas::Coord x1() const =0
static std::vector< uint32_t > pitch_colors
Definition: note_base.h:133
bool _with_events
Definition: note_base.h:146
static Gtkmm2ext::Color velocity_color_table[128]
Definition: note_base.h:160
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:123
virtual void set_outline_color(uint32_t c)=0
float mouse_x_fraction() const
Definition: note_base.h:111
virtual void set_velocity(double)
Definition: note_base.h:108
@ HideSelection
Definition: note_base.h:64
@ Selected
Definition: note_base.h:63
static Gtkmm2ext::SVAModifier color_modifier
Definition: note_base.h:159
const std::shared_ptr< NoteType > note() const
Definition: note_base.h:114
virtual void hide()=0
static bool _color_init
Definition: note_base.h:161
void validate()
static void set_colors()
void set_selected(bool yn)
ArdourCanvas::Text * _text
Definition: note_base.h:143
Evoral::Note< Temporal::Beats > NoteType
Definition: note_base.h:68
static Gtkmm2ext::Color selected_color()
Definition: note_base.h:120
virtual ArdourCanvas::Coord y1() const =0
ArdourCanvas::Item * item() const
Definition: note_base.h:74
static Gtkmm2ext::Color _selected_col
Definition: note_base.h:158
void show_velocity()
bool selected() const
Definition: note_base.h:83
NoteBase(MidiView &region, bool, const std::shared_ptr< NoteType > note=std::shared_ptr< NoteType >())
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
PBD::PropertyDescriptor< bool > region
Definition: editor.h:85
uint32_t Color
Definition: colors.h:33
DebugBits Beats
link region and track selection