-int
-MidiTimeAxisView::step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, Evoral::MusicalTime beat_duration)
-{
- if (step_edit_region == 0) {
-
- step_edit_region = add_region (step_edit_insert_position);
- RegionView* rv = view()->find_view (step_edit_region);
- step_edit_region_view = dynamic_cast<MidiRegionView*>(rv);
- }
-
- if (step_edit_region && step_edit_region_view) {
- if (step_edit_beat_pos < 0.0) {
- framecnt_t frames_from_start = _editor.get_preferred_edit_position() - step_edit_region->position();
- if (frames_from_start < 0) {
- return 1;
- }
- step_edit_beat_pos = step_edit_region_view->frames_to_beats (frames_from_start);
- }
-
- if (beat_duration == 0.0) {
- bool success;
- beat_duration = _editor.get_grid_type_as_beats (success, step_edit_insert_position);
-
- if (!success) {
- return -1;
- }
- }
-
- step_edit_region_view->step_add_note (channel, pitch, velocity, step_edit_beat_pos, beat_duration);
-
- if (_step_edit_triplet_countdown > 0) {
- _step_edit_triplet_countdown--;
-
- if (_step_edit_triplet_countdown == 0) {
- _step_edit_triplet_countdown = 3;
- }
- }
-
- if (!_step_edit_within_chord) {
- step_edit_beat_pos += beat_duration;
- } else {
- step_edit_beat_pos += 1.0/Meter::ticks_per_beat; // tiny, but no longer overlapping
- _step_edit_chord_duration = beat_duration;
- }
- }
-
- return 0;
-}
-
-bool
-MidiTimeAxisView::step_edit_within_triplet() const
-{
- return _step_edit_triplet_countdown > 0;
-}
-
-bool
-MidiTimeAxisView::step_edit_within_chord() const
-{
- return _step_edit_within_chord;
-}
-
-void
-MidiTimeAxisView::step_edit_toggle_triplet ()
-{
- if (_step_edit_triplet_countdown == 0) {
- _step_edit_within_chord = false;
- _step_edit_triplet_countdown = 3;
- } else {
- _step_edit_triplet_countdown = 0;
- }
-}
-
-void
-MidiTimeAxisView::step_edit_toggle_chord ()
-{
- if (_step_edit_within_chord) {
- _step_edit_within_chord = false;
- step_edit_beat_pos += _step_edit_chord_duration;
- } else {
- _step_edit_triplet_countdown = 0;
- _step_edit_within_chord = true;
- }
-}
-
-void
-MidiTimeAxisView::step_edit_rest ()
-{
- bool success;
- Evoral::MusicalTime beats = _editor.get_grid_type_as_beats (success, step_edit_insert_position);
- step_edit_beat_pos += beats;
-}
-
-boost::shared_ptr<Region>
-MidiTimeAxisView::add_region (framepos_t pos)
-{
- Editor* real_editor = dynamic_cast<Editor*> (&_editor);
-
- real_editor->begin_reversible_command (_("create region"));
- playlist()->clear_history ();
-
- framepos_t start = pos;
- real_editor->snap_to (start, -1);
- const Meter& m = _session->tempo_map().meter_at(start);
- const Tempo& t = _session->tempo_map().tempo_at(start);
- double length = floor (m.frames_per_bar(t, _session->frame_rate()));
-
- boost::shared_ptr<Source> src = _session->create_midi_source_for_session (view()->trackview().track().get(),
- view()->trackview().track()->name());
- PropertyList plist;
-
- plist.add (ARDOUR::Properties::start, 0);
- plist.add (ARDOUR::Properties::length, length);
- plist.add (ARDOUR::Properties::name, PBD::basename_nosuffix(src->name()));
-
- boost::shared_ptr<Region> region = (RegionFactory::create (src, plist));
-
- playlist()->add_region (region, start);
- _session->add_command (new StatefulDiffCommand (playlist()));
-
- real_editor->commit_reversible_command();
-
- return region;
-}
-