Skip to content

Commit

Permalink
Support switching the preview in studio mode
Browse files Browse the repository at this point in the history
`scene switch` always changes the program, but I expect it to change the
preview in case the studio mode is enabled.

So change `scene switch` to switch the preview (if studio mode is
enabled) or the program (if studio mode is disabled). Add `scene
current` for always changing the program scene and add `scene preview`
to always change the preview scene (which requires studio mode to be
enabled).

Signed-off-by: Benjamin Drung <bdrung@posteo.de>
  • Loading branch information
bdrung authored and muesli committed Nov 29, 2021
1 parent 11a70d7 commit 614a165
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,19 @@ obs-cli recording status

### Scenes

Switch to a scene:
Switch program to a scene:

```
obs-cli scene current <scene>
```

Switch preview to a scene (studio mode must be enabled):

```
obs-cli scene preview <scene>
```

Switch program (studio mode disabled) or preview (studio mode enabled) to a scene:

```
obs-cli scene switch <scene>
Expand Down
49 changes: 47 additions & 2 deletions scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/andreykaipov/goobs/api/requests/scenes"
"github.com/andreykaipov/goobs/api/requests/studio_mode"
"github.com/spf13/cobra"
)

Expand All @@ -16,9 +17,31 @@ var (
RunE: nil,
}

currentSceneCmd = &cobra.Command{
Use: "current",
Short: "Switch program to a different scene",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("current requires a scene name as argument")
}
return setCurrentScene(strings.Join(args, " "))
},
}

previewSceneCmd = &cobra.Command{
Use: "preview",
Short: "Switch preview to a different scene (studio mode must be enabled)",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("preview requires a scene name as argument")
}
return setPreviewScene(strings.Join(args, " "))
},
}

switchSceneCmd = &cobra.Command{
Use: "switch",
Short: "Switch to a different scene",
Short: "Switch program or preview in studio mode to a different scene",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("switch requires a scene name as argument")
Expand All @@ -28,15 +51,37 @@ var (
}
)

func switchScene(scene string) error {
func setCurrentScene(scene string) error {
r := scenes.SetCurrentSceneParams{
SceneName: scene,
}
_, err := client.Scenes.SetCurrentScene(&r)
return err
}

func setPreviewScene(scene string) error {
r := studiomode.SetPreviewSceneParams{
SceneName: scene,
}
_, err := client.StudioMode.SetPreviewScene(&r)
return err
}

func switchScene(scene string) error {
isStudioModeEnabled, err := IsStudioModeEnabled()
if err != nil {
return err
}

if isStudioModeEnabled {
return setPreviewScene(scene)
}
return setCurrentScene(scene)
}

func init() {
sceneCmd.AddCommand(currentSceneCmd)
sceneCmd.AddCommand(previewSceneCmd)
sceneCmd.AddCommand(switchSceneCmd)
rootCmd.AddCommand(sceneCmd)
}
10 changes: 8 additions & 2 deletions studiomode.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,19 @@ func enableStudioMode() error {
return err
}

func studioModeStatus() error {
// Determine if the studio mode is currently enabled in OBS.
func IsStudioModeEnabled() (bool, error) {
r, err := client.StudioMode.GetStudioModeStatus()
return r.StudioMode, err
}

func studioModeStatus() error {
isStudioModeEnabled, err := IsStudioModeEnabled()
if err != nil {
return err
}

fmt.Printf("Studio Mode: %s\n", strconv.FormatBool(r.StudioMode))
fmt.Printf("Studio Mode: %s\n", strconv.FormatBool(isStudioModeEnabled))
return nil
}

Expand Down

0 comments on commit 614a165

Please sign in to comment.