Compare commits

..

4 Commits

3 changed files with 35 additions and 14 deletions

View File

@ -4,7 +4,7 @@ INSTALLDIR = ~/Library/Application\ Support/com.elgato.StreamDeck/Plugins/com.dl
#SDPLUGINDIR = "./com.dlprows.macvolumecontrol.sdPlugin" #SDPLUGINDIR = "./com.dlprows.macvolumecontrol.sdPlugin"
update: update:
killall Stream\ Deck.app || true killall Stream\ Deck || true
go build -o $(INSTALLDIR) . go build -o $(INSTALLDIR) .
open -a Elgato\ Stream\ Deck open -a Elgato\ Stream\ Deck

View File

@ -95,7 +95,7 @@ func setup(client *streamdeck.Client) {
return err return err
} }
return setFeedbackIfNeeded(ctx, client, newSettings) return setFeedback(ctx, client, newSettings)
}) })
action.RegisterHandler(streamdeck.WillDisappear, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error { action.RegisterHandler(streamdeck.WillDisappear, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error {
@ -119,17 +119,14 @@ func setup(client *streamdeck.Client) {
ctx := context.Background() ctx := context.Background()
ctx = sdcontext.WithContext(ctx, ctxStr) ctx = sdcontext.WithContext(ctx, ctxStr)
setFeedbackIfNeeded(ctx, client, newSettings) setFeedback(ctx, client, newSettings)
} }
_currentSettings = newSettings
} }
}() }()
} }
func setFeedbackIfNeeded(ctx context.Context, client *streamdeck.Client, newSettings *volume.VolumeSettings) error { func setFeedback(ctx context.Context, client *streamdeck.Client, newSettings *volume.VolumeSettings) error {
if _currentSettings.OutputVolume == newSettings.OutputVolume && _currentSettings.OutputMuted == newSettings.OutputMuted {
return nil
}
payload := FeedbackPayload{} payload := FeedbackPayload{}
@ -151,10 +148,19 @@ func setFeedbackIfNeeded(ctx context.Context, client *streamdeck.Client, newSett
payload.Icon = ValueWithOpacity[any]{nil, opacity} payload.Icon = ValueWithOpacity[any]{nil, opacity}
_currentSettings = newSettings
return client.SetFeedback(ctx, payload) return client.SetFeedback(ctx, payload)
} }
func setFeedbackIfNeeded(ctx context.Context, client *streamdeck.Client, newSettings *volume.VolumeSettings) error {
if _currentSettings.OutputVolume == newSettings.OutputVolume && _currentSettings.OutputMuted == newSettings.OutputMuted {
return nil
}
_currentSettings = newSettings
return setFeedback(ctx, client, newSettings)
}
type FeedbackPayload struct { type FeedbackPayload struct {
Value ValueWithOpacity[string] `json:"value"` Value ValueWithOpacity[string] `json:"value"`
Indicator ValueWithOpacity[int] `json:"indicator"` Indicator ValueWithOpacity[int] `json:"indicator"`

View File

@ -2,8 +2,9 @@ package volume
/* /*
#cgo CFLAGS: -x objective-c #cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework CoreAudio #cgo LDFLAGS: -framework CoreAudio -framework AudioToolbox
#include <CoreAudio/CoreAudio.h> #include <CoreAudio/CoreAudio.h>
#include <AudioToolbox/AudioToolbox.h>
*/ */
import "C" import "C"
import ( import (
@ -42,11 +43,18 @@ func GetDefaultOutputDevice() (AudioObjectID, OSStatus) {
func GetVolume(objectID AudioObjectID) (float32, OSStatus) { func GetVolume(objectID AudioObjectID) (float32, OSStatus) {
properties := C.AudioObjectPropertyAddress{
C.kAudioHardwareServiceDeviceProperty_VirtualMainVolume,
C.kAudioDevicePropertyScopeOutput,
C.kAudioObjectPropertyElementMain,
}
/*
properties := C.AudioObjectPropertyAddress{ properties := C.AudioObjectPropertyAddress{
C.kAudioDevicePropertyVolumeScalar, C.kAudioDevicePropertyVolumeScalar,
C.kAudioDevicePropertyScopeOutput, C.kAudioDevicePropertyScopeOutput,
0, //main channel 0, //main channel
} }
*/
var data C.Float32 var data C.Float32
dataSize := C.UInt32(unsafe.Sizeof(data)) dataSize := C.UInt32(unsafe.Sizeof(data))
@ -65,11 +73,18 @@ func GetVolume(objectID AudioObjectID) (float32, OSStatus) {
func SetVolume(objectID AudioObjectID, volume float32) OSStatus { func SetVolume(objectID AudioObjectID, volume float32) OSStatus {
properties := C.AudioObjectPropertyAddress{
C.kAudioHardwareServiceDeviceProperty_VirtualMainVolume,
C.kAudioDevicePropertyScopeOutput,
C.kAudioObjectPropertyElementMain,
}
/*
properties := C.AudioObjectPropertyAddress{ properties := C.AudioObjectPropertyAddress{
C.kAudioDevicePropertyVolumeScalar, C.kAudioDevicePropertyVolumeScalar,
C.kAudioDevicePropertyScopeOutput, C.kAudioDevicePropertyScopeOutput,
0, //main channel 0, //main channel
} }
*/
data := C.Float32(volume) data := C.Float32(volume)