- /* do these things in case undo removed the step edit region
- */
- if (!step_edit_region) {
- resync_step_edit_position ();
- prepare_step_edit_region ();
- reset_step_edit_beat_pos ();
- step_edit_region_view->show_step_edit_cursor (step_edit_beat_pos);
- step_edit_region_view->set_step_edit_cursor_width (step_editor->note_length());
- }
-
- assert (step_edit_region);
- assert (step_edit_region_view);
-
- if (beat_duration == 0.0) {
- bool success;
- beat_duration = _editor.get_grid_type_as_beats (success, step_edit_insert_position);
-
- if (!success) {
- return -1;
- }
- }
-
- MidiStreamView* msv = _mtv.midi_view();
-
- /* make sure its visible on the vertical axis */
-
- if (pitch < msv->lowest_note() || pitch > msv->highest_note()) {
- msv->update_note_range (pitch);
- msv->set_note_range (MidiStreamView::ContentsRange);
- }
-
- /* make sure its visible on the horizontal axis */
-
- framepos_t fpos = step_edit_region->position() +
- step_edit_region_view->beats_to_frames (step_edit_beat_pos + beat_duration);
-
- if (fpos >= (_editor.leftmost_position() + _editor.current_page_frames())) {
- _editor.reset_x_origin (fpos - (_editor.current_page_frames()/4));
- }
-
- Evoral::MusicalTime at = step_edit_beat_pos;
- Evoral::MusicalTime len = beat_duration;
-
- if ((last_added_pitch >= 0) && (pitch == last_added_pitch) && (last_added_end == step_edit_beat_pos)) {
-
- /* avoid any apparent note overlap - move the start of this note
- up by 1 tick from where the last note ended
- */
-
- at += 1.0/Meter::ticks_per_beat;
- len -= 1.0/Meter::ticks_per_beat;
- }
-
- step_edit_region_view->step_add_note (channel, pitch, velocity, at, len);
-
- last_added_pitch = pitch;
- last_added_end = at+len;
-
- 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;
- step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos);
- } else {
- step_edit_beat_pos += 1.0/Meter::ticks_per_beat; // tiny, but no longer overlapping
- _step_edit_chord_duration = max (_step_edit_chord_duration, beat_duration);
- }
-
- return 0;
+ /* do these things in case undo removed the step edit region
+ */
+ if (!step_edit_region) {
+ resync_step_edit_position ();
+ prepare_step_edit_region ();
+ reset_step_edit_beat_pos ();
+ step_edit_region_view->show_step_edit_cursor (step_edit_beat_pos);
+ step_edit_region_view->set_step_edit_cursor_width (step_editor->note_length());
+ }
+
+ assert (step_edit_region);
+ assert (step_edit_region_view);
+
+ if (beat_duration == 0.0 && step_editor) {
+ beat_duration = step_editor->note_length();
+ } else if (beat_duration == 0.0) {
+ bool success;
+ beat_duration = _editor.get_grid_type_as_beats (success, step_edit_insert_position);
+
+ if (!success) {
+ return -1;
+ }
+ }
+
+ MidiStreamView* msv = _mtv.midi_view();
+
+ /* make sure its visible on the vertical axis */
+
+ if (pitch < msv->lowest_note() || pitch > msv->highest_note()) {
+ msv->update_note_range (pitch);
+ msv->set_note_range (MidiStreamView::ContentsRange);
+ }
+
+ /* make sure its visible on the horizontal axis */
+
+ framepos_t fpos = step_edit_region_view->region_beats_to_absolute_frames (step_edit_beat_pos + beat_duration);
+
+ if (fpos >= (_editor.leftmost_sample() + _editor.current_page_samples())) {
+ _editor.reset_x_origin (fpos - (_editor.current_page_samples()/4));
+ }
+
+ Evoral::Beats at = step_edit_beat_pos;
+ Evoral::Beats len = beat_duration;
+
+ if ((last_added_pitch >= 0) && (pitch == last_added_pitch) && (last_added_end == step_edit_beat_pos)) {
+
+ /* avoid any apparent note overlap - move the start of this note
+ up by 1 tick from where the last note ended
+ */
+
+ at += Evoral::Beats::ticks(1);
+ len -= Evoral::Beats::ticks(1);
+ }
+
+ step_edit_region_view->step_add_note (channel, pitch, velocity, at, len);
+
+ last_added_pitch = pitch;
+ last_added_end = at+len;
+
+ 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;
+ step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos);
+ } else {
+ step_edit_beat_pos += Evoral::Beats::ticks(1); // tiny, but no longer overlapping
+ _step_edit_chord_duration = max (_step_edit_chord_duration, beat_duration);
+ }
+
+ step_edit_region_view->set_step_edit_cursor_width (step_editor->note_length());
+
+ return 0;