C major 7 chords suit (Jazz)


#1

My first but long try ^^

Inspiration :

Comments in French

##########################################################################
# Coded by ThemePlard
#
# Suite de 7 accords en do majeur.
#
# Inspiration :
# -SWING & WALKING BASS
#   https://davidsfiddleblog.wordpress.com/2017/09/18/swing-walking-bass/
# -Trap beat for sonic pi
#   https://gist.github.com/interstar/4ed48718cb44ae6d9715988ae160e3f1
##########################################################################

use_debug false

use_bpm 120 # Définir la vitesse


########################
# Mixage               #
########################

set_mixer_control! amp:1 #définir l'amplitude du son global

# Pour finir le morceau en douceur décommenter la ligne ci-dessous, relancer l'execution du script.
# Après la fin recommenter et arrêter l'execution du script.
##| set_mixer_control! amp: 0, amp_slide: 16

org_amp = 1
cym_amp = 0.5
bas_amp = 1
drub_amp = 4
drus_amp = 1.3
tabb_amp = 1.3
tab_amp = 0.4
melo_amp = 0.6
all = (ramp *(line 1,0,steps: 32)).look


########################
# Live sample          #
########################

##| sample :ambi_lunar_land, amp: 0.4 # faire Alt +R pour rejouer ce sample pendant le morceau
##:| sample :guit_em9, rate: [0.25, 0.5, -1].choose, amp: 0.6
##| sample :guit_e_slide, rate: [0.25, 0.5, -1].choose
##| sample :guit_e_fifths, rate: [0.25, 0.5, -1].choose
##| sample :guit_harmonics, rate: [0.25, 0.5, -1].choose


########################
# Orgue                #
########################

chords = (ring 1, 6, 4, 2, 7, 5, 3) # Suite d'accord en degree
live_loop :harmony do #Début de boucle
  with_fx :flanger do #Ajouter un effet flanger
    use_synth :sine #choisir un synthétiseur sine
    tick # Incrémenter de 1 le tick par defaut et retourne la valeur
    4.times do # faire 4 fois
      play_chord (chord_degree chords.look, :c3,:major,4), amp: org_amp # Jouer l'accord (4 notes) suivant de la suite chords en do majeur octave 3
      sleep 1 # 1 temps avant le prochain son
    end
  end
end

########################
# Cymbale Swing        #
########################

live_loop :swing, delay: 4  do #Début de boucle après 4 temps
  sample :drum_cymbal_soft, cutoff: rrand(105, 130), amp: cym_amp #Jouer le sample :drum_cymbal_soft, en modifiant les fréquences aléatoirement(plus naturel) et une amplitude 0.5
  sleep (ring 1,0.7,0.3).tick # Swing
end

########################
# WALKING BASS         #
########################

live_loop :walking_bass, delay: 32 do
  tick
  use_synth :fm
  play (chord_degree chords.look,
        :c2,:major)[0], amp: bas_amp # Jouer la fondamentale de l'accord
  sleep 1
  play (chord_degree chords.look, :c2, # Jouer une note choisie dans les 5 premières(pas sûr)
        :major,5).choose, amp: bas_amp
  sleep 1
  play (chord_degree chords.look, :c2, # Jouer une note choisie dans le ring
        :major)[(ring 1,2,3).choose], amp: bas_amp
  sleep 1
  play (chord_degree chords[look + 1],
        :c2,:major)[0] + (ring -2,-1,1,2).choose, amp: bas_amp # Jouer la fondamentale de l'accord modifier par la valeur choisie dans le ring
  sleep 1
end

########################
# Drum                 #
########################

