Gotchas when converting midi to Sonic Pi

This article only makes sense when you have looked at the two previous articles on this topic which are here for part 1 and here for part 2.

Having extensively used the script to convert midi to Sonic Pi format over the last fortnight, I thought it might be useful to detail some of the pitfalls and gotachs that occur when using it, so that others can have a less steep learning curve aobut how to use it effectively. The script works very well, but does have strict limits as to what it can handle. With judicious use of MusicScore to prepare the parts that you feed into the script I have found that it is possible to prepare quite complicated pieces so that they can be converted to Sonic Pi format.

The limitations of the script are as follows.

  1. It can only deal with parts which contain 1 voice. If your part has a structure containing 2 or more voices (you can see this by selecting the whole part and checking that it is all one (blue) colour. If you see green or (red) sections it contains 2 (or 3) voices and these must be separated into separate parts (which is fairly easy to do). which are then processed individually by the script. (NB you will occasionally see  one or two red notes in UNSELECTED parts. These signify notes which are out of the normal note range specified for the instrument which is selected. E.G. F3 would be just below the range of a Violin which goes down to G3.
  2. Chords in parts are permissable provided that no note within the chord is tied to another note (you will see the tie symbol). If this is the case, then you need to either remove the tie (which means the music will not sound exactly as intended) or split the part concerned into 2 parts, with the tied note separated from the remainder of the chord (although played at the same time by the second part). The easiest way to do this is to create a new blank part (using the same instrument) by means of the instruments… command on the edit menu, and then copy and select the bar(s) containing the tied note chord combination to this second part. You can then delete the tied note from the first part and the chords from the second, thus separating them. (You would also delete notes that are directly duplicated in the second part so that they are not played twice).
  3. If you have already existing, or add, ornaments such as tr(ill) symbols to a part, then they will be ignored by the script. To get them to work, you have to export the part (or the whole score) again as a midi file and reimport it, when the trills and other ornaments will be replaced by a sequence of notes instead.
  4. If you have tempo changes attached to a note in one part, then they are automatically applied to every part at the same time point in the score. This only works for each part that is to be used with the conversion script if a note or rest STARTS at that particular instant of time in EVERY part. The problem usually occurs in a piece where a ralentando or slowing up is applied with sucessive changes in tempo often within the same bar or couple of bars usually at the end of a piece. A “normal” midi player can usually cope even if note changes are not aligned in every part during the ralentando. When you want to use the parts with the script you may have to simplify the ralentando to make sure that temp changes can occur properly in EVERY part. The usual gotch is when one or more parts has a complete bar’s rest during the ralentando. In this case, if the temp change occurs within this bar it is important to replace the bar rest symbol with a sequence of shorter rests e.g. one per beat, so that the tempo change can be effected properly for the part containing the bar’s rest.
  5. Piano or other keyboard parts can be problematical. These usually have two staves linked together (a treble and a bass clef part). You need first of all to split these two linked parts which you can do by creating two further Piano (for example) instrument pairs of staves, but delete the bass clef from the first and the treble clef from the second. You then copy the linked treble and bass parts in the original piano part repectively to the two new clefs you have created. However, if the two treble and bass parts are themselves quite complex with two voices per part, then you will have to further separate these into separate parts. I have converted several such parts which have required a total of 6 parts to replace the original linked treble and bass parts. As all these parts will finally be played together it doesn’t matter which part any notes end up in. It may look messy but it will still sound OK.

How do you know when things are not right? The most obvious is when the script stops with an error. usually is occurs with a ArrayIndexOutOfBoundsException with  array t1[2] often accompanied by warning messages printed on the output screen. This often occurs when you have not properly separated a part containing two voices. Seconodly the script may run, but within the black console window one or more warnings are printed before the script output. This usually occurs when you have chords with ties to notes outside the chord. If you have difficulty tracking down the cause of problems,  you can resort to shortening (a copy) of the part a bar (or two or three bars) at a time and rerunning the script to try and find the location and cause of the problem.

I hope that the above comments will help you to get the best of the script. The more you practice with it the easier it will become. It is best to start converting some parts which are likely to meet the requirements. e.g. a solo wind instrument part until you get the hang of it. It is also a good idea to spend some time learning how to use MuseScore effectively. The commands you will need include:

  1. Using the instruments… command on the edit menu to create extra parts.
  2. Using the Parts… command on the File menu to split up the score into separate parts. I usually name them p1,p2,p3…etc rather than using the instrument names as it makes it much quick when you come to select the files for use in the script. You will still see the instrument names on the first page of the score.
  3. Using the Export Parts .. command on the File menu. This lets you export the parts in whatever format you require. Make sure you select .mid or .xml as required for Midi export or music xml export, using the file type selector. (Don’t use the compressed music xml format .mxl)
  4. Use short cut Home and End keys (on Mac Fn <- and Fn -> ) to move to the beginning or end page of the score. There is a good table of shortcuts here
  5. Selecting a part: click on an empty section of the first bar to select it. Go to end of the part (see 4 above). Shift click on the last bar in the part.
  6. Pasting a part to another track (part). having copied the part (5 above) click on the first note or rest in the first bar of the new part and then paste.
  7. Selecting one voice in a part containing two or more voices. Make sure the selection filter is visible (on the view menu). Make sure all four voices are ticked, then select the part concerned (as per 5). Now remove voice part ticks apart from the voice you wish to copy. e.g. untick 2,3,4 to just select voice 1. Now copy and paste to a new track(part) (as per 6). Note if you untick all voices in the part then it will be totally deslected and you will have to start again with all the voices ticked.
  8. Finishing off when you have copied voice 2 or 3 in 7 above. In this case, when you paste the copied voice 2 or 3 to a new stave you will in fact also have a voice 1 part there. to sort this find the voices… command on the edit menu and swap voices 1 with the part you have copied. Then you want to leave the new voice 1 and delete voices 2,3,4 from the new part. with the new part selected keep voice 1 ticked, untick voices 2,3,4 and press delete (back arrow on the Mac).
  9. Tempo markings. These are best added graphically using the tempo templates on the Palettes, which are selected from the View Menu. To apply a tempo, always use a crotchet=nn setting, as this is what Sonic Pi will recognise. Don’t select quaver or minim settings. To apply a tempo select the note from which you wish the tempo to apply, and in the Tempo palette double click the entry crotchet = 80. Then go to the text in the score and edit the 80 to whatever value is desired.

As mentioned in the previous 2 articles, the .xml files for each part should be exported to the data folder for the script. If you name the parts p1, p2, p3 ….etc then once you have copied the filename for the first part into the script you should just have to edit the p1 at the end of the filename to p2, p3…etc to process subsequent parts also remembering to alter the pn variable in the next line to match 1,2,3…..

As each part is processed, it can be copied and pasted into a text editor file (I use TextWrangler on my Mac) In my adjusted script, because the various arrays are named a1,b1 a2,b2… they can be run “as is”, in which case all parts will play with the default synth (:beep)  At this stage I add whatever synths I want for each part using use_synth <name> I also add :amp and :pan settings for each part as required, remembering that if you have a lot of parts you may want to play them all at :amp settings less than 1. Sometimes I use the fx_level, :amp <value> do……end effect to group together a volume multiplier for several parts, I also put comment do….end blocks around groups of instruments so that I can selectively siwtch them off when adjusting the volume settings to get a good balance. You will find that the more you use the system the easier it becomes, and the end results I think are very gratifying.