# How Can I Fix This Sequencer?

Italic words

Hi there:

Once again, i was looking at sequencers.
On my own topic about “Drum Machine”,
i received several replies…
However,most of then aren’t so intuitive.
So, i was wondering what is need to fix this

code:

´´´

DRUM SEQUENCER

use_debug false
with_fx :sound_out_stereo, mix: 1 do
with_fx :gverb,mix: 0.1,damp: 0.8 do

# Drum Samples

dsp = [
  
  :bd_ada,
  :drum_snare_hard,
  :drum_cymbal_closed,
  
]

# Drum Patterns

# Pattern 1

ptt1 = [
  
  "x--x----x--x--x-",
  "----x-------x---",
  "---------------x",
  
]

# Pattern 2

ptt2 = [
  
  "x--x----x--x--x-",
  "----x-------x---",
  "---------------x",
  
]



use_sample_defaults amp: 0.5,pan: 0,rate: 1,
  beat_stretch: 1, attack: 0,release: 1


use_bpm 86

loop do
  16.times do |i|
    if [i] <= 16 then
      play dsp,ptt1.tick
    end
    sleep 0.25
  end
end
16.times do |i|
  if [i] >= 17  then
    play dsp,ptt2.tick
  end
  sleep 0.25
end
´´´

It seemed the simplest way to create a sequencer.

Thank you for your attention.

I think the code below achieves what you are aiming at.
I use tick to cycle through the values in each ptt entry. It doesn’t matter that it increase beyond 16 as it cycles round and starts with the elements in order again.
I’ve added an optional metronome to indicate 4 beats to check the samples sound when expected.
Your ptt1 and ptt2 arrays are identical at present so each sequence will sound the same.
If you try changing ptt2 you will get different rhythms for the second 16 pulses.
Finally I’m not sure if you really need most of the sample_defaults in this application. Try without.

# Drum Samples
use_debug false
dsp = [
  
  :bd_ada,
  :drum_snare_hard,
  :drum_cymbal_closed,
  
]

# Drum Patterns

# Pattern 1

ptt1 = [ "x--x----x--x--x-","----x-------x---","---------------x"]
ptt2 = [ "x--x----x--x--x-","----x-------x---","---------------x"]

use_sample_defaults amp: 0.5,pan: 0,rate: 1,beat_stretch: 1,
attack: 0,release: 1

use_bpm 86
live_loop :metro do #added metronome to check samples occuring when you expect
  tick
  if look%4==0
    play 84,release: 0.1
  else
    play 72,release: 0.1
  end
  
  sleep 1
end

live_loop :drums do
  16.times do
    tick
    sample dsp[0] if ptt1[0].look=="x"
    sample dsp[1] if ptt1[1].look=="x"
    sample dsp[2] if ptt1[2].look=="x"
    sleep 0.25
  end
  16.times do
    tick
    sample dsp[0] if ptt2[0].look=="x"
    sample dsp[1] if ptt2[1].look=="x"
    sample dsp[2] if ptt2[2].look=="x"
    sleep 0.25
  end
end
1 Like

Hi Robin :

This works perfectly, and it’s the most
simple sequencer around. Thank you
very much !

*To those that are interested on Sonic Pi,
i also recommend this course by Steve Lydford;
at UDEMY :

hi @GWB70

i propose that way

bd_01 = (ring 1,0,0,0, 0,0,0,0, 1,0,0,1, 0,0,1,0) + (ring 1,0,0,0, 0,0,0,0, 1,0,1,1, 0,0,2,0)
sn_01 = (ring 0,0,0,0, 1,0,0,0, 0,0,0,0, 1,0,0,0)
hh_01 = (ring 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1)

live_loop :drums_01 do
  16.times do
    sample :bd_808, amp: bd_01.tick('bd')
    sample :sn_generic, amp: sn_01.tick('sn')
    sample :drum_cymbal_closed, amp: hh_01.tick('hh')
    sleep 0.25
  end
end
  • you can easily read the all pattern in just a sight.
  • you can play on the intensity of each step (0 to 4,5 6 as you want but take care not to saturate)
  • you can change easily the sample using the auto completion from the editor rather using an array in which you don’t have the sonic pi instruments suggested.

image

Then we can go further and introduce a method not to repeat ourselves


# pattern 01
bd_01 = (ring 1,0,0,0, 0,0,0,0, 1,0,0,1, 0,0,1,0) + (ring 1,0,0,0, 0,0,0,0, 1,0,1,1, 0,0,2,0)
sn_01 = (ring 0,0,0,0, 1,0,0,0, 0,0,0,0, 1,0,0,0)
hh_01 = (ring 0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,0)

# pattern 02
bd_02 = (ring 1,0,0,0, 0,0,1,0, 0,0,1,0, 0,0,1,0)
sn_02 = (ring 0,0,0,0, 1,0,0,0, 0,0,0,0, 1.5,1,1,1)
hh_02 = (ring 0,2,1,0, 0,0,1,0) * 2

