コード例 #1
0
ファイル: uParserBed.cpp プロジェクト: NGS-lib/NGSplusplus
/** \brief Initialize the uParserBed object (open file and parse header).
 * \param const std::string& filename: name of the bed file to parse.
 * \param bool header: true if there is a header to parse (value at false by default).
 */
void uParserBed::init(const std::string& filename, bool header)
{
    uParserBase::init(filename, header);
    if (header == true)
    {
        _parseHeader();
    }
    m_headerParsed = true;
    m_delimiter = '\t';
}
コード例 #2
0
int NDHttpRequest::ParseData()
{
	if (0== m_parseStat) {
		return _parseInit() ;
	}
	else if(1==m_parseStat) {
		return _parseHeader();
	}
	else if(2==m_parseStat){
		return _parseBody() ;
	}
	return 0;
}
コード例 #3
0
//
// setString():
//
void MadelineTable::setString(std::string inString){
	
	_readString(inString);
	_getLineCount();
	_allocateLineInformationVector();
	_assignLinePointers();
	_determineNumberOfBlocks();
	_assignRecordTypes();
	_checkDataBlockRectangularity();
	_calculateColumnFillRates();
	_determineNumberOfColumns();
	_determineFieldBoundaries();
	_parseHeader();
	//
	// Now Handled downstream in DataTable instead: 
	//_classifyColumns();
	// This is basically obsoleted now because DataTable now handles classification: 
	//_resolveDeclaredVersusDiscoveredColumnTypes();
	//
	_fillVectors();
	// DEBUG:
	//display();
}
コード例 #4
0
ファイル: MidiParser.cpp プロジェクト: CalculatorSP/xbot2014
Song* MidiParser::parseMidi(const char* filename, Instrument instrument, SongDifficulty difficulty)
{
    Song* song = new Song();
    FILE* fp;
    uint64_t currentTimestamp = 0;
    NoteEvent* lastStage = NULL;
    bool press = false;
    bool lastEventPress = false;
    bool stagedForRelease[5] = { false, false, false, false, false };

    if (fopen_s(&fp, filename, "rb"))
        return NULL;

    // Add release at beginning of song
    NoteEvent initialEvent;
    initialEvent.timestamp = 0;
    initialEvent.key = GREEN;
    initialEvent.press = false;
    initialEvent.type = PREPARE;
    song->add(initialEvent);
    initialEvent.key = RED;
    song->add(initialEvent);
    initialEvent.key = YELLOW;
    song->add(initialEvent);
    initialEvent.key = BLUE;
    song->add(initialEvent);
    initialEvent.key = ORANGE;
    song->add(initialEvent);
    initialEvent.timestamp = 250;
    initialEvent.type = ACTUATE;
    song->add(initialEvent);

    // Get tempo from header track
    uint64_t microsPerTick = _parseHeader(fp);

    // For bass part, skip guitar track
    uint32_t trackLen;
    fseek(fp, 4, SEEK_CUR);
    fread_s(&trackLen, 4, 4, 1, fp);
    trackLen = _byteswap_ulong(trackLen);
    if (instrument == BASS)
    {
        fseek(fp, trackLen + 4, SEEK_CUR);
        fread_s(&trackLen, 4, 4, 1, fp);
        trackLen = _byteswap_ulong(trackLen);
    }

    // Parse instrument track
    long endPos = ftell(fp) + trackLen;
    uint64_t lastUsedTimestamp = 0;
    while (ftell(fp) < endPos)
    {
        // Update running timestamp
        uint64_t deltaTime = (uint64_t)(_readVariableLen(fp)) * microsPerTick;
        currentTimestamp += deltaTime;
        uint8_t cmd;
        fread_s(&cmd, 1, 1, 1, fp);

        // Skip any meta events
        if (cmd == 0xFF)
        {
            fseek(fp, 1, SEEK_CUR);
            fseek(fp, _readVariableLen(fp), SEEK_CUR);
        }
        else
        {
            NoteEvent noteEvent;
            noteEvent.type = PREPARE;
            bool goodEvent = true;

            // Check if button is pressed or released
            if (cmd == 0x90)
            {
                press = true;
                fread_s(&cmd, 1, 1, 1, fp);
            }
            else if (cmd == 0x80)
            {
                press = false;
                fread_s(&cmd, 1, 1, 1, fp);
            }
            noteEvent.press = press;

            if (press)
                noteEvent.timestamp = currentTimestamp - 250;	// PREPARE needs to happen before ACTUATE
            else
                noteEvent.timestamp = currentTimestamp - 750;	// Release needs to happen before press
            
            // Get key based on difficulty
            if (cmd == _greenButton[difficulty])
                noteEvent.key = GREEN;
            else if (cmd == _redButton[difficulty])
                noteEvent.key = RED;
            else if (cmd == _yellowButton[difficulty])
                noteEvent.key = YELLOW;
            else if (cmd == _blueButton[difficulty])
                noteEvent.key = BLUE;
            else if (cmd == _orangeButton[difficulty])
                noteEvent.key = ORANGE;
            else
                goodEvent = false;

            if (goodEvent)
            {
                bool isChord = false;

                // If we have a new timestamp, we need to have an actuation of the previous note
                if (noteEvent.timestamp > lastUsedTimestamp)
                {
                    NoteEvent actuateEvent;
                    actuateEvent.timestamp = lastUsedTimestamp + 250;
                    actuateEvent.key = GREEN;
                    actuateEvent.press = false;
                    if (lastEventPress)
                    {
                        actuateEvent.type = ACTUATE;
                        for (int i = 0; i < 5; ++i)
                            stagedForRelease[i] = false;
                        lastStage = NULL;
                    }
                    else
                        actuateEvent.type = STAGE;

                    song->add(actuateEvent);

                    if (actuateEvent.type == STAGE)
                        lastStage = &(*song)[song->size - 1];

                    lastUsedTimestamp = noteEvent.timestamp;
                }
                else
                    isChord = true;

                // If this buttonpress is staged for release, we need to commit the previous actuate event first
                if ((isChord || (noteEvent.press && stagedForRelease[noteEvent.key])) && lastStage != NULL)
                {
                    lastStage->type = ACTUATE;
                    for (int i = 0; i < 5; ++i)
                        stagedForRelease[i] = false;
                    lastStage = NULL;
                }

                song->add(noteEvent);

                if (!noteEvent.press)
                    stagedForRelease[noteEvent.key] = true;

                lastEventPress = noteEvent.press;
            }

            // Skip velocity
            fseek(fp, 1, SEEK_CUR);
        }
    }

    // Add release at end of song
    NoteEvent finalEvent;
    finalEvent.timestamp = lastUsedTimestamp + 250;
    finalEvent.key = GREEN;
    finalEvent.press = false;
    finalEvent.type = ACTUATE;
    song->add(finalEvent);

    return song;
}