Ardour  8.12
location.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2006 Hans Fugal <hans@fugal.net>
4  * Copyright (C) 2008-2011 David Robillard <d@drobilla.net>
5  * Copyright (C) 2008 Sakari Bergen <sakari.bergen@beatwaves.net>
6  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
7  * Copyright (C) 2015-2016 Nick Mainsbridge <mainsbridge@gmail.com>
8  * Copyright (C) 2016-2019 Robin Gareus <robin@gareus.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24 
25 #ifndef __ardour_location_h__
26 #define __ardour_location_h__
27 
28 #include <string>
29 #include <list>
30 #include <iostream>
31 #include <map>
32 #include <vector>
33 
34 #include <sys/types.h>
35 
36 #include <glibmm/threads.h>
37 
38 #include "pbd/undo.h"
39 #include "pbd/stateful.h"
41 
43 #include "temporal/domain_swap.h"
44 #include "temporal/types.h"
45 
46 #include "ardour/ardour.h"
47 #include "ardour/scene_change.h"
48 #include "ardour/session_handle.h"
49 
50 namespace ARDOUR {
51 
52 class SceneChange;
53 
56 {
57 public:
58  enum Flags {
59  IsMark = 0x1,
60  IsAutoPunch = 0x2,
61  IsAutoLoop = 0x4,
62  IsHidden = 0x8,
63  IsCDMarker = 0x10,
64  IsRangeMarker = 0x20,
65  IsSessionRange = 0x40,
66  IsSkip = 0x80,
67  IsSkipping = 0x100, /* skipping is active (or not) */
68  IsClockOrigin = 0x200,
69  IsXrun = 0x400,
70  IsCueMarker = 0x800,
71  IsSection = 0x1000,
72  IsScene = 0x2000
73  };
74 
76  Location (Session &, Temporal::timepos_t const &, Temporal::timepos_t const &, const std::string &, Flags bits = Flags(0), int32_t cue_id = 0);
77  Location (Location const& other, bool no_signal);
78  Location (Session &, const XMLNode&);
79  Location* operator= (const Location& other);
80 
81  bool operator==(const Location& other);
82 
83  bool locked() const { return _locked; }
84  void lock ();
85  void unlock ();
86 
87  int64_t timestamp() const { return _timestamp; };
88  timepos_t start() const { return _start; }
89  timepos_t end() const { return _end; }
90  timecnt_t length() const { return _start.distance (_end); }
91 
92  samplepos_t start_sample() const { return _start.samples(); }
93  samplepos_t end_sample() const { return _end.samples(); }
94  samplecnt_t length_samples() const { return _end.samples() - _start.samples(); }
95 
96  int set_start (timepos_t const & s, bool force = false);
97  int set_end (timepos_t const & e, bool force = false);
98  int set (timepos_t const & start, timepos_t const & end);
99 
100  int move_to (timepos_t const & pos);
101 
102  const std::string& name() const { return _name; }
103  void set_name (const std::string &str);
104 
105  void set_auto_punch (bool yn, void *src);
106  void set_auto_loop (bool yn, void *src);
107  void set_hidden (bool yn, void *src);
108  void set_cd (bool yn, void *src);
109  void set_cue (bool yn, void *src);
110  void set_is_range_marker (bool yn, void* src);
111  void set_is_clock_origin (bool yn, void* src);
112  void set_skip (bool yn);
113  void set_skipping (bool yn);
114  void set_section (bool yn);
115 
116  bool is_auto_punch () const { return _flags & IsAutoPunch; }
117  bool is_auto_loop () const { return _flags & IsAutoLoop; }
118  bool is_mark () const { return _flags & IsMark; }
119  bool is_hidden () const { return _flags & IsHidden; }
120  bool is_cd_marker () const { return _flags & IsCDMarker; }
121  bool is_cue_marker () const { return _flags & IsCueMarker; }
122  bool is_session_range () const { return _flags & IsSessionRange; }
123  bool is_range_marker() const { return _flags & IsRangeMarker; }
124  bool is_skip() const { return _flags & IsSkip; }
125  bool is_clock_origin() const { return _flags & IsClockOrigin; }
126  bool is_skipping() const { return (_flags & IsSkip) && (_flags & IsSkipping); }
127  bool is_xrun() const { return _flags & IsXrun; }
128  bool is_section() const { return _flags & IsSection; }
129  bool is_scene() const { return (bool) _scene_change && _flags & IsScene; }
130  bool matches (Flags f) const { return _flags & f; }
131 
132  /* any range with start < end -- not a marker */
133  bool is_range() const { return _flags & (IsSessionRange | IsRangeMarker | IsAutoLoop | IsAutoPunch | IsCDMarker); }
134 
135  Flags flags () const { return _flags; }
136 
137  std::shared_ptr<SceneChange> scene_change() const { return _scene_change; }
138  void set_scene_change (std::shared_ptr<SceneChange>);
139 
140  int32_t cue_id() const { assert (is_cue_marker()); return _cue; }
141  void set_cue_id (int32_t);
142 
143  /* these are static signals for objects that want to listen to all
144  * locations at once.
145  */
146 
147  static PBD::Signal1<void,Location*> name_changed;
148  static PBD::Signal1<void,Location*> end_changed;
149  static PBD::Signal1<void,Location*> start_changed;
150  static PBD::Signal1<void,Location*> flags_changed;
151  static PBD::Signal1<void,Location*> lock_changed;
152  static PBD::Signal1<void,Location*> cue_change;
153  static PBD::Signal1<void,Location*> scene_changed;
154  static PBD::Signal1<void,Location*> time_domain_changed; /* unused */
155 
156  /* this is sent only when both start and end change at the same time */
157  static PBD::Signal1<void,Location*> changed;
158 
159  /* these are member signals for objects that care only about
160  * changes to this object
161  */
162 
163  PBD::Signal0<void> Changed;
164 
165  PBD::Signal0<void> NameChanged;
166  PBD::Signal0<void> EndChanged;
167  PBD::Signal0<void> StartChanged;
168  PBD::Signal0<void> FlagsChanged;
169  PBD::Signal0<void> LockChanged;
170  PBD::Signal0<void> CueChanged;
171  PBD::Signal0<void> SceneChanged; /* unused */
172  PBD::Signal0<void> TimeDomainChanged;
173 
174  /* CD Track / CD-Text info */
175 
176  std::map<std::string, std::string> cd_info;
177  static XMLNode& cd_info_node (const std::string &, const std::string &);
178 
179  XMLNode& get_state () const;
180  int set_state (const XMLNode&, int version);
181 
182  Temporal::TimeDomain position_time_domain() const { return _start.time_domain(); }
183 
184  /* Similar to, but not identical to the Temporal::TimeDomainSwapper API */
185 
188 
190 
192  public:
193  ChangeSuspender (Location* l) : _l (l) {
194  _l->suspend_signals ();
195  }
196  ChangeSuspender (ChangeSuspender const& other) : _l (other._l) {
197  _l->suspend_signals ();
198  }
200  _l->resume_signals ();
201  }
202  private:
204  };
205 
206 protected:
207  friend class ChangeSuspender;
209  void resume_signals ();
210 
211 private:
212  Location (Location const&); // no copy c'tor
213  void set_mark (bool yn);
214  bool set_flag_internal (bool yn, Flags flag);
215 
216  enum Signal {
226  };
227 
230 
231 
232  std::string _name;
236  bool _locked;
237  int64_t _timestamp;
238  int32_t _cue;
239 
241  std::set<Signal> _postponed_signals;
242 
243  std::shared_ptr<SceneChange> _scene_change;
244 
246 };
247 
250 {
251 public:
252  typedef std::list<Location *> LocationList;
253  typedef std::pair<Temporal::timepos_t, Location*> LocationPair;
254 
257 
258  const LocationList& list () const { return locations; }
259  LocationList list () { return locations; }
260 
261  void add (Location *, bool make_current = false);
262 
270  Location* add_range (timepos_t const & start, timepos_t const & end);
271 
272  void remove (Location *);
273  bool clear ();
274  bool clear_markers ();
276  bool clear_ranges ();
277 
280 
281  void cut_copy_section (timepos_t const& start, timepos_t const& end, timepos_t const& to, SectionOperation const op);
282 
283  void ripple (timepos_t const & at, timecnt_t const & distance, bool include_locked);
284 
285  XMLNode& get_state () const;
286  int set_state (const XMLNode&, int version);
288 
293 
294  int next_available_name(std::string& result,std::string base);
295  uint32_t num_range_markers() const;
296 
297  int set_current (Location *, bool want_lock = true);
298  Location *current () const { return current_location; }
299 
301 
302  void set_clock_origin (Location*, void *src);
303 
304  timepos_t first_mark_before_flagged (timepos_t const &, bool include_special_ranges = false, Location::Flags whitelist = Location::Flags (0), Location::Flags blacklist = Location::Flags (0), Location::Flags equalist = Location::Flags (0), Location** retval = nullptr);
305  timepos_t first_mark_after_flagged (timepos_t const &, bool include_special_ranges = false, Location::Flags whitelist = Location::Flags (0), Location::Flags blacklist = Location::Flags (0), Location::Flags equalist = Location::Flags (0), Location** retval = nullptr);
306 
307  timepos_t first_mark_after (timepos_t const & t, bool include_special_ranges = false) {
308  return first_mark_after_flagged (t, include_special_ranges);
309  }
310  timepos_t first_mark_before (timepos_t const & t, bool include_special_ranges = false) {
311  return first_mark_before_flagged (t, include_special_ranges);
312  }
313 
315  Location* next_section_iter (Location*, timepos_t&, timepos_t&, std::vector<LocationPair>& cache) const;
317 
318  void marks_either_side (timepos_t const &, timepos_t &, timepos_t &) const;
319 
328  Location* range_starts_at (timepos_t const & pos, timecnt_t const & slop = timecnt_t (Temporal::AudioTime), bool incl = false) const;
329 
331 
335 
337 
338  PBD::Signal1<void,Location*> current_changed;
339 
340  /* Objects that care about individual addition and removal of Locations should connect to added/removed.
341  * If an object additionally cares about potential mass clearance of Locations, they should connect to changed.
342  */
343 
344  PBD::Signal1<void,Location*> added;
345  PBD::Signal1<void,Location*> removed;
346  PBD::Signal0<void> changed; /* emitted when any action that could have added/removed more than 1 location actually removed 1 or more */
347 
348  template<class T> void apply (T& obj, void (T::*method)(const LocationList&)) const {
349  /* We don't want to hold the lock while the given method runs, so take a copy
350  * of the list and pass that instead.
351  */
353  {
354  Glib::Threads::RWLock::ReaderLock lm (_lock);
355  copy = locations;
356  }
357  (obj.*method)(copy);
358  }
359 
360 private:
361  void sorted_section_locations (std::vector<LocationPair>&) const;
362 
365  mutable Glib::Threads::RWLock _lock;
366 
370 };
371 
372 } // namespace ARDOUR
373 
374 #endif /* __ardour_location_h__ */
ChangeSuspender(ChangeSuspender const &other)
Definition: location.h:196
timepos_t _start
Definition: location.h:233
void emit_signal(Signal)
static PBD::Signal1< void, Location * > name_changed
Definition: location.h:147
void start_domain_bounce(Temporal::DomainBounceInfo &)
bool locked() const
Definition: location.h:83
void set_is_range_marker(bool yn, void *src)
XMLNode & get_state() const
bool is_skipping() const
Definition: location.h:126
const std::string & name() const
Definition: location.h:102
bool is_cue_marker() const
Definition: location.h:121
void set_name(const std::string &str)
void set_time_domain(Temporal::TimeDomain)
PBD::Signal0< void > Changed
Definition: location.h:163
int64_t timestamp() const
Definition: location.h:87
void set_scene_change(std::shared_ptr< SceneChange >)
void suspend_signals()
Location(Location const &other, bool no_signal)
void set_mark(bool yn)
static PBD::Signal1< void, Location * > start_changed
Definition: location.h:149
timecnt_t length() const
Definition: location.h:90
void actually_emit_signal(Signal)
std::string _name
Definition: location.h:232
static PBD::Signal1< void, Location * > time_domain_changed
Definition: location.h:154
void set_cue(bool yn, void *src)
bool is_mark() const
Definition: location.h:118
void set_skip(bool yn)
int move_to(timepos_t const &pos)
PBD::Signal0< void > NameChanged
Definition: location.h:165
void set_cd(bool yn, void *src)
bool operator==(const Location &other)
Location(Location const &)
bool is_session_range() const
Definition: location.h:122
void set_auto_punch(bool yn, void *src)
static PBD::Signal1< void, Location * > flags_changed
Definition: location.h:150
bool set_flag_internal(bool yn, Flags flag)
samplepos_t end_sample() const
Definition: location.h:93
std::shared_ptr< SceneChange > _scene_change
Definition: location.h:243
Location(Session &, Temporal::timepos_t const &, Temporal::timepos_t const &, const std::string &, Flags bits=Flags(0), int32_t cue_id=0)
PBD::Signal0< void > CueChanged
Definition: location.h:170
int32_t cue_id() const
Definition: location.h:140
std::shared_ptr< SceneChange > scene_change() const
Definition: location.h:137
void finish_domain_bounce(Temporal::DomainBounceInfo &)
bool is_auto_loop() const
Definition: location.h:117
Location(Session &)
void set_hidden(bool yn, void *src)
Location(Session &, const XMLNode &)
static PBD::Signal1< void, Location * > changed
Definition: location.h:157
samplecnt_t length_samples() const
Definition: location.h:94
bool is_cd_marker() const
Definition: location.h:120
samplepos_t start_sample() const
Definition: location.h:92
bool is_xrun() const
Definition: location.h:127
bool is_range_marker() const
Definition: location.h:123
bool is_skip() const
Definition: location.h:124
Flags flags() const
Definition: location.h:135
PBD::Signal0< void > LockChanged
Definition: location.h:169
int set_end(timepos_t const &e, bool force=false)
Temporal::TimeDomain position_time_domain() const
Definition: location.h:182
int64_t _timestamp
Definition: location.h:237
bool is_range() const
Definition: location.h:133
std::map< std::string, std::string > cd_info
Definition: location.h:176
int32_t _cue
Definition: location.h:238
timepos_t end() const
Definition: location.h:89
std::set< Signal > _postponed_signals
Definition: location.h:241
bool is_auto_punch() const
Definition: location.h:116
PBD::Signal0< void > EndChanged
Definition: location.h:166
static PBD::Signal1< void, Location * > end_changed
Definition: location.h:148
bool is_clock_origin() const
Definition: location.h:125
int set_state(const XMLNode &, int version)
void set_skipping(bool yn)
PBD::Signal0< void > StartChanged
Definition: location.h:167
uint32_t _signals_suspended
Definition: location.h:240
static PBD::Signal1< void, Location * > lock_changed
Definition: location.h:151
timepos_t start() const
Definition: location.h:88
static PBD::Signal1< void, Location * > scene_changed
Definition: location.h:153
int set(timepos_t const &start, timepos_t const &end)
void set_cue_id(int32_t)
void set_section(bool yn)
PBD::Signal0< void > SceneChanged
Definition: location.h:171
bool is_section() const
Definition: location.h:128
void set_position_time_domain(Temporal::TimeDomain)
void set_is_clock_origin(bool yn, void *src)
bool matches(Flags f) const
Definition: location.h:130
int set_start(timepos_t const &s, bool force=false)
timepos_t _end
Definition: location.h:234
static XMLNode & cd_info_node(const std::string &, const std::string &)
PBD::Signal0< void > TimeDomainChanged
Definition: location.h:172
PBD::Signal0< void > FlagsChanged
Definition: location.h:168
bool is_hidden() const
Definition: location.h:119
static PBD::Signal1< void, Location * > cue_change
Definition: location.h:152
void set_auto_loop(bool yn, void *src)
bool is_scene() const
Definition: location.h:129
void time_domain_changed()
Location * add_range(timepos_t const &start, timepos_t const &end)
Location * range_starts_at(timepos_t const &pos, timecnt_t const &slop=timecnt_t(Temporal::AudioTime), bool incl=false) const
PBD::Signal1< void, Location * > added
Definition: location.h:344
PBD::Signal0< void > changed
Definition: location.h:346
std::pair< Temporal::timepos_t, Location * > LocationPair
Definition: location.h:253
int set_state(const XMLNode &, int version)
Location * current() const
Definition: location.h:298
timepos_t first_mark_after_flagged(timepos_t const &, bool include_special_ranges=false, Location::Flags whitelist=Location::Flags(0), Location::Flags blacklist=Location::Flags(0), Location::Flags equalist=Location::Flags(0), Location **retval=nullptr)
void listen_to(Location *)
LocationList locations
Definition: location.h:363
int next_available_name(std::string &result, std::string base)
Location * auto_loop_location() const
void start_domain_bounce(Temporal::DomainBounceInfo &)
XMLNode & get_state() const
const LocationList & list() const
Definition: location.h:258
LocationList list()
Definition: location.h:259
void finish_domain_bounce(Temporal::DomainBounceInfo &)
Location * next_section(Location *, timepos_t &, timepos_t &) const
void cut_copy_section(timepos_t const &start, timepos_t const &end, timepos_t const &to, SectionOperation const op)
timepos_t first_mark_before_flagged(timepos_t const &, bool include_special_ranges=false, Location::Flags whitelist=Location::Flags(0), Location::Flags blacklist=Location::Flags(0), Location::Flags equalist=Location::Flags(0), Location **retval=nullptr)
timepos_t first_mark_after(timepos_t const &t, bool include_special_ranges=false)
Definition: location.h:307
uint32_t num_range_markers() const
PBD::Signal1< void, Location * > removed
Definition: location.h:345
Location * get_location_by_id(PBD::ID)
void set_time_domain(Temporal::TimeDomain)
void find_all_between(timepos_t const &start, timepos_t const &end, LocationList &, Location::Flags)
int set_current(Location *, bool want_lock=true)
Location * section_at(timepos_t const &, timepos_t &, timepos_t &) const
Location * clock_origin_location() const
void ripple(timepos_t const &at, timecnt_t const &distance, bool include_locked)
Location * current_location
Definition: location.h:364
Location * next_section_iter(Location *, timepos_t &, timepos_t &, std::vector< LocationPair > &cache) const
Locations(Session &)
Glib::Threads::RWLock _lock
Definition: location.h:365
int set_current_unlocked(Location *)
void location_changed(Location *)
timepos_t first_mark_before(timepos_t const &t, bool include_special_ranges=false)
Definition: location.h:310
void remove(Location *)
void marks_either_side(timepos_t const &, timepos_t &, timepos_t &) const
bool clear_cue_markers(samplepos_t start, samplepos_t end)
void set_clock_origin(Location *, void *src)
void apply(T &obj, void(T::*method)(const LocationList &)) const
Definition: location.h:348
bool clear_xrun_markers()
std::list< Location * > LocationList
Definition: location.h:252
Location * auto_punch_location() const
bool clear_scene_markers(samplepos_t start, samplepos_t end)
PBD::Signal1< void, Location * > current_changed
Definition: location.h:338
Location * mark_at(timepos_t const &, timecnt_t const &slop=timecnt_t::zero(Temporal::AudioTime), Location::Flags flags=Location::Flags(0)) const
void add(Location *, bool make_current=false)
void sorted_section_locations(std::vector< LocationPair > &) const
Location * session_range_location() const
Definition: id.h:35
static timecnt_t zero(TimeDomain td)
Definition: timeline.h:326
int62_t const & distance() const
Definition: timeline.h:341
Definition: xml++.h:114
#define LIBARDOUR_API
PBD::PropertyDescriptor< timepos_t > start
Temporal::samplecnt_t samplecnt_t
Temporal::samplepos_t samplepos_t
const guchar * bits
Definition: xcursors.h:1