How to send midi chords through vsti, via Sonic Pi?

Hi there :

Sonic Pi has lots of possibilities to play sequences of notes,

chords,and chords progressions, but…

I was experimenting pass midi notes to Reason and,

with one note,worked fine.

When i tried to pass a list;nothing happened :

# Midi in/Out (midi through DAW)

# Set Bpm (Tempo)

use_bpm 120
use_debug false

# Sends midi clock at current bpm

live_loop:clock do
  midi_clock_beat
  sleep 1
end

# Midi Out

live_loop :midich do
  (midi_notes :d3, :d4, :d5).tick
  use_midi_defaults channel: 2,port: "pure_data_in"
end

# Send midi control messages

midi_cc 42,65, channel: 2 # cc = 65 to Malstrom

There’s some other way to pass notes,and chords to

external devices,instead note per note ?

Once again,thank you for your attention.

Well… in fact,this issue was posted before.

So,the best way i find to solved it for now is:

# Midi in/Out (midi through DAW)

# Set Bpm (Tempo)

use_bpm 120
use_debug false

# Sends midi clock at current bpm

live_loop:clock do
  midi_clock_beat
  sleep 1
end

# Midi Chord

define :midi_chord do |notes, *args|
  notes.each do |note|
    midi note, *args
  end
end
live_loop :midich do
  midi_chord chord(:c4,:major),channel: 2,
    port:"pure_data_in", sustain: 2
  sleep 4
end

I’d not be able to define a function like this,so i took from

here : https://github.com/samaaron/sonic-pi/issues/1691

However, if someone find another way,please, let me know.

1 Like

You are correct, using the .each method for a block is the way to go.

…OMG we have *args??? I feel derpy for not realizing that, thank you.

1 Like

In fact, i see no advantage,since this method only

play one chord;no rings or progressions.

So, i stick with the old one;here’s an improvement:

# Notes Through vst

# Note Durations

w = 4
h = 2
q = 1
e = 0.5
s = 0.25

# Set Bpm (Tempo)

use_bpm 120
use_debug false

# Sends midi clock at current bpm

live_loop:clock do
  midi_clock_beat
  sleep 1
end

# Midi Out

live_loop :Ch1 do
  midi [:C3,:Eb3].ring.tick(:note),
    channel: 1,port:"pure_data_in",
    attack: 0.01, sustain: 0.3, release: 0.1
  sleep (ring q,e,s,h).tick(:dur)
end

Naming Ticks are equivalent to play_pattern_timed (in this case)

See chapter 9.4

Am using this to pass information through Minihost Modular Beta

from where i load my vsts;better than nothing.

Here’s the link for Minihost :

https://forum.image-line.com/viewtopic.php?f=1919&t=123031

Best regards.

1 Like

You’ve done it again. I did not realize that I could use sustain: with midi. I’ve been doing all my note on/off the hard way, tracking the last played value. However, are you able to make use of attack: and release: ? Is that sending standard CCs for those?

1 Like

@kniknoo, the midi function isn’t a direct representation of anything in the standard MIDI specification. Instead, it’s two calls: first a call to midi_note_on followed by a pause and then a call to midi_note_off. The midi function handles this implicit concurrency and strict timing for you :slight_smile:

So the following can be seen to be equivalent:

midi :e1, release: 0.2
at do
  midi_note_on :e1 
  sleep 0.2
  midi_note_off :e1
end

Hi Sam :

Much better now !
I’ll experiment to write a sequence of them into a function:

define :pattern do
  midi :e1, release: 0.2
  midi :g1, release: 0.2
  midi :e1, release: 0.5
end

and call it into a thread.

Just one more question :

How can i trigger a bunch of notes at same time, a chord progression ?

There’s some way ?

Thank you for your attention.

Apologies, but I’m not 100% sure what you mean here. Triggering a bunch of notes at the same time is done by writing each note trigger code on a separate line with no interleaving calls to sleep or sync. A chord progression implies that you’re spreading out the note triggers over time which would require either a sleep or sync to advance time:

(chord :e3, :minor).each do |n|
  midi n, release: 0.1
end

sleep 1

(chord :a2, :major).each do |n|
  midi n, release: 0.1
end

sleep 1

(chord :f2, :major).each do |n|
  midi n, release: 0.1
end

Hi,

there was a discussion on Github about that some time ago. The result was the following function (which is exactly what @samaaron says made convenient as a function). You could keep that at the top of your buffer (I keep it in the init file of Sonic Pi at ~/.sonic-pi/init.rb):

# https://github.com/samaaron/sonic-pi/issues/1691
# Use: midi_chord chord(:c4,:major), sustain:0.2
define :midi_chord do |notes, *args|
  notes.each do |note|
    midi note, *args
  end
end
2 Likes

Hi Sam :

In fact i blended the two questions together,
and fortunately you answered both.
Be sure that you solved one of main issues for
Sonic Pi users.
Thank you very much, once again.

Hi Martin :

I saw this issue but was not being able to use this.

Was trying to use it to trigger chords,and not seemed a great deal.

Will try to use as you told me,and see what can be achieved.

Thank you for sharing your knowledge with us !

P.S : Am using your drum machine since then,and loving…

Simple and clear,yet versatile.

Hi there :

Here is the answer to what you asked me,
with an improvement of our friends :

Passing Notes Through vst


define :midi_chord do |notes, *args|
  notes.each do |note|
    midi note, *args
  end
end

# Note Durations

w = 4
h = 2
q = 1
e = 0.5
s = 0.25

# Set Bpm (Tempo)

use_bpm 120
use_debug false

# Sends midi clock at current bpm

live_loop:clock do
  midi_clock_beat
  sleep s
end

live_loop :midich1 do
  use_midi_defaults channel: 1,release: 0.2,port:"pure_data_in"
  midi :e3
  sleep q
  midi :g3
  sleep q
  midi :b3
  sleep q
end

Send midi control messages

midi_cc n channel: x # n = see MIDI Implementation Chart
# of your DAW or vst(documrntation folder of your app).

For future reference, I’ve just added some information on how to format your posts using Markdown to the pinned community post. You might be interested in reading the section on formatting code blocks :slight_smile:

Thanks Sam:

It’s a useful information,that i have to know.:slightly_smiling_face:

You’re welcome!

Here’s a challenge, see if you can edit your recent post to add syntax highlighting to your code block :slight_smile: