Пример #1
0
BeatType TimeSigFrac::rtick2beatType(int rtick)
      {
      if (rtick == 0)
            return BeatType::DOWNBEAT;

      if (rtick % dUnitTicks() != 0)
            return BeatType::SUBBEAT;

      if (isCompound()) {
            if (rtick % beatTicks() != 0)
                  return BeatType::COMPOUND_SUBBEAT;
            }

      const int beatNum = rtick / beatTicks();

      int stressBeat = 0;
      if (isTriple())
            stressBeat = 3;
      else if (isDuple())
            stressBeat = 2;

      if (stressBeat && beatNum % stressBeat == 0)
            return isCompound() ? BeatType::SIMPLE_STRESSED : BeatType::COMPOUND_STRESSED;

      return isCompound() ? BeatType::SIMPLE_UNSTRESSED : BeatType::COMPOUND_UNSTRESSED;
      }
int solutionsFor(int p){
	int ans = 0;
	for(int i = 1; i < p; i++){
		for(int j = i + 1; j < p - i; j++){
			int k = p - i - j;
			if(isTriple(i, j, k)) ans++;
		}
	}
	return ans;
}
// The function walks the given buffer and provides two things:
// - an array of absolute positions of the beginning of each line
// - a deque of found comments
void getLineShiftsAndComments( const char *  buffer, int *  lineShifts,
                               std::deque< CommentLine > &  comments )
{
    int             absPos = 0;
    char            symbol;
    int             line = 1;
    int             column = 1;
    ExpectState     expectState = expectCommentStart;
    CommentLine     comment;

    /* index 0 is not used; The first line starts with shift 0 */
    lineShifts[ 1 ] = 0;
    while ( buffer[ absPos ] != '\0' )
    {
        symbol = buffer[ absPos ];

        if ( symbol == '#' )
        {
            if ( expectState == expectCommentStart )
            {
                comment.begin = absPos;
                comment.line = line;
                comment.pos = column;
                expectState = expectCommentEnd;

                ++absPos;
                ++column;
                continue;
            }
        }
        else if ( expectState != expectCommentEnd )
        {
            if ( symbol == '\"' || symbol == '\'' )
            {
                if ( isEscaped( buffer, absPos ) )
                {
                    ++absPos;
                    ++column;
                    continue;
                }

                // It is not escaped some kind of quote
                if ( symbol == '\"' &&
                        ( expectState == expectClosingSingleQuote ||
                          expectState == expectClosingTripleSingleQuote ) )
                {
                    // " inside ' or '''
                    ++absPos;
                    ++column;
                    continue;
                }
                if ( symbol == '\'' &&
                        ( expectState == expectClosingDoubleQuote ||
                          expectState == expectClosingTripleDoubleQuote ) )
                {
                    // ' inside " or """
                    ++absPos;
                    ++column;
                    continue;
                }

                // String literal beginning case
                if ( expectState == expectCommentStart )
                {
                    if ( isTriple( buffer, absPos ) == true )
                    {
                        if ( symbol == '\"' )
                            expectState = expectClosingTripleDoubleQuote;
                        else
                            expectState = expectClosingTripleSingleQuote;
                        absPos += 3;
                        column += 3;
                    }
                    else
                    {
                        if ( symbol == '\"' )
                            expectState = expectClosingDoubleQuote;
                        else
                            expectState = expectClosingSingleQuote;
                        ++absPos;
                        ++column;
                    }
                    continue;
                }

                // String literal end case
                if ( expectState == expectClosingSingleQuote ||
                     expectState == expectClosingDoubleQuote )
                {
                    expectState = expectCommentStart;
                    ++absPos;
                    ++column;
                    continue;
                }
                else if ( expectState == expectClosingTripleSingleQuote ||
                          expectState == expectClosingTripleDoubleQuote )
                {
                    if ( isTriple( buffer, absPos ) == true )
                    {
                        expectState = expectCommentStart;
                        absPos += 3;
                        column += 3;
                        continue;
                    }
                    ++absPos;
                    ++column;
                    continue;
                }
                else
                    throw std::runtime_error( "Fatal error: unknown quote state" );
            }
        }



        if ( symbol == '\r' )
        {
            comment.end = absPos - 1;   // will not harm but will unify the code
            ++absPos;
            if ( buffer[ absPos ] == '\n' )
            {
                ++absPos;
            }
            ++line;
            lineShifts[ line ] = absPos;
            column = 1;
            if ( expectState == expectCommentEnd )
            {
                comment.detectType( buffer );
                comments.push_back( comment );
                comment.begin = -1;
                expectState = expectCommentStart;
            }
            continue;
        }

        if ( symbol == '\n' )
        {
            comment.end = absPos - 1;   // will not harm but will unify the code
            ++absPos;
            ++line;
            lineShifts[ line ] = absPos;
            column = 1;
            if ( expectState == expectCommentEnd )
            {
                comment.detectType( buffer );
                comments.push_back( comment );
                comment.begin = -1;
                expectState = expectCommentStart;
            }
            continue;
        }
        ++absPos;
        ++column;
    }

    if ( comment.begin != -1 )
    {
        // Need to flush the collected comment
        comment.detectType( buffer );
        comment.end = absPos - 1;
        comments.push_back( comment );
    }

    return;
}