bfinio
Posts: 35
Joined: Mon Oct 14, 2013 8:53 pm

MIDI Instruments?

Thu Dec 03, 2015 1:49 pm

UPDATE for anyone reading this in the future: don't forget to expand your SD card's file system before attempting anything listed below!

Hi,

Could someone please give me a layman's explanation of "MIDI Instruments," what they are, and how to play them in Scratch? I've always noticed that the "set instrument" block seems not to work, and the sound always stays the same even if you pick a new instrument. I saw the blog post that mentions "support for MIDI general instruments", and this thread in the forum:

viewtopic.php?f=77&t=88024

So I took that to mean that "set instrument" would now work. However, I just tried a fresh Jessie install and tried using "play note" with different instruments, but nothing changed. Am I missing something?
Last edited by bfinio on Thu Dec 10, 2015 1:00 pm, edited 1 time in total.

timrowledge
Posts: 1139
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: MIDI Instruments?

Thu Dec 03, 2015 7:51 pm

You're simply missing the sound-fonts needed and timidity needs configuring. The opinion at Pi Towers was that the 150Mb taken by the sound font files was not something suitable to include in the general release.

See viewtopic.php?p=854029#p854029 for the shell script you need to run to to both install the files and do the configuration. I'm working on getting the info included in the Scratch related doc online.

Do please tell me how it worked for you - it should be really simple but we all know that no battle plan survives contact with reality.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

bfinio
Posts: 35
Joined: Mon Oct 14, 2013 8:53 pm

Re: MIDI Instruments?

Fri Dec 04, 2015 4:07 pm

So, as for surviving contact with reality...would it be bad news if I told you it nuked the SD card :-)? The first time I tried this, after the reboot my screen just went blank. On the off chance I had previously corrupted the SD card somehow, I tried again with these exact steps:

- flash fresh image of latest Jessie and boot up
- open terminal
- ifconfig
- (transfer timidityinstall.sh to /home/pi via FTP)
- chdmod +x timidityinstall.sh
- ./timidityinstall.sh
- "Installing Timidity and Soundfonts"
- (bunch of other stuff)
- "Installation of Timidity & Soundfonts for eVY1 Scratch is completed."
- "You need to reboot for changes to take effect."
- Menu -> Shutdown -> Reboot -> OK
- (Pi shuts down)
- (Pi starts rebooting)
- (screen goes blank after a few seconds)
- (wait patiently for a few minutes and screen is still blank)

Please note that I am a complete Linux noob and had to google how to run the script - followed the directions from the second comment here: viewtopic.php?t=26188. I think the first time I tried I went straight to ./timidityinstall.sh and got "command not found."

timrowledge
Posts: 1139
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: MIDI Instruments?

Fri Dec 04, 2015 4:22 pm

I think the phrase "Oh poo" leaps most readily to mind here. I've used that script on several Pi of varying sorts, with both wheezy and Jessie.

Were you short of space? No, that ought to have been covered by the install stuff. There simply isn't anything a fairly simple script is likely to do to cause this.

You could try manually running the apt-get install bits of the script and leave out the timidity config parts. That might provide a clue. I'm stuck in meetings today but I can take a look later and tomorrow.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

bfinio
Posts: 35
Joined: Mon Oct 14, 2013 8:53 pm

Re: MIDI Instruments?

Fri Dec 04, 2015 6:21 pm

If it's worth anything - I rolled back to the September release of Jessie and tried again, and the installation worked without causing a crash. The instruments still don't work in Scratch, but I assume that's to be expected since support wasn't added until the November release. This is all on a Pi 2. Would it help if I posted the text from the install script running?

timrowledge
Posts: 1139
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: MIDI Instruments?

Mon Dec 07, 2015 6:18 pm

Yes indeed, the output (or even dmesg log?) could be instructive. It is apparent that at least ghp (Gerhard Hepp) has been able to load it up since he has submitted a bug report about the unfortunate behaviour of the instrument-choice menus.

I imagine you ought to be able to load the newest Scratch onto a wheezy system with apt-get incantations, unless something has been set to prevent it. If so, just email me direct and I'll find way to get you a set of files worth testing.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

timrowledge
Posts: 1139
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: MIDI Instruments?

Mon Dec 07, 2015 8:30 pm

