Ardour  9.0-rc2-58-g8c745ff78c
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 Canvas;
41  class Container;
42  class GtkCanvasViewport;
43  class PianoRollHeader;
44  class ScrollGroup;
45  class Widget;
46 }
47 
48 namespace ArdourWidgets {
49  class ArdourButton;
50  class MetaButton;
51 }
52 
53 class PianorollMidiView;
55 
56 struct ControllerControls : public Gtk::HBox {
57  ControllerControls (int num, std::string const & name, Gtk::RadioButtonGroup& group);
59 
63  int number;
64 
65  bool showing() const;
66  bool editing() const;
67 
68  sigc::signal<void> show_clicked;
69  sigc::signal<void> edit_clicked;
70 
71  void set_showing (bool);
72  void set_editing (bool);
73 };
74 
75 class Pianoroll : public CueEditor
76 {
77  public:
78  Pianoroll (std::string const & name, bool with_transport_controls = false);
80 
82 
84 
85  void get_per_region_note_selection (std::list<std::pair<PBD::ID, std::set<std::shared_ptr<Evoral::Note<Temporal::Beats> > > > >&) const {}
86 
89 
97 
98  int32_t get_grid_beat_divisions (Editing::GridType gt) const { return 1; }
99  int32_t get_grid_music_divisions (Editing::GridType gt) const { return 1; }
100 
101  void set_region (std::shared_ptr<ARDOUR::Region>);
102  void set_track (std::shared_ptr<ARDOUR::Track>);
103 
104  double max_extents_scale() const { return 1.2; }
106 
107  void set_mouse_mode (Editing::MouseMode, bool force = false);
108 
109  void midi_action (void (MidiView::*method)());
110 
111  std::list<SelectableOwner*> selectable_owners();
112  void select_all_within (Temporal::timepos_t const &, Temporal::timepos_t const &, double, double, std::list<SelectableOwner*> const &, ARDOUR::SelectionOperation, bool);
113 
116  Gdk::Cursor* which_trim_cursor (bool left_side) const;
118 
119  void set_visible_channel (int chan);
120  int visible_channel () const { return _visible_channel; }
121 
125 
130 
131  void delete_ ();
132  void paste (float times, bool from_context_menu);
133  void keyboard_paste ();
135 
136  PianorollMidiView* midi_view() const { return view; }
138  bool allow_trim_cursors () const;
139 
140  void shift_contents (Temporal::timepos_t const &, bool model);
142 
144 
145  void set_show_source (bool);
147 
148  protected:
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 
170  void escape ();
172 
173  private:
178 
184 #ifdef PIANOROLL_USER_BUTTONS
185  ControllerControls cc_dropdown1;
186  ControllerControls cc_dropdown2;
187  ControllerControls cc_dropdown3;
188 #endif
189  typedef std::map<ControllerControls*,Evoral::Parameter> ParameterButtonMap;
192 
195 
196  void build_canvas ();
200 
202 
204  {
205  public:
206  BBTMetric (Pianoroll& ec) : context (&ec) {}
207 
208  void get_marks (std::vector<ArdourCanvas::Ruler::Mark>& marks, int64_t lower, int64_t upper, int maxchars) const {
209  context->metric_get_bbt (marks, lower, upper, maxchars);
210  }
211 
212  private:
214  };
215 
217 
219  void maybe_update ();
221 
222  void unset_region ();
223  void unset_trigger ();
224 
226 
228 
231 
234 
236 
237  sigc::signal<void> NoteModeChanged;
238 
240 
242 
244  void add_multi_controller_item (Gtk::Menu_Helpers::MenuList& ctl_items, uint16_t channels, int ctl, const std::string& name, ArdourWidgets::MetaButton*);
246 
249 
251 
254 
257 
258  void set_note_selection (uint8_t note);
259  void add_note_selection (uint8_t note);
260  void extend_note_selection (uint8_t note);
261  void toggle_note_selection (uint8_t note);
262 
265 
266  void begin_write ();
267  void end_write ();
268 
270 
271  void show_count_in (std::string const &);
272  void hide_count_in ();
273 
274  void instant_save ();
275  void parameter_changed (std::string param);
277 
280 };
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:34
Pianoroll * context
Definition: pianoroll.h:213
void get_marks(std::vector< ArdourCanvas::Ruler::Mark > &marks, int64_t lower, int64_t upper, int maxchars) const
Definition: pianoroll.h:208
BBTMetric(Pianoroll &ec)
Definition: pianoroll.h:206
void set_from_rsu(RegionUISettings &)
void user_automation_show_button_click(GdkEventButton *ev, ArdourWidgets::MetaButton *metabutton)
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)
void add_multi_controller_item(Gtk::Menu_Helpers::MenuList &ctl_items, uint16_t channels, int ctl, const std::string &name, ArdourWidgets::MetaButton *)
sigc::signal< void > NoteModeChanged
Definition: pianoroll.h:237
PBD::ScopedConnectionList view_connections
Definition: pianoroll.h:218
void add_single_controller_item(Gtk::Menu_Helpers::MenuList &ctl_items, int ctl, const std::string &name, ArdourWidgets::MetaButton *)
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:120
bool button_release_dispatch(GdkEventButton *)
void parameter_changed(std::string param)
void update_rulers()
Definition: pianoroll.h:253
void set_trigger_start(Temporal::timepos_t const &)
void keyboard_paste()
void trigger_prop_change(PBD::PropertyChange const &)
void update_tempo_based_rulers()
void rebuild_parameter_button_map()
void extend_note_selection(uint8_t note)
std::list< SelectableOwner * > selectable_owners()
Gtk::Menu _region_context_menu
Definition: pianoroll.h:255
void canvas_allocate(Gtk::Allocation)
Gtk::Widget & contents()
void delete_()
Gdk::Cursor * which_track_cursor() const
void set_mouse_mode(Editing::MouseMode, bool force=false)
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 *)
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)
Gtk::Menu * get_single_region_context_menu()
void midi_action(void(MidiView::*method)())
void set_track(std::shared_ptr< ARDOUR::Track >)
bool ignore_channel_changes
Definition: pianoroll.h:247
void toggle_note_selection(uint8_t note)
void begin_write()
ControllerControls * velocity_button
Definition: pianoroll.h:179
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)
bool canvas_bg_event(GdkEvent *event, ArdourCanvas::Item *)
void popup_region_context_menu(ArdourCanvas::Item *item, GdkEvent *event)
void shift_contents(Temporal::timepos_t const &, bool model)
Gdk::Cursor * which_mode_cursor() const
void build_canvas()
void pack_inner(Gtk::Box &)
bool canvas_velocity_event(GdkEvent *event, ArdourCanvas::Item *)
int32_t get_grid_music_divisions(Editing::GridType gt) const
Definition: pianoroll.h:99
void build_cc_menu(ArdourWidgets::MetaButton *)
void automation_active_button_click(Evoral::ParameterType type, int id)
PianorollMidiBackground * bg
Definition: pianoroll.h:193
void maybe_update()
ArdourCanvas::Rectangle * meter_bar
Definition: pianoroll.h:176
void note_mode_clicked()
BBTMetric bbt_metric
Definition: pianoroll.h:216
bool canvas_note_event(GdkEvent *event, ArdourCanvas::Item *)
double max_extents_scale() const
Definition: pianoroll.h:104
bool allow_trim_cursors() const
bool canvas_velocity_base_event(GdkEvent *event, ArdourCanvas::Item *)
bool button_press_handler(ArdourCanvas::Item *, GdkEvent *, ItemType)
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:85
Temporal::timepos_t snap_to_grid(Temporal::timepos_t const &start, Temporal::RoundMode direction, ARDOUR::SnapPref gpref) const
ArdourCanvas::PianoRollHeader * prh
Definition: pianoroll.h:177
PianorollMidiView * midi_view() const
Definition: pianoroll.h:136
ControllerControls * bender_button
Definition: pianoroll.h:180
bool motion_handler(ArdourCanvas::Item *, GdkEvent *, bool from_autoscroll=false)
void automation_state_changed()
bool canvas_control_point_event(GdkEvent *event, ArdourCanvas::Item *, ControlPoint *)
bool user_automation_active_button_click(GdkEventButton *ev, ArdourWidgets::MetaButton *mb)
void session_going_away()
void unset_region()
void make_a_region()
int32_t get_grid_beat_divisions(Editing::GridType gt) const
Definition: pianoroll.h:98
void set_samples_per_pixel(samplecnt_t)
void bindings_changed()
void set_visible_channel(int chan)
void unset_trigger()
void end_write()
void set_show_source(bool)
bool idle_data_captured()
void pack_outer(Gtk::Box &)
void instant_save()
ArdourCanvas::Ruler * bbt_ruler
Definition: pianoroll.h:174
ControllerControls * pressure_button
Definition: pianoroll.h:181
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:235
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 visible_channel_changed()
void cut_copy(Editing::CutCopyOp)
samplecnt_t current_page_samples() const
void escape()
ARDOUR::NoteMode note_mode() const
ArdourCanvas::Rectangle * tempo_bar
Definition: pianoroll.h:175
Pianoroll(std::string const &name, bool with_transport_controls=false)
void show_count_in(std::string const &)
ControllerControls * modulation_button
Definition: pianoroll.h:183
MidiViews midiviews_from_region_selection(RegionSelection const &) const
PianorollMidiView * view
Definition: pianoroll.h:194
ParameterButtonMap parameter_button_map
Definition: pianoroll.h:190
void reset_user_cc_choice(std::string, Evoral::Parameter param, ArdourWidgets::MetaButton *)
ControllerControls * expression_button
Definition: pianoroll.h:182
void hide_count_in()
bool key_press_handler(ArdourCanvas::Item *, GdkEvent *, ItemType)
Temporal::timepos_t source_to_timeline(Temporal::timepos_t const &source_pos) const
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)
bool button_press_dispatch(GdkEventButton *)
void add_note_selection(uint8_t note)
std::map< ControllerControls *, Evoral::Parameter > ParameterButtonMap
Definition: pianoroll.h:189
void set_session(ARDOUR::Session *)
ItemType
Definition: editor_items.h:24
GtkImageIconNameData name
Definition: gtkimage.h:6
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:192
@ RoundNearest
Round to nearest.
Gtk::Label name
Definition: pianoroll.h:62
bool showing() const
bool editing() const
sigc::signal< void > show_clicked
Definition: pianoroll.h:68
ArdourWidgets::ArdourButton * edit_button
Definition: pianoroll.h:61
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:69
ArdourWidgets::ArdourButton * show_hide_button
Definition: pianoroll.h:60