: Diskstream(sess, name, flag)
, _playback_buf(0)
, _capture_buf(0)
- //, _current_playback_buffer(0)
- //, _current_capture_buffer(0)
- //, _playback_wrap_buffer(0)
- //, _capture_wrap_buffer(0)
, _source_port(0)
- , _capture_transition_buf(0)
, _last_flush_frame(0)
, _note_mode(Sustained)
{
: Diskstream(sess, node)
, _playback_buf(0)
, _capture_buf(0)
- //, _current_playback_buffer(0)
- //, _current_capture_buffer(0)
- //, _playback_wrap_buffer(0)
- //, _capture_wrap_buffer(0)
, _source_port(0)
- , _capture_transition_buf(0)
, _last_flush_frame(0)
, _note_mode(Sustained)
{
set_block_size (_session.get_block_size());
allocate_temporary_buffers ();
- _playback_buf = new MidiRingBuffer (_session.diskstream_buffer_size());
- _capture_buf = new MidiRingBuffer (_session.diskstream_buffer_size());
- _capture_transition_buf = new RingBufferNPT<CaptureTransition> (128);
+ _playback_buf = new MidiRingBuffer (_session.midi_diskstream_buffer_size());
+ _capture_buf = new MidiRingBuffer (_session.midi_diskstream_buffer_size());
_n_channels = ChanCount(DataType::MIDI, 1);
Glib::Mutex::Lock lm (state_lock);
}
+
+void
+MidiDiskstream::non_realtime_locate (nframes_t position)
+{
+ assert(_write_source);
+ _write_source->set_timeline_position (position);
+ seek(position, false);
+}
+
+
void
MidiDiskstream::non_realtime_input_change ()
{
_source_port = _io->midi_input(0);
- /* I don't get it....
- const char **connections = _io->input(0)->get_connections ();
-
- if (connections == 0 || connections[0] == 0) {
-
- if (_source_port) {
- // _source_port->disable_metering ();
- }
-
- _source_port = 0;
-
- } else {
- _source_port = dynamic_cast<MidiPort*>(
- _session.engine().get_port_by_name (connections[0]) );
- }
-
- if (connections) {
- free (connections);
- }*/
+ // do... stuff?
}
int
/* if per-track or global rec-enable turned on while the other was already on, we've started recording */
- if ((change & track_rec_enabled) && record_enabled() && (!(change & global_rec_enabled) && can_record) ||
+ if (((change & track_rec_enabled) && record_enabled() && (!(change & global_rec_enabled) && can_record)) ||
((change & global_rec_enabled) && can_record && (!(change & track_rec_enabled) && record_enabled()))) {
/* starting to record: compute first+last frames */
}
- if (_flags & Recordable) {
- RingBufferNPT<CaptureTransition>::rw_vector transvec;
- _capture_transition_buf->get_write_vector(&transvec);
-
- if (transvec.len[0] > 0) {
- transvec.buf[0]->type = CaptureStart;
- transvec.buf[0]->capture_val = capture_start_frame;
- _capture_transition_buf->increment_write_ptr(1);
- } else {
- // bad!
- fatal << X_("programming error: capture_transition_buf is full on rec start! inconceivable!")
- << endmsg;
- }
- }
-
} else if (!record_enabled() || !can_record) {
/* stop recording */
return 0;
}
- /* This lock is held until the end of AudioDiskstream::commit, so these two functions
+ /* This lock is held until the end of ::commit, so these two functions
must always be called as a pair. The only exception is if this function
returns a non-zero value, in which case, ::commit should not be called.
*/
MidiBuffer::iterator port_iter = _source_port->get_midi_buffer().begin();
for (size_t i=0; i < to_write; ++i) {
- const MidiEvent& ev = *port_iter;
- _capture_buf->write(ev.time + transport_frame, ev.size, ev.buffer);
+ const MIDI::Event& ev = *port_iter;
+ assert(ev.buffer());
+ _capture_buf->write(ev.time() + transport_frame, ev.size(), ev.buffer());
++port_iter;
}
adjust_capture_position = 0;
}
+ /* what audio does:
+ * can't do this with midi: write space is in bytes, chunk_frames is in frames
if (_slaved) {
need_butler = _playback_buf->write_space() >= _playback_buf->capacity() / 2;
} else {
need_butler = _playback_buf->write_space() >= disk_io_chunk_frames
|| _capture_buf->read_space() >= disk_io_chunk_frames;
- }
+ }*/
+
+ /* we'll just keep the playback buffer full for now.
+ * this should be decreased to reduce edit latency */
+ need_butler = _playback_buf->write_space() >= _playback_buf->capacity() / 2;
if (commit_should_unlock) {
state_lock.unlock();
/* called from audio thread, so we can use the read ptr and playback sample as we wish */
pending_overwrite = yn;
-
+
overwrite_frame = playback_sample;
- //overwrite_offset = channels.front().playback_buf->get_read_ptr();
}
int
MidiDiskstream::overwrite_existing_buffers ()
{
+ //cerr << "MDS: overwrite_existing_buffers() (does nothing)" << endl;
return 0;
}
{
Glib::Mutex::Lock lm (state_lock);
int ret = -1;
-
+
_playback_buf->reset();
_capture_buf->reset();
int
MidiDiskstream::internal_playback_seek (nframes_t distance)
{
+ cerr << "MDS: internal_playback_seek " << distance << endl;
+
first_recordable_frame += distance;
playback_sample += distance;
int
MidiDiskstream::do_refill ()
{
- int32_t ret = 0;
- size_t write_space = _playback_buf->write_space();
-
- bool reversed = (_visible_speed * _session.transport_speed()) < 0.0f;
+ int ret = 0;
+ size_t write_space = _playback_buf->write_space();
+ bool reversed = (_visible_speed * _session.transport_speed()) < 0.0f;
if (write_space == 0) {
return 0;
}
-
- /* if there are 2+ chunks of disk i/o possible for
- this track, let the caller know so that it can arrange
- for us to be called again, ASAP.
- */
-
- // FIXME: using disk_io_chunk_frames as an event count, not good
- // count vs duration semantic differences are nonexistant for audio,
- // which makes translating for MIDI code confusing...
- if (_playback_buf->write_space() >= (_slaved?3:2) * disk_io_chunk_frames) {
- ret = 1;
- }
-
- /* if we're running close to normal speed and there isn't enough
- space to do disk_io_chunk_frames of I/O, then don't bother.
-
- at higher speeds, just do it because the sync between butler
- and audio thread may not be good enough.
- */
-
- if ((write_space < disk_io_chunk_frames) && fabs (_actual_speed) < 2.0f) {
- cerr << "No refill 1\n";
- return 0;
- }
-
- /* when slaved, don't try to get too close to the read pointer. this
- leaves space for the buffer reversal to have something useful to
- work with.
- */
-
- if (_slaved && write_space < (_playback_buf->capacity() / 2)) {
- cerr << "No refill 2\n";
- return 0;
- }
-
+
if (reversed) {
- cerr << "No refill 3 (reverse)\n";
return 0;
}
+ /* at end: nothing to do */
if (file_frame == max_frames) {
- //cerr << "No refill 4 (EOF)\n";
-
- /* at end: nothing to do */
-
return 0;
}
-#if 0
- // or this
- if (file_frame > max_frames - total_space) {
-
- /* to close to the end: read what we can, and zero fill the rest */
-
- zero_fill = total_space - (max_frames - file_frame);
- total_space = max_frames - file_frame;
-
- } else {
- zero_fill = 0;
- }
-#endif
-
- // At this point we:
+ // At this point we...
assert(_playback_buf->write_space() > 0); // ... have something to write to, and
assert(file_frame <= max_frames); // ... something to write
- // So (read it, then) write it:
-
- nframes_t file_frame_tmp = file_frame;
nframes_t to_read = min(disk_io_chunk_frames, (max_frames - file_frame));
- // FIXME: read count?
- if (read (file_frame_tmp, to_read, reversed)) {
+ if (read (file_frame, to_read, reversed)) {
ret = -1;
- goto out;
}
-
- file_frame = file_frame_tmp;
-
-out:
-
+
return ret;
}
{
uint32_t to_write;
int32_t ret = 0;
- // FIXME: I'd be lying if I said I knew what this thing was
- //RingBufferNPT<CaptureTransition>::rw_vector transvec;
nframes_t total;
_write_data_count = 0;
total = _session.transport_frame() - _last_flush_frame;
- if (total == 0 || _capture_buf->read_space() == 0 && _session.transport_speed() == 0 || (total < disk_io_chunk_frames && !force_flush && was_recording)) {
+ if (total == 0 || (_capture_buf->read_space() == 0 && _session.transport_speed() == 0) || (total < disk_io_chunk_frames && !force_flush && was_recording)) {
goto out;
}
ret = 1;
}
- //to_write = min (disk_io_chunk_frames, (nframes_t) vector.len[0]);
to_write = disk_io_chunk_frames;
assert(!destructive());
if (record_enabled() && _session.transport_frame() - _last_flush_frame > disk_io_chunk_frames) {
- if ((!_write_source) || _write_source->write (*_capture_buf, to_write) != to_write) {
+ if ((!_write_source) || _write_source->midi_write (*_capture_buf, to_write) != to_write) {
error << string_compose(_("MidiDiskstream %1: cannot write to disk"), _id) << endmsg;
return -1;
} else {
}
out:
- //return ret;
- return 0; // FIXME: everything's fine! always! honest!
+ return ret;
}
void
/* figure out the name for this take */
srcs.push_back (_write_source);
- _write_source->update_header (capture_info.front()->start, when, twhen);
+ _write_source->set_timeline_position (capture_info.front()->start);
_write_source->set_captured_for (_name);
string whole_file_region_name;
_source_port->request_monitor_input (!(Config->get_auto_input() && rolling));
}
- _write_source->mark_streaming_midi_write_started (_note_mode);
+ // FIXME: Why is this necessary? Isn't needed for AudioDiskstream...
+ if (!_write_source)
+ use_new_write_source();
+
+ _write_source->mark_streaming_midi_write_started (_note_mode, _session.transport_frame());
RecordEnableChanged (); /* EMIT SIGNAL */
}
snprintf (buf, sizeof(buf), "0x%x", _flags);
node->add_property ("flags", buf);
+ node->add_property("channel-mode", enum_2_string(get_channel_mode()));
+
+ snprintf (buf, sizeof(buf), "0x%x", get_channel_mask());
+ node->add_property("channel-mask", buf);
+
node->add_property ("playlist", _playlist->name());
snprintf (buf, sizeof(buf), "%f", _visible_speed);
_flags = Flag (string_2_enum (prop->value(), _flags));
}
+ ChannelMode channel_mode = AllChannels;
+ if ((prop = node.property ("channel-mode")) != 0) {
+ channel_mode = ChannelMode (string_2_enum(prop->value(), channel_mode));
+ }
+
+ unsigned int channel_mask = 0xFFFF;
+ if ((prop = node.property ("channel-mask")) != 0) {
+ sscanf (prop->value().c_str(), "0x%x", &channel_mask);
+ if (channel_mask & (~0xFFFF)) {
+ warning << _("MidiDiskstream: XML property channel-mask out of range") << endmsg;
+ }
+ }
+
+ set_channel_mode(channel_mode, channel_mask);
+
if ((prop = node.property ("channels")) != 0) {
nchans = atoi (prop->value().c_str());
}
if (_write_source) {
- if (SMFSource::is_empty (_write_source->path())) {
+ if (_write_source->is_empty ()) {
_write_source->mark_for_remove ();
_write_source.reset();
} else {
if (_write_source && mark_write_complete) {
_write_source->mark_streaming_write_completed ();
}
+
use_new_write_source (0);
if (record_enabled()) {