Pentatonic Improv

Just a little nice sounding thing where I combined a couple of the things I made so far. Plays some more or less random melodie on the pluck synth.

#---settings---

use_random_seed = 12345

root = 57

minor = true

#experimental
use_rythm = false


#---functions---

define :parabola do |p, q, k, x|
  parabola = -((4*k)/(1.0*((p-q)**2)))*(x-p)*(x-q)
end


define :gr_generate_rythm do
  
  gr_rythm = (ring 0)
  
  gr_base_rythm = (bools 0, 1, 1, 1).pick(16)
  
  gr_best = 0
  
  gr_offset = 0
  
  tick_set:gr_pattern, -1
  16.times do
    
    tick(:gr_pattern)
    
    gr_score = 0
    
    tick_set:gr_position, -1
    16.times do
      
      tick(:gr_position)
      
      if gr_base_rythm.look(:gr_position, offset: look(:gr_pattern))
        gr_score = gr_score + (ring 3, 0, 1, 0, 2, 0, 1, 0).look(:gr_position)
      end
      
    end
    
    if  gr_score > gr_best
      gr_best = gr_score
      gr_offset = look(:gr_pattern)
    end
    
  end
  
  tick_set:gr_shift, -1
  gr_rythm = (ring)
  16.times do
    gr_rythm = gr_rythm + (ring gr_base_rythm.tick(:gr_shift, offset: gr_offset))
  end
  
  gr_generate_rythm = gr_rythm
  
end


#---setup---

if minor
  our_scale = (scale root, :minor_pentatonic)
else
  our_scale = (scale root, :major_pentatonic)
end

start_phrase = true

p_range = 1

p_start_at = 0

rythm = (ring true)


#---main loop---

live_loop :improv do
  
  use_synth :pluck
  
  tick
  
  if (range 0, 32).look == 0
    
    play (chord_invert, our_scale, -12)[0], coef: 0.6
    start_phrase = true
    
  elsif (range 0, 32).look == 16
    
    play (chord_invert, our_scale, -11)[0], coef: 0.6
    start_phrase = true
    
  else
    
    #puts p_range
    
    cur_note = p_start_at + parabola(0, 16, p_range, (range 0, 16).look) + rdist(3 ,0)
    
    
    play (chord_invert, our_scale, cur_note)[0],
      amp: (1-0.5+parabola(0, 14, 0.5, (range 0, 16).look)) * (1-(1-(ring 1, 0.125, 0.25, 0.125, 0.5, 0.125, 0.25, 0.125)[(range 0, 16).look])*0.5),
      on: rythm.look
    
  end
  
  if start_phrase
    
    start_phrase = false
    
    p_start_at = rand_i(6)
    
    p_range = rrand(2, 5)
    
    if one_in 2
      
      p_range = p_range * -1
      
    end
    
    if use_rythm
      rythm = gr_generate_rythm
    end
    
    
  end
  
  sleep 0.25
  
end

3 Likes

Fixed the rythm option

#---settings---

use_random_seed = 12345

root = 57

minor = true

use_rythm = true


#---functions---

define :parabola do |p, q, k, x|
  parabola = -((4*k)/(1.0*((p-q)**2)))*(x-p)*(x-q)
end


define :gr_generate_rythm do
  
  gr_rythm = (ring 0)
  
  gr_base_rythm = (bools 0, 1, 1, 1).pick(8)
  
  gr_best = 0
  
  gr_offset = 0
  
  tick_reset :gr_pattern
  8.times do
    
    tick(:gr_pattern)
    
    gr_score = 0
    
    tick_reset :gr_position
    8.times do
      
      tick(:gr_position)
      
      if gr_base_rythm.look(:gr_position, offset: look(:gr_pattern))
        gr_score = gr_score + (ring 4, 0, 1, 0, 2, 0, 1, 0).look(:gr_position)
      end
      
    end
    
    if  gr_score > gr_best
      gr_best = gr_score
      gr_offset = look(:gr_pattern)
    end
    
  end
  
  tick_reset :gr_shift
  gr_rythm = (ring)
  8.times do
    gr_rythm = gr_rythm + (ring gr_base_rythm.tick(:gr_shift, offset: gr_offset))
  end
  
  gr_generate_rythm = gr_rythm
  
end


#---setup---

if minor
  our_scale = (scale root, :minor_pentatonic)
else
  our_scale = (scale root, :major_pentatonic)
end

start_phrase = true

p_range = 1

p_start_at = 0

rythm = (ring true)


#---main loop---

live_loop :improv do
  
  use_synth :pluck
  
  tick
  
  if (range 0, 32).look == 0
    
    play (chord_invert, our_scale, -12)[0], coef: 0.6
    start_phrase = true
    
  elsif (range 0, 32).look == 16
    
    play (chord_invert, our_scale, -11)[0], coef: 0.6
    start_phrase = true
    
  else
    
    #puts p_range
    
    cur_note = p_start_at + parabola(0, 16, p_range, (range 0, 16).look) + rdist(3 ,0)
    
    
    play (chord_invert, our_scale, cur_note)[0],
      amp: (1-0.5+parabola(0, 14, 0.5, (range 0, 16).look)) * (1-(1-(ring 1, 0.125, 0.25, 0.125, 0.5, 0.125, 0.25, 0.125)[(range 0, 16).look])*0.5),
      on: rythm.look
    
  end
  
  if start_phrase
    
    start_phrase = false
    
    p_start_at = rand_i(6)
    
    p_range = rrand(2, 5)
    
    if one_in 2
      
      p_range = p_range * -1
      
    end
    
    if use_rythm
      rythm = gr_generate_rythm
    end
    
    
  end
  
  sleep 0.25
  
end