Basic Scripting Question

Programming applications for making music on Linux.

Moderators: MattKingUSA, khz

Post Reply
x7i7l
Established Member
Posts: 16
Joined: Sun Jun 24, 2018 3:21 am

Basic Scripting Question

Post by x7i7l »

I'm trying to make a script and would appreciate some help. I'm really new to this kind of thing

Basically I am doing some scoring in Bitwig with xjadeo
I can manually set it up but I would like to start to understand scripting and save a little time.

The process I want to automate is this:
  • Open xjadeo
    Right click. Select Sync/MTC (ALSA Seq).
    Open a terminal. Type
    sudo modprobe snd-virmidi midi_devs=1
    Open Catia. Connect the output of the device "Virtual Raw MIDI 2-0" with the "MTC In" of "xjadeo".
So far I have all but the last step, because it's quite easy, so my script is
sudo modprobe snd-virmidi midi_devs=1
xjadeo -d alsa-seq -m alsa-seq
Does anyone know how I would achieve the last step "Connect the output of the device "Virtual Raw MIDI 2-0" with the "MTC In" of "xjadeo"."

Thanks

Adrienne
User avatar
SpotlightKid
Established Member
Posts: 250
Joined: Sun Jul 02, 2017 1:24 pm
Has thanked: 48 times
Been thanked: 54 times

Re: Basic Scripting Question

Post by SpotlightKid »

Does xjadeo have ALSA MIDI ports?

If so, you would use the 'aconnect' command line program, to connect them with the virtual MIDI port.

If xjadeo only has JACK MIDI ports, you need to run 'a2jmidid', to expose ALSA ports to JACK and then use 'jack_connect' (note the underscore, not dash) to connect them. Use the 'jack_lsp' program to list JACK port names.
x7i7l
Established Member
Posts: 16
Joined: Sun Jun 24, 2018 3:21 am

Re: Basic Scripting Question

Post by x7i7l »

Thanks for that. Yes xjadeo does have alsa midi ports.
I'll give it a shot now.
x7i7l
Established Member
Posts: 16
Joined: Sun Jun 24, 2018 3:21 am

Re: Basic Scripting Question

Post by x7i7l »

Hi,
I made some progress. But I'm stuck. The commands work if I type them in manually to the terminal, but it doesn't work when I run the script in the terminal. aconnect throws out generic -help information when I run the scrip in the terminal. Here is the script:

Code: Select all

sudo modprobe snd-virmidi midi_devs=1
nohup xjadeo -d alsa-seq -m alsa-seq &!
XJD_ID=$(aconnect -o | grep xjadeo | awk '{print $2}')
aconnect 'Virtual Raw MIDI 1-0' $XJD_ID
Can anyone point out my error?

Thank you!
User avatar
SpotlightKid
Established Member
Posts: 250
Joined: Sun Jul 02, 2017 1:24 pm
Has thanked: 48 times
Been thanked: 54 times

Re: Basic Scripting Question

Post by SpotlightKid »

Probably the value of $XJD_ID has spaces in it, so you need to quote (with double quotes) it in the last line.
tavasti
Established Member
Posts: 2047
Joined: Tue Feb 16, 2016 6:56 am
Location: Kangasala, Finland
Has thanked: 369 times
Been thanked: 208 times
Contact:

Re: Basic Scripting Question

Post by tavasti »

x7i7l wrote:Hi,

Code: Select all

sudo modprobe snd-virmidi midi_devs=1
nohup xjadeo -d alsa-seq -m alsa-seq &!
XJD_ID=$(aconnect -o | grep xjadeo | awk '{print $2}')
aconnect 'Virtual Raw MIDI 1-0' $XJD_ID
Can anyone point out my error?
What does aconnect -o | grep xjadeo print out? I suspect that there that the id has spaces, so that awk will pick only first word of that.

Try this:

Code: Select all

sudo modprobe snd-virmidi midi_devs=1
nohup xjadeo -d alsa-seq -m alsa-seq &!
XJD_ID=$(aconnect -o | grep xjadeo | tail -n1  | sed "s/'\$//;s/^.*'//")
aconnect 'Virtual Raw MIDI 1-0' "$XJD_ID"

Linux veteran & Novice musician

Latest track: https://www.youtube.com/watch?v=ycVrgGtrBmM

x7i7l
Established Member
Posts: 16
Joined: Sun Jun 24, 2018 3:21 am

Re: Basic Scripting Question

Post by x7i7l »

Hi, thanks for your help, but these suggestions did not work

