void OnSceneSwitch(CTSTR scene) { XElement *sceneElement; float desktopVolumeLevel, micVolumeLevel; int dMFV, mMFV; bool desktopMuted, micMuted; if(!bPSVEnabled) return; sceneElement = OBSGetSceneElement(); if(sceneElement) { desktopVolumeLevel = sceneElement->GetFloat(TEXT("psvDesktopVolume"), 1.0f); micVolumeLevel = sceneElement->GetFloat(TEXT("psvMicVolume"), 1.0f); dMFV = sceneElement->GetInt(TEXT("psvDesktopMFV")); mMFV = sceneElement->GetInt(TEXT("psvMicMFV")); desktopMuted = (dMFV & PSV_VOL_MUTED) == PSV_VOL_MUTED; micMuted = (mMFV & PSV_VOL_MUTED) == PSV_VOL_MUTED; OBSSetDesktopVolume(desktopVolumeLevel, true); if(desktopMuted) OBSToggleDesktopMute(); OBSSetMicVolume(micVolumeLevel, true); if(micMuted) OBSToggleMicMute(); } }
void RestoreInitialVolumes() { OBSSetDesktopVolume(config.GetFloat(TEXT("General"), TEXT("PrevDesktopVolume")), true); OBSSetMicVolume(config.GetFloat(TEXT("General"), TEXT("PrevMicVolume")), true); if(config.GetInt(TEXT("General"), TEXT("PrevDesktopMuted")) == 1) OBSToggleDesktopMute(); if(config.GetInt(TEXT("General"), TEXT("PrevMicMuted")) ==1) OBSToggleMicMute(); }
json_t* OBSAPIMessageHandler::HandleSetVolume(OBSAPIMessageHandler* handler, json_t* message) { json_t* channel = json_object_get(message, "channel"); json_t* volume = json_object_get(message, "volume"); json_t* finalValue = json_object_get(message, "final"); if(volume == NULL) { return GetErrorResponse("Volume not specified."); } if(!json_is_number(volume)) { return GetErrorResponse("Volume not number."); } float val = (float) json_number_value(volume); val = min(1.0f, max(0.0f, val)); if(finalValue == NULL) { return GetErrorResponse("Final not specified."); } if(!json_is_boolean(finalValue)) { return GetErrorResponse("Final is not a boolean."); } if(channel != NULL && json_typeof(channel) == JSON_STRING) { const char* channelVal = json_string_value(channel); if(stricmp(channelVal, "desktop") == 0) { OBSSetDesktopVolume(val, json_is_true(finalValue)); } else if(stricmp(channelVal, "microphone") == 0) { OBSSetMicVolume(val, json_is_true(finalValue)); } else { return GetErrorResponse("Invalid channel specified."); } } else { return GetErrorResponse("Channel not specified."); } return GetOkResponse(); }