Ardour  9.0-pre0-582-g084a23a80d
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 
25 #include "temporal/beats.h"
26 #include "canvas/types.h"
27 #include "gtkmm2ext/colors.h"
28 
29 #include "ardour/types.h"
30 
31 #include "rgb_macros.h"
32 #include "ui_config.h"
33 
34 class Editor;
35 class MidiView;
36 
37 namespace Evoral {
38  template<typename T> class Note;
39  class Beats;
40 }
41 
42 namespace ArdourCanvas {
43  class Item;
44  class Text;
45 }
46 
58 class NoteBase : public sigc::trackable
59 {
60  private:
61  enum Flags {
62  Selected = 0x1,
64  };
65 
66  public:
68 
69  NoteBase (MidiView& region, bool, const std::shared_ptr<NoteType> note = std::shared_ptr<NoteType>());
70  virtual ~NoteBase ();
71 
73  ArdourCanvas::Item* item() const { return _item; }
74 
75  virtual void show() = 0;
76  virtual void hide() = 0;
77 
78  bool valid() const { return _valid; }
79  void invalidate ();
80  void validate ();
81 
82  bool selected() const { return _flags & Selected; }
83  void set_selected(bool yn);
84  void set_hide_selection (bool yn);
85 
86  virtual void move_event(double dx, double dy) = 0;
87 
88  uint32_t base_color();
89  static uint32_t base_color (int velocity, ARDOUR::ColorMode color_mode, Gtkmm2ext::Color, int channel, bool selected);
90 
91  void show_velocity();
92  void hide_velocity();
93 
95  void on_channel_change(uint8_t channel);
96 
99 
100  virtual void set_outline_color(uint32_t c) = 0;
101  virtual void set_fill_color(uint32_t c) = 0;
102 
103  virtual void set_ignore_events(bool ignore) = 0;
104 
105  virtual ArdourCanvas::Coord x0 () const = 0;
106  virtual ArdourCanvas::Coord y0 () const = 0;
107  virtual ArdourCanvas::Coord x1 () const = 0;
108  virtual ArdourCanvas::Coord y1 () const = 0;
109 
110  virtual void set_velocity (double) {}
111  virtual double visual_velocity() const = 0;
112 
113  float mouse_x_fraction() const { return _mouse_x_fraction; }
114  float mouse_y_fraction() const { return _mouse_y_fraction; }
115 
116  const std::shared_ptr<NoteType> note() const { return _note; }
117  MidiView& region_view() const { return _region; }
118 
119  static void set_colors ();
120 
122 
124  inline static uint32_t calculate_outline(uint32_t color, bool showing_selection = false) {
125  if (showing_selection) {
126  return _selected_col;
127  } else {
128  return UINT_INTERPOLATE(color, 0x000000ff, 0.5);
129  }
130  }
131 
133  static const uint32_t midi_channel_colors[16];
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:158
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:114
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: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 *)
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:142
static Gtkmm2ext::Color meter_style_fill_color(uint8_t vel, bool selected)
State _state
Definition: note_base.h:144
void on_channel_change(uint8_t channel)
bool valid() const
Definition: note_base.h:78
static const uint32_t midi_channel_colors[16]
hue circle divided into 16 equal-looking parts, courtesy Thorsten Wilms
Definition: note_base.h:133
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
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:124
virtual void set_outline_color(uint32_t c)=0
float mouse_x_fraction() const
Definition: note_base.h:113
virtual void set_velocity(double)
Definition: note_base.h:110
MidiView & region_view() const
Definition: note_base.h:117
@ HideSelection
Definition: note_base.h:63
@ Selected
Definition: note_base.h:62
static Gtkmm2ext::SVAModifier color_modifier
Definition: note_base.h:159
const std::shared_ptr< NoteType > note() const
Definition: note_base.h:116
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:67
MidiView & _region
Definition: note_base.h:141
virtual ArdourCanvas::Coord y1() const =0
ArdourCanvas::Item * item() const
Definition: note_base.h:73
static Gtkmm2ext::Color _selected_col
Definition: note_base.h:158
void show_velocity()
bool selected() const
Definition: note_base.h:82
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:86
uint32_t Color
Definition: colors.h:33
DebugBits Beats
link region and track selection