Qsynth: one instrument starts to sounds like many of that instrument [SOLVED]

Hello!

I hope you all are well! I’ve being playing and studying with Sonic Pi for a year approx. and I have enjoyed this a lot! I’m not a musician and all what I’ve learnt so far has been thanks to Sonic Pi.

Recently, I discovered Qsynth and I would like explore the midi world, ports, etc. I think I succeeded connecting the Qsynth with Sonic Pi and I have been able to play some isolated melodies with the different instruments in Qsynth. However, when I tried to use a loop with a melody, all works good just for some time but after a while, is like many instruments started to sound at the same time.
I’ve been done all what I could do but the problem persists. My code is below and the result of the sound I got for the trumpet is like this (a link to my dropbox).

I would appreciate if some of you could give me some ideas to solve the problem.

use_bpm 124 

r=4
b=2
n=1
np=1.5
c=0.5
cp=0.75

midi_all_notes_off

live_audio :qsynth,stereo: true

# stolen and modified from: http://ecotronics.ch.honorius.sui-inter.net/wordpress/2017/sonic-pi-advanced-programming/
define :play_my_melody3 do |my_note_list, my_sleep_list, sustains, canal|
  my_length = my_note_list.length
  my_length.times do
    my_counter = tick(:my_melody_tick)
    midi my_note_list.ring[my_counter], channel: canal, sustain: sustains[my_counter], velocity: 50
    sleep my_sleep_list.ring[my_counter]
  end
end

define :lead3 do
  play_my_melody3( [:af, :a, :af, :g,:af, :a, :af, :g,
                    :af, :a, :af, :f,:af, :a, :af, :f,
                    :a, :g, :a, :f,:a, :g, :a, :f,
                    :a, :g, :a, :f,:a, :g, :a, :f
                    ],
                   [c,c,c,c,c,c,c,c,
                    c,c,c,c,c,c,c,c,
                    c,c,c,c,c,c,c,c,
                    c,c,c,c,c,c,c,c
                    ],
                   [0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,
                    0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,
                    0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,
                    0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1
                    ], 1)
end

midi_pc 56, channel: 1

in_thread do
  loop do
    lead3
  end
end

# midi_all_notes_off

Are you turning off each note after playing it ?
Some synths do not respond to ’ all notes off ’
Some voices will continue to ’ ring ’ , building up
to a mixture .

1 Like

Oh, thanks a lot!

Following your suggestion, I changed the function to

define :play_my_melody4 do |my_note_list, my_sleep_list, sustains, canal|
  my_length = my_note_list.length
  my_length.times do
    my_counter = tick(:my_melody_tick)
    midi_note_on my_note_list.ring[my_counter], channel: canal, sustain: sustains[my_counter], velocity: 50
    sleep my_sleep_list.ring[my_counter]
    midi_note_off my_note_list.ring[my_counter], channel: canal
  end
end

and all works as I expected!!

1 Like