Ardour  9.8-93-g460ea8c013
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  Transient = 0x800, /* do not save with session */
62  };
63 
66 
67  Source (Session&, DataType type, const std::string& name, Flag flags=Flag(0));
68  Source (Session&, const XMLNode&);
69 
70  virtual ~Source ();
71 
72  DataType type() { return _type; }
73 
74  time_t timestamp() const { return _timestamp; }
75  void stamp (time_t when) { _timestamp = when; }
76 
77  virtual timepos_t length() const { return _length; }
78 
79  virtual bool empty () const;
80  virtual void update_length (timepos_t const & dur) {}
81 
82  void set_take_id (std::string id) { _take_id =id; }
83  const std::string& take_id () const { return _take_id; }
84 
86 
87  virtual void mark_streaming_write_started (const WriterLock& lock) {}
88  /* The duration argument is ignored for audio data, where length is
89  implicitly given by the sample data. It matters for MIDI data, where
90  the file may be intended to be N bars long, but has no events that
91  occur at that duration.
92  */
93  virtual void mark_streaming_write_completed (const WriterLock& lock, Temporal::timecnt_t const & duration) = 0;
94 
95  virtual void session_saved() {}
96 
97  XMLNode& get_state () const;
98  int set_state (XMLNode const &, int version);
99 
100  bool writable () const;
101 
102  virtual bool length_mutable() const { return false; }
103 
105 
106  bool has_been_analysed() const;
107  virtual bool can_be_analysed() const { return false; }
108  virtual void set_been_analysed (bool yn);
110 
112 
114  std::string get_transients_path() const;
115  int load_transients (const std::string&);
116 
117  size_t n_captured_xruns () const { return _xruns.size (); }
118  XrunPositions const& captured_xruns () const { return _xruns; }
119  void set_captured_xruns (XrunPositions const& xruns) { _xruns = xruns; }
120  void set_captured_marks (CueMarkers const& marks);
121 
122  CueMarkers const & cue_markers() const { return _cue_markers; }
123  bool add_cue_marker (CueMarker const &);
124  bool move_cue_marker (CueMarker const &, timepos_t const & source_relative_position);
125  bool remove_cue_marker (CueMarker const &);
126  bool rename_cue_marker (CueMarker&, std::string const &);
129 
130  virtual timepos_t natural_position() const { return _natural_position; }
131  virtual void set_natural_position (timepos_t const & pos);
132 
133  bool have_natural_position() const { return _have_natural_position; }
134 
135  /* This method is only for use during a capture pass. It makes no sense
136  * in any other context.
137  */
139 
141 
142  PBD::RWLock& mutex() { return _lock; }
143  Flag flags() const { return _flags; }
144  bool transient() const { return _flags & Transient; }
145 
146  virtual void inc_use_count ();
147  virtual void dec_use_count ();
148  int use_count() const { return _use_count.load(); }
149  bool used() const { return use_count() > 0; }
150 
151  uint32_t level() const { return _level; }
152 
153  std::string ancestor_name() { return _ancestor_name.empty() ? name() : _ancestor_name; }
154  void set_ancestor_name(const std::string& name) { _ancestor_name = name; }
155 
156  void set_captured_for (std::string str) { _captured_for = str; }
157  std::string captured_for() const { return _captured_for; }
158 
160  int set_segment_descriptor (SegmentDescriptor const &, bool replace = false);
161 
162  void copy_segment_descriptors (Source const & other);
163 
164  protected:
167  time_t _timestamp;
168  std::string _take_id;
171  bool _analysed;
172  std::atomic<int> _use_count;
173  uint32_t _level; /* how deeply nested is this source w.r.t a disk file */
174  std::string _ancestor_name;
175  std::string _captured_for;
179 
180  typedef std::vector<SegmentDescriptor> SegmentDescriptors;
182 
185 
186  private:
188 
190  int set_cue_state (XMLNode const &, int);
191 };
192 
193 }
194 
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