From 1ed095de48667a9cce9a3825cfea374158744625 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Tue, 28 Dec 2021 17:36:41 -0800 Subject: [PATCH 1/2] EventHandler: Add `InputAudioBalanceChanged` --- src/eventhandler/EventHandler.cpp | 2 ++ src/eventhandler/EventHandler.h | 1 + src/eventhandler/EventHandler_Inputs.cpp | 33 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/src/eventhandler/EventHandler.cpp b/src/eventhandler/EventHandler.cpp index 8470e633..b012fc1b 100644 --- a/src/eventhandler/EventHandler.cpp +++ b/src/eventhandler/EventHandler.cpp @@ -134,6 +134,7 @@ void EventHandler::ConnectSourceSignals(obs_source_t *source) // Applies to inpu signal_handler_connect(sh, "hide", HandleInputShowStateChanged, this); signal_handler_connect(sh, "mute", HandleInputMuteStateChanged, this); signal_handler_connect(sh, "volume", HandleInputVolumeChanged, this); + signal_handler_connect(sh, "audio_balance", HandleInputAudioBalanceChanged, this); signal_handler_connect(sh, "audio_sync", HandleInputAudioSyncOffsetChanged, this); signal_handler_connect(sh, "audio_mixers", HandleInputAudioTracksChanged, this); //signal_handler_connect(sh, "audio_monitoring", HandleInputAudioMonitorTypeChanged, this); @@ -174,6 +175,7 @@ void EventHandler::DisconnectSourceSignals(obs_source_t *source) signal_handler_disconnect(sh, "hide", HandleInputShowStateChanged, this); signal_handler_disconnect(sh, "mute", HandleInputMuteStateChanged, this); signal_handler_disconnect(sh, "volume", HandleInputVolumeChanged, this); + signal_handler_disconnect(sh, "audio_balance", HandleInputAudioBalanceChanged, this); signal_handler_disconnect(sh, "audio_sync", HandleInputAudioSyncOffsetChanged, this); signal_handler_disconnect(sh, "audio_mixers", HandleInputAudioTracksChanged, this); //signal_handler_disconnect(sh, "audio_monitoring", HandleInputAudioMonitorTypeChanged, this); diff --git a/src/eventhandler/EventHandler.h b/src/eventhandler/EventHandler.h index 98fec117..bdd1cde8 100644 --- a/src/eventhandler/EventHandler.h +++ b/src/eventhandler/EventHandler.h @@ -107,6 +107,7 @@ class EventHandler static void HandleInputShowStateChanged(void *param, calldata_t *data); // Direct callback static void HandleInputMuteStateChanged(void *param, calldata_t *data); // Direct callback static void HandleInputVolumeChanged(void *param, calldata_t *data); // Direct callback + static void HandleInputAudioBalanceChanged(void *param, calldata_t *data); // Direct callback static void HandleInputAudioSyncOffsetChanged(void *param, calldata_t *data); // Direct callback static void HandleInputAudioTracksChanged(void *param, calldata_t *data); // Direct callback static void HandleInputAudioMonitorTypeChanged(void *param, calldata_t *data); // Direct callback diff --git a/src/eventhandler/EventHandler_Inputs.cpp b/src/eventhandler/EventHandler_Inputs.cpp index a4b0c2af..7d937939 100644 --- a/src/eventhandler/EventHandler_Inputs.cpp +++ b/src/eventhandler/EventHandler_Inputs.cpp @@ -236,6 +236,39 @@ void EventHandler::HandleInputVolumeChanged(void *param, calldata_t *data) eventHandler->BroadcastEvent(EventSubscription::Inputs, "InputVolumeChanged", eventData); } +/** + * The audio balance value of an input has changed. + * + * @dataField inputName | String | Name of the affected input + * @dataField inputAudioBalance | Number | New audio balance value of the input + * + * @eventType InputAudioBalanceChanged + * @eventSubscription Inputs + * @complexity 2 + * @rpcVersion -1 + * @initialVersion 5.0.0 + * @category inputs + * @api events + */ +void EventHandler::HandleInputAudioBalanceChanged(void *param, calldata_t *data) +{ + auto eventHandler = reinterpret_cast(param); + + obs_source_t *source = GetCalldataPointer(data, "source"); + if (!source) + return; + + if (obs_source_get_type(source) != OBS_SOURCE_TYPE_INPUT) + return; + + float inputAudioBalance = (float)calldata_float(data, "balance"); + + json eventData; + eventData["inputName"] = obs_source_get_name(source); + eventData["inputAudioBalance"] = inputAudioBalance; + eventHandler->BroadcastEvent(EventSubscription::Inputs, "InputAudioBalanceChanged", eventData); +} + /** * The sync offset of an input has changed. * From 9113ff90213f73aed2d511951be2f56fedc1a9cd Mon Sep 17 00:00:00 2001 From: tt2468 Date: Tue, 28 Dec 2021 17:46:46 -0800 Subject: [PATCH 2/2] RequestHandler: Add audio balance requests --- src/requesthandler/RequestHandler.cpp | 2 + src/requesthandler/RequestHandler.h | 2 + src/requesthandler/RequestHandler_Inputs.cpp | 55 ++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/src/requesthandler/RequestHandler.cpp b/src/requesthandler/RequestHandler.cpp index f3c21599..ca8c54f1 100644 --- a/src/requesthandler/RequestHandler.cpp +++ b/src/requesthandler/RequestHandler.cpp @@ -77,6 +77,8 @@ const std::map RequestHandler::_handlerMap {"ToggleInputMute", &RequestHandler::ToggleInputMute}, {"GetInputVolume", &RequestHandler::GetInputVolume}, {"SetInputVolume", &RequestHandler::SetInputVolume}, + {"GetInputAudioBalance", &RequestHandler::GetInputAudioBalance}, + {"SetInputAudioBalance", &RequestHandler::SetInputAudioBalance}, {"GetInputAudioSyncOffset", &RequestHandler::GetInputAudioSyncOffset}, {"SetInputAudioSyncOffset", &RequestHandler::SetInputAudioSyncOffset}, {"GetInputAudioMonitorType", &RequestHandler::GetInputAudioMonitorType}, diff --git a/src/requesthandler/RequestHandler.h b/src/requesthandler/RequestHandler.h index 19e3fde4..410b6b56 100644 --- a/src/requesthandler/RequestHandler.h +++ b/src/requesthandler/RequestHandler.h @@ -99,6 +99,8 @@ class RequestHandler { RequestResult ToggleInputMute(const Request&); RequestResult GetInputVolume(const Request&); RequestResult SetInputVolume(const Request&); + RequestResult GetInputAudioBalance(const Request&); + RequestResult SetInputAudioBalance(const Request&); RequestResult GetInputAudioSyncOffset(const Request&); RequestResult SetInputAudioSyncOffset(const Request&); RequestResult GetInputAudioMonitorType(const Request&); diff --git a/src/requesthandler/RequestHandler_Inputs.cpp b/src/requesthandler/RequestHandler_Inputs.cpp index f65a3c07..d7018bc9 100644 --- a/src/requesthandler/RequestHandler_Inputs.cpp +++ b/src/requesthandler/RequestHandler_Inputs.cpp @@ -488,6 +488,61 @@ RequestResult RequestHandler::SetInputVolume(const Request& request) return RequestResult::Success(); } +/** + * Gets the audio balance of an input. + * + * @requestField inputName | String | Name of the input to get the audio balance of + * + * @responseField inputAudioBalance | Number | Audio balance value from 0.0-1.0 + * + * @requestType GetInputAudioBalance + * @complexity 2 + * @rpcVersion -1 + * @initialVersion 5.0.0 + * @api requests + * @category inputs + */ +RequestResult RequestHandler::GetInputAudioBalance(const Request& request) +{ + RequestStatus::RequestStatus statusCode; + std::string comment; + OBSSourceAutoRelease input = request.ValidateInput("inputName", statusCode, comment); + if (!input) + return RequestResult::Error(statusCode, comment); + + json responseData; + responseData["inputAudioBalance"] = obs_source_get_balance_value(input); + + return RequestResult::Success(responseData); +} + +/** + * Sets the audio balance of an input. + * + * @requestField inputName | String | Name of the input to set the audio balance of + * @requestField inputAudioBalance | Number | New audio balance value | >= 0.0, <= 1.0 + * + * @requestType SetInputAudioBalance + * @complexity 2 + * @rpcVersion -1 + * @initialVersion 5.0.0 + * @api requests + * @category inputs + */ +RequestResult RequestHandler::SetInputAudioBalance(const Request& request) +{ + RequestStatus::RequestStatus statusCode; + std::string comment; + OBSSourceAutoRelease input = request.ValidateInput("inputName", statusCode, comment); + if (!(input && request.ValidateNumber("inputAudioBalance", statusCode, comment, 0.0, 1.0))) + return RequestResult::Error(statusCode, comment); + + float inputAudioBalance = request.RequestData["inputAudioBalance"]; + obs_source_set_balance_value(input, inputAudioBalance); + + return RequestResult::Success(); +} + /** * Gets the audio sync offset of an input. *