Added the property "unique-id" to PluginInserts so that ladspa plugins
[ardour.git] / libs / ardour / ardour / filesource.h
1 /*
2     Copyright (C) 2000 Paul Davis 
3
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.
8
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.
13
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.
17
18     $Id$
19 */
20
21 #ifndef __playlist_file_buffer_h__ 
22 #define __playlist_file_buffer_h__
23
24 // darwin supports 64 by default and doesn't provide wrapper functions.
25 #if defined (__APPLE__)
26 typedef off_t off64_t;
27 #define open64 open
28 #define close64 close
29 #define lseek64 lseek
30 #define pread64 pread
31 #define pwrite64 pwrite
32 #endif
33
34 #include <vector>
35 #include <string>
36
37 #include <ardour/source.h>
38
39 struct tm;
40
41 using std::string;
42
43 namespace ARDOUR {
44
45 class FileSource : public Source {
46   public:
47         FileSource (string path, jack_nframes_t rate, bool repair_first = false);
48         FileSource (const XMLNode&, jack_nframes_t rate);
49         ~FileSource ();
50
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; }
58
59         int update_header (jack_nframes_t when, struct tm&, time_t);
60
61         int move_to_trash (const string trash_dir_name);
62
63         static bool is_empty (string path);
64         void mark_streaming_write_completed ();
65
66         void   mark_take (string);
67         string take_id() const { return _take_id; }
68
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);
72         
73         static void set_search_path (string);
74
75   protected:
76         int            fd;
77         string        _path;
78         bool           remove_at_unref;
79         bool           is_bwf;
80         off64_t        data_offset;
81         string        _take_id;
82
83         static char bwf_country_code[3];
84         static char bwf_organization_code[4];
85         static char bwf_serial_number[13];
86
87         struct GenericChunk {
88             char    id[4];
89             int32_t  size; 
90         };
91
92         struct WAVEChunk : public GenericChunk {
93             char    text[4];      /* wave pseudo-chunk id "WAVE" */
94         };
95
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 */
103         };
104
105         struct BroadcastChunk : public GenericChunk {
106             char   description[256];
107             char   originator[32];
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" */
114             char   umid[64];
115             char   reserved[190];
116             /* we don't treat coding history as part of the struct */
117         };
118
119         struct ChunkInfo {
120             string        name;
121             uint32_t size;
122             off64_t         offset;
123             
124             ChunkInfo (string s, uint32_t sz, off64_t o) 
125                     : name (s), size (sz), offset (o) {}
126         };
127
128         vector<ChunkInfo> chunk_info;
129         
130         struct {
131             WAVEChunk               wave;
132             FMTChunk                format;
133             GenericChunk            data;
134             BroadcastChunk          bext;
135             vector<string>          coding_history;
136             bool                    bigendian;
137         } header;
138
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;
141
142         int discover_chunks (bool silent);
143         ChunkInfo* lookup_chunk (string name);
144
145         int write_header ();
146         int read_header (bool silent);
147
148         int check_header (jack_nframes_t rate, bool silent);
149         int fill_header (jack_nframes_t rate);
150         
151         int read_broadcast_data (ChunkInfo&);
152         void compute_header_size ();
153         
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);
156
157         static string search_path;
158
159         int repair (string, jack_nframes_t);
160
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;
165 };
166
167 }
168
169 #endif /* __playlist_file_buffer_h__ */