Code Monkey home page Code Monkey logo

clj-krach's Introduction

clj-krach

What is it?

Glue code to use Leipzig with Sonic Pi.

How does it work

  • start Sonic Pi
  • start a repl in a project that has access to clj-krach
  • write some krach flavored leipzig
  • use the function krach to convert leipzigs edn data structures into Sonic Pi compatible ruby code and tell sonic pi to run it

Krach flavored Leipzig?

Leipzig models music as a sequence of notes, each of which is a map. They are ordered by :time:

[{:time 0
  :pitch 67
  :duration 2
  :part :melody}
 {:time 2
  :pitch 71
  :duration 2
  :part :melody}]

To use more of Sonic Pis functionality you can extend this basic maps in several ways.

basic scenarios

Every note must know when it is played. So this is the simplest legal note.

(krach [{:time 0}])

Without a pitch clj-krach ignores it and nothing is played.

(krach [{:time 0 
         :pitch 67}])

When we add a pitch we get a sound.

  • Since we don't wish for a special duration, the note is played for 1 second.
  • Since we don't tell the note which part to play, it defaults to the beep synth as it would in Sonic Pi.
(krach [{:time 0 
         :pitch 67 
         :duration 2 
         :part :piano}
        {:time 2
         :pitch 71
         :duration 2
         :part :mod_saw}])

If we add a :part key with another keyword as a value, clj-krach assumes that we want to play the Sonic Pi synth with that name.

options

Sonic Pi synth options can be added as a map under the :options key.

(krach [{:time 0
         :pitch 67
         :duration 2
         :part :prophet
         :options {:attack 0.5
                   :release 1
                   :cutoff 50}}])

defaults

Instead of a simple keyword the :part key can itself be a map with a :part key. Sonic Pi synth option defaults can be added as a map under the :defaults key.

(krach [{:time 0
         :pitch 67
         :duration 2
         :part {:part :prophet
                :defaults {:attack 0.5
                           :release 1
                           :cutoff 50}}}])

effects

A vector of effect descriptions can be added to the :part map under the :fx key.

(krach [{:pitch 52
         :time 0
         :duration 2
         :part {:part :mod_saw
                :fx [{:fx :distortion :options {:distort 0.5}}
                     {:fx :nlpf :options {:cutoff 75}}
                     {:fx :reverb :options {:room 0.2}}]}}])

control

To control the sound of a single note during its lifetime add a :control key with a vector of time offsets and options. Notice that the slide options can be put in the main :options map as defaults or in the :options map of a control event to set them for this event only.

(krach/krach [{:pitch 45
               :time 0
               :duration 12
               :part :subpulse
               :options {:note_slide 1}
               :control [{:offset 3, :options {:note 50}}
                         {:offset 6, :options {:note 40 :note_slide 0.1}}
                         {:offset 9, :options {:note 52}}]}])

playing a sample

Add a :type key to the map for non-synth commands. Supply options as usual.

(krach [{:type :sample
         :time 0
         :part :loop_amen
         :options {:beat_stretch 4}}])

A sample can not be controlled, but effects can be applyed.

(krach [{:type :sample
         :time 0
         :part {:part "/path/to/my-sample.wav"
                :fx [{:fx :distortion :options {:distort 0.9}}]}}])

playing midi

TODO

Why is it called that?

Chris Ford called his Clojurescript wrapper for the Web Audio API cljs-bach. Krach is german for noise. Go figure.

clj-krach's People

Contributors

tarnung avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.