152a38012Sejakowatz /* 252a38012Sejakowatz 352a38012Sejakowatz SynthFileReader.h 452a38012Sejakowatz 5*2ca13760SColdfirex Copyright (c) 2002 Haiku. 652a38012Sejakowatz 752a38012Sejakowatz Author: 852a38012Sejakowatz Michael Pfeiffer 952a38012Sejakowatz 1052a38012Sejakowatz Permission is hereby granted, free of charge, to any person obtaining a copy of 1152a38012Sejakowatz this software and associated documentation files (the "Software"), to deal in 1252a38012Sejakowatz the Software without restriction, including without limitation the rights to 1352a38012Sejakowatz use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 1452a38012Sejakowatz of the Software, and to permit persons to whom the Software is furnished to do 1552a38012Sejakowatz so, subject to the following conditions: 1652a38012Sejakowatz 1752a38012Sejakowatz The above copyright notice and this permission notice shall be included in all 1852a38012Sejakowatz copies or substantial portions of the Software. 1952a38012Sejakowatz 2052a38012Sejakowatz THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2152a38012Sejakowatz IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2252a38012Sejakowatz FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2352a38012Sejakowatz AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2452a38012Sejakowatz LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 2552a38012Sejakowatz OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 2652a38012Sejakowatz THE SOFTWARE. 2752a38012Sejakowatz 2852a38012Sejakowatz */ 2952a38012Sejakowatz 3052a38012Sejakowatz #ifndef _SYNTH_FILE_READER_H 3152a38012Sejakowatz #define _SYNTH_FILE_READER_H 3252a38012Sejakowatz 3352a38012Sejakowatz #include <stdio.h> 3452a38012Sejakowatz #include <SupportDefs.h> 3552a38012Sejakowatz #include <String.h> 3652a38012Sejakowatz 37bc962561SMichael Pfeiffer class SSynthFile; 38bc962561SMichael Pfeiffer 39bc962561SMichael Pfeiffer class SSynthFileReader { 40bc962561SMichael Pfeiffer private: 4152a38012Sejakowatz FILE* fFile; 4252a38012Sejakowatz 4352a38012Sejakowatz typedef char tag[4]; 4452a38012Sejakowatz 4552a38012Sejakowatz bool TagEquals(const char* tag1, const char* tag2) const; 4652a38012Sejakowatz bool Read(void* data, uint32 size); 4752a38012Sejakowatz bool Read(BString& s, uint32 size); 4852a38012Sejakowatz bool Read(tag &tag); 4952a38012Sejakowatz bool Read(uint64 &n, uint32 size); 5052a38012Sejakowatz bool Read(uint32 &n); 5152a38012Sejakowatz bool Read(uint16 &n); 5252a38012Sejakowatz bool Read(uint8 &n); 5352a38012Sejakowatz bool Skip(uint32 bytes); Tell()54bc962561SMichael Pfeiffer uint32 Tell() { return ftell(fFile); } Seek(uint32 pos)55bc962561SMichael Pfeiffer void Seek(uint32 pos) { fseek(fFile, pos, SEEK_SET); } 56bc962561SMichael Pfeiffer 57bc962561SMichael Pfeiffer bool ReadHeader(uint32& version, uint32& chunks, uint32& nextChunk); 58bc962561SMichael Pfeiffer bool NextChunk(tag& tag, uint32& nextChunk); 59bc962561SMichael Pfeiffer bool ReadInstHeader(uint16& inst, uint16& snd, uint16& snds, BString& name, uint32& size); 60bc962561SMichael Pfeiffer bool ReadSoundInRange(uint8& start, uint8& end, uint16& snd, uint32& size); 61bc962561SMichael Pfeiffer bool ReadSoundHeader(uint16& inst, BString& name, uint32& size); 6252a38012Sejakowatz 6352a38012Sejakowatz // debugging support 6452a38012Sejakowatz void Print(tag tag); 6552a38012Sejakowatz void Dump(uint32 bytes); 6652a38012Sejakowatz void Play(uint16 rate, uint32 offset, uint32 size); 6752a38012Sejakowatz 6852a38012Sejakowatz public: 69bc962561SMichael Pfeiffer SSynthFileReader(const char* synthFile); 70bc962561SMichael Pfeiffer ~SSynthFileReader(); 71bc962561SMichael Pfeiffer status_t InitCheck() const; 72bc962561SMichael Pfeiffer 73bc962561SMichael Pfeiffer status_t Initialize(SSynthFile* synth); 7452a38012Sejakowatz 7552a38012Sejakowatz void Dump(bool play, uint32 instrOnly); 7652a38012Sejakowatz }; 7752a38012Sejakowatz 7852a38012Sejakowatz #endif 79