Basic Scripting Question

Programming applications for making music on Linux.

Moderators: khz, MattKingUSA

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

Basic Scripting Question

Postby x7i7l » Sat Dec 22, 2018 2:26 pm

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: 111
Joined: Sun Jul 02, 2017 1:24 pm

Re: Basic Scripting Question

Postby SpotlightKid » Sat Dec 22, 2018 4:32 pm

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: 9
Joined: Sun Jun 24, 2018 3:21 am

Re: Basic Scripting Question

Postby x7i7l » Wed Dec 26, 2018 9:15 pm

Thanks for that. Yes xjadeo does have alsa midi ports.
I'll give it a shot now.

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

Re: Basic Scripting Question

Postby x7i7l » Fri Jan 18, 2019 11:04 pm

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: 111
Joined: Sun Jul 02, 2017 1:24 pm

Re: Basic Scripting Question

Postby SpotlightKid » Sat Jan 19, 2019 1:30 am

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: 857
Joined: Tue Feb 16, 2016 6:56 am
Location: Kangasala, Finland
Contact:

Re: Basic Scripting Question

Postby tavasti » Sat Jan 19, 2019 9:45 am

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

Hear my music at https://audiu.net/users/tawaste

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

Re: Basic Scripting Question

Postby x7i7l » Sat Jan 19, 2019 4:15 pm

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: 234
Joined: Mon Jan 26, 2009 5:15 pm

Re: Basic Scripting Question

Postby Drumfix » Sun Jan 20, 2019 9:42 am

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: 857
Joined: Tue Feb 16, 2016 6:56 am
Location: Kangasala, Finland
Contact:

Re: Basic Scripting Question

Postby tavasti » Mon Jan 21, 2019 12:03 am

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

Hear my music at https://audiu.net/users/tawaste

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

Re: Basic Scripting Question

Postby x7i7l » Fri Jan 25, 2019 3:28 pm

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: 283
Joined: Wed Sep 06, 2017 2:55 am
Location: Southern Utah, USA
Contact:

Re: Basic Scripting Question

Postby milo » Tue Jan 29, 2019 8:25 pm

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: 111
Joined: Sun Jul 02, 2017 1:24 pm

Re: Basic Scripting Question

Postby SpotlightKid » Wed Jan 30, 2019 9:29 am


tramp
Established Member
Posts: 1455
Joined: Mon Jul 01, 2013 8:13 am

Re: Basic Scripting Question

Postby tramp » Wed Jan 30, 2019 9:48 am

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: 9
Joined: Sun Jun 24, 2018 3:21 am

Re: Basic Scripting Question

Postby x7i7l » Thu Jan 31, 2019 6:58 am

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


Return to “Developer's Section”

Who is online

Users browsing this forum: No registered users and 2 guests