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