Shaurya
Posts: 26
Joined: Sat Mar 02, 2019 7:37 am

Running two applications on startup

Mon Jun 22, 2020 8:14 am

Hello!
I am using the pi to try and make a drum kit. I am very new to this so please forgive me for stupid questions.
I want to start puredata at bootup, which I did by finding the autostart file in LXDE folder and adding this line-

Code: Select all

@lxterminal -e /usr/bin/pd -alsamidi -mididev 1 DrumKit.pd
This works fine but now I want to also connect a midi device with puredata.
I can do this by manually opening aconnectgui and making the connections or by

Code: Select all

sudo aconnect 20 128
I have noted the client numbers, as you see.
I need to connect the device at startup.

I tried

Code: Select all

@lxterminal -e /usr/bin/pd -alsamidi -mididev 1 DrumKit.pd aconnect 20 128
I also tried to use another lxterminal window by adding another line after the pd startup line-

Code: Select all

@lxterminal -e /usr/bin/aconnect aconnect 20 128
But it did not work. (Only pd started up)
I know I am making a tiny mistake, but where???
Thank you

User avatar
kerry_s
Posts: 2365
Joined: Thu Jan 30, 2020 7:14 pm

Re: Running two applications on startup

Mon Jun 22, 2020 9:00 am

i'll teach you how to make things easy.

oops forgot, need to create that folder:

Code: Select all

 mkdir ~/.config/autostart
open a terminal:

Code: Select all

mousepad ~/.config/autostart/startup.desktop
in that file put this & save:

Code: Select all

[Desktop Entry]
Type=Application
Exec=/home/pi/startup
now for the startup file:

Code: Select all

mousepad ~/startup
in that put this & save:

Code: Select all

#!/bin/sh
lxterminal -e /usr/bin/pd -alsamidi -mididev 1 DrumKit.pd &
sudo aconnect 20 128 &
now ya need to make that file executable:

Code: Select all

chmod +x ~/startup

now just undo all the changes in that other file and reboot.
now you have quick access to add & remove whatever you want
good luck

klricks
Posts: 8018
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Running two applications on startup

Mon Jun 22, 2020 1:10 pm

Autostart processes lines of code differently.
Each line is run independently at nearly the same time in a parallel fashion.... Or the autostart does not wait for the first command to finish before starting the next command.

If you need to run the commands sequentially then you need to create a bash script containing your commands, then call the bash script from autostart.

Or use the method kerry_s suggested.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

Shaurya
Posts: 26
Joined: Sat Mar 02, 2019 7:37 am

Re: Running two applications on startup

Tue Jun 23, 2020 9:37 am

Thank you for providing the instructions.
I tried kerry_s's method by creating the desktop file and the startup file. But again, only pd starts up with the configs and the DrumKit.pd file. The midi device does not get connected.
Each line is run independently at nearly the same time in a parallel fashion....
I noticed that pd takes a second or two to start up, set the midi ports and load the patch.
I think, because both the commands (start pd and aconnect) are run in a parallel fashion, there are issues with connections, ie aconnect can't connect to client 128 cuz pd hasn't fully started yet...
Of course that is just my theory.
I looked up some articles about the sleep command in bash script, so I think that would be the way to go.
Something like
-> start pd
-> wait 2 seconds
-> connect 20 with 128???
Thank you for listening to me...

User avatar
kerry_s
Posts: 2365
Joined: Thu Jan 30, 2020 7:14 pm

Re: Running two applications on startup

Tue Jun 23, 2020 10:46 am

Code: Select all

lxterminal -e /usr/bin/pd -alsamidi -mididev 1 DrumKit.pd; aconnect 20 128 &
try this than the command will run in order after the first completes.

klricks
Posts: 8018
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Running two applications on startup

Tue Jun 23, 2020 2:35 pm

