2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 $Id: audio_source.h 486 2006-04-27 09:04:24Z pauld $
21 #ifndef __ardour_audio_source_h__
22 #define __ardour_audio_source_h__
28 #include <boost/shared_ptr.hpp>
29 #include <boost/enable_shared_from_this.hpp>
33 #include <glibmm/thread.h>
35 #include <sigc++/signal.h>
37 #include <ardour/source.h>
38 #include <ardour/ardour.h>
39 #include <pbd/stateful.h>
40 #include <pbd/xml++.h>
48 const nframes_t frames_per_peak = 256;
50 class AudioSource : public Source, public boost::enable_shared_from_this<ARDOUR::AudioSource>
53 AudioSource (Session&, string name);
54 AudioSource (Session&, const XMLNode&);
55 virtual ~AudioSource ();
57 /* one could argue that this should belong to Source, but other data types
58 generally do not come with a model of "offset along an audio timeline"
59 so its here in AudioSource for now.
62 virtual nframes_t natural_position() const { return 0; }
64 /* returns the number of items in this `audio_source' */
66 virtual nframes_t length() const {
70 virtual nframes_t available_peaks (double zoom) const;
72 virtual nframes_t read (Sample *dst, nframes_t start, nframes_t cnt) const;
73 virtual nframes_t write (Sample *src, nframes_t cnt);
75 virtual float sample_rate () const = 0;
77 virtual void mark_for_remove() = 0;
78 virtual void mark_streaming_write_completed () {}
80 void set_captured_for (string str) { _captured_for = str; }
81 string captured_for() const { return _captured_for; }
83 uint32_t read_data_count() const { return _read_data_count; }
84 uint32_t write_data_count() const { return _write_data_count; }
86 virtual int read_peaks (PeakData *peaks, nframes_t npeaks, nframes_t start, nframes_t cnt, double samples_per_unit) const;
88 bool peaks_ready (sigc::slot<void>, sigc::connection&) const;
90 mutable sigc::signal<void> PeaksReady;
91 mutable sigc::signal<void,nframes_t,nframes_t> PeakRangeReady;
93 XMLNode& get_state ();
94 int set_state (const XMLNode&);
96 static int start_peak_thread ();
97 static void stop_peak_thread ();
99 int rename_peakfile (std::string newpath);
100 void touch_peakfile ();
102 static void set_build_missing_peakfiles (bool yn) {
103 _build_missing_peakfiles = yn;
106 static void set_build_peakfiles (bool yn) {
107 _build_peakfiles = yn;
110 virtual int setup_peakfile () { return 0; }
113 static bool _build_missing_peakfiles;
114 static bool _build_peakfiles;
117 mutable Glib::Mutex _lock;
119 bool next_peak_clear_should_notify;
121 string _captured_for;
123 mutable uint32_t _read_data_count; // modified in read()
124 mutable uint32_t _write_data_count; // modified in write()
126 int initialize_peakfile (bool newfile, string path);
127 void build_peaks_from_scratch ();
129 int do_build_peak (nframes_t, nframes_t);
130 void truncate_peakfile();
132 mutable off_t _peak_byte_max; // modified in do_build_peaks()
134 virtual nframes_t read_unlocked (Sample *dst, nframes_t start, nframes_t cnt) const = 0;
135 virtual nframes_t write_unlocked (Sample *dst, nframes_t cnt) = 0;
136 virtual string peak_path(string audio_path) = 0;
137 virtual string old_peak_path(string audio_path) = 0;
139 void update_length (nframes_t pos, nframes_t cnt);
141 static pthread_t peak_thread;
142 static bool have_peak_thread;
143 static void* peak_thread_work(void*);
145 static int peak_request_pipe[2];
154 static vector<boost::shared_ptr<AudioSource> > pending_peak_sources;
155 static Glib::Mutex* pending_peak_sources_lock;
157 static void queue_for_peaks (boost::shared_ptr<AudioSource>, bool notify=true);
158 static void clear_queue_for_peaks ();
160 struct PeakBuildRecord {
164 PeakBuildRecord (nframes_t f, nframes_t c)
165 : frame (f), cnt (c) {}
166 PeakBuildRecord (const PeakBuildRecord& other) {
172 list<AudioSource::PeakBuildRecord *> pending_peak_builds;
175 bool file_changed (string path);
180 #endif /* __ardour_audio_source_h__ */