Move region naming stuff from Session into RegionFactory, cleaning up some vestiges...
[ardour.git] / libs / ardour / ardour / region_factory.h
1 /*
2     Copyright (C) 2000-2007 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 #ifndef __ardour_region_factory_h__
21 #define __ardour_region_factory_h__
22
23 #include <map>
24 #include <glibmm/thread.h>
25
26 #include "pbd/id.h"
27 #include "pbd/signals.h"
28
29 #include "ardour/types.h"
30 #include "ardour/region.h"
31
32 class XMLNode;
33
34 namespace ARDOUR {
35
36 class Session;
37 class AudioRegion;
38
39 class RegionFactory {
40
41   public:
42         typedef std::map<PBD::ID,boost::shared_ptr<Region> > RegionMap;
43
44         static boost::shared_ptr<Region> region_by_id (const PBD::ID&);
45         static const RegionMap all_regions() { return region_map; }
46         static void clear_map ();
47
48         /** This is emitted only when a new id is assigned. Therefore,
49            in a pure Region copy, it will not be emitted.
50
51            It must be emitted using a derived instance of Region, not Region
52            itself, to permit dynamic_cast<> to be used to
53            infer the type of Region.
54         */
55         static PBD::Signal1<void,boost::shared_ptr<Region> >  CheckNewRegion;
56
57         /** create a "pure copy" of Region @param other */
58         static boost::shared_ptr<Region> create (boost::shared_ptr<const Region> other);
59
60         /** create a region from a single Source */
61         static boost::shared_ptr<Region> create (boost::shared_ptr<Source>, 
62                                                  const PBD::PropertyList&, bool announce = true);
63         /** create a region from a multiple sources */
64         static boost::shared_ptr<Region> create (const SourceList &, 
65                                                  const PBD::PropertyList&, bool announce = true);
66         /** create a copy of @other starting at zero within @param other's sources */
67         static boost::shared_ptr<Region> create (boost::shared_ptr<Region> other, 
68                                                  const PBD::PropertyList&, bool announce = true);
69         /** create a copy of @other starting at @param offset within @param other */
70         static boost::shared_ptr<Region> create (boost::shared_ptr<Region>, frameoffset_t offset, 
71                                                  const PBD::PropertyList&, bool announce = true);
72         /** create a "copy" of @param other but using a different set of sources @param srcs */
73         static boost::shared_ptr<Region> create (boost::shared_ptr<Region> other, const SourceList& srcs, 
74                                                  const PBD::PropertyList&, bool announce = true);
75         
76         /** create a region with no sources, using XML state */
77         static boost::shared_ptr<Region> create (Session&, XMLNode&, bool);
78         /** create a region with specified sources @param srcs and XML state */
79         static boost::shared_ptr<Region> create (SourceList& srcs, const XMLNode&);
80
81         static void map_remove (boost::shared_ptr<Region>);
82         static void delete_all_regions ();
83         static const RegionMap& regions() { return region_map; }
84         static uint32_t nregions ();
85
86         static int region_name (std::string &, std::string, bool new_level = false);
87         static std::string new_region_name (std::string);
88   
89   private:
90
91         static boost::shared_ptr<Region> create (boost::shared_ptr<Region>, frameoffset_t offset,
92                                                  bool offset_relative,
93                                                  const PBD::PropertyList&, bool announce = true);
94
95         static void region_changed (PBD::PropertyChange const &, boost::weak_ptr<Region>);
96         
97         static Glib::StaticMutex region_map_lock;
98         
99         static RegionMap region_map;
100         static void map_add (boost::shared_ptr<Region>);
101
102         static Glib::StaticMutex region_name_map_lock;
103
104         static std::map<std::string, uint32_t> region_name_map;
105         static void update_region_name_map (boost::shared_ptr<Region>);
106
107         static PBD::ScopedConnectionList region_list_connections;
108 };
109
110 }
111
112 #endif /* __ardour_region_factory_h__  */