extensive changes to PresentationInfo API
[ardour.git] / libs / ardour / diskstream.cc
index 9f3322dadee4f0120cecfa4030198f57b5a75ce6..3ca463189c4ace26477a47d6ec3efd0ae5e50f4e 100644 (file)
@@ -17,7 +17,6 @@
 
 */
 
-#include <fstream>
 #include <cassert>
 #include <cstdio>
 #include <unistd.h>
@@ -42,6 +41,7 @@
 #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"
@@ -380,11 +380,12 @@ Diskstream::use_playlist (boost::shared_ptr<Playlist> playlist)
                _playlist = playlist;
                _playlist->use();
 
-               if (!in_set_state && recordable()) {
+               if (!in_set_state && destructive() && recordable()) {
                        reset_write_sources (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));
        }
@@ -460,7 +461,7 @@ Diskstream::get_state ()
 {
        XMLNode* node = new XMLNode ("Diskstream");
         char buf[64];
-       LocaleGuard lg (X_("C"));
+       LocaleGuard lg;
 
        node->add_property ("flags", enum_2_string (_flags));
        node->add_property ("playlist", _playlist->name());
@@ -482,7 +483,7 @@ Diskstream::get_state ()
 int
 Diskstream::set_state (const XMLNode& node, int /*version*/)
 {
-       const XMLProperty* prop;
+       XMLProperty const * prop;
 
        if ((prop = node.property ("name")) != 0) {
                _name = prop->value();
@@ -498,6 +499,11 @@ Diskstream::set_state (const XMLNode& node, int /*version*/)
                _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 {
@@ -519,7 +525,7 @@ Diskstream::set_state (const XMLNode& node, int /*version*/)
                        non_realtime_set_speed ();
                }
        }
-       
+
        if ((prop = node.property ("record-safe")) != 0) {
            _record_safe = PBD::string_is_affirmative (prop->value()) ? 1 : 0;
        }
@@ -792,10 +798,69 @@ 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;
+}