-
Notifications
You must be signed in to change notification settings - Fork 5
/
s4pd-help.pd
executable file
·338 lines (338 loc) · 13 KB
/
s4pd-help.pd
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#N canvas 265 42 923 688 12;
#X declare -path s4pd;
#X obj 22 170 fudiformat -u;
#X obj 22 197 list tosymbol;
#N canvas 265 42 673 610 sending-from-outlets 0;
#X msg 90 147 reset, f 6;
#X obj 11 173 s4pd;
#X msg 221 382 (out 0 (list 1 2 3));
#X msg 223 411 (out 0 (list 'a :b "C"));
#X msg 222 438 (out 0 (vector 1 2 3));
#X obj 11 200 print s4pd-out;
#X msg 220 173 (out 0 "a string");
#X msg 222 147 (out 0 'foobaz);
#X msg 222 67 (out 0 1);
#X msg 222 92 (out 0 1.1);
#X msg 222 120 (out 0 :foobar);
#X text 411 122 Quoted symbols \, keywords \, and strings are all sent
as symbol messages, f 32;
#X text 409 69 Send output from outlet 0;
#X text 414 237 Plain messages work for non-nested expressions \, and
non space separated strings, f 32;
#X msg 220 294 out 0 "an error";
#X msg 212 469 (out 0 (list 'list 'a 'b));
#X msg 221 239 out 0 'hello-world;
#X msg 221 266 out 0 "an-ok-string";
#X text 419 439 Vectors are translated to lists, f 32;
#X text 215 13 Sending values out an s4pd outlet. Click the message
boxes and watch the console.;
#X text 420 470 We can output a list that starts with the symbol 'list
if you need a list selector., f 32;
#X text 422 379 Output lists - they can be of mixed type., f 32;
#X obj 27 146 r \$0_in;
#X obj 173 324 s \$0_in;
#X obj 12 90 fudiformat -u;
#X obj 12 117 list tosymbol;
#X obj 12 67 r \$0_code;
#X obj 172 197 s \$0_code;
#X obj 171 499 s \$0_code;
#X connect 0 0 1 0;
#X connect 1 0 5 0;
#X connect 2 0 28 0;
#X connect 3 0 28 0;
#X connect 4 0 28 0;
#X connect 6 0 27 0;
#X connect 7 0 27 0;
#X connect 8 0 27 0;
#X connect 9 0 27 0;
#X connect 10 0 27 0;
#X connect 14 0 23 0;
#X connect 15 0 28 0;
#X connect 16 0 23 0;
#X connect 17 0 23 0;
#X connect 22 0 1 0;
#X connect 24 0 25 0;
#X connect 25 0 1 0;
#X connect 26 0 24 0;
#X restore 10 470 pd sending-from-outlets;
#N canvas 265 42 613 357 array-io 0;
#X msg 38 96 (tabw 'array-1 0 .5);
#N canvas 265 42 450 278 (subpatch) 0;
#X array array-1 8 float 3;
#A 0 0.5 0 0 0 0 0 0 0;
#X coords 0 1 8 -1 200 140 1;
#X restore 26 174 graph;
#X text 26 23 Read and write to arrays with the table-read and table-write
functions \, also available as tabr and tabw.;
#X msg 27 68 (post "array-1 0:" (table-read 'array-1 0));
#X obj 26 125 s code;
#X connect 0 0 4 0;
#X connect 3 0 4 0;
#X restore 11 526 pd array-io;
#N canvas 265 42 735 340 loading-files 0;
#X text 21 12 Examples of loading files. In addition to specifying
a file name as the 2nd argument to s4pd \, we can load files dynamically
with Scheme code and with the read message. Note that loading files
this way does not reset the interpreter \, so multiple files can be
loaded on top of each other. In s7 \, redefining is permitted., f
97;
#X obj 104 227 s4pd;
#X text 19 93 Load a file without resetting the interpreter with the
read message. It will preserve any running definitions and state.,
f 97;
#X msg 23 192 read help-1.scm;
#X msg 165 192 read help-2.scm;
#X text 21 136 Within Scheme files \, you can load other files using
(load-from-path "filename.scm) You can use it in your Scheme files
to load other modules - see the help-2.scm file \, which loads help-1.scm.
, f 96;
#X text 22 265 Both read and load-from-path will look in the current
directory and then on your Pd file paths. Subdirectories will work
as well., f 96;
#X connect 3 0 1 0;
#X connect 4 0 1 0;
#X restore 10 419 pd loading-files;
#N canvas 265 42 643 484 wireless-messages 0;
#X floatatom 14 78 5 0 0 2 my-num my-num -;
#X msg 14 135 :a :b, f 8;
#X msg 150 82 (send 'my-num 99);
#X floatatom 152 207 5 0 0 0 - - -;
#X msg 152 228 (send 'my-num \$1);
#X msg 151 281 (define dest 'my-num) \, (send dest 42);
#X obj 14 107 r msg-1;
#X msg 152 160 (send 'msg-1 'set 'a 'b 'c);
#X msg 152 133 (send 'msg-1 'set 1 2 3);
#X text 150 112 Multiple arguments get sent as a Pd list;
#X text 150 332 Doing the same as a plain Pd message.;
#X text 13 10 Send messages to named receivers with the send function.
Receiver names should be quoted symbols or variables that point to
those.;
#X msg 153 378 send 'msg-1 'set var-1 var-2;
#X msg 153 353 define var-1 :a \, define var-2 :b;
#X text 398 355 <- click first!;
#X text 147 62 Send a message to the receiver named my-num;
#X obj 77 409 s s4pd-in;
#X obj 85 305 s code;
#X text 150 189 Change the number to send messages;
#X text 148 263 Make a var called dest and send to it.;
#X connect 2 0 17 0;
#X connect 3 0 4 0;
#X connect 4 0 17 0;
#X connect 5 0 17 0;
#X connect 6 0 1 0;
#X connect 7 0 17 0;
#X connect 8 0 17 0;
#X connect 12 0 16 0;
#X connect 13 0 16 0;
#X restore 11 499 pd wireless-messages;
#X obj 22 147 r code;
#X msg 225 290 (post "hello world!");
#X msg 399 290 (out 0 (+ 1 2 3));
#X floatatom 27 311 5 0 0 0 - - -;
#X msg 223 415 reset;
#X msg 368 530 out 0 my-var;
#X msg 225 530 define my-var 333;
#X symbolatom 76 311 11 0 0 0 - - -;
#X msg 475 530 out 1 'quoted-sym;
#N canvas 265 42 772 770 scheduling-events 0;
#X obj 407 123 loadbang;
#X msg 406 145 (define my-var 99);
#X text 20 434 To make a zero-argument function from some other function
\, we can use lambda., f 51;
#X msg 406 461 (set! my-var \$1);
#X floatatom 406 436 5 0 0 0 - - -;
#X text 455 435 Widget to change my-var;
#X text 472 122 Ensure my-var defined;
#X floatatom 257 685 5 0 0 0 - - -;
#X msg 257 708 (define (future-fun)(out 0 \$1));
#X text 20 201 Delay returns a handle we can use to cancel it, f 51
;
#X msg 35 368 (clear-delays);
#X msg 21 123 (define (post-my-var)(post 'my-var: my-var)) \, (delay
1000 post-my-var), f 46;
#X msg 23 222 (define handle (delay 1000 (lambda()(out 0 my-var))))
;
#X msg 71 248 (cancel-delay handle);
#X msg 160 368 reset;
#X msg 22 344 (delay 1000 (lambda()(post :one))) \, (delay 1500 (lambda()(post
:two))), f 72;
#X text 19 323 Cancel all running delays with clear-delay. resetting
also clears all delays., f 78;
#X text 20 533 Or capture the current value of my-var and use this
in the future with a let-over-lambda closure. (try moving the widget!)
, f 75;
#X text 21 648 To use a *function* as it will be in the future \, we
can wrap a call to eval in a lambda. Click on the right before the
time elapses to define it., f 74;
#X text 314 687 Widget to change future-fun;
#X msg 21 568 (delay 3000 (let ((captured-my-var my-var)) (lambda()(out
0 captured-my-var)))), f 54;
#X msg 21 685 (delay 3000 (lambda() (eval '(future-fun)))), f 26;
#X text 18 8 Schedule functions to run in the future with delay. Delay
takes 2 args: time to delay in ms \, and a function that must be callable
with no arguments. Note that if have log-null on \, you will see the
gensym handle for the delay instance logged to the console. Important:
the delay function uses infrastructure defined in Scheme \, in s4pd-schedule.scm.
If you did not ensure that the s4pd scm directory is on your Pd file
path \, these will not work. If it loaded correctly \, the global variable
s4pd-schedule-loaded will be #true., f 98;
#X text 241 249 <- click within one second to cancel!;
#X msg 23 470 (delay 2000 (lambda()(out 0 my-var)));
#X obj 23 495 s code;
#X obj 406 486 s code;
#X obj 21 164 s code;
#X obj 406 167 s code;
#X obj 23 273 s code;
#X obj 22 394 s code;
#X obj 21 611 s code;
#X obj 21 732 s code;
#X obj 257 734 s code;
#X obj 160 393 s s4pd-in;
#X connect 0 0 1 0;
#X connect 1 0 28 0;
#X connect 3 0 26 0;
#X connect 4 0 3 0;
#X connect 7 0 8 0;
#X connect 8 0 33 0;
#X connect 10 0 30 0;
#X connect 11 0 27 0;
#X connect 12 0 29 0;
#X connect 13 0 29 0;
#X connect 14 0 34 0;
#X connect 15 0 30 0;
#X connect 20 0 31 0;
#X connect 21 0 32 0;
#X connect 24 0 25 0;
#X restore 11 552 pd scheduling-events;
#N canvas 265 42 728 745 logging-to-console 0;
#X msg 12 304 (post "hello world" 1 1.2 :a-keyword);
#X msg 14 488 (post (list 1 :two "three" '(:a :nested :list)));
#X msg 14 400 (post 'symbol-1 (quote symbol-2) :a-keyword-is-a-symbol)
;
#X msg 12 619 post "this-one-is-ok" 1 2.25 'three :four;
#X msg 11 681 post "this is not ok";
#X text 6 10 Examples of posting to the Pd console. Note that these
send to the s4pd instance of the parent patch., f 97;
#X text 11 366 Posting quoted symbols prints the symbol name. Keywords
start with a colon and are symbols that act like they are always quoted.
, f 96;
#X text 11 465 Posting lists \, vectors \, hash-tables \, and pairs
will use their printed repr with parens., f 93;
#X msg 23 512 (post (hash-table :a 1 :b 2 :c (cons :d :e)));
#X obj 13 146 s s4pd-in;
#X obj 13 99 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1
;
#X obj 16 221 s s4pd-in;
#X obj 16 175 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X obj 150 146 s code;
#X text 10 277 When sending parenthesized code \, we can post pretty
much any type \, including strings with spaces, f 96;
#X obj 150 219 s code;
#X msg 150 196 (define n '());
#X msg 16 196 log-null \$1;
#X msg 13 121 log-repl \$1;
#X msg 150 122 (define v 42);
#X text 268 105 Evaluating an expression will print the value returned
if logging reply return values is on. Define returns the value defined
\, so we see 42 log-repl is on by default.;
#X text 269 174 Evaluating expressions that return the null list \,
<unspecified> \, or a gensym \, will only print to the console if log-null
is on (off by default). gensyms are returned by delay calls \, so scheduling
can log many of them.;
#X text 6 51 By default \, s4pd logs return values from evaluation
to the Pd console \, including null values \, shown as (). You can
turn these on and off with the log-repl and log-null messsages to s4pd.
, f 97;
#X text 11 580 When posting from plain messages (not parenthesized
code) \, strings without spaces are fine \, as they are still one atom
to Pd \, but strings with spaces are buggy still (hopefully to be fixed!)
, f 96;
#X msg 185 682 post "should\\\ be\\\ ok\\\,\\\ but\\\ buggy \, \ avoid"
;
#X msg 323 618 (post "and this is ok");
#X obj 12 330 s code;
#X obj 15 425 s code;
#X obj 13 538 s code;
#X obj 12 646 s s4pd-in;
#X obj 323 643 s code;
#X obj 11 709 s s4pd-in;
#X connect 0 0 26 0;
#X connect 1 0 28 0;
#X connect 2 0 27 0;
#X connect 3 0 29 0;
#X connect 4 0 31 0;
#X connect 8 0 28 0;
#X connect 10 0 18 0;
#X connect 12 0 17 0;
#X connect 16 0 15 0;
#X connect 17 0 11 0;
#X connect 18 0 9 0;
#X connect 19 0 13 0;
#X connect 24 0 31 0;
#X connect 25 0 30 0;
#X restore 10 444 pd logging-to-console;
#X obj 20 339 print s4pd-out;
#X text 8 395 Click for more features:;
#X msg 107 232 reset;
#X obj 30 232 r s4pd-in;
#X obj 223 441 s s4pd-in;
#X obj 387 558 s s4pd-in;
#X obj 20 278 s4pd 2 help-1.scm;
#X obj 23 118 declare -path s4pd;
#X text 221 182 The s4pd object takes 2 optional arguments \, an integer
for number of outlets \, and a filename to load on creation (found
by searching the Pd filepath). It always loads the s4pd.scm bootstrap
file first. You can change this file to create your own boot file.
, f 93;
#X obj 325 440 s s4pd-in;
#X text 25 6 Scheme for Pd embeds the s7 Scheme interpreter to allow
scripting and live coding Pd with Scheme Lisp. It is (mostly) compatible
with Scheme for Max \, so if you've never used Scheme \, you might
like the online "Learn Scheme For Max" e-book. Check the GitHub page
for further resources. Scheme for Pd was written by Iain C.T. Duncan
\, and uses the s7 Scheme interpreter \, by Bill Schottstaedt at CCRMA.
Please report any bugs \, issues \, or suggestions on the GitHub page
as issues. The main page is here: https://github.com/iainctduncan/scheme-for-pd
, f 121;
#X text 220 113 Ensure you have the s4pd directory on your Pd file
path so that s4pd can find its Scheme (.scm) files. These will be in
the same directory as the s4pd external on install. You can do this
with a declare path object \, or by setting it in your File Preferences
(recommended). For these examples \, you'll want to watch the Pd console
for helpful messages and post output., f 93;
#X text 221 479 Sending s4pd a message that starts with a symbol will
also evaluate the message as Scheme code \, as if it's surrounded by
parentheses. Any symbols will be taken to be variable names unless
quoted. This allows easy one-liners., f 93;
#X text 222 599 We can also use fudiformat and tosymbol to convert
code quoted string. s4pd interpets the 'symbol' message as a request
to evaluate the contents as Scheme. This can be used to send s4pd code
over the network as osc messages from a text editor., f 93;
#X obj 225 316 s code;
#X text 222 360 The reset message reboots the s7 intepreter and reloads
s4pd.scm. If you have a filename argument in your s4pd object \, this
file will also be reloaded. The read message loads a Scheme file without
resetting the interpreter \, preserving any active definitions and
state., f 94;
#X msg 325 414 read help-1.scm;
#X text 222 238 To send messages of Scheme code and have them evaluate
\, we can convert the code to a symbol message. (See the 'fudiformat
-u' and 'list tosymbol' on the left.) The return value is logged to
the console by default. Nils are (by default) not logged. (See logging-to-console).
, f 93;
#X connect 0 0 1 0;
#X connect 1 0 23 0;
#X connect 6 0 0 0;
#X connect 7 0 31 0;
#X connect 8 0 31 0;
#X connect 10 0 21 0;
#X connect 11 0 22 0;
#X connect 12 0 22 0;
#X connect 14 0 22 0;
#X connect 19 0 23 0;
#X connect 20 0 23 0;
#X connect 23 0 9 0;
#X connect 23 0 17 0;
#X connect 23 1 13 0;
#X connect 33 0 26 0;