As an aside about the timidity install shell script, I just noticed while looking something up for another poster that the script is in fact already installed in /usr/share/scratch, saving the effort of fetching it. Unfortunately the execute permission was forgotten so you need to do

Code: Select all

sudo chmod a+x /usr/share/scratch/timidityinstall.sh
before actually running it with

Code: Select all

/usr/share/scratch/timidityinstall.sh
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

timrowledge
Posts: 1139
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: MIDI Instruments?

Mon Dec 07, 2015 8:37 pm

Oh, and now I see what has happened, at least enough to complain at the right people. The script wants to reconfigure ALSA and some file placements have changed since it last got checked; such is the joy of release hell.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

ghp
Posts: 1170
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: MIDI Instruments?

Mon Dec 07, 2015 9:41 pm

Hello,
I have installed the midi files recently on a fresh jessie-distribution. I have seen the reconfigure-messages to fail, ignored this and had some fun with all these fancy instruments. So although the installation is not flawless, the relevant things are done correctly.

Regards,
Gerhard

bfinio
Posts: 35
Joined: Mon Oct 14, 2013 8:53 pm

Re: MIDI Instruments?

Mon Dec 07, 2015 10:25 pm

Actually taking a look at the text when it installs - I'm guessing you're referring to this:

cp: cannot stat '/etc/modprobe.d/alsa-base.conf': No such file or directory
sed: can't read /etc/modprobe.d/alsa-base.conf.org: No such file or directory

those are the last 2 lines before "Installation of Timidity & Soundfonts for eYV1 Scratch is completed."

In case this helps at all...I went to open Epiphany so I could copy-paste those lines directly from my Pi, and I got a pop-up error message that said

"Could not start Web

Startup failed because of the following error:
Failed to create directory '/home/pi/.config/epiphany' "

(and then I wound up typing this all on my PC). So, it somehow breaks Epiphany too...

timrowledge
Posts: 1139
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: MIDI Instruments?

Mon Dec 07, 2015 11:10 pm

Eeek. Well ghp clearly had a better result, and I've tried again and had the same experience; the script complains but reboots ok and actually the MIDI seems to work afterwards.

If you're having trouble with Epiphany too then I have to suspect something more systemic since that install script is actually pretty simple. All it does is load some packages and configures one of them and then try (and fail, of course) to configure ALSA. About the only thing I can imagine causing wider issues might be running out of room but surely that would get caught long before?

Do you have a completely clean SD card to try loading up with a totally fresh copy of jessie?
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

bfinio
Posts: 35
Joined: Mon Oct 14, 2013 8:53 pm

Re: MIDI Instruments?

Tue Dec 08, 2015 12:56 pm

Yep. Using Win32DiskImager to overwrite the card with brand-new Jessie, booting up, and not doing anything else before I try this. I'll try it again today...

timrowledge
Posts: 1139
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: MIDI Instruments?

Tue Dec 08, 2015 7:25 pm

A possible experiment to try to track down this problem; separately execute each step where practical and reboot after each one. Tedious but often effective.

Breaking up the script -

Code: Select all

sudo apt-get -y install timidity timidity-daemon
split out the loading of timidity (which was pre-installed on my systems, so I think should not need any actual downloading or install)

Code: Select all

sudo apt-get fluid-soundfont-gm fluid-soundfont-gs
load the large blob of sound fonts

Code: Select all

sudo mv /etc/timidity/timidity.cfg /tmp/timidity.cfg
sudo sh -c "sed -e \"s/#source/source/g\" -e \"s/^\(source.*freepats.*\)/#\1/\" /tmp/timidity.cfg > /etc/timidity/timidity.cfg"
sudo rm /tmp/timidity.cfg
echo "\n\033[36m\033[1m Change /etc/default/timidity configuration...\033[00m\n"
sudo mv /etc/default/timidity /tmp/timidity
sudo sh -c "sed -e 's/\(\-Os\)\"$/\1 --sequencer-ports=1\"/' /tmp/timidity > /etc/default/timidity"
sudo rm /tmp/timidity
configure the timidity setup. I suggest completely leaving out the attempt to mess with the apparently non-existent alas-base.conf file.

Code: Select all

sudo service timidity stop

Code: Select all

sudo service timidity start
wild guess - if something failed in the timidity config changes above, starting the deamon might be an issue? But surely, shouldn't prevent booting.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

bfinio
Posts: 35
Joined: Mon Oct 14, 2013 8:53 pm

