Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Output priority and fallback (Read 1128 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Output priority and fallback

Hi all,

My foobar2000 may output to :
- A USB DAC (that is my preferred output)
- A PCI sound card (that is my secondary output)

The USB DAC is only plugged in from time to time. The PCI sound card is always connected.

Since foobar2000 can dynamically detect all the output devices, I'd like to be able to automate its output without having to select it manually every time :
- When USB DAC is connected, select it as output
- Otherwise, fall back to the PCI sound card instead of just selecting "nothing" as output

Can this be achieved, either by foobar, or by a component, or by an external app ? Thanks !

Re: Output priority and fallback

Reply #1
@wcs13 , fyi, till it's fixed in fb2k you can work around this with SMP/JSP script using on_output_device_changed callback and SetOutputDevice

Re: Output priority and fallback

Reply #2
There is nothing to fix. Use default output instead of picking a device by name and mark the external DAC as default in Windows. When it gets unplugged Windows will switch to the previous default device, which would then be your PCI card.

Re: Output priority and fallback

Reply #3
@TheQwertiest , amazing as usual. Thank you. :)

@Case , I'm afraid it's not so simple. The DAC is my prefferred output for fb2k, but the PCI card is my preferred output for all other apps, all the time, including when the DAC is plugged. So I can't just set the DAC as default device in Windows. If Windows allowed to set a default device on a per-app basis, that would be a different story. Windows 7 I mean. I'll switch to Windows 10 when the laptop I want becomes available, which can still take 6 months or so.

There is nothing to "fix" in fb2k, obviously, but there may be something to "improve". Something like Prefs > Playback > Output > Device, and then "set priority order (1, 2, 3...)" or something like that.
I mean, having foobar select no output at all when the preferred output is not connected is not a bug, but it's something that could be improved IMHO.

Re: Output priority and fallback

Reply #4
Can you not just put the output switcher in the toolbar and then it's just a couple of clicks to change the output device?
Who are you and how did you get in here ?
I'm a locksmith, I'm a locksmith.

Re: Output priority and fallback

Reply #5
Can you not just put the output switcher in the toolbar and then it's just a couple of clicks to change the output device?
Sure, already done it a long time ago. :) Not good enough for me, sorry.
I often switch the DAC on and off, so having to change the device back and forth in fb2k, always between the two same devices, is really annoying.

fb2k autodetects active devices fine. We just need a way to prioritize them somehow. TheQwertiest already showed that it's possible using JS. So a short script would do the trick. A 3rd party component would work too. And hopefully this will make its way into fb2k core someday. It would be a nice added feature, probably not too difficult to add.

Re: Output priority and fallback

Reply #6
Read the tooltip. Requires >SMP 1.4.0. Install on any location (*)
Load buttons_device_priority.js

X

(*) Don't overwrite files if you use any of my other scripts, put it on its subfolder: 'xxx-scripts\devicePriority'. If you are using a buttons bar, on next releases of Playlist Tools this button will be already included ready to be added to the buttons bar. If you still want to add it to the bar with the latest release, just copy the button file to the buttons folder ' xxx-scripts\buttons' and forget the rest.

Re: Output priority and fallback

Reply #7
Fix: One callback was not working as expected.  Does not change devices while setting the menus (missing bit from testing I forgot to delete).

Overwrite old one.

As a bonus now the playback continues when changing the devices. i.e. some Bluetooth devices paused the playback when you power them off, so the device changing worked but playback remained stopped. Now if that happens after changing the device, playback continues.

Re: Output priority and fallback

Reply #8
Hi @regor , thank you so much! :D I guess that's exactly what I'm looking for.
I have a tiny little problem though :

Code: [Select]
Error: Spider Monkey Panel v1.5.1 ({CDE784FB-88D4-4A5D-9BCA-EA185948CAE7})
include failed:
Path does not point to a valid file: ..\helpers\buttons_xxx.js

File: <main>
Line: 9, Column: 1
Stack trace:
  @:9:1

Your script folder is here : C:\Program Files (x86)\foobar2000 (principal)\xxx-scripts\devicePriority
I have loaded your script, which is here : C:\Program Files (x86)\foobar2000 (principal)\xxx-scripts\devicePriority\buttons\buttons_device_priority.js
And the file it's trying to include is here : C:\Program Files (x86)\foobar2000 (principal)\xxx-scripts\devicePriority\helpers\buttons_xxx.js

Re: Output priority and fallback

Reply #9
Hi @regor , thank you so much! :D I'm sure that's what I'm looking for.
I have a tiny little problem though :

Code: [Select]
Error: Spider Monkey Panel v1.5.1 ({CDE784FB-88D4-4A5D-9BCA-EA185948CAE7})
include failed:
Path does not point to a valid file: ..\helpers\buttons_xxx.js

File: <main>
Line: 9, Column: 1
Stack trace:
  @:9:1

Your script folder is here : C:\Program Files (x86)\foobar2000 (principal)\xxx-scripts\devicePriority
I have loaded your script, which is of course here : C:\Program Files (x86)\foobar2000 (principal)\xxx-scripts\devicePriority\buttons\buttons_device_priority.js
And the file it's trying to include is here : C:\Program Files (x86)\foobar2000 (principal)\xxx-scripts\devicePriority\helpers\buttons_xxx.js
Relative folders work fine on my side (win 7), using the same zip I posted. Hope that's not another win10 / win7 difference hahaha
Note ..\\ at include equals to one one level up, therefore '..\helpers\buttons_xxx.js' does in fact point to 'devicePriority\helpers\buttons_xxx.js'

