Esempio n. 1
0
QString FileHelper::extractGenericFeature(const QString &featureToExtract) const
{
	QString feature;
	TagLib::PropertyMap p = _file->properties();
	if (p.contains(featureToExtract.toStdString().data())) {
		TagLib::StringList list = p[featureToExtract.toStdString().data()];
		if (!list.isEmpty()) {
			feature = list.front().toCString(true);
		}
	}
	return feature;
}
Esempio n. 2
0
BlockResult Block::eval(const TagLib::PropertyMap& metadata)
{
    BlockResult result;

    std::sort(this->variables.begin(), this->variables.end() ,
    [](Block::Variable a, Block::Variable  b) {
        return a.pos < b.pos;
    });
    std::sort(this->functions.begin(), this->functions.end() ,
    [](Block::Function a, Block::Function  b) {
        return a.pos < b.pos;
    });

    result.success = false;
    result.result = this->parsed_statement;

    int offset = 0;
    auto var_itr = this->variables.begin();
    auto func_itr = this->functions.begin();

    // Iterate over the Function and Variables lists in order of appearance in the raw statement
    while (var_itr != this->variables.end() || func_itr != this->functions.end()) {
        bool eval_var = true;

        // Decide if the next item to be evaluated should be a variable or a function call
        if (var_itr == this->variables.end()) {
            eval_var = false;
        } else if (func_itr != this->functions.end()) {
            // Check the positions of the statements in the raw string
            if ((*var_itr).raw_pos > (*func_itr).raw_pos) {
                eval_var = false;
            }
        }

        if (eval_var) {
            if (metadata.contains((*var_itr).name)) {
                // insert at the index of the variable
                // TODO : alias some names, e.g. tacknumber -> track
                std::string meta = metadata[(*var_itr).name].toString().toCString(false);
                result.result.insert((*var_itr).pos + offset, meta);
                offset += meta.length();

                result.success = true;
            }
        } else {
            if (FunctionMap.find((*func_itr).name) != FunctionMap.end()) {
                // Call function
                BlockResult func_result = FunctionMap[(*func_itr).name].eval(metadata, (*func_itr).args);

                // OR'd to keep existing successes
                result.success |= func_result.success;

                result.result.insert((*func_itr).pos + offset, func_result.result);
                offset += func_result.result.length();
            } else {
                // Throw unknown function exception
            }
        }

        if (eval_var) {
            var_itr++;
        } else {
            func_itr++;
        }
    }

    /**
     * Using this conversion from String to integer it will allow for the
     * convention of:
     *	"c3po" → 0
     *	"4.8"  → 4
     *	"-12"  → -12
     *	"- 12" → 0
     */
    std::stringstream ss(result.result);
    ss >> result.value;

    return result;
}