Skip to content

Commit

Permalink
Detect activation of a scene on preview when transitioning from progr…
Browse files Browse the repository at this point in the history
…am to suppress start-action execution (13)
  • Loading branch information
vwout committed Jul 19, 2023
1 parent 83f6440 commit c2d62ae
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
17 changes: 7 additions & 10 deletions README.md
Expand Up @@ -122,21 +122,18 @@ To permanently disable execution, without removing the configuration, change the

#### Custom Command action execution overview

| | Preview scene load | Transition to program | Transition back to preview | Unload preview scene (select other scene) |
|--------------------------------------------------------------------------|--------------------|-----------------------|-------------------------------------------------------------|-------------------------------------------|
| **Action Active**: Always<br/>**On preview exclusive**: No | Send start command | Send start command | 1. Send start commmand<sup>2</sup><br/>2. Send stop command | Send stop command |
| **Action Active**: Always<br/>**On preview exclusive**: Yes<sup>1</sup> | - | Send start command | Send stop command | - |
| **Action Active**: Preview<br/>**On preview exclusive**: No | Send start command | - | Send start commmand<sup>2</sup> | Send stop command |
| **Action Active**: Preview<br/>**On preview exclusive**: Yes<sup>1</sup> | - | - | - | - |
| **Action Active**: Program<br/>**On preview exclusive**: N/A | - | Send start command | Send stop command | - |
| | Preview scene load | Transition to program | Transition back to preview | Unload preview scene (select other scene) |
|--------------------------------------------------------------------------|--------------------|-----------------------|----------------------------|-------------------------------------------|
| **Action Active**: Always<br/>**On preview exclusive**: No | Send start command | Send start command | Send stop command | Send stop command |
| **Action Active**: Always<br/>**On preview exclusive**: Yes<sup>1</sup> | - | Send start command | Send stop command | - |
| **Action Active**: Preview<br/>**On preview exclusive**: No | Send start command | - | - | Send stop command |
| **Action Active**: Preview<br/>**On preview exclusive**: Yes<sup>1</sup> | - | - | - | - |
| **Action Active**: Program<br/>**On preview exclusive**: N/A | - | Send start command | Send stop command | - |


<sup>1</sup>The checkbox 'Run action on preview only...' is active *and* for the same camera a Visca action is active (visible) on program.
In case no Visca camera is active on program, or a different Visca camera is active, the table result for 'No' apply.

<sup>2</sup>The source for this scene become active as preview scene, for that reason, the start command is send, directly followed by the stop command.
This is considered a bug and will be removed in the future, so don't rely on it!

### Hotkeys
The plugin adds a number of hotkeys to the global OBS settings.
All hotkeys apply to a specific camera, except for [Suppress actions on scenes](#suppress_actions_on_scenes) (see the previous paragraph).
Expand Down
35 changes: 35 additions & 0 deletions obs-visca-control.lua
Expand Up @@ -21,6 +21,10 @@ local plugin_data = {
debug = false,
active_scene = nil,
preview_scene = nil,
program_scene = {}, -- List containing typically 1 scene name that is on program.
-- This datastructure is a list because the signals activate and deactivate are triggered
-- respectively before and after change to/from program. During the transition there are
-- thus two scenes that could be active on program.
connections = {},
reply_data = {},
hotkeys = {},
Expand Down Expand Up @@ -1165,6 +1169,37 @@ local function source_signal_processor(source_settings, source_name, signal)
signal.hide_fe_event and "Hide (FE)" or
"?", source_name, do_action and "process" or "no action")

if signal.show or signal.show_fe_event then
local current_preview_scene = obs.obs_frontend_get_current_preview_scene()
local current_preview_scene_name = obs.obs_source_get_name(current_preview_scene)

if plugin_data.program_scene[current_preview_scene_name] ~= nil then
do_action = false
log("Not running start action on preview for source '%s', " ..
"because it transitioned from program in scene %s", source_name or "?", current_preview_scene_name)
end

obs.obs_source_release(current_preview_scene)
end

if signal.activate then
local current_program_scene = obs.obs_frontend_get_current_scene()
local current_program_scene_name = obs.obs_source_get_name(current_program_scene)

plugin_data.program_scene[current_program_scene_name] = true

obs.obs_source_release(current_program_scene)
end

if signal.deactivate then
local current_preview_scene = obs.obs_frontend_get_current_preview_scene()
local current_preview_scene_name = obs.obs_source_get_name(current_preview_scene)

plugin_data.program_scene[current_preview_scene_name] = nil

obs.obs_source_release(current_preview_scene)
end

if do_action then
local camera_id = obs.obs_data_get_int(source_settings, "scene_camera")

Expand Down

0 comments on commit c2d62ae

Please sign in to comment.