Fixes for GCC 4.3.
[ardour.git] / libs / ardour / audio_diskstream.cc
index c4b2c06e159320beca3d58c051c39797913d4c57..59e6007a6dafc138fc06f0037f24a1a7dd5a5642 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <ardour/ardour.h>
 #include <ardour/audioengine.h>
+#include <ardour/analyser.h>
 #include <ardour/audio_diskstream.h>
 #include <ardour/utils.h>
 #include <ardour/configuration.h>
@@ -264,7 +265,7 @@ AudioDiskstream::use_new_playlist ()
 {
        string newname;
        boost::shared_ptr<AudioPlaylist> playlist;
-
+       
        if (!in_set_state && destructive()) {
                return 0;
        }
@@ -397,8 +398,8 @@ AudioDiskstream::check_record_status (nframes_t transport_frame, nframes_t nfram
 
        /* 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) || 
-           ((change & global_rec_enabled) && can_record && (!(change & track_rec_enabled) && record_enabled()))) {
+       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 */
 
@@ -523,6 +524,11 @@ AudioDiskstream::process (nframes_t transport_frame, nframes_t nframes, nframes_
 
        commit_should_unlock = false;
 
+       if (!_io->active()) {
+               _processed = true;
+               return 0;
+       }
+
        check_record_status (transport_frame, nframes, can_record);
 
        nominally_recording = (can_record && re);
@@ -744,6 +750,7 @@ AudioDiskstream::process (nframes_t transport_frame, nframes_t nframes, nframes_
                                nframes_t total = chaninfo->playback_vector.len[0] + chaninfo->playback_vector.len[1];
                                
                                if (necessary_samples > total) {
+                                       cerr << "underrun for " << _name << endl;
                                        DiskUnderrun ();
                                        goto out;
                                        
@@ -828,6 +835,10 @@ AudioDiskstream::commit (nframes_t nframes)
 {
        bool need_butler = false;
 
+       if (!_io->active()) {
+               return false;
+       }
+
        if (_actual_speed < 0.0) {
                playback_sample -= playback_distance;
        } else {
@@ -850,10 +861,18 @@ AudioDiskstream::commit (nframes_t nframes)
        }
        
        if (_slaved) {
-               need_butler = c->front()->playback_buf->write_space() >= c->front()->playback_buf->bufsize() / 2;
+               /*if (_io && _io->active()) {*/
+                       need_butler = c->front()->playback_buf->write_space() >= c->front()->playback_buf->bufsize() / 2;
+               /*} else {
+                       need_butler = false;
+               }*/
        } else {
-               need_butler = c->front()->playback_buf->write_space() >= disk_io_chunk_frames
-                       || c->front()->capture_buf->read_space() >= disk_io_chunk_frames;
+               /*if (_io && _io->active()) {*/
+                       need_butler = c->front()->playback_buf->write_space() >= disk_io_chunk_frames
+                               || c->front()->capture_buf->read_space() >= disk_io_chunk_frames;
+               /*} else {
+                       need_butler = c->front()->capture_buf->read_space() >= disk_io_chunk_frames;
+               }*/
        }
 
        if (commit_should_unlock) {
@@ -1551,6 +1570,9 @@ AudioDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_ca
                        s->update_header (capture_info.front()->start, when, twhen);
                        s->set_captured_for (_name);
                        s->mark_immutable ();
+                       if (Config->get_auto_analyse_audio()) {
+                               Analyser::queue_source_for_analysis (s, true);
+                       }
                }
        }
 
@@ -1745,6 +1767,9 @@ AudioDiskstream::finish_capture (bool rec_monitors_input, boost::shared_ptr<Chan
 
        capture_info.push_back (ci);
        capture_captured = 0;
+
+       /* now we've finished a capture, reset first_recordable_frame for next time */
+       first_recordable_frame = max_frames;
 }
 
 void
@@ -1816,8 +1841,8 @@ AudioDiskstream::disengage_record_enable ()
 {
        g_atomic_int_set (&_record_enabled, 0);
        boost::shared_ptr<ChannelList> c = channels.reader();
-       for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan) {
-               if (Config->get_monitoring_model() == HardwareMonitoring) {
+       if (Config->get_monitoring_model() == HardwareMonitoring) {
+               for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan) {
                        if ((*chan)->source) {
                                (*chan)->source->ensure_monitor_input (false);
                        }
@@ -1937,6 +1962,7 @@ AudioDiskstream::set_state (const XMLNode& node)
        if (nchans > _n_channels.n_audio()) {
 
                add_channel (nchans - _n_channels.n_audio());
+               IO::PortCountChanged(_n_channels);
 
        } else if (nchans < _n_channels.n_audio()) {
 
@@ -1986,8 +2012,6 @@ AudioDiskstream::set_state (const XMLNode& node)
           up of the IO that owns this DS (::non_realtime_input_change())
        */
                
-       in_set_state = false;
-
        return 0;
 }
 
@@ -2198,7 +2222,7 @@ AudioDiskstream::add_channel (uint32_t how_many)
 int
 AudioDiskstream::remove_channel_from (boost::shared_ptr<ChannelList> c, uint32_t how_many)
 {
-       while (--how_many && !c->empty()) {
+       while (how_many-- && !c->empty()) {
                delete c->back();
                c->pop_back();
        }