diff --git a/MappingManager.cpp b/MappingManager.cpp index af5461e..36779f3 100644 --- a/MappingManager.cpp +++ b/MappingManager.cpp @@ -42,6 +42,27 @@ QMap MappingManager::getPaintMappings(const Paint::ptr paint) return paintMappings; } + +Paint::ptr MappingManager::getPaintByName(QString name) +{ + return _getElementByName(paintVector, name); +} + +QVector MappingManager::getPaintsByNameRegExp(QString namePattern) +{ + return _getElementsByNameRegExp(paintVector, namePattern); +} + +Mapping::ptr MappingManager::getMappingByName(QString name) +{ + return _getElementByName(mappingVector, name); +} + +QVector MappingManager::getMappingsByNameRegExp(QString namePattern) +{ + return _getElementsByNameRegExp(mappingVector, namePattern); +} + QMap MappingManager::getPaintMappingsById(uid paintId) const { return getPaintMappings(paintMap[paintId]); diff --git a/MappingManager.h b/MappingManager.h index 21daae0..4f320b8 100644 --- a/MappingManager.h +++ b/MappingManager.h @@ -81,6 +81,12 @@ public: /// Returns paint with given uid. Paint::ptr getPaintById(uid id) { return paintMap[id]; } + /// Returns mapping with given name (first match). + Paint::ptr getPaintByName(QString name); + + /// Returns all mappings with given regexp. + QVector getPaintsByNameRegExp(QString namePattern); + /// Adds a mapping and returns its uid. uid addMapping(Mapping::ptr mapping); @@ -99,6 +105,12 @@ public: /// Returns mapping with given uid. Mapping::ptr getMappingById(uid id) { return mappingMap[id]; } + /// Returns mapping with given name (first match). + Mapping::ptr getMappingByName(QString name); + + /// Returns all mappings with given regexp. + QVector getMappingsByNameRegExp(QString namePattern); + /// Reorders the mappings according to given list of uids. QVector needs to void reorderMappings(QVector mappingIds); @@ -112,6 +124,36 @@ public: QVector getVisiblePaints() const; void clearAll(); + +private: + template + QSharedPointer _getElementByName(const QVector >& vector, QString name) + { + foreach (QSharedPointer it, vector) + { + if (it->getName() == name) + { + return it; + } + } + // Nothing found. + return QSharedPointer(); + } + + template + QVector > _getElementsByNameRegExp(const QVector >& vector, QString namePattern) + { + QVector > matchedElems; + QRegExp regExp(namePattern, Qt::CaseSensitive, QRegExp::Wildcard); + foreach (QSharedPointer it, vector) + { + if (regExp.exactMatch(it->getName())) + { + matchedElems.push_back(it); + } + } + return matchedElems; + } }; MM_END_NAMESPACE diff --git a/OscInterface.cpp b/OscInterface.cpp index 507f61b..bf492a4 100644 --- a/OscInterface.cpp +++ b/OscInterface.cpp @@ -192,21 +192,44 @@ void OscInterface::applyOscCommand(MainWindow &main_window, QVariantList & comma iterator = next(iterator.second); if (iterator.first == OSC_PAINT) { - // Find paint. - int id = command.at(2).toInt(); - Paint::ptr elem = main_window.getMappingManager().getPaintById(id); - iterator = next(iterator.second); - if (iterator.first == OSC_REWIND) - elem->rewind(); + // Find paint (or paints). + QVector paints; + if (command.at(2).type() == QVariant::String) + paints = main_window.getMappingManager().getPaintsByNameRegExp(command.at(2).toString()); else - pathIsValid = setElementProperty(elem, iterator.first, command.at(3)); + { + int id = command.at(2).toInt(); + paints.push_back(main_window.getMappingManager().getPaintById(id)); + } + // Process all paints. + pathIsValid = true; + iterator = next(iterator.second); + foreach (Paint::ptr elem, paints) + { + if (iterator.first == OSC_REWIND) + elem->rewind(); + else + pathIsValid &= setElementProperty(elem, iterator.first, command.at(3)); + } } else if (iterator.first == OSC_MAPPING) { - // Find mapping. - int id = command.at(2).toInt(); - Mapping::ptr elem = main_window.getMappingManager().getMappingById(id); - pathIsValid = setElementProperty(elem, next(iterator.second).first, command.at(3)); + // Find mapping (or mappings). + QVector mappings; + if (command.at(2).type() == QVariant::String) + mappings = main_window.getMappingManager().getMappingsByNameRegExp(command.at(2).toString()); + else + { + int id = command.at(2).toInt(); + mappings.push_back(main_window.getMappingManager().getMappingById(id)); + } + // Process all mappings. + pathIsValid = true; + iterator = next(iterator.second); + foreach (Mapping::ptr elem, mappings) + { + pathIsValid &= setElementProperty(elem, iterator.first, command.at(3)); + } } else if (iterator.first == OSC_PLAY) {