Tuesday, July 11, 2017

ex1D13. Simple Algorithmic Note Generator

# ex1D13.py
# Simple Algorithmic Note Generator

from moduleCsound import *

tags(1)

header(ksmps=32, nch=1)

# --- global
# GEN 17 - x,y pairs (-17 not normalized)
# Both tables of size 100 (- since not power of 2)

add("""
giNotes ftgen 0,0,-100,-17,0,48, 15,53, 30,55, 40,60, 50,63, 60,65, 79,67, 85,70, 90,72, 96,75
giDurs ftgen 0,0,-100,-17,0,2, 30,0.5, 75,1, 90,1.5
""")

# --- instruments
# instr 1 triggers instr 2

add("""
  instr 1
kDur  init        0.5             ; initial rhythmic duration
kTrig metro       2/kDur          ; metronome freq. 2 times inverse of duration
kNdx  trandom     kTrig,0,1       ; create a random index upon each metro 'click'
kDur  table       kNdx,giDurs,1   ; read a note duration value
      schedkwhen  kTrig,0,0,2,0,1 ; trigger a note!
  endin

  instr 2
iNote table     rnd(1),giNotes,1                 ; read a random value from the function table
aEnv  linsegr 0, 0.005, 1, p3-0.105, 1, 0.1, 0 ; amplitude envelope
iPlk  random 0.1, 0.3                         ; point at which to pluck the string
iDtn  random    -0.05, 0.05                      ; random detune
aSig  wgpluck2  0.98, 0.2, cpsmidinn(iNote+iDtn), iPlk, 0.06
      out       aSig * aEnv
  endin
""")

tags(2)

# --- score

add("""
i 1 0    300  ; start 3 long notes close after one another
i 1 0.01 300
i 1 0.02 300
""")

tags(3)

writeRun(__file__)

No comments:

Post a Comment

ex3A05. Audio Vector