*/
-#include <fstream>
#include <cassert>
#include <cstdio>
#include <unistd.h>
#include "ardour/diskstream.h"
#include "ardour/io.h"
#include "ardour/pannable.h"
+#include "ardour/profile.h"
#include "ardour/playlist.h"
#include "ardour/session.h"
#include "ardour/track.h"
using namespace ARDOUR;
using namespace PBD;
-/* XXX This goes uninitialized when there is no ~/.config/ardour3 directory.
- * I can't figure out why, so this will do for now (just stole the
- * default from configuration_vars.h). 0 is not a good value for
- * allocating buffer sizes..
- */
-ARDOUR::framecnt_t Diskstream::disk_io_chunk_frames = 1024 * 256 / sizeof (Sample);
+ARDOUR::framecnt_t Diskstream::disk_read_chunk_frames = default_disk_read_chunk_frames ();
+ARDOUR::framecnt_t Diskstream::disk_write_chunk_frames = default_disk_write_chunk_frames ();
PBD::Signal0<void> Diskstream::DiskOverrun;
PBD::Signal0<void> Diskstream::DiskUnderrun;
, i_am_the_modifier (0)
, _track (0)
, _record_enabled (0)
+ , _record_safe (0)
, _visible_speed (1.0f)
, _actual_speed (1.0f)
, _buffer_reallocation_required (false)
, i_am_the_modifier (0)
, _track (0)
, _record_enabled (0)
+ , _record_safe (0)
, _visible_speed (1.0f)
, _actual_speed (1.0f)
, _buffer_reallocation_required (false)
}
_playlist->ContentsChanged.connect_same_thread (playlist_connections, boost::bind (&Diskstream::playlist_modified, this));
+ _playlist->LayeringChanged.connect_same_thread (playlist_connections, boost::bind (&Diskstream::playlist_modified, this));
_playlist->DropReferences.connect_same_thread (playlist_connections, boost::bind (&Diskstream::playlist_deleted, this, boost::weak_ptr<Playlist>(_playlist)));
_playlist->RangesMoved.connect_same_thread (playlist_connections, boost::bind (&Diskstream::playlist_ranges_moved, this, _1, _2));
}
{
XMLNode* node = new XMLNode ("Diskstream");
char buf[64];
- LocaleGuard lg (X_("POSIX"));
+ LocaleGuard lg (X_("C"));
node->add_property ("flags", enum_2_string (_flags));
node->add_property ("playlist", _playlist->name());
snprintf (buf, sizeof(buf), "%f", _visible_speed);
node->add_property ("speed", buf);
node->add_property ("capture-alignment", enum_2_string (_alignment_choice));
+ node->add_property ("record-safe", _record_safe ? "yes" : "no");
if (_extra_xml) {
node->add_child_copy (*_extra_xml);
_flags = Flag (string_2_enum (prop->value(), _flags));
}
+ if (Profile->get_trx() && (_flags & Destructive)) {
+ error << string_compose (_("%1: this session uses destructive tracks, which are not supported"), PROGRAM_NAME) << endmsg;
+ return -1;
+ }
+
if ((prop = node.property (X_("capture-alignment"))) != 0) {
set_align_choice (AlignChoice (string_2_enum (prop->value(), _alignment_choice)), true);
} else {
}
}
- return 0;
+ if ((prop = node.property ("record-safe")) != 0) {
+ _record_safe = PBD::string_is_affirmative (prop->value()) ? 1 : 0;
+ }
+
+ return 0;
}
void
case Evoral::OverlapInternal:
/* ---------- recrange
- |---| transrange
- */
+ * |---| transrange
+ */
rec_nframes = nframes;
rec_offset = 0;
break;
case Evoral::OverlapStart:
/* |--------| recrange
- -----| transrange
- */
+ * -----| transrange
+ */
rec_nframes = transport_frame + nframes - first_recordable_frame;
if (rec_nframes) {
rec_offset = first_recordable_frame - transport_frame;
case Evoral::OverlapEnd:
/* |--------| recrange
- |-------- transrange
- */
+ * |-------- transrange
+ */
rec_nframes = last_recordable_frame - transport_frame;
rec_offset = 0;
break;
case Evoral::OverlapExternal:
/* |--------| recrange
- -------------- transrange
- */
+ * -------------- transrange
+ */
rec_nframes = last_recordable_frame - first_recordable_frame;
rec_offset = first_recordable_frame - transport_frame;
break;
{
g_atomic_int_set (&_record_enabled, 0);
}
+
+void
+Diskstream::engage_record_safe ()
+{
+ g_atomic_int_set (&_record_safe, 1);
+}
+
+void
+Diskstream::disengage_record_safe ()
+{
+ g_atomic_int_set (&_record_safe, 0);
+}
+
+framecnt_t
+Diskstream::default_disk_read_chunk_frames()
+{
+ return 65536;
+}
+
+framecnt_t
+Diskstream::default_disk_write_chunk_frames ()
+{
+ return 65536;
+}
+
+void
+Diskstream::set_buffering_parameters (BufferingPreset bp)
+{
+ framecnt_t read_chunk_size;
+ framecnt_t read_buffer_size;
+ framecnt_t write_chunk_size;
+ framecnt_t write_buffer_size;
+
+ if (!get_buffering_presets (bp, read_chunk_size, read_buffer_size, write_chunk_size, write_buffer_size)) {
+ return;
+ }
+
+ disk_read_chunk_frames = read_chunk_size;
+ disk_write_chunk_frames = write_chunk_size;
+ Config->set_audio_capture_buffer_seconds (write_buffer_size);
+ Config->set_audio_playback_buffer_seconds (read_buffer_size);
+
+ cerr << "Set buffering params to " << disk_read_chunk_frames << '|' << disk_write_chunk_frames << '|'
+ << Config->get_audio_playback_buffer_seconds() << '|'
+ << Config->get_audio_capture_buffer_seconds ()
+ << endl;
+}
+
+bool
+Diskstream::get_buffering_presets (BufferingPreset bp,
+ framecnt_t& read_chunk_size,
+ framecnt_t& read_buffer_size,
+ framecnt_t& write_chunk_size,
+ framecnt_t& write_buffer_size)
+{
+ switch (bp) {
+ case Small:
+ read_chunk_size = 65536; /* samples */
+ write_chunk_size = 65536; /* samples */
+ read_buffer_size = 5; /* seconds */
+ write_buffer_size = 5; /* seconds */
+ break;
+
+ case Medium:
+ read_chunk_size = 262144; /* samples */
+ write_chunk_size = 131072; /* samples */
+ read_buffer_size = 10; /* seconds */
+ write_buffer_size = 10; /* seconds */
+ break;
+
+ case Large:
+ read_chunk_size = 524288; /* samples */
+ write_chunk_size = 131072; /* samples */
+ read_buffer_size = 20; /* seconds */
+ write_buffer_size = 20; /* seconds */
+ break;
+
+ default:
+ return false;
+ }
+
+ return true;
+}