Where is the init.rb that everyone is talking about?
I have three raspberry pi 4’s in front of me, with a new download of sonic pi from the web, not through terminal. None of them have a file called init.rb anywhere, what am I missing? Where is that file supposed to be?
There is a config folder, but no files in that folder.
I am looking to start playing immediately on boot of a headless raspberry pi getting midi input.
Hi @louiselessel
I see that if you have installed Sonic Pi for the first time, the init.rb file is not created automatically. (Or at least, that is how it appears to be, after I simulated this by renaming Sonic Pi’s .sonic-pi folder and opening Sonic Pi, to pretend that this was a fresh install). I’ll double check this behaviour, in case it was actually our intention here that the init file should be automatically created for you.
The default location is indeed in the ~/.sonic-pi/config folder. It will be just a matter of creating a file in there called init.rb and filling it with whatever Sonic Pi code you wish to run on Sonic Pi startup.
(There are examples of this and other files that live in the config folder, at the following link):
just to confirm, the init.rb file doesn’t exist until you have started Sonic Pi at least once. “Installing” Sonic Pi is just a matter of putting the app in the program files/app directory and doesn’t modify anything else. Only when you start the program does it check to see if you have a ~/.sonic-pi directory and if not it creates it. This is where all the config/log/buffers are stored so that Sonic Pi remembers the state of the app when you close it so that it’s the same when you open it again.
Hi both, thank you for the quick reply.
I have opened and closed sonic pi many times after the install and I have things in at least buffer number zero. The init.rb file did not get created.
I also tried making the directory in config/user examples/ and putting a file named init.rb in it. Nothing happened. Is there a good way to check the init.rb does run? Some init.rb demo code I could check?
that’s very curious. Firstly, the buffers shouldn’t be in the log folder, it’s very strange that they are for you, they should be inside ~/.sonic-pi/store/default. The init.rb file should be found at ~/.sonic-pi/config/init.rb.
What do you see inside your ~/.sonic-pi folder? For me, it’s the sub-folders: config, log and store. These store the following:
Hi, I am so sorry about the late reply. It appears it was not sent through the email.
Got the pi again and this is what the directory looks like (I have code in 3 of the stores in Sonic Pi and a saved file in my Documents folder as well):
Got the pi again and this is what the directory looks like (I have code in 3 of the stores in Sonic Pi and a saved file in my Documents folder as well):
Sure, that’s worth a try. You can put anything in the init.rb file that you would normally put in a standard Sonic Pi buffer - it should get evaluated as you boot the app.
Could not find init.rb file: /home/pi/.sonic-pi/config/init.rb
I would definitely try creating this manually and seeing if it works. Simply putting sample :loop_amen in there should make the amen break play on app start… fingers crossed!
I tried having it print something on the pi 4 last week but that did nothing, so I was confused as to where this goes. Since there was no visual output either. I think it’d definitely be a nice user friendly feature request if there was a buffer that you could find inside the gui of sonic pi that would just auto play on boot. Like buffer 0 through 9 + buffer “boot”
Actually, the init.rb file is silent in terms of visual output and log by design. It was really just intended for people to load functions and other data that is common for their music projects.
Out of interest, what are you specifically trying to achieve?
Just a thought, but is having text output of init.rb optionally visible (but silent by default) via a setting agreeable? Seems like it is harmless enough…