Reduce stack requirement of AudioTrack::export_stuff, which fixes a crash when freezing.
[ardour.git] / libs / ardour / audio_track.cc
1 /*
2     Copyright (C) 2002 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <boost/scoped_array.hpp>
21
22 #include "pbd/error.h"
23 #include "pbd/enumwriter.h"
24 #include "pbd/boost_debug.h"
25
26 #include "evoral/Curve.hpp"
27
28 #include "ardour/amp.h"
29 #include "ardour/audio_buffer.h"
30 #include "ardour/audio_diskstream.h"
31 #include "ardour/audio_track.h"
32 #include "ardour/audioplaylist.h"
33 #include "ardour/audioregion.h"
34 #include "ardour/audiosource.h"
35 #include "ardour/buffer_set.h"
36 #include "ardour/io_processor.h"
37 #include "ardour/panner.h"
38 #include "ardour/meter.h"
39 #include "ardour/playlist_factory.h"
40 #include "ardour/plugin_insert.h"
41 #include "ardour/processor.h"
42 #include "ardour/region_factory.h"
43 #include "ardour/route_group_specialized.h"
44 #include "ardour/session.h"
45 #include "ardour/utils.h"
46 #include "ardour/session_playlists.h"
47 #include "i18n.h"
48
49 using namespace std;
50 using namespace ARDOUR;
51 using namespace PBD;
52
53 AudioTrack::AudioTrack (Session& sess, string name, Route::Flag flag, TrackMode mode)
54         : Track (sess, name, flag, mode)
55 {
56 }
57
58 AudioTrack::~AudioTrack ()
59 {
60 }
61
62 void
63 AudioTrack::use_new_diskstream ()
64 {
65         AudioDiskstream::Flag dflags = AudioDiskstream::Flag (0);
66
67         if (_flags & Hidden) {
68                 dflags = AudioDiskstream::Flag (dflags | AudioDiskstream::Hidden);
69         } else {
70                 dflags = AudioDiskstream::Flag (dflags | AudioDiskstream::Recordable);
71         }
72
73         if (_mode == Destructive) {
74                 dflags = AudioDiskstream::Flag (dflags | AudioDiskstream::Destructive);
75         } else if (_mode == NonLayered){
76                 dflags = AudioDiskstream::Flag(dflags | AudioDiskstream::NonLayered);
77         }
78
79         AudioDiskstream* dsp (new AudioDiskstream (_session, name(), dflags));
80         boost::shared_ptr<AudioDiskstream> ds (dsp);
81
82         _session.add_diskstream (ds);
83
84         set_diskstream (ds);
85 }
86
87 void
88 AudioTrack::set_diskstream (boost::shared_ptr<Diskstream> ds)
89 {
90         _diskstream = ds;
91         _diskstream->set_route (*this);
92         _diskstream->set_destructive (_mode == Destructive);
93         _diskstream->set_non_layered (_mode == NonLayered);
94
95         if (audio_diskstream()->deprecated_io_node) {
96
97                 if (!IO::connecting_legal) {
98                         IO::ConnectingLegal.connect_same_thread (*this, boost::bind (&AudioTrack::deprecated_use_diskstream_connections, this));
99                 } else {
100                         deprecated_use_diskstream_connections ();
101                 }
102         }
103
104         _diskstream->set_record_enabled (false);
105         _diskstream->monitor_input (false);
106
107         DiskstreamChanged (); /* EMIT SIGNAL */
108 }
109
110 boost::shared_ptr<AudioDiskstream>
111 AudioTrack::audio_diskstream() const
112 {
113         return boost::dynamic_pointer_cast<AudioDiskstream>(_diskstream);
114 }
115
116 int
117 AudioTrack::set_mode (TrackMode m)
118 {
119         if (m != _mode) {
120
121                 if (_diskstream->set_destructive (m == Destructive)) {
122                         return -1;
123                 }
124
125                 _diskstream->set_non_layered (m == NonLayered);
126                 _mode = m;
127
128                 TrackModeChanged (); /* EMIT SIGNAL */
129         }
130
131         return 0;
132 }
133
134 bool
135 AudioTrack::can_use_mode (TrackMode m, bool& bounce_required)
136 {
137         switch (m) {
138         case NonLayered:
139         case Normal:
140                 bounce_required = false;
141                 return true;
142
143         case Destructive:
144         default:
145                 return _diskstream->can_become_destructive (bounce_required);
146         }
147 }
148
149 int
150 AudioTrack::deprecated_use_diskstream_connections ()
151 {
152         boost::shared_ptr<AudioDiskstream> diskstream = audio_diskstream();
153
154         if (diskstream->deprecated_io_node == 0) {
155                 return 0;
156         }
157
158         const XMLProperty* prop;
159         XMLNode& node (*diskstream->deprecated_io_node);
160
161         /* don't do this more than once. */
162
163         diskstream->deprecated_io_node = 0;
164
165         if ((prop = node.property ("gain")) != 0) {
166                 _amp->set_gain (atof (prop->value().c_str()), this);
167         }
168
169         if ((prop = node.property ("input-connection")) != 0) {
170                 boost::shared_ptr<Bundle> c = _session.bundle_by_name (prop->value());
171
172                 if (c == 0) {
173                         error << string_compose(_("Unknown bundle \"%1\" listed for input of %2"), prop->value(), _name) << endmsg;
174
175                         if ((c = _session.bundle_by_name (_("in 1"))) == 0) {
176                                 error << _("No input bundles available as a replacement")
177                                 << endmsg;
178                                 return -1;
179                         } else {
180                                 info << string_compose (_("Bundle %1 was not available - \"in 1\" used instead"), prop->value())
181                                << endmsg;
182                         }
183                 }
184
185                 _input->connect_ports_to_bundle (c, this);
186
187         } else if ((prop = node.property ("inputs")) != 0) {
188                 if (_input->set_ports (prop->value())) {
189                         error << string_compose(_("improper input channel list in XML node (%1)"), prop->value()) << endmsg;
190                         return -1;
191                 }
192         }
193
194         return 0;
195 }
196
197 int
198 AudioTrack::set_state (const XMLNode& node, int version)
199 {
200         return _set_state (node, version, true);
201 }
202
203 int
204 AudioTrack::_set_state (const XMLNode& node, int version, bool call_base)
205 {
206         const XMLProperty *prop;
207         XMLNodeConstIterator iter;
208
209         if (call_base) {
210                 if (Route::_set_state (node, version, call_base)) {
211                         return -1;
212                 }
213         }
214
215         if ((prop = node.property (X_("mode"))) != 0) {
216                 _mode = TrackMode (string_2_enum (prop->value(), _mode));
217         } else {
218                 _mode = Normal;
219         }
220
221         XMLNodeList nlist;
222         XMLNodeConstIterator niter;
223         XMLNode *child;
224
225         nlist = node.children();
226         for (niter = nlist.begin(); niter != nlist.end(); ++niter){
227                 child = *niter;
228
229                 if (child->name() == X_("recenable")) {
230                         _rec_enable_control->set_state (*child, version);
231                         _session.add_controllable (_rec_enable_control);
232                 }
233         }
234
235         pending_state = const_cast<XMLNode*> (&node);
236
237         if (_session.state_of_the_state() & Session::Loading) {
238                 _session.StateReady.connect_same_thread (*this, boost::bind (&AudioTrack::set_state_part_two, this));
239         } else {
240                 set_state_part_two ();
241         }
242
243         return 0;
244 }
245
246 XMLNode&
247 AudioTrack::state(bool full_state)
248 {
249         XMLNode& root (Route::state(full_state));
250         XMLNode* freeze_node;
251         char buf[64];
252
253         if (_freeze_record.playlist) {
254                 XMLNode* inode;
255
256                 freeze_node = new XMLNode (X_("freeze-info"));
257                 freeze_node->add_property ("playlist", _freeze_record.playlist->name());
258                 freeze_node->add_property ("state", enum_2_string (_freeze_record.state));
259
260                 for (vector<FreezeRecordProcessorInfo*>::iterator i = _freeze_record.processor_info.begin(); i != _freeze_record.processor_info.end(); ++i) {
261                         inode = new XMLNode (X_("processor"));
262                         (*i)->id.print (buf, sizeof (buf));
263                         inode->add_property (X_("id"), buf);
264                         inode->add_child_copy ((*i)->state);
265
266                         freeze_node->add_child_nocopy (*inode);
267                 }
268
269                 root.add_child_nocopy (*freeze_node);
270         }
271
272         /* Alignment: act as a proxy for the diskstream */
273
274         XMLNode* align_node = new XMLNode (X_("Alignment"));
275         AlignStyle as = _diskstream->alignment_style ();
276         align_node->add_property (X_("style"), enum_2_string (as));
277         root.add_child_nocopy (*align_node);
278
279         root.add_property (X_("mode"), enum_2_string (_mode));
280
281         /* we don't return diskstream state because we don't
282            own the diskstream exclusively. control of the diskstream
283            state is ceded to the Session, even if we create the
284            diskstream.
285         */
286
287         _diskstream->id().print (buf, sizeof (buf));
288         root.add_property ("diskstream-id", buf);
289
290         root.add_child_nocopy (_rec_enable_control->get_state());
291
292         return root;
293 }
294
295 void
296 AudioTrack::set_state_part_two ()
297 {
298         XMLNode* fnode;
299         XMLProperty* prop;
300         LocaleGuard lg (X_("POSIX"));
301
302         /* This is called after all session state has been restored but before
303            have been made ports and connections are established.
304         */
305
306         if (pending_state == 0) {
307                 return;
308         }
309
310         if ((fnode = find_named_node (*pending_state, X_("freeze-info"))) != 0) {
311
312                 _freeze_record.state = Frozen;
313
314                 for (vector<FreezeRecordProcessorInfo*>::iterator i = _freeze_record.processor_info.begin(); i != _freeze_record.processor_info.end(); ++i) {
315                         delete *i;
316                 }
317                 _freeze_record.processor_info.clear ();
318
319                 if ((prop = fnode->property (X_("playlist"))) != 0) {
320                         boost::shared_ptr<Playlist> pl = _session.playlists->by_name (prop->value());
321                         if (pl) {
322                                 _freeze_record.playlist = boost::dynamic_pointer_cast<AudioPlaylist> (pl);
323                         } else {
324                                 _freeze_record.playlist.reset ();
325                                 _freeze_record.state = NoFreeze;
326                         return;
327                         }
328                 }
329
330                 if ((prop = fnode->property (X_("state"))) != 0) {
331                         _freeze_record.state = FreezeState (string_2_enum (prop->value(), _freeze_record.state));
332                 }
333
334                 XMLNodeConstIterator citer;
335                 XMLNodeList clist = fnode->children();
336
337                 for (citer = clist.begin(); citer != clist.end(); ++citer) {
338                         if ((*citer)->name() != X_("processor")) {
339                                 continue;
340                         }
341
342                         if ((prop = (*citer)->property (X_("id"))) == 0) {
343                                 continue;
344                         }
345
346                         FreezeRecordProcessorInfo* frii = new FreezeRecordProcessorInfo (*((*citer)->children().front()),
347                                                                                    boost::shared_ptr<Processor>());
348                         frii->id = prop->value ();
349                         _freeze_record.processor_info.push_back (frii);
350                 }
351         }
352
353         /* Alignment: act as a proxy for the diskstream */
354
355         if ((fnode = find_named_node (*pending_state, X_("Alignment"))) != 0) {
356
357                 if ((prop = fnode->property (X_("style"))) != 0) {
358
359                         /* fix for older sessions from before EnumWriter */
360
361                         string pstr;
362
363                         if (prop->value() == "capture") {
364                                 pstr = "CaptureTime";
365                         } else if (prop->value() == "existing") {
366                                 pstr = "ExistingMaterial";
367                         } else {
368                                 pstr = prop->value();
369                         }
370
371                         AlignStyle as = AlignStyle (string_2_enum (pstr, as));
372                         _diskstream->set_persistent_align_style (as);
373                 }
374         }
375         return;
376 }
377
378 int
379 AudioTrack::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
380                   bool can_record, bool rec_monitors_input, bool& need_butler)
381 {
382         int dret;
383         Sample* b;
384         Sample* tmpb;
385         nframes_t transport_frame;
386         boost::shared_ptr<AudioDiskstream> diskstream = audio_diskstream();
387         
388         {
389                 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
390                 if (lm.locked()) {
391                         // automation snapshot can also be called from the non-rt context
392                         // and it uses the redirect list, so we take the lock out here
393                         automation_snapshot (start_frame, false);
394                 }
395         }
396
397         if (n_outputs().n_total() == 0 && _processors.empty()) {
398                 return 0;
399         }
400
401         if (!_active) {
402                 silence (nframes);
403                 return 0;
404         }
405
406         transport_frame = _session.transport_frame();
407
408         if ((nframes = check_initial_delay (nframes, transport_frame)) == 0) {
409
410                 /* need to do this so that the diskstream sets its
411                    playback distance to zero, thus causing diskstream::commit
412                    to do nothing.
413                 */
414                 return diskstream->process (transport_frame, 0, can_record, rec_monitors_input, need_butler);
415         }
416
417         _silent = false;
418         _amp->apply_gain_automation(false);
419
420         if ((dret = diskstream->process (transport_frame, nframes, can_record, rec_monitors_input, need_butler)) != 0) {
421                 silence (nframes);
422                 return dret;
423         }
424
425         /* special condition applies */
426
427         if (_meter_point == MeterInput) {
428                 _input->process_input (_meter, start_frame, end_frame, nframes);
429         }
430
431         if (diskstream->record_enabled() && !can_record && !_session.config.get_auto_input()) {
432
433                 /* not actually recording, but we want to hear the input material anyway,
434                    at least potentially (depending on monitoring options)
435                  */
436
437                 passthru (start_frame, end_frame, nframes, false);
438
439         } else if ((b = diskstream->playback_buffer(0)) != 0) {
440
441                 /*
442                   XXX is it true that the earlier test on n_outputs()
443                   means that we can avoid checking it again here? i think
444                   so, because changing the i/o configuration of an IO
445                   requires holding the AudioEngine lock, which we hold
446                   while in the process() tree.
447                 */
448
449
450                 /* copy the diskstream data to all output buffers */
451
452                 size_t limit = input_streams ().n_audio();
453                 BufferSet& bufs = _session.get_scratch_buffers ();
454                 const size_t blimit = bufs.count().n_audio();
455
456                 uint32_t n;
457                 uint32_t i;
458
459                 if (limit > blimit) {
460
461                         /* example case: auditioner configured for stereo output,
462                            but loaded with an 8 channel file. there are only
463                            2 passthrough buffers, but n_process_buffers() will
464                            return 8.
465
466                            arbitrary decision: map all channels in the diskstream
467                            to the outputs available.
468                         */
469
470                         float scaling = limit/blimit;
471
472                         for (i = 0, n = 1; i < blimit; ++i, ++n) {
473
474                                 /* first time through just copy a channel into
475                                    the output buffer.
476                                 */
477
478                                 Sample* bb = bufs.get_audio (i).data();
479
480                                 for (nframes_t xx = 0; xx < nframes; ++xx) {
481                                         bb[xx] = b[xx] * scaling;
482                                 }
483
484                                 if (n < diskstream->n_channels().n_audio()) {
485                                         tmpb = diskstream->playback_buffer(n);
486                                         if (tmpb!=0) {
487                                                 b = tmpb;
488                                         }
489                                 }
490                         }
491
492                         for (;i < limit; ++i, ++n) {
493
494                                 /* for all remaining channels, sum with existing
495                                    data in the output buffers
496                                 */
497
498                                 bufs.get_audio (i%blimit).accumulate_with_gain_from (b, nframes, 0, scaling);
499
500                                 if (n < diskstream->n_channels().n_audio()) {
501                                         tmpb = diskstream->playback_buffer(n);
502                                         if (tmpb!=0) {
503                                                 b = tmpb;
504                                         }
505                                 }
506
507                         }
508
509                         limit = blimit;
510
511                 } else {
512                         for (i = 0, n = 1; i < limit; ++i, ++n) {
513                                 memcpy (bufs.get_audio (i).data(), b, sizeof (Sample) * nframes);
514                                 if (n < diskstream->n_channels().n_audio()) {
515                                         tmpb = diskstream->playback_buffer(n);
516                                         if (tmpb!=0) {
517                                                 b = tmpb;
518                                         }
519                                 }
520                         }
521
522                         /* try to leave any MIDI buffers alone */
523
524                         ChanCount chn;
525                         chn.set_audio (limit);
526                         chn.set_midi (_input->n_ports().n_midi());
527                         bufs.set_count (chn);
528                 }
529
530                 /* don't waste time with automation if we're recording or we've just stopped (yes it can happen) */
531
532                 if (!diskstream->record_enabled() && _session.transport_rolling()) {
533 #ifdef XXX_MOVE_THIS_TO_AMP
534                         Glib::Mutex::Lock am (data().control_lock(), Glib::TRY_LOCK);
535
536                         if (am.locked() && gain_control()->automation_playback()) {
537                                 _amp->apply_gain_automation(
538                                                 gain_control()->list()->curve().rt_safe_get_vector (
539                                                         start_frame, end_frame, _session.gain_automation_buffer(), nframes));
540                         }
541 #endif
542                 }
543
544                 process_output_buffers (bufs, start_frame, end_frame, nframes, (!_session.get_record_enabled() || !Config->get_do_not_record_plugins()), declick);
545
546         } else {
547                 /* problem with the diskstream; just be quiet for a bit */
548                 silence (nframes);
549         }
550
551         return 0;
552 }
553
554 int
555 AudioTrack::export_stuff (BufferSet& buffers, sframes_t start, nframes_t nframes, bool enable_processing)
556 {
557         boost::scoped_array<gain_t> gain_buffer (new gain_t[nframes]);
558         boost::scoped_array<float> mix_buffer (new float[nframes]);
559         ProcessorList::iterator i;
560         boost::shared_ptr<AudioDiskstream> diskstream = audio_diskstream();
561
562         Glib::RWLock::ReaderLock rlock (_processor_lock);
563
564         boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist>(diskstream->playlist());
565         assert(apl);
566
567         assert(buffers.get_audio(0).capacity() >= nframes);
568
569         if (apl->read (buffers.get_audio(0).data(), mix_buffer.get(), gain_buffer.get(), start, nframes) != nframes) {
570                 return -1;
571         }
572
573         assert(buffers.count().n_audio() >= 1);
574         uint32_t n=1;
575         Sample* b = buffers.get_audio(0).data();
576         BufferSet::audio_iterator bi = buffers.audio_begin();
577         ++bi;
578         for ( ; bi != buffers.audio_end(); ++bi, ++n) {
579                 if (n < diskstream->n_channels().n_audio()) {
580                         if (apl->read (bi->data(), mix_buffer.get(), gain_buffer.get(), start, nframes, n) != nframes) {
581                                 return -1;
582                         }
583                         b = bi->data();
584                 }
585                 else {
586                         /* duplicate last across remaining buffers */
587                         memcpy (bi->data(), b, sizeof (Sample) * nframes);
588                 }
589         }
590
591         // If no processing is required, there's no need to go any further.
592         if (!enable_processing) {
593                 return 0;
594         }
595
596         /* note: only run processors during export. other layers in the machinery
597            will already have checked that there are no external port processors.
598         */
599
600         for (i = _processors.begin(); i != _processors.end(); ++i) {
601                 boost::shared_ptr<Processor> processor;
602                 if ((processor = boost::dynamic_pointer_cast<Processor>(*i)) != 0) {
603                         processor->run (buffers, start, start+nframes, nframes, true);
604                 }
605         }
606
607         return 0;
608 }
609
610 boost::shared_ptr<Region>
611 AudioTrack::bounce (InterThreadInfo& itt)
612 {
613         vector<boost::shared_ptr<Source> > srcs;
614         return _session.write_one_track (*this, _session.current_start_frame(), _session.current_end_frame(), false, srcs, itt);
615 }
616
617 boost::shared_ptr<Region>
618 AudioTrack::bounce_range (nframes_t start, nframes_t end, InterThreadInfo& itt, bool enable_processing)
619 {
620         vector<boost::shared_ptr<Source> > srcs;
621         return _session.write_one_track (*this, start, end, false, srcs, itt, enable_processing);
622 }
623
624 void
625 AudioTrack::freeze_me (InterThreadInfo& itt)
626 {
627         vector<boost::shared_ptr<Source> > srcs;
628         string new_playlist_name;
629         boost::shared_ptr<Playlist> new_playlist;
630         string dir;
631         string region_name;
632         boost::shared_ptr<AudioDiskstream> diskstream = audio_diskstream();
633
634         if ((_freeze_record.playlist = boost::dynamic_pointer_cast<AudioPlaylist>(diskstream->playlist())) == 0) {
635                 return;
636         }
637
638         uint32_t n = 1;
639
640         while (n < (UINT_MAX-1)) {
641
642                 string candidate;
643
644                 candidate = string_compose ("<F%2>%1", _freeze_record.playlist->name(), n);
645
646                 if (_session.playlists->by_name (candidate) == 0) {
647                         new_playlist_name = candidate;
648                         break;
649                 }
650
651                 ++n;
652
653         }
654
655         if (n == (UINT_MAX-1)) {
656           error << string_compose (X_("There are too many frozen versions of playlist \"%1\""
657                             " to create another one"), _freeze_record.playlist->name())
658                << endmsg;
659                 return;
660         }
661
662         boost::shared_ptr<Region> res;
663
664         if ((res = _session.write_one_track (*this, _session.current_start_frame(), _session.current_end_frame(), true, srcs, itt)) == 0) {
665                 return;
666         }
667
668         _freeze_record.processor_info.clear ();
669
670         {
671                 Glib::RWLock::ReaderLock lm (_processor_lock);
672
673                 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
674
675                         boost::shared_ptr<Processor> processor;
676
677                         if ((processor = boost::dynamic_pointer_cast<Processor>(*r)) != 0) {
678
679                                 FreezeRecordProcessorInfo* frii  = new FreezeRecordProcessorInfo ((*r)->get_state(), processor);
680
681                                 frii->id = processor->id();
682
683                                 _freeze_record.processor_info.push_back (frii);
684
685                                 /* now deactivate the processor */
686
687                                 processor->deactivate ();
688                                 _session.set_dirty ();
689                         }
690                 }
691         }
692
693         new_playlist = PlaylistFactory::create (DataType::AUDIO, _session, new_playlist_name, false);
694
695         _freeze_record.gain = _amp->gain();
696         _freeze_record.gain_automation_state = _amp->gain_control()->automation_state();
697         /* XXX need main outs automation state _freeze_record.pan_automation_state = _mainpanner->automation_state(); */
698
699         region_name = new_playlist_name;
700
701         /* create a new region from all filesources, keep it private */
702
703         PropertyList plist;
704         
705         plist.add (Properties::start, 0);
706         plist.add (Properties::length, srcs[0]->length(srcs[0]->timeline_position()));
707         plist.add (Properties::name, region_name);
708         plist.add (Properties::whole_file, true);
709
710         boost::shared_ptr<Region> region (RegionFactory::create (srcs, plist, false));
711
712         new_playlist->set_orig_diskstream_id (diskstream->id());
713         new_playlist->add_region (region, _session.current_start_frame());
714         new_playlist->set_frozen (true);
715         region->set_locked (true);
716
717         diskstream->use_playlist (boost::dynamic_pointer_cast<AudioPlaylist>(new_playlist));
718         diskstream->set_record_enabled (false);
719
720         /* reset stuff that has already been accounted for in the freeze process */
721
722         set_gain (1.0, this);
723         _amp->gain_control()->set_automation_state (Off);
724         /* XXX need to use _main_outs _panner->set_automation_state (Off); */
725
726         _freeze_record.state = Frozen;
727         FreezeChange(); /* EMIT SIGNAL */
728 }
729
730 void
731 AudioTrack::unfreeze ()
732 {
733         if (_freeze_record.playlist) {
734                 audio_diskstream()->use_playlist (_freeze_record.playlist);
735
736                 {
737                         Glib::RWLock::ReaderLock lm (_processor_lock); // should this be a write lock? jlc
738                         for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
739                                 for (vector<FreezeRecordProcessorInfo*>::iterator ii = _freeze_record.processor_info.begin(); ii != _freeze_record.processor_info.end(); ++ii) {
740                                         if ((*ii)->id == (*i)->id()) {
741                                                 (*i)->set_state (((*ii)->state), Stateful::current_state_version);
742                                                 break;
743                                         }
744                                 }
745                         }
746                 }
747
748                 _freeze_record.playlist.reset ();
749                 set_gain (_freeze_record.gain, this);
750                 _amp->gain_control()->set_automation_state (_freeze_record.gain_automation_state);
751                 /* XXX need to use _main_outs _panner->set_automation_state (_freeze_record.pan_automation_state); */
752         }
753
754         _freeze_record.state = UnFrozen;
755         FreezeChange (); /* EMIT SIGNAL */
756 }
757