#include <fcntl.h>
#include <cstdlib>
#include <ctime>
-#include <strings.h> // for ffs(3)
#include <sys/stat.h>
-#include <sys/mman.h>
#include "pbd/error.h"
+#include "pbd/ffs.h"
#include "pbd/basename.h"
#include <glibmm/threads.h>
#include "pbd/xml++.h"
break;
case ForceChannel:
if (ev.is_channel_event()) {
- ev.set_channel (ffs(mask) - 1);
+ ev.set_channel (PBD::ffs(mask) - 1);
}
_capture_buf->write(transport_frame + loop_offset + ev.time(),
ev.type(), ev.size(), ev.buffer());
break;
}
}
- g_atomic_int_add(const_cast<gint*> (&_frames_pending_write), nframes);
+ g_atomic_int_add(const_cast<gint*>(&_frames_pending_write), nframes);
if (buf.size() != 0) {
Glib::Threads::Mutex::Lock lm (_gui_feed_buffer_mutex, Glib::Threads::TRY_LOCK);
}
/* if there are 2+ chunks of disk i/o possible for
- this track, let the caller know so that it can arrange
+ this track), let the caller know so that it can arrange
for us to be called again, ASAP.
if we are forcing a flush, then if there is* any* extra
try {
_write_source = boost::dynamic_pointer_cast<SMFSource>(
- _session.create_midi_source_for_session (0, name ()));
+ _session.create_midi_source_for_session (name ()));
if (!_write_source) {
throw failed_constructor();
return 0;
}
-
-list<boost::shared_ptr<Source> >
-MidiDiskstream::steal_write_sources()
+/**
+ * We want to use the name of the existing write source (the one that will be
+ * used by the next capture) for another purpose. So change the name of the
+ * current source, and return its current name.
+ *
+ * Return an empty string if the change cannot be accomplished.
+ */
+std::string
+MidiDiskstream::steal_write_source_name ()
{
- list<boost::shared_ptr<Source> > ret;
-
- /* put some data on the disk, even if its just a header for an empty file */
- boost::dynamic_pointer_cast<SMFSource> (_write_source)->ensure_disk_file ();
+ string our_old_name = _write_source->name();
- /* never let it go away */
- _write_source->mark_nonremovable ();
-
- ret.push_back (_write_source);
-
- /* get a new one */
-
- use_new_write_source (0);
+ /* this will bump the name of the current write source to the next one
+ * (e.g. "MIDI 1-1" gets renamed to "MIDI 1-2"), thus leaving the
+ * current write source name (e.g. "MIDI 1-1" available). See the
+ * comments in Session::create_midi_source_by_stealing_name() about why
+ * we do this.
+ */
- return ret;
+ try {
+ string new_name = _session.new_midi_source_name (name());
+
+ if (_write_source->rename (new_name)) {
+ return string();
+ }
+ } catch (...) {
+ return string ();
+ }
+
+ return our_old_name;
}
void