Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hs.audiodevice state is particular to Hammerspoon object, not audio device (Documation clarification needed) #3559

Closed
von opened this issue Nov 11, 2023 · 1 comment

Comments

@von
Copy link
Contributor

von commented Nov 11, 2023

This is spawned from issue 3057. It is not believed to be a bug, but counterintuitive behavior that is not currently documented.

Create a watcher on an audiodevice:

> a = hs.audiodevice.allInputDevices()
> a[1]:uid()
BuiltInMicrophoneDevice
> a[1]:watcherIsRunning()
false
> a[1]:watcherCallback(c)
hs.audiodevice: MacBook Pro Microphone (0x6000006ccb98)
> a[1]:watcherStart()
hs.audiodevice: MacBook Pro Microphone (0x6000006ccb98)
> a[1]:watcherIsRunning()
true

Then re-obtain the audiodevice, the watcher will not appear to be running when examining the new object:

> a = hs.audiodevice.allInputDevices()
> a[1]:uid()
BuiltInMicrophoneDevice
> a[1]:watcherIsRunning()
false
> a[1]:watcherStart()
2022-10-19 11:32:22: 11:32:22 ERROR:   LuaSkin: You must call hs.audiodevice:setCallback() before hs.audiodevice:start()
nil

See comment from Rhys-T for more detail.

@cmsj
Copy link
Member

cmsj commented Dec 10, 2023

Yeah that is not technically a code bug, we don't keep track ourselves of the Lua objects that have previously been created to represent system resources, they just live in Lua until it decides to garbage-collect them.

It's definitely a design bug though, albeit one that is not trivial to avoid without making it impossible to ever release memory. Some of our extensions are better at this than others.

I've pushed a note to the hs.audiodevice docs to mention this, but it's definitely not the only extension where this is true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants