Beispiel #1
0
QVariantHash FSTReader::parseMapping(QIODevice* device) {
    QVariantHash properties;
    
    QByteArray line;
    while (!(line = device->readLine()).isEmpty()) {
        if ((line = line.trimmed()).startsWith('#')) {
            continue; // comment
        }
        QList<QByteArray> sections = line.split('=');
        if (sections.size() < 2) {
            continue;
        }
        QByteArray name = sections.at(0).trimmed();
        if (sections.size() == 2) {
            properties.insertMulti(name, sections.at(1).trimmed());
            
        } else if (sections.size() == 3) {
            QVariantHash heading = properties.value(name).toHash();
            heading.insertMulti(sections.at(1).trimmed(), sections.at(2).trimmed());
            properties.insert(name, heading);
            
        } else if (sections.size() >= 4) {
            QVariantHash heading = properties.value(name).toHash();
            QVariantList contents;
            for (int i = 2; i < sections.size(); i++) {
                contents.append(sections.at(i).trimmed());
            }
            heading.insertMulti(sections.at(1).trimmed(), contents);
            properties.insert(name, heading);
        }
    }
    
    return properties;
}
Beispiel #2
0
QByteArray ViewJson::render(Context *c) const
{
    Q_D(const ViewJson);

    QByteArray ret;
    QJsonObject obj;

    const QVariantHash stash = c->stash();

    switch (d->exposeMode) {
    case All:
        obj = QJsonObject::fromVariantHash(stash);
        break;
    case String:
    {
        auto it = stash.constFind(d->exposeKey);
        if (it != stash.constEnd()) {
            obj.insert(d->exposeKey, QJsonValue::fromVariant(it.value()));
        }
        break;
    }
    case StringList:
    {
        QVariantHash exposedStash;

        auto it = stash.constBegin();
        while (it != stash.constEnd()) {
            const QString key = it.key();
            if (d->exposeKeys.contains(key)) {
                exposedStash.insertMulti(it.key(), it.value());
            }
            ++it;
        }
        obj = QJsonObject::fromVariantHash(exposedStash);
        break;
    }
    case RegularExpression:
    {
        QVariantHash exposedStash;
        QRegularExpression re = d->exposeRE; // thread safety

        auto it = stash.constBegin();
        while (it != stash.constEnd()) {
            const QString key = it.key();
            if (re.match(key).hasMatch()) {
                exposedStash.insertMulti(key, it.value());
            }
            ++it;
        }
        obj = QJsonObject::fromVariantHash(exposedStash);
        break;
    }
    }

    c->response()->setContentType(QStringLiteral("application/json"));

    ret = QJsonDocument(obj).toJson(d->format);
    return ret;
}
Beispiel #3
0
void Asterisk::onSocketReadyRead()
{
//    qDebug("<ready-read>");

    QVariantHash headers;

    while (socket.canReadLine()) {
        QByteArray line = socket.readLine();

//        qDebug() << "Line:" << line;

        if (line != "\r\n") {
            QStringList header = QString(line.trimmed()).split(':');

            headers.insertMulti(header[0], decodeValue(header[1].trimmed()));
        } else {
            if (headers.contains("Response"))
                responses.insert(headers.take("ActionID").toString(), headers);
            else if (headers.contains("Event"))
                emit eventReceived(headers.take("Event").toString(), headers);

            headers.clear();
        }
    }

//    qDebug("</ready-read>");
}
Beispiel #4
0
QVariantHash Asterisk::originate(QString channel,
                                 QString exten,
                                 QString context,
                                 uint priority,
                                 QString application,
                                 QString data,
                                 uint timeout,
                                 QString callerId,
                                 QVariantHash variables,
                                 QString account,
                                 bool earlyMedia,
                                 bool async,
                                 QStringList codecs)
{
    QVariantHash headers;
    headers["Channel"] = channel;
    headers["EarlyMedia"] = earlyMedia;
    headers["Async"] = async;

    insertNotEmpty(&headers, "Timeout", timeout);
    insertNotEmpty(&headers, "CallerID", callerId);
    insertNotEmpty(&headers, "Account", account);
    insertNotEmpty(&headers, "Codecs", codecs.join(","));

    if (!exten.isEmpty() && !context.isEmpty() && priority > 0) {
        headers["Exten"] = exten;
        headers["Context"] = context;
        headers["Priority"] = priority;
    }

    if (!application.isEmpty()) {
        headers["Application"] = application;

        insertNotEmpty(&headers, "Data", data);
    }

    if (!variables.isEmpty()) {
        QHashIterator<QString, QVariant> variable(variables);
        while (variable.hasNext()) {
            variable.next();

            headers.insertMulti("Variable", QString("%1=%2").arg(variable.key(), encodeValue(variable.value())));
        }
    }

    return sendPacket("Originate", headers);
}
Beispiel #5
0
void ModelPackager::populateBasicMapping(QVariantHash& mapping, QString filename, const hfm::Model& hfmModel) {

    // mixamo files - in the event that a mixamo file was edited by some other tool, it's likely the applicationName will
    // be rewritten, so we detect the existence of several different blendshapes which indicate we're likely a mixamo file
    bool likelyMixamoFile = hfmModel.applicationName == "mixamo.com" ||
                            (hfmModel.blendshapeChannelNames.contains("BrowsDown_Right") &&
                             hfmModel.blendshapeChannelNames.contains("MouthOpen") &&
                             hfmModel.blendshapeChannelNames.contains("Blink_Left") &&
                             hfmModel.blendshapeChannelNames.contains("Blink_Right") &&
                             hfmModel.blendshapeChannelNames.contains("Squint_Right"));
    
    if (!mapping.contains(NAME_FIELD)) {
        mapping.insert(NAME_FIELD, QFileInfo(filename).baseName());
    }
    
    if (!mapping.contains(FILENAME_FIELD)) {
        QDir root(_modelFile.path());
        mapping.insert(FILENAME_FIELD, root.relativeFilePath(filename));
    }
    if (!mapping.contains(TEXDIR_FIELD)) {
        mapping.insert(TEXDIR_FIELD, ".");
    }
    if (!mapping.contains(SCRIPT_FIELD)) {
        mapping.insert(SCRIPT_FIELD, ".");
    }
    // mixamo/autodesk defaults
    if (!mapping.contains(SCALE_FIELD)) {
        mapping.insert(SCALE_FIELD, 1.0);
    }
    QVariantHash joints = mapping.value(JOINT_FIELD).toHash();
    if (!joints.contains("jointEyeLeft")) {
        joints.insert("jointEyeLeft", hfmModel.jointIndices.contains("jointEyeLeft") ? "jointEyeLeft" :
                      (hfmModel.jointIndices.contains("EyeLeft") ? "EyeLeft" : "LeftEye"));
    }
    if (!joints.contains("jointEyeRight")) {
        joints.insert("jointEyeRight", hfmModel.jointIndices.contains("jointEyeRight") ? "jointEyeRight" :
                      hfmModel.jointIndices.contains("EyeRight") ? "EyeRight" : "RightEye");
    }
    if (!joints.contains("jointNeck")) {
        joints.insert("jointNeck", hfmModel.jointIndices.contains("jointNeck") ? "jointNeck" : "Neck");
    }
    
    if (!joints.contains("jointRoot")) {
        joints.insert("jointRoot", "Hips");
    }
    if (!joints.contains("jointLean")) {
        joints.insert("jointLean", "Spine");
    }
    if (!joints.contains("jointLeftHand")) {
        joints.insert("jointLeftHand", "LeftHand");
    }
    if (!joints.contains("jointRightHand")) {
        joints.insert("jointRightHand", "RightHand");
    }
    
    if (!joints.contains("jointHead")) {
        const char* topName = likelyMixamoFile ? "HeadTop_End" : "HeadEnd";
        joints.insert("jointHead", hfmModel.jointIndices.contains(topName) ? topName : "Head");
    }

    mapping.insert(JOINT_FIELD, joints);

    if (!mapping.contains(FREE_JOINT_FIELD)) {
        mapping.insertMulti(FREE_JOINT_FIELD, "LeftArm");
        mapping.insertMulti(FREE_JOINT_FIELD, "LeftForeArm");
        mapping.insertMulti(FREE_JOINT_FIELD, "RightArm");
        mapping.insertMulti(FREE_JOINT_FIELD, "RightForeArm");
    }
    
    // If there are no blendshape mappings, and we detect that this is likely a mixamo file,
    // then we can add the default mixamo to "faceshift" mappings
    if (!mapping.contains(BLENDSHAPE_FIELD) && likelyMixamoFile) {
        QVariantHash blendshapes;
        blendshapes.insertMulti("BrowsD_L", QVariantList() << "BrowsDown_Left" << 1.0);
        blendshapes.insertMulti("BrowsD_R", QVariantList() << "BrowsDown_Right" << 1.0);
        blendshapes.insertMulti("BrowsU_C", QVariantList() << "BrowsUp_Left" << 1.0);
        blendshapes.insertMulti("BrowsU_C", QVariantList() << "BrowsUp_Right" << 1.0);
        blendshapes.insertMulti("BrowsU_L", QVariantList() << "BrowsUp_Left" << 1.0);
        blendshapes.insertMulti("BrowsU_R", QVariantList() << "BrowsUp_Right" << 1.0);
        blendshapes.insertMulti("ChinLowerRaise", QVariantList() << "Jaw_Up" << 1.0);
        blendshapes.insertMulti("ChinUpperRaise", QVariantList() << "UpperLipUp_Left" << 0.5);
        blendshapes.insertMulti("ChinUpperRaise", QVariantList() << "UpperLipUp_Right" << 0.5);
        blendshapes.insertMulti("EyeBlink_L", QVariantList() << "Blink_Left" << 1.0);
        blendshapes.insertMulti("EyeBlink_R", QVariantList() << "Blink_Right" << 1.0);
        blendshapes.insertMulti("EyeOpen_L", QVariantList() << "EyesWide_Left" << 1.0);
        blendshapes.insertMulti("EyeOpen_R", QVariantList() << "EyesWide_Right" << 1.0);
        blendshapes.insertMulti("EyeSquint_L", QVariantList() << "Squint_Left" << 1.0);
        blendshapes.insertMulti("EyeSquint_R", QVariantList() << "Squint_Right" << 1.0);
        blendshapes.insertMulti("JawFwd", QVariantList() << "JawForeward" << 1.0);
        blendshapes.insertMulti("JawLeft", QVariantList() << "JawRotateY_Left" << 0.5);
        blendshapes.insertMulti("JawOpen", QVariantList() << "MouthOpen" << 0.7);
        blendshapes.insertMulti("JawRight", QVariantList() << "Jaw_Right" << 1.0);
        blendshapes.insertMulti("LipsFunnel", QVariantList() << "JawForeward" << 0.39);
        blendshapes.insertMulti("LipsFunnel", QVariantList() << "Jaw_Down" << 0.36);
        blendshapes.insertMulti("LipsFunnel", QVariantList() << "MouthNarrow_Left" << 1.0);
        blendshapes.insertMulti("LipsFunnel", QVariantList() << "MouthNarrow_Right" << 1.0);
        blendshapes.insertMulti("LipsFunnel", QVariantList() << "MouthWhistle_NarrowAdjust_Left" << 0.5);
        blendshapes.insertMulti("LipsFunnel", QVariantList() << "MouthWhistle_NarrowAdjust_Right" << 0.5);
        blendshapes.insertMulti("LipsFunnel", QVariantList() << "TongueUp" << 1.0);
        blendshapes.insertMulti("LipsLowerClose", QVariantList() << "LowerLipIn" << 1.0);
        blendshapes.insertMulti("LipsLowerDown", QVariantList() << "LowerLipDown_Left" << 0.7);
        blendshapes.insertMulti("LipsLowerDown", QVariantList() << "LowerLipDown_Right" << 0.7);
        blendshapes.insertMulti("LipsLowerOpen", QVariantList() << "LowerLipOut" << 1.0);
        blendshapes.insertMulti("LipsPucker", QVariantList() << "MouthNarrow_Left" << 1.0);
        blendshapes.insertMulti("LipsPucker", QVariantList() << "MouthNarrow_Right" << 1.0);
        blendshapes.insertMulti("LipsUpperClose", QVariantList() << "UpperLipIn" << 1.0);
        blendshapes.insertMulti("LipsUpperOpen", QVariantList() << "UpperLipOut" << 1.0);
        blendshapes.insertMulti("LipsUpperUp", QVariantList() << "UpperLipUp_Left" << 0.7);
        blendshapes.insertMulti("LipsUpperUp", QVariantList() << "UpperLipUp_Right" << 0.7);
        blendshapes.insertMulti("MouthDimple_L", QVariantList() << "Smile_Left" << 0.25);
        blendshapes.insertMulti("MouthDimple_R", QVariantList() << "Smile_Right" << 0.25);
        blendshapes.insertMulti("MouthFrown_L", QVariantList() << "Frown_Left" << 1.0);
        blendshapes.insertMulti("MouthFrown_R", QVariantList() << "Frown_Right" << 1.0);
        blendshapes.insertMulti("MouthLeft", QVariantList() << "Midmouth_Left" << 1.0);
        blendshapes.insertMulti("MouthRight", QVariantList() << "Midmouth_Right" << 1.0);
        blendshapes.insertMulti("MouthSmile_L", QVariantList() << "Smile_Left" << 1.0);
        blendshapes.insertMulti("MouthSmile_R", QVariantList() << "Smile_Right" << 1.0);
        blendshapes.insertMulti("Puff", QVariantList() << "CheekPuff_Left" << 1.0);
        blendshapes.insertMulti("Puff", QVariantList() << "CheekPuff_Right" << 1.0);
        blendshapes.insertMulti("Sneer", QVariantList() << "NoseScrunch_Left" << 0.75);
        blendshapes.insertMulti("Sneer", QVariantList() << "NoseScrunch_Right" << 0.75);
        blendshapes.insertMulti("Sneer", QVariantList() << "Squint_Left" << 0.5);
        blendshapes.insertMulti("Sneer", QVariantList() << "Squint_Right" << 0.5);
        mapping.insert(BLENDSHAPE_FIELD, blendshapes);
    }
}