: 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);
void
MidiDiskstream::non_realtime_locate (nframes_t position)
{
- //cerr << "MDS: non_realtime_locate: " << position << endl;
assert(_write_source);
_write_source->set_timeline_position (position);
- seek(position, true); // correct?
+ seek(position, false);
}
void
MidiDiskstream::set_note_mode (NoteMode m)
{
- cout << "MDS: SET NOTE MODE: " << m << endl;
_note_mode = m;
midi_playlist()->set_note_mode(m);
if (_write_source && _write_source->model())
/* 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.
*/
for (size_t i=0; i < to_write; ++i) {
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
Glib::Mutex::Lock lm (state_lock);
int ret = -1;
- //cerr << "MDS: seek: " << frame << endl;
-
_playback_buf->reset();
_capture_buf->reset();
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 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;
}
assert(_playback_buf->write_space() > 0); // ... have something to write to, and
assert(file_frame <= max_frames); // ... something to write
- 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());
}
out:
- //return ret;
- return 0; // FIXME: everything's fine! always! honest!
+ return ret;
}
void
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);
-
- snprintf (buf, sizeof(buf), "%d", get_force_channel());
- node->add_property("force_channel", buf);
+ node->add_property("channel-mask", buf);
node->add_property ("playlist", _playlist->name());
if ((prop = node.property ("flags")) != 0) {
_flags = Flag (string_2_enum (prop->value(), _flags));
}
-
- if ((prop = node.property ("channel_mask")) != 0) {
- unsigned int channel_mask;
- sscanf (prop->value().c_str(), "0x%x", &channel_mask);
- set_channel_mask(channel_mask);
+
+ ChannelMode channel_mode = AllChannels;
+ if ((prop = node.property ("channel-mode")) != 0) {
+ channel_mode = ChannelMode (string_2_enum(prop->value(), channel_mode));
}
- if ((prop = node.property ("force_channel")) != 0) {
- int force_channel;
- sscanf (prop->value().c_str(), "%d", &force_channel);
- set_force_channel(force_channel);
+ 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());
}