using namespace ARDOUR;
using namespace PBD;
-nframes_t MidiDiskstream::midi_readahead = 4096;
+framecnt_t MidiDiskstream::midi_readahead = 4096;
MidiDiskstream::MidiDiskstream (Session &sess, const string &name, Diskstream::Flag flag)
: Diskstream(sess, name, flag)
allocate_temporary_buffers ();
const size_t size = _session.butler()->midi_diskstream_buffer_size();
- _playback_buf = new MidiRingBuffer<nframes_t>(size);
- _capture_buf = new MidiRingBuffer<nframes_t>(size);
+ _playback_buf = new MidiRingBuffer<framepos_t>(size);
+ _capture_buf = new MidiRingBuffer<framepos_t>(size);
_n_channels = ChanCount(DataType::MIDI, 1);
void
-MidiDiskstream::non_realtime_locate (nframes_t position)
+MidiDiskstream::non_realtime_locate (framepos_t position)
{
if (_write_source) {
_write_source->set_timeline_position (position);
{
Glib::Mutex::Lock lm (state_lock);
- if (input_change_pending == NoChange) {
+ if (input_change_pending.type == IOChange::NoChange) {
return;
}
- if (input_change_pending & ConfigurationChanged) {
+ if (input_change_pending.type & IOChange::ConfigurationChanged) {
if (_io->n_ports().n_midi() != _n_channels.n_midi()) {
error << "Can not feed IO " << _io->n_ports()
<< " with diskstream " << _n_channels << endl;
set_align_style_from_io ();
}
- input_change_pending = NoChange;
+ input_change_pending.type = IOChange::NoChange;
/* implicit unlock */
}
/* now refill channel buffers */
if (speed() != 1.0f || speed() != -1.0f) {
- seek ((nframes_t) (_session.transport_frame() * (double) speed()));
+ seek ((framepos_t) (_session.transport_frame() * (double) speed()));
}
else {
seek (_session.transport_frame());
#endif
int
-MidiDiskstream::process (nframes_t transport_frame, nframes_t nframes, bool can_record, bool rec_monitors_input, bool& need_butler)
+MidiDiskstream::process (framepos_t transport_frame, pframes_t nframes, bool can_record, bool rec_monitors_input, bool& need_butler)
{
int ret = -1;
- nframes_t rec_offset = 0;
- nframes_t rec_nframes = 0;
+ framecnt_t rec_offset = 0;
+ framecnt_t rec_nframes = 0;
bool nominally_recording;
bool re = record_enabled ();
playback_distance = 0;
- check_record_status (transport_frame, nframes, can_record);
+ check_record_status (transport_frame, can_record);
nominally_recording = (can_record && re);
adjust_capture_position = 0;
- if (nominally_recording || (_session.get_record_enabled() && _session.config.get_punch_in())) {
+ if (nominally_recording || (re && was_recording && _session.get_record_enabled() && _session.config.get_punch_in())) {
OverlapType ot = coverage (first_recordable_frame, last_recordable_frame, transport_frame, transport_frame + nframes);
calculate_record_range(ot, transport_frame, nframes, rec_nframes, rec_offset);
_capture_buf->write(ev.time() + transport_frame, ev.type(), ev.size(), ev.buffer());
}
+ if (buf.size() != 0) {
+ /* Make a copy of this data and emit it for the GUI to see */
+ boost::shared_ptr<MidiBuffer> copy (new MidiBuffer (buf.capacity ()));
+ for (MidiBuffer::iterator i = buf.begin(); i != buf.end(); ++i) {
+ copy->push_back ((*i).time() + transport_frame, (*i).size(), (*i).buffer());
+ }
+
+ DataRecorded (copy, _write_source); /* EMIT SIGNAL */
+ }
+
} else {
if (was_recording) {
}
bool
-MidiDiskstream::commit (nframes_t nframes)
+MidiDiskstream::commit (framecnt_t nframes)
{
bool need_butler = false;
int
MidiDiskstream::overwrite_existing_buffers ()
{
- //read(overwrite_frame, disk_io_chunk_frames, false);
+ /* This is safe as long as the butler thread is suspended, which it should be */
+ _playback_buf->reset ();
+
+ g_atomic_int_set (&_frames_read_from_ringbuffer, 0);
+ g_atomic_int_set (&_frames_written_to_ringbuffer, 0);
+
+ read (overwrite_frame, disk_io_chunk_frames, false);
overwrite_queued = false;
_pending_overwrite = false;
}
int
-MidiDiskstream::seek (nframes_t frame, bool complete_refill)
+MidiDiskstream::seek (framepos_t frame, bool complete_refill)
{
Glib::Mutex::Lock lm (state_lock);
int ret = -1;
}
int
-MidiDiskstream::can_internal_playback_seek (nframes_t distance)
+MidiDiskstream::can_internal_playback_seek (framecnt_t distance)
{
uint32_t frames_read = g_atomic_int_get(&_frames_read_from_ringbuffer);
uint32_t frames_written = g_atomic_int_get(&_frames_written_to_ringbuffer);
}
int
-MidiDiskstream::internal_playback_seek (nframes_t distance)
+MidiDiskstream::internal_playback_seek (framecnt_t distance)
{
first_recordable_frame += distance;
playback_sample += distance;
/** @a start is set to the new frame position (TIME) read up to */
int
-MidiDiskstream::read (nframes_t& start, nframes_t dur, bool reversed)
+MidiDiskstream::read (framepos_t& start, framecnt_t dur, bool reversed)
{
- nframes_t this_read = 0;
+ framecnt_t this_read = 0;
bool reloop = false;
- nframes_t loop_end = 0;
- nframes_t loop_start = 0;
+ framepos_t loop_end = 0;
+ framepos_t loop_start = 0;
Location *loc = 0;
if (!reversed) {
- nframes_t loop_length = 0;
+ framecnt_t loop_length = 0;
/* Make the use of a Location atomic for this read operation.
if (reloop) {
// Synthesize LoopEvent here, because the next events
// written will have non-monotonic timestamps.
- _playback_buf->write(loop_end - 1, LoopEventType, 0, 0);
- cout << "Pushing LoopEvent ts=" << loop_end-1
- << " start+this_read " << start+this_read << endl;
-
+ _playback_buf->write(loop_end - 1, LoopEventType, sizeof (framepos_t), (uint8_t *) &loop_start);
start = loop_start;
} else {
start += this_read;
}
/* at end: nothing to do */
- if (file_frame == max_frames) {
+ if (file_frame == max_framepos) {
return 0;
}
// At this point we...
assert(_playback_buf->write_space() > 0); // ... have something to write to, and
- assert(file_frame <= max_frames); // ... something to write
+ assert(file_frame <= max_framepos); // ... something to write
// now calculate how much time is in the ringbuffer.
// and lets write as much as we need to get this to be midi_readahead;
return 0;
}
- nframes_t to_read = midi_readahead - (frames_written - frames_read);
+ framecnt_t to_read = midi_readahead - (frames_written - frames_read);
//cout << "MDS read for midi_readahead " << to_read << " rb_contains: "
// << frames_written - frames_read << endl;
- to_read = min(to_read, (max_frames - file_frame));
+ to_read = (framecnt_t) min ((framecnt_t) to_read, (framecnt_t) (max_framepos - file_frame));
if (read (file_frame, to_read, reversed)) {
ret = -1;
{
uint32_t to_write;
int32_t ret = 0;
- nframes_t total;
+ framecnt_t total;
_write_data_count = 0;
total = _session.transport_frame() - _last_flush_frame;
- if (_last_flush_frame > _session.transport_frame()
- || _last_flush_frame < capture_start_frame) {
+ if (_last_flush_frame > _session.transport_frame() || _last_flush_frame < capture_start_frame) {
_last_flush_frame = _session.transport_frame();
}
if (record_enabled() &&
((_session.transport_frame() - _last_flush_frame > disk_io_chunk_frames) ||
force_flush)) {
- if ((!_write_source) || _write_source->midi_write (*_capture_buf, capture_start_frame, to_write) != to_write) {
+ if ((!_write_source) || _write_source->midi_write (*_capture_buf, get_capture_start_frame (0), to_write) != to_write) {
error << string_compose(_("MidiDiskstream %1: cannot write to disk"), _id) << endmsg;
return -1;
} else {
assert(_write_source);
- nframes_t total_capture = 0;
+ framecnt_t total_capture = 0;
for (ci = capture_info.begin(); ci != capture_info.end(); ++ci) {
total_capture += (*ci)->frames;
}
_last_capture_sources.insert (_last_capture_sources.end(), srcs.begin(), srcs.end());
- _playlist->clear_history ();
+ _playlist->clear_changes ();
_playlist->freeze ();
- uint32_t buffer_position = 0;
- for (buffer_position = 0, ci = capture_info.begin(); ci != capture_info.end(); ++ci) {
+ /* Session frame time of the initial capture in this pass, which is where the source starts */
+ framepos_t initial_capture = 0;
+ if (!capture_info.empty()) {
+ initial_capture = capture_info.front()->start;
+ }
+
+ for (ci = capture_info.begin(); ci != capture_info.end(); ++ci) {
string region_name;
try {
PropertyList plist;
-
- plist.add (Properties::start, buffer_position);
+
+ /* start of this region is the offset between the start of its capture and the start of the whole pass */
+ plist.add (Properties::start, (*ci)->start - initial_capture);
plist.add (Properties::length, (*ci)->frames);
plist.add (Properties::name, region_name);
i_am_the_modifier++;
_playlist->add_region (region, (*ci)->start);
i_am_the_modifier--;
-
- buffer_position += (*ci)->frames;
}
_playlist->thaw ();
}
void
-MidiDiskstream::transport_looped (nframes_t transport_frame)
+MidiDiskstream::transport_looped (framepos_t transport_frame)
{
if (was_recording) {
// no latency adjustment or capture offset needs to be made, as that already happened the first time
capture_start_frame = transport_frame;
first_recordable_frame = transport_frame; // mild lie
- last_recordable_frame = max_frames;
+ last_recordable_frame = max_framepos;
was_recording = true;
}
}
void
MidiDiskstream::engage_record_enable ()
{
- bool rolling = _session.transport_speed() != 0.0f;
+ bool const rolling = _session.transport_speed() != 0.0f;
g_atomic_int_set (&_record_enabled, 1);
_source_port->request_monitor_input (!(_session.config.get_auto_input() && rolling));
}
- _write_source->mark_streaming_midi_write_started (_note_mode, _session.transport_frame());
-
RecordEnableChanged (); /* EMIT SIGNAL */
}
}
void
-MidiDiskstream::set_block_size (nframes_t /*nframes*/)
+MidiDiskstream::set_block_size (pframes_t /*nframes*/)
{
}
* so that an event at \a start has time = 0
*/
void
-MidiDiskstream::get_playback (MidiBuffer& dst, nframes_t start, nframes_t end)
+MidiDiskstream::get_playback (MidiBuffer& dst, framepos_t start, framepos_t end)
{
dst.clear();
assert(dst.size() == 0);