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 virtual nframes_t available_peaks (double zoom) const;
59 virtual nframes_t read (Sample *dst, nframes_t start, nframes_t cnt) const;
60 virtual nframes_t write (Sample *src, nframes_t cnt);
62 virtual float sample_rate () const = 0;
64 virtual void mark_for_remove() = 0;
65 virtual void mark_streaming_write_completed () {}
67 void set_captured_for (string str) { _captured_for = str; }
68 string captured_for() const { return _captured_for; }
70 uint32_t read_data_count() const { return _read_data_count; }
71 uint32_t write_data_count() const { return _write_data_count; }
73 virtual int read_peaks (PeakData *peaks, nframes_t npeaks, nframes_t start, nframes_t cnt, double samples_per_unit) const;
75 bool peaks_ready (sigc::slot<void>, sigc::connection&) const;
77 mutable sigc::signal<void> PeaksReady;
78 mutable sigc::signal<void,nframes_t,nframes_t> PeakRangeReady;
80 XMLNode& get_state ();
81 int set_state (const XMLNode&);
83 static int start_peak_thread ();
84 static void stop_peak_thread ();
86 int rename_peakfile (std::string newpath);
87 void touch_peakfile ();
89 static void set_build_missing_peakfiles (bool yn) {
90 _build_missing_peakfiles = yn;
93 static void set_build_peakfiles (bool yn) {
94 _build_peakfiles = yn;
97 virtual int setup_peakfile () { return 0; }
100 static bool _build_missing_peakfiles;
101 static bool _build_peakfiles;
104 mutable Glib::Mutex _lock;
105 bool next_peak_clear_should_notify;
107 string _captured_for;
109 mutable uint32_t _read_data_count; // modified in read()
110 mutable uint32_t _write_data_count; // modified in write()
112 int initialize_peakfile (bool newfile, string path);
113 void build_peaks_from_scratch ();
115 int do_build_peak (nframes_t, nframes_t);
117 virtual nframes_t read_unlocked (Sample *dst, nframes_t start, nframes_t cnt) const = 0;
118 virtual nframes_t write_unlocked (Sample *dst, nframes_t cnt) = 0;
119 virtual string peak_path(string audio_path) = 0;
120 virtual string old_peak_path(string audio_path) = 0;
122 static pthread_t peak_thread;
123 static bool have_peak_thread;
124 static void* peak_thread_work(void*);
126 static int peak_request_pipe[2];
135 static vector<boost::shared_ptr<AudioSource> > pending_peak_sources;
136 static Glib::Mutex* pending_peak_sources_lock;
138 static void queue_for_peaks (boost::shared_ptr<AudioSource>);
139 static void clear_queue_for_peaks ();
141 struct PeakBuildRecord {
145 PeakBuildRecord (nframes_t f, nframes_t c)
146 : frame (f), cnt (c) {}
147 PeakBuildRecord (const PeakBuildRecord& other) {
153 list<AudioSource::PeakBuildRecord *> pending_peak_builds;
156 bool file_changed (string path);
161 #endif /* __ardour_audio_source_h__ */