Created
December 10, 2011 07:01
-
-
Save deltam/1454748 to your computer and use it in GitHub Desktop.
Clojureでクリスマスソングを書こう
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns overtone-chrismas.core | |
(:use [overtone.live])) | |
; example/basic.cljからコピペ | |
(defsynth foo [freq 200 dur 0.5] | |
(let [src (saw [freq (* freq 1.01) (* 0.99 freq)]) | |
low (sin-osc (/ freq 2)) | |
filt (lpf src (line:kr (* 10 freq) freq 10)) | |
env (env-gen (perc 0.1 dur) :action FREE)] | |
(out 0 (pan2 (* 0.1 low env filt))))) | |
; ドレミの周波数を定義 | |
(def doremi {:do [260.7 3] | |
:re [293.3 3] | |
:mi [330.0 3] | |
:fa [347.7 3] | |
:so [391.1 3] | |
:ra [440.0 3] | |
:si [495.0 3] | |
:do2 [521.5 3]}) | |
(defn key-on [note] | |
(apply foo (note doremi))) | |
(defn play-notes [notes wait-sec] | |
(dorun (map #(do (key-on %) (Thread/sleep wait-sec)) | |
notes))) | |
(comment | |
;ジングルベル | |
(do (play-notes [:do :ra :so :fa :do] 500) | |
(Thread/sleep 250) | |
(play-notes [:do :ra :so :fa :re] 500) | |
(Thread/sleep 250) | |
(play-notes [:re :si :ra :so :mi] 500) | |
(Thread/sleep 250) | |
(play-notes [:do2 :do2 :si :so :ra] 500) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment