Compare commits

..

5 Commits

Author SHA1 Message Date
74e44a07ba ignore .idea 2024-05-23 14:50:45 -04:00
6b8ad1f5d4 kotlin 2, dbus-java-core 5 2024-05-23 14:50:26 -04:00
e01589aab8 docs 2024-04-18 12:02:55 -04:00
265efd1db0 use String instead of Op; support SCENE_<number> 2024-03-13 15:31:20 -04:00
e0838be9b8 remove unused Backoff.kt 2024-03-13 15:27:39 -04:00
7 changed files with 39 additions and 62 deletions

1
.gitignore vendored
View File

@@ -5,3 +5,4 @@ gradlew*
# Ignore Gradle build output directory
build
.idea

View File

@@ -2,12 +2,21 @@
OBS control from D-Bus messages
Send a D-Bus signal to perform an operation with `src/obsdc-signal`, which takes a single operation name
as an argument.
Send a D-Bus signal to perform an operation with `src/obsdc-signal`, which takes a single operation command
as an argument, and performs an action in OBS.
## Operations
See [Op](src/main/kotlin/net/eksb/obsdc/Op.kt) for a list of operations.
* `SCENE_NEXT` - switch to the next scene
* `SCENE_PREV` - switch to the previous scene
* `SCENE_#` - switch to the indicated scene
* replace `#` with scene index, starting with 1.
* `STUDIO_TRANSITION` - transition the studio preview and program
* `STUDIO_MODE_TOGGLE` - toggle studio mode
* `PAN_UP` - move the top unlocked source up 50px
* `PAN_DOWN` - move the top unlocked source down 50px
* `PAN_LEFT` - move the top unlocked source left 50px
* `PAN_RIGHT` - move the top unlocked source right 50pxt
## Configuration

View File

@@ -1,5 +1,5 @@
plugins {
id("org.jetbrains.kotlin.jvm") version "1.9.0"
id("org.jetbrains.kotlin.jvm") version "2.0.0"
application
}
@@ -7,8 +7,8 @@ dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.3")
implementation("com.github.hypfvieh:dbus-java-core:4.3.1")
runtimeOnly("com.github.hypfvieh:dbus-java-transport-native-unixsocket:4.3.1")
implementation("com.github.hypfvieh:dbus-java-core:5.0.0")
runtimeOnly("com.github.hypfvieh:dbus-java-transport-native-unixsocket:5.0.0")
implementation("io.obs-websocket.community:client:2.0.0")

View File

@@ -1,8 +0,0 @@
package net.eksb.obsdc
class Backoff {
fun backoff() {
// TODO: actual bakoff
Thread.sleep(5_000)
}
}

View File

@@ -19,7 +19,7 @@ import org.slf4j.LoggerFactory
*
* `src/scripts/obsdc-signal` takes an [Op] name and sends the signal.
*/
class DBus(private val opRunner:OpRunner): AutoCloseable {
class DBus(private val opHandler:(String)->Unit): AutoCloseable {
// To monitor DBUS: `dbus-monitor`
// To see what is registered: `qdbus net.eksb.obsdc /`
@@ -37,9 +37,7 @@ class DBus(private val opRunner:OpRunner): AutoCloseable {
dbus.addSigHandler<ObsdcDBusInterface.Signal> { signal ->
log.debug("signal: ${signal.op}")
val op = Op.valueOf(signal.op)
log.debug("op: ${op}")
opRunner.run(op)
opHandler.invoke(signal.op)
}
log.debug("DBUS initialized")
}

View File

@@ -1,27 +0,0 @@
package net.eksb.obsdc
enum class Op {
/** If in studio mode, transition between scenes. */
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. */
SCENE_1,
/** Activate the second scene. */
SCENE_2,
/** Activate the third scene. */
SCENE_3,
/** Move the bottom-most unlocked source in the active scene up. */
PAN_UP,
/** Move the bottom-most unlocked source in the active scene down. */
PAN_DOWN,
/** Move the bottom-most unlocked source in the active scene left. */
PAN_LEFT,
/** Move the bottom-most unlocked source in the active scene right. */
PAN_RIGHT,
;
}

View File

@@ -9,11 +9,11 @@ import io.obswebsocket.community.client.model.SceneItem.Transform.TransformBuild
import org.slf4j.LoggerFactory
/**
* Use an [obs] to run [Op]s.
* Use an [obs] to run an operation.
*
* Call [run] to run an OBS operation.
* Call [invoke] to run an OBS operation.
*/
class OpRunner(private val obs:Obs) {
class OpRunner(private val obs:Obs): (String)->Unit {
/** How much to pan. */
private val panAmount = 50F
@@ -21,12 +21,14 @@ class OpRunner(private val obs:Obs) {
private val controller = obs.controller
/**
* Run the specified [Op].
* Run the specified [op].
*
* @param op Operation to run.
*/
fun run(op:Op) {
override fun invoke(op:String) {
obs.submit { controller ->
when(op) {
Op.SCENE_NEXT -> scene { scenes, current ->
when {
op == "SCENE_NEXT" -> scene { scenes, current ->
if (current != null) {
scenes.asSequence()
.dropWhile { scene -> scene != current }
@@ -37,7 +39,7 @@ class OpRunner(private val obs:Obs) {
null
}
}
Op.SCENE_PREV -> scene { scenes, current ->
op == "SCENE_PREV" -> scene { scenes, current ->
if (current != null) {
scenes.reversed().asSequence()
.dropWhile { scene -> scene != current }
@@ -48,19 +50,21 @@ class OpRunner(private val obs:Obs) {
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.startsWith("SCENE_") -> scene { scenes, current ->
val drop = op.drop("SCENE_".length).toInt() - 1
scenes.asSequence().drop(drop).firstOrNull()
}
op == "STUDIO_TRANSITION" -> {
controller.triggerStudioModeTransition { response ->
log.debug("studio transitioned: ${response.isSuccessful}")
}
}
Op.STUDIO_MODE_TOGGLE -> studioModeToggle()
Op.PAN_UP -> 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_RIGHT -> transform { old -> positionX(old.positionX + panAmount ) }
op == "STUDIO_MODE_TOGGLE" -> studioModeToggle()
op == "PAN_UP" -> 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_RIGHT" -> transform { old -> positionX(old.positionX + panAmount ) }
else -> log.error("Unhandled op \"${op}\"")
}
}
}