static int ReadStateChunk(MEMFILE *st, SFORMAT *sf, int size) { //if(scan_chunks) // return mem_fseek(st,size,SEEK_CUR) == 0; SFORMAT *tmp; int temp; temp=mem_ftell(st); while(mem_ftell(st)<temp+size) { uint32 tsize; char toa[4]; if(mem_fread(toa,1,4,st)<=0) return 0; mem_read32le(&tsize,st); if((tmp=CheckS(sf,tsize,toa))) { mem_fread((uint8 *)tmp->v,1,tmp->s&(~RLSB),st); #ifndef LSB_FIRST if(tmp->s&RLSB) FlipByteOrder(tmp->v,tmp->s&(~RLSB)); #endif } else { mem_fseek(st,tsize,SEEK_CUR); printf("ReadStateChunk: sect \"%c%c%c%c\" not handled\n", toa[0], toa[1], toa[2], toa[3]); } } // while(...) return 1; }
// // I_ReadMidiTrack() // // Reads an entire midi track from memory and creates a list of MidiEvents // pointers where the event's start time is the time since the beginning of the // track. It is the caller's responsibility to delete the list returned // by this function. // static std::list<MidiEvent*> *I_ReadMidiTrack(MEMFILE *mf) { if (!mf) return NULL; midi_chunk_header_t chunkheader; unsigned int track_time = 0; size_t res = mem_fread(&chunkheader, cTrackHeaderSize, 1, mf); if (!res) return NULL; chunkheader.chunk_id = ntohl(chunkheader.chunk_id); chunkheader.chunk_size = ntohl(chunkheader.chunk_size); if (chunkheader.chunk_id != cTrackChunkId) { Printf(PRINT_HIGH, "I_ReadMidiTrack: Unexpected chunk header ID\n"); return NULL; } std::list<MidiEvent*> *eventlist = new std::list<MidiEvent*>; size_t trackend = mem_ftell(mf) + chunkheader.chunk_size; while (mem_ftell(mf) < int(trackend)) { MidiEvent *newevent = I_ReadMidiEvent(mf, track_time); if (!newevent) { Printf(PRINT_HIGH, "I_ReadMidiTrack: Unable to read MIDI event\n"); I_ClearMidiEventList(eventlist); delete eventlist; return NULL; } eventlist->push_back(newevent); track_time = newevent->getMidiClockTime(); } return eventlist; }
// // I_ReadDataBlock() // // Returns a handle to the internal storage of a MEMFILE and moves the read // position of the MEMFILE forward to the end of the block. // static byte* I_ReadDataBlock(MEMFILE *mf, size_t length) { if (!mf) return NULL; size_t memfileoffset = mem_ftell(mf); if (mem_fsize(mf) < memfileoffset + length) return NULL; byte* data = (byte*)mem_fgetbuf(mf) + memfileoffset; mem_fseek(mf, length, MEM_SEEK_CUR); return data; }