display results of a bounce in the region list
[ardour.git] / libs / ardour / audio_track.cc
index 78af23e3df8bf7cdea43b2f2ad91dc5fbe8b02ae..171f2d7c6b39483bb5e6385bd715225d9af86980 100644 (file)
@@ -28,6 +28,7 @@
 #include <ardour/redirect.h>
 #include <ardour/audioregion.h>
 #include <ardour/audiosource.h>
+#include <ardour/region_factory.h>
 #include <ardour/route_group_specialized.h>
 #include <ardour/insert.h>
 #include <ardour/audioplaylist.h>
@@ -55,9 +56,10 @@ AudioTrack::AudioTrack (Session& sess, string name, Route::Flag flag, TrackMode
                dflags = AudioDiskstream::Flag (dflags | AudioDiskstream::Destructive);
        }
 
-       AudioDiskstream* ds = new AudioDiskstream (_session, name, dflags);
-       
-       set_diskstream (*ds, this);
+       boost::shared_ptr<AudioDiskstream> ds (new AudioDiskstream (_session, name, dflags));
+       _session.add_diskstream (ds);
+
+       set_diskstream (boost::dynamic_pointer_cast<AudioDiskstream> (ds), this);
 }
 
 AudioTrack::AudioTrack (Session& sess, const XMLNode& node)
