ardour
playlist_factory.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2000-2006 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 "pbd/error.h"
21 #include "pbd/xml++.h"
22 
23 #include "ardour/playlist.h"
24 #include "ardour/audioplaylist.h"
25 #include "ardour/midi_playlist.h"
27 
28 #include "i18n.h"
29 
30 using namespace std;
31 using namespace ARDOUR;
32 using namespace PBD;
33 
34 PBD::Signal2<void,boost::shared_ptr<Playlist>, bool> PlaylistFactory::PlaylistCreated;
35 
37 PlaylistFactory::create (Session& s, const XMLNode& node, bool hidden, bool unused)
38 {
39  const XMLProperty* type = node.property("type");
40 
42 
43  try {
44  if (!type || type->value() == "audio") {
45  pl = boost::shared_ptr<Playlist> (new AudioPlaylist (s, node, hidden));
46  } else if (type->value() == "midi") {
47  pl = boost::shared_ptr<Playlist> (new MidiPlaylist (s, node, hidden));
48  }
49 
50  pl->set_region_ownership ();
51 
52  if (pl && !hidden) {
53  PlaylistCreated (pl, unused);
54  }
55  return pl;
56 
57  } catch (...) {
59  }
60 }
61 
63 PlaylistFactory::create (DataType type, Session& s, string name, bool hidden)
64 {
66 
67  try {
68  if (type == DataType::AUDIO)
69  pl = boost::shared_ptr<Playlist> (new AudioPlaylist (s, name, hidden));
70  else if (type == DataType::MIDI)
71  pl = boost::shared_ptr<Playlist> (new MidiPlaylist (s, name, hidden));
72 
73  if (pl && !hidden) {
74  PlaylistCreated (pl, false);
75  }
76 
77  return pl;
78  } catch (...) {
80  }
81 }
82 
84 PlaylistFactory::create (boost::shared_ptr<const Playlist> old, string name, bool hidden)
85 {
89 
90  try {
91 
92  if ((apl = boost::dynamic_pointer_cast<const AudioPlaylist> (old)) != 0) {
93  pl = boost::shared_ptr<Playlist> (new AudioPlaylist (apl, name, hidden));
94  pl->set_region_ownership ();
95  } else if ((mpl = boost::dynamic_pointer_cast<const MidiPlaylist> (old)) != 0) {
96  pl = boost::shared_ptr<Playlist> (new MidiPlaylist (mpl, name, hidden));
97  pl->set_region_ownership ();
98  }
99 
100  if (pl && !hidden) {
101  PlaylistCreated (pl, false);
102  }
103 
104  return pl;
105  } catch (...) {
106  return boost::shared_ptr<Playlist> ();
107  }
108 
109 }
110 
112 PlaylistFactory::create (boost::shared_ptr<const Playlist> old, framepos_t start, framecnt_t cnt, string name, bool hidden)
113 {
117 
118  try {
119  if ((apl = boost::dynamic_pointer_cast<const AudioPlaylist> (old)) != 0) {
120  pl = boost::shared_ptr<Playlist> (new AudioPlaylist (apl, start, cnt, name, hidden));
121  pl->set_region_ownership ();
122  } else if ((mpl = boost::dynamic_pointer_cast<const MidiPlaylist> (old)) != 0) {
123  pl = boost::shared_ptr<Playlist> (new MidiPlaylist (mpl, start, cnt, name, hidden));
124  pl->set_region_ownership ();
125  }
126 
127  /* this factory method does NOT notify others */
128 
129  return pl;
130  } catch (...) {
131  return boost::shared_ptr<Playlist> ();
132  }
133 }
const std::string & value() const
Definition: xml++.h:159
LIBARDOUR_API PBD::PropertyDescriptor< bool > hidden
Definition: route_group.h:50
Definition: Beats.hpp:239
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > start
Definition: region.cc:63
int64_t framecnt_t
Definition: types.h:76
XMLProperty * property(const char *)
Definition: xml++.cc:413
Definition: amp.h:29
int64_t framepos_t
Definition: types.h:66
const char * name
Definition: xml++.h:95
Definition: debug.h:30
void set_region_ownership()
Definition: playlist.cc:725