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__
30 #include <glibmm/thread.h>
32 #include <sigc++/signal.h>
34 #include <ardour/source.h>
35 #include <ardour/ardour.h>
36 #include <pbd/stateful.h>
37 #include <pbd/xml++.h>
45 const jack_nframes_t frames_per_peak = 256;
47 class AudioSource : public Source
50 AudioSource (string name);
51 AudioSource (const XMLNode&);
52 virtual ~AudioSource ();
54 /* one could argue that this should belong to Source, but other data types
55 generally do not come with a model of "offset along an audio timeline"
56 so its here in AudioSource for now.
59 virtual jack_nframes_t natural_position() const { return 0; }
61 /* returns the number of items in this `audio_source' */
63 virtual jack_nframes_t length() const {
67 virtual jack_nframes_t available_peaks (double zoom) const;
69 virtual jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const;
70 virtual jack_nframes_t write (Sample *src, jack_nframes_t cnt);
72 virtual float sample_rate () const = 0;
74 virtual void mark_for_remove() = 0;
75 virtual void mark_streaming_write_completed () {}
77 void set_captured_for (string str) { _captured_for = str; }
78 string captured_for() const { return _captured_for; }
80 uint32_t read_data_count() const { return _read_data_count; }
81 uint32_t write_data_count() const { return _write_data_count; }
83 int read_peaks (PeakData *peaks, jack_nframes_t npeaks, jack_nframes_t start, jack_nframes_t cnt, double samples_per_unit) const;
85 bool peaks_ready (sigc::slot<void>, sigc::connection&) const;
87 static sigc::signal<void,AudioSource*> AudioSourceCreated;
89 mutable sigc::signal<void> PeaksReady;
90 mutable sigc::signal<void,jack_nframes_t,jack_nframes_t> PeakRangeReady;
92 XMLNode& get_state ();
93 int set_state (const XMLNode&);
95 static int start_peak_thread ();
96 static void stop_peak_thread ();
98 int rename_peakfile (std::string newpath);
100 static void set_build_missing_peakfiles (bool yn) {
101 _build_missing_peakfiles = yn;
104 static void set_build_peakfiles (bool yn) {
105 _build_peakfiles = yn;
109 static bool _build_missing_peakfiles;
110 static bool _build_peakfiles;
113 mutable Glib::Mutex _lock;
114 jack_nframes_t _length;
115 bool next_peak_clear_should_notify;
117 string _captured_for;
119 mutable uint32_t _read_data_count; // modified in read()
120 mutable uint32_t _write_data_count; // modified in write()
122 int initialize_peakfile (bool newfile, string path);
123 void build_peaks_from_scratch ();
125 int do_build_peak (jack_nframes_t, jack_nframes_t);
127 virtual jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const = 0;
128 virtual jack_nframes_t write_unlocked (Sample *dst, jack_nframes_t cnt) = 0;
129 virtual string peak_path(string audio_path) = 0;
130 virtual string old_peak_path(string audio_path) = 0;
132 void update_length (jack_nframes_t pos, jack_nframes_t cnt);
134 static pthread_t peak_thread;
135 static bool have_peak_thread;
136 static void* peak_thread_work(void*);
138 static int peak_request_pipe[2];
147 static vector<AudioSource*> pending_peak_sources;
148 static Glib::Mutex* pending_peak_sources_lock;
150 static void queue_for_peaks (AudioSource&);
151 static void clear_queue_for_peaks ();
153 struct PeakBuildRecord {
154 jack_nframes_t frame;
157 PeakBuildRecord (jack_nframes_t f, jack_nframes_t c)
158 : frame (f), cnt (c) {}
159 PeakBuildRecord (const PeakBuildRecord& other) {
165 list<AudioSource::PeakBuildRecord *> pending_peak_builds;
168 bool file_changed (string path);
173 #endif /* __ardour_audio_source_h__ */