Shaurya wrote:
Tue Jun 23, 2020 9:37 am
Thank you for providing the instructions.
I tried kerry_s's method by creating the desktop file and the startup file. But again, only pd starts up with the configs and the DrumKit.pd file. The midi device does not get connected.
Each line is run independently at nearly the same time in a parallel fashion....
I noticed that pd takes a second or two to start up, set the midi ports and load the patch.
I think, because both the commands (start pd and aconnect) are run in a parallel fashion, there are issues with connections, ie aconnect can't connect to client 128 cuz pd hasn't fully started yet...
Of course that is just my theory.
I looked up some articles about the sleep command in bash script, so I think that would be the way to go.
Something like
-> start pd
-> wait 2 seconds
-> connect 20 with 128???
Thank you for listening to me...
Bash files do not run commands in parallel. That's the whole reason for making the batch file.

You can use one or more sleep commands:

Code: Select all

#!/bin/sh
lxterminal -e /usr/bin/pd -alsamidi -mididev 1 DrumKit.pd &
sleep 5         # Adjust as needed
sudo aconnect 20 128 & 
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

Shaurya
Posts: 26
Joined: Sat Mar 02, 2019 7:37 am

Re: Running two applications on startup

Tue Jun 23, 2020 4:59 pm

Hello!
I tried both the methods that you provided. Neither of them seem to work. Where am I going wrong???
Only pd starts and the device doesn't get connected.
Thank you

User avatar
kerry_s
Posts: 2365
Joined: Thu Jan 30, 2020 7:14 pm

Re: Running two applications on startup

Tue Jun 23, 2020 8:05 pm

Shaurya wrote:
Tue Jun 23, 2020 4:59 pm
Hello!
I tried both the methods that you provided. Neither of them seem to work. Where am I going wrong???
Only pd starts and the device doesn't get connected.
Thank you
wow, must of been tired. your using lxterminal to run it. it doesn't know the difference between spaces & end. ya have to enclose it so it runs as 1 command.

Code: Select all

lxterminal -e '/usr/bin/pd -alsamidi -mididev 1 DrumKit.pd; aconnect 20 128' &

klricks
Posts: 8018
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Running two applications on startup

Tue Jun 23, 2020 8:08 pm

Shaurya wrote:
Tue Jun 23, 2020 4:59 pm
Hello!
I tried both the methods that you provided. Neither of them seem to work. Where am I going wrong???
Only pd starts and the device doesn't get connected.
Thank you
Does it work if you run the startup script from the command line?
Do the programs require network connection?
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

Shaurya
Posts: 26
Joined: Sat Mar 02, 2019 7:37 am

Re: Running two applications on startup

Wed Jun 24, 2020 8:28 am

Hello again!
Really sad to say that this method also didn't work. Adding apostrophes to the ends of the command just opens a terminal window with a title that is same as the command.

User avatar
kerry_s
Posts: 2365
Joined: Thu Jan 30, 2020 7:14 pm

Re: Running two applications on startup

Wed Jun 24, 2020 8:59 am

put the whole command in a terminal & see what the error is.
Attachments
2020-06-23-225812_1600x900_scrot.png
2020-06-23-225812_1600x900_scrot.png (47.36 KiB) Viewed 797 times

Shaurya
Posts: 26
Joined: Sat Mar 02, 2019 7:37 am

Re: Running two applications on startup

Wed Jun 24, 2020 5:33 pm

put the whole command in a terminal & see what the error is.
There is no error. Only a terminal window opens with "pd -alsamidi -mididev 1 Drumkit.pd" and the whole command as the title.
I also experimented with previously given methods. I found that typing this in the terminal

Code: Select all

 lxterminal -e /usr/bin/pd -alsamidi -mididev 1 DrumKit.pd& sleep 5; aconnect 24 128 &

Runs pd and connects the midi device, just the way I wanted.
I copied this text and pasted it in the startup file, but like earlier, only pd starts up, and the midi device doesn't get connected...
Any ideas???

User avatar
kerry_s
Posts: 2365
Joined: Thu Jan 30, 2020 7:14 pm

Re: Running two applications on startup

Wed Jun 24, 2020 8:30 pm

does it need the " lxterminal -e " ?
this seems like something that just needs to be running in the background.

Return to “General discussion”