Ardour  9.0-pre0-1051-g8dd89616e1
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 <ytkmm/adjustment.h>
24 
25 #include "canvas/ruler.h"
26 
27 #include "cue_editor.h"
28 
29 namespace Gtk {
30  class Widget;
31 }
32 
33 namespace ArdourCanvas {
34  class Box;
35  class Canvas;
36  class Container;
37  class GtkCanvasViewport;
38  class PianoRollHeader;
39  class ScrollGroup;
40  class Widget;
41 }
42 
43 namespace ArdourWidgets {
44  class ArdourButton;
45  class MetaButton;
46 }
47 
48 class PianorollMidiView;
50 
51 class Pianoroll : public CueEditor
52 {
53  public:
54  Pianoroll (std::string const & name, bool with_transport_controls = false);
56 
61 
62  double visible_canvas_width() const { return _visible_canvas_width; }
64 
65  void get_per_region_note_selection (std::list<std::pair<PBD::ID, std::set<std::shared_ptr<Evoral::Note<Temporal::Beats> > > > >&) const {}
66 
69 
77 
78  int32_t get_grid_beat_divisions (Editing::GridType gt) const { return 1; }
79  int32_t get_grid_music_divisions (Editing::GridType gt, uint32_t event_state) const { return 1; }
80 
82  void set_region (std::shared_ptr<ARDOUR::MidiRegion>);
83  void set_track (std::shared_ptr<ARDOUR::MidiTrack>);
84 
87 
88  double max_extents_scale() const { return 1.2; }
90 
91  void set_mouse_mode (Editing::MouseMode, bool force = false);
92  void step_mouse_mode (bool next);
94  bool internal_editing() const;
95 
98 
100  size_t n_timebars;
101 
104 
105  int set_state (const XMLNode&, int version);
106  XMLNode& get_state () const;
107 
108  void maybe_autoscroll (bool, bool, bool);
109  bool autoscroll_active() const;
110 
111  void midi_action (void (MidiView::*method)());
112 
113  std::list<SelectableOwner*> selectable_owners();
114  void select_all_within (Temporal::timepos_t const &, Temporal::timepos_t const &, double, double, std::list<SelectableOwner*> const &, ARDOUR::SelectionOperation, bool);
115 
118  Gdk::Cursor* which_trim_cursor (bool left_side) const;
120 
121  void set_visible_channel (int chan);
122  int visible_channel () const { return _visible_channel; }
123 
127 
132 
135 
136  void delete_ ();
137  void paste (float times, bool from_context_menu);
138  void keyboard_paste ();
140 
141  PianorollMidiView* midi_view() const { return view; }
143  bool allow_trim_cursors () const;
144 
145  protected:
146  void load_bindings ();
148 
150  Temporal::RoundMode direction,
151  ARDOUR::SnapPref gpref) const;
152 
156  bool ensure_snap = false) const;
157 
164  bool motion_handler (ArdourCanvas::Item*, GdkEvent*, bool from_autoscroll = false);
169 
171 
172  void escape ();
174 
175  private:
177  std::shared_ptr<ARDOUR::MidiTrack> _track;
180 
181  /* The group containing all other groups that are scrolled vertically
182  and horizontally.
183  */
185 
186  /* The group containing all other groups that are scrolled horizontally ONLY
187  */
190 
191  /* Scroll group for cursors, scrolled horizontally, above everything else
192  */
194 
202 
204 
207 
217 
218  typedef std::map<ArdourWidgets::ArdourButton*,Evoral::Parameter> ParameterButtonMap;
221 
224 
225  void build_canvas ();
229 
231 
233 
234  void metric_get_bbt (std::vector<ArdourCanvas::Ruler::Mark>&, samplepos_t, samplepos_t, gint);
235 
237  {
238  public:
239  BBTMetric (Pianoroll& ec) : context (&ec) {}
240 
241  void get_marks (std::vector<ArdourCanvas::Ruler::Mark>& marks, int64_t lower, int64_t upper, int maxchars) const {
242  context->metric_get_bbt (marks, lower, upper, maxchars);
243  }
244 
245  private:
247  };
248 
250 
252 
253  /* autoscrolling */
254 
256  void start_canvas_autoscroll (bool allow_horiz, bool allow_vert, const ArdourCanvas::Rect& boundary);
258 
259  sigc::connection _update_connection;
262  void maybe_update ();
264 
265  void unset ();
266 
269 
272  std::atomic<int> idle_update_queued;
275 
281 
283 
285  sigc::signal<void> NoteModeChanged;
286 
288 
290 
291  std::pair<Temporal::timepos_t,Temporal::timepos_t> max_zoom_extent() const;
292 
294 
296 
301 
306 
312 
314 
317  void blink_rec_enable (bool);
318  sigc::connection rec_blink_connection;
319 
321  void add_multi_controller_item (Gtk::Menu_Helpers::MenuList& ctl_items, uint16_t channels, int ctl, const std::string& name, ArdourWidgets::MetaButton*);
323 
326 
330 };
double _visible_canvas_width
Definition: id.h:34
Pianoroll * context
Definition: pianoroll.h:246
void get_marks(std::vector< ArdourCanvas::Ruler::Mark > &marks, int64_t lower, int64_t upper, int maxchars) const
Definition: pianoroll.h:241
BBTMetric(Pianoroll &ec)
Definition: pianoroll.h:239
void build_lower_toolbar()
bool leave_handler(ArdourCanvas::Item *, GdkEvent *, ItemType)
void set_trigger_bounds(Temporal::timepos_t const &, Temporal::timepos_t const &)
ArdourWidgets::ArdourButton solo_button
Definition: pianoroll.h:299
void select_all_within(Temporal::timepos_t const &, Temporal::timepos_t const &, double, double, std::list< SelectableOwner * > const &, ARDOUR::SelectionOperation, bool)
void add_multi_controller_item(Gtk::Menu_Helpers::MenuList &ctl_items, uint16_t channels, int ctl, const std::string &name, ArdourWidgets::MetaButton *)
ArdourWidgets::MetaButton * cc_dropdown1
Definition: pianoroll.h:214
void set_recording_length(Temporal::BBT_Offset bars)
sigc::signal< void > NoteModeChanged
Definition: pianoroll.h:285
PBD::ScopedConnectionList view_connections
Definition: pianoroll.h:261
void build_upper_toolbar()
void visual_changer(const VisualChange &)
void add_single_controller_item(Gtk::Menu_Helpers::MenuList &ctl_items, int ctl, const std::string &name, ArdourWidgets::MetaButton *)
PBD::ScopedConnectionList capture_connections
Definition: pianoroll.h:273
int visible_channel() const
Definition: pianoroll.h:122
bool button_release_dispatch(GdkEventButton *)
void register_actions()
std::atomic< int > idle_update_queued
Definition: pianoroll.h:272
void set_trigger_start(Temporal::timepos_t const &)
ArdourCanvas::GtkCanvasViewport * get_canvas_viewport() const
bool play_button_press(GdkEventButton *)
ArdourCanvas::Container * get_trackview_group() const
Definition: pianoroll.h:57
Gtk::EventBox _contents
Definition: pianoroll.h:205
void keyboard_paste()
void trigger_prop_change(PBD::PropertyChange const &)
void set(ARDOUR::TriggerReference &)
void rebuild_parameter_button_map()
std::list< SelectableOwner * > selectable_owners()
Temporal::BBT_Offset rec_length
Definition: pianoroll.h:308
void step_mouse_mode(bool next)
void zoom_to_show(Temporal::timecnt_t const &)
void stop_canvas_autoscroll()
ArdourCanvas::GtkCanvas * get_canvas() const
void canvas_allocate(Gtk::Allocation)
Gtk::Widget & contents()
ArdourWidgets::ArdourButton rec_enable_button
Definition: pianoroll.h:297
bool rec_button_press(GdkEventButton *)
void trigger_rec_enable_change(ARDOUR::Trigger const &)
bool canvas_pre_event(GdkEvent *)
void delete_()
Gdk::Cursor * which_track_cursor() const
void set_mouse_mode(Editing::MouseMode, bool force=false)
ARDOUR::TriggerReference ref
Definition: pianoroll.h:176
void map_transport_state()
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 *)
Gtk::Label length_label
Definition: pianoroll.h:309
bool user_automation_button_event(GdkEventButton *ev, ArdourWidgets::MetaButton *mb)
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)
double timebar_height
Definition: pianoroll.h:99
void midi_action(void(MidiView::*method)())
void load_bindings()
ArdourCanvas::GtkCanvas * _canvas
Definition: pianoroll.h:179
bool ignore_channel_changes
Definition: pianoroll.h:324
ArdourWidgets::ArdourButton * bender_button
Definition: pianoroll.h:210
void data_captured(samplecnt_t)
void point_selection_changed()
bool button_press_handler_1(ArdourCanvas::Item *, GdkEvent *, ItemType)
void set_trigger_end(Temporal::timepos_t const &)
bool canvas_bg_event(GdkEvent *event, ArdourCanvas::Item *)
double visible_canvas_width() const
Definition: pianoroll.h:62
Gdk::Cursor * which_mode_cursor() const
void build_canvas()
bool canvas_velocity_event(GdkEvent *event, ArdourCanvas::Item *)
void full_zoom_clicked()
PianorollMidiBackground * bg
Definition: pianoroll.h:222
void maybe_update()
ArdourWidgets::ArdourButton * velocity_button
Definition: pianoroll.h:209
ArdourCanvas::Rectangle * meter_bar
Definition: pianoroll.h:200
void note_mode_clicked()
void metric_get_bbt(std::vector< ArdourCanvas::Ruler::Mark > &, samplepos_t, samplepos_t, gint)
std::shared_ptr< ARDOUR::MidiTrack > _track
Definition: pianoroll.h:177
Gtk::HBox play_box
Definition: pianoroll.h:311
bool zoom_in_allocate
Definition: pianoroll.h:295
std::pair< Temporal::timepos_t, Temporal::timepos_t > max_zoom_extent() const
BBTMetric bbt_metric
Definition: pianoroll.h:249
bool canvas_note_event(GdkEvent *event, ArdourCanvas::Item *)
double max_extents_scale() const
Definition: pianoroll.h:88
ArdourCanvas::ScrollGroup * get_cursor_scroll_group() const
Definition: pianoroll.h:86
bool allow_trim_cursors() const
void on_samples_per_pixel_changed()
ArdourCanvas::ScrollGroup * h_scroll_group
Definition: pianoroll.h:188
bool canvas_velocity_base_event(GdkEvent *event, ArdourCanvas::Item *)
PBD::ScopedConnectionList object_connections
Definition: pianoroll.h:260
ArdourCanvas::Rectangle * transport_loop_range_rect
Definition: pianoroll.h:203
bool button_press_handler(ArdourCanvas::Item *, GdkEvent *, ItemType)
bool autoscroll_canvas()
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:65
Temporal::timepos_t snap_to_grid(Temporal::timepos_t const &start, Temporal::RoundMode direction, ARDOUR::SnapPref gpref) const
XMLNode & get_state() const
sigc::connection _update_connection
Definition: pianoroll.h:259
void set_track(std::shared_ptr< ARDOUR::MidiTrack >)
size_t n_timebars
Definition: pianoroll.h:100
ArdourCanvas::PianoRollHeader * prh
Definition: pianoroll.h:201
PianorollMidiView * midi_view() const
Definition: pianoroll.h:141
ArdourWidgets::MetaButton * cc_dropdown2
Definition: pianoroll.h:215
bool internal_editing() const
ArdourCanvas::ScrollGroup * get_hscroll_group() const
Definition: pianoroll.h:85
void box_rec_enable_change(ARDOUR::TriggerBox const &)
void start_canvas_autoscroll(bool allow_horiz, bool allow_vert, const ArdourCanvas::Rect &boundary)
bool with_transport_controls
Definition: pianoroll.h:327
bool motion_handler(ArdourCanvas::Item *, GdkEvent *, bool from_autoscroll=false)
bool bang_button_press(GdkEventButton *)
void automation_state_changed()
bool canvas_control_point_event(GdkEvent *event, ArdourCanvas::Item *, ControlPoint *)
RegionSelection region_selection()
samplecnt_t data_capture_duration
Definition: pianoroll.h:274
ArdourWidgets::ArdourButton loop_button
Definition: pianoroll.h:300
ArdourWidgets::ArdourDropdown length_selector
Definition: pianoroll.h:307
Gtk::Widget & viewport()
int32_t get_grid_beat_divisions(Editing::GridType gt) const
Definition: pianoroll.h:78
void set_samples_per_pixel(samplecnt_t)
void bindings_changed()
void set_visible_channel(int chan)
ArdourCanvas::Container * get_noscroll_group() const
Definition: pianoroll.h:58
ArdourWidgets::ArdourButton * expression_button
Definition: pianoroll.h:212
ArdourCanvas::ScrollGroup * hv_scroll_group
Definition: pianoroll.h:184
void rec_enable_change()
bool idle_data_captured()
ArdourCanvas::Ruler * bbt_ruler
Definition: pianoroll.h:198
ArdourWidgets::MetaButton * cc_dropdown3
Definition: pianoroll.h:216
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:282
Editing::MouseMode current_mouse_mode() const
bool solo_button_press(GdkEventButton *)
ArdourWidgets::ArdourButton * pressure_button
Definition: pianoroll.h:211
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)
ArdourCanvas::GtkCanvasViewport * _canvas_viewport
Definition: pianoroll.h:178
void visible_channel_changed()
void set_note_mode(ARDOUR::NoteMode)
void cut_copy(Editing::CutCopyOp)
int set_state(const XMLNode &, int version)
samplecnt_t current_page_samples() const
void blink_rec_enable(bool)
ArdourCanvas::ScrollGroup * v_scroll_group
Definition: pianoroll.h:189
std::map< ArdourWidgets::ArdourButton *, Evoral::Parameter > ParameterButtonMap
Definition: pianoroll.h:218
void escape()
ARDOUR::NoteMode note_mode() const
Definition: pianoroll.h:125
bool autoscroll_active() const
ArdourCanvas::Rectangle * tempo_bar
Definition: pianoroll.h:199
Pianoroll(std::string const &name, bool with_transport_controls=false)
int32_t get_grid_music_divisions(Editing::GridType gt, uint32_t event_state) const
Definition: pianoroll.h:79
void mouse_mode_toggled(Editing::MouseMode)
ArdourWidgets::ArdourButton play_button
Definition: pianoroll.h:298
void build_zoom_focus_menu()
PianorollMidiView * view
Definition: pianoroll.h:223
Gtk::VBox _toolbox
Definition: pianoroll.h:206
ArdourCanvas::Container * data_group
Definition: pianoroll.h:197
ParameterButtonMap parameter_button_map
Definition: pianoroll.h:219
void reset_user_cc_choice(std::string, Evoral::Parameter param, ArdourWidgets::MetaButton *)
void user_led_click(GdkEventButton *ev, ArdourWidgets::MetaButton *metabutton)
bool key_press_handler(ArdourCanvas::Item *, GdkEvent *, ItemType)
Gtk::HBox button_bar
Definition: pianoroll.h:208
void set_region(std::shared_ptr< ARDOUR::MidiRegion >)
ArdourCanvas::ScrollGroup * cursor_scroll_group
Definition: pianoroll.h:193
ArdourWidgets::ArdourButton * modulation_button
Definition: pianoroll.h:213
bool canvas_cue_end_event(GdkEvent *event, ArdourCanvas::Item *)
void unset()
void maybe_autoscroll(bool, bool, bool)
void set_trigger_length(Temporal::timecnt_t const &)
void paste(float times, bool from_context_menu)
Gtk::HBox rec_box
Definition: pianoroll.h:310
bool loop_button_press(GdkEventButton *)
ArdourCanvas::Container * no_scroll_group
Definition: pianoroll.h:196
void automation_led_click(GdkEventButton *, Evoral::ParameterType type, int id)
bool button_press_dispatch(GdkEventButton *)
ArdourCanvas::Container * global_rect_group
Definition: pianoroll.h:195
void update_solo_display()
bool automation_button_event(GdkEventButton *, Evoral::ParameterType type, int id)
bool automation_button_click(Evoral::ParameterType type, int id, ARDOUR::SelectionOperation)
void set_session(ARDOUR::Session *)
sigc::connection rec_blink_connection
Definition: pianoroll.h:318
ARDOUR::NoteMode _note_mode
Definition: pianoroll.h:284
Definition: xml++.h:114
ItemType
Definition: editor_items.h:24
GtkImageIconNameData name
Definition: gtkimage.h:6
PBD::PropertyDescriptor< timepos_t > start
Temporal::samplecnt_t samplecnt_t
Temporal::samplepos_t samplepos_t
CutCopyOp
Definition: editing.h:228
GridType
Definition: editing.h:52
MouseMode
Definition: editing.h:98
uint32_t ParameterType
Definition: ardour_ui.h:191
@ RoundNearest
Round to nearest.