Ardour  9.2-593-gb74daf4ce6
pianoroll.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Paul Davis <paul@linuxaudiosystems.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #pragma once
20 
21 #include <map>
22 
23 #include "pbd/timer.h"
24 
25 #include <ytkmm/adjustment.h>
26 #include <ytkmm/radiotoolbutton.h>
27 
28 #include "canvas/ruler.h"
29 #include "widgets/eventboxext.h"
30 
31 #include "cue_editor.h"
32 
33 namespace Gtk {
34  class Widget;
35  class HScrollbar;
36 }
37 
38 namespace ArdourCanvas {
39  class Box;
40  class Button;
41  class Canvas;
42  class Container;
43  class GtkCanvasViewport;
44  class Icon;
45  class PianoRollHeader;
46  class ScrollGroup;
47  class Widget;
48 }
49 
50 namespace ArdourWidgets {
51  class ArdourButton;
52  class MetaButton;
53 }
54 
55 class CrossCursor;
56 class PianorollMidiView;
58 class MidiInspector;
59 
60 struct ControllerControls : public Gtk::HBox {
61  ControllerControls (int num, std::string const & name, Gtk::RadioButtonGroup& group);
63 
67  int number;
68 
69  bool showing() const;
70  bool editing() const;
71 
72  sigc::signal<void> show_clicked;
73  sigc::signal<void> edit_clicked;
74 
75  void set_showing (bool);
76  void set_editing (bool);
77 };
78 
79 class Pianoroll : public CueEditor
80 {
81  public:
85  };
86 
87 
88  Pianoroll (std::string const & name, bool with_transport_controls = false, bool expandable = false);
90 
92 
94 
97 
98  void get_per_region_note_selection (std::list<std::pair<PBD::ID, std::set<std::shared_ptr<Evoral::Note<Temporal::Beats> > > > >&) const {}
99 
102 
113 
114  int32_t get_grid_beat_divisions (Editing::GridType gt) const { return 1; }
115  int32_t get_grid_music_divisions (Editing::GridType gt) const { return 1; }
116 
117  std::shared_ptr<ARDOUR::MidiTrack> midi_track() const;
118 
119  void add_region (std::shared_ptr<ARDOUR::Region>, std::shared_ptr<ARDOUR::MidiTrack>);
120  void remove_region (std::shared_ptr<ARDOUR::Region>);
121  void set_region (std::shared_ptr<ARDOUR::Region>);
122 
123  double max_extents_scale() const { return 1.2; }
125 
126  void set_mouse_mode (Editing::MouseMode, bool force = false);
127 
128  void midi_action (void (MidiView::*method)());
129 
130  std::list<SelectableOwner*> selectable_owners();
131  void select_all_within (Temporal::timepos_t const &, Temporal::timepos_t const &, double, double, std::list<SelectableOwner*> const &, ARDOUR::SelectionOperation, bool);
132 
135  Gdk::Cursor* which_trim_cursor (bool left_side) const;
137 
138  void set_visible_channel (int chan);
139  int visible_channel () const { return _visible_channel; }
140 
144 
149 
150  void delete_ ();
151  void paste (float times, bool from_context_menu);
152  void keyboard_paste ();
154 
157  bool allow_trim_cursors () const;
158 
159  void shift_contents (Temporal::timepos_t const &, bool model);
161 
163 
164  void set_show_source (bool);
166 
168  void set_note_highlight (uint8_t note);
169 
170  void apply_note_range (uint8_t lowest, uint8_t highest);
171 
172  void note_entered ();
173  void note_left ();
174 
175  struct AutomationLane {
176  AutomationLane (Evoral::Parameter const &, Pianoroll const &, ArdourCanvas::Item*, uint32_t nth);
178 
179  double height() const { return group->height(); }
180  void deduce_color (uint32_t nth);
181 
186  };
187 
191 
192  bool get_midi_chord (int root_pitch, std::vector<int>& pitches) const;
193 
195 
196  protected:
198  Temporal::RoundMode direction,
199  ARDOUR::SnapPref gpref) const;
200 
204  bool ensure_snap = false) const;
205 
212  bool motion_handler (ArdourCanvas::Item*, GdkEvent*, bool from_autoscroll = false);
217 
218  void escape ();
220 
223 
225  std::string parameter_name (Evoral::Parameter const &) const;
226 
227  private:
234 
238  void toggle_size();
239 
242 
245 
246  bool no_toggle;
248  void add_single_controller_item (Gtk::Menu_Helpers::MenuList&, int, const std::string&);
249  void add_multi_controller_item (Gtk::Menu_Helpers::MenuList&, uint16_t, int, const std::string&);
250 
251  typedef std::map<Evoral::Parameter, AutomationLane*> AutomationLanes;
253 
255 
256  typedef std::map<std::shared_ptr<ARDOUR::Region>, PianorollMidiView*> RegionMidiViewMap;
258  void region_going_away (std::weak_ptr<ARDOUR::Region> region);
259 
261 
262  void build_canvas ();
266 
268 
270  {
271  public:
272  BBTMetric (Pianoroll& ec) : context (&ec) {}
273 
274  void get_marks (std::vector<ArdourCanvas::Ruler::Mark>& marks, int64_t lower, int64_t upper, int maxchars) const {
275  context->metric_get_bbt (marks, lower, upper, maxchars);
276  }
277 
278  private:
280  };
281 
283 
285  void maybe_update ();
287 
288  void unset_region ();
289  void unset_trigger ();
290 
292 
294 
297 
300 
302 
303  sigc::signal<void> NoteModeChanged;
304 
306 
309 
311 
314 
317 
318  void set_note_selection (uint8_t note);
319  void add_note_selection (uint8_t note);
320  void extend_note_selection (uint8_t note);
321  void toggle_note_selection (uint8_t note);
322 
325 
326  void begin_write ();
327  void end_write ();
328 
330 
331  void show_count_in (std::string const &);
332  void hide_count_in ();
333 
334  void instant_save ();
335  void parameter_changed (std::string param);
337 
340 
341  void setup_colors ();
343 
345 
348 
350  void replace_chord (std::vector<int> intervals);
351  void invert_selected_chord (bool up);
352  void drop_selected_chord (std::vector<int> which_notes);
353 
355  sigc::connection selection_connection;
356 
361  static std::map<std::string,std::string> controller_name_map;
362 };
void metric_get_bbt(std::vector< ArdourCanvas::Ruler::Mark > &, samplepos_t, samplepos_t, gint)
bool with_transport_controls
Definition: cue_editor.h:151
std::vector< MidiView * > MidiViews
Definition: id.h:33
Pianoroll * context
Definition: pianoroll.h:279
void get_marks(std::vector< ArdourCanvas::Ruler::Mark > &marks, int64_t lower, int64_t upper, int maxchars) const
Definition: pianoroll.h:274
BBTMetric(Pianoroll &ec)
Definition: pianoroll.h:272
void set_from_rsu(RegionUISettings &)
void user_automation_show_button_click(GdkEventButton *ev, ArdourWidgets::MetaButton *metabutton)
void partition_height()
void build_lower_toolbar()
bool leave_handler(ArdourCanvas::Item *, GdkEvent *, ItemType)
void set_trigger_bounds(Temporal::timepos_t const &, Temporal::timepos_t const &)
void select_all_within(Temporal::timepos_t const &, Temporal::timepos_t const &, double, double, std::list< SelectableOwner * > const &, ARDOUR::SelectionOperation, bool)
sigc::signal< void > NoteModeChanged
Definition: pianoroll.h:303
PBD::ScopedConnectionList view_connections
Definition: pianoroll.h:284
void note_mode_chosen(ARDOUR::NoteMode)
ARDOUR::InstrumentInfo * instrument_info() const
void set_note_selection(uint8_t note)
int visible_channel() const
Definition: pianoroll.h:139
bool button_release_dispatch(GdkEventButton *)
void parameter_changed(std::string param)
void update_rulers()
Definition: pianoroll.h:313
void set_trigger_start(Temporal::timepos_t const &)
AutomationLanes automation_lanes
Definition: pianoroll.h:252
static void build_midi_controller_name_map()
void keyboard_paste()
void midi_view_selection_changed()
void update_pitch_colors()
ArdourWidgets::ArdourDropdown policy_dropdown
Definition: pianoroll.h:243
void trigger_prop_change(PBD::PropertyChange const &)
void update_tempo_based_rulers()
void extend_note_selection(uint8_t note)
std::list< SelectableOwner * > selectable_owners()
Gtk::Menu _region_context_menu
Definition: pianoroll.h:315
void canvas_allocate(Gtk::Allocation)
Gtk::Widget & contents()
void remove_automation_lane(Evoral::Parameter const &param)
void add_single_controller_item(Gtk::Menu_Helpers::MenuList &, int, const std::string &)
sigc::connection selection_connection
Definition: pianoroll.h:355
void rebuild_region_dropdown()
void delete_()
Gtk::Menu * build_automation_menu()
Gdk::Cursor * which_track_cursor() const
void set_mouse_mode(Editing::MouseMode, bool force=false)
@ ActiveView
Definition: pianoroll.h:84
@ AllViews
Definition: pianoroll.h:83
void map_transport_state()
void invert_selected_chord(bool up)
void snap_to_internal(Temporal::timepos_t &first, Temporal::RoundMode direction=Temporal::RoundNearest, ARDOUR::SnapPref gpref=ARDOUR::SnapToAny_Visual, bool ensure_snap=false) const
bool canvas_cue_start_event(GdkEvent *event, ArdourCanvas::Item *)
bool canvas_enter_leave(GdkEventCrossing *ev)
Gdk::Cursor * which_trim_cursor(bool left_side) const
bool button_press_handler_2(ArdourCanvas::Item *, GdkEvent *, ItemType)
bool button_release_handler(ArdourCanvas::Item *, GdkEvent *, ItemType)
void manage_possible_header(Gtk::Allocation &alloc)
void note_left()
Gtk::Menu * get_single_region_context_menu()
void midi_action(void(MidiView::*method)())
bool automation_clear_event(GdkEvent *event, Evoral::Parameter)
bool ignore_channel_changes
Definition: pianoroll.h:307
MidiInspector * midi_inspector
Definition: pianoroll.h:349
void toggle_note_selection(uint8_t note)
void begin_write()
void point_selection_changed()
void set_region(std::shared_ptr< ARDOUR::Region >)
bool button_press_handler_1(ArdourCanvas::Item *, GdkEvent *, ItemType)
void set_trigger_end(Temporal::timepos_t const &)
void automation_show_button_click(Evoral::ParameterType type, int id)
static std::map< std::string, std::string > controller_name_map
Definition: pianoroll.h:361
bool canvas_bg_event(GdkEvent *event, ArdourCanvas::Item *)
void popup_region_context_menu(ArdourCanvas::Item *item, GdkEvent *event)
void add_multi_controller_item(Gtk::Menu_Helpers::MenuList &, uint16_t, int, const std::string &)
EditingPolicy editing_policy() const
Definition: pianoroll.h:96
void shift_contents(Temporal::timepos_t const &, bool model)
bool get_midi_chord(int root_pitch, std::vector< int > &pitches) const
Gdk::Cursor * which_mode_cursor() const
PianorollMidiView * _active_view
Definition: pianoroll.h:260
void build_canvas()
void pack_inner(Gtk::Box &)
std::string parameter_name(Evoral::Parameter const &) const
bool canvas_velocity_event(GdkEvent *event, ArdourCanvas::Item *)
ArdourWidgets::ArdourButton size_button
Definition: pianoroll.h:235
void set_color_mode(ARDOUR::ColorMode)
int32_t get_grid_music_divisions(Editing::GridType gt) const
Definition: pianoroll.h:115
void build_cc_menu(ArdourWidgets::MetaButton *)
void set_layered_automation(bool)
void automation_active_button_click(Evoral::ParameterType type, int id)
PianorollMidiBackground * bg
Definition: pianoroll.h:254
void maybe_update()
ArdourCanvas::Rectangle * meter_bar
Definition: pianoroll.h:230
void note_mode_clicked()
void apply_note_range(uint8_t lowest, uint8_t highest)
BBTMetric bbt_metric
Definition: pianoroll.h:282
bool canvas_note_event(GdkEvent *event, ArdourCanvas::Item *)
std::shared_ptr< ARDOUR::MidiTrack > midi_track() const
double max_extents_scale() const
Definition: pianoroll.h:123
bool allow_trim_cursors() const
bool canvas_velocity_base_event(GdkEvent *event, ArdourCanvas::Item *)
bool button_press_handler(ArdourCanvas::Item *, GdkEvent *, ItemType)
void add_region(std::shared_ptr< ARDOUR::Region >, std::shared_ptr< ARDOUR::MidiTrack >)
void get_per_region_note_selection(std::list< std::pair< PBD::ID, std::set< std::shared_ptr< Evoral::Note< Temporal::Beats > > > > > &) const
Definition: pianoroll.h:98
Evoral::Parameter automation_by_y(double y)
Temporal::timepos_t snap_to_grid(Temporal::timepos_t const &start, Temporal::RoundMode direction, ARDOUR::SnapPref gpref) const
void drop_selected_chord(std::vector< int > which_notes)
ArdourCanvas::PianoRollHeader * prh
Definition: pianoroll.h:231
PianorollMidiView * midi_view() const
Definition: pianoroll.h:155
ArdourWidgets::ArdourDropdown colors_dropdown
Definition: pianoroll.h:244
bool automation_group_event(GdkEvent *event, Evoral::Parameter)
void toggle_size()
bool motion_handler(ArdourCanvas::Item *, GdkEvent *, bool from_autoscroll=false)
void setup_colors()
RegionMidiViewMap region_view_map
Definition: pianoroll.h:257
bool canvas_control_point_event(GdkEvent *event, ArdourCanvas::Item *, ControlPoint *)
void add_automation_lane(Evoral::Parameter const &param)
bool user_automation_active_button_click(GdkEventButton *ev, ArdourWidgets::MetaButton *mb)
void replace_chord(std::vector< int > intervals)
void set_editing_policy(EditingPolicy)
void session_going_away()
ARDOUR::Quantize * get_quantize_op()
void unset_region()
void make_a_region()
bool expandable
Definition: pianoroll.h:237
bool no_toggle
Definition: pianoroll.h:246
ArdourWidgets::ArdourDropdown region_dropdown
Definition: pianoroll.h:240
Pianoroll(std::string const &name, bool with_transport_controls=false, bool expandable=false)
int32_t get_grid_beat_divisions(Editing::GridType gt) const
Definition: pianoroll.h:114
void set_samples_per_pixel(samplecnt_t)
void bindings_changed()
void set_visible_channel(int chan)
void region_going_away(std::weak_ptr< ARDOUR::Region > region)
void unset_trigger()
void end_write()
void set_show_source(bool)
bool idle_data_captured()
void pack_outer(Gtk::Box &)
void instant_save()
void note_entered()
ArdourCanvas::Ruler * bbt_ruler
Definition: pianoroll.h:228
void set_note_highlight(uint8_t note)
Temporal::Beats get_draw_length_as_beats(bool &success, Temporal::timepos_t const &position) const
bool enter_handler(ArdourCanvas::Item *, GdkEvent *, ItemType)
int _visible_channel
Definition: pianoroll.h:301
ArdourWidgets::ArdourButton automation_button
Definition: pianoroll.h:236
Temporal::Beats get_grid_type_as_beats(bool &success, Temporal::timepos_t const &position) const
Gdk::Cursor * which_canvas_cursor(ItemType type) const
bool key_release_handler(ArdourCanvas::Item *, GdkEvent *, ItemType)
void automation_button_clicked()
void visible_channel_changed()
void cut_copy(Editing::CutCopyOp)
samplecnt_t current_page_samples() const
void clear_automation_lane(Evoral::Parameter const &param)
std::map< Evoral::Parameter, AutomationLane * > AutomationLanes
Definition: pianoroll.h:251
void escape()
ARDOUR::NoteMode note_mode() const
bool automation_close_event(GdkEvent *event, Evoral::Parameter)
std::map< std::shared_ptr< ARDOUR::Region >, PianorollMidiView * > RegionMidiViewMap
Definition: pianoroll.h:256
ArdourCanvas::Rectangle * tempo_bar
Definition: pianoroll.h:229
void show_count_in(std::string const &)
MidiViews midiviews_from_region_selection(RegionSelection const &) const
void toggle_automation(Evoral::Parameter param)
void motion_track(ArdourCanvas::Duple const &)
void show_automation_for_all()
void hide_count_in()
bool key_press_handler(ArdourCanvas::Item *, GdkEvent *, ItemType)
EditingPolicy _editing_policy
Definition: pianoroll.h:232
Temporal::timepos_t source_to_timeline(Temporal::timepos_t const &source_pos) const
ARDOUR::ColorMode _color_mode
Definition: pianoroll.h:233
bool canvas_cue_end_event(GdkEvent *event, ArdourCanvas::Item *)
void set_trigger_length(Temporal::timecnt_t const &)
void paste(float times, bool from_context_menu)
void remove_region(std::shared_ptr< ARDOUR::Region >)
CrossCursor * xcursor
Definition: pianoroll.h:344
bool button_press_dispatch(GdkEventButton *)
void add_note_selection(uint8_t note)
ARDOUR::ColorMode color_mode() const
Definition: pianoroll.h:222
void set_session(ARDOUR::Session *)
ItemType
Definition: editor_items.h:24
GtkImageIconNameData name
Definition: gtkimage.h:6
PBD::PropertyDescriptor< bool > region
PBD::PropertyDescriptor< timepos_t > start
Temporal::samplecnt_t samplecnt_t
CutCopyOp
Definition: editing.h:241
GridType
Definition: editing.h:53
MouseMode
Definition: editing.h:99
uint32_t ParameterType
Definition: ardour_ui.h:182
@ RoundNearest
Round to nearest.
Gtk::Label name
Definition: pianoroll.h:66
bool showing() const
bool editing() const
sigc::signal< void > show_clicked
Definition: pianoroll.h:72
ArdourWidgets::ArdourButton * edit_button
Definition: pianoroll.h:65
void set_editing(bool)
void set_showing(bool)
ControllerControls(int num, std::string const &name, Gtk::RadioButtonGroup &group)
sigc::signal< void > edit_clicked
Definition: pianoroll.h:73
ArdourWidgets::ArdourButton * show_hide_button
Definition: pianoroll.h:64
ArdourCanvas::Text * label
Definition: pianoroll.h:183
AutomationLane(Evoral::Parameter const &, Pianoroll const &, ArdourCanvas::Item *, uint32_t nth)
void deduce_color(uint32_t nth)
ArdourCanvas::Button * clear_button
Definition: pianoroll.h:185
double height() const
Definition: pianoroll.h:179
ArdourCanvas::Icon * close_x
Definition: pianoroll.h:184
ArdourCanvas::Rectangle * group
Definition: pianoroll.h:182