+
+boost::shared_ptr<MidiRegion>
+MidiTimeAxisView::add_region (framepos_t pos, framecnt_t length, bool commit)
+{
+ Editor* real_editor = dynamic_cast<Editor*> (&_editor);
+
+ real_editor->begin_reversible_command (Operations::create_region);
+ playlist()->clear_changes ();
+
+ real_editor->snap_to (pos, 0);
+
+ 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, pos);
+ _session->add_command (new StatefulDiffCommand (playlist()));
+
+ if (commit) {
+ real_editor->commit_reversible_command ();
+ }
+
+ return boost::dynamic_pointer_cast<MidiRegion>(region);
+}
+
+void
+MidiTimeAxisView::ensure_step_editor ()
+{
+ if (!_step_editor) {
+ _step_editor = new StepEditor (_editor, midi_track(), *this);
+ }
+}
+
+void
+MidiTimeAxisView::start_step_editing ()
+{
+ ensure_step_editor ();
+ _step_editor->start_step_editing ();
+
+}
+void
+MidiTimeAxisView::stop_step_editing ()
+{
+ if (_step_editor) {
+ _step_editor->stop_step_editing ();
+ }
+}
+
+
+/** @return channel (counted from 0) to add an event to, based on the current setting
+ * of the channel selector.
+ */
+uint8_t
+MidiTimeAxisView::get_channel_for_add () const
+{
+ uint16_t const chn_mask = _channel_selector.get_selected_channels ();
+ int chn_cnt = 0;
+ uint8_t channel = 0;
+
+ /* pick the highest selected channel, unless all channels are selected,
+ which is interpreted to mean channel 1 (zero)
+ */
+
+ for (uint16_t i = 0; i < 16; ++i) {
+ if (chn_mask & (1<<i)) {
+ channel = i;
+ chn_cnt++;
+ }
+ }
+
+ if (chn_cnt == 16) {
+ channel = 0;
+ }
+
+ return channel;
+}
+
+void
+MidiTimeAxisView::note_range_changed ()
+{
+ set_gui_property ("note-range-min", (int) midi_view()->lowest_note ());
+ set_gui_property ("note-range-max", (int) midi_view()->highest_note ());
+}
+
+void
+MidiTimeAxisView::contents_height_changed ()
+{
+ _range_scroomer->set_size_request (-1, _view->child_height ());
+}