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);
48 FileSource (const XMLNode&, jack_nframes_t rate);
51 jack_nframes_t length() const { return _length; }
52 jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const;
53 jack_nframes_t write (Sample *src, jack_nframes_t cnt);
54 void mark_for_remove();
55 string peak_path(string audio_path);
56 string old_peak_path(string audio_path);
57 string path() const { return _path; }
59 int update_header (jack_nframes_t when, struct tm&, time_t);
61 int move_to_trash (const string trash_dir_name);
63 static bool is_empty (string path);
64 void mark_streaming_write_completed ();
66 void mark_take (string);
67 string take_id() const { return _take_id; }
69 static void set_bwf_country_code (string x);
70 static void set_bwf_organization_code (string x);
71 static void set_bwf_serial_number (int);
73 static void set_search_path (string);
83 static char bwf_country_code[3];
84 static char bwf_organization_code[4];
85 static char bwf_serial_number[13];
92 struct WAVEChunk : public GenericChunk {
93 char text[4]; /* wave pseudo-chunk id "WAVE" */
96 struct FMTChunk : public GenericChunk {
97 int16_t formatTag; /* format tag; currently pcm */
98 int16_t nChannels; /* number of channels */
99 uint32_t nSamplesPerSec; /* sample rate in hz */
100 int32_t nAvgBytesPerSec; /* average bytes per second */
101 int16_t nBlockAlign; /* number of bytes per sample */
102 int16_t nBitsPerSample; /* number of bits in a sample */
105 struct BroadcastChunk : public GenericChunk {
106 char description[256];
108 char originator_reference[32];
109 char origination_date[10];
110 char origination_time[8];
111 int32_t time_reference_low;
112 int32_t time_reference_high;
113 int16_t version; /* 1.0 because we have umid and 190 bytes of "reserved" */
116 /* we don't treat coding history as part of the struct */
124 ChunkInfo (string s, uint32_t sz, off64_t o)
125 : name (s), size (sz), offset (o) {}
128 vector<ChunkInfo> chunk_info;
135 vector<string> coding_history;
139 int init (string, bool must_exist, jack_nframes_t);
140 jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const;
142 int discover_chunks (bool silent);
143 ChunkInfo* lookup_chunk (string name);
146 int read_header (bool silent);
148 int check_header (jack_nframes_t rate, bool silent);
149 int fill_header (jack_nframes_t rate);
151 int read_broadcast_data (ChunkInfo&);
152 void compute_header_size ();
154 static const int32_t wave_header_size = sizeof (WAVEChunk) + sizeof (FMTChunk) + sizeof (GenericChunk);
155 static const int32_t bwf_header_size = wave_header_size + sizeof (BroadcastChunk);
157 static string search_path;
159 int repair (string, jack_nframes_t);
161 void swap_endian (GenericChunk & chunk) const;
162 void swap_endian (FMTChunk & chunk) const;
163 void swap_endian (BroadcastChunk & chunk) const;
164 void swap_endian (Sample *buf, jack_nframes_t cnt) const;
169 #endif /* __playlist_file_buffer_h__ */