enable/disable the scene to force a scene transition when song changes

This commit is contained in:
Octopus Octopus 2025-02-26 11:46:59 -06:00
parent 3cf7387c12
commit b2a2c16388
2 changed files with 51 additions and 17 deletions

Binary file not shown.

68
main.go
View File

@ -2,6 +2,7 @@ package main
import ( import (
"flag" "flag"
"fmt"
"log" "log"
"time" "time"
@ -13,9 +14,8 @@ import (
/* /*
TODO: TODO:
1. Transition effect when swapping songs 1. Scene transition is jumpy sometimes, probably doesn't like the 'cmus' scene changing while the scene item 'cmus' in 'streaming' is mid transition. (add a delay?)
2. Has/Get code in parse could probably be done with an interface instead? (is it worth it?) 1. Document functions
3. Document functions
*/ */
var password string var password string
@ -25,7 +25,6 @@ func init() {
} }
func main() { func main() {
// change this password lol!
sleepTime := 1.0 sleepTime := 1.0
client, err := goobs.New("localhost:4455", goobs.WithPassword(password)) client, err := goobs.New("localhost:4455", goobs.WithPassword(password))
if err != nil { if err != nil {
@ -33,12 +32,17 @@ func main() {
} }
defer client.Disconnect() defer client.Disconnect()
cmusParams := sceneitems.NewGetSceneItemListParams().WithSceneName("cmus") cmusParams := sceneitems.NewGetSceneItemListParams().WithSceneName("cmus")
scil, err := client.SceneItems.GetSceneItemList(cmusParams) streamParams := sceneitems.NewGetSceneItemListParams().WithSceneName("stream")
cmusSCIL, err := client.SceneItems.GetSceneItemList(cmusParams)
if err != nil { if err != nil {
// i should force create the scene if it does not exist. but this is solely for me. // i should force create the scene if it does not exist. but this is solely for me.
// failing in this way is probably smarter since it forces to arrange the scene how i want it. // failing in this way is probably smarter since it forces to arrange the scene how i want it.
log.Fatalf("Expecting a scene named \"cmus\", but the scene was not found.\n%v", err.Error()) log.Fatalf("Expecting a scene named \"cmus\", but the scene was not found.\n%v", err.Error())
} }
streamSCIL, err := client.SceneItems.GetSceneItemList(streamParams)
if err != nil {
log.Fatalf("Expecting a scene named \"stream\", but the scene was not found.\n%v", err.Error())
}
var prevPath string var prevPath string
for { for {
out, err := CmusRemoteOutput() out, err := CmusRemoteOutput()
@ -50,6 +54,13 @@ func main() {
log.Fatal(err.Error()) log.Fatal(err.Error())
} }
if path != prevPath { if path != prevPath {
//stream scene
for _, sI := range streamSCIL.SceneItems {
if sI.SourceName == "cmus" {
enableItem(client, "stream", sI, false)
}
}
//cmus scene
artist, err := getAttribute(out, "tag artist ", "tag albumartist ", "tag composer ") artist, err := getAttribute(out, "tag artist ", "tag albumartist ", "tag composer ")
if err != nil { if err != nil {
log.Printf("%v does not have an artist listed.", path) log.Printf("%v does not have an artist listed.", path)
@ -65,7 +76,6 @@ func main() {
log.Printf("%v does not have an album listed.", path) log.Printf("%v does not have an album listed.", path)
album = "Single" album = "Single"
} }
art, err := retrieveArt(path) art, err := retrieveArt(path)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -80,21 +90,27 @@ func main() {
log.Printf("Could not determine color, setting to default color.\n%v", err) log.Printf("Could not determine color, setting to default color.\n%v", err)
color = 0xff424242 color = 0xff424242
} }
for i := range scil.SceneItems { for _, sI := range cmusSCIL.SceneItems {
if scil.SceneItems[i].SourceName == "Artist" { if sI.SourceName == "Artist" {
updateItem(client, scil.SceneItems[i], artist, "text") updateItem(client, sI, artist, "text")
} }
if scil.SceneItems[i].SourceName == "Song" { if sI.SourceName == "Song" {
updateItem(client, scil.SceneItems[i], title, "text") updateItem(client, sI, title, "text")
} }
if scil.SceneItems[i].SourceName == "Album" { if sI.SourceName == "Album" {
updateItem(client, scil.SceneItems[i], album, "text") updateItem(client, sI, album, "text")
} }
if scil.SceneItems[i].SourceName == "Art" { if sI.SourceName == "Art" {
updateItem(client, scil.SceneItems[i], artFile, "file") updateItem(client, sI, artFile, "file")
} }
if scil.SceneItems[i].SourceName == "Color" { if sI.SourceName == "Color" {
updateItem(client, scil.SceneItems[i], color, "color") updateItem(client, sI, color, "color")
}
}
// stream scene
for _, sI := range streamSCIL.SceneItems {
if sI.SourceName == "cmus" {
enableItem(client, "stream", sI, true)
} }
} }
} }
@ -114,3 +130,21 @@ func updateItem(client *goobs.Client, sI *typedefs.SceneItem, value any, key str
log.Fatal(err) log.Fatal(err)
} }
} }
func enableItem(client *goobs.Client, sceneName string, sI *typedefs.SceneItem, enabled bool) {
params := sceneitems.NewSetSceneItemEnabledParams().WithSceneName(sceneName).WithSceneUuid(sI.SourceUuid).WithSceneItemId(sI.SceneItemID).WithSceneItemEnabled(enabled)
_, err := client.SceneItems.SetSceneItemEnabled(params)
if err != nil {
log.Printf("could not set %v to %v.\n%v\n", sI.SourceName, enabled, err)
}
}
func getItemSettings(client *goobs.Client, sI *typedefs.SceneItem) {
params := inputs.NewGetInputSettingsParams().WithInputName(sI.SourceName).WithInputUuid(sI.SourceUuid)
gis, err := client.Inputs.GetInputSettings(params)
if err != nil {
// this is a helper function, it should not be running usually. this is fine for debugging/development
log.Fatal(err)
}
fmt.Printf("%v\n", gis)
}