How to Send MIDI Music to the Spielatron
by Averton Engineering in Circuits > Robots
1900 Views, 17 Favorites, 0 Comments
How to Send MIDI Music to the Spielatron
![instructables02.png](/proxy/?url=https://content.instructables.com/FB3/MVDO/JACTTQZR/FB3MVDOJACTTQZR.png&filename=instructables02.png)
This Instructable covers the software tools we use to easily take standard music notation, convert it to a MIDI file and play it on the Spielatron.
FOSS
![Spielatron software tools + Greensleeves performance](/proxy/?url=https://content.instructables.com/FPW/7J4Y/JACTTQY9/FPW7J4YJACTTQY9.jpg&filename=Spielatron software tools + Greensleeves performance)
Wherever possible we use Free & Open Source Software (FOSS) running on a Linux computer, in this case using Ubuntu Mate.
Arranging or Composing Music to Play
![Musescore 01.png](/proxy/?url=https://content.instructables.com/FQU/BGB2/JACTTQXS/FQUBGB2JACTTQXS.png&filename=Musescore 01.png)
As our music abilities are limited, composing is not a real option, and to avoid copyright issues we like to arrange old classics into single line pieces suitable for the Spielatron. Basically you need to keep the music monophonic ie single note only and within the Spielatron's note range G5 to G7. For this purpose we use Musescore which we have found to be totally awesome for this purpose and for creating musical scores from which to play.
We use the Linux 64 bit app image available from
https://musescore.org/en/download/musescore-x86_64...
One trick we use to keep the notes on the stave considering the high register of the Spielatron is to use the Treble Clef 8va option from the Clef Pallette, note the small 8 above the treble clef.
One of the great things about Musescore is the amazing community providing help, tutorials, examples and lots of Musescore files to download.
Export a MIDI File
![Musescore 02-e.png](/proxy/?url=https://content.instructables.com/F6D/0522/JACTTQXT/F6D0522JACTTQXT.png&filename=Musescore 02-e.png)
Once you are happy with your musical composition in Musescore you need to export it as a MIDI file. This is in File - Export and select the file format Standard Midi.
Connecting the Spielatron to ALSA MIDI Programs
![ttymidi 01.png](/proxy/?url=https://content.instructables.com/FFV/WB2J/JACTTQXU/FFVWB2JJACTTQXU.png&filename=ttymidi 01.png)
As we now wish to send our MIDI file to the Arduino on the Spielatron we need a connection between a USB device eg. ttyUSB0 and MIDI software eg. ALSA programs. Also this connection is at a computer baud rate rather than the standard MIDI baud rate of 31250.
Fortunately someone else has already written a driver program to perform this task called ttymidi.
ttymidi is available from here:
http://www.varal.org/ttymidi/ttymidi.tar.gz
This program is only supplied as source code with a make file. When we ran the make file we received a linker error and had to modify the make file as follows.
Original command line which gave the errors
gcc src/ttymidi.c -o ttymidi -lasound
modified command line which worked
gcc src/ttymidi.c -o ttymidi -lasound -lpthread
In the end we did not run the make file and only compiled it with the command line above, so it is not installed on our system. When we wish to run ttymidi we open a terminal window, change directory to the ttymidi directory and execute the program as per the image above. With no switches used ttymidi defaults to 115200 baud rate which matches the code we supplied for the Spielatron. Note that once ttymidi is executed the terminal window does not return to the command prompt until "control c" is entered which exits the program.
Setting a MIDI Device Name and USB Port
![ttymidi 02.png](/proxy/?url=https://content.instructables.com/FNS/UTW4/JACTTQXV/FNSUTW4JACTTQXV.png&filename=ttymidi 02.png)
In this example we have used ttymidi with no switches which defaults to using ttyUSB0 and 115200 baud rate. If for any reason you needed to change these eg. you had more than one ttyUSB device connected to your computer, you can use the switches as shown in the picture above.
Using LMMS
![LMMS 01-e.png](/proxy/?url=https://content.instructables.com/FNE/UIU1/JACTTQXL/FNEUIU1JACTTQXL.png&filename=LMMS 01-e.png)
LMMS (formerly Linux MultiMedia Studio) is a digital audio workstation application program which is another totally awesome program that we are only beginners at using. LMMS is available from the Ubuntu Software Centre or here https://lmms.io/
Although for this purpose we are not using LMMS to play the MIDI file from the computer, LMMS still expects a sound font to be available to use when importing MIDI files. Therefore we are using Unison sound font which is available here:
ftp://ftp.personalcopy.net/pub/Unison.sf2.gz
http://www.personalcopy.com/linuxfiles.htm
To use the sound font all you need to do is extract the file into a directory that you are going to keep and then in LMMS go to Edit - Settings - Folders to set Unison as the default sound font, as per the picture above.
Import Your MIDI File Into LMMS
![LMMS 02.png](/proxy/?url=https://content.instructables.com/FNQ/Z0YW/JACTTQXO/FNQZ0YWJACTTQXO.png&filename=LMMS 02.png)
Import the MIDI file you created with Musescore (or from any other source) into LMMS. Use File - Import as per the picture above.
Set LMMS Output to TtyUSB0
![LMMS 03-e.png](/proxy/?url=https://content.instructables.com/FHI/U78J/JACTTQXP/FHIU78JJACTTQXP.png&filename=LMMS 03-e.png)
Once the MIDI file is imported it will appear in the Song Editor window as a Unison track. Go to the gear wheel symbol on the left end of the track. Left click on the gear wheel, select Midi then Output and you should see a device called ttymidi (or the name that you supplied with the -n switch when starting ttymidi) as per the picture above. Select this device and you should see a tick beside it.
Stop Computer Sound Output
![LMMS 04-e.png](/proxy/?url=https://content.instructables.com/F2I/G0WN/JACTTQXQ/F2IG0WNJACTTQXQ.png&filename=LMMS 04-e.png)
If you play the track at this point, LMMS will output the MIDI file to both ttyUSB0 (the Spielatron) and the computer sound card. As the Spielatron software has a 200ms delay to allow for the rotational sevos to travel, the Spielatron's music is delayed by this amount which will be out of sync with the computer sound card output. This can be overcome by turning down the volume on the Unison track as per the picture above.
Hit Play, Sit Back and Enjoy the Music!
![LMMS 06-e.png](/proxy/?url=https://content.instructables.com/FR0/9EO4/JACTTQXR/FR09EO4JACTTQXR.png&filename=LMMS 06-e.png)
Press play button as per the picture above and the Spielatron or any other Arduino music synth will play your MIDI piece. In the example at the end of the opening video the Spielatron on location plays the well known Old English folk song Greensleeves.
Apart from the music needing to be monophonic and within the range of G5 to G7, there is obviously a limitation imposed by the response time of the servos. This means that your music is limited either by the shortness if note used or the beats per minute (BPM) used. ie. if you have a high BPM then you will not be able to use very short notes or vice versa.
Example:
120 BPM at 4/4 time (4 beats per bar) gives 30 bars in 1 minute.
60 seconds divided by 30 gives 2 seconds per bar.
Therefore a crotchet will have 500ms each (easily within the servo delay time).
A quaver will have 250ms (just in the time allowing 200ms for rotation & 40ms for hammer travel).
A semiquaver is just not on without reducing the BPM.