Skip to content

Instantly share code, notes, and snippets.

@mohayonao
mohayonao / gist:7119472
Last active December 26, 2015 07:59
1up
def = Synth.def (freq)->
amp = Line.kr(1, 0, dur:1.5, doneAction:2)
mod = SinOsc.ar(freq * 2)
Out.ar(0, SinOsc.ar(freq, phase:mod, mul:0.25) * amp)
Task.loop ->
scale = Scale.major # Scale.diminished / Scale.choose()
synth = def.play()
Task.each [2,4,9,7,8,9], (degree)->
freq = scale.degreeToFreq degree, 1046.50
def = Synth.def (freq=440, amp=1)->
amp *= Line.kr(0.5, 0, 1.25, doneAction:2)
Out.ar(0, SinOsc.ar([freq, freq * 1.01]) * amp)
Task.loop ->
scale = Scale.major
t = Task.each [0,1,2,3,4,5,6,7], (degree)->
def.play freq:scale.degreeToFreq degree, 880
@wait 500
.play()
@mohayonao
mohayonao / coverage-task.coffee
Last active December 26, 2015 22:59
istanbul + mocha + grunt
grunt.registerTask 'coverage', ->
path = require 'path'
istanbul = require 'istanbul'
Instrumenter = istanbul.Instrumenter # 計算用のファイルを作る
Collector = istanbul.Collector # 集計する
Reporter = istanbul.Reporter # 出力する
hook = istanbul.hook # あとで説明する
coverageVar = "$$cov#{Date.now()}$$"
instrumenter = new Instrumenter(coverageVar:coverageVar)
@mohayonao
mohayonao / replaced.coffee
Last active December 27, 2015 10:09
Task関数の書き換え
Task.do ->
[s1] = []
[
=>
s1 = def.play()
@wait 100
=>
s1.set freq:220
@wait 200
=>
@mohayonao
mohayonao / iterator.coffee
Last active December 27, 2015 10:09
iterator
i = Iterator ->
x = 0
@yield x # 0
x += 10
@yield x # 10
x += 10
if no
@yield "skipped"
else if yes
@yield x
@mohayonao
mohayonao / gist:7382876
Created November 9, 2013 07:47
SynthDefTemplate
# 関数の中を調べて最終行が関数でない
SynthDef (freq=440)->
Out.ar(0, SinOsc.ar(freq))
# replaced
SynthDef((freq)->
Out.ar(0, SinOsc.ar(freq))
, ["freq", "440"])
# 関数の中を調べて最終行が関数 = (template)
@mohayonao
mohayonao / patch.js
Last active December 28, 2015 06:29
Web CassetteをiOSで鳴らすためのパッチ
CassetteSound.prototype.start = function() {
this.on = true;
var self = this;
if (!this.connected) {
this.connected = true;
// iOSはユーザー発のイベントから Web Audio API をスタートさせないと動かないので
// コンストラクタの connect を start に移動させる
if (this.dummy.noteOn) { // Firefox対策 (なぜか noteOn メソッドがない)
(->
trig = Dust.kr([5, 5])
freq = TIRand.kr(110, 1760, trig).lag(1)
SinOscFB.ar(freq, 0.5.pi()) * Decay.kr(trig, 0.25)
).play()
# src
a = for i in list by 2
console.log i
@wait 1
i
console.log a
# replaced
@wait a = Task.ForLoop list, 2, (i)->
console.log i
@mohayonao
mohayonao / task.coffee
Created November 20, 2013 05:20
こう書きたい
Task ->
i = 0
loop
console.log i
1.wait()
.play()
Task ->
for i in [0..10] by 2
console.log i