live_loop :drum, delay: 32 do
  x = [0,0,0,1,0,0,0,2,0,0,0,3].choose #Choisir au hasard un des modèles ci-dessous à jouer
  case x
  when 0
    sample :bd_boom, cutoff: rrand(70, 100), amp: drub_amp
    sleep 2
    sample :drum_snare_soft, cutoff: rrand(100, 120), amp: drus_amp
    sleep 2
  when 1
    sample :bd_boom, cutoff: rrand(70, 100), amp: drub_amp
    sleep 2
    sample :drum_snare_soft, cutoff: rrand(100, 120), amp: drus_amp
    sleep 1
    sample :drum_snare_soft, cutoff: rrand(100, 120), amp: drus_amp
    sleep 1
  when 2
    sample :bd_boom, cutoff: rrand(70, 100), amp: drub_amp
    sleep 2
    sample :drum_snare_soft, cutoff: rrand(100, 120), amp: drus_amp
    sleep 0.75
    sample :drum_snare_soft, cutoff: rrand(100, 120), amp: drus_amp
    sleep 1.25
  when 3
    sample :bd_boom, cutoff: rrand(70, 100), amp: drub_amp
    sleep 2
    sample :drum_snare_soft, cutoff: rrand(100, 120), amp: drus_amp
    sleep 0.6
    sample :drum_snare_soft, cutoff: rrand(100, 120), amp: drus_amp
    sleep 0.7
    sample :drum_snare_soft, cutoff: rrand(100, 120), amp: drus_amp
    sleep 0.7
  end
end


########################
# Tabla Bass           #
########################

live_loop :smpl, delay: 56, sync: :drum do  # Boucle syncronisée avec la boucle :drum
  #stop
  a = [0,0,0,0,1,2,1,2,3,3,3].choose #Choisir au hasard un des modèles ci-dessous à jouer
  case a
  when 0
    sample :tabla_ghe2, cutoff: rrand(70, 100), amp: tabb_amp
    sleep 1.5
    sample :tabla_ghe4, cutoff: rrand(70, 100), amp: tabb_amp
    sleep 2.5
  when 1
    sample :tabla_ghe2, cutoff: rrand(70, 100), amp: tabb_amp
    sleep 0.6
    sample :tabla_ghe4, cutoff: rrand(70, 100), amp: tabb_amp
    sleep 0.7
    sample :tabla_ghe4, cutoff: rrand(70, 100), amp: tabb_amp
    sleep 0.7
  when 2
    sample :tabla_ghe3, cutoff: rrand(70, 100), amp: tabb_amp
    sleep 1.5
    sample :tabla_ghe4, cutoff: rrand(70, 100), amp: tabb_amp
    sleep 0.5
    sample :tabla_ghe4, cutoff: rrand(70, 100), amp: tabb_amp
    sleep 2
  when 3
    sample :tabla_ghe2, cutoff: rrand(70, 100), amp: tabb_amp
    sleep 1.5
    sample :tabla_ghe4, cutoff: rrand(70, 100), amp: tabb_amp
    sleep 1.5
    sample :tabla_ghe4, cutoff: rrand(70, 100), amp: tabb_amp
    sleep 1
  end
end

########################
# Tabla                #
########################

def hat(v) #création d'une fonction
  sample [:tabla_na_o,:tabla_tas1,:tabla_na_s,:tabla_tas2,:tabla_na,:tabla_tas3,:tabla_tun1].choose, cutoff: rrand(60, 120), amp: v
end

live_loop :hats, delay: 56, sync: :swing do
  #stop
  b = [0,0,0,0,1,2,2,2,3,3].choose #Choisir au hasard un des modèles ci-dessous à jouer
  case b
  when 0
    4.times do
      hat(tab_amp)
      sleep 0.5
    end
  when 1
    8.times do
      hat(tab_amp)
      sleep 0.25
    end
  when 2
    2.times do
      hat(tab_amp)
      sleep 0.3
      hat(tab_amp)
      sleep 0.3
      hat(tab_amp)
      sleep 0.4
    end
  when 3
    1.times do
      hat(tab_amp)
      sleep 0.6
      hat(tab_amp)
      sleep 0.7
      hat(tab_amp)
      sleep 0.7
    end
  end
end

########################
# Mélodie              #
########################


def melo(mamp)
  chords = (ring 1,1,6,6,4,4,2,2,7,7,5,5,3,3)
  use_synth :beep
  play (chord_degree chords.look, :c4,:major,4).choose, amp: mamp
end

