Expose virtual-keyboard port as async-port
[ardour.git] / libs / ardour / playlist_factory.cc
1 /*
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>
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #include "pbd/error.h"
22 #include "pbd/xml++.h"
23
24 #include "ardour/playlist.h"
25 #include "ardour/audioplaylist.h"
26 #include "ardour/midi_playlist.h"
27 #include "ardour/playlist_factory.h"
28
29 #include "pbd/i18n.h"
30
31 using namespace std;
32 using namespace ARDOUR;
33 using namespace PBD;
34
35 PBD::Signal2<void,boost::shared_ptr<Playlist>, bool> PlaylistFactory::PlaylistCreated;
36
37 boost::shared_ptr<Playlist>
38 PlaylistFactory::create (Session& s, const XMLNode& node, bool hidden, bool unused)
39 {
40         XMLProperty const * type = node.property("type");
41
42         boost::shared_ptr<Playlist> pl;
43
44         try {
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));
49                 }
50
51                 pl->set_region_ownership ();
52
53                 if (pl && !hidden) {
54                         PlaylistCreated (pl, unused);
55                 }
56                 return pl;
57
58         } catch (...) {
59                 return boost::shared_ptr<Playlist> ();
60         }
61 }
62
63 boost::shared_ptr<Playlist>
64 PlaylistFactory::create (DataType type, Session& s, string name, bool hidden)
65 {
66         boost::shared_ptr<Playlist> pl;
67
68         try {
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));
73
74                 if (pl && !hidden) {
75                         PlaylistCreated (pl, false);
76                 }
77
78                 return pl;
79         } catch (...) {
80                 return boost::shared_ptr<Playlist> ();
81         }
82 }
83
84 boost::shared_ptr<Playlist>
85 PlaylistFactory::create (boost::shared_ptr<const Playlist> old, string name, bool hidden)
86 {
87         boost::shared_ptr<Playlist> pl;
88         boost::shared_ptr<const AudioPlaylist> apl;
89         boost::shared_ptr<const MidiPlaylist> mpl;
90
91         try {
92
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 ();
99                 }
100
101                 if (pl && !hidden) {
102                         PlaylistCreated (pl, false);
103                 }
104
105                 return pl;
106         } catch (...) {
107                 return boost::shared_ptr<Playlist> ();
108         }
109
110 }
111
112 boost::shared_ptr<Playlist>
113 PlaylistFactory::create (boost::shared_ptr<const Playlist> old, samplepos_t start, samplecnt_t cnt, string name, bool hidden)
114 {
115         boost::shared_ptr<Playlist> pl;
116         boost::shared_ptr<const AudioPlaylist> apl;
117         boost::shared_ptr<const MidiPlaylist> mpl;
118
119         try {
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 ();
126                 }
127
128                 /* this factory method does NOT notify others */
129
130                 return pl;
131         } catch (...) {
132                 return boost::shared_ptr<Playlist> ();
133         }
134 }