define :seq do |bd_ring, sn_ring, hh_ring|
  16.times do
    sample :bd_fat, amp: bd_ring.tick('bd'), cutoff: 50
    sample :drum_snare_hard, amp: sn_ring.tick('sn')
    sample :drum_cymbal_closed, amp: hh_ring.tick('hh'), cutoff: 110
    sleep 0.25
    
  end
end

at [0, 4, 8, 16, 20, 24 ] do
  seq bd_01, sn_01, hh_01
end

at [12, 16+12] do
  seq bd_02, sn_02, hh_02
end

you can keep on using the live_loop


# pattern 01
bd_01 = (ring 1,0,0,0, 0,0,0,0, 1,0,0,1, 0,0,1,0) + (ring 1,0,0,0, 0,0,0,0, 1,0,1,1, 0,0,2,0)
sn_01 = (ring 0,0,0,0, 1,0,0,0, 0,0,0,0, 1,0,0,0)
hh_01 = (ring 0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,0)

# pattern 02
bd_02 = (ring 1,0,0,0, 0,0,1,0, 0,0,1,0, 0,0,1,0)
sn_02 = (ring 0,0,0,0, 1,0,0,0, 0,0,0,0, 1.5,1,1,1)
hh_02 = (ring 0,2,1,0, 0,0,1,0) * 2

define :seq do |bd_ring, sn_ring, hh_ring|
  16.times do
    sample :bd_fat, amp: bd_ring.tick('bd'), cutoff: 50
    sample :drum_snare_hard, amp: sn_ring.tick('sn')
    sample :drum_cymbal_closed, amp: hh_ring.tick('hh'), cutoff: 110
    sleep 0.25
    
  end
end


live_loop :drums do
  3.times do
    seq bd_01, sn_01, hh_01    
  end
  seq bd_02, sn_02, hh_02  
end

And change the sample used into the seq method.

Hope it helps
Good coding !

1 Like

We can always take something from
here 'n there… Yes, it helps, and makes me
aware about take lessons on programming.
I’ll start learn the fundamentals soon.
Have a nice day !

And now with a bass :slight_smile:

use_sample_defaults amp: 0.5, pan: 0,rate: 1, attack: 0,release: 2

use_bpm 96

# pattern 01
bd_01 = (ring 1,0,0,0, 0,0,0,0, 1,0,0,1, 0,0,1,0) + (ring 1,0,0,0, 0,0,0,0, 1,0,1,1, 1,0,1,0)
sn_01 = (ring 0,0,0,0, 1,0,0,0, 0,0,0,0, 1,0,0,0)
hh_01 = (ring 0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,0)

bass_notes_01 = (ring :c2, :c3, :d2, :d3) * 3 + (ring :f3, :f4, :d2, :d3)
bass_volume_01 = (ring 1, 0.5, 2, 0.5)



# pattern 02
bd_02 = (ring 1,0,0,0, 0,0,1,0, 0, 0,1,0, 0,1,0,0)
sn_02 = (ring 0,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0.8,0.9)
##| sn_02 = (ring 0,0,0,0, 0,0,1,0, 1,0,0,0, 1,0,0.8,0.9)

hh_02 = (ring 1,2,0,1, 0,0,0,0) * 2


define :seq do |bd_ring, sn_ring, hh_ring, bass_notes, bass_vol|
  with_fx :reverb, room: 0.7 do
    16.times do
      
      sample :drum_bass_hard, amp: bd_ring.tick('bd'), cutoff: 90, compress: 1
      sample :drum_snare_hard, amp: sn_ring.tick('sn'), finish: 0.25, compress: 1
      sample :drum_cymbal_hard, amp: hh_ring.tick('hh')*0.5, hpf: 110, start: [0.1, 0.2].tick('dfdf')
      synth :tb303, note: bass_notes.tick('n'), amp: bass_vol.tick('vol')*0.2, release: 0.1,
        cutoff: rrand_i(85,105),
        decay: rrand_i(0.1, 0.5)
      sleep 0.25
    end
  end
end


live_loop :drums do
  
  3.times do
    seq bd_01, sn_01, hh_01, bass_notes_01, bass_volume_01
  end
  seq bd_02, sn_02, hh_02, bass_notes_01, bass_volume_01
end

live_loop :drone do
  with_fx :echo, phase: 0.75, mix: 0.5, pre_mix: 0.8 do
    sample :ambi_drone, sustain: 4, rate: 3, attack: 0.1
    sleep 8
  end
end


##| at [0, 4, 8, 16, 20, 24] do
##|   seq bd_01, sn_01, hh_01,bass_notes_01, bass_volume_01
##| end

##| at [12, 16+12] do
##|   seq bd_02, sn_02, hh_02, bass_notes_01, bass_volume_01
##| end

Let’s run this code and play on it !

1 Like