# Vcv rack with sonic pi, midi clock question

**URL:** <https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248>\
**Category:** Support, Help & Resources\
**Created:** [March 11, 2021, 10:16am UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248 "2021-03-11T10:16:28Z")\
**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:** [March 11, 2021, 10:16am UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248/1 "2021-03-11T10:16:28Z")

</div>

Hi,

Just want to start slowly with vcv rack and sonic pi.  
I just want to get the tempo from sonic pi to send into a seq module ?  
If some of you can propose a little vcvrack patch to get this, you’re welcomed !

Edit : [spi/spi-vcvrack-clock.vcv at main · nlebellier/spi · GitHub](https://github.com/nlebellier/spi/blob/main/spi-vcvrack-clock.vcv)

How to get the midi clock from Sonic Pi ? An idea ?

Cheers

---

<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:** [March 11, 2021, 12:15pm UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248/2 "2021-03-11T12:15:27Z")

</div>

![image](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/0/091a9e8f560f4bfc30b69baff1eb88ef053f55d6.png)

```ruby
# How to get the midi clock to send to vcv rack ?
use_midi_defaults port: "loopmidi-01_1"

use_bpm 240
live_loop :clock do
  
  midi_clock_tick
  sleep 1
end

```

is it the right way to do that ?  
Cheers

---

<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:** [March 11, 2021, 12:23pm UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248/3 "2021-03-11T12:23:18Z")

</div>

Almost. Take a look at the docstring for `midi_clock_tick`:

> Sends a MIDI clock tick message to all connected devices on all channels. Use the port: and channel: opts to restrict which MIDI ports and channels are used.  
> Typical MIDI devices expect the clock to send 24 ticks per quarter note (typically a beat). See midi\_clock\_beat for a simple way of sending all the ticks for a given beat.

You’d therefore need to call `midi_clock_tick` 24 times per quarter note for it to work correctly as a MIDI clock generator. Alternatively you could use `midi_clock_beat` which does this for you:

```ruby
live_loop :foo do
  midi_clock_beat
  sleep 1
end

```

Hope that this helps!

---

<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:** [March 11, 2021, 12:44pm UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248/4 "2021-03-11T12:44:58Z")

</div>

thanks @samaaron

as i’m a newbie in vcv, i am prudent but it seems to work correctly with ``midi\_clock\_tick". But i’m gonna to read the doc

---

<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:** [March 11, 2021, 1:35pm UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248/5 "2021-03-11T13:35:49Z")

</div>

Yeah, it will work, but not likely at the BPM you’re expecting 🙂

---

<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:** [March 11, 2021, 3:49pm UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248/6 "2021-03-11T15:49:57Z")

</div>

There should be something to set in vcv rack if we want to use ` midi_clock_beat`

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

---

<div class="post-metadata">

**Author:** ![soxsa](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/soxsa/32/1669_2.png) [@soxsa](https://in-thread.sonic-pi.net/u/soxsa)\
**Post date:** [March 11, 2021, 6:22pm UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248/7 "2021-03-11T18:22:53Z")

</div>

It doesn’t work properly I’m afraid, if you try to drive a VCV Rack clock module from it, it jitters all over the place. I think it’s at the VCV Rack end rather than Sonic Pi, as midi clock works great with all the hardware devices I’ve tried.

I use rack with Spi a lot, just not the clock. Send it midi notes and CC, that works.

For the clock, just set it manually in rack to the song tempo. Sometimes I send a midi note to reset the clock, or just do it manually. Works a treat.

BTW I’ve seen a demo using the Arturia BeatStepPro where they get the same result putting midi clock into rack - tempo wanders about.

---

<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:** [March 11, 2021, 7:38pm UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248/8 "2021-03-11T19:38:15Z")

</div>

thanks for your feedbacks @soxsa !

> [@soxsa](#):
>
> I use rack with Spi a lot, just not the clock. Send it midi notes and CC, that works.

Some videos somewhere or not at all ?

So if i understand you i would rather forget the idea to control the bpm of vcv rack from sonic pi ?  
Well it’s a bit strange no ?

---

<div class="post-metadata">

**Author:** ![soxsa](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/soxsa/32/1669_2.png) [@soxsa](https://in-thread.sonic-pi.net/u/soxsa)\
**Post date:** [March 11, 2021, 9:11pm UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248/9 "2021-03-11T21:11:36Z")

</div>

If it worked I’d used it for sure. I like VCV Rack a lot, and it’s a key part of my setup. But now I’ve got SPi, it’s often easier to do the sequencing in Spi and send midi notes than use the sequencers in rack.

If you want to see how the tempo wanders about, use the clock in rack called ‘Clocked’ (which is a great module IMO) and put the midi clock from the MIDI-CV into that input.

I’m hoping they’ll fix this in the next big release of rack, but don’t know when that’ll be. I did contemplate writing a module to smooth out the jitter, but didn’t in the end.

---

<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:** [March 11, 2021, 9:40pm UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248/10 "2021-03-11T21:40:30Z")

</div>

ok thanks a lot for your precious advices 🙂 It will allow me not to loose time on this point. Very appreciated !  
Do you have some code somewhere to inspire me where spi is used with Rack ?

---

<div class="post-metadata">

**Author:** ![soxsa](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/soxsa/32/1669_2.png) [@soxsa](https://in-thread.sonic-pi.net/u/soxsa)\
**Post date:** [March 12, 2021, 10:47am UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248/11 "2021-03-12T10:47:37Z")

</div>

You’re welcome. I don’t have one specific thing - as I just tend to substitute a Sonic Pi ‘play’ with a ‘midi’ command. My VCV Rack patch for working with SPi is constantly evolving, but with the basic idea of having one voice per rack line, with it’s own MIDI-CV module set to channel 1,2,3…

I can send you that if you like?

If it’s any help, this is my midi script that I put in buffer 9 and run first time. It’s set up for my USB-MIDI hub but can work with anything. You’ll see I’ve got various handy midi functions there, including :midistart and :midiclock (NOT for VCV Rack!)

```ruby
#Midi4x4 Rpi V3 (Sonic PI 3.3)
#For Raspberry Pi
#midi4x4 ports like midi4x4_midi4x4_midi_1_28_0

#Midi4x4 port IDs
p=[]
n="28"
p[0]="midi4x4_midi4x4_midi_1_"+n+"_0"
p[1]="midi4x4_midi4x4_midi_2_"+n+"_1"
p[2]="midi4x4_midi4x4_midi_3_"+n+"_2"
p[3]="midi4x4_midi4x4_midi_4_"+n+"_3"

define :midi4x4 do |n,v,d,ch,pid|
  midi n,v,channel: ch,sustain: d,port: p[pid]
end

define :midi4x4cc do |n,v,ch,pid|
  midi_cc n,v,channel: ch,port: p[pid]
end

define :midistart do
  midi_reset port: p[0], channel: 1
  midi_start port: p[0], channel: 1
end

define :midiclock do |n|
  in_thread do
    n.times do
      midi_clock_beat 1, port: p[0], channel: 1
      sleep 1
    end
  end
end

live_loop :midiccin do
  use_real_time
  n,v=sync "/midi:mpk_mini_midi_1:1:1/control_change"
  set "cc_"+n.to_s,v
end

define :cc do |n,min,max,default|
  v=get["cc_"+n.to_s]
  if v==nil
    x=default
  else
    x=min+(v/128.0)*(max-min)
  end
  puts n.to_s + "," + x.to_s
  x
end

```

---

<div class="post-metadata">

**Author:** ![soxsa](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/soxsa/32/1669_2.png) [@soxsa](https://in-thread.sonic-pi.net/u/soxsa)\
**Post date:** [March 12, 2021, 10:57am UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248/12 "2021-03-12T10:57:40Z")

</div>

Here’s a birds eye view of the Rack patch, can’t see the detail here but the top line is the mixer/delay/output and the three other lines are the voices, on midi channels 1,2,3. With this basic idea you can swap out voices as you fancy, or just keep it as a generic synth.

I have tried other arrangements - as I say, having a Rack patch with it’s own clock and sync’ing either with a midi note sent e.g. every 4 bars. Syncing by hand works fine in practice - we’re musicians after all eh?

Worth knowing that, unlike SPi, the VCV Rack clock will tend to drift on it’s own because of OS glitches so etc. so you do need to sync every now and then.

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/7/74eab7dfe38972d0f2d1997f52b1da02655703c9.jpeg)

---

<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:** [March 12, 2021, 12:24pm UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248/13 "2021-03-12T12:24:18Z")

</div>

thanks a lot @soxsa

Oh for a vcv Rack newbie as me it’s a bit dizzying 🙂  
i will try to take time to understand module one by one as if i have to buy them in real life with their real costs 🙂

What i just want to do at the moment and maybe others newbies would be interested is to send notes and cc messages to vcv rack  
As you told me, do not try to synchronize Rack via spi, i would set the clock right into Rack with a clock module.  
I believe that for newbies it’s a good point to use vcv modules to share our learnings.

ps : i would appreciate to receive the Rack patch though

Cheers

---

<div class="post-metadata">

**Author:** ![soxsa](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/soxsa/32/1669_2.png) [@soxsa](https://in-thread.sonic-pi.net/u/soxsa)\
**Post date:** [March 12, 2021, 2:44pm UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248/14 "2021-03-12T14:44:30Z")

</div>

Dizzying yes! There are so many modules, litterally thousands of them. I think that people tend to build up their favourties for control (sequencers, clock, gates, logic etc.) and then use them with all the different osciallators that are available.

Some of the modules are basic building blocks, and some have huge functionality built into them - and take a while to get to grips with. So indeed it’s good to spend quite a lot of time on each one.

Once you get the principles of CV, driving them is all very similar. At some point I’ll put up a patch - you have to ‘subscribe’ to the module brands to get them on your computer. As I say, these ones are bare bones, with all the music done in SPi.

I worked out that just one of my patches would cost about £5,000 in hardware. And lots of modules are software versions of real modules. One of the reasons VCV Rack is so amazing.

---

<div class="post-metadata">

**Author:** ![soxsa](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/soxsa/32/1669_2.png) [@soxsa](https://in-thread.sonic-pi.net/u/soxsa)\
**Post date:** [March 13, 2021, 6:29am UTC](https://in-thread.sonic-pi.net/t/vcv-rack-with-sonic-pi-midi-clock-question/5248/15 "2021-03-13T06:29:43Z")

</div>

Here’s a patch 3-voice-MIDI… I can’t remember if rack prompts you for the modules it needs to download. If you open it and see lots of gaps compared to the screenshot above, that means you’re missing some modules. They’re all free ones.

> **[soxsa/patches](https://github.com/soxsa/patches)**
>
> Contribute to soxsa/patches development by creating an account on GitHub.

Some you’ll definitely need:  
Squinky Labs  
Audible Instruments  
Alright Devices  
Stoermelder  
Bogaudio  
AS
