Skip to content

Commit

Permalink
feat: previous scene active variable/feedback, adjust transition dura…
Browse files Browse the repository at this point in the history
…tion action (#275)

* feat: previous scene active variable, feedback

* chore: update changelog

* feat: add adjust transition duration action
  • Loading branch information
bryce-seifert authored Jul 1, 2024
1 parent 6b983a0 commit 4af893d
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 17 deletions.
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,34 @@ See [HELP.md](https://github.com/bitfocus/companion-module-obs-studio/blob/maste

## Changelog

### v3.7.0

- New
- Added Previous Scene Active feedback
- Added scene_previous variable
- Added Adjust Transition Duration action
- Allow custom variable in Set Transition Duration action

### v3.6.0

- New
- Added Split Record action _(requires OBS 30.2)_
- Added Record Chapter action _(requires OBS 30.2)_
- Fix
- Ensure feedbacks that use custom variables are re-checked if the variable changes
- Properly throw error if unable to get initial info from obs-websocket

### v3.5.0

- New
- Added transition_active variable
- Set Filter Settings action
- Improved
- Allow customization of Stream Congestion feedback colors, including a color for when streaming is not active
- Allow custom variables in additional actions and feedbacks
- Fix
- Grouped text sources not appearing in dropdown of text sources

### v3.4.3

- Fix
Expand Down Expand Up @@ -92,15 +120,15 @@ See [HELP.md](https://github.com/bitfocus/companion-module-obs-studio/blob/maste

- Fix
- All text source now appear as choices in the Set Text action dropdown on startup
- Minor
- Improved
- Allow hostnames to be used in the module configuration

### v2.0.4

- Fix
- When using Set Scene Visibility on a group source, the sources within groups are now not affected
- Toggle/Start/Stop Output now works properly with Virtual Camera
- Minor
- Improved
- Update obs-websocket-js to latest version
- Use obs-websocket's Batch command for certain actions

Expand Down
71 changes: 66 additions & 5 deletions actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,76 @@ export function getActions() {
{
type: 'number',
label: 'Transition time (in ms)',
tooltip: 'Must be between 50 and 20000ms',
id: 'duration',
default: null,
min: 0,
max: 60 * 1000, //max is required by api
default: 500,
min: 50,
max: 20000, //max is required by api
range: false,
isVisible: (options) => !options.useVariable,
},
{
type: 'textinput',
useVariables: true,
label: 'Transition time variable (in ms)',
id: 'variableValue',
default: '500',
isVisible: (options) => options.useVariable,
},
{
type: 'checkbox',
label: 'Use Variable',
id: 'useVariable',
default: false,
},
],
callback: (action) => {
this.sendRequest('SetCurrentSceneTransitionDuration', { transitionDuration: action.options.duration })
callback: async (action) => {
let duration = null
if (action.options.useVariable) {
duration = await this.parseVariablesInString(action.options.variableValue)
duration = parseInt(duration)
if (duration >= 50 && duration <= 20000) {
duration = duration
} else {
this.log('warn', 'Transition duration must be between 50 and 20000ms')
return
}
} else {
duration = action.options.duration
}
this.sendRequest('SetCurrentSceneTransitionDuration', { transitionDuration: duration })
},
}
actions['adjustTransitionDuration'] = {
name: 'Adjust Transition Duration',
options: [
{
type: 'number',
label: 'Adjustment amount +/- (in ms)',
id: 'duration',
default: 500,
min: -20000,
max: 20000,
range: false,
},
],
callback: async (action) => {
if (this.states.transitionDuration) {
let duration = null
duration = this.states.transitionDuration + action.options.duration
if (duration >= 50 && duration <= 20000) {
duration = duration
} else if (duration < 50) {
duration = 50
} else if (duration > 20000) {
duration = 20000
} else {
duration = this.states.transitionDuration
}
this.sendRequest('SetCurrentSceneTransitionDuration', { transitionDuration: duration })
} else {
this.log('warn', 'Unable to adjust transition duration')
}
},
}
actions['set_stream_settings'] = {
Expand Down
3 changes: 3 additions & 0 deletions companion/HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This module will allow you to control OBS Studio using the obs-websocket plugin.
- Quick Transition _(Performs the selected transition and then returns to the previous transition)_
- Set Transition Type
- Set Transition Duration
- Adjust Transition Duration

**Sources**

Expand Down Expand Up @@ -78,6 +79,7 @@ This module will allow you to control OBS Studio using the obs-websocket plugin.
**Switching & Transitions**

- Scene in Preview / Program (Program and Preview, Program Only, or Preview Only)
- Previous Scene Active
- Transition in Progress
- Current Transition Type
- Transition Duration
Expand Down Expand Up @@ -127,6 +129,7 @@ This module will allow you to control OBS Studio using the obs-websocket plugin.
- preview_only
- scene_active
- scene_preview
- scene_previous
- current_transition
- transition_duration

Expand Down
2 changes: 1 addition & 1 deletion companion/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "obs-studio",
"shortname": "obs",
"description": "Control OBS Studio using the obs-websocket plugin",
"version": "3.6.0",
"version": "3.7.0",
"license": "MIT",
"repository": "git+https://github.com/bitfocus/companion-module-obs-studio.git",
"bugs": "https://github.com/bitfocus/companion-module-obs-studio/issues",
Expand Down
23 changes: 23 additions & 0 deletions feedbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,29 @@ export function getFeedbacks() {
},
}

feedbacks['scenePrevious'] = {
type: 'boolean',
name: 'Previous Scene Active',
description: 'If a scene was the last scene previously active, change the style of the button',
defaultStyle: {
color: ColorWhite,
bgcolor: ColorGreen,
},
options: [
{
type: 'dropdown',
label: 'Scene',
id: 'scene',
default: this.sceneListDefault,
choices: this.sceneChoices,
minChoicesForSearch: 5,
},
],
callback: (feedback) => {
return this.states.previousScene === feedback.options.scene
},
}

feedbacks['scene_item_active'] = {
type: 'boolean',
name: 'Source Visible in Program',
Expand Down
12 changes: 5 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ class OBSInstance extends InstanceBase {
this.buildSceneTransitionList()
this.buildSpecialInputs()
this.buildSceneList()
}
else {
} else {
//throw an error if initial info returns false.
throw new Error('could not get OBS info')
}
Expand Down Expand Up @@ -381,16 +380,15 @@ class OBSInstance extends InstanceBase {
this.updateActionsFeedbacksVariables()
})
this.obs.on('CurrentProgramSceneChanged', (data) => {
this.states.previousScene = this.states.programScene
this.states.programScene = data.sceneName
this.setVariableValues({ scene_active: this.states.programScene })
this.checkFeedbacks('scene_active')
this.checkFeedbacks('sceneProgram')
this.setVariableValues({ scene_active: this.states.programScene, scene_previous: this.states.previousScene })
this.checkFeedbacks('scene_active', 'sceneProgram', 'scenePrevious')
})
this.obs.on('CurrentPreviewSceneChanged', (data) => {
this.states.previewScene = data.sceneName ?? 'None'
this.setVariableValues({ scene_preview: this.states.previewScene })
this.checkFeedbacks('scene_active')
this.checkFeedbacks('scenePreview')
this.checkFeedbacks('scene_active', 'scenePreview')
})
this.obs.on('SceneListChanged', (data) => {
this.scenes = data.scenes
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obs-studio",
"version": "3.6.0",
"version": "3.7.0",
"main": "index.js",
"type": "module",
"scripts": {
Expand All @@ -19,4 +19,4 @@
"@companion-module/tools": "^1.5.1"
},
"prettier": "@companion-module/tools/.prettierrc.json"
}
}
23 changes: 23 additions & 0 deletions upgrades.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,29 @@ export default [
}
}

return changes
},
function v3_7_0(context, props) {
let changes = {
updatedConfig: null,
updatedActions: [],
updatedFeedbacks: [],
}

for (const action of props.actions) {
if (action.actionId === 'set_transition_duration') {
if (action.options.duration < 50) {
action.options.duration = 50
}
if (action.options.duration > 20000) {
action.options.duration = 20000
}
action.options.variableValue = '500'
action.options.useVariable = false
changes.updatedActions.push(action)
}
}

return changes
},
]
2 changes: 2 additions & 0 deletions variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function getVariables() {
variables.push({ variableId: 'kbits_per_sec', name: 'Stream output in kilobits per second' })
variables.push({ variableId: 'scene_active', name: 'Current active scene' })
variables.push({ variableId: 'scene_preview', name: 'Current preview scene' })
variables.push({ variableId: 'scene_previous', name: 'Previously active scene, before the current scene' })
variables.push({ variableId: 'profile', name: 'Current profile' })
variables.push({ variableId: 'scene_collection', name: 'Current scene collection' })
variables.push({ variableId: 'current_transition', name: 'Current transition' })
Expand All @@ -46,6 +47,7 @@ export function getVariables() {
current_media_time_remaining: '--:--:--',
scene_preview: this.states.previewScene ?? 'None',
scene_active: this.states.programScene ?? 'None',
scene_previous: this.states.previousScene ?? 'None',
})

//Source Specific Variables
Expand Down

0 comments on commit 4af893d

Please sign in to comment.