@spotlight kid: adding double quotes doesn't make the connection prints out
nohup: appending output to 'nohup.out'
invalid destination address
[1]+ Done nohup xjadeo -d alsa-seq -m alsa-seq
@tavasti: aconnect -o | grep xjadeo prints out
client 129: 'xjadeo-30583' [type=user,pid=30583]
The changes to the script you proposed fails and prints out
nohup: appending output to 'nohup.out'
invalid destination address [type=user,pid=30583]
Scripting, grep, etc is all new to me so I am not able to figure out what the problem is.
Drumfix
Established Member
Posts: 299
Joined: Mon Jan 26, 2009 5:15 pm
Been thanked: 11 times

Re: Basic Scripting Question

Post by Drumfix »

On my system the following script does work:

Code: Select all

sudo modprobe snd-virmidi midi_devs=1
nohup xjadeo -d alsa-seq -m alsa-seq &!
sleep 1
XJD_ID=`aconnect -o | grep xjadeo | awk '{print $3}' | tr -d \'`
aconnect 'Virtual Raw MIDI 1-0' $XJD_ID
tavasti
Established Member
Posts: 2047
Joined: Tue Feb 16, 2016 6:56 am
Location: Kangasala, Finland
Has thanked: 369 times
Been thanked: 208 times
Contact:

Re: Basic Scripting Question

Post by tavasti »

x7i7l wrote: @tavasti: aconnect -o | grep xjadeo prints out
client 129: 'xjadeo-30583' [type=user,pid=30583]
Ok, so this should work:
sudo modprobe snd-virmidi midi_devs=1
nohup xjadeo -d alsa-seq -m alsa-seq &!
XJD_ID=$(aconnect -o | grep xjadeo | tail -n1 | sed "s/' .*\$//;s/^.*'//")
aconnect 'Virtual Raw MIDI 1-0' "$XJD_ID"

Linux veteran & Novice musician

Latest track: https://www.youtube.com/watch?v=ycVrgGtrBmM

x7i7l
Established Member
Posts: 16
Joined: Sun Jun 24, 2018 3:21 am

Re: Basic Scripting Question

Post by x7i7l »

Hi Tavasti, hi Drumfix,
Thanks. both of your solutions worked - except for one thing
My system has started naming the virtual midi devices differently since last time I was playing with this script (I don't undestand why). Now the virtual midi device is named "Virtual Raw MIDI 2-0", instead of "Virtual Raw MIDI 1-0".
I adapted Drumfix's solution because I could follow it. I couldn't quite understand how Tavasti's solution functons.

Code: Select all

pkexec modprobe snd-virmidi midi_devs=1
nohup xjadeo -d alsa-seq -m alsa-seq &!
sleep 1
XJD_ID=`aconnect -o | grep xjadeo | awk '{print $3}' | tr -d \'`
VMD_ID=`aconnect -o | grep Virtual | awk '{print $3}' | tr -d \'`
aconnect $VMD_ID $XJD_ID
rm nohup.out
The last issue I'm facing is calling up the script from the GUI - I would like to place it on my desktop. - you'll notice I used "pkexec" before modprobe instead of "sudo". If I execute the script from the terminal, it works, but if I execute it from pcmanfm it does nothing. I am not sure how to debug the script when I run it from pcmanfm because there is no output.

Does anyone know how I can successfully call up the super user privileges from the GUI?
User avatar
milo
Established Member
Posts: 1242
Joined: Wed Sep 06, 2017 2:55 am
Location: Southern Utah, USA
Has thanked: 275 times
Been thanked: 218 times
Contact:

Re: Basic Scripting Question

Post by milo »

x7i7l wrote:Does anyone know how I can successfully call up the super user privileges from the GUI?
On XFCE you can make a panel launcher for a script, and there is a checkbox to have it run in a terminal. For scripts that require sudo, the first thing you see in the terminal that pops up is a prompt is for your password. Not sure if this would work in your situation, or if there is an analogous function in other desktop environments, but it's a useful feature on XFCE.
User avatar
SpotlightKid
Established Member
Posts: 250
Joined: Sun Jul 02, 2017 1:24 pm
Has thanked: 48 times
Been thanked: 54 times

Re: Basic Scripting Question

Post by SpotlightKid »

tramp
Established Member
Posts: 2335
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 454 times

Re: Basic Scripting Question

Post by tramp »

pkexec is a good choice for such a action. Just, you need to write a policyconfig file in order to allow yourself to run /sbin/modprobe as user with the UID 0/root flag set.
Check the pkexec man-page for how to do it.
https://www.freedesktop.org/software/po ... xec.1.html

here is a policyconfig file I use to allow myself to run a special command with the UID 0/root flag set without the need to enter a password to run it with root rights.

https://github.com/brummer10/nosuspend/ ... cy.relaxed

You could easily edit it for your needs.
On the road again.
x7i7l
Established Member
Posts: 16
Joined: Sun Jun 24, 2018 3:21 am

Re: Basic Scripting Question

Post by x7i7l »

Thanks everyone for these ideas. They all seem workable. I'll try them out.
Post Reply