-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
nornsgenerate
executable file
·239 lines (189 loc) · 4.58 KB
/
nornsgenerate
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/bash
######################################################################
#
# NORNS PROJECT GENERATOR
# by Mads Kjeldgaard, 2020
#
######################################################################
PROJECTNAME=$1
ENGINENAME=$2
PROJECTDIR="$PROJECTNAME"
ENGINE="lib/Engine_$ENGINENAME.sc"
LUAFILE="$PROJECTNAME.lua"
function main() {
if [[ ! -z "$PROJECTNAME" ]] ; then
greeting
echo "Creating Norns project $PROJECTNAME in $PROJECTDIR"
# Create directory
mkdir $PROJECTDIR
cd $PROJECTDIR
# LUA FILE
echo "making main lua file $LUAFILE"
make_main_lua
# README
echo "making README file"
echo "# $PROJECTNAME" >> README.md
echo "A project for the monome norns sound computing platform" >> README.md
# Create engine
if [[ ! -z "$ENGINENAME" ]]; then
echo "making supercollider engine file $ENGINE"
make_engine
fi
initgit
echo "Done..."
else
echo "No project name supplied... exiting"
exit 1
fi
}
# If git is on the system, initialize a git repo and make the first commit
function initgit(){
if [[ -f "$(which git)" ]]; then
git init;
git add .
git commit . -m "first"
fi
}
# Create engine file
function make_engine() {
mkdir lib
echo "Engine_$ENGINENAME : CroneEngine {
var synth;
*new { arg context, doneCallback;
^super.new(context, doneCallback);
}
alloc {
SynthDef.new(\boringvolume, {|inL=0, inR=1, out=0, amp=0.5, pan=0|
var sig = In.ar([inL, inR]);
sig = sig * amp;
sig = Balance2.ar(sig[0], sig[1], pan);
Out.ar(out, sig)
}).add;
// Sync with audio norns' sc server
context.server.sync;
/*
The audio context's fx group:
context.xg
The in bus:
context.in_b
The out bus:
context.out_b
*/
synth = Synth.new(\boringvolume,
[
\inL, context.in_b[0].index,
\inR, context.in_b[1].index,
\out, context.out_b.index
],
target: context.xg // The fx group of Crone
);
// Expose commands to lua like this:
this.addCommand(\"amp\", \"f\", {|msg|
var val = msg[1];
synth.set(\amp, val)
});
this.addCommand(\"pan\", \"f\", {|msg|
var val = msg[1];
synth.set(\pan, val)
});
}
free {
synth.free;
}
}" > $ENGINE
}
# Create lua file
function make_main_lua() {
if [[ ! -z "$ENGINENAME" ]]; then
# Top part of generated LUA file
TOPCODE="-- Parameters for custom engine
engine.name = \"$ENGINENAME\"
-- Amplitude
params:add_control(\"amp\", \"amp\", controlspec.new(0.0, 1.0, 'lin', 0, 0.5, 'amps'))
params:set_action(\"amp\", function(x) engine.amp(x) end)
-- Panning
params:add_control(\"pan\", \"pan\", controlspec.new(-1.0, 1.0, 'lin', 0, 0.0, 'pans'))
params:set_action(\"pan\", function(x) engine.pan(x) end)
-- initialization
function init()
engine.load(\"$ENGINENAME\")
end
local viewport = { width = 128, height = 64, frame = 0 }
-- encoder actions: n = number, d = delta
function enc(n,d)
if n == 2 then
params:delta(\"amp\", d)
elseif n == 3 then
params:delta(\"pan\", d)
end
end
"
else
TOPCODE="engine.name = \"TestSine\"
-- initialization
function init()
engine.hz(100)
end
-- key actions: n = number, z = state
function key(n,z)
print(\"Key \" .. n .. \" pressed: \" .. z)
end
-- encoder actions: n = number, d = delta
function enc(n,d)
print(\"Enc \" .. n .. \" touched: \" .. d)
end
"
fi
# And then joined with the bottom part
echo "-- scriptname: $PROJECTNAME
-- v1.0.0 @$USER
$TOPCODE
-- key actions: n = number, z = state
function key(n,z)
end
function redraw()
screen.clear()
screen.move(0,viewport.height/2)
screen.text(\"this is $PROJECTNAME\")
screen.update()
end
-- deinitialization
function cleanup()
end
" > $LUAFILE
}
function greeting(){
echo "
@@@ @@@ @@@@@@ @@@@@@@ @@@ @@@ @@@@@@
@@@@ @@@ @@@@@@@@ @@@@@@@@ @@@@ @@@ @@@@@@@
@@!@!@@@ @@! @@@ @@! @@@ @@!@!@@@ !@@
!@!!@!@! !@! @!@ !@! @!@ !@!!@!@! !@!
@!@ !!@! @!@ !@! @!@!!@! @!@ !!@! !!@@!!
!@! !!! !@! !!! !!@!@! !@! !!! !!@!!!
!!: !!! !!: !!! !!: :!! !!: !!! !:!
:!: !:! :!: !:! :!: !:! :!: !:! !:!
:: :: ::::: :: :: ::: :: :: :::: ::
:: : : : : : : : :: : :: : :
"
}
function echo_help(){
echo "
NORNS PROJECT GENERATOR
usage:
nornsgenerate projectname [enginename]
projectname Project name (mandatory)
enginename If supplied, will create a lib directory with a SuperCollider Engine inside of it
-h Show help
EXAMPLE:
nornsgenerate howdy TurboMegaOverdrive
Will result in the following project structure:
howdy/howdy.lua
howdy/lib/Engine_TurboMegaOverdrive.sc
"
}
if [ $# -eq 0 ] || [ "$1" == "-h" ]; then
echo_help
exit 1
else
main
fi