Ardour  9.2-541-gc1841a13dd
ardour/ardour/source.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2014 David Robillard <d@drobilla.net>
3  * Copyright (C) 2006-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2016-2019 Robin Gareus <robin@gareus.org>
6  * Copyright (C) 2018-2019 Ben Loftis <ben@harrisonconsoles.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #pragma once
24 
25 #include <atomic>
26 #include <memory>
27 #include <string>
28 
29 #include "pbd/mutex.h"
30 #include "pbd/rwlock.h"
32 
33 #include "ardour/ardour.h"
34 #include "ardour/scale_provider.h"
35 #include "ardour/session_object.h"
36 #include "ardour/data_type.h"
38 
39 namespace ARDOUR {
40 
41 class Session;
42 
44  public std::enable_shared_from_this<ARDOUR::Source>,
45  public ScaleProvider
46 {
47 public:
48  enum Flag {
49  Writable = 0x1,
50  CanRename = 0x2,
51  Broadcast = 0x4,
52  Removable = 0x8,
53  RemovableIfEmpty = 0x10,
54  RemoveAtDestroy = 0x20,
55  NoPeakFile = 0x40,
56  /* No longer in use but kept to allow loading of older sessions */
57  Destructive = 0x80,
58  Empty = 0x100, /* used for MIDI only */
59  RF64_RIFF = 0x200,
60  Missing = 0x400, /* used for MIDI only */
61  };
62 
65 
66  Source (Session&, DataType type, const std::string& name, Flag flags=Flag(0));
67  Source (Session&, const XMLNode&);
68 
69  virtual ~Source ();
70 
71  DataType type() { return _type; }
72 
73  time_t timestamp() const { return _timestamp; }
74  void stamp (time_t when) { _timestamp = when; }
75 
76  virtual timepos_t length() const { return _length; }
77 
78  virtual bool empty () const;
79  virtual void update_length (timepos_t const & dur) {}
80 
81  void set_take_id (std::string id) { _take_id =id; }
82  const std::string& take_id () const { return _take_id; }
83 
85 
86  virtual void mark_streaming_write_started (const WriterLock& lock) {}
87  /* The duration argument is ignored for audio data, where length is
88  implicitly given by the sample data. It matters for MIDI data, where
89  the file may be intended to be N bars long, but has no events that
90  occur at that duration.
91  */
92  virtual void mark_streaming_write_completed (const WriterLock& lock, Temporal::timecnt_t const & duration) = 0;
93 
94  virtual void session_saved() {}
95 
96  XMLNode& get_state () const;
97  int set_state (XMLNode const &, int version);
98 
99  bool writable () const;
100 
101  virtual bool length_mutable() const { return false; }
102 
104 
105  bool has_been_analysed() const;
106  virtual bool can_be_analysed() const { return false; }
107  virtual void set_been_analysed (bool yn);
109 
111 
113  std::string get_transients_path() const;
114  int load_transients (const std::string&);
115 
116  size_t n_captured_xruns () const { return _xruns.size (); }
117  XrunPositions const& captured_xruns () const { return _xruns; }
118  void set_captured_xruns (XrunPositions const& xruns) { _xruns = xruns; }
119  void set_captured_marks (CueMarkers const& marks);
120 
121  CueMarkers const & cue_markers() const { return _cue_markers; }
122  bool add_cue_marker (CueMarker const &);
123  bool move_cue_marker (CueMarker const &, timepos_t const & source_relative_position);
124  bool remove_cue_marker (CueMarker const &);
125  bool rename_cue_marker (CueMarker&, std::string const &);
128 
129  virtual timepos_t natural_position() const { return _natural_position; }
130  virtual void set_natural_position (timepos_t const & pos);
131 
132  bool have_natural_position() const { return _have_natural_position; }
133 
134  /* This method is only for use during a capture pass. It makes no sense
135  * in any other context.
136  */
138 
140 
141  PBD::RWLock& mutex() { return _lock; }
142  Flag flags() const { return _flags; }
143 
144  virtual void inc_use_count ();
145  virtual void dec_use_count ();
146  int use_count() const { return _use_count.load(); }
147  bool used() const { return use_count() > 0; }
148 
149  uint32_t level() const { return _level; }
150 
151  std::string ancestor_name() { return _ancestor_name.empty() ? name() : _ancestor_name; }
152  void set_ancestor_name(const std::string& name) { _ancestor_name = name; }
153 
154  void set_captured_for (std::string str) { _captured_for = str; }
155  std::string captured_for() const { return _captured_for; }
156 
158  int set_segment_descriptor (SegmentDescriptor const &, bool replace = false);
159 
160  void copy_segment_descriptors (Source const & other);
161 
162  protected:
165  time_t _timestamp;
166  std::string _take_id;
169  bool _analysed;
170  std::atomic<int> _use_count;
171  uint32_t _level; /* how deeply nested is this source w.r.t a disk file */
172  std::string _ancestor_name;
173  std::string _captured_for;
177 
178  typedef std::vector<SegmentDescriptor> SegmentDescriptors;
180 
183 
184  private:
186 
188  int set_cue_state (XMLNode const &, int);
189 };
190 
191 }
192 
uint32_t level() const
size_t n_captured_xruns() const
virtual timepos_t length() const
Source(Session &, DataType type, const std::string &name, Flag flags=Flag(0))
PBD::RWLock::ReaderLock ReaderLock
int set_segment_descriptor(SegmentDescriptor const &, bool replace=false)
std::vector< SegmentDescriptor > SegmentDescriptors
AnalysisFeatureList transients
const std::string & take_id() const
void mark_for_remove()
virtual ~Source()
std::atomic< int > _use_count
virtual void set_been_analysed(bool yn)
void set_ancestor_name(const std::string &name)
bool has_been_analysed() const
bool move_cue_marker(CueMarker const &, timepos_t const &source_relative_position)
bool remove_cue_marker(CueMarker const &)
void copy_segment_descriptors(Source const &other)
bool rename_cue_marker(CueMarker &, std::string const &)
timecnt_t time_since_capture_start(timepos_t const &pos)
XMLNode & get_state() const
int set_state(XMLNode const &, int version)
time_t timestamp() const
void set_allow_remove_if_empty(bool yn)
bool have_natural_position() const
virtual bool can_be_analysed() const
void stamp(time_t when)
void fix_writable_flags()
PBD::Signal< void()> AnalysisChanged
void set_captured_for(std::string str)
std::string ancestor_name()
bool get_segment_descriptor(TimelineRange const &, SegmentDescriptor &)
void set_captured_marks(CueMarkers const &marks)
std::string _ancestor_name
void set_captured_xruns(XrunPositions const &xruns)
CueMarkers const & cue_markers() const
bool clear_cue_markers()
virtual bool empty() const
virtual void inc_use_count()
XrunPositions _xruns
int set_cue_state(XMLNode const &, int)
static PBD::Signal< void(Source *)> SourceCreated
virtual void set_natural_position(timepos_t const &pos)
virtual timepos_t natural_position() const
Source(Session &, const XMLNode &)
virtual void mark_streaming_write_completed(const WriterLock &lock, Temporal::timecnt_t const &duration)=0
virtual bool check_for_analysis_data_on_disk()
virtual void update_length(timepos_t const &dur)
XMLNode & get_cue_state() const
bool writable() const
virtual void dec_use_count()
bool add_cue_marker(CueMarker const &)
SegmentDescriptors segment_descriptors
std::string _captured_for
virtual bool length_mutable() const
void set_take_id(std::string id)
PBD::Signal< void()> CueMarkersChanged
virtual void session_saved()
PBD::RWLock::WriterLock WriterLock
int load_transients(const std::string &)
std::string get_transients_path() const
XrunPositions const & captured_xruns() const
virtual void mark_streaming_write_started(const WriterLock &lock)
std::string captured_for() const
PBD::RWLock & mutex()
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
std::list< samplepos_t > AnalysisFeatureList
std::set< CueMarker > CueMarkers
std::vector< samplepos_t > XrunPositions