void Tmx2MapData::readMapData(char * urlmapdata) { unsigned long fileLen = 0; unsigned char *fileData = NULL; fileData = CCFileUtils::sharedFileUtils()->getFileData(urlmapdata, "rb", (ssize_t*)(&fileLen)); unsigned char* data = fileData; unsigned long pos = 0; CC_SAFE_DELETE(maskArray); searchPath->UnLoadScene(); pos += readUint16(data, width,false); pos += readUint16(data, height,false); pos += readUint16(data, xLen,false); pos += readUint16(data, yLen,false); pos += readUint16(data, cellWidth,false); pos += readUint16(data, cellHeight,false); uint16 temp; pos += readUint16(data, temp,false); pos += readUint16(data, temp,false); int vecsize=0; pos += readInt(data,vecsize,false); searchPath->InitializationMap(xLen, yLen); maskArray =new std::vector<unsigned char>(); for (int i=0;i<vecsize;i++) { unsigned char uc; readUChar(data,uc); maskArray->push_back(uc); if ((*maskArray)[i]==(unsigned char)1) { searchPath->SetBlock(i/yLen, i%yLen, false); } } pos += readInt(data,vecsize,false); aphaVec =new std::vector<unsigned char>(); for (int i=0;i<vecsize;i++) { unsigned char uc; readUChar(data,uc); aphaVec->push_back(uc); if (uc==(unsigned char) 0) { int x=i/yLen; int y=i%yLen; int i=0; } } CC_SAFE_DELETE(fileData); }
bool L2Login_PlayFail::parse( L2_VERSION ver /*= L2_VERSION_T1*/ ) { UNREFERENCED_PARAMETER(ver); if( getPacketType() != 0x06 ) return false; if( !canReadBytes(1) ) return false; p_reasonCode = readUChar(); return true; }
void File::readHeader() { if (!file_ptr) { Error::addMessage(Error::NULL_REFERENCE, LIBGENS_FILE_H_ERROR_FILE_HEADER); return; } unsigned char next_gen_check=0; readUChar(&next_gen_check); goToAddress(0); if (next_gen_check == 0x80) { // Read new header root_node_type = LIBGENS_MODEL_ROOT_DYNAMIC_LOST_WORLD; root_node_address = LIBGENS_FILE_HEADER_ROOT_ADDRESS_NEXT_GEN; unsigned short file_size = 0; goToAddress(2); readInt16BE(&file_size); unsigned int signature = 0; readInt32BE(&signature); unsigned int offset_table_size=0; size_t offset_table_address_absolute=0; readInt32BE(&offset_table_address_absolute); readInt32BE(&offset_table_size); // FIXME: Awful way to seek through the new type of Lost World header, needs to be done // in a better way. size_t max_section_scan = 32; for (size_t i=0; i<max_section_scan; i++) { unsigned short section_flag = 0; unsigned short section_address = 0; unsigned int section_value = 0; string section_name = ""; readInt16BE(§ion_flag); readInt16BE(§ion_address); readInt32BE(§ion_value); readString(§ion_name, 8); if (section_name == "Contexts") { break; } } } else { fseek(file_ptr, LIBGENS_FILE_HEADER_ROOT_TYPE_ADDRESS+global_offset, SEEK_SET); readInt32BE(&root_node_type); fseek(file_ptr, LIBGENS_FILE_HEADER_ROOT_NODE_ADDRESS+global_offset, SEEK_SET); readInt32BE(&root_node_address); fseek(file_ptr, root_node_address+global_offset, SEEK_SET); } }
int GuitarPro5::readBeatEffects(int track, Segment* segment) { int effects = 0; uchar fxBits1 = readUChar(); uchar fxBits2 = readUChar(); if (fxBits1 & BEAT_FADE) effects = 4; // fade in if (fxBits1 & BEAT_EFFECT) effects = readUChar(); if (fxBits2 & BEAT_TREMOLO) readTremoloBar(track, segment); // readBend(); if (fxBits1 & BEAT_ARPEGGIO) { int strokeup = readUChar(); // up stroke length int strokedown = readUChar(); // down stroke length Arpeggio* a = new Arpeggio(score); // representation is different in guitar pro 5 - the up/down order below is correct if( strokeup > 0 ) { a->setArpeggioType(ArpeggioType::UP_STRAIGHT); } else if( strokedown > 0 ) { a->setArpeggioType(ArpeggioType::DOWN_STRAIGHT); } else { delete a; a = 0; } if(a) { ChordRest* cr = new Chord(score); cr->setTrack(track); cr->add(a); segment->add(cr); } } if (fxBits2 & BEAT_STROKE_DIR) { effects = readChar(); // stroke pick direction effects += 4; //1 or 2 for effects becomes 4 or 5 } return effects; }
/* $(bytelist) */ int readByteList( TAInputStream * stream, unsigned char ** list_ptr ) { int size, i; verifyType_TAInputStream( stream, "bytelist" ); size = readInt( stream ); if ( size == -1 ) { * list_ptr = NULL; } else if ( size >= 0 ) { * list_ptr = (unsigned char *)ta_alloc_memory( size * sizeof( unsigned char ) ); assertion( * list_ptr != NULL, "Can't alloc %d bytes for list", size * sizeof( unsigned char ) ); for ( i = 0; i < size; i++ ) { (* list_ptr)[ i ] = readUChar( stream ); } } return size; }
bool File::compare(File *file) { if (!file) return false; if (getFileSize() != file->getFileSize()) return false; unsigned char source=0; unsigned char dest=0; goToAddress(0); file->goToAddress(0); while (!endOfFile()) { readUChar(&source); file->readUChar(&dest); if (source != dest) { return false; } } return true; }
virtual void readUChar(uchar* buf,int count,bool& success) { for(int i=0; i < count; i++) buf[i] = readUChar(success); }
Track* GTM::fetchNextTrack() { /* Point to the actual track offset */ if ( VSIFSeekL(pGTMFile, actualTrackOffset, SEEK_SET) != 0) return nullptr; /* Read string length */ const unsigned short stringSize = readUShort(pGTMFile); /* Read name string */ char* pszName = (char*) VSI_MALLOC2_VERBOSE(sizeof(char), stringSize+1); if( pszName == nullptr ) return nullptr; if ( stringSize != 0 && !readFile( pszName, 1, sizeof(char) * stringSize ) ) { CPLFree(pszName); return nullptr; } pszName[stringSize] = '\0'; /* Read type */ const unsigned char type = readUChar(pGTMFile); /* Read color */ const int color = readInt(pGTMFile); Track* poTrack = new Track(pszName, type, color); CPLFree(pszName); /* Adjust actual Track offset */ actualTrackOffset = VSIFTellL(pGTMFile) + 7; ++trackFetched; /* Now, We read all trackpoints for this track */ double latitude = 0.0; double longitude = 0.0; GIntBig datetime = 0; unsigned char start = 0; float altitude = 0.0f; /* NOTE: Parameters are passed by reference */ if ( !readTrackPoints(latitude, longitude, datetime, start, altitude) ) { delete poTrack; return nullptr; } /* Check if it is the start, if not we have done something wrong */ if (start != 1) { delete poTrack; return nullptr; } poTrack->addPoint(longitude, latitude, datetime, altitude); do { /* NOTE: Parameters are passed by reference */ if ( !readTrackPoints(latitude, longitude, datetime, start, altitude) ) { delete poTrack; return nullptr; } if (start == 0) poTrack->addPoint(longitude, latitude, datetime, altitude); } while(start == 0 && trackpointFetched < ntcks); /* We have read one more than necessary, so we adjust the offset */ if (trackpointFetched < ntcks) { actualTrackpointOffset -= 25; --trackpointFetched; } return poTrack; }
Waypoint* GTM::fetchNextWaypoint() { /* Point to the actual waypoint offset */ if ( VSIFSeekL(pGTMFile, actualWaypointOffset, SEEK_SET) != 0) return nullptr; const double latitude = readDouble(pGTMFile); const double longitude = readDouble(pGTMFile); char name[11]; if ( !readFile( name, 1, 10 ) ) return nullptr; /* Trim string name */ { int i = 9; // Used after for. for( ; i >= 0; --i) { if (name[i] != ' ') { name[i+1] = '\0'; break; } } if (i < 0) name[0] = '\0'; } /* Read String Length */ const unsigned short stringSize = readUShort(pGTMFile); /* Read Comment String */ char* comment = static_cast<char *>( VSI_MALLOC2_VERBOSE(sizeof(char), stringSize+1) ); if( comment == nullptr ) return nullptr; if ( stringSize != 0 && !readFile( comment, 1, sizeof(char)*stringSize ) ) { CPLFree(comment); return nullptr; } comment[stringSize] = '\0'; /* Read Icon */ const unsigned short icon = readUShort(pGTMFile); /* Display number */ readUChar(pGTMFile); /* Waypoint date */ GIntBig wptdate = readInt(pGTMFile); if (wptdate != 0) wptdate += GTM_EPOCH; /* Rotation text angle */ readUShort(pGTMFile); /* Altitude */ const float altitude = readFloat(pGTMFile); Waypoint* poWaypoint = new Waypoint(latitude, longitude, altitude, name, comment, (int) icon, wptdate); /* Set actual waypoint offset to the next it there is one */ ++waypointFetched; if (waypointFetched < nwpts) { actualWaypointOffset += 8 + 8 + 10 + 2 + stringSize + 2 + 1 + 4 + 2 + 4 + 2; } CPLFree(comment); return poWaypoint; }
void GuitarPro5::read(QFile* fp) { f = fp; readInfo(); readLyrics(); readPageSetup(); previousDynamic = -1; previousTempo = -1; //previousDynamic = new int [staves * VOICES]; // initialise the dynamics to 0 //for (int i = 0; i < staves * VOICES; i++) // previousDynamic[i] = 0; tempo = readInt(); if (version > 500) skip(1); key = readInt(); /* int octave =*/ readChar(); // octave readChannels(); skip(42); measures = readInt(); staves = readInt(); slurs = new Slur*[staves]; for (int i = 0; i < staves; ++i) slurs[i] = 0; int tnumerator = 4; int tdenominator = 4; for (int i = 0; i < measures; ++i) { if (i > 0) skip(1); GpBar bar; uchar barBits = readUChar(); if (barBits & SCORE_TIMESIG_NUMERATOR) tnumerator = readUChar(); if (barBits & SCORE_TIMESIG_DENOMINATOR) tdenominator = readUChar(); if (barBits & SCORE_REPEAT_START) bar.repeatFlags = bar.repeatFlags | Repeat::START; if (barBits & SCORE_REPEAT_END) { // number of repeats bar.repeatFlags = bar.repeatFlags |Repeat::END; bar.repeats = readUChar(); } if (barBits & SCORE_MARKER) { bar.marker = readDelphiString(); // new section? /*int color =*/ readInt(); // color? } if (barBits & SCORE_VOLTA) { // a volta uchar voltaNumber = readUChar(); while (voltaNumber > 0) { // voltas are represented as flags bar.volta.voltaType = GP_VOLTA_FLAGS; bar.volta.voltaInfo.append(voltaNumber & 1); voltaNumber >>= 1; } } if (barBits & SCORE_KEYSIG) { int currentKey = readUChar(); /* key signatures are specified as * 1# = 1, 2# = 2, ..., 7# = 7 * 1b = 255, 2b = 254, ... 7b = 249 */ bar.keysig = currentKey <= 7 ? currentKey : -256+currentKey; readUChar(); // specified major/minor mode } if (barBits & SCORE_DOUBLE_BAR) bar.barLine = BarLineType::DOUBLE; if (barBits & 0x3) skip(4); if ((barBits & 0x10) == 0) skip(1); readChar(); // triple feel (none, 8, 16) bar.timesig = Fraction(tnumerator, tdenominator); bars.append(bar); }
void GuitarPro5::readTracks() { for (int i = 0; i < staves; ++i) { int tuning[GP_MAX_STRING_NUMBER]; Staff* staff = score->staff(i); Part* part = staff->part(); uchar c = readUChar(); // simulations bitmask if (c & 0x2) { // 12 stringed guitar } if (c & 0x4) { // banjo track } if (i == 0 || version == 500) skip(1); QString name = readPascalString(40); int strings = readInt(); if (strings <= 0 || strings > GP_MAX_STRING_NUMBER) throw GuitarProError::GP_BAD_NUMBER_OF_STRINGS ; for (int j = 0; j < strings; ++j) { tuning[j] = readInt(); } for (int j = strings; j < GP_MAX_STRING_NUMBER; ++j) readInt(); /*int midiPort =*/ readInt(); // -1 int midiChannel = readInt() - 1; /*int midiChannel2 =*/ readInt(); // -1 int frets = readInt(); int capo = readInt(); /*int color =*/ readInt(); skip(version > 500 ? 49 : 44); if (version > 500) { // british stack clean / amp tone readDelphiString(); readDelphiString(); } int tuning2[strings]; for (int k = 0; k < strings; ++k) tuning2[strings-k-1] = tuning[k]; StringData stringData(frets, strings, tuning2); Instrument* instr = part->instr(); instr->setStringData(stringData); part->setPartName(name); part->setLongName(name); instr->setTranspose(Interval(capo)); // // determine clef // int patch = channelDefaults[midiChannel].patch; ClefType clefId = ClefType::G; if (midiChannel == GP_DEFAULT_PERCUSSION_CHANNEL) { clefId = ClefType::PERC; // instr->setUseDrumset(DrumsetKind::GUITAR_PRO); instr->setDrumset(gpDrumset); staff->setStaffType(StaffType::preset(StaffTypes::PERC_DEFAULT)); } else if (patch >= 24 && patch < 32) clefId = ClefType::G3; else if (patch >= 32 && patch < 40) clefId = ClefType::F8; Measure* measure = score->firstMeasure(); Clef* clef = new Clef(score); clef->setClefType(clefId); clef->setTrack(i * VOICES); Segment* segment = measure->getSegment(Segment::Type::Clef, 0); segment->add(clef); Channel& ch = instr->channel(0); if (midiChannel == GP_DEFAULT_PERCUSSION_CHANNEL) { ch.program = 0; ch.bank = 128; } else { ch.program = patch; ch.bank = 0; } ch.volume = channelDefaults[midiChannel].volume; ch.pan = channelDefaults[midiChannel].pan; ch.chorus = channelDefaults[midiChannel].chorus; ch.reverb = channelDefaults[midiChannel].reverb; //qDebug("default2: %d", channelDefaults[i].reverb); // missing: phase, tremolo ch.updateInitList(); } skip(version == 500 ? 2 : 1); }
int GuitarPro5::readBeat(int tick, int voice, Measure* measure, int staffIdx, Tuplet** tuplets, bool /*mixChange*/) { uchar beatBits = readUChar(); bool dotted = beatBits & BEAT_DOTTED; slide = -1; int track = staffIdx * VOICES + voice; if (slides.contains(track)) slide = slides.take(track); int pause = -1; if (beatBits & BEAT_PAUSE) pause = readUChar(); // readDuration int len = readChar(); int tuple = 0; if (beatBits & BEAT_TUPLET) tuple = readInt(); Segment* segment = measure->getSegment(Segment::Type::ChordRest, tick); if (beatBits & BEAT_CHORD) { int numStrings = score->staff(staffIdx)->part()->instr()->stringData()->strings(); skip(17); QString name = readPascalString(21); skip(4); // no header to be read in the GP5 format - default to true. readChord(segment, staffIdx * VOICES, numStrings, name, true); skip(32); } Lyrics* lyrics = 0; if (beatBits & BEAT_LYRICS) { QString txt = readDelphiString(); lyrics = new Lyrics(score); lyrics->setText(txt); } gpLyrics.beatCounter++; if (gpLyrics.beatCounter >= gpLyrics.fromBeat && gpLyrics.lyricTrack == staffIdx+1) { int index = gpLyrics.beatCounter - gpLyrics.fromBeat; if (index < gpLyrics.lyrics.size()) { lyrics = new Lyrics(score); lyrics->setText(gpLyrics.lyrics[index]); } } int beatEffects = 0; if (beatBits & BEAT_EFFECTS) beatEffects = readBeatEffects(track, segment); if (beatBits & BEAT_MIX_CHANGE) readMixChange(measure); int strings = readUChar(); // used strings mask Fraction l = len2fraction(len); // Some beat effects could add a Chord before this ChordRest* cr = segment->cr(track); if (voice != 0 && pause == 0 && strings == 0) cr = 0; else { if (strings == 0) { if (cr) { segment->remove(cr); delete cr; cr = 0; } cr = new Rest(score); } else { if (!cr) cr = new Chord(score); } cr->setTrack(track); TDuration d(l); d.setDots(dotted ? 1 : 0); if (dotted) l = l + (l/2); if (tuple) { Tuplet* tuplet = tuplets[staffIdx * 2 + voice]; if ((tuplet == 0) || (tuplet->elementsDuration() == tuplet->baseLen().fraction() * tuplet->ratio().numerator())) { tuplet = new Tuplet(score); // int track = staffIdx * 2 + voice; tuplets[staffIdx * 2 + voice] = tuplet; tuplet->setTrack(cr->track()); setTuplet(tuplet, tuple); tuplet->setParent(measure); } tuplet->setTrack(cr->track()); tuplet->setBaseLen(l); tuplet->setDuration(l * tuplet->ratio().denominator()); cr->setTuplet(tuplet); tuplet->add(cr); } cr->setDuration(l); if (cr->type() == Element::Type::REST && (pause == 0 || l == measure->len())) cr->setDurationType(TDuration::DurationType::V_MEASURE); else cr->setDurationType(d); if(!segment->cr(track)) segment->add(cr); Staff* staff = cr->staff(); int numStrings = staff->part()->instr()->stringData()->strings(); bool hasSlur = false; for (int i = 6; i >= 0; --i) { if (strings & (1 << i) && ((6-i) < numStrings)) { Note* note = new Note(score); if (dotted) { // there is at most one dotted note in this guitar pro version NoteDot* dot = new NoteDot(score); dot->setIdx(0); dot->setParent(note); dot->setTrack(track); // needed to know the staff it belongs to (and detect tablature) dot->setVisible(true); note->add(dot); } static_cast<Chord*>(cr)->add(note); hasSlur = readNote(6-i, note); note->setTpcFromPitch(); } } createSlur(hasSlur, staffIdx, cr); if (lyrics) cr->add(lyrics); } int rr = readChar(); if (cr && (cr->type() == Element::Type::CHORD)) { Chord* chord = static_cast<Chord*>(cr); applyBeatEffects(chord, beatEffects); if (rr == ARPEGGIO_DOWN) chord->setStemDirection(MScore::Direction::DOWN); else if (rr == ARPEGGIO_UP) chord->setStemDirection(MScore::Direction::UP); } int r = readChar(); if (r & 0x8) { int rrr = readChar(); qDebug(" 3beat read 0x%02x", rrr); } if (cr && (cr->type() == Element::Type::CHORD) && slide > 0) createSlide(slide, cr, staffIdx); restsForEmptyBeats(segment, measure, cr, l, track, tick); return cr ? cr->actualTicks() : measure->ticks(); }
Waypoint* GTM::fetchNextWaypoint() { unsigned short stringSize; double latitude, longitude; char name[11]; char* comment; unsigned short icon; int i; float altitude; GIntBig wptdate; /* Point to the actual waypoint offset */ if ( VSIFSeekL(pGTMFile, actualWaypointOffset, SEEK_SET) != 0) return NULL; latitude = readDouble(pGTMFile); longitude = readDouble(pGTMFile); if ( !readFile( name, 1, 10 ) ) return NULL; /* Trim string name */ for (i = 9; i >= 0; --i) { if (name[i] != ' ') { name[i+1] = '\0'; break; } } if (i < 0) name[0] = '\0'; /* Read String Length */ stringSize = readUShort(pGTMFile); /* Read Comment String */ comment = (char*) VSIMalloc2(sizeof(char), stringSize+1); if ( stringSize != 0 && !readFile( comment, 1, sizeof(char)*stringSize ) ) { CPLFree(comment); return NULL; } comment[stringSize] = '\0'; /* Read Icon */ icon = readUShort(pGTMFile); /* Display number */ readUChar(pGTMFile); /* Waypoint date */ wptdate = readInt(pGTMFile); if (wptdate != 0) wptdate += GTM_EPOCH; /* Rotation text angle */ readUShort(pGTMFile); /* Altitude */ altitude = readFloat(pGTMFile); Waypoint* poWaypoint = new Waypoint(latitude, longitude, altitude, name, comment, (int) icon, wptdate); /* Set actual waypoint offset to the next it there is one */ ++waypointFetched; if (waypointFetched < nwpts) { actualWaypointOffset += 8 + 8 + 10 + 2 + stringSize + 2 + 1 + 4 + 2 + 4 + 2; } CPLFree(comment); return poWaypoint; }