Allow OSC message addressing of paints and mappings by names through regular expressions.

This commit is contained in:
Tats
2016-05-13 01:31:53 +00:00
parent 7ac70e7cf7
commit f9633b0065
3 changed files with 97 additions and 11 deletions
+21
View File
@@ -42,6 +42,27 @@ QMap<uid, Mapping::ptr> MappingManager::getPaintMappings(const Paint::ptr paint)
return paintMappings;
}
Paint::ptr MappingManager::getPaintByName(QString name)
{
return _getElementByName(paintVector, name);
}
QVector<Paint::ptr> MappingManager::getPaintsByNameRegExp(QString namePattern)
{
return _getElementsByNameRegExp(paintVector, namePattern);
}
Mapping::ptr MappingManager::getMappingByName(QString name)
{
return _getElementByName(mappingVector, name);
}
QVector<Mapping::ptr> MappingManager::getMappingsByNameRegExp(QString namePattern)
{
return _getElementsByNameRegExp(mappingVector, namePattern);
}
QMap<uid, Mapping::ptr> MappingManager::getPaintMappingsById(uid paintId) const
{
return getPaintMappings(paintMap[paintId]);
+42
View File
@@ -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<Paint::ptr> 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<Mapping::ptr> getMappingsByNameRegExp(QString namePattern);
/// Reorders the mappings according to given list of uids. QVector needs to
void reorderMappings(QVector<uid> mappingIds);
@@ -112,6 +124,36 @@ public:
QVector<Paint::ptr> getVisiblePaints() const;
void clearAll();
private:
template<class T>
QSharedPointer<T> _getElementByName(const QVector<QSharedPointer<T> >& vector, QString name)
{
foreach (QSharedPointer<T> it, vector)
{
if (it->getName() == name)
{
return it;
}
}
// Nothing found.
return QSharedPointer<T>();
}
template<class T>
QVector<QSharedPointer<T> > _getElementsByNameRegExp(const QVector<QSharedPointer<T> >& vector, QString namePattern)
{
QVector<QSharedPointer<T> > matchedElems;
QRegExp regExp(namePattern, Qt::CaseSensitive, QRegExp::Wildcard);
foreach (QSharedPointer<T> it, vector)
{
if (regExp.exactMatch(it->getName()))
{
matchedElems.push_back(it);
}
}
return matchedElems;
}
};
MM_END_NAMESPACE
+34 -11
View File
@@ -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<Paint::ptr> 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<Mapping::ptr> 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)
{