Skip to content

Latest commit

 

History

History
87 lines (61 loc) · 3.92 KB

cookbook.org

File metadata and controls

87 lines (61 loc) · 3.92 KB

cl-patterns cookbook

A “cookbook” for cl-patterns; various recipes for instruction and inspiration.

Random notes from a scale

cl-patterns provides musical scale data in scales.lisp. If we feel like being blasphemous, we can shuffle a scale and call it “automatic jazz”:

(pbind :degree (pshuf (scale-notes :minor) 4)
       :dur (pshuf (list 1/3 1/4)))

Play sections of an audio file

With the bdef library, you can conveniently load sound files and define splits, which represent sections of the file. The library comes with a psplits pattern in its bdef/cl-patterns sub-system which makes it easy to integrate with cl-patterns. Example:

(bdef :song "/path/to/song.wav")

(pbind :instrument :spt
       :bufnum (bdef :song)
       :split (pseries 0 1 (splits-length (bdef :song)))
       :legato 1
       :embed (psplits))

The above does the following:

  • Loads a song into a buffer with bdef, giving it the song key.
  • Selects the spt synth, which has a gate parameter, as well as start and end, which represent the start and end points of the split as a percentage in the file (0..1).
  • Loads a song.
  • Automatically finds onset points in the song with any defined bdef “auto-metadata”.
  • Uses pseries to select each split associated with the bdef, in order.
  • Sets the legato to 1 to ensure the full split is played.
  • Uses psplits to embed the parameters for the selected split to be played with spt.

So what does this pattern actually do? All it does is play each section of the audio file in order. If the file is divided into a series of consecutive, non-overlapping splits, the pattern will sound just like the input file.

Why would we want to do this? This is often a good starting point for if you want to do something like remixing a song. From here you can add further keys to the end of the pbind to change the split pitch, send the output to an effect, change the rhythm, etc.

Keep in mind that psplits outputs events that include start, end, and dur for each split. So if you wanted to do something like playing every even split for half its original length, and every odd for double, you’d add the following after the psplits:

:dur (p* (pk :dur) (pseq '(1/2 2)))

Of course, the possibilities are endless here. And thanks to splits having a comments slot, you can associate any data you want with each split. This could be manually-entered textual comments, automatically-generated audio analysis data, etc.

Ideas for things to use the comments field for:

  • Divide the splits up by the part of the song they fall into, to allow a remix to run different “algorithms” for each.
  • Analyze the pitch of each split, then use it to create a makeshift “autotune”.

Amen break

It should be fairly easy to write the Amen break based on textual notation. For example, the page here provides drum tabs. There’s no reason a computer couldn’t read these as easily as a human can. Fortunately, the pcycles pattern accepts strings as input and reads the same notation as the provided tabs.

(tempo 136/60) ;; the Amen break is 136 BPM

(pb :hat
  :instrument :hat
  :dur 1/2 ;; play the hihat every 1/2 beat
  :pfindur 4 ;; limit the pattern to 4 beats in length (it loops automatically)
  :quant 4 ;; ensure that the pattern starts on a beat that is divisible by 4
  )

(pb :snare
  :embed (pcycles "----o--o-o--o--o") ;; using the snare tab from the page linked above
  :instrument :snare
  :dur 1/4
  :quant 4)

(pb :kick
  :embed (pcycles "o-o-------oo----")
  :instrument :kick
  :dur 1/4
  :quant 4)

;; play the patterns we've defined:
(play (list :hat :snare :kick))