Esempio n. 1
0
    bool isSameMajorVersion( const char* version ) {

        BSONArray remoteVersionArray = toVersionArray( version );

        BSONObjIterator remoteIt(remoteVersionArray);
        BSONObjIterator myIt(versionArray);

        // Compare only the first two fields of the version
        int compareLen = 2;
        while (compareLen > 0 && remoteIt.more() && myIt.more()) {
            if (remoteIt.next().numberInt() != myIt.next().numberInt()) break;
            compareLen--;
        }

        return compareLen == 0;
    }
Esempio n. 2
0
void Cancion::parsear(){
    pugi::xml_document documento;
    pugi::xml_parse_result resultado;
    pugi::xml_node nodoActual, nodoVacio;

    resultado = documento.load_file(ruta.c_str());
    if(!resultado){
        lERROR << "ERROR";
    }

    tituloCancion = documento.child("Song").child("Title").first_child().value();
    descripcionCancion =  documento.child("Song").child("Desc").first_child().value();;
    bpm = boost::lexical_cast<int>(documento.child("Song").child("BPM").first_child().value());

    string cadenaNotas = documento.child("Song").child("Notes").first_child().value();

    // Expresión regular para cazar las notas
    boost::regex myRegExp("(do|re|mi|fa|sol|la|si|xx)(5|6|0)(r|b|n|c)(p)?");

    // Iterador de regexp para iterar por las diferentes notas captadas
    boost::sregex_iterator myIt(cadenaNotas.begin(), cadenaNotas.end(), myRegExp), itEnd;

    float acumulado = 0;


    for(;myIt != itEnd; myIt++){
        bool puntillo = ((*myIt)[4] == "p");
        string figura = (*myIt)[3];
        string alturaRead = string((*myIt)[1]) + string((*myIt)[2]);

        t_altura alturaLocal = Do5;
        t_figura figuraLocal = (t_figura) Negra | Puntillo;
        float duracionLocal = 0;

        if(alturaRead == "do5") alturaLocal = Do5;
        else if(alturaRead == "re5") alturaLocal = Re5;
        else if(alturaRead == "mi5") alturaLocal = Mi5;
        else if(alturaRead == "fa5") alturaLocal = Fa5;
        else if(alturaRead == "sol5") alturaLocal = Sol5;
        else if(alturaRead == "la5") alturaLocal = La5;
        else if(alturaRead == "si5") alturaLocal = Si5;
        else if(alturaRead == "do6") alturaLocal = Do6;
        else if(alturaRead == "re6") alturaLocal = Re6;
        else if(alturaRead == "xx0") alturaLocal = Silencio;

        if(figura == "r"){
            figuraLocal = Redonda;
            duracionLocal = 4;
        }

        else if(figura == "b"){
            figuraLocal = Blanca;
            duracionLocal = 2;
        }

        else if(figura == "n"){
            figuraLocal = Negra;
            duracionLocal = 1;
        }

        else if(figura == "c"){
            figuraLocal = Corchea;
            duracionLocal = 0.5;
        }

        if(puntillo){
            duracionLocal += duracionLocal / 2;
            figuraLocal = figuraLocal | Puntillo;
        }

        conjNotas.push_back(boost::shared_ptr<Nota>(new Nota(g, alturaLocal, 
                                                             figuraLocal, acumulado)));
        acumulado += duracionLocal;

    }

    conjNotas.push_back(boost::shared_ptr<Nota>(new NotaFinal(g, acumulado)));

    numeroInicialNotas = conjNotas.size();

    lDEBUG << "BPM: " << bpm;
    milisegundosPorPulso = 1 / (bpm / 60.) * 1000;
    lDEBUG << "El espacio entre pulsos es " << milisegundosPorPulso << " ms";


    lDEBUG << "El intervalo de refresco es " << REFRESCO << " ms";
    // frecuencia = 1000./REFRESCO;
    // lDEBUG << "La frecuencia es de " << frecuencia << " Hz, es decir, salen " << frecuencia
	//    << " fotogramas por segundo.";

    lDEBUG << "La distancia de un pulso (espacio entre dos negras) es " << distanciaPulso << " px";
    lDEBUG << "Con " << bpm << " pulsos por minuto, se recorren " 
           << distanciaPulso * bpm << " píxeles por minuto, ó " 
           << distanciaPulso * bpm / 60. << " píxeles por segundo.";

    duracionCancion = acumulado * milisegundosPorPulso;
    maximoPuntos = incrementoDePuntos * (duracionCancion / REFRESCO);

    lDEBUG << "El total de tiempos de la canción es de " << acumulado << " pulsos.";
    lDEBUG << "El tiempo de la canción será de: " << duracionCancion << " ms";
    lDEBUG << "En cada lectura, se añadirán " << incrementoDePuntos << " puntos.";
    lDEBUG << "Máximo de puntos: " << maximoPuntos;

}