Skip to content

Instantly share code, notes, and snippets.

@tado
Created October 30, 2013 13:55
Show Gist options
  • Save tado/7233085 to your computer and use it in GitHub Desktop.
Save tado/7233085 to your computer and use it in GitHub Desktop.
//----- エンベロープ -----------------------------------------------
// Env.linen - アタック、サステイン、リリース、レベルで指定
Env.linen(0.05, 0.2, 0.5, 0.7).plot;
(
{
var env = Env.linen(0.05, 0.1, 0.5);
SinOsc.ar(440) * EnvGen.kr(env, doneAction: 2)
}.play
)
// Env.perk - パーカッシブなエンベロープ
Env.perc(0.01, 2.0).plot;
(
{
var env = Env.perc(0.01, 2.0);
SinOsc.ar(440) * EnvGen.kr(env, doneAction: 2)
}.play
)
// Env.triangle - 三角形のエンベロープ
Env.triangle(1, 1).plot;
(
{
var env = Env.triangle(1, 1);
SinOsc.ar(440) * EnvGen.kr(env, doneAction: 2)
}.play
)
// Env.sine - ハニング窓
Env.sine(1, 1).plot;
(
{
var env = Env.sine(1, 1);
SinOsc.ar(440) * EnvGen.kr(env, doneAction: 2)
}.play
)
// Env.new - 完全に自由なエンベロープ生成
// レベルの配列と、時間の配列で指定
Env.new([0, 1, 0.9, 0], [0.1, 0.5, 1],[-5, 0, -5]).plot;
(
{
var env = Env.new([0, 1, 0.9, 0], [0.1, 0.5, 1],[-5, 0, -5]);
SinOsc.ar(440) * EnvGen.kr(env, doneAction: 2)
}.play
)
//----- スケジューリング -------------------------------------------
// Routine基本
r = Routine({
"あいうえお".yield;
"かきくけこ".yield;
"さしすせそ".yield;
"たちつてと".yield;
"なにぬねの".yield;
"はひふへほ".yield;
});
r.next; // Routineの次の値を取得
6.do({ r.next.postln }); // 6回まとめて実行
// Routineをスケジューリング- 1
Routine({
//12回くりかえし
12.do{
//カウンタ変数
arg i;
//メッセージを出力
"Count = ".post; i.postln;
//1秒待つ
1.yield;
}
}).play;
// Routineをスケジューリング - 2
r = Routine({
//待ち時間を記録する変数
var delta;
12.do {
//待ち時間、1〜5秒をランダムに生成
delta = rrand(1,5);
//メッセージを出力
"Will wait ".post; delta.postln;
//1〜5秒待つ
delta.yield;
}
}).play;
// Routine実験用、Synth "singrain"
(
SynthDef("singrain", {
arg freq = 440, amp = 0.2, sustain = 1;
var env, sig;
env = EnvGen.kr(Env.perc(0.01, sustain), doneAction: 2);
sig = SinOsc.ar([freq, freq * 1.01], 0, amp) * env;
Out.ar(0, sig);
}).add;
)
//反復して演奏
(
Routine({
loop{
Synth("singrain");
1.yield;
}
}).play;
)
//等比的に上昇
(
Routine({
var freq;
24.do{
arg i;
freq = i * 1.5 * 55;
Synth("singrain", ["freq", freq]);
0.2.yield;
}
}).play;
)
//12音階をランダムに
(
Routine({
var freq;
loop{
freq = [60,61,62,63,64,65,66,67,68,69,70,71].choose.midicps;
Synth("singrain", ["freq", freq]);
0.5.yield;
}
}).play;
)
//音程、長さ、音量をランダムに
(
Routine({
var freq, amp, sustain;
loop{
freq = [60,61,62,63,64,65,66,67,68,69,70,71].choose.midicps;
amp = exprand(0.1, 0.5);
sustain = rrand(1, 4) * 0.5;
Synth("singrain", ["freq", freq, "amp", amp, "sustain", sustain]);
(sustain * 0.8).yield;
}
}).play;
)
//2つの音程
(
Routine({
var freq1, freq2, amp, sustain;
loop{
freq1 = [60,61,62,63,64,65,66,67,68,69,70,71].choose.midicps;
freq2 = [60,61,62,63,64,65,66,67,68,69,70,71].choose.midicps;
amp = exprand(0.1, 0.3);
sustain = rrand(1, 4) * 0.5;
Synth("singrain", ["freq", freq1, "amp", amp, "sustain", sustain]);
Synth("singrain", ["freq", freq2, "amp", amp, "sustain", sustain]);
(sustain * 0.8).yield;
}
}).play;
)
//2つの音程 - 2
(
Routine({
var freq1, freq2, amp, sustain;
loop{
freq1 = [60,61,62,63,64,65,66,67,68,69,70,71].choose.midicps;
freq2 = freq1 * [1.0/1.0, 2.0/1.0, 3.0/2.0, 4.0/3.0, 5.0/4.0].choose;
amp = exprand(0.1, 0.3);
sustain = rrand(1, 4) * 0.5;
Synth("singrain", ["freq", freq1, "amp", amp, "sustain", sustain]);
Synth("singrain", ["freq", freq2, "amp", amp, "sustain", sustain]);
(sustain * 0.8).yield;
}
}).play;
)
//4つの音程
(
Routine({
var note1, note2, note3, note4, amp, sustain;
loop{
note1 = [60,61,62,63,64,65,66,67,68,69,70,71].choose;
note2 = note1 + [0, 2, 4, 5, 7, 9].choose - [0, 12].choose;
note3 = note1 + [0, 2, 4, 5, 7, 9].choose - [0, 12].choose;
note4 = note1 + [0, 2, 4, 5, 7, 9].choose - [0, 12].choose;
amp = exprand(0.05, 0.2);
sustain = rrand(1, 8) * 0.5;
Synth("singrain", ["freq", note1.midicps, "amp", amp, "sustain", sustain]);
Synth("singrain", ["freq", note2.midicps, "amp", amp, "sustain", sustain]);
Synth("singrain", ["freq", note3.midicps, "amp", amp, "sustain", sustain]);
Synth("singrain", ["freq", note4.midicps, "amp", amp, "sustain", sustain]);
(sustain * 0.8).yield;
}
}).play;
)
//4つの音程2
(
Routine({
var note1, note2, note3, note4, amp, sustain;
loop{
note1 = [60,61,62,63,64,65,66,67,68,69,70,71].choose;
note2 = note1 + [0, 5, 7].choose - [0, 12].choose;
note3 = note2 + [0, 5, 7].choose - [0, 12].choose;
note4 = note3 + [0, 5, 7].choose - [0, 12].choose;
amp = exprand(0.1, 0.2);
sustain = rrand(1, 8);
Synth("singrain", ["freq", note1.midicps, "amp", amp, "sustain", sustain]);
Synth("singrain", ["freq", note2.midicps, "amp", amp, "sustain", sustain]);
Synth("singrain", ["freq", note3.midicps, "amp", amp, "sustain", sustain]);
Synth("singrain", ["freq", note4.midicps, "amp", amp, "sustain", sustain]);
(sustain * 0.8).yield;
}
}).play;
)
//4つの音程 x 2
(
r = Routine({
var note1, note2, note3, note4, amp, sustain;
loop{
note1 = [60,61,62,63,64,65,66,67,68,69,70,71].choose;
note2 = note1 + [0, 5, 7].choose - [0, 12, 24].choose;
note3 = note2 + [0, 5, 7].choose - [0, 12, 24].choose;
note4 = note3 + [0, 5, 7].choose - [0, 12, 24].choose;
amp = exprand(0.05, 0.1);
sustain = rrand(1, 8);
Synth("singrain", ["freq", note1.midicps, "amp", amp, "sustain", sustain]);
Synth("singrain", ["freq", note2.midicps, "amp", amp, "sustain", sustain]);
Synth("singrain", ["freq", note3.midicps, "amp", amp, "sustain", sustain]);
Synth("singrain", ["freq", note4.midicps, "amp", amp, "sustain", sustain]);
(sustain * 0.8).yield;
}
});
r.play;
r.play;
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment