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