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.
21 #ifndef __ardour_source_h__
22 #define __ardour_source_h__
30 #include <sigc++/signal.h>
32 #include <ardour/ardour.h>
33 #include <ardour/stateful.h>
34 #include <pbd/xml++.h>
43 typedef Sample PeakDatum;
49 const jack_nframes_t frames_per_peak = 256;
51 class Source : public Stateful, public sigc::trackable
54 Source (bool announce=true);
55 Source (const XMLNode&);
58 const string& name() const { return _name; }
60 ARDOUR::id_t id() const { return _id; }
62 /* returns the number of items in this `source' */
64 virtual jack_nframes_t length() const {
68 virtual jack_nframes_t available_peaks (double zoom) const;
70 virtual jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const {
74 virtual jack_nframes_t write (Sample *src, jack_nframes_t cnt, char * workbuf) {
78 virtual float sample_rate () const { return 0; }
80 uint32_t use_cnt() const { return _use_cnt; }
84 virtual void mark_for_remove() = 0;
85 virtual void mark_streaming_write_completed () {}
87 time_t timestamp() const { return _timestamp; }
88 void stamp (time_t when) { _timestamp = when; }
90 void set_captured_for (string str) { _captured_for = str; }
91 string captured_for() const { return _captured_for; }
93 uint32_t read_data_count() const { return _read_data_count; }
94 uint32_t write_data_count() const { return _write_data_count; }
96 int read_peaks (PeakData *peaks, jack_nframes_t npeaks, jack_nframes_t start, jack_nframes_t cnt, double samples_per_unit) const;
98 bool peaks_ready (sigc::slot<void>, sigc::connection&) const;
100 static sigc::signal<void,Source*> SourceCreated;
102 sigc::signal<void,Source *> GoingAway;
103 mutable sigc::signal<void> PeaksReady;
104 mutable sigc::signal<void,jack_nframes_t,jack_nframes_t> PeakRangeReady;
106 XMLNode& get_state ();
107 int set_state (const XMLNode&);
109 static int start_peak_thread ();
110 static void stop_peak_thread ();
112 int rename_peakfile (std::string newpath);
114 static void set_build_missing_peakfiles (bool yn) {
115 _build_missing_peakfiles = yn;
117 static void set_build_peakfiles (bool yn) {
118 _build_peakfiles = yn;
122 static bool _build_missing_peakfiles;
123 static bool _build_peakfiles;
128 mutable PBD::Lock _lock;
129 jack_nframes_t _length;
130 bool next_peak_clear_should_notify;
133 string _captured_for;
135 mutable uint32_t _read_data_count; // modified in read()
136 mutable uint32_t _write_data_count; // modified in write()
138 int initialize_peakfile (bool newfile, string path);
139 void build_peaks_from_scratch ();
141 int do_build_peak (jack_nframes_t, jack_nframes_t);
142 virtual jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const = 0;
143 virtual string peak_path(string audio_path) = 0;
145 static pthread_t peak_thread;
146 static bool have_peak_thread;
147 static void* peak_thread_work(void*);
149 static int peak_request_pipe[2];
158 static vector<Source*> pending_peak_sources;
159 static PBD::Lock pending_peak_sources_lock;
161 static void queue_for_peaks (Source&);
162 static void clear_queue_for_peaks ();
164 struct PeakBuildRecord {
165 jack_nframes_t frame;
168 PeakBuildRecord (jack_nframes_t f, jack_nframes_t c)
169 : frame (f), cnt (c) {}
170 PeakBuildRecord (const PeakBuildRecord& other) {
176 list<Source::PeakBuildRecord *> pending_peak_builds;
181 bool file_changed (string path);
186 #endif /* __ardour_source_h__ */