Polyphony and midi controllers

Hello, apols if this has been covered, have searched but not found this topic :sweat_smile …
Is it possible to play out multiple midi channels, triggered by Sonic Pi?

I have Novation Circuit Tracks working with SP, would like to allocate different channels with different sounds. The code run is showing channel 1, though midi out is set to all and the code below has no channel 1.

Have been trying code like this (be warned, am a beginner!): Thanks for any help or suggestions you can give, not sure if this setup is possible.

Blockquote
use_midi_logging port: “circuit_tracks_3”

use_bpm 60

in_thread do
loop do
midi channel: 2
midi 75
sleep 0.25
midi 81
sleep 0.25
midi_all_notes_off
end
end

in_thread do
loop do
midi channel: 5
midi_note_on 44
sleep 0.3
midi_note_on 50
sleep 0.3
midi_all_notes_off
end
end

in_thread do
loop do
midi channel: 6
midi_note_on 62
sleep 0.3
midi_all_notes_off
end
end

loop do
midi channel: 5
midi 44
sleep 0.3
midi_note_on 39
sleep 0.3
midi_all_notes_off
end

Hi Jules
There are a few things that need changing in your code. I came up with the version below, and I’ll discuss some of the changes. First, when you paste code on in_thread it is a good idea to put three back ticks on the line before the code starts, and a further three on the line after the code ends. This formats it nicely and makes it easier to copy.

use_bpm 60
use_midi_logging true
use_midi_defaults port: "circuit_tracks_3" #set the destination port

# midi_all_notes_off channel: "*" ; stop

live_loop :m1 do
  use_merged_midi_defaults channel: 2
  midi 75,sustain: 0.5
  sleep 0.25
  midi 81,sustain: 0.25
  sleep 0.25
end

live_loop :m2 do
  use_merged_midi_defaults channel: 5
  midi 44,sustain: 0.6
  sleep 0.3
  midi 50,sustain: 0.3
  sleep 0.3
end

live_loop :m3 do
  use_merged_midi_defaults channel: 6
  midi 62,sustain: 0.3
  sleep 0.3
end

live_loop :m4 do #this live loop gives example of using midi_note_on
  use_merged_midi_defaults channel: 5
  midi_note_on 44
  sleep 0.3
  midi_note_on 39
  sleep 0.3
  midi_all_notes_off #uses currently specified channel
end

The first change you’ll notice is how to specify the midi port you want to send to (I assume it is “circuit_tracks_3” If your novation device is connected it should display the port name in the IO menu Midi Outputs section on Sonic PI.

Secondly, it is much neater not to use loop do inside an in_thread but instead to use a live_loop as shown. The main difference is that you have to give each live loop a unique name. Here I arbitrarily used :m1, :m2 :m3…

Third lets look at the actual midi command. By itself it will automatically send a midi_note_on and then 1 beat later a midi_note_off. If youi want the note to last for a different duration you can use midi 72,sustain: 0.3 for example which will last for 0.3 seconds at 60bpm
You can also specify the channel :and/or port: directly in each midi command if you wish, but it is easier to use the use_midi_defaults or in this case use_merged_midi_defaults command which means that you can specify the channel just once in each live loop rather than for every note. The merged bit allows it to use the port: setting which then is only typed once art the top of the program and merged into the separete channel settings.

You can (as you did) uae seperate midi_note_on commands as shown in live_loop :m4

Finally I would incorporate a paniic line
# midi_all_notes_off channel: "*" ; stop
at the start of the program. When you stop the preograms running it will be in the middle of live loops and some notes will still be sounding. You can then uncommnet this line and run again,a dn it will stop all the currently sounding notes. Note specifying the channel: “*” is important to make sure it kills the notes on ALL channels.
Alternatively, there may be a panic button on your novation to stop all notes.

Have fun, getting it going with your Novation Circuit Tracks

1 Like

Fabulous - thanks so much, Robin. I wouldn’t have got there without your help!

It worked well and I’ve played around with it. The Circuit pots can be used for FX, distort etc, can be heard here in action, first attempt :smiley:


Noted about pasting code - thanks.
V exciting!
Jules

1 Like

Glad you got it going. Sounds good on SoundCloud. Have fun developing it further.
Robin

1 Like