script for quick switch between audio interfaces via commandline

Talk about your MIDI interfaces, microphones, keyboards...

Moderators: MattKingUSA, khz

Post Reply
alignwaivers
Established Member
Posts: 4
Joined: Thu Sep 26, 2019 11:38 pm

script for quick switch between audio interfaces via commandline

Post by alignwaivers »

So I switch so much back and forth between my usb audio interface and my internal soundcard (when I take my laptop elsewhere), it gets a little tedious managing all the settings manually (in cadence) whenever I switch.

A slightly better step would be to create two separate rooms in claudia and switch between loading those. But I'm wondering, is there a way of switching between audio devices in the command line? Haven't had success with this but have put much effort into doing so. Any insights would be greatly appreciated, thanks

p.s. would be fine to use claudia to switch 'rooms' if I could do so from the terminal, but as far as I'm aware this is not a feature and claudia takes no arguments when run in the command line

User avatar
bluebell
Established Member
Posts: 1332
Joined: Sat Sep 15, 2012 11:44 am
Location: Saarland & Frankfurt, Germany

Re: script for quick switch between audio interfaces via commandline

Post by bluebell »

alignwaivers wrote:So I switch so much back and forth between my usb audio interface and my internal soundcard (when I take my laptop elsewhere), it gets a little tedious managing all the settings manually (in cadence) whenever I switch.

A slightly better step would be to create two separate rooms in claudia and switch between loading those. But I'm wondering, is there a way of switching between audio devices in the command line? Haven't had success with this but have put much effort into doing so. Any insights would be greatly appreciated, thanks

p.s. would be fine to use claudia to switch 'rooms' if I could do so from the terminal, but as far as I'm aware this is not a feature and claudia takes no arguments when run in the command line
AFAIK jackd's audio interface can't be changed on the fly. So you have to restart jack, e.g. with a shell script.
Linux – MOTU UltraLite AVB – Qtractor – https://soundcloud.com/suedwestlicht

User avatar
Linuxmusician01
Established Member
Posts: 702
Joined: Mon Feb 23, 2015 2:38 pm
Location: Holland

Re: script for quick switch between audio interfaces via commandline

Post by Linuxmusician01 »

I made a shell script for personal use on my various Linux machines. Maybe it's almost what you mean. You can find it here and it looks like this:

Code: Select all

┌─────────────────────────────────────┐
│              Audio menu             │
└─────────────────────────────────────┘
Use ↑ and ↓ keys to select and Enter
to execute.

 Jack audio daemon: start               
                  : kill                
 Check Midi       : port numbers        
                  : output              
 Check Alsa       : device/card numbers 
 Pulseaudio       : start               
                  : stop                
                  : PAVUControl         
 Config file      : create/edit         
                  : delete              
                  : view                
 Help                                  
 Exit                                  

alignwaivers
Established Member
Posts: 4
Joined: Thu Sep 26, 2019 11:38 pm

Re: script for quick switch between audio interfaces via commandline

Post by alignwaivers »

That's an awesome script! Thanks for sharing that

Unfortunately I am primarily interested in switching the master instead of restarting jack completely.

Do you know if that might be possible if you change the device based on the config file?





I found a useable solution (thanks to Falktx for pointing me in the right direction)

jack_control dps device "hw:USB,0" #(my audio interface)
jack_control sm

HERE's the new problem. I switch between 2 different USB audio interfaces that BOTH show up as "hw:USB,0"

I hope to find a way to clear / reset jack's memory of the devices so when I plug in the NEW device my script tries to connect to that "hw:USB,0" and ignores the old one.

The only way I know how to do that now is by stopping jack :(

User avatar
Linuxmusician01
Established Member
Posts: 702
Joined: Mon Feb 23, 2015 2:38 pm
Location: Holland

Re: script for quick switch between audio interfaces via commandline

Post by Linuxmusician01 »

alignwaivers wrote:That's an awesome script! Thanks for sharing that

Unfortunately I am primarily interested in switching the master instead of restarting jack completely.

Do you know if that might be possible if you change the device based on the config file?





I found a useable solution (thanks to Falktx for pointing me in the right direction)

jack_control dps device "hw:USB,0" #(my audio interface)
jack_control sm

HERE's the new problem. I switch between 2 different USB audio interfaces that BOTH show up as "hw:USB,0"

I hope to find a way to clear / reset jack's memory of the devices so when I plug in the NEW device my script tries to connect to that "hw:USB,0" and ignores the old one.

The only way I know how to do that now is by stopping jack :(
I don't think that I know exactly what you want but I think that it's not possible. One cannot change between audio devices without restarting Jack I think.

You might also try the commands that you already know w/ sound card names instead of sound card numbers. Like for instance:

Code: Select all

cat /proc/asound/cards
 0 [CMI8738        ]: CMI8738-MC6 - C-Media CMI8738
                      C-Media CMI8738 (model 55) at 0xd000, irq 20
 1 [PCH            ]: HDA-Intel - HDA Intel PCH
                      HDA Intel PCH at 0xf7c10000 irq 45
And then:

Code: Select all

alsamixer -c "CMI8738"
Instead of:

Code: Select all

alsamixer -c "0"

User avatar
nikgnomicradio
Established Member
Posts: 91
Joined: Wed Feb 07, 2018 9:31 pm
Contact:

Re: script for quick switch between audio interfaces via commandline

Post by nikgnomicradio »

Code: Select all

I am primarily interested in switching the master instead of restarting jack completely.
do not see how you can switch out system device that is part of the command to start JACK without restarting

maybe if started JACK with dummy device, then alsa_in and alsa_out commands to load ALSA device
would that allow ALSA device to be removed and replaced later without disturbing JACK ?
I switch between 2 different USB audio interfaces that BOTH show up as "hw:USB,0"
if they are non-identical devices, the Vendor ID (vid) and Product ID (pid) numbers can be assigned to ALSA index numbers
https://alsa.opensrc.org/MultipleUSBAudioDevices

tavasti
Established Member
Posts: 1060
Joined: Tue Feb 16, 2016 6:56 am
Location: Kangasala, Finland
Contact:

Re: script for quick switch between audio interfaces via commandline

Post by tavasti »

nikgnomicradio wrote: maybe if started JACK with dummy device, then alsa_in and alsa_out commands to load ALSA device
would that allow ALSA device to be removed and replaced later without disturbing JACK ?
Instead of alsa_in and alsa_out, jack_load could be used.
Linux veteran & Novice musician

Latest track: https://www.youtube.com/watch?v=ycVrgGtrBmM
More my music https://audiu.net/users/tawaste

merlyn
Established Member
Posts: 625
Joined: Thu Oct 11, 2018 4:13 pm

Re: script for quick switch between audio interfaces via commandline

Post by merlyn »

You can switch device while JACK is running using

Code: Select all

jack_control dps device hw:<x>
jack_control sm
You can if you're using jackdbus. Does jack_control do anything if you're using jackd?

@alignwaivers there must be a unique identifier for each card. If you do

Code: Select all

aplay -l
you'll get the card indexes which you can use as hw:<x> rather than the name of the card.
Pandemics happen. Vaccinate your children.

alignwaivers
Established Member
Posts: 4
Joined: Thu Sep 26, 2019 11:38 pm

Re: script for quick switch between audio interfaces via commandline

Post by alignwaivers »

thanks for the insights, the one issue is going by the hw:#, means you always have to plug audio devices in the same order.

Fortunately I found some good options for renaming the devices https://jackaudio.org/faq/device_naming.html


and also a completely separate solution: https://github.com/SpotlightKid/

Post Reply