ensure that the name used the control out IO for a route always uses the desired...
[ardour.git] / libs / ardour / region_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/session.h>
23
24 #include <ardour/region_factory.h>
25 #include <ardour/region.h>
26 #include <ardour/audioregion.h>
27 #include <ardour/audiosource.h>
28
29 #include "i18n.h"
30
31 using namespace ARDOUR;
32 using namespace PBD;
33
34 sigc::signal<void,boost::shared_ptr<Region> > RegionFactory::CheckNewRegion;
35
36 boost::shared_ptr<Region>
37 RegionFactory::create (boost::shared_ptr<Region> region, nframes_t start, 
38                        nframes_t length, const std::string& name, 
39                        layer_t layer, Region::Flag flags, bool announce)
40 {
41         boost::shared_ptr<const AudioRegion> other;
42
43         if ((other = boost::dynamic_pointer_cast<AudioRegion>(region)) != 0) {
44                 AudioRegion* ar = new AudioRegion (other, start, length, name, layer, flags);
45                 boost::shared_ptr<AudioRegion> arp (ar);
46                 boost::shared_ptr<Region> ret (boost::static_pointer_cast<Region> (arp));
47                 if (announce) {
48                         CheckNewRegion (ret);
49                 }
50                 return ret;
51         } else {
52                 fatal << _("programming error: RegionFactory::create() called with unknown Region type")
53                       << endmsg;
54                 /*NOTREACHED*/
55                 return boost::shared_ptr<Region>();
56         }
57 }
58
59 boost::shared_ptr<Region>
60 RegionFactory::create (boost::shared_ptr<const Region> region)
61 {
62         boost::shared_ptr<const AudioRegion> other;
63         
64         if ((other = boost::dynamic_pointer_cast<const AudioRegion>(region)) != 0) {
65                 boost::shared_ptr<Region> ret (new AudioRegion (other));
66                 /* pure copy constructor - no CheckNewRegion emitted */
67                 return ret;
68         } else {
69                 fatal << _("programming error: RegionFactory::create() called with unknown Region type")
70                       << endmsg;
71                 /*NOTREACHED*/
72                 return boost::shared_ptr<Region>();
73         }
74 }
75
76 boost::shared_ptr<Region>
77 RegionFactory::create (boost::shared_ptr<AudioRegion> region, nframes_t start, 
78                        nframes_t length, const std::string& name, 
79                        layer_t layer, Region::Flag flags, bool announce)
80 {
81         return create (boost::static_pointer_cast<Region> (region), start, length, name, layer, flags, announce);
82 }
83
84 boost::shared_ptr<Region>
85 RegionFactory::create (boost::shared_ptr<Region> region, const SourceList& srcs,
86                        const std::string& name, layer_t layer, Region::Flag flags, bool announce)
87
88 {
89         boost::shared_ptr<const AudioRegion> other;
90
91         /* used by AudioFilter when constructing a new region that is intended to have nearly
92            identical settings to an original, but using different sources.
93         */
94
95         if ((other = boost::dynamic_pointer_cast<AudioRegion>(region)) != 0) {
96                 AudioRegion* ar = new AudioRegion (other, srcs, srcs.front()->length(), name, layer, flags);
97                 boost::shared_ptr<AudioRegion> arp (ar);
98                 boost::shared_ptr<Region> ret (boost::static_pointer_cast<Region> (arp));
99                 if (announce) {
100                         CheckNewRegion (ret);
101                 }
102                 return ret;
103         } else {
104                 fatal << _("programming error: RegionFactory::create() called with unknown Region type")
105                       << endmsg;
106                 /*NOTREACHED*/
107                 return boost::shared_ptr<Region>();
108         }
109 }
110
111 boost::shared_ptr<Region>
112 RegionFactory::create (Session& session, XMLNode& node, bool yn)
113 {
114         boost::shared_ptr<Region> r = session.XMLRegionFactory (node, yn);
115
116         if (r) {
117                 CheckNewRegion (r);
118         }
119
120         return r;
121 }
122         
123 boost::shared_ptr<Region> 
124 RegionFactory::create (const SourceList& srcs, nframes_t start, nframes_t length, const string& name, layer_t layer, Region::Flag flags, bool announce)
125 {
126         boost::shared_ptr<AudioRegion> arp (new AudioRegion (srcs, start, length, name, layer, flags));
127         boost::shared_ptr<Region> ret (boost::static_pointer_cast<Region> (arp));
128         if (announce) {
129                 CheckNewRegion (ret);
130         }
131         return ret;
132 }       
133
134 boost::shared_ptr<Region> 
135 RegionFactory::create (SourceList& srcs, const XMLNode& node)
136 {
137         if (srcs.empty()) {
138                 return boost::shared_ptr<Region>();
139         }
140
141         boost::shared_ptr<Region> ret (new AudioRegion (srcs, node));
142         CheckNewRegion (ret);
143         return ret;
144 }
145
146 boost::shared_ptr<Region> 
147 RegionFactory::create (boost::shared_ptr<Source> src, nframes_t start, nframes_t length, const string& name, layer_t layer, Region::Flag flags, bool announce)
148 {
149         boost::shared_ptr<AudioSource> as;
150
151         if ((as = boost::dynamic_pointer_cast<AudioSource>(src)) != 0) {
152                 boost::shared_ptr<Region> ret (new AudioRegion (as, start, length, name, layer, flags));
153                 if (announce) {
154                         CheckNewRegion (ret);
155                 }
156                 return ret;
157         }
158
159         return boost::shared_ptr<Region>();
160 }