Ardour  9.0-pre0-350-gf17a656217
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 #pragma once
26 
27 #include <string>
28 #include <list>
29 #include <iostream>
30 #include <map>
31 #include <vector>
32 
33 #include <sys/types.h>
34 
35 #include <glibmm/threads.h>
36 
37 #include "pbd/undo.h"
38 #include "pbd/stateful.h"
40 
42 #include "temporal/domain_swap.h"
43 #include "temporal/types.h"
44 
45 #include "ardour/ardour.h"
46 #include "ardour/scene_change.h"
47 #include "ardour/session_handle.h"
48 
49 namespace ARDOUR {
50 
51 class SceneChange;
52 
55 {
56 public:
57  enum Flags {
58  IsMark = 0x1,
59  IsAutoPunch = 0x2,
60  IsAutoLoop = 0x4,
61  IsHidden = 0x8,
62  IsCDMarker = 0x10,
63  IsRangeMarker = 0x20,
64  IsSessionRange = 0x40,
65  IsSkip = 0x80,
66  IsSkipping = 0x100, /* skipping is active (or not) */
67  IsClockOrigin = 0x200,
68  IsXrun = 0x400,
69  IsCueMarker = 0x800,
70  IsSection = 0x1000,
71  IsScene = 0x2000
72  };
73 
75  Location (Session &, Temporal::timepos_t const &, Temporal::timepos_t const &, const std::string &, Flags bits = Flags(0), int32_t cue_id = 0);
76  Location (Location const& other, bool no_signal);
77  Location (Session &, const XMLNode&);
78  Location* operator= (const Location& other);
79 
80  bool operator==(const Location& other);
81 
82  bool locked() const { return _locked; }
83  void lock ();
84  void unlock ();
85 
86  int64_t timestamp() const { return _timestamp; };
87  timepos_t start() const { return _start; }
88  timepos_t end() const { return _end; }
89  timecnt_t length() const { return _start.distance (_end); }
90 
91  samplepos_t start_sample() const { return _start.samples(); }
92  samplepos_t end_sample() const { return _end.samples(); }
93  samplecnt_t length_samples() const { return _end.samples() - _start.samples(); }
94 
95  int set_start (timepos_t const & s, bool force = false);
96  int set_end (timepos_t const & e, bool force = false);
97  int set (timepos_t const & start, timepos_t const & end);
98 
99  int move_to (timepos_t const & pos);
100 
101  const std::string& name() const { return _name; }
102  void set_name (const std::string &str);
103 
104  void set_auto_punch (bool yn, void *src);
105  void set_auto_loop (bool yn, void *src);
106  void set_hidden (bool yn, void *src);
107  void set_cd (bool yn, void *src);
108  void set_cue (bool yn, void *src);
109  void set_is_range_marker (bool yn, void* src);
110  void set_is_clock_origin (bool yn, void* src);
111  void set_skip (bool yn);
112  void set_skipping (bool yn);
113  void set_section (bool yn);
114 
115  bool is_auto_punch () const { return _flags & IsAutoPunch; }
116  bool is_auto_loop () const { return _flags & IsAutoLoop; }
117  bool is_mark () const { return _flags & IsMark; }
118  bool is_hidden () const { return _flags & IsHidden; }
119  bool is_cd_marker () const { return _flags & IsCDMarker; }
120  bool is_cue_marker () const { return _flags & IsCueMarker; }
121  bool is_session_range () const { return _flags & IsSessionRange; }
122  bool is_range_marker() const { return _flags & IsRangeMarker; }
123  bool is_skip() const { return _flags & IsSkip; }
124  bool is_clock_origin() const { return _flags & IsClockOrigin; }
125  bool is_skipping() const { return (_flags & IsSkip) && (_flags & IsSkipping); }
126  bool is_xrun() const { return _flags & IsXrun; }
127  bool is_section() const { return _flags & IsSection; }
128  bool is_scene() const { return (bool) _scene_change && _flags & IsScene; }
129  bool matches (Flags f) const { return _flags & f; }
130 
131  /* any range with start < end -- not a marker */
132  bool is_range() const { return _flags & (IsSessionRange | IsRangeMarker | IsAutoLoop | IsAutoPunch | IsCDMarker); }
133 
134  Flags flags () const { return _flags; }
135 
136  std::shared_ptr<SceneChange> scene_change() const { return _scene_change; }
137  void set_scene_change (std::shared_ptr<SceneChange>);
138 
139  int32_t cue_id() const { assert (is_cue_marker()); return _cue; }
140  void set_cue_id (int32_t);
141 
142  /* these are static signals for objects that want to listen to all
143  * locations at once.
144  */
145 
153  static PBD::Signal<void(Location*)> time_domain_changed; /* unused */
154 
155  /* this is sent only when both start and end change at the same time */
156  static PBD::Signal<void(Location*)> changed;
157 
158  /* these are member signals for objects that care only about
159  * changes to this object
160  */
161 
163 
170  PBD::Signal<void()> SceneChanged; /* unused */
172 
173  /* CD Track / CD-Text info */
174 
175  std::map<std::string, std::string> cd_info;
176  static XMLNode& cd_info_node (const std::string &, const std::string &);
177 
178  XMLNode& get_state () const;
179  int set_state (const XMLNode&, int version);
180 
181  Temporal::TimeDomain position_time_domain() const { return _start.time_domain(); }
182 
183  /* Similar to, but not identical to the Temporal::TimeDomainSwapper API */
184 
187 
189 
191  public:
192  ChangeSuspender (Location* l) : _l (l) {
193  _l->suspend_signals ();
194  }
195  ChangeSuspender (ChangeSuspender const& other) : _l (other._l) {
196  _l->suspend_signals ();
197  }
199  _l->resume_signals ();
200  }
201  private:
203  };
204 
205 protected:
206  friend class ChangeSuspender;
208  void resume_signals ();
209 
210 private:
211  Location (Location const&); // no copy c'tor
212  void set_mark (bool yn);
213  bool set_flag_internal (bool yn, Flags flag);
214 
215  enum Signal {
225  };
226 
229 
230 
231  std::string _name;
235  bool _locked;
236  int64_t _timestamp;
237  int32_t _cue;
238 
240  std::set<Signal> _postponed_signals;
241 
242  std::shared_ptr<SceneChange> _scene_change;
243 
245 };
246 
249 {
250 public:
251  typedef std::list<Location *> LocationList;
252  typedef std::pair<Temporal::timepos_t, Location*> LocationPair;
253 
256 
257  const LocationList& list () const { return locations; }
258  LocationList list () { return locations; }
259 
260  void add (Location *, bool make_current = false);
261 
269  Location* add_range (timepos_t const & start, timepos_t const & end);
270 
271  void remove (Location *);
272  bool clear ();
273  bool clear_markers ();
275  bool clear_ranges ();
276 
279 
280  void cut_copy_section (timepos_t const& start, timepos_t const& end, timepos_t const& to, SectionOperation const op);
281 
282  void ripple (timepos_t const & at, timecnt_t const & distance, bool include_locked);
283 
284  XMLNode& get_state () const;
285  int set_state (const XMLNode&, int version);
287 
292 
293  int next_available_name(std::string& result,std::string base);
294  uint32_t num_range_markers() const;
295 
296  int set_current (Location *, bool want_lock = true);
297  Location *current () const { return current_location; }
298 
300 
301  void set_clock_origin (Location*, void *src);
302 
303  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);
304  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);
305 
306  timepos_t first_mark_after (timepos_t const & t, bool include_special_ranges = false) {
307  return first_mark_after_flagged (t, include_special_ranges);
308  }
309  timepos_t first_mark_before (timepos_t const & t, bool include_special_ranges = false) {
310  return first_mark_before_flagged (t, include_special_ranges);
311  }
312 
314  Location* next_section_iter (Location*, timepos_t&, timepos_t&, std::vector<LocationPair>& cache) const;
316 
317  void marks_either_side (timepos_t const &, timepos_t &, timepos_t &) const;
318 
327  Location* range_starts_at (timepos_t const & pos, timecnt_t const & slop = timecnt_t (Temporal::AudioTime), bool incl = false) const;
328 
330 
334 
336 
338 
339  /* Objects that care about individual addition and removal of Locations should connect to added/removed.
340  * If an object additionally cares about potential mass clearance of Locations, they should connect to changed.
341  */
342 
345  PBD::Signal<void()> changed; /* emitted when any action that could have added/removed more than 1 location actually removed 1 or more */
346 
347  template<class T> void apply (T& obj, void (T::*method)(const LocationList&)) const {
348  /* We don't want to hold the lock while the given method runs, so take a copy
349  * of the list and pass that instead.
350  */
352  {
353  Glib::Threads::RWLock::ReaderLock lm (_lock);
354  copy = locations;
355  }
356  (obj.*method)(copy);
357  }
358 
359 private:
360  void sorted_section_locations (std::vector<LocationPair>&) const;
361 
364  mutable Glib::Threads::RWLock _lock;
365 
369 };
370 
371 } // namespace ARDOUR
372 
ChangeSuspender(ChangeSuspender const &other)
Definition: location.h:195
timepos_t _start
Definition: location.h:232
void emit_signal(Signal)
void start_domain_bounce(Temporal::DomainBounceInfo &)
bool locked() const
Definition: location.h:82
void set_is_range_marker(bool yn, void *src)
XMLNode & get_state() const
static PBD::Signal< void(Location *)> time_domain_changed
Definition: location.h:153
bool is_skipping() const
Definition: location.h:125
const std::string & name() const
Definition: location.h:101
bool is_cue_marker() const
Definition: location.h:120
void set_name(const std::string &str)
void set_time_domain(Temporal::TimeDomain)
int64_t timestamp() const
Definition: location.h:86
void set_scene_change(std::shared_ptr< SceneChange >)
void suspend_signals()
Location(Location const &other, bool no_signal)
void set_mark(bool yn)
timecnt_t length() const
Definition: location.h:89
void actually_emit_signal(Signal)
std::string _name
Definition: location.h:231
void set_cue(bool yn, void *src)
bool is_mark() const
Definition: location.h:117
void set_skip(bool yn)
PBD::Signal< void()> CueChanged
Definition: location.h:169
int move_to(timepos_t const &pos)
void set_cd(bool yn, void *src)
bool operator==(const Location &other)
Location(Location const &)
bool is_session_range() const
Definition: location.h:121
static PBD::Signal< void(Location *)> cue_change
Definition: location.h:151
void set_auto_punch(bool yn, void *src)
PBD::Signal< void()> SceneChanged
Definition: location.h:170
PBD::Signal< void()> NameChanged
Definition: location.h:164
static PBD::Signal< void(Location *)> start_changed
Definition: location.h:148
bool set_flag_internal(bool yn, Flags flag)
PBD::Signal< void()> FlagsChanged
Definition: location.h:167
samplepos_t end_sample() const
Definition: location.h:92
std::shared_ptr< SceneChange > _scene_change
Definition: location.h:242
Location(Session &, Temporal::timepos_t const &, Temporal::timepos_t const &, const std::string &, Flags bits=Flags(0), int32_t cue_id=0)
int32_t cue_id() const
Definition: location.h:139
static PBD::Signal< void(Location *)> flags_changed
Definition: location.h:149
std::shared_ptr< SceneChange > scene_change() const
Definition: location.h:136
static PBD::Signal< void(Location *)> changed
Definition: location.h:156
void finish_domain_bounce(Temporal::DomainBounceInfo &)
bool is_auto_loop() const
Definition: location.h:116
static PBD::Signal< void(Location *)> name_changed
Definition: location.h:146
Location(Session &)
void set_hidden(bool yn, void *src)
Location(Session &, const XMLNode &)
samplecnt_t length_samples() const
Definition: location.h:93
bool is_cd_marker() const
Definition: location.h:119
samplepos_t start_sample() const
Definition: location.h:91
bool is_xrun() const
Definition: location.h:126
bool is_range_marker() const
Definition: location.h:122
static PBD::Signal< void(Location *)> lock_changed
Definition: location.h:150
bool is_skip() const
Definition: location.h:123
Flags flags() const
Definition: location.h:134
int set_end(timepos_t const &e, bool force=false)
Temporal::TimeDomain position_time_domain() const
Definition: location.h:181
int64_t _timestamp
Definition: location.h:236
bool is_range() const
Definition: location.h:132
PBD::Signal< void()> LockChanged
Definition: location.h:168
std::map< std::string, std::string > cd_info
Definition: location.h:175
int32_t _cue
Definition: location.h:237
timepos_t end() const
Definition: location.h:88
std::set< Signal > _postponed_signals
Definition: location.h:240
bool is_auto_punch() const
Definition: location.h:115
bool is_clock_origin() const
Definition: location.h:124
int set_state(const XMLNode &, int version)
void set_skipping(bool yn)
uint32_t _signals_suspended
Definition: location.h:239
timepos_t start() const
Definition: location.h:87
static PBD::Signal< void(Location *)> scene_changed
Definition: location.h:152
int set(timepos_t const &start, timepos_t const &end)
void set_cue_id(int32_t)
void set_section(bool yn)
PBD::Signal< void()> TimeDomainChanged
Definition: location.h:171
static PBD::Signal< void(Location *)> end_changed
Definition: location.h:147
PBD::Signal< void()> Changed
Definition: location.h:162
bool is_section() const
Definition: location.h:127
PBD::Signal< void()> StartChanged
Definition: location.h:166
void set_position_time_domain(Temporal::TimeDomain)
void set_is_clock_origin(bool yn, void *src)
bool matches(Flags f) const
Definition: location.h:129
int set_start(timepos_t const &s, bool force=false)
timepos_t _end
Definition: location.h:233
static XMLNode & cd_info_node(const std::string &, const std::string &)
PBD::Signal< void()> EndChanged
Definition: location.h:165
bool is_hidden() const
Definition: location.h:118
void set_auto_loop(bool yn, void *src)
bool is_scene() const
Definition: location.h:128
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::Signal< void(Location *)> current_changed
Definition: location.h:337
std::pair< Temporal::timepos_t, Location * > LocationPair
Definition: location.h:252
int set_state(const XMLNode &, int version)
Location * current() const
Definition: location.h:297
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:362
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:257
LocationList list()
Definition: location.h:258
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:306
uint32_t num_range_markers() const
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:363
PBD::Signal< void(Location *)> added
Definition: location.h:343
Location * next_section_iter(Location *, timepos_t &, timepos_t &, std::vector< LocationPair > &cache) const
Locations(Session &)
Glib::Threads::RWLock _lock
Definition: location.h:364
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:309
void remove(Location *)
PBD::Signal< void(Location *)> removed
Definition: location.h:344
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:347
bool clear_xrun_markers()
std::list< Location * > LocationList
Definition: location.h:251
Location * auto_punch_location() const
bool clear_scene_markers(samplepos_t start, samplepos_t end)
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
PBD::Signal< void()> changed
Definition: location.h:345
Definition: id.h:34
static timecnt_t zero(TimeDomain td)
Definition: timeline.h:325
int62_t const & distance() const
Definition: timeline.h:340
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