EDIT: you can replace all relative paths with the absolute counterparts and it should work. But it would be appreciated if you can look at it a bit more, since that behavior is not expected at all (may point to a bug on SMP or SO path handling).

X
X

Re: Output priority and fallback

Reply #10
I have Win 7 too !
Yes, I know that ..\\ means one level up. So it should definitely work... but it doesn't.

Absolute paths seem to work fine, because if I do this :

Code: [Select]
include('C:\\Program Files (x86)\\foobar2000 (principal)\\xxx-scripts\\devicePriority\\helpers\\buttons_xxx.js'); 
include('..\\helpers\\helpers_xxx.js');
include('..\\helpers\\helpers_xxx_file.js');
include('..\\helpers\\menu_xxx.js');

... then the error goes to the next line :
Code: [Select]
Error: Spider Monkey Panel v1.5.1 ({CDE784FB-88D4-4A5D-9BCA-EA185948CAE7})
include failed:
Path does not point to a valid file: ..\helpers\helpers_xxx.js

Please let me know if there's some more testing that I could do. Maybe it will help find a glitch, who knows !

Re: Output priority and fallback

Reply #11
I really have no idea.
Have also tested it on a portable installation (1.4.8 and 1.6.5). And also tested it with the folder at a random place and within the profile folder. In all cases it works ok.

Could you try loading it from other folder? like C:\\devicePriority\\.... Maybe the program files folder gives problems.
EDIT: a permissions problem? Hidden files or something like that?

Re: Output priority and fallback

Reply #12
I have just tried from C:\devicePriority (loading the original script without any modifications). Same exact error. So it doesn't seem to be path-related or space-related.
@TheQwertiest ? Any hints ?...

 

Re: Output priority and fallback

Reply #13
@regor , I should mention that I have another issue.
I have replaced all 4 relative paths by absolute paths, so now the script loads and I can see my device list. :)
However, if I select Device 1 > Name of the first device, and then I go to Device 1 again, I see that nothing has been selected (it defaults to "None"). It's like settings aren't remembered at all. :o

Re: Output priority and fallback

Reply #14
@regor , I should mention that I have another issue.
I have replaced all 4 relative paths by absolute paths, so now the script loads and I can see my device list. :)
However, if I select Device 1 > Name of the first device, and then I go to Device 1 again, I see that nothing has been selected (it defaults to "None"). It's like settings aren't remembered at all. :o

Do you have a folder named 'js_data\' at foobar profile folder? There should be a file named 'devices_priority.json' when you select a device. And a file named 'devices.json' when you export the current list of devices.

I can imagine that's the problem, I forgot to check if that folder exists (it's used by other multiple smp scripts) so whenever it is not present, writing a file to the path fails (folder must be explicitly created first). Check the new files (only the button one needs a fix, you can easily merge the 2 diff lines at 32 and 51)

The rel path thing maybe was related to 1.5.0 and 1.5.1. There were some changes at rel paths there. It was working on 1.4.2 and can confirm it works on my side with the latest dev build too.

Re: Output priority and fallback

Reply #15
By the way, also note that if you connect a device like headphones, export the list, select that device as (1) and then disconnect the device... the device is on the available list only because you exported the list first!

What you are seeing is not the actual device list, but the 'saved' device list. The actual device list is only used as fallback. If you export the list again without the device connected, then you will never see the device attached to (1), since its gone. Although all functionality will still work.

The same applies if you don't export the list first. You will only see the actual device list, therefore it will change according to the current devices connected.

See the gif
Spoiler (click to show/hide)
I have a Bluetooth device attached to (1). I deleted my exported list on purpose...So the device does not appear when it's off.  Although you can see at the devices_priority.json it's there assigned to (1).
As soon as I turn the device on and it's recognized by the pc, auto-switch fires and then it appears on the actual device list. You could "fix" it by exporting the list when it's connected. Note there is no other way to show devices when they are not present, so that's was my workaround.

Re: Output priority and fallback

Reply #16
Spoiler (click to show/hide)

When not using the export list feature, if a set device is not currently connected, the menus indicate it (to differentiate from real 'none'). Also at top the current device name is always shown (whether is connected or not). That should solve the confusion.

Without the export list feature, you can not set devices currently disconnected. That's by design. Only currently available ones can be set.

Re: Output priority and fallback

Reply #17
I made sure that the js_data folder existed, and the script seems to work great now ! :) The two .json files are now written correctly within that folder.
Only the 4 relative paths still don't work. I have replaced them by absolute paths, hoping that somebody finds where the glitch comes from.
Thank you again @regor , your script was just what I needed ! :D

Re: Output priority and fallback

Reply #18
The latest version already checks if the folder exists too, so it should work in any case now. The rel path errors will have to wait until @TheQwertiest checks it.

Glad you like it. I find really great that now I can just power on my Bluetooth speakers at the shower and foobar automatically switches to it, I think it will be specially useful for foobar servers, so you don't have to go to the PC at all....

Re: Output priority and fallback

Reply #19
Will create a thread when I add a release.
https://github.com/regorxxx/Device-Priority-SMP

(first upgrade all my other scripts if using them, before installing this one)