MidiTrack::MidiTrack (Session& sess, string name, TrackMode mode)
: Track (sess, name, PresentationInfo::MidiTrack, mode, DataType::MIDI)
, _immediate_events(6096) // FIXME: size?
+ , _immediate_event_buffer(6096)
, _step_edit_ring_buffer(64) // FIXME: size?
, _note_mode (Sustained)
, _step_editing (false)
_disk_writer->set_note_mode (_note_mode);
_disk_reader->reset_tracker ();
+ _disk_writer->DataRecorded.connect_same_thread (*this, boost::bind (&MidiTrack::data_recorded, this, _1));
+
return 0;
}
+void
+MidiTrack::data_recorded (boost::weak_ptr<MidiSource> src)
+{
+ DataRecorded (src); /* EMIT SIGNAL */
+}
+
bool
MidiTrack::can_be_record_safe ()
{
}
XMLNode&
-MidiTrack::state(bool full_state)
+MidiTrack::state(bool save_template)
{
- XMLNode& root (Track::state(full_state));
+ XMLNode& root (Track::state (save_template));
XMLNode* freeze_node;
char buf[64];
}
void
-MidiTrack::update_controls(const BufferSet& bufs)
+MidiTrack::update_controls (BufferSet const& bufs)
{
const MidiBuffer& buf = bufs.get_midi(0);
for (MidiBuffer::const_iterator e = buf.begin(); e != buf.end(); ++e) {
- const Evoral::Event<samplepos_t>& ev = *e;
+ const Evoral::Event<samplepos_t>& ev = *e;
const Evoral::Parameter param = midi_parameter(ev.buffer(), ev.size());
const boost::shared_ptr<AutomationControl> control = automation_control (param);
if (control) {
- control->set_double(ev.value(), _session.transport_sample(), false);
- control->Changed (false, Controllable::NoGroup);
+ double old = control->get_double (false, 0);
+ control->set_double (ev.value(), 0, false);
+ if (old != ev.value()) {
+ control->Changed (false, Controllable::NoGroup);
+ }
}
}
}
}
void
-MidiTrack::write_out_of_band_data (BufferSet& bufs, samplepos_t /*start*/, samplepos_t /*end*/, samplecnt_t nframes)
+MidiTrack::snapshot_out_of_band_data (samplecnt_t nframes)
{
- MidiBuffer& buf (bufs.get_midi (0));
-
- update_controls (bufs);
+ _immediate_event_buffer.clear ();
+ if (0 == _immediate_events.read_space()) {
+ return;
+ }
- // Append immediate events
+ assert (nframes > 0);
- if (_immediate_events.read_space()) {
+ DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 has %2 of immediate events to deliver\n",
+ name(), _immediate_events.read_space()));
- DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 has %2 of immediate events to deliver\n",
- name(), _immediate_events.read_space()));
+ /* write as many of the immediate events as we can, but give "true" as
+ * the last argument ("stop on overflow in destination") so that we'll
+ * ship the rest out next time.
+ *
+ * the Port::port_offset() + (nframes-1) argument puts all these events at the last
+ * possible position of the output buffer, so that we do not
+ * violate monotonicity when writing. Port::port_offset() will
+ * be non-zero if we're in a split process cycle.
+ */
+ _immediate_events.read (_immediate_event_buffer, 0, 1, Port::port_offset() + nframes - 1, true);
+}
- /* write as many of the immediate events as we can, but give "true" as
- * the last argument ("stop on overflow in destination") so that we'll
- * ship the rest out next time.
- *
- * the Port::port_offset() + (nframes-1) argument puts all these events at the last
- * possible position of the output buffer, so that we do not
- * violate monotonicity when writing. Port::port_offset() will
- * be non-zero if we're in a split process cycle.
- */
- _immediate_events.read (buf, 0, 1, Port::port_offset() + nframes - 1, true);
- }
+void
+MidiTrack::write_out_of_band_data (BufferSet& bufs, samplecnt_t nframes) const
+{
+ MidiBuffer& buf (bufs.get_midi (0));
+ buf.merge_from (_immediate_event_buffer, nframes);
}
int
uint8_t ev[3] = { parameter.channel(), uint8_t (val), 0 };
switch(parameter.type()) {
case MidiCCAutomation:
- ev[0] += MIDI_CMD_CONTROL;
+ ev[0] |= MIDI_CMD_CONTROL;
ev[1] = parameter.id();
ev[2] = int(val);
break;
case MidiPgmChangeAutomation:
size = 2;
- ev[0] += MIDI_CMD_PGM_CHANGE;
+ ev[0] |= MIDI_CMD_PGM_CHANGE;
ev[1] = int(val);
break;
case MidiChannelPressureAutomation:
size = 2;
- ev[0] += MIDI_CMD_CHANNEL_PRESSURE;
+ ev[0] |= MIDI_CMD_CHANNEL_PRESSURE;
ev[1] = int(val);
break;
case MidiNotePressureAutomation:
- ev[0] += MIDI_CMD_NOTE_PRESSURE;
+ ev[0] |= MIDI_CMD_NOTE_PRESSURE;
ev[1] = parameter.id();
ev[2] = int(val);
break;
case MidiPitchBenderAutomation:
- ev[0] += MIDI_CMD_BENDER;
+ ev[0] |= MIDI_CMD_BENDER;
ev[1] = 0x7F & int(val);
ev[2] = 0x7F & (int(val) >> 7);
break;
default:
+ size = 0;
assert(false);
}
_route->write_immediate_event(size, ev);
boost::shared_ptr<MidiBuffer>
MidiTrack::get_gui_feed_buffer () const
{
- return _disk_reader->get_gui_feed_buffer ();
+ return _disk_writer->get_gui_feed_buffer ();
}
void
return ms;
}
+MonitorState
+MidiTrack::get_auto_monitoring_state () const
+{
+ //if we are a midi track, we ignore auto_input, tape_mode, etc etc. "Auto" will monitor Disk+In
+ return MonitoringCue;
+}
+
void
MidiTrack::filter_input (BufferSet& bufs)
{