diff --git a/libraries/controllers/src/controllers/Mapping.cpp b/libraries/controllers/src/controllers/Mapping.cpp index 0063a1d24a..b6214a43fc 100644 --- a/libraries/controllers/src/controllers/Mapping.cpp +++ b/libraries/controllers/src/controllers/Mapping.cpp @@ -1,5 +1,11 @@ +// +// Created by Bradley Austin Davis 2015/10/09 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// #include "Mapping.h" -namespace controller { -} + diff --git a/libraries/controllers/src/controllers/Mapping.h b/libraries/controllers/src/controllers/Mapping.h index 5b54a1745b..39fe6ba788 100644 --- a/libraries/controllers/src/controllers/Mapping.h +++ b/libraries/controllers/src/controllers/Mapping.h @@ -28,9 +28,9 @@ namespace controller { using Pointer = std::shared_ptr; Map _channelMappings; + QString _name; - void parse(const QString& json); - QString serialize(); + protected: }; } diff --git a/libraries/controllers/src/controllers/NewControllerScriptingInterface.cpp b/libraries/controllers/src/controllers/NewControllerScriptingInterface.cpp index f5d6276b91..c4d1bb65c4 100644 --- a/libraries/controllers/src/controllers/NewControllerScriptingInterface.cpp +++ b/libraries/controllers/src/controllers/NewControllerScriptingInterface.cpp @@ -301,6 +301,10 @@ namespace controller { return Endpoint::Pointer(); } + UserInputMapper::Input NewControllerScriptingInterface::inputFor(const QString& inputName) { + return DependencyManager::get()->findDeviceInput(inputName); + } + Endpoint::Pointer NewControllerScriptingInterface::endpointFor(const UserInputMapper::Input& inputId) { auto iterator = _endpoints.find(inputId); if (_endpoints.end() == iterator) { diff --git a/libraries/controllers/src/controllers/NewControllerScriptingInterface.h b/libraries/controllers/src/controllers/NewControllerScriptingInterface.h index 6bf0bda40d..39791eacb2 100644 --- a/libraries/controllers/src/controllers/NewControllerScriptingInterface.h +++ b/libraries/controllers/src/controllers/NewControllerScriptingInterface.h @@ -68,6 +68,8 @@ namespace controller { Endpoint::Pointer endpointFor(const UserInputMapper::Input& endpoint); Endpoint::Pointer compositeEndpointFor(Endpoint::Pointer first, Endpoint::Pointer second); + UserInputMapper::Input inputFor(const QString& inputName); + friend class MappingBuilderProxy; friend class RouteBuilderProxy; private: diff --git a/libraries/controllers/src/controllers/impl/MappingBuilderProxy.cpp b/libraries/controllers/src/controllers/impl/MappingBuilderProxy.cpp index 4e2c6a4d8c..71a8a417fd 100644 --- a/libraries/controllers/src/controllers/impl/MappingBuilderProxy.cpp +++ b/libraries/controllers/src/controllers/impl/MappingBuilderProxy.cpp @@ -11,11 +11,14 @@ #include #include +#include +#include + #include "RouteBuilderProxy.h" #include "../NewControllerScriptingInterface.h" #include "../Logging.h" -namespace controller { +using namespace controller; QObject* MappingBuilderProxy::from(const QJSValue& source) { qCDebug(controllers) << "Creating new Route builder proxy from " << source.toString(); @@ -41,4 +44,49 @@ QObject* MappingBuilderProxy::join(const QJSValue& source1, const QJSValue& sour return from(_parent.compositeEndpointFor(source1Endpoint, source2Endpoint)); } + +const QString JSON_NAME = QStringLiteral("name"); +const QString JSON_CHANNELS = QStringLiteral("channels"); +const QString JSON_CHANNEL_FROM = QStringLiteral("from"); +const QString JSON_CHANNEL_TO = QStringLiteral("to"); +const QString JSON_CHANNEL_FILTERS = QStringLiteral("filters"); + + +void MappingBuilderProxy::parse(const QJsonObject& json) { + _mapping->_name = json[JSON_NAME].toString(); + + _mapping->_channelMappings.clear(); + const auto& jsonChannels = json[JSON_CHANNELS].toArray(); + for (const auto& channelIt : jsonChannels) { + parseRoute(channelIt); + } +} + +void MappingBuilderProxy::parseRoute(const QJsonValue& json) { + if (json.isObject()) { + const auto& jsonChannel = json.toObject(); + + auto newRoute = from(jsonChannel[JSON_CHANNEL_FROM]); + if (newRoute) { + auto route = dynamic_cast(newRoute); + route->filters(jsonChannel[JSON_CHANNEL_FILTERS]); + route->to(jsonChannel[JSON_CHANNEL_TO]); + + return + } + } +} + +QObject* MappingBuilderProxy::from(const QJsonValue& json) { + if (json.isString()) { + return from(_parent.endpointFor(_parent.inputFor(json.toString()))); + } else if (json.isObject()) { + // Endpoint is defined as an object, we expect a js function then + return nullptr; + } +} + + +Filter::List MappingBuilderProxy::parseFilters(const QJsonValue& json) const { + return Filter::List(); } diff --git a/libraries/controllers/src/controllers/impl/MappingBuilderProxy.h b/libraries/controllers/src/controllers/impl/MappingBuilderProxy.h index b5e02bbfdf..d0101b95a7 100644 --- a/libraries/controllers/src/controllers/impl/MappingBuilderProxy.h +++ b/libraries/controllers/src/controllers/impl/MappingBuilderProxy.h @@ -32,12 +32,24 @@ public: Q_INVOKABLE QObject* from(const QScriptValue& source); Q_INVOKABLE QObject* join(const QJSValue& source1, const QJSValue& source2); + + // JSON route creation point + Q_INVOKABLE QObject* from(const QJsonValue& json); + + + void parse(const QJsonObject& json); + // void serialize(QJsonObject& json); + protected: QObject* from(const Endpoint::Pointer& source); friend class RouteBuilderProxy; NewControllerScriptingInterface& _parent; Mapping::Pointer _mapping; + + + void parseRoute(const QJsonValue& json); + }; } diff --git a/libraries/controllers/src/controllers/impl/RouteBuilderProxy.h b/libraries/controllers/src/controllers/impl/RouteBuilderProxy.h index 63cd106edb..a62a465700 100644 --- a/libraries/controllers/src/controllers/impl/RouteBuilderProxy.h +++ b/libraries/controllers/src/controllers/impl/RouteBuilderProxy.h @@ -40,6 +40,10 @@ class RouteBuilderProxy : public QObject { Q_INVOKABLE QObject* constrainToInteger(); Q_INVOKABLE QObject* constrainToPositiveInteger(); + // JSON route creation point + Q_INVOKABLE QObject* filters(const QJsonValue& json); + Q_INVOKABLE void to(const QJsonValue& json); + private: void to(const Endpoint::Pointer& destination); void addFilter(Filter::Lambda lambda); diff --git a/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp b/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp index c29acc09af..325dc5dfe7 100755 --- a/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp +++ b/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp @@ -64,7 +64,7 @@ void UserInputMapper::resetDevice(uint16 deviceID) { } } -int UserInputMapper::findDevice(QString name) { +int UserInputMapper::findDevice(QString name) const { for (auto device : _registeredDevices) { if (device.second->_name.split(" (")[0] == name) { return device.first; @@ -82,6 +82,28 @@ QVector UserInputMapper::getDeviceNames() { return result; } +UserInputMapper::Input UserInputMapper::findDeviceInput(const QString& inputName) const { + + // Split the full input name as such: deviceName.inputName + auto names = inputName.split('.'); + + if (names.size() >= 2) { + // Get the device name: + auto deviceName = names[0]; + auto inputName = names[1]; + + int deviceID = findDevice(deviceName); + if (deviceID != Input::INVALID_DEVICE) { + // getAllInputsForDevice(deviceID); + } + + + } + + return Input(); +} + + bool UserInputMapper::addInputChannel(Action action, const Input& input, float scale) { return addInputChannel(action, input, Input(), scale); diff --git a/libraries/input-plugins/src/input-plugins/UserInputMapper.h b/libraries/input-plugins/src/input-plugins/UserInputMapper.h index 304e74e8cc..b7b105df5e 100755 --- a/libraries/input-plugins/src/input-plugins/UserInputMapper.h +++ b/libraries/input-plugins/src/input-plugins/UserInputMapper.h @@ -140,9 +140,12 @@ public: QVector getAvailableInputs(uint16 deviceID) { return _registeredDevices[deviceID]->getAvailabeInputs(); } void resetAllDeviceBindings(); void resetDevice(uint16 deviceID); - int findDevice(QString name); + int findDevice(QString name) const; QVector getDeviceNames(); + Input findDeviceInput(const QString& inputName) const; + + // Actions are the output channels of the Mapper, that's what the InputChannel map to // For now the Actions are hardcoded, this is bad, but we will fix that in the near future enum Action { diff --git a/tests/controllers/src/main.cpp b/tests/controllers/src/main.cpp index d694bcae1d..b42359e48a 100644 --- a/tests/controllers/src/main.cpp +++ b/tests/controllers/src/main.cpp @@ -83,7 +83,9 @@ int main(int argc, char** argv) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; - + for (auto path : qApp->libraryPaths()) { + qDebug() << path; + } { DependencyManager::set(); foreach(auto inputPlugin, PluginManager::getInstance()->getInputPlugins()) {