add STUDIO_MODE_TOGGLE, SCENE_PREV, and SCENE_NEXT

This commit is contained in:
2023-10-29 18:58:18 -04:00
parent d433179db4
commit fb9fc290ad
2 changed files with 62 additions and 10 deletions

View File

@@ -3,6 +3,12 @@ package net.eksb.obsdc
enum class Op { enum class Op {
/** If in studio mode, transition between scenes. */ /** If in studio mode, transition between scenes. */
STUDIO_TRANSITION, STUDIO_TRANSITION,
/** Enable/disable studio mode. */
STUDIO_MODE_TOGGLE,
/** Activate the previous scene. */
SCENE_PREV,
/** Activate the next scene. */
SCENE_NEXT,
/** Activate the first scene. */ /** Activate the first scene. */
SCENE_1, SCENE_1,
/** Activate the second scene. */ /** Activate the second scene. */

View File

@@ -20,17 +20,43 @@ class OpRunner(private val obs:Obs) {
private val controller = obs.controller private val controller = obs.controller
/**
* Run the specified [Op].
*/
fun run(op:Op) { fun run(op:Op) {
obs.submit { controller -> obs.submit { controller ->
when(op) { when(op) {
Op.SCENE_1 -> scene { scenes -> scenes.firstOrNull() } Op.SCENE_NEXT -> scene { scenes, current ->
Op.SCENE_2 -> scene { scenes -> scenes.asSequence().drop(1).firstOrNull() } if (current != null) {
Op.SCENE_3 -> scene { scenes -> scenes.asSequence().drop(2).firstOrNull() } scenes.asSequence()
.dropWhile { scene -> scene != current }
.drop(1)
.firstOrNull()
?: scenes.firstOrNull()
} else {
null
}
}
Op.SCENE_PREV -> scene { scenes, current ->
if (current != null) {
scenes.reversed().asSequence()
.dropWhile { scene -> scene != current }
.drop(1)
.firstOrNull()
?: scenes.lastOrNull()
} else {
null
}
}
Op.SCENE_1 -> scene { scenes, current -> scenes.firstOrNull() }
Op.SCENE_2 -> scene { scenes, current -> scenes.asSequence().drop(1).firstOrNull() }
Op.SCENE_3 -> scene { scenes, current -> scenes.asSequence().drop(2).firstOrNull() }
Op.STUDIO_TRANSITION -> { Op.STUDIO_TRANSITION -> {
controller.triggerStudioModeTransition { response -> controller.triggerStudioModeTransition { response ->
log.debug("studio transitioned: ${response.isSuccessful}") log.debug("studio transitioned: ${response.isSuccessful}")
} }
} }
Op.STUDIO_MODE_TOGGLE -> studioModeToggle()
Op.PAN_UP -> transform { old -> positionY(old.positionY - panAmount ) } Op.PAN_UP -> transform { old -> positionY(old.positionY - panAmount ) }
Op.PAN_DOWN -> transform { old -> positionY(old.positionY + panAmount ) } Op.PAN_DOWN -> transform { old -> positionY(old.positionY + panAmount ) }
Op.PAN_LEFT -> transform { old -> positionX(old.positionX - panAmount ) } Op.PAN_LEFT -> transform { old -> positionX(old.positionX - panAmount ) }
@@ -39,13 +65,32 @@ class OpRunner(private val obs:Obs) {
} }
} }
private fun studioModeToggle() {
controller.getStudioModeEnabled { response ->
if (response.isSuccessful) {
val enable = !response.studioModeEnabled
log.debug("toggle studio mode: ${!enable}")
controller.setStudioModeEnabled(enable) { response ->
log.debug("toggled studio mode: ${enable}")
}
}
}
}
/** /**
* Select a scene from the scene list with the supplied [selector] and set the selected scene (if any) * Select a scene from the scene list with the supplied [selector] and set the selected scene (if any)
* as the current program scene. * as the current program scene.
*
* @param selector Lambda that takes as arguments the list of scenes and the current scene (or null if the current
* scene is unknown), and returns the scene to select, or null to not change the scene.
*/ */
private fun scene(selector:(List<Scene>)->Scene?) { private fun scene(selector:(List<Scene>,Scene?)->Scene?) {
controller.getCurrentProgramScene { response ->
val currentSceneName = response.currentProgramSceneName
controller.getSceneList { response -> controller.getSceneList { response ->
val scene = selector(response.scenes.sortedBy(Scene::getSceneIndex).reversed()) val scenes = response.scenes.sortedBy(Scene::getSceneIndex).reversed()
val currentScene = scenes.find { scene -> scene.sceneName == currentSceneName }
val scene = selector(response.scenes.sortedBy(Scene::getSceneIndex).reversed(), currentScene)
log.debug("select scene ${scene?.sceneName} index:${scene?.sceneIndex}") log.debug("select scene ${scene?.sceneName} index:${scene?.sceneIndex}")
if (scene != null) { if (scene != null) {
controller.setCurrentProgramScene(scene.sceneName) { response -> controller.setCurrentProgramScene(scene.sceneName) { response ->
@@ -54,6 +99,7 @@ class OpRunner(private val obs:Obs) {
} }
} }
} }
}
/** /**
* Generate a transform for the lowest non-locked item in the current program scene with the * Generate a transform for the lowest non-locked item in the current program scene with the