# Midi clock and co

**URL:** <https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359>\
**Category:** Support, Help & Resources\
**Created:** [April 3, 2021, 11:02am UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359 "2021-04-03T11:02:41Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [April 3, 2021, 11:02am UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359/1 "2021-04-03T11:02:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Bohrbug](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/bohrbug/32/73_2.png) [@Bohrbug](https://in-thread.sonic-pi.net/u/Bohrbug)\
**Post date:** [April 5, 2021, 4:01pm UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359/2 "2021-04-05T16:01:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [April 5, 2021, 5:06pm UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359/3 "2021-04-05T17:06:06Z")

</div>

> [@Bohrbug](#):
>
> The clock is send to all available midi devices connected, you can’t specify one.

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

---

<div class="post-metadata">

**Author:** ![Bohrbug](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/bohrbug/32/73_2.png) [@Bohrbug](https://in-thread.sonic-pi.net/u/Bohrbug)\
**Post date:** [April 5, 2021, 5:07pm UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359/4 "2021-04-05T17:07:51Z")

</div>

You’re welcome. Yes, even when you specify a port. Doesn’t work for midi\_beat\_clock.

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [April 15, 2021, 7:43pm UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359/5 "2021-04-15T19:43:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Bohrbug](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/bohrbug/32/73_2.png) [@Bohrbug](https://in-thread.sonic-pi.net/u/Bohrbug)\
**Post date:** [April 15, 2021, 8:51pm UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359/6 "2021-04-15T20:51:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [April 15, 2021, 8:58pm UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359/7 "2021-04-15T20:58:51Z")

</div>

> [@Bohrbug](#):
>
> 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:

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

```

---

<div class="post-metadata">

**Author:** ![Bohrbug](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/bohrbug/32/73_2.png) [@Bohrbug](https://in-thread.sonic-pi.net/u/Bohrbug)\
**Post date:** [April 15, 2021, 9:03pm UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359/8 "2021-04-15T21:03:37Z")

</div>

aha, I see, ok, thanks!

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

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [June 10, 2022, 3:15pm UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359/9 "2022-06-10T15:15:15Z")

</div>

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 !!!

```ruby
# 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.

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/5/557c7ed02d62c0c80ac515d5bbf2fdd8570ab9e3.png)

Cheers

---

<div class="post-metadata">

**Author:** ![rebelcello](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/rebelcello/32/2602_2.png) [@rebelcello](https://in-thread.sonic-pi.net/u/rebelcello)\
**Post date:** [July 29, 2025, 9:40pm UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359/10 "2025-07-29T21:40:56Z")

</div>

Analogue clocking!😆

Been trying to clock Sonic Pi + live looping together for aeons, no joy, much hair lost, many rabbit holes visited.

Finally realised they were like human musicians and just need to start at roughly the same time, and try to avoid wandering off. Here’s what I’ve ended up with, works a treat:

On looper, record a 120 bpm reference track (empty if you like).  
Start Sonic Pi beat at 120 bpm.  
Hit your looper as close as humanly possible on the beat.

Put a slight delay-nudge in Sonic Pi loop if you need it. My looper likes this for some reason:

> live\_loop :gb, delay: 0.1 do  
> sample :bd\_haus, amp: 1  
> sleep 1  
> end

If you fail, stop and start again.

Just putting it out here, in case anyone else has similarly struggled. No mocking please 😃 and also would love to hear how on earth bands managed in the 80s!

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [July 29, 2025, 10:21pm UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359/11 "2025-07-29T22:21:34Z")

</div>

You can also use the global time warp in the bottom right to nudge everything forward or back a bit to match the phase of an external beat.

---

<div class="post-metadata">

**Author:** ![rebelcello](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/rebelcello/32/2602_2.png) [@rebelcello](https://in-thread.sonic-pi.net/u/rebelcello)\
**Post date:** [July 30, 2025, 7:58pm UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359/12 "2025-07-30T19:58:37Z")

</div>

Thanks Sam! I didn’t know what that was for, haven’t found it in the manual. Only just got Ableton.

Can we please have a beginner section on this forum? Everyone is super-advanced at maths, coding and tech already, so much so that I feel stupid for asking and stumbling around, even though I’ve tried hard and Sonic Pi is presented towards beginners 🙂 Would this be possible?

Eg for tips like: Ruby’s colons are hard to remember, so I made a mnemonic:

:this = !NameSignal

```ruby
:this 

```

is like a front Capital Letter or Exclaim, whereas

```ruby
this: 

```

looks like a wee key :- to unlock what comes next - a value

I’m hesitant to post beginner stuff, but this helped to finally get my eye in, and understand colon use.

It would be good to have a place to gather beginner tips. Looking forward to more courses!

---

<div class="post-metadata">

**Author:** ![rebelcello](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/rebelcello/32/2602_2.png) [@rebelcello](https://in-thread.sonic-pi.net/u/rebelcello)\
**Post date:** [July 30, 2025, 9:24pm UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359/13 "2025-07-30T21:24:35Z")

</div>

Hurray! Thanks so much Sam for pointing this out, has enabled RC-600 linkup breakthrough.

So what now works 🤞 No need for midiclock in-out etc code.

- Sonic Pi and Ableton linked via Live link.
- Ableton - add a midi clip and play. (found this info on [Ben Rowland’s site](https://www.youtube.com/watch?v=j_jmOYaHVPY&t=160s), [04:20], didn’t need the 2nd bit, setting up clicks - it worked without it.
- Ableton - set output port to the looper and click ‘sync’.

Now can change the tempo either from Sonic Pi or Ableton, and the looper follows!! 🥳 🎉 🙏 Just using a USB cable from the looper, not DIN.  
So can play live looper with SonicPi now.

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [July 31, 2025, 11:28am UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359/14 "2025-07-31T11:28:16Z")

</div>

I’m really sorry that this forum feels so advanced - all I can say is that I really don’t think it is, although I can understand that it might feel this way.

All questions are welcome - there’s no stupid questions and everyone is really happy to help out.

---

<div class="post-metadata">

**Author:** ![rebelcello](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/rebelcello/32/2602_2.png) [@rebelcello](https://in-thread.sonic-pi.net/u/rebelcello)\
**Post date:** [August 3, 2025, 7:50pm UTC](https://in-thread.sonic-pi.net/t/midi-clock-and-co/5359/15 "2025-08-03T19:50:36Z")

</div>

Thanks Sam. I guess it’s not that advanced for people familiar with coding and midi 🙂 v satisfying though when you work something out and it’s a leap forward 😃
