Skip to content

Instantly share code, notes, and snippets.

@mortuosplango
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortuosplango/a4611700c212752d6528 to your computer and use it in GitHub Desktop.
Save mortuosplango/a4611700c212752d6528 to your computer and use it in GitHub Desktop.
// =====================================================================
// Amy Twigger Holroyd & Holger Ballweg: Knitting Sonification
// 10/01/2015
// =====================================================================
s.reboot
(
SynthDef(\pling, { |out=0,amp=0.1,sustain=1.0,freq=440,drop=1|
var snd, env;
snd = Splay.ar(LFCub.ar(Line.ar(freq * [1,1.01], freq * drop * [1,1.01])));
env = EnvGen.ar(Env.perc(0.001,sustain,curve:-6), doneAction:2);
OffsetOut.ar(out, snd * env * amp);
}).add;
SynthDef(\rpling, { |out=0,amp=0.1,sustain=1.0,freq=440,drop=1|
var snd,snd2, env;
snd = LFCub.ar(Line.ar(freq * [1,1.01], freq * drop * [1,1.01]));
snd2 = GrayNoise.ar(XLine.ar(1.0,0.0001,0.1));
snd2 = RHPF.ar(snd2, freq, 0.3);
snd = (snd + snd2)/2;
env = EnvGen.ar(Env.perc(0.1,sustain,curve:-4), doneAction:2);
OffsetOut.ar(out, snd * env * amp);
}).add;
SynthDef(\tsch, { |out=0,amp=0.1,sustain=1.0,freq=440|
var snd, env;
snd = GrayNoise.ar(1!2);
snd = RHPF.ar(snd, freq, 0.3);
snd = LPF.ar(snd, XLine.ar(8000,3000,sustain));
env = EnvGen.ar(Env.perc(0.01,sustain, curve:-4), doneAction:2);
OffsetOut.ar(out, snd * env * amp);
}).add;
)
// TODO "learning mode" go slower at the start, after 1 repeat of pattern go faster
// TODO fix parser for end and beginning stiches (can be there, can not be there)
// TODO have "overview" (speed up version of pattern) at the start of a row
// stop at repeat makes sense to show structure
(
// horseshoe lace
// http://www.knitting-bee.com/knitting-stitch-library/fancy-stitch-knitting-patterns/horseshoe-lace-knitting-stitch
~pattern_whole = [
"k1, *yo, k3, sl1, k2tog, psso, k3, yo, k1*",
"purl",
"k1, *k1, yo, k2, sl1, k2tog, psso, k2, yo, k2*",
"purl",
"k1, *k2, yo, k1, sl1, k2tog, psso, k1, yo, k3*",
"purl",
"k1, *k3, yo, sl1, k2tog, psso, yo, k4*",
"purl",
]
)
// (
// // chevron lace from 1300 patterns book
// ~pattern_whole = [
// "*k2, k2tog, k2, yo*",
// "purl",
// "*yo, k2, k2tog, k2*",
// "purl",
// ]
// )
(
~parse_pattern = {
|pattern|
pattern.collect({
|pat|
pat.replace(" ","").split($*).collect(_.split($,)).collect(_.select(_ != "")).select(_.size > 0).collect(_.collect{
|str|
switch (str[0],
$k, {
if(str.size > 2,
{
['ktog', str[1].asString.asInt];
},
{
['k', str[1].asString.asInt]
});
},
$s, {
['sl', str[2].asString.asInt]
},
$p, {
if(str == "psso", {
['psso'];
}, {
['purl']
});
},
$y, {
['yo']
},
{
['FAIL']
});
})});
};
)
// how to parse:
(
~parse_pattern.(~pattern_whole);
)
(
~play_stitch = {
|str,sustain=1.3, amp=0.5, tempo=1.5|
switch (str[0],
'k', {
"knit".post;
str[1].do{
|no|
(no + 1).post;
(instrument: \pling, amp:amp, freq: 400, sustain:sustain).play;
tempo.wait;
}},
'ktog', {
"knit two together".post;
[400,600,800][..str[1]].do{
|fr|
(instrument: \pling, amp:amp, freq: fr + [0,200] , sustain:(sustain * 1)).play;
(tempo/2).wait;
};
},
'sl', {
"slip".post;
str[1].do{
(instrument: \pling, drop: 0.5, amp:amp, freq: 400 * (1..3), sustain:sustain).play;
tempo.wait;
}
},
'psso', {
"pass stitch over".post;
(instrument: \pling, drop: 1.5, freq: 100 * (1,3..8),sustain: sustain, amp: amp).play;
tempo.wait;
},
'purl', {
// purl: reverse knit, should be equal in size
// but somewhat opposite
"purl".post;
(instrument: \rpling, freq: 400, sustain: sustain * 0.8, amp:amp).play;
tempo.wait;
},
'yo', {
var n = (1..3);
"yarn over".post;
n.do{ |j|
(instrument: \pling, freq: 100 * j, amp: amp, sustain: sustain/2).play;
((tempo/2)/(n.size + 1)).wait;
};
(tempo/2).wait;
},
{
"FAIL".post;
(instrument: \pling, amp:amp, freq: 800, sustain: sustain, drop: 0.1).play;
tempo.wait;
}
);
"| ".post
};
)
// test tasks to play the different sounds
Tdef(\t, { ~play_stitch.(['yo',]) }).play
Tdef(\t, { ~play_stitch.(['ktog',2]) }).play
Tdef(\t, { ~play_stitch.(['sl',1]) }).play
Tdef(\t, { ~play_stitch.(['psso'])}).play
Tdef(\t, { ~play_stitch.(['k', 1])}).play
Tdef(\t, { ~play_stitch.(['purl'])}).play
Tdef(\t, { ~play_stitch.(['F'])}).play
(
Tdef(\tt, {
loop {
var tempo = 1.5; // normal
//var tempo = 0.2; // fast
var amp = 0.3;
var sustain = tempo*0.8;
var repeats = 2;
// work out row length
var multiples = 10;
var pattern = ~parse_pattern.(~pattern_whole);
var rowlength = (multiples * repeats) + 1;
pattern.do{
|row, index|
("Row " ++ (index+1)).postln;
row[0].size.postln;
(instrument: \tsch, sustain: 0.1, freq: 2800, amp: amp).play;
tempo.wait;
if(row.size == 1, {
rowlength.do{
~play_stitch.(row[0][0], sustain, amp, tempo);
};
"\n".postln;
}, {
// play first stitch
~play_stitch.(row[0][0], sustain, amp, tempo);
// play repeated pattern
if(row.size > 0, {
repeats.do{
|repeat|
(instrument: \tsch, sustain: sustain/2, freq: 800*2, amp: amp).play;
(tempo).wait;
row[1].do{
|stitch|
~play_stitch.(stitch, sustain, amp, tempo);
};
};
});
"\n".postln;
});
tempo.wait;
(instrument: \tsch, sustain: sustain, freq: 200, amp: amp).play;
tempo.wait;
};
};
});
)
Tdef(\tt).play;
Tdef(\tt).stop;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment