Page 1 of 1

Basic Scripting Question

Posted: Sat Dec 22, 2018 2:26 pm
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

Re: Basic Scripting Question

Posted: Sat Dec 22, 2018 4:32 pm
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.

Re: Basic Scripting Question

Posted: Wed Dec 26, 2018 9:15 pm
by x7i7l
Thanks for that. Yes xjadeo does have alsa midi ports.
I'll give it a shot now.

Re: Basic Scripting Question

Posted: Fri Jan 18, 2019 11:04 pm
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!

Re: Basic Scripting Question

Posted: Sat Jan 19, 2019 1:30 am
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.

Re: Basic Scripting Question

Posted: Sat Jan 19, 2019 9:45 am
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"

Re: Basic Scripting Question

Posted: Sat Jan 19, 2019 4:15 pm
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.

Re: Basic Scripting Question

Posted: Sun Jan 20, 2019 9:42 am
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

Re: Basic Scripting Question

Posted: Mon Jan 21, 2019 12:03 am
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"

Re: Basic Scripting Question

Posted: Fri Jan 25, 2019 3:28 pm
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?

Re: Basic Scripting Question

Posted: Tue Jan 29, 2019 8:25 pm
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.

Re: Basic Scripting Question

Posted: Wed Jan 30, 2019 9:29 am
by SpotlightKid

Re: Basic Scripting Question

Posted: Wed Jan 30, 2019 9:48 am
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.

Re: Basic Scripting Question

Posted: Thu Jan 31, 2019 6:58 am
by x7i7l
Thanks everyone for these ideas. They all seem workable. I'll try them out.