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 __playlist_file_buffer_h__
22 #define __playlist_file_buffer_h__
24 // darwin supports 64 by default and doesn't provide wrapper functions.
25 #if defined (__APPLE__)
26 typedef off_t off64_t;
31 #define pwrite64 pwrite
37 #include <ardour/source.h>
45 class FileSource : public Source {
47 FileSource (string path, jack_nframes_t rate, bool repair_first = false, SampleFormat samp_format=FormatFloat);
48 FileSource (const XMLNode&, jack_nframes_t rate);
51 int set_name (std::string str, bool destructive);
53 void set_allow_remove_if_empty (bool yn);
55 jack_nframes_t length() const { return _length; }
56 jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
57 jack_nframes_t write (Sample *src, jack_nframes_t cnt, char * workbuf);
58 void mark_for_remove();
59 string peak_path(string audio_path);
60 string path() const { return _path; }
62 virtual int seek (jack_nframes_t frame) {return 0; }
63 virtual jack_nframes_t last_capture_start_frame() const { return 0; }
64 virtual void mark_capture_start (jack_nframes_t) {}
65 virtual void mark_capture_end () {}
66 virtual void clear_capture_marks() {}
68 int update_header (jack_nframes_t when, struct tm&, time_t);
70 int move_to_trash (const string trash_dir_name);
72 static bool is_empty (string path);
73 void mark_streaming_write_completed ();
75 void mark_take (string);
76 string take_id() const { return _take_id; }
78 static void set_bwf_country_code (string x);
79 static void set_bwf_organization_code (string x);
80 static void set_bwf_serial_number (int);
82 static void set_search_path (string);
91 SampleFormat _sample_format;
93 bool allow_remove_if_empty;
95 static char bwf_country_code[3];
96 static char bwf_organization_code[4];
97 static char bwf_serial_number[13];
104 struct WAVEChunk : public GenericChunk {
105 char text[4]; /* wave pseudo-chunk id "WAVE" */
108 struct FMTChunk : public GenericChunk {
109 int16_t formatTag; /* format tag; currently pcm */
110 int16_t nChannels; /* number of channels */
111 uint32_t nSamplesPerSec; /* sample rate in hz */
112 int32_t nAvgBytesPerSec; /* average bytes per second */
113 int16_t nBlockAlign; /* number of bytes per sample */
114 int16_t nBitsPerSample; /* number of bits in a sample */
117 struct BroadcastChunk : public GenericChunk {
118 char description[256];
120 char originator_reference[32];
121 char origination_date[10];
122 char origination_time[8];
123 int32_t time_reference_low;
124 int32_t time_reference_high;
125 int16_t version; /* 1.0 because we have umid and 190 bytes of "reserved" */
128 /* we don't treat coding history as part of the struct */
136 ChunkInfo (string s, uint32_t sz, off64_t o)
137 : name (s), size (sz), offset (o) {}
140 vector<ChunkInfo> chunk_info;
147 vector<string> coding_history;
151 int init (string, bool must_exist, jack_nframes_t);
152 jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
154 ssize_t file_write (Sample *src, jack_nframes_t framepos, jack_nframes_t cnt, char * workbuf) {
155 switch (_sample_format) {
156 case FormatInt24: return write_pcm_24(src, framepos, cnt, workbuf);
157 default: return write_float(src, framepos, cnt, workbuf);
161 ssize_t file_read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const {
162 switch (_sample_format) {
163 case FormatInt24: return read_pcm_24(dst, start, cnt, workbuf);
164 default: return read_float(dst, start, cnt, workbuf);
168 ssize_t write_float(Sample *src, jack_nframes_t framepos, jack_nframes_t cnt, char * workbuf);
169 ssize_t read_float (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
170 ssize_t write_pcm_24(Sample *src, jack_nframes_t framepos, jack_nframes_t cnt, char * workbuf);
171 ssize_t read_pcm_24 (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
173 int discover_chunks (bool silent);
174 ChunkInfo* lookup_chunk (string name);
177 int read_header (bool silent);
179 int check_header (jack_nframes_t rate, bool silent);
180 int fill_header (jack_nframes_t rate);
182 int read_broadcast_data (ChunkInfo&);
183 void compute_header_size ();
185 static const int32_t wave_header_size = sizeof (WAVEChunk) + sizeof (FMTChunk) + sizeof (GenericChunk);
186 static const int32_t bwf_header_size = wave_header_size + sizeof (BroadcastChunk);
188 static string search_path;
190 int repair (string, jack_nframes_t);
192 void swap_endian (GenericChunk & chunk) const;
193 void swap_endian (FMTChunk & chunk) const;
194 void swap_endian (BroadcastChunk & chunk) const;
195 void swap_endian (Sample *buf, jack_nframes_t cnt) const;
200 #endif /* __playlist_file_buffer_h__ */