-
Notifications
You must be signed in to change notification settings - Fork 0
/
funktapp.sc
117 lines (95 loc) · 2.89 KB
/
funktapp.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
FunktApp{
var <screenX, <screenY, <fps, <scAddr, <ciAddr, <mode, <appPath;
var args, oscPrefix = "/funkt/", patternLib, settings, symmetry;
*new{|screenX=800, screenY=600, fps=32, scAddr, ciAddr, mode=0, path, numPatterns=20|
^super.newCopyArgs(screenX, screenY, fps, scAddr, ciAddr, mode, path).init(numPatterns);
}
init{|numPatterns|
scAddr = scAddr ? NetAddr(NetAddr.localAddr.hostname, NetAddr.localAddr.port);
ciAddr = ciAddr ? NetAddr("127.0.0.1", 7000);
appPath = appPath ? "~/Development/funkt/cinder/xcode/build/Release/funktApp.app";
patternLib = Array.fill(numPatterns, {|i|
(index: i, active: 0, alpha: 0.0, alphamap: 0, colormap: 0)
});
// symmetry = ('ZERO': 0, 'AX': 1, 'AY': 2, 'DIAG': 3, 'QUAD': 4);
// interp = ( 'NONE': 0, 'LINEAR': 1, 'COSINE': 2 ); // interp count
settings = ('rule': 0, 'add': 0.005, 'symmetry': 4, 'interp': [0, 1], 'background': (0.0 ! 3));
}
makeArgumentString{
var str = "";
args = (
'-screenx': screenX,
'-screeny': screenY,
'-fps': fps,
'-remote': scAddr.hostname,
'-outport': scAddr.port,
'-inport': ciAddr.port,
'-wmode': mode
);
args.keysValuesDo({|key, val|
str = (str + key.asString + val.asString)
});
^("--args" ++ str)
}
open{|includeArgs=true|
if (includeArgs) {
("open" + appPath + this.makeArgumentString).unixCmd
}
{
("open" + appPath).unixCmd
}
}
start{|argMode|
mode = argMode ? 0;
this.open;
}
initWorld{|sizeX, sizeY, vectorSize, tdur, lrate|
this.sendMsg("init", sizeX, sizeY, vectorSize, tdur, lrate)
}
setPattern{|index, active, alpha, alphamap, colormap|
patternLib[index].active = active ? patternLib[index].active;
patternLib[index].alpha = alpha ? patternLib[index].alpha;
patternLib[index].alphamap = alphamap ? patternLib[index].alphamap;
patternLib[index].colormap = colormap ? patternLib[index].colormap;
this.sendPattern(index);
}
setPatternArg{|index, argname, value, send=true|
patternLib[index][argname] = value;
if (send) { this.sendPattern(index) }
}
sendPattern{|index|
this.sendMsg("pattern", index, *this.collectPatternArgs(index))
}
sendPresetRule{|name|
var rule;
rule = Generations.rules[name];
this.sendMsg("births", *rule[0]);
this.sendMsg("survivals", *rule[1]);
this.sendMsg("states", *rule[2]);
}
changeSetting{|name, value, send=true|
settings[name] = value;
if (send) { this.sendSetting(name) }
}
sendSetting{|name|
if (settings[name].isKindOf(Array)) {
this.sendMsg(name.asString, *settings[name])
}
{
this.sendMsg(name.asString, settings[name])
}
}
sendWeights{| ... weights|
this.sendMsg("weights", *weights)
}
collectPatternArgs{|index|
^(#[active, alpha, alphamap, colormap]).collect(patternLib[index][_])
}
quit{
this.sendMsg("quit")
}
sendMsg{|cmd ... msg|
ciAddr.sendMsg(oscPrefix++cmd, *msg)
}
changeOscPrefix{|prefix| oscPrefix = prefix }
}