Ardour  9.2-129-gdf5e1050bd
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/session_object.h"
35 #include "ardour/data_type.h"
37 
38 namespace ARDOUR {
39 
40 class Session;
41 
43  public std::enable_shared_from_this<ARDOUR::Source>
44 {
45 public:
46  enum Flag {
47  Writable = 0x1,
48  CanRename = 0x2,
49  Broadcast = 0x4,
50  Removable = 0x8,
51  RemovableIfEmpty = 0x10,
52  RemoveAtDestroy = 0x20,
53  NoPeakFile = 0x40,
54  /* No longer in use but kept to allow loading of older sessions */
55  Destructive = 0x80,
56  Empty = 0x100, /* used for MIDI only */
57  RF64_RIFF = 0x200,
58  Missing = 0x400, /* used for MIDI only */
59  };
60 
63 
64  Source (Session&, DataType type, const std::string& name, Flag flags=Flag(0));
65  Source (Session&, const XMLNode&);
66 
67  virtual ~Source ();
68 
69  DataType type() { return _type; }
70 
71  time_t timestamp() const { return _timestamp; }
72  void stamp (time_t when) { _timestamp = when; }
73 
74  virtual timepos_t length() const { return _length; }
75 
76  virtual bool empty () const;
77  virtual void update_length (timepos_t const & dur) {}
78 
79  void set_take_id (std::string id) { _take_id =id; }
80  const std::string& take_id () const { return _take_id; }
81 
83 
84  virtual void mark_streaming_write_started (const WriterLock& lock) {}
85  /* The duration argument is ignored for audio data, where length is
86  implicitly given by the sample data. It matters for MIDI data, where
87  the file may be intended to be N bars long, but has no events that
88  occur at that duration.
89  */
90  virtual void mark_streaming_write_completed (const WriterLock& lock, Temporal::timecnt_t const & duration) = 0;
91 
92  virtual void session_saved() {}
93 
94  XMLNode& get_state () const;
95  int set_state (XMLNode const &, int version);
96 
97  bool writable () const;
98 
99  virtual bool length_mutable() const { return false; }
100 
102 
103  bool has_been_analysed() const;
104  virtual bool can_be_analysed() const { return false; }
105  virtual void set_been_analysed (bool yn);
107 
109 
111  std::string get_transients_path() const;
112  int load_transients (const std::string&);
113 
114  size_t n_captured_xruns () const { return _xruns.size (); }
115  XrunPositions const& captured_xruns () const { return _xruns; }
116  void set_captured_xruns (XrunPositions const& xruns) { _xruns = xruns; }
117  void set_captured_marks (CueMarkers const& marks);
118 
119  CueMarkers const & cue_markers() const { return _cue_markers; }
120  bool add_cue_marker (CueMarker const &);
121  bool move_cue_marker (CueMarker const &, timepos_t const & source_relative_position);
122  bool remove_cue_marker (CueMarker const &);
123  bool rename_cue_marker (CueMarker&, std::string const &);
126 
127  virtual timepos_t natural_position() const { return _natural_position; }
128  virtual void set_natural_position (timepos_t const & pos);
129 
130  bool have_natural_position() const { return _have_natural_position; }
131 
132  /* This method is only for use during a capture pass. It makes no sense
133  * in any other context.
134  */
136 
138 
139  PBD::RWLock& mutex() { return _lock; }
140  Flag flags() const { return _flags; }
141 
142  virtual void inc_use_count ();
143  virtual void dec_use_count ();
144  int use_count() const { return _use_count.load(); }
145  bool used() const { return use_count() > 0; }
146 
147  uint32_t level() const { return _level; }
148 
149  std::string ancestor_name() { return _ancestor_name.empty() ? name() : _ancestor_name; }
150  void set_ancestor_name(const std::string& name) { _ancestor_name = name; }
151 
152  void set_captured_for (std::string str) { _captured_for = str; }
153  std::string captured_for() const { return _captured_for; }
154 
156  int set_segment_descriptor (SegmentDescriptor const &, bool replace = false);
157 
158  void copy_segment_descriptors (Source const & other);
159 
160  protected:
163  time_t _timestamp;
164  std::string _take_id;
167  bool _analysed;
168  std::atomic<int> _use_count;
169  uint32_t _level; /* how deeply nested is this source w.r.t a disk file */
170  std::string _ancestor_name;
171  std::string _captured_for;
175 
176  typedef std::vector<SegmentDescriptor> SegmentDescriptors;
178 
181 
182  private:
184 
186  int set_cue_state (XMLNode const &, int);
187 };
188 
189 }
190 
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