live_loop :melo, delay: 60 do
  with_fx :reverb, room: 1 do
    sync :swing
    c = [0,0,0,0,1,2,3,3,3,3].choose
    case c
    when 0
      1.times do
        melo(melo_amp)
        sleep 2
      end
    when 1
      2.times do
        melo(melo_amp)
        sleep 1
      end
    when 2
      4.times do
        melo(melo_amp)
        sleep 0.5
      end
    when 3
      1.times do
        melo(melo_amp)
        sleep (ring 0.6, 0.7, 0.7).look
      end
    end
  end
end


#2

I just learned this new case thing thanks to you. Could you give more details on what’s going on with this type of condition ?


#3

Try and see

loop do
  sleep 0.125
  x = [0,0,0,1,0,0,0,2,0,0,0,3].choose # random value 0-3
  case x
  when 0
    puts x
  when 1
    puts x
  when 2
    puts x
  when 3
    puts x
  end
end

#4

I know that case is not supported by the default syntax of the software. However, I thought about an application of this technique that could be very nice to sequence multiple patterns inside an unique live_loop.
I was expecting this to work but it seems that the loops are not sleeping or syncing correctly:

# TINY TINY MUSIC TRACKER FOR LIVE-CODING ----------
# Used to sequence easily tiny rythmical synth loops

live_loop :tracker do ; tick ; a = 0.125 ; rel = (knit 0.1, 1, 0.3, 1).look ; attack = 0 ; decay = (knit 0.5, 1, 0.2, 1).look
  pat = [1, 0, 0, 1].look
  use_bpm 90
  cutoff = (line 60, 110, steps: 5).reflect.look
  use_synth :dsaw
  use_synth_defaults release: rel, attack: attack, decay: decay, cutoff: cutoff, detune: 0.2
  play (ring :c3, :f3).look ; sleep a
  play (ring :c3, :f3).look ; sleep a
  play (ring :eb3, :ab3).look ; sleep a
  play (ring :c3, :f3).look ; sleep a
  play (ring :c3, :f3).look ; sleep a
  #------------------------
  play (ring :c3, :f3).look ; sleep a
  play (ring :g3, :bb3).look ; sleep a
  play (ring :c3, :f3).look ; sleep a
  play (ring :c3, :f3).look ; sleep a
  play (ring :c3, :f3).look ; sleep a
end

I was searching to extend this code by adding a second sequence to play.

When using a case on the pat variable, Sonic Pi is raising an error. I think that there must be something special to do with sleep to correct that but I can’t think of a solution right now.


#5

Like that

# TINY TINY MUSIC TRACKER FOR LIVE-CODING ----------
# Used to sequence easily tiny rythmical synth loops

live_loop :tracker do
  sleep 1
  tick
  a = 0.125
  rel = (knit 0.1, 1, 0.3, 1).look
  attack = 0
  decay = (knit 0.5, 1, 0.2, 1).look
  pat = [1, 0, 0, 1].look
  use_bpm 90
  cutoff = (line 60, 110, steps: 5).reflect.look
  use_synth :dsaw
  use_synth_defaults release: rel, attack: attack, decay: decay, cutoff: cutoff, detune: 0.2, amp: 4
  x = [0,0,0,1,0,0,0,2,0,0,0].choose # random value 0-2
  puts x
  case x
  when 0
    play (ring :c3, :f3).look
    sleep a
    play (ring :c3, :f3).look
    sleep a
    play (ring :eb3, :ab3).look
    sleep a
    play (ring :c3, :f3).look
    sleep a
    play (ring :c3, :f3).look
    sleep a
  when 1
    play (ring :c3, :f3).look
    sleep a
    play (ring :g3, :bb3).look
    sleep a
    play (ring :c3, :f3).look
    sleep a
    play (ring :c3, :f3).look
    sleep a
    play (ring :c3, :f3).look
    sleep a
  when 2
    play (ring :c3, :f3).look
    sleep a
    play (ring :g3, :bb3).look
    sleep a
    play (ring :c4, :f4).look
    sleep a
    play (ring :c4, :f4).look
    sleep a
    play (ring :c4, :f4).look
    sleep a
  end
end