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