Ardour  9.0-pre0-582-g084a23a80d
region_factory.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2000-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2006-2012 David Robillard <d@drobilla.net>
4  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
6  * Copyright (C) 2016-2017 Nick Mainsbridge <mainsbridge@gmail.com>
7  * Copyright (C) 2018-2019 Ben Loftis <ben@harrisonconsoles.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #pragma once
25 
26 #include <glibmm/threads.h>
27 #include <map>
28 #include <set>
29 
30 #include "pbd/id.h"
31 #include "pbd/property_list.h"
32 #include "pbd/signals.h"
33 
35 #include "ardour/types.h"
36 
37 class XMLNode;
38 class RegionNamingTest;
39 
40 namespace ARDOUR {
41 
42 class AudioRegion;
43 class Session;
44 class ThawList;
45 
47 {
48 public:
49  typedef std::map<PBD::ID, std::shared_ptr<Region> > RegionMap;
50 
51  static std::shared_ptr<Region> wholefile_region_by_name (const std::string& name);
52  static std::shared_ptr<Region> region_by_id (const PBD::ID&);
53  static std::shared_ptr<Region> region_by_name (const std::string& name);
54  static void clear_map ();
55  static const RegionMap all_regions ()
56  {
57  return region_map;
58  }
59 
67  static PBD::Signal<void(std::shared_ptr<Region> )> CheckNewRegion;
68 
70  static std::shared_ptr<Region> create (std::shared_ptr<const Region> other, bool announce, bool fork = false, ThawList* tl = 0);
71 
73  static std::shared_ptr<Region> create (std::shared_ptr<Region> other, bool announce, bool fork)
74  {
75  return create (std::shared_ptr<const Region> (other), announce, fork, 0);
76  }
77 
79  static std::shared_ptr<Region> create (std::shared_ptr<Source>, const PBD::PropertyList&, bool announce = true, ThawList* tl = 0);
81  static std::shared_ptr<Region> create (const SourceList&, const PBD::PropertyList&, bool announce = true, ThawList* tl = 0);
83  static std::shared_ptr<Region> create (std::shared_ptr<Region> other, const PBD::PropertyList&, bool announce = true, ThawList* tl = 0);
85  static std::shared_ptr<Region> create (std::shared_ptr<Region> other, timecnt_t const & offset, const PBD::PropertyList&, bool announce = true, ThawList* tl = 0);
87  static std::shared_ptr<Region> create (std::shared_ptr<Region> other, const SourceList& srcs, const PBD::PropertyList&, bool announce = true, ThawList* tl = 0);
88 
90  static std::shared_ptr<Region> create (Session&, XMLNode&, bool);
92  static std::shared_ptr<Region> create (SourceList& srcs, const XMLNode&);
93 
94  static std::shared_ptr<Region> get_whole_region_for_source (std::shared_ptr<ARDOUR::Source>);
95 
96  static void get_regions_using_source (std::shared_ptr<Source>, std::set<std::shared_ptr<Region> >&);
97  static void remove_regions_using_source (std::shared_ptr<Source>);
98 
99  static void map_remove (std::weak_ptr<Region>);
100  static void delete_all_regions ();
101 
102  static const RegionMap& regions ()
103  {
104  return region_map;
105  }
106 
107  static uint32_t nregions ();
108 
109  static void foreach_region (std::function<void (std::shared_ptr<Region>)> f)
110  {
111  Glib::Threads::Mutex::Lock ls (region_map_lock);
112  for (RegionMap::const_iterator i = region_map.begin (); i != region_map.end (); ++i) {
113  f ((*i).second);
114  }
115  }
116 
117  static int region_name (std::string&, std::string, bool new_level = false);
118  static std::string new_region_name (std::string);
119  static std::string compound_region_name (const std::string& playlist, uint32_t compound_ops, uint32_t depth, bool whole_source);
120 
121  /* when we make a compound region, for every region involved there
122  * are two "instances" - the original, which is removed from this
123  * playlist, and a copy, which is added to the playlist used as
124  * the source for the compound.
125  *
126  * when we uncombine, we want to put the originals back into this
127  * playlist after we remove the compound. this map lets us
128  * look them up easily. note that if the compound was trimmed or
129  * split, we may have to trim the originals
130  * and they may not be added back if the compound was trimmed
131  * or split sufficiently.
132  */
133 
134  typedef std::map<std::shared_ptr<Region>, std::shared_ptr<Region> > CompoundAssociations;
135 
137  {
138  return _compound_associations;
139  }
140 
141  static void add_compound_association (std::shared_ptr<Region>, std::shared_ptr<Region>);
142 
143  /* exposed because there may be cases where regions are created with
144  * announce=false but they still need to be in the map soon after
145  * creation.
146  */
147 
148  static void map_add (std::shared_ptr<Region>);
149 
150 private:
151  friend class ::RegionNamingTest;
152 
153  static void region_changed (PBD::PropertyChange const&, std::weak_ptr<Region>);
154  static void add_to_region_name_maps (std::shared_ptr<Region>);
155  static void rename_in_region_name_maps (std::shared_ptr<Region>);
156  static void update_region_name_number_map (std::shared_ptr<Region>);
157  static void remove_from_region_name_map (std::string);
158 
159  static Glib::Threads::Mutex region_map_lock;
161 
162  static Glib::Threads::Mutex region_name_maps_mutex;
164  static std::map<std::string, uint32_t> region_name_number_map;
166  static std::map<std::string, PBD::ID> region_name_map;
167 
170 };
171 
172 } // namespace ARDOUR
173 
static uint32_t nregions()
static std::shared_ptr< Region > create(Session &, XMLNode &, bool)
static std::shared_ptr< Region > wholefile_region_by_name(const std::string &name)
static void add_to_region_name_maps(std::shared_ptr< Region >)
static std::shared_ptr< Region > create(std::shared_ptr< Region > other, const SourceList &srcs, const PBD::PropertyList &, bool announce=true, ThawList *tl=0)
static CompoundAssociations _compound_associations
static RegionMap region_map
static std::shared_ptr< Region > get_whole_region_for_source(std::shared_ptr< ARDOUR::Source >)
static const RegionMap & regions()
static std::map< std::string, PBD::ID > region_name_map
static std::shared_ptr< Region > create(std::shared_ptr< Source >, const PBD::PropertyList &, bool announce=true, ThawList *tl=0)
static CompoundAssociations & compound_associations()
static std::map< std::string, uint32_t > region_name_number_map
static std::shared_ptr< Region > create(SourceList &srcs, const XMLNode &)
static Glib::Threads::Mutex region_map_lock
static PBD::Signal< void(std::shared_ptr< Region >)> CheckNewRegion
static std::string compound_region_name(const std::string &playlist, uint32_t compound_ops, uint32_t depth, bool whole_source)
static std::string new_region_name(std::string)
std::map< std::shared_ptr< Region >, std::shared_ptr< Region > > CompoundAssociations
static void delete_all_regions()
static std::shared_ptr< Region > create(std::shared_ptr< Region > other, const PBD::PropertyList &, bool announce=true, ThawList *tl=0)
static std::shared_ptr< Region > region_by_id(const PBD::ID &)
std::map< PBD::ID, std::shared_ptr< Region > > RegionMap
static void region_changed(PBD::PropertyChange const &, std::weak_ptr< Region >)
static std::shared_ptr< Region > create(const SourceList &, const PBD::PropertyList &, bool announce=true, ThawList *tl=0)
static const RegionMap all_regions()
static void rename_in_region_name_maps(std::shared_ptr< Region >)
static int region_name(std::string &, std::string, bool new_level=false)
static void map_add(std::shared_ptr< Region >)
static void remove_regions_using_source(std::shared_ptr< Source >)
static std::shared_ptr< Region > create(std::shared_ptr< Region > other, bool announce, bool fork)
static Glib::Threads::Mutex region_name_maps_mutex
static void get_regions_using_source(std::shared_ptr< Source >, std::set< std::shared_ptr< Region > > &)
static void remove_from_region_name_map(std::string)
static std::shared_ptr< Region > create(std::shared_ptr< Region > other, timecnt_t const &offset, const PBD::PropertyList &, bool announce=true, ThawList *tl=0)
static PBD::ScopedConnectionList * region_list_connections
static std::shared_ptr< Region > create(std::shared_ptr< const Region > other, bool announce, bool fork=false, ThawList *tl=0)
static void clear_map()
static void map_remove(std::weak_ptr< Region >)
static void add_compound_association(std::shared_ptr< Region >, std::shared_ptr< Region >)
static std::shared_ptr< Region > region_by_name(const std::string &name)
static void update_region_name_number_map(std::shared_ptr< Region >)
static void foreach_region(std::function< void(std::shared_ptr< Region >)> f)
Definition: id.h:34
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
std::vector< std::shared_ptr< Source > > SourceList