Sonic Pi 3 Player /Recorder version 1.2 using TouchOSC

Having played with the initial release, and following comments on the in-thread Sonic Pi site, I was spurred on to try and develop this further. I think I have now crammed about as much as can fit onto the main page of the TouchOSC screen, with an extra screen dealing with loading and saving files, but in the process the size of the screen has had to increase to a table template. Also, with the extra facilities added it is no longer practical to run the program on a Raspberry Pi, even with a relatively low latency sound card. I wanted to tune the application to give as good a response as possible, and in doing so it is possible to abuse it and cause problems if you go overboard with the rate of note inputs. Having said that it is amazing how fast you can add notes when accompanying in playback mode without things falling over.

I have also taken the opportunity to improve the safeguards when loading and saving files, or making recordings, so that in each case an arming button has to be set, which has a “lifetime” of 1.5 seconds before requiring to e reset again. I have also added helpful message feedback on the file handling  screen.

The new layout of the main screen is shown below with annotations describing the various elements.

 

You will see that the screen is now heavily populated with buttons and labels. If you expand the picture you will be able to read the explanations abut them. There follows a list of the features

  • An 8×8 note input matrix covering 4 octaves and 1 note. As described in version 1, each row as you move up from the bottom starts 4 notes higher than the row below. Thus in C major we have C,D,E for the first three notes of the bottom row, and the first note of row 7 is the following F.
  • The blue dots signify the tonic notes for the selected key. Son in C major or minor they all play a C, although there is some duplication of notes. Going up the diagonal from bottom left we cover 4 C with the final top right note giving a 5th C
  • At the bottom of the screen you can select one of 10 synths. These can be changed at any time as you record (affecting the recorded note), or during playback in which case they affect the accompaniment notes.
  • Above the synths, you can select the key signature, C,D,E…B major or minor. The Major button changes to minor when you press it and then toggles back again next push.
  • A metronome is provided, turned on by the purple Met On button. Three tempos are provided marked Slow, Medium and Fast. If you record in time with a metronome, (or at double its rate), you will be able to seamlessly repeat repeat the recording, on playback busing by setting PB  Repeats button to the desired value before playing. (You can repeat any recording, even free tempo ones, but the join may not be as nice).
  • two rest buttons, rest x 0.5 and rest x 2 accommodate recordings made synced to the metronome but with two notes per beat, or maybe requiring a longer rest between repeats. These can be set either before the recording, in which case they are incorporated in it, or on playback, or even on both for interesting effects.
  • To make a recording, you press the enable recording button, and then the Record button. This wipes out the current piece stored in memory (but if you have saved it, it can always be reloaded). Everything you then play, and changes in the key signature, volume or decay time are recorded on a note by note basis, so that they can be replayed later. Note it is NOT possible to alter the elements of a recording once you have made it, (eg changing the synth) apart from altering its tempo. To stop recording you press the record button again. For accurate timing, you should record with the metronome running at an appropriate rate. The recording starts from the first note keypress, and ends with the last note pressed before you stop recording. When you stop, the current rest time is added to the recording for use when repeating playback.
  • You can alter the volume, decay, key signature or synth at any time whilst recording. Changes apply from the next note pressed.
  • To Playback you press the Play Key. This is interlocked with the Record button so that neither can override the other. Playback will stop either when the piece finishes (assuming repeats are not selected), or when you press the play button again.
  • The playback tempo has three possible selections. S plays back at the recorded tempo. M at 1.5 times this tempo and F at twice this tempo.
  • Whilst playback is taking place, you can play further notes on the note input matrix. These cannot be recorded, by the program, but you can record the total resulting audio using the built in record facilities in Sonic Pi. So you might record a repeating riff, and then add some harmony or a tune on top during replay.
  • There are two yellow buttons marked helper leds on and playback leds on. The former allows you to display on the note matrix other note pads which sound the SAME note as the one you are pressing. This makes it easier to navigate the keyboard whille you are recording. It does not happen while playback takes place, although the actual key you pressed is illuminated then. However if you press further keys during playback it will work with these. However, it is fairly intensive on resources, and it may be better (and less confusing) to switch it off in fast pieces. The second button switches off the control of the sliders, the key indication and the notes playing during playback. This can make it a little less confusing if you are playing along to the playback, when they will indicate the current settings for the extra notes you are playing Otherwise they oscillate back and forth between the two settings, (the recorded note and the note you push). Again you reduce the pressure on resources by switching them off.
  • An experimental drums section is available. This works by having a drum loop which is synced to the start of playback, and thereafter, cued by the next note it sees when the drum loop ends. The speed of the drum loop is set by the metronome tempo settings. It is a bit hit and miss (no pun intended!) But if you experiment you can get some quite nice effects. You can change the metronome tempo while it is playing, and also switch it off and on again. It is best to switch it off before stopping playback or it will be armed again to do a burst (although it is not recorded) time you start a recording.
  • The final two keys marked Flat and Sharp can be held down to lower or raise a note key pressed while the flat or sharp key is held down, by one semitone. This can be of use since the full keyboard is not covered: only the notes in the scale selected.

