diff options
Diffstat (limited to 'src/lib/hd24fs.h')
-rwxr-xr-x | src/lib/hd24fs.h | 432 |
1 files changed, 432 insertions, 0 deletions
diff --git a/src/lib/hd24fs.h b/src/lib/hd24fs.h new file mode 100755 index 0000000..b91d4c1 --- /dev/null +++ b/src/lib/hd24fs.h | |||
@@ -0,0 +1,432 @@ | |||
1 | #ifndef __hd24fs_h__ | ||
2 | #define __hd24fs_h__ | ||
3 | |||
4 | #include <config.h> | ||
5 | #include <stdio.h> | ||
6 | #include <string> | ||
7 | #include <hd24utils.h> | ||
8 | #include "memutils.h" | ||
9 | #include "convertlib.h" | ||
10 | #define CLUSTER_UNDEFINED (0xFFFFFFFF) | ||
11 | |||
12 | #if defined(LINUX) || defined(DARWIN) | ||
13 | # define FSHANDLE int | ||
14 | # define FSHANDLE_INVALID -1 | ||
15 | #endif | ||
16 | |||
17 | #ifdef WINDOWS | ||
18 | # include <windows.h> | ||
19 | # include <winioctl.h> | ||
20 | # define FSHANDLE HANDLE | ||
21 | # define FSHANDLE_INVALID INVALID_HANDLE_VALUE | ||
22 | #endif | ||
23 | |||
24 | using namespace std; | ||
25 | |||
26 | class hd24fs; | ||
27 | class hd24project; | ||
28 | class hd24raw; | ||
29 | class hd24song; | ||
30 | |||
31 | class AudioStorage | ||
32 | { | ||
33 | public: | ||
34 | virtual __uint32 samplerate() { return 0; }; | ||
35 | virtual void currentlocation(__uint32 newpos) { return; }; | ||
36 | virtual __uint32 currentlocation() { return 0; }; | ||
37 | virtual __uint32 getlocatepos(int locatepoint) { return 0; }; | ||
38 | virtual __uint32 setlocatepos(int locatepoint,__uint32 newpos) { return 0; }; | ||
39 | virtual bool trackarmed(__uint32 base1tracknum) { return false; } | ||
40 | virtual void trackarmed(__uint32 base1tracknum,bool arm) { return; } | ||
41 | virtual ~AudioStorage() { return; } ; | ||
42 | }; | ||
43 | |||
44 | class hd24song : public AudioStorage | ||
45 | { | ||
46 | friend class hd24project; | ||
47 | friend class hd24fs; | ||
48 | friend class hd24transferjob; | ||
49 | friend class hd24transferengine; | ||
50 | private: | ||
51 | __uint32 framespersec; | ||
52 | unsigned char* buffer; // for songinfo | ||
53 | unsigned char* audiobuffer; // for audio data | ||
54 | unsigned char* scratchbook; // for write-back audio data | ||
55 | __uint32* blocksector; | ||
56 | int evenodd; /* specifies if we are dealing with | ||
57 | even or odd samples in high speed mode. */ | ||
58 | bool lengthened; /* Indicate if reallocating song length change occured */ | ||
59 | bool busyrecording; | ||
60 | int mysongid; | ||
61 | int polling; | ||
62 | int currentreadmode; | ||
63 | int currcachebufnum; | ||
64 | bool rehearsemode; | ||
65 | bool lastallocentrynum; | ||
66 | hd24fs* parentfs; | ||
67 | unsigned char** cachebuf_ptr; | ||
68 | __uint32* cachebuf_blocknum; | ||
69 | hd24project* parentproject; | ||
70 | hd24song(hd24project* p_parent,__uint32 p_songid); | ||
71 | unsigned char* getcachedbuffer(long unsigned int); | ||
72 | void queuecacheblock(__uint32 blocknum); | ||
73 | void loadblockintocache(__uint32 blocknum); | ||
74 | void setblockcursor(__uint32 blocknum); | ||
75 | void memoizeblocksectors(__uint32 lastblock); | ||
76 | __uint32 memblocksector(__uint32 blocknum); | ||
77 | __uint32 blocktoqueue; // next block to cache | ||
78 | __uint32 songcursor; // current cursor pos within song, in samples | ||
79 | __uint32 allocentrynum; // which allocation entry is currently being used | ||
80 | __uint32 allocstartblock; // the first audioblock in given entry | ||
81 | __uint32 allocstartsector; // the sector pointed to by that entry | ||
82 | __uint32 allocaudioblocks; // the number of audioblocks in the block | ||
83 | __uint32 divider; | ||
84 | __uint32 lastreadblock; | ||
85 | __uint32 lastavailablecacheblock; | ||
86 | __uint32 mustreadblock; | ||
87 | __uint32 track_armed[24]; | ||
88 | __uint32 track_readenabled[24]; // used to speed up copy mode. | ||
89 | void unmark_used_clusters(unsigned char* sectors_orphan); | ||
90 | __uint32 used_alloctable_entries(); | ||
91 | __uint32 audioblocks_in_alloctable(); | ||
92 | void silenceaudioblocks(__uint32 allocsector,__uint32 blocks); | ||
93 | bool allocatenewblocks(long unsigned int, bool, char*, int*, int (*)()); | ||
94 | |||
95 | public: | ||
96 | ~hd24song(); | ||
97 | string* songname(); | ||
98 | __uint32 songid(); | ||
99 | hd24fs* fs(); | ||
100 | static void sectorinit(unsigned char* sectorbuf); | ||
101 | static void settrackcount(unsigned char* sectorbuf,__uint32 trackcount); | ||
102 | static void songname(unsigned char* sectorbuf,string newname); | ||
103 | void songname(string newname); | ||
104 | static string* songname(hd24fs* parentfs,unsigned char* sectorbuf); | ||
105 | void bufferpoll(); | ||
106 | |||
107 | void readenabletrack(__uint32 tracknum); | ||
108 | void readenabletrack(__uint32 tracknum,bool enable); | ||
109 | |||
110 | bool isrehearsemode(); | ||
111 | void setrehearsemode(bool p_rehearsemode); | ||
112 | bool recording(); | ||
113 | |||
114 | bool trackarmed(__uint32 tracknum); | ||
115 | void trackarmed(__uint32 tracknum,bool arm); | ||
116 | |||
117 | bool istrackmonitoringinput(__uint32 tracknum); | ||
118 | void startrecord(int record_mode); | ||
119 | void stoprecord(); | ||
120 | __uint32 samplerate(); | ||
121 | static void samplerate(unsigned char* sectorbuf,__uint32 samplerate); | ||
122 | void samplerate(__uint32 newrate); | ||
123 | static __uint32 samplerate(unsigned char* songbuf); | ||
124 | __uint32 bitdepth(); | ||
125 | __uint32 physical_channels(); | ||
126 | static __uint32 physical_channels(unsigned char* songbuf); | ||
127 | void physical_channels(__uint32 newchannelcount); | ||
128 | static void physical_channels(unsigned char* songbuf,__uint32 newchannelcount); | ||
129 | __uint32 logical_channels(); | ||
130 | static __uint32 logical_channels(unsigned char* songbuf); | ||
131 | void logical_channels(__uint32 newchannelcount); | ||
132 | static void logical_channels(unsigned char* songbuf,__uint32 channelcount); | ||
133 | __uint32 songlength_in_samples(); | ||
134 | __uint32 songlength_in_samples(__uint32 newlen); | ||
135 | __uint32 songlength_in_samples(__uint32 newlen,bool silence); | ||
136 | __uint32 songlength_in_samples(__uint32 newlen,bool silence,char* savemessage,int* cancel); | ||
137 | __uint32 songlength_in_samples(__uint32 newlen,bool silence,char* savemessage,int* cancel,int (*checkfunc)()); | ||
138 | |||
139 | __uint32 display_hours(); | ||
140 | __uint32 display_hours(__uint32 offset); | ||
141 | static __uint32 display_hours(__uint32 offset,__uint32 samrate); | ||
142 | |||
143 | __uint32 display_minutes(); | ||
144 | __uint32 display_minutes(__uint32 offset); | ||
145 | static __uint32 display_minutes(__uint32 offset,__uint32 samrate); | ||
146 | |||
147 | __uint32 display_seconds(); | ||
148 | __uint32 display_seconds(__uint32 offset); | ||
149 | static __uint32 display_seconds(__uint32 offset,__uint32 samrate); | ||
150 | |||
151 | __uint32 display_subseconds(); | ||
152 | __uint32 display_subseconds(__uint32 offset); | ||
153 | static __uint32 display_subseconds(__uint32 offset,__uint32 samrate); | ||
154 | |||
155 | string* display_duration(); | ||
156 | string* display_duration(__uint32 offset); | ||
157 | string* display_duration(__uint32 offset,__uint32 samrate); | ||
158 | |||
159 | string* display_cursor(); | ||
160 | __uint32 cursorpos(); | ||
161 | __uint32 locatepointcount(); | ||
162 | __uint32 getlocatepos(int locatepoint); | ||
163 | |||
164 | __uint32 currentlocation(); | ||
165 | void currentlocation(__uint32 offset); | ||
166 | __uint32 golocatepos(__uint32 offset); | ||
167 | |||
168 | __uint32 setlocatepos(int locatepoint,__uint32 offset); | ||
169 | void setlocatename(int locatepoint,string newname); | ||
170 | string* getlocatename(int locatepoint); | ||
171 | bool iswriteprotected(); | ||
172 | void setwriteprotected(bool prot); | ||
173 | void getmultitracksample(long* mtsample,int readmode); | ||
174 | int getmtrackaudiodata(__uint32 firstsamnum,__uint32 samples,unsigned char* buffer,int readmode); | ||
175 | int putmtrackaudiodata(__uint32 firstsamnum,__uint32 samples,unsigned char* buffer,int writemode); | ||
176 | void deinterlaceblock(unsigned char* buffer,unsigned char* targetbuffer); | ||
177 | void interlaceblock(unsigned char* buffer,unsigned char* targetbuffer); | ||
178 | static const int LOCATEPOS_SONGSTART; | ||
179 | static const int LOCATEPOS_LOOPSTART; | ||
180 | static const int LOCATEPOS_LOOPEND; | ||
181 | static const int LOCATEPOS_PUNCHIN; | ||
182 | static const int LOCATEPOS_PUNCHOUT; | ||
183 | static const int LOCATEPOS_EDITIN; | ||
184 | static const int LOCATEPOS_EDITOUT; | ||
185 | static const int LOCATEPOS_LAST; | ||
186 | static const int READMODE_COPY; | ||
187 | static const int READMODE_REALTIME; | ||
188 | static const int WRITEMODE_COPY; | ||
189 | static const int WRITEMODE_REALTIME; | ||
190 | |||
191 | __uint32 getnextfreesector(__uint32 allocsector); | ||
192 | bool has_unexpected_end(); // indicates if there is an 'unexpected end of song' error | ||
193 | bool is_fixable_unexpected_end(); // ...and if so, if we know how to fix it. | ||
194 | bool setallocinfo(bool silencenew); | ||
195 | bool setallocinfo(bool silencenew,char* message,int* cancel,int (*checkfunc)()); | ||
196 | __uint32 requiredaudioblocks(__uint32 songlen); | ||
197 | void appendorphanclusters(unsigned char*,bool allowsongresize); | ||
198 | void save(); | ||
199 | }; | ||
200 | |||
201 | class hd24project | ||
202 | { | ||
203 | friend class hd24fs; | ||
204 | friend class hd24song; | ||
205 | |||
206 | private: | ||
207 | unsigned char* buffer; | ||
208 | hd24fs* parentfs; | ||
209 | __sint32 myprojectid; | ||
210 | hd24song* songlist; | ||
211 | hd24project(hd24fs* p_parent,__sint32 projectid); | ||
212 | hd24project(hd24fs* p_parent,__sint32 projectid,__uint32 projsector,const char* projectname,bool isnew); | ||
213 | __uint32 getsongsectornum(int i); | ||
214 | void setsongsectornum(int i,__uint32 newsector); | ||
215 | void save(__uint32 projsector); | ||
216 | void populatesongusagetable(unsigned char* songused); | ||
217 | __uint32 getunusedsongslot(); | ||
218 | void initvars(hd24fs* p_parent,__sint32 p_projectid); | ||
219 | public: | ||
220 | ~hd24project(); | ||
221 | string* projectname(); | ||
222 | void projectname(string newname); | ||
223 | __sint32 lastsongid(); | ||
224 | void lastsongid(signed long songid); | ||
225 | __uint32 songcount(); | ||
226 | __uint32 maxsongs(); | ||
227 | __sint32 projectid(); | ||
228 | hd24song* getsong(__uint32 songid); | ||
229 | hd24song* createsong(const char* songname,__uint32 trackcount,__uint32 samplerate); | ||
230 | __uint32 deletesong(__uint32 songid); | ||
231 | void save(); | ||
232 | void sort(); | ||
233 | }; | ||
234 | |||
235 | class hd24fs | ||
236 | { | ||
237 | friend class hd24project; | ||
238 | friend class hd24song; | ||
239 | friend class hd24raw; | ||
240 | friend class hd24utils; | ||
241 | |||
242 | private: | ||
243 | const char* imagedir; | ||
244 | int transportstatus; | ||
245 | bool writeprotected; | ||
246 | bool allinput; | ||
247 | bool autoinput; | ||
248 | bool forcemode; | ||
249 | bool formatting; // true during a format operation | ||
250 | bool headermode; | ||
251 | bool maintenancemode; | ||
252 | bool wavefixmode; | ||
253 | __uint32 highestFSsectorwritten; | ||
254 | |||
255 | __uint32 nextfreeclusterword; // memoization cache for write allocation | ||
256 | |||
257 | FSHANDLE devhd24; // device handle | ||
258 | FSHANDLE hd24header; // header device handle | ||
259 | bool m_isOpen; | ||
260 | bool gotlastsectornum; | ||
261 | __uint32 foundlastsectornum; | ||
262 | int p_mode; | ||
263 | hd24project* projlist; | ||
264 | string* devicename; | ||
265 | unsigned char* sector_boot; | ||
266 | unsigned char* sector_diskinfo; | ||
267 | unsigned char* sectors_driveusage; | ||
268 | unsigned char* sectors_orphan; | ||
269 | unsigned char* sectors_songusage; | ||
270 | long readsectors(FSHANDLE handle, __uint32 secnum, unsigned char* buffer,int sectors); | ||
271 | long readsector(FSHANDLE handle, __uint32 secnum, unsigned char* buffer); | ||
272 | long readsector_noheader(FSHANDLE handle, __uint32 secnum, unsigned char* buffer); | ||
273 | long readsector_noheader(hd24fs* currenthd24, __uint32 secnum, unsigned char* buffer); | ||
274 | long writesectors(FSHANDLE handle, __uint32 secnum, unsigned char* buffer,int sectors); | ||
275 | long writesector(FSHANDLE handle, __uint32 secnum, unsigned char* buffer); | ||
276 | |||
277 | string* gethd24currentdir(int, char**); | ||
278 | void hd24close(); | ||
279 | void hd24closedevice(FSHANDLE handle); | ||
280 | static void hd24seek(FSHANDLE handle,__uint64 seekpos); | ||
281 | void clearbuffer(unsigned char* buffer); | ||
282 | void clearbuffer(unsigned char* buffer,unsigned int bytes); | ||
283 | FSHANDLE findhd24device(); | ||
284 | FSHANDLE findhd24device(int mode); | ||
285 | FSHANDLE findhd24device(int mode, int base0devnum); | ||
286 | FSHANDLE findhd24device(int mode, string* dev,bool force,bool tryharder); | ||
287 | static bool isinvalidhandle(FSHANDLE handle); | ||
288 | unsigned char* readbootinfo(); | ||
289 | unsigned char* readdiskinfo(); | ||
290 | unsigned char* readdriveusageinfo(); | ||
291 | unsigned char* resetsongusage(); | ||
292 | unsigned char* resetdriveusage(); | ||
293 | unsigned char* calcsongusage(); | ||
294 | void refreshsongusage(); | ||
295 | unsigned char* getsector_bootinfo(); | ||
296 | unsigned char* getsector_diskinfo(); | ||
297 | unsigned char* getsectors_driveusage(); | ||
298 | unsigned char* getcopyofusagetable(); // allocates memory and fills it up with a copy of the current usage table | ||
299 | void initvars(); | ||
300 | __uint32 driveusagesectorcount(); | ||
301 | __uint32 clustercount(); | ||
302 | __uint32 driveusagefirstsector(); | ||
303 | __uint32 getblockspercluster(); | ||
304 | __uint32 getprojectsectornum(__uint32 base1proj); | ||
305 | bool isfreecluster(__uint32 clusternum); | ||
306 | bool isfreecluster(__uint32 clusternum,unsigned char* usagebuffer); | ||
307 | __uint32 freeclustercount(); | ||
308 | __uint32 getlastsectornum(); | ||
309 | __uint32 getlastsectornum(FSHANDLE handle); | ||
310 | __uint32 headersectors; | ||
311 | void writebackupblock(__uint32 sector,__uint32 blocksize, | ||
312 | __uint32 lastsec,bool fullcommit); | ||
313 | __uint32 getnextfreesectorword(); | ||
314 | __uint32 getnextfreeclusterword(); | ||
315 | __uint32 getnextfreesector(__uint32 cluster); | ||
316 | void enablebit(__uint32 ibit,unsigned char* usagebuffer); | ||
317 | void disablebit(__uint32 ibit,unsigned char* usagebuffer); | ||
318 | bool isbitzero(__uint32 ibit,unsigned char* usagebuffer); | ||
319 | long unsigned int songentry2songsector(long unsigned int entry); | ||
320 | long unsigned int songsector2songentry(long unsigned int entry); | ||
321 | void allocsongentry(__uint32 entrynum); | ||
322 | void allocatecluster(__uint32 clusternum); | ||
323 | void allocatecluster(__uint32 clusternum,unsigned char* usagebuffer); | ||
324 | void freecluster(__uint32 clusternum); | ||
325 | void freecluster(__uint32 clusternum,unsigned char* usagebuffer); | ||
326 | signed long nextunusedsongentry(); | ||
327 | void useinternalboot(unsigned char*, long unsigned int); | ||
328 | __uint32 getunusedsongsector(); | ||
329 | __uint32 songsondisk(); | ||
330 | void songsondisk(__uint32 songsondisk); | ||
331 | void setprojectsectornum(int i,__uint32 newsector); | ||
332 | void setimagedir(const char* newdir); | ||
333 | int deviceid; | ||
334 | public: | ||
335 | __uint32 lasterror; | ||
336 | void force_reload(); | ||
337 | static void setname(unsigned char* namebuf,string newname,__uint32 shortnameoff,__uint32 longnameoff); | ||
338 | void dumpclusterusage(); | ||
339 | void dumpclusterusage(unsigned char* buffer); | ||
340 | void dumpclusterusage2(); | ||
341 | void dumpclusterusage2(unsigned char* buffer); | ||
342 | unsigned char* findorphanclusters(); | ||
343 | static const int TRANSPORTSTATUS_PLAY; | ||
344 | static const int TRANSPORTSTATUS_STOP; | ||
345 | static const int TRANSPORTSTATUS_REC; | ||
346 | __uint32 cluster2sector(__uint32 clusternum); | ||
347 | __uint32 sector2cluster(__uint32 sectornum); | ||
348 | __uint32 songentry2sector(__uint32 entrynum); | ||
349 | __uint32 songsector2entry(__uint32 sectornum); | ||
350 | void settransportstatus(int newstatus); | ||
351 | int gettransportstatus(); | ||
352 | bool isallinput(); | ||
353 | void setallinput(bool p_allinput); | ||
354 | void setallinput(void); | ||
355 | bool isautoinput(); | ||
356 | void setautoinput(bool p_autoinput); | ||
357 | void setautoinput(void); | ||
358 | |||
359 | hd24fs(const char* imagedir); | ||
360 | hd24fs(const char* imagedir,int mode); | ||
361 | hd24fs(const char* imagedir,int mode,int base0devnum); | ||
362 | hd24fs(const char* imagedir,int mode,string* dev,bool force); | ||
363 | ~hd24fs(); | ||
364 | __uint32 getblocksizeinsectors(); | ||
365 | __uint32 getbytesperaudioblock(); | ||
366 | static void fstfix(unsigned char* bootblock,int fixsize); | ||
367 | bool isOpen(); | ||
368 | int mode(); | ||
369 | string* volumename(); | ||
370 | string* getdevicename(); | ||
371 | int getdeviceid(); | ||
372 | void setdevicename(const char* orig,string* newname); | ||
373 | void setvolumename(string newname); | ||
374 | string* version(); | ||
375 | __uint32 hd24devicecount(); | ||
376 | __sint32 lastprojectid(); | ||
377 | void lastprojectid(signed long projectid); | ||
378 | __uint32 projectcount(); | ||
379 | __uint32 maxprojects(); | ||
380 | __uint32 maxsongsperproject(); | ||
381 | hd24project* getproject(__sint32 projectid); | ||
382 | hd24project* createproject(const char* projectname); | ||
383 | void setmaintenancemode(int mode); | ||
384 | int getmaintenancemode(); | ||
385 | void setwavefixmode(int mode); | ||
386 | int getwavefixmode(); | ||
387 | string* gethd24currentdir(); | ||
388 | static const int MODE_RDONLY; | ||
389 | static const int MODE_RDWR; | ||
390 | string* freespace(__uint32 rate,__uint32 tracks); | ||
391 | bool useheaderfile(string headerfilename); | ||
392 | bool isexistingdevice(string *devname); | ||
393 | bool commit(bool fullcommit); | ||
394 | bool commit(); | ||
395 | long unsigned int setsectorchecksum(unsigned char* buffer,unsigned int startoffset,unsigned int startsector,unsigned int sectors); | ||
396 | void savedriveinfo(); | ||
397 | void savedriveusage(); | ||
398 | __uint32 writesuperblock(__uint32 lastsectornum); | ||
399 | void cleardriveinfo(unsigned char* buffer); | ||
400 | __uint32 writedriveinfo(); | ||
401 | __uint32 writesongusage(); | ||
402 | __uint32 writedriveusage(); | ||
403 | __uint32 quickformat(char* lasterror); | ||
404 | __uint32 deleteproject(__sint32 projid); | ||
405 | void write_enable(); | ||
406 | void write_disable(); | ||
407 | }; | ||
408 | |||
409 | /* Provides sector level access to hd24 disks | ||
410 | * (functionality which is private in hd24fs) | ||
411 | */ | ||
412 | class hd24raw | ||
413 | { | ||
414 | friend class hd24fs; | ||
415 | |||
416 | private: | ||
417 | hd24fs* fsys; | ||
418 | |||
419 | public: | ||
420 | hd24raw(hd24fs* fsys); | ||
421 | hd24raw(hd24fs* fsys,bool notranslate); | ||
422 | ~hd24raw() {}; | ||
423 | long readsectors(__uint32 secnum, unsigned char* buffer,int sectors); | ||
424 | long writesectors(__uint32 secnum, unsigned char* buffer,int sectors); | ||
425 | __uint32 getnextfreesector(__uint32 cluster); | ||
426 | __uint32 getprojectsectornum(__uint32 projectid); | ||
427 | __uint32 getlastsectornum(); | ||
428 | __uint32 songsondisk(); | ||
429 | __uint32 quickformat(char* lasterror); | ||
430 | }; | ||
431 | |||
432 | #endif | ||