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 <glibmm/thread.h>
34 #include <ardour/ardour.h>
35 #include <ardour/stateful.h>
36 #include <pbd/xml++.h>
45 typedef Sample PeakDatum;
51 const jack_nframes_t frames_per_peak = 256;
53 class Source : public Stateful, public sigc::trackable
56 Source (bool announce=true);
57 Source (const XMLNode&);
60 const string& name() const { return _name; }
62 ARDOUR::id_t id() const { return _id; }
64 /* returns the number of items in this `source' */
66 virtual jack_nframes_t length() const {
70 virtual jack_nframes_t available_peaks (double zoom) const;
72 virtual jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const {
76 virtual jack_nframes_t write (Sample *src, jack_nframes_t cnt, char * workbuf) {
80 virtual float sample_rate () const { return 0; }
82 uint32_t use_cnt() const { return _use_cnt; }
86 virtual void mark_for_remove() = 0;
87 virtual void mark_streaming_write_completed () {}
89 time_t timestamp() const { return _timestamp; }
90 void stamp (time_t when) { _timestamp = when; }
92 void set_captured_for (string str) { _captured_for = str; }
93 string captured_for() const { return _captured_for; }
95 uint32_t read_data_count() const { return _read_data_count; }
96 uint32_t write_data_count() const { return _write_data_count; }
98 int read_peaks (PeakData *peaks, jack_nframes_t npeaks, jack_nframes_t start, jack_nframes_t cnt, double samples_per_unit) const;
100 bool peaks_ready (sigc::slot<void>, sigc::connection&) const;
102 static sigc::signal<void,Source*> SourceCreated;
104 sigc::signal<void,Source *> GoingAway;
105 mutable sigc::signal<void> PeaksReady;
106 mutable sigc::signal<void,jack_nframes_t,jack_nframes_t> PeakRangeReady;
108 XMLNode& get_state ();
109 int set_state (const XMLNode&);
111 static int start_peak_thread ();
112 static void stop_peak_thread ();
114 int rename_peakfile (std::string newpath);
116 static void set_build_missing_peakfiles (bool yn) {
117 _build_missing_peakfiles = yn;
119 static void set_build_peakfiles (bool yn) {
120 _build_peakfiles = yn;
124 static bool _build_missing_peakfiles;
125 static bool _build_peakfiles;
130 mutable Glib::Mutex _lock;
131 jack_nframes_t _length;
132 bool next_peak_clear_should_notify;
135 string _captured_for;
137 mutable uint32_t _read_data_count; // modified in read()
138 mutable uint32_t _write_data_count; // modified in write()
140 int initialize_peakfile (bool newfile, string path);
141 void build_peaks_from_scratch ();
143 int do_build_peak (jack_nframes_t, jack_nframes_t);
144 virtual jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const = 0;
145 virtual string peak_path(string audio_path) = 0;
147 static pthread_t peak_thread;
148 static bool have_peak_thread;
149 static void* peak_thread_work(void*);
151 static int peak_request_pipe[2];
160 static vector<Source*> pending_peak_sources;
161 static Glib::StaticMutex pending_peak_sources_lock;
163 static void queue_for_peaks (Source&);
164 static void clear_queue_for_peaks ();
166 struct PeakBuildRecord {
167 jack_nframes_t frame;
170 PeakBuildRecord (jack_nframes_t f, jack_nframes_t c)
171 : frame (f), cnt (c) {}
172 PeakBuildRecord (const PeakBuildRecord& other) {
178 list<Source::PeakBuildRecord *> pending_peak_builds;
183 bool file_changed (string path);
188 #endif /* __ardour_source_h__ */