Re: MIDI Instruments?

Wed Dec 09, 2015 10:16 pm

Haven't had a chance to try any of your step-by-step directions yet, but small update...I actually have a black screen with a single blinking cursor all the way in the upper left corner! That seems better than a totally blank screen. At least it has a pulse.

bfinio
Posts: 35
Joined: Mon Oct 14, 2013 8:53 pm

Re: MIDI Instruments?

Wed Dec 09, 2015 10:36 pm

Aaaand I started going through this line by line as you suggested but didn't get far.

Code: Select all

sudo apt-get -y install timidity timidity-daemon
ran fine and no problems with immediate reboot.

Code: Select all

sudo apt-get fluid-soundfont-gm fluid-soundfont-gs
Gives the error "E: invalid operation fluid-soundfont-gm"

bfinio
Posts: 35
Joined: Mon Oct 14, 2013 8:53 pm

Re: MIDI Instruments?

Wed Dec 09, 2015 11:28 pm

Next attempt: I opened timidityinstall.sh and noticed that it has this all as one line:

Code: Select all

sudo apt-get -y install timidity timidity-daemon fluid-soundfont-gm fluid-soundfont-gs
As usual, Linux noob here but maybe the "-y" has something to do with the previous error message (that was missing when I ran the soundfont part as a separate line)? Anyway, running it as one line seemed to work fine at first, until it ended in this:

Code: Select all

E: IO Error to output - fwrite (28: no space left on device)
E: IO Error to output - fwrite (28: no space left on device)
E: IO Error to output - fwrite (28: no space left on device)
E: IO Error to output - fwrite (28: no space left on device)
E: IO Error to output - fwrite (28: no space left on device)
and then, when I went to launch Epiphany to paste all of that into the forum, I got the same error from earlier (failed to create directory "/home/pi/.config/epiphany").

and (light bulb goes on over head) - now I have a guess. I've been installing a fresh Jessie image on an 8GB card and this is literally the first thing I've tried each time I boot up. Never adjusted any of the raspi-config settings...including expanding the filesystem to take up the whole 8GB card. I know Jessie is already cutting it very close on a 4GB card, and I believe you said all the sound files are 150MB. So, I bet that explains it. Will try expanding the filesystem first and report back...

bfinio
Posts: 35
Joined: Mon Oct 14, 2013 8:53 pm

Re: MIDI Instruments?

Thu Dec 10, 2015 12:00 am

And that did it. Sorry for the wild goose chase. Made sure to expand the filesystem first and went back to square one. Everything works fine. I will edit my original post so anyone else who stumbles across this doesn't go down the same rabbit hole.

As I believe you mentioned somewhere, sound quality is not great over 3.5mm jack. Will test over HDMI when I get a chance.

timrowledge
Posts: 1139
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: MIDI Instruments?

Thu Dec 10, 2015 4:46 am

Oh excellent! I love it when it turns out to be simple. Sure, it can be embarrassing but an easy fix trumps that anyday.

I've been able to hear the sound over cdmi a couple of times and it is much clearer, as you'd expect. What *is* odd is that on one setup the sound was weirdly delayed unless it was continuing directly from another sound. So first sound...wait for it ... oh, there it is, next one comes promptly etc. No idea what might lead to that but we had had lots of trouble getting the a/v receiver to play anything, so maybe it had issues.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

bfinio
Posts: 35
Joined: Mon Oct 14, 2013 8:53 pm

Re: MIDI Instruments?

Thu Dec 10, 2015 1:02 pm

I did notice that over 3.5mm, each sound has a pretty long fade-out that seems to last a second or two - much longer than half a beat or whatever I had set in the block. So, maybe you can't actually hear that over HDMI (it's quieter than the initial noise), but technically it's still playing, causing the delay? Not sure...

eikimart
Posts: 1
Joined: Mon May 14, 2018 8:43 pm

Re: MIDI Instruments?

Mon May 14, 2018 8:48 pm

I'm trying to get the same thing done here some years later. I followed along with all of this, it appears to succeed and the pi reboots fine. But it doesn't actually work. In S4A (Scratch 4 Arduino) it plays the same tone as ever. In the Scratch Midi installation linked too in this thread even that doesn't work, it actually produces no sound at all. How can I better understand this? Where does timidity log to? Is there some command line tool I can use to check if timidity is doing anything?

Return to “Scratch”