possible fix for race between diskstream buffer overwrite and channel setup
[ardour2.git] / libs / ardour / playlist_factory.cc
blob2619d0e0c4dbc12fa6b2cc2c18981d8364732112
1 /*
2 Copyright (C) 2000-2006 Paul Davis
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.
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.
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.
20 #include "pbd/error.h"
21 #include "pbd/xml++.h"
23 #include "ardour/playlist.h"
24 #include "ardour/audioplaylist.h"
25 #include "ardour/midi_playlist.h"
26 #include "ardour/playlist_factory.h"
28 #include "i18n.h"
30 using namespace std;
31 using namespace ARDOUR;
32 using namespace PBD;
34 PBD::Signal2<void,boost::shared_ptr<Playlist>, bool> PlaylistFactory::PlaylistCreated;
36 boost::shared_ptr<Playlist>
37 PlaylistFactory::create (Session& s, const XMLNode& node, bool hidden, bool unused)
39 const XMLProperty* type = node.property("type");
41 boost::shared_ptr<Playlist> pl;
43 if ( !type || type->value() == "audio" )
44 pl = boost::shared_ptr<Playlist> (new AudioPlaylist (s, node, hidden));
45 else if ( type->value() == "midi" )
46 pl = boost::shared_ptr<Playlist> (new MidiPlaylist (s, node, hidden));
48 pl->set_region_ownership ();
50 if (pl && !hidden) {
51 PlaylistCreated (pl, unused);
53 return pl;
56 boost::shared_ptr<Playlist>
57 PlaylistFactory::create (DataType type, Session& s, string name, bool hidden)
59 boost::shared_ptr<Playlist> pl;
61 if (type == DataType::AUDIO)
62 pl = boost::shared_ptr<Playlist> (new AudioPlaylist (s, name, hidden));
63 else if (type == DataType::MIDI)
64 pl = boost::shared_ptr<Playlist> (new MidiPlaylist (s, name, hidden));
66 if (pl && !hidden) {
67 PlaylistCreated (pl, false);
70 return pl;
73 boost::shared_ptr<Playlist>
74 PlaylistFactory::create (boost::shared_ptr<const Playlist> old, string name, bool hidden)
76 boost::shared_ptr<Playlist> pl;
77 boost::shared_ptr<const AudioPlaylist> apl;
78 boost::shared_ptr<const MidiPlaylist> mpl;
80 if ((apl = boost::dynamic_pointer_cast<const AudioPlaylist> (old)) != 0) {
81 pl = boost::shared_ptr<Playlist> (new AudioPlaylist (apl, name, hidden));
82 pl->set_region_ownership ();
83 } else if ((mpl = boost::dynamic_pointer_cast<const MidiPlaylist> (old)) != 0) {
84 pl = boost::shared_ptr<Playlist> (new MidiPlaylist (mpl, name, hidden));
85 pl->set_region_ownership ();
88 if (pl && !hidden) {
89 PlaylistCreated (pl, false);
92 return pl;
95 boost::shared_ptr<Playlist>
96 PlaylistFactory::create (boost::shared_ptr<const Playlist> old, nframes_t start, nframes_t cnt, string name, bool hidden)
98 boost::shared_ptr<Playlist> pl;
99 boost::shared_ptr<const AudioPlaylist> apl;
100 boost::shared_ptr<const MidiPlaylist> mpl;
102 if ((apl = boost::dynamic_pointer_cast<const AudioPlaylist> (old)) != 0) {
103 pl = boost::shared_ptr<Playlist> (new AudioPlaylist (apl, start, cnt, name, hidden));
104 pl->set_region_ownership ();
105 } else if ((mpl = boost::dynamic_pointer_cast<const MidiPlaylist> (old)) != 0) {
106 pl = boost::shared_ptr<Playlist> (new MidiPlaylist (mpl, start, cnt, name, hidden));
107 pl->set_region_ownership ();
110 /* this factory method does NOT notify others */
112 return pl;