- if (step_edit_region) {
- RegionView* rv = view()->find_view (step_edit_region);
- step_edit_region_view = dynamic_cast<MidiRegionView*> (rv);
- } else {
- step_edit_region_view = 0;
- }
-
- midi_track()->set_step_editing (true);
-}
-
-void
-MidiTimeAxisView::stop_step_editing ()
-{
- midi_track()->set_step_editing (false);
-}
-
-void
-MidiTimeAxisView::check_step_edit ()
-{
- MidiRingBuffer<nframes_t>& incoming (midi_track()->step_edit_ring_buffer());
- Evoral::Note<Evoral::MusicalTime> note;
- uint8_t* buf;
- uint32_t bufsize = 32;
-
- buf = new uint8_t[bufsize];
-
- while (incoming.read_space()) {
- nframes_t time;
- Evoral::EventType type;
- uint32_t size;
-
- incoming.read_prefix (&time, &type, &size);
-
- if (size > bufsize) {
- delete [] buf;
- bufsize = size;
- buf = new uint8_t[bufsize];
- }
-
- incoming.read_contents (size, buf);
-
- if ((buf[0] & 0xf0) == MIDI_CMD_NOTE_ON) {
-
- if (step_edit_region == 0) {
-
- step_edit_region = add_region (step_edit_insert_position);
- RegionView* rv = view()->find_view (step_edit_region);
-
- if (rv) {
- step_edit_region_view = dynamic_cast<MidiRegionView*>(rv);
- } else {
- fatal << X_("programming error: no view found for new MIDI region") << endmsg;
- /*NOTREACHED*/
- }
- }
-
- if (step_edit_region_view) {
-
- bool success;
- Evoral::MusicalTime beats = _editor.get_grid_type_as_beats (success, step_edit_insert_position);
-
- if (!success) {
- continue;
- }
-
- step_edit_region_view->add_note (buf[0] & 0xf, buf[1], buf[2], step_edit_beat_pos, beats);
- step_edit_beat_pos += beats;
- }
- }
-
- }
-}
-
-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 (nframes64_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()->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;
-}