The new layout fo the File Saving screen is shown below:

 

Again you may see more detail if you click to enlarge it.

IT has the following features:

  • It shows the location of the .json format files used to hold the saved recordings. This is specified at the beginning of the program, and can be adjusted to suit.
  • It accommodates 20 slots in which files can be saved, arranged in two banks of 10. The banks are selected using the Slot Bank selector switch, and a new feature is that I have added a tex prompt below the slot selecting 10 way switch indicating which bank is acrtive,
  • On the right of the slot select switch are two series of 10 coloured leds. The blue ones relate to slots 1-10 and the pink ones to slots 11-20. When these are lit, they indicate that a file exists which has recorded content in it. Darkened leds indicate that there is an empty file (or a missing file) at that position. Initially you may have no files. You should record an empty pice. (just start recording then stop without pushing any notes) then save the file to each of the 20 slot positions. The content leds will still remain dark at this stage.
  • On the left of the screen are two rows of leds which show the last accessed file, whether for lading or saving.the left hand row has orange leds (slots 1-10) the right hand row brown leds (slots 11-20)
  • A pair of green buttons control loading files to memory. You need to press the enable load button first, and then have 1.5 seconds to press the load button. This will then load the file specified by the slot select and bank select buttons. A green led lights to signify that the enable slot is active. Various messages are displayed in the label just below the Safe File button to show progress. If the file doesn’t exist an error sound plays.
  • A pair of red buttons perform a similar function for saving a file from memory.

Previously I had two buffers in Sonic Pi utilised each holding code relevant to the separate screens. During teh development it became apparent that two buffers were not going to be enough, so I decided to change to a single file, which necessitates using the run_file command to execute the file in Sonic Pi. The file is called recordplayercombined-RF.rb, and you execute it using a command like

run_file "path/to/the/file/recordplayer-RF.rb"

where path/to/the/file/ is the path of the file directory where the file is located. (I use -RF at the end of the file name to signify that run_file should be used to execute it. One advantage of doing this has been that I have been able to add a significant number of comments to the program which should enable you to follow how it is working. I do not intend to give a blow by blow account of this, but should say that unlike in the first version, I now save all the information for playing the notes in just two arrays, with a single entry for the rtime value as well. previously I used separate arrays for each parameter, which led to quite unwieldy playback logic. The format for a short recording looks like this:

{
  "Vtimn": [
    1.477972,
    2.012986
  ],
  "Vrecn": [
    [
      "4",
      "2",
      "1",
      0.0,
      "1",
      0.1,
      0.5,
      0
    ],
    [
      "4",
      "2",
      "1",
      0.0,
      "1",
      0.1,
      0.5,
      0
    ]
  ],
  "Vrtime": 0.5
}

This shows the two arrays Vtimn and Vrecn and the Vrtime value stored. The file plays two notes both coordinates column 4 row 2, with synth 1 (= piano),majmin 0 (major),key 1 (C),Decay 0.1, Volume 0.5,mod 0 (sharp 1 or flat -11 or none 0 ) When recorded the first note was played 1.477972 beats after the value of st was set, and the second 2.012986 beats after the value of st was set. So on playback the first note is played at 0, and the second at 2.012986 – 1.477972 = 0.53 beats later. At the end the repeat delay is 0.5 beats. This is a not very accurate recording of two notes per metronome beat. They should be 0.5 beats apart.the Vrtime value was 0.5 because the “rest x 0.5” switch was pushed before the recording. If it hadn’t been the Vrtime value would have been 1.0 or 1 beat.

This has been a great but very demanding project to do. In terms of Sonic Pi it is not very sophisticated, only making use of a with_fx :reverb wrapped around a play command playing a selected note from a scale with multiple octaves What makes it exciting is the control that the TouchOSC interface gives on selecting the scale, the key, the synth the tempo, the volume and decay settings, and the ability to record and replay in real time according to the notes input using the note input matrix. The facility to play along a second part and to add an experimental synchronised percussion makes it a really fun setup to play with. I hope you enjoy using it as much as I do.

You can download the program and TouchOSC template here

A VIDEO HAS BEEN ADDED OF THE PROJECT IN USE view it here

 

 

 

Advertisements