2 Copyright (C) 2000-2006 Paul Davis
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.
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.
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.
20 #include "pbd/error.h"
21 #include "pbd/boost_debug.h"
23 #include "ardour/session.h"
25 #include "ardour/region_factory.h"
26 #include "ardour/region.h"
27 #include "ardour/audioregion.h"
28 #include "ardour/audiosource.h"
29 #include "ardour/midi_source.h"
30 #include "ardour/midi_region.h"
34 using namespace ARDOUR;
37 PBD::Signal1<void,boost::shared_ptr<Region> > RegionFactory::CheckNewRegion;
39 boost::shared_ptr<Region>
40 RegionFactory::create (boost::shared_ptr<Region> region, nframes_t start,
41 nframes_t length, const std::string& name,
42 layer_t layer, Region::Flag flags, bool announce)
44 boost::shared_ptr<const AudioRegion> other_a;
45 boost::shared_ptr<const MidiRegion> other_m;
47 if ((other_a = boost::dynamic_pointer_cast<AudioRegion>(region)) != 0) {
48 AudioRegion* ar = new AudioRegion (other_a, start, length, name, layer, flags);
49 boost_debug_shared_ptr_mark_interesting (ar, "Region");
50 boost::shared_ptr<AudioRegion> arp (ar);
51 boost::shared_ptr<Region> ret (boost::static_pointer_cast<Region> (arp));
52 ret->unlock_property_changes ();
57 } else if ((other_m = boost::dynamic_pointer_cast<MidiRegion>(region)) != 0) {
58 MidiRegion* ar = new MidiRegion (other_m, start, length, name, layer, flags);
59 boost::shared_ptr<MidiRegion> arp (ar);
60 boost::shared_ptr<Region> ret (boost::static_pointer_cast<Region> (arp));
61 ret->unlock_property_changes ();
67 fatal << _("programming error: RegionFactory::create() called with unknown Region type")
70 return boost::shared_ptr<Region>();
74 boost::shared_ptr<Region>
75 RegionFactory::create (boost::shared_ptr<const Region> region)
77 boost::shared_ptr<const AudioRegion> ar;
78 boost::shared_ptr<const MidiRegion> mr;
80 if ((ar = boost::dynamic_pointer_cast<const AudioRegion>(region)) != 0) {
81 AudioRegion* arn = new AudioRegion (ar);
82 boost_debug_shared_ptr_mark_interesting (arn, "Region");
83 boost::shared_ptr<Region> ret (arn);
84 ret->unlock_property_changes ();
85 /* pure copy constructor - no CheckNewRegion emitted */
87 } else if ((mr = boost::dynamic_pointer_cast<const MidiRegion>(region)) != 0) {
88 boost::shared_ptr<Region> ret (new MidiRegion (mr));
89 ret->unlock_property_changes ();
90 /* pure copy constructor - no CheckNewRegion emitted */
93 fatal << _("programming error: RegionFactory::create() called with unknown Region type")
96 return boost::shared_ptr<Region>();
100 boost::shared_ptr<Region>
101 RegionFactory::create (boost::shared_ptr<AudioRegion> region, nframes_t start,
102 nframes_t length, const std::string& name,
103 layer_t layer, Region::Flag flags, bool announce)
105 return create (boost::static_pointer_cast<Region> (region), start, length, name, layer, flags, announce);
108 boost::shared_ptr<Region>
109 RegionFactory::create (boost::shared_ptr<Region> region, const SourceList& srcs,
110 const std::string& name, layer_t layer, Region::Flag flags, bool announce)
113 boost::shared_ptr<const AudioRegion> other;
115 /* used by AudioFilter when constructing a new region that is intended to have nearly
116 identical settings to an original, but using different sources.
119 if ((other = boost::dynamic_pointer_cast<AudioRegion>(region)) != 0) {
120 AudioRegion* ar = new AudioRegion (other, srcs, srcs.front()->length(srcs.front()->timeline_position()), name, layer, flags);
121 boost_debug_shared_ptr_mark_interesting (ar, "Region");
122 boost::shared_ptr<AudioRegion> arp (ar);
123 boost::shared_ptr<Region> ret (boost::static_pointer_cast<Region> (arp));
124 ret->unlock_property_changes ();
126 CheckNewRegion (ret);
130 fatal << _("programming error: RegionFactory::create() called with unknown Region type")
133 return boost::shared_ptr<Region>();
137 boost::shared_ptr<Region>
138 RegionFactory::create (Session& session, XMLNode& node, bool yn)
140 boost::shared_ptr<Region> r = session.XMLRegionFactory (node, yn);
143 r->unlock_property_changes ();
150 boost::shared_ptr<Region>
151 RegionFactory::create (const SourceList& srcs, nframes_t start, nframes_t length, const string& name, layer_t layer, Region::Flag flags, bool announce)
154 return boost::shared_ptr<Region>();
157 if (srcs[0]->type() == DataType::AUDIO) {
159 AudioRegion* ar = new AudioRegion (srcs, start, length, name, layer, flags);
160 boost_debug_shared_ptr_mark_interesting (ar, "Region");
161 boost::shared_ptr<AudioRegion> arp (ar);
162 boost::shared_ptr<Region> ret (boost::static_pointer_cast<Region> (arp));
163 ret->unlock_property_changes ();
165 CheckNewRegion (ret);
169 } else if (srcs[0]->type() == DataType::MIDI) {
171 MidiRegion* ar = new MidiRegion (srcs, start, length, name, layer, flags);
172 boost::shared_ptr<MidiRegion> mrp (ar);
173 boost::shared_ptr<Region> ret (boost::static_pointer_cast<Region> (mrp));
174 ret->unlock_property_changes ();
176 CheckNewRegion (ret);
182 return boost::shared_ptr<Region> ();
185 boost::shared_ptr<Region>
186 RegionFactory::create (SourceList& srcs, const XMLNode& node)
189 return boost::shared_ptr<Region>();
192 if (srcs[0]->type() == DataType::AUDIO) {
193 AudioRegion* ar = new AudioRegion (srcs, node);
194 boost_debug_shared_ptr_mark_interesting (ar, "Region");
195 boost::shared_ptr<Region> ret (ar);
196 ret->unlock_property_changes ();
197 CheckNewRegion (ret);
199 } else if (srcs[0]->type() == DataType::MIDI) {
200 boost::shared_ptr<Region> ret (new MidiRegion (srcs, node));
201 ret->unlock_property_changes ();
202 CheckNewRegion (ret);
206 return boost::shared_ptr<Region> ();
209 boost::shared_ptr<Region>
210 RegionFactory::create (boost::shared_ptr<Source> src, nframes_t start, nframes_t length, const string& name, layer_t layer, Region::Flag flags, bool announce)
212 boost::shared_ptr<AudioSource> as;
213 boost::shared_ptr<MidiSource> ms;
215 if ((as = boost::dynamic_pointer_cast<AudioSource>(src)) != 0) {
216 AudioRegion* ar = new AudioRegion (as, start, length, name, layer, flags);
217 boost_debug_shared_ptr_mark_interesting (ar, "Region");
218 boost::shared_ptr<Region> ret (ar);
219 ret->unlock_property_changes ();
221 CheckNewRegion (ret);
224 } else if ((ms = boost::dynamic_pointer_cast<MidiSource>(src)) != 0) {
225 boost::shared_ptr<Region> ret (new MidiRegion (ms, start, length, name, layer, flags));
226 ret->unlock_property_changes ();
228 CheckNewRegion (ret);
233 return boost::shared_ptr<Region>();