Midi clock and co

Hi,

Have you some good ressources about midi clock in general to share ?

what is it possible in sonic pi ?

  • send midi clock to another midi device, sonic pi can change the tempo of the midi instrument
  • receive midi clock from a (master) main</github joke> device

It seems a important fied that it can be tough…
Cheers

Hi nlb,

I use this

live_loop :clock do
  midi_clock_beat
  midi_start if tick == 0
  sleep 1
end

It’s not possible to sync Sonic Pi to external clock for now
The clock is send to all available midi devices connected, you can’t specify one.
If you change the tempo of the midi clock, the receiving device will adjust it’s tempo.

Thanks for your answer @Bohrbug .
Just tl be sure : Even if we specify a midi port ?

You’re welcome. Yes, even when you specify a port. Doesn’t work for midi_beat_clock.

Hi @Bohrbug - are you sure about this?

I just traced the code all the way from the Ruby DSL to the C++ layer and it definitely looks like it should be honouring the port name for clock data for midi_clock_beat just like it does for all other Midi functions.

Could you verify that this isn’t working as you expect on v3.3.1?

Hi @samaaron,

A while ago I thought you mentioned that it was not possible to choose a port.
I see now in the docs, that it should now, I wasn’t aware of that.
But, when testing just now on v3.3.1, I couldn’t get that to work.
But I just found out why.

    use_bpm 120

notes = scale(:f3, :chromatic, num_octaves: 2)



live_loop :midiout do
  midi notes.choose, channel: 1, port: "iac_driver_iac_bus_1", sustain: 0.25
  sleep 0.5
end

    live_loop :cc_send do
      midi_cc 100, val_f: 0.8, channel: 5, port: "iac_driver_iac_bus_1"
      sleep 1
    end

    live_loop :clock do
      midi_clock_beat, port: "iac_driver_iac_bus_1"
      sleep 1
    end

Midi notes, and cc work like a charm with channel and port.
‘midi_clock_beat’ works.
But adding a port option to the midi_clock_beat gave this error :

workspace_zero:19: syntax error, unexpected label, expecting ‘=’

Now, I just found out, that when I specify the beats (that I never needed to, because without that option the midi-clock works just fine), it does work with the port !
Without it not.

So, this works:

live_loop :clock do
midi_clock_beat 0.5, port: “iac_driver_iac_bus_1”
sleep 1
end

this not:

live_loop :clock do
midi_clock_beat, port: “iac_driver_iac_bus_1”
sleep 1
end

This is unfortunately a quirk of Ruby’s syntax. If you jump straight into opts such as port: then you shouldn’t put a comma.

This will work:

live_loop :clock do
  midi_clock_beat port: “iac_driver_iac_bus_1”
  sleep 1
end
1 Like

aha, I see, ok, thanks!

Glad you intervened here.
Cause having the port option, saves a lot of midi bandwith.

2 Likes

hello there,

Up this topic as i just decide to dive into this feature.

Does sonic pi (version 3.3.1) can impose its tempo to an external soft ?

i’d like to set the tempo from sonicpi to Cantabile or to MPC Beats or to Ableton live

Any code is welcomed to reach this goal !!!

# logiciels nécessaires :

# sonic pi
# loopmidi
# Cantabile comme vst host
# vb-audio pour un retour de l'audio vers sonic pi afin d'enregistrer le retour audio des VSTs
# vsts :


midi_all_notes_off
use_bpm 120
use_midi_defaults port: "lp-01_3"

live_loop :clock do
  midi_clock_beat
  sleep 1
end

live_loop :vers_canal_01 do
  ##| stop
  ##| midi (scale :c4, :acem_asiran).tick,
  midi (ring :c3).tick,
    channel: 1, sustain: 0.5
  sleep [0.5].tick('s')
  
end



live_loop :vers_canal_04 do
  ##| stop
  midi (scale :c4, :bartok).pick, channel: 4, velocity: 65, sustain: 0.5
  sleep [2].tick('s')
  
end

live_loop :drumdrums do
  with_fx :reverb, mix: 0.6, room: 0.7 do
    2.times do
      sample :drum_bass_hard, lpf: 70
      sleep 2
      sample :drum_snare_hard, hpf: 75
      sleep 2
    end
    sample :drum_bass_hard, lpf: 70
    sleep 0.5
    sample :drum_bass_hard, lpf: 70
    sleep 1.5
    sample :drum_snare_hard, hpf: 75
    sleep 2
    
    sample :drum_bass_hard, lpf: 70
    sleep 2
    
    sample :drum_snare_hard, hpf: 75
    sleep 1
    sample :drum_snare_hard, hpf: 75
    sleep 1
  end
  
end

live_loop :hithats do
  sample :drum_snare_soft, hpf: 90, finish: 0.5,  amp: [0.5, 0.75, 1, 0.5].tick, amp: 0.5
  sleep 0.5
end


##| live_loop :audioFromCantabile do

##|   live_audio :back, input: 1
##|   sleep 8

##| end







stop





a = "D:/audio/mesSamples/drumbeats/acoustic_2_3.wav"
b = "D:/audio/mesSamples/drumbeats/breakbeats_2_1.wav"



s = (ring a, b)
a = s.to_a

s.length.times do
  current = s.tick
  sample current
  sleep sample_duration(current)
end


sample a[1]
sleep sample_duration(a[1])
sample a[0]

stop







# Splat version thanks to Ethan :-)
# A shorty solution
# send chord via osc

use_osc "localhost", 4560
use_osc_logging false
use_debug false

use_bpm 240

live_loop :sendChordsNotesViaOSC do
  use_real_time
  notes = chord :c, :madd11
  osc "/foo/notes", *notes
  
  # just send a amp integer value
  osc "/foo/notes/amp", [0.5, 1, 2, 4].tick
  sleep 1
end

Of course this does not work with Cantabile. The tempo stays to 96 bpm.

Cheers