@@ -73,18 +75,18 @@ AudioTrack::~AudioTrack ()
 int
 AudioTrack::deprecated_use_diskstream_connections ()
 {
-       AudioDiskstream& diskstream = audio_diskstream();
+       boost::shared_ptr<AudioDiskstream> diskstream = audio_diskstream();
 
-       if (diskstream.deprecated_io_node == 0) {
+       if (diskstream->deprecated_io_node == 0) {
                return 0;
        }
 
        const XMLProperty* prop;
-       XMLNode& node (*diskstream.deprecated_io_node);
+       XMLNode& node (*diskstream->deprecated_io_node);
 
        /* don't do this more than once. */
 
-       diskstream.deprecated_io_node = 0;
+       diskstream->deprecated_io_node = 0;
 
        set_input_minimum (-1);
        set_input_maximum (-1);
@@ -125,17 +127,13 @@ AudioTrack::deprecated_use_diskstream_connections ()
 }
 
 int
-AudioTrack::set_diskstream (AudioDiskstream& ds, void *src)
+AudioTrack::set_diskstream (boost::shared_ptr<AudioDiskstream> ds, void *src)
 {
-       if (_diskstream) {
-               _diskstream->unref();
-       }
-
-       _diskstream = &ds.ref();
+       _diskstream = ds;
        _diskstream->set_io (*this);
        _diskstream->set_destructive (_mode == Destructive);
 
-       if (audio_diskstream().deprecated_io_node) {
+       if (audio_diskstream()->deprecated_io_node) {
 
                if (!connecting_legal) {
                        ConnectingLegal.connect (mem_fun (*this, &AudioTrack::deprecated_use_diskstream_connections));
@@ -158,33 +156,33 @@ AudioTrack::set_diskstream (AudioDiskstream& ds, void *src)
 int 
 AudioTrack::use_diskstream (string name)
 {
-       AudioDiskstream *dstream;
+       boost::shared_ptr<AudioDiskstream> dstream;
 
-       if ((dstream = dynamic_cast<AudioDiskstream*>(_session.diskstream_by_name (name))) == 0) {
-         error << string_compose(_("AudioTrack: audio diskstream \"%1\" not known by session"), name) << endmsg;
+       if ((dstream = boost::dynamic_pointer_cast<AudioDiskstream>(_session.diskstream_by_name (name))) == 0) {
+               error << string_compose(_("AudioTrack: audio diskstream \"%1\" not known by session"), name) << endmsg;
                return -1;
        }
        
-       return set_diskstream (*dstream, this);
+       return set_diskstream (dstream, this);
 }
 
 int 
 AudioTrack::use_diskstream (const PBD::ID& id)
 {
-       AudioDiskstream *dstream;
+       boost::shared_ptr<AudioDiskstream> dstream;
 
-       if ((dstream = dynamic_cast<AudioDiskstream*>(_session.diskstream_by_id (id))) == 0) {
+       if ((dstream = boost::dynamic_pointer_cast<AudioDiskstream> (_session.diskstream_by_id (id))) == 0) {
                error << string_compose(_("AudioTrack: audio diskstream \"%1\" not known by session"), id) << endmsg;
                return -1;
        }
        
-       return set_diskstream (*dstream, this);
+       return set_diskstream (dstream, this);
 }
 
-AudioDiskstream&
+boost::shared_ptr<AudioDiskstream>
 AudioTrack::audio_diskstream() const
 {
-       return *dynamic_cast<AudioDiskstream*>(_diskstream);
+       return boost::dynamic_pointer_cast<AudioDiskstream>(_diskstream);
 }
 
 int
@@ -248,6 +246,10 @@ AudioTrack::set_state (const XMLNode& node)
                                sscanf (prop->value().c_str(), "%d", &x);
                                set_remote_control_id (x);
                        }
+
+               } else if (child->name() == X_("recenable")) {
+                       _rec_enable_control.set_state (*child);
+                       _session.add_controllable (&_rec_enable_control);
                }
        }
 
@@ -275,7 +277,7 @@ AudioTrack::state(bool full_state)
 
                for (vector<FreezeRecordInsertInfo*>::iterator i = _freeze_record.insert_info.begin(); i != _freeze_record.insert_info.end(); ++i) {
                        inode = new XMLNode (X_("insert"));
-                       (*i)->id.print (buf);
+                       (*i)->id.print (buf, sizeof (buf));
                        inode->add_property (X_("id"), buf);
                        inode->add_child_copy ((*i)->state);
                
@@ -319,9 +321,11 @@ AudioTrack::state(bool full_state)
           diskstream.
        */
 
-       _diskstream->id().print (buf);
+       _diskstream->id().print (buf, sizeof (buf));
        root.add_property ("diskstream-id", buf);
 
+       root.add_child_nocopy (_rec_enable_control.get_state());
+
        return root;
 }
 
@@ -407,14 +411,14 @@ AudioTrack::n_process_buffers ()
 }
 
 void
-AudioTrack::passthru_silence (jack_nframes_t start_frame, jack_nframes_t end_frame, jack_nframes_t nframes, jack_nframes_t offset, int declick, bool meter)
+AudioTrack::passthru_silence (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter)
 {
        uint32_t nbufs = n_process_buffers ();
        process_output_buffers (_session.get_silent_buffers (nbufs), nbufs, start_frame, end_frame, nframes, offset, true, declick, meter);
 }
 
 int 
-AudioTrack::no_roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nframes_t end_frame, jack_nframes_t offset, 
+AudioTrack::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, 
                     bool session_state_changing, bool can_record, bool rec_monitors_input)
 {
        if (n_outputs() == 0) {
@@ -434,7 +438,7 @@ AudioTrack::no_roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nf
                return 0;
        }
 
-       audio_diskstream().check_record_status (start_frame, nframes, can_record);
+       audio_diskstream()->check_record_status (start_frame, nframes, can_record);
 
        bool send_silence;
        
@@ -446,15 +450,15 @@ AudioTrack::no_roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nf
                send_silence = true;
        } else {
 
-               if (_session.get_auto_input()) {
-                       if (Config->get_use_sw_monitoring()) {
+               if (Config->get_auto_input()) {
+                       if (Config->get_monitoring_model() == SoftwareMonitoring) {
                                send_silence = false;
                        } else {
                                send_silence = true;
                        }
                } else {
                        if (_diskstream->record_enabled()) {
-                               if (Config->get_use_sw_monitoring()) {
+                               if (Config->get_monitoring_model() == SoftwareMonitoring) {
                                        send_silence = false;
                                } else {
                                        send_silence = true;
@@ -494,14 +498,14 @@ AudioTrack::no_roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nf
 }
 
 int
-AudioTrack::roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nframes_t end_frame, jack_nframes_t offset, int declick,
+AudioTrack::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
                  bool can_record, bool rec_monitors_input)
 {
        int dret;
        Sample* b;
        Sample* tmpb;
-       jack_nframes_t transport_frame;
-       AudioDiskstream& diskstream = audio_diskstream();
+       nframes_t transport_frame;
+       boost::shared_ptr<AudioDiskstream> diskstream = audio_diskstream();
        
        {
                Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
@@ -528,13 +532,13 @@ AudioTrack::roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nfram
                   playback distance to zero, thus causing diskstream::commit
                   to do nothing.
                */
-               return diskstream.process (transport_frame, 0, 0, can_record, rec_monitors_input);
+               return diskstream->process (transport_frame, 0, 0, can_record, rec_monitors_input);
        } 
 
        _silent = false;
        apply_gain_automation = false;
 
-       if ((dret = diskstream.process (transport_frame, nframes, offset, can_record, rec_monitors_input)) != 0) {
+       if ((dret = diskstream->process (transport_frame, nframes, offset, can_record, rec_monitors_input)) != 0) {
                
                silence (nframes, offset);
 
@@ -547,7 +551,7 @@ AudioTrack::roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nfram
                just_meter_input (start_frame, end_frame, nframes, offset);
        }
 
-       if (diskstream.record_enabled() && !can_record && !_session.get_auto_input()) {
+       if (diskstream->record_enabled() && !can_record && !Config->get_auto_input()) {
 
                /* not actually recording, but we want to hear the input material anyway,
                   at least potentially (depending on monitoring options)
@@ -555,7 +559,7 @@ AudioTrack::roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nfram
 
                passthru (start_frame, end_frame, nframes, offset, 0, true);
 
-       } else if ((b = diskstream.playback_buffer(0)) != 0) {
+       } else if ((b = diskstream->playback_buffer(0)) != 0) {
 
                /*
                  XXX is it true that the earlier test on n_outputs()
@@ -577,8 +581,8 @@ AudioTrack::roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nfram
 
                for (i = 0, n = 1; i < limit; ++i, ++n) {
                        memcpy (bufs[i], b, sizeof (Sample) * nframes); 
-                       if (n < diskstream.n_channels()) {
-                               tmpb = diskstream.playback_buffer(n);
+                       if (n < diskstream->n_channels()) {
+                               tmpb = diskstream->playback_buffer(n);
                                if (tmpb!=0) {
                                        b = tmpb;
                                }
@@ -587,7 +591,7 @@ AudioTrack::roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nfram
 
                /* don't waste time with automation if we're recording or we've just stopped (yes it can happen) */
 
-               if (!diskstream.record_enabled() && _session.transport_rolling()) {
+               if (!diskstream->record_enabled() && _session.transport_rolling()) {
                        Glib::Mutex::Lock am (automation_lock, Glib::TRY_LOCK);
                        
                        if (am.locked() && gain_automation_playback()) {
@@ -595,7 +599,7 @@ AudioTrack::roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nfram
                        }
                }
 
-               process_output_buffers (bufs, limit, start_frame, end_frame, nframes, offset, (!_session.get_record_enabled() || !_session.get_do_not_record_plugins()), declick, (_meter_point != MeterInput));
+               process_output_buffers (bufs, limit, start_frame, end_frame, nframes, offset, (!_session.get_record_enabled() || !Config->get_do_not_record_plugins()), declick, (_meter_point != MeterInput));
                
        } else {
                /* problem with the diskstream; just be quiet for a bit */
@@ -606,7 +610,7 @@ AudioTrack::roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nfram
 }
 
 int
-AudioTrack::silent_roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nframes_t end_frame, jack_nframes_t offset, 
+AudioTrack::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, 
                         bool can_record, bool rec_monitors_input)
 {
        if (n_outputs() == 0 && _redirects.empty()) {
@@ -623,11 +627,11 @@ AudioTrack::silent_roll (jack_nframes_t nframes, jack_nframes_t start_frame, jac
 
        silence (nframes, offset);
 
-       return audio_diskstream().process (_session.transport_frame() + offset, nframes, offset, can_record, rec_monitors_input);
+       return audio_diskstream()->process (_session.transport_frame() + offset, nframes, offset, can_record, rec_monitors_input);
 }
 
 int
-AudioTrack::export_stuff (vector<Sample*>& buffers, char * workbuf, uint32_t nbufs, jack_nframes_t start, jack_nframes_t nframes)
+AudioTrack::export_stuff (vector<Sample*>& buffers, uint32_t nbufs, nframes_t start, nframes_t nframes)
 {
        gain_t  gain_automation[nframes];
        gain_t  gain_buffer[nframes];
@@ -637,15 +641,15 @@ AudioTrack::export_stuff (vector<Sample*>& buffers, char * workbuf, uint32_t nbu
        gain_t this_gain = _gain;
        vector<Sample*>::iterator bi;
        Sample * b;
-       AudioDiskstream& diskstream = audio_diskstream();
+       boost::shared_ptr<AudioDiskstream> diskstream = audio_diskstream();
        
        Glib::RWLock::ReaderLock rlock (redirect_lock);
 
        // FIXME
-       AudioPlaylist* const apl = dynamic_cast<AudioPlaylist*>(diskstream.playlist());
+       AudioPlaylist* const apl = dynamic_cast<AudioPlaylist*>(diskstream->playlist());
        assert(apl);
 
-       if (apl->read (buffers[0], mix_buffer, gain_buffer, workbuf, start, nframes) != nframes) {
+       if (apl->read (buffers[0], mix_buffer, gain_buffer, start, nframes) != nframes) {
                return -1;
        }
 
@@ -654,8 +658,8 @@ AudioTrack::export_stuff (vector<Sample*>& buffers, char * workbuf, uint32_t nbu
        b = buffers[0];
        ++bi;
        for (; bi != buffers.end(); ++bi, ++n) {
-               if (n < diskstream.n_channels()) {
-                       if (apl->read ((*bi), mix_buffer, gain_buffer, workbuf, start, nframes, n) != nframes) {
+               if (n < diskstream->n_channels()) {
+                       if (apl->read ((*bi), mix_buffer, gain_buffer, start, nframes, n) != nframes) {
                                return -1;
                        }
                        b = (*bi);
@@ -692,7 +696,7 @@ AudioTrack::export_stuff (vector<Sample*>& buffers, char * workbuf, uint32_t nbu
 
                for (bi = buffers.begin(); bi != buffers.end(); ++bi) {
                        Sample *b = *bi;
-                       for (jack_nframes_t n = 0; n < nframes; ++n) {
+                       for (nframes_t n = 0; n < nframes; ++n) {
                                b[n] *= gain_automation[n];
                        }
                }
@@ -701,7 +705,7 @@ AudioTrack::export_stuff (vector<Sample*>& buffers, char * workbuf, uint32_t nbu
 
                for (bi = buffers.begin(); bi != buffers.end(); ++bi) {
                        Sample *b = *bi;
-                       for (jack_nframes_t n = 0; n < nframes; ++n) {
+                       for (nframes_t n = 0; n < nframes; ++n) {
                                b[n] *= this_gain;
                        }
                }
@@ -730,30 +734,29 @@ AudioTrack::export_stuff (vector<Sample*>& buffers, char * workbuf, uint32_t nbu
 void
 AudioTrack::bounce (InterThreadInfo& itt)
 {
-       vector<AudioSource*> srcs;
+       vector<boost::shared_ptr<AudioSource> > srcs;
        _session.write_one_audio_track (*this, 0, _session.current_end_frame(), false, srcs, itt);
 }
 
 
 void
-AudioTrack::bounce_range (jack_nframes_t start, jack_nframes_t end, InterThreadInfo& itt)
+AudioTrack::bounce_range (nframes_t start, nframes_t end, InterThreadInfo& itt)
 {
-       vector<AudioSource*> srcs;
+       vector<boost::shared_ptr<AudioSource> > srcs;
        _session.write_one_audio_track (*this, start, end, false, srcs, itt);
 }
 
 void
 AudioTrack::freeze (InterThreadInfo& itt)
 {
-       vector<AudioSource*> srcs;
+       vector<boost::shared_ptr<AudioSource> > srcs;
        string new_playlist_name;
        Playlist* new_playlist;
        string dir;
-       AudioRegion* region;
        string region_name;
-       AudioDiskstream& diskstream = audio_diskstream();
+       boost::shared_ptr<AudioDiskstream> diskstream = audio_diskstream();
        
-       if ((_freeze_record.playlist = dynamic_cast<AudioPlaylist*>(diskstream.playlist())) == 0) {
+       if ((_freeze_record.playlist = dynamic_cast<AudioPlaylist*>(diskstream->playlist())) == 0) {
                return;
        }
 
@@ -816,18 +819,18 @@ AudioTrack::freeze (InterThreadInfo& itt)
 
        /* create a new region from all filesources, keep it private */
 
-       region = new AudioRegion (srcs, 0, srcs[0]->length(), 
-                                 region_name, 0, 
-                                 (AudioRegion::Flag) (AudioRegion::WholeFile|AudioRegion::DefaultFlags),
-                                 false);
+       boost::shared_ptr<Region> region (RegionFactory::create (srcs, 0, srcs[0]->length(), 
+                                                                region_name, 0, 
+                                                                (AudioRegion::Flag) (AudioRegion::WholeFile|AudioRegion::DefaultFlags),
+                                                                false));
 
-       new_playlist->set_orig_diskstream_id (diskstream.id());
-       new_playlist->add_region (*region, 0);
+       new_playlist->set_orig_diskstream_id (diskstream->id());
+       new_playlist->add_region (region, 0);
        new_playlist->set_frozen (true);
        region->set_locked (true);
 
-       diskstream.use_playlist (dynamic_cast<AudioPlaylist*>(new_playlist));
-       diskstream.set_record_enabled (false);
+       diskstream->use_playlist (dynamic_cast<AudioPlaylist*>(new_playlist));
+       diskstream->set_record_enabled (false);
 
        _freeze_record.state = Frozen;
        FreezeChange(); /* EMIT SIGNAL */
@@ -837,7 +840,7 @@ void
 AudioTrack::unfreeze ()
 {
        if (_freeze_record.playlist) {
-               audio_diskstream().use_playlist (_freeze_record.playlist);
+               audio_diskstream()->use_playlist (_freeze_record.playlist);
 
                if (_freeze_record.have_mementos) {