2 * Copyright (C) 2006-2009 David Robillard <d@drobilla.net>
3 * Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "pbd/error.h"
22 #include "pbd/xml++.h"
24 #include "ardour/playlist.h"
25 #include "ardour/audioplaylist.h"
26 #include "ardour/midi_playlist.h"
27 #include "ardour/playlist_factory.h"
32 using namespace ARDOUR;
35 PBD::Signal2<void,boost::shared_ptr<Playlist>, bool> PlaylistFactory::PlaylistCreated;
37 boost::shared_ptr<Playlist>
38 PlaylistFactory::create (Session& s, const XMLNode& node, bool hidden, bool unused)
40 XMLProperty const * type = node.property("type");
42 boost::shared_ptr<Playlist> pl;
45 if (!type || type->value() == "audio") {
46 pl = boost::shared_ptr<Playlist> (new AudioPlaylist (s, node, hidden));
47 } else if (type->value() == "midi") {
48 pl = boost::shared_ptr<Playlist> (new MidiPlaylist (s, node, hidden));
51 pl->set_region_ownership ();
54 PlaylistCreated (pl, unused);
59 return boost::shared_ptr<Playlist> ();
63 boost::shared_ptr<Playlist>
64 PlaylistFactory::create (DataType type, Session& s, string name, bool hidden)
66 boost::shared_ptr<Playlist> pl;
69 if (type == DataType::AUDIO)
70 pl = boost::shared_ptr<Playlist> (new AudioPlaylist (s, name, hidden));
71 else if (type == DataType::MIDI)
72 pl = boost::shared_ptr<Playlist> (new MidiPlaylist (s, name, hidden));
75 PlaylistCreated (pl, false);
80 return boost::shared_ptr<Playlist> ();
84 boost::shared_ptr<Playlist>
85 PlaylistFactory::create (boost::shared_ptr<const Playlist> old, string name, bool hidden)
87 boost::shared_ptr<Playlist> pl;
88 boost::shared_ptr<const AudioPlaylist> apl;
89 boost::shared_ptr<const MidiPlaylist> mpl;
93 if ((apl = boost::dynamic_pointer_cast<const AudioPlaylist> (old)) != 0) {
94 pl = boost::shared_ptr<Playlist> (new AudioPlaylist (apl, name, hidden));
95 pl->set_region_ownership ();
96 } else if ((mpl = boost::dynamic_pointer_cast<const MidiPlaylist> (old)) != 0) {
97 pl = boost::shared_ptr<Playlist> (new MidiPlaylist (mpl, name, hidden));
98 pl->set_region_ownership ();
102 PlaylistCreated (pl, false);
107 return boost::shared_ptr<Playlist> ();
112 boost::shared_ptr<Playlist>
113 PlaylistFactory::create (boost::shared_ptr<const Playlist> old, samplepos_t start, samplecnt_t cnt, string name, bool hidden)
115 boost::shared_ptr<Playlist> pl;
116 boost::shared_ptr<const AudioPlaylist> apl;
117 boost::shared_ptr<const MidiPlaylist> mpl;
120 if ((apl = boost::dynamic_pointer_cast<const AudioPlaylist> (old)) != 0) {
121 pl = boost::shared_ptr<Playlist> (new AudioPlaylist (apl, start, cnt, name, hidden));
122 pl->set_region_ownership ();
123 } else if ((mpl = boost::dynamic_pointer_cast<const MidiPlaylist> (old)) != 0) {
124 pl = boost::shared_ptr<Playlist> (new MidiPlaylist (mpl, start, cnt, name, hidden));
125 pl->set_region_ownership ();
128 /* this factory method does NOT notify others */
132 return boost::shared_ptr<Playlist> ();