obs-websocket icon indicating copy to clipboard operation
obs-websocket copied to clipboard

Feature Request: Add support for 'inputVariables' basic operations in batch requests

Open LorenaGdL opened this issue 2 years ago • 0 comments

Feature Request Type

Other

Feature Request Type (Other)

Add support for inputVariables basic operations in batch requests

Requested Feature

Currently, batch requests allow the use of inputVariables/outputVariables to easily store and use the results of a previous request stage in the next ones. However, they're implemented as a simple key-value store and it's not possible to apply basic operators to the values themselves before inputting to the next stage. This would be a nice feature for common use cases like toggling some property/item, where you need to set the negation of the current value, as it would really make the most out of batch requests.

My proposal is to optionally specify such operations in the inputVariables value string, separated by some special delimiter. E.g.:

"inputVariables": {
    "sceneItemEnabled": "sceneItemEnabledVariable:negate"
}

This seems feasible with some changes to the last section of PreProcessVariables, where the optional operator would be parsed and applied to the raw stored value instead of just returning it as it is: https://github.com/obsproject/obs-websocket/blob/f4b72b69ce7f9ec6a5fdb1b06971e00d2b091bec/src/requesthandler/RequestBatchHandler.cpp#L74-L85

As for the operations, I propose to include:

  • (must have) Booleans negation, to allow for toggling in batch requests. E.g. someBooleanVariable:negate
  • (should have) Numbers addition and multiplication. E.g. someNumberVariable:add:5, someNumberVariable:mul:0.5
  • (maybe) String addition/concat. E.g. someStringVariable:add:somestring

Requested Feature Usage Scenario

(non-exhaustive list of use cases)

  • Batch requests that aim to toggle a boolean value (and don't have a separate ToggleX request)

    • GetSceneItemId > GetSceneItemEnabled > SetSceneItemEnabled
    • GetSceneItemId > GetSceneItemLocked > SetSceneItemLocked
    • GetSourceFilter > SetSourceFilterEnabled
    • GetStudioModeEnabled > SetStudioModeEnabled
  • Batch requests that aim to set a number value based on current value

    • GetSceneItemIndex > SetSceneItemIndex
    • GetInputVolume > SetInputVolume
    • GetCurrentSceneTransition > SetCurrentSceneTransitionDuration

LorenaGdL avatar Mar 17 '23 22:03 LorenaGdL