Remove unnecessary 0 checks before delete; see http://www.parashift.com/c++-faq-lite...
[ardour.git] / libs / ardour / playlist_factory.cc
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
22 #include <ardour/playlist.h>
23 #include <ardour/audioplaylist.h>
24 #include <ardour/midi_playlist.h>
25 #include <ardour/playlist_factory.h>
26
27 #include "i18n.h"
28
29 using namespace ARDOUR;
30 using namespace PBD;
31
32 sigc::signal<void,boost::shared_ptr<Playlist>, bool> PlaylistFactory::PlaylistCreated;
33
34 boost::shared_ptr<Playlist> 
35 PlaylistFactory::create (Session& s, const XMLNode& node, bool hidden, bool unused)
36 {
37         const XMLProperty* type = node.property("type");
38
39         boost::shared_ptr<Playlist> pl;
40
41         if ( !type || type->value() == "audio" )
42                 pl = boost::shared_ptr<Playlist> (new AudioPlaylist (s, node, hidden));
43         else if ( type->value() == "midi" )
44                 pl = boost::shared_ptr<Playlist> (new MidiPlaylist (s, node, hidden));
45
46         pl->set_region_ownership ();
47
48         if (pl && !hidden) {
49                 PlaylistCreated (pl, unused);
50         }
51         return pl;
52 }
53
54 boost::shared_ptr<Playlist> 
55 PlaylistFactory::create (DataType type, Session& s, string name, bool hidden) 
56 {
57         boost::shared_ptr<Playlist> pl;
58
59         if (type == DataType::AUDIO)
60                 pl = boost::shared_ptr<Playlist> (new AudioPlaylist (s, name, hidden));
61         else if (type == DataType::MIDI)
62                 pl = boost::shared_ptr<Playlist> (new MidiPlaylist (s, name, hidden));
63
64         if (pl && !hidden) {
65                 PlaylistCreated (pl, false);
66         }
67
68         return pl;
69 }
70
71 boost::shared_ptr<Playlist> 
72 PlaylistFactory::create (boost::shared_ptr<const Playlist> old, string name, bool hidden) 
73 {
74         boost::shared_ptr<Playlist> pl;
75         boost::shared_ptr<const AudioPlaylist> apl;
76         boost::shared_ptr<const MidiPlaylist> mpl;
77
78         if ((apl = boost::dynamic_pointer_cast<const AudioPlaylist> (old)) != 0) {
79                 pl = boost::shared_ptr<Playlist> (new AudioPlaylist (apl, name, hidden));
80                 pl->set_region_ownership ();
81         } else if ((mpl = boost::dynamic_pointer_cast<const MidiPlaylist> (old)) != 0) {
82                 pl = boost::shared_ptr<Playlist> (new MidiPlaylist (mpl, name, hidden));
83                 pl->set_region_ownership ();
84         }
85
86         if (pl && !hidden) {
87                 PlaylistCreated (pl, false);
88         }
89
90         return pl;
91 }
92
93 boost::shared_ptr<Playlist> 
94 PlaylistFactory::create (boost::shared_ptr<const Playlist> old, nframes_t start, nframes_t cnt, string name, bool hidden) 
95 {
96         boost::shared_ptr<Playlist> pl;
97         boost::shared_ptr<const AudioPlaylist> apl;
98         boost::shared_ptr<const MidiPlaylist> mpl;
99         
100         if ((apl = boost::dynamic_pointer_cast<const AudioPlaylist> (old)) != 0) {
101                 pl = boost::shared_ptr<Playlist> (new AudioPlaylist (apl, start, cnt, name, hidden));
102                 pl->set_region_ownership ();
103         } else if ((mpl = boost::dynamic_pointer_cast<const MidiPlaylist> (old)) != 0) {
104                 pl = boost::shared_ptr<Playlist> (new MidiPlaylist (mpl, start, cnt, name, hidden));
105                 pl->set_region_ownership ();
106         }
107
108         /* this factory method does NOT notify others */
109
110         return pl;
111 }