-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.html
2389 lines (2123 loc) · 115 KB
/
README.html
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2021-09-20 Mon 09:10 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Ad Libitum</title>
<meta name="generator" content="Org mode" />
<meta name="author" content="Ruslan Prakapchuk" />
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
font-size: medium;
font-weight: bold;
margin-top:0; }
.todo { font-family: monospace; color: red; }
.done { font-family: monospace; color: green; }
.priority { font-family: monospace; color: orange; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: auto;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline; margin-top: 14px;}
/* Languages per Org manual */
pre.src-asymptote:before { content: 'Asymptote'; }
pre.src-awk:before { content: 'Awk'; }
pre.src-C:before { content: 'C'; }
/* pre.src-C++ doesn't work in CSS */
pre.src-clojure:before { content: 'Clojure'; }
pre.src-css:before { content: 'CSS'; }
pre.src-D:before { content: 'D'; }
pre.src-ditaa:before { content: 'ditaa'; }
pre.src-dot:before { content: 'Graphviz'; }
pre.src-calc:before { content: 'Emacs Calc'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-fortran:before { content: 'Fortran'; }
pre.src-gnuplot:before { content: 'gnuplot'; }
pre.src-haskell:before { content: 'Haskell'; }
pre.src-hledger:before { content: 'hledger'; }
pre.src-java:before { content: 'Java'; }
pre.src-js:before { content: 'Javascript'; }
pre.src-latex:before { content: 'LaTeX'; }
pre.src-ledger:before { content: 'Ledger'; }
pre.src-lisp:before { content: 'Lisp'; }
pre.src-lilypond:before { content: 'Lilypond'; }
pre.src-lua:before { content: 'Lua'; }
pre.src-matlab:before { content: 'MATLAB'; }
pre.src-mscgen:before { content: 'Mscgen'; }
pre.src-ocaml:before { content: 'Objective Caml'; }
pre.src-octave:before { content: 'Octave'; }
pre.src-org:before { content: 'Org mode'; }
pre.src-oz:before { content: 'OZ'; }
pre.src-plantuml:before { content: 'Plantuml'; }
pre.src-processing:before { content: 'Processing.js'; }
pre.src-python:before { content: 'Python'; }
pre.src-R:before { content: 'R'; }
pre.src-ruby:before { content: 'Ruby'; }
pre.src-sass:before { content: 'Sass'; }
pre.src-scheme:before { content: 'Scheme'; }
pre.src-screen:before { content: 'Gnu Screen'; }
pre.src-sed:before { content: 'Sed'; }
pre.src-sh:before { content: 'shell'; }
pre.src-sql:before { content: 'SQL'; }
pre.src-sqlite:before { content: 'SQLite'; }
/* additional languages in org.el's org-babel-load-languages alist */
pre.src-forth:before { content: 'Forth'; }
pre.src-io:before { content: 'IO'; }
pre.src-J:before { content: 'J'; }
pre.src-makefile:before { content: 'Makefile'; }
pre.src-maxima:before { content: 'Maxima'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-picolisp:before { content: 'Pico Lisp'; }
pre.src-scala:before { content: 'Scala'; }
pre.src-shell:before { content: 'Shell Script'; }
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
/* additional language identifiers per "defun org-babel-execute"
in ob-*.el */
pre.src-cpp:before { content: 'C++'; }
pre.src-abc:before { content: 'ABC'; }
pre.src-coq:before { content: 'Coq'; }
pre.src-groovy:before { content: 'Groovy'; }
/* additional language identifiers from org-babel-shell-names in
ob-shell.el: ob-shell is the only babel language using a lambda to put
the execution function name together. */
pre.src-bash:before { content: 'bash'; }
pre.src-csh:before { content: 'csh'; }
pre.src-ash:before { content: 'ash'; }
pre.src-dash:before { content: 'dash'; }
pre.src-ksh:before { content: 'ksh'; }
pre.src-mksh:before { content: 'mksh'; }
pre.src-posh:before { content: 'posh'; }
/* Additional Emacs modes also supported by the LaTeX listings package */
pre.src-ada:before { content: 'Ada'; }
pre.src-asm:before { content: 'Assembler'; }
pre.src-caml:before { content: 'Caml'; }
pre.src-delphi:before { content: 'Delphi'; }
pre.src-html:before { content: 'HTML'; }
pre.src-idl:before { content: 'IDL'; }
pre.src-mercury:before { content: 'Mercury'; }
pre.src-metapost:before { content: 'MetaPost'; }
pre.src-modula-2:before { content: 'Modula-2'; }
pre.src-pascal:before { content: 'Pascal'; }
pre.src-ps:before { content: 'PostScript'; }
pre.src-prolog:before { content: 'Prolog'; }
pre.src-simula:before { content: 'Simula'; }
pre.src-tcl:before { content: 'tcl'; }
pre.src-tex:before { content: 'TeX'; }
pre.src-plain-tex:before { content: 'Plain TeX'; }
pre.src-verilog:before { content: 'Verilog'; }
pre.src-vhdl:before { content: 'VHDL'; }
pre.src-xml:before { content: 'XML'; }
pre.src-nxml:before { content: 'XML'; }
/* add a generic configuration mode; LaTeX export needs an additional
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
pre.src-conf:before { content: 'Configuration File'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.org-right { text-align: center; }
th.org-left { text-align: center; }
th.org-center { text-align: center; }
td.org-right { text-align: right; }
td.org-left { text-align: left; }
td.org-center { text-align: center; }
dt { font-weight: bold; }
.footpara { display: inline; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.equation-container {
display: table;
text-align: center;
width: 100%;
}
.equation {
vertical-align: middle;
}
.equation-label {
display: table-cell;
text-align: right;
vertical-align: middle;
}
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
.org-svg { width: 90%; }
/*]]>*/-->
</style>
<link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/htmlize.css"/>
<link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/readtheorg.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/src/lib/js/jquery.stickytableheaders.min.js"></script>
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/js/readtheorg.js"></script>
<script type="text/javascript">
// @license magnet:?xt=urn:btih:e95b018ef3580986a04669f1b5879592219e2a7a&dn=public-domain.txt Public Domain
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.classList.add("code-highlighted");
target.classList.add("code-highlighted");
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.classList.remove("code-highlighted");
target.classList.remove("code-highlighted");
}
}
/*]]>*///-->
// @license-end
</script>
</head>
<body>
<div id="content">
<h1 class="title">Ad Libitum</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org60b23b7">1. Getting Started</a>
<ul>
<li><a href="#orgae7fbf2">1.1. Chez Scheme</a>
<ul>
<li><a href="#org832873b">1.1.1. Clone Chez Scheme repository</a></li>
<li><a href="#orgef9f628">1.1.2. Configure, build and install Chez Scheme</a></li>
<li><a href="#orgf5c310f">1.1.3. Test it's working</a></li>
</ul>
</li>
<li><a href="#orga38fa2c">1.2. libsoundio</a></li>
<li><a href="#org4470dca">1.3. PortMidi</a></li>
<li><a href="#org4b5d8e8">1.4. Ad Libitum itself</a>
<ul>
<li><a href="#orgd5db719">1.4.1. Install</a></li>
<li><a href="#orgb9f4620">1.4.2. Test</a></li>
<li><a href="#orgad169ed">1.4.3. Play</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#orgeaf5b92">2. Contribution</a></li>
<li><a href="#org59a8a4c">3. Kernel</a>
<ul>
<li><a href="#orgb79f8fd">3.1. Sound I/O</a></li>
<li><a href="#orgd311c09">3.2. Scheduler</a>
<ul>
<li><a href="#orgd112e7d">3.2.1. Pairing Heap</a></li>
</ul>
</li>
<li><a href="#org5d93302">3.3. Remote REPL</a>
<ul>
<li><a href="#org6c1f1b3">3.3.1. <span class="todo TODO">TODO</span> Ensure that protocol is TCP</a></li>
<li><a href="#org481e5de">3.3.2. Blocking vs Async sockets</a></li>
<li><a href="#org4b9a40d">3.3.3. Open socket</a></li>
<li><a href="#org3582e09">3.3.4. Accept connections</a></li>
<li><a href="#org934036f">3.3.5. Spawn remote REPL</a></li>
<li><a href="#org95ee76d">3.3.6. <span class="todo TODO">TODO</span> Stop loop and close socket on disconnect</a></li>
<li><a href="#orga58e6d9">3.3.7. Start REPL server</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#orge80390d">4. Core</a>
<ul>
<li><a href="#orga3cec52">4.1. Math</a></li>
<li><a href="#org7ec6f54">4.2. Generators</a></li>
<li><a href="#org131663f">4.3. Envelopes</a>
<ul>
<li><a href="#org5684e44">4.3.1. ADSR</a></li>
<li><a href="#org1517c56">4.3.2. Impulse</a></li>
<li><a href="#org9c0711a">4.3.3. Transition</a></li>
</ul>
</li>
<li><a href="#org006427d">4.4. Metronome</a></li>
<li><a href="#orge56cf93">4.5. Control signals</a></li>
</ul>
</li>
<li><a href="#orgd4e35bd">5. Std</a>
<ul>
<li><a href="#orgac328ce">5.1. FFT</a></li>
<li><a href="#orgecc153e">5.2. Filters</a></li>
<li><a href="#orgbac777e">5.3. Instruments</a></li>
<li><a href="#orgb22d8bc">5.4. Scales</a></li>
<li><a href="#orgf4ede71">5.5. Rhythm</a></li>
<li><a href="#org5e66f64">5.6. MIDI</a></li>
</ul>
</li>
<li><a href="#org499e186">6. Misc</a></li>
</ul>
</div>
</div>
<p>
The Scheme Live Coding Environment. Built on Chez Scheme and libsoundio.
</p>
<p>
You might want to read this file here <a href="http://ul.mantike.pro/ad-libitum/README.html">http://ul.mantike.pro/ad-libitum/README.html</a>
</p>
<div id="outline-container-org60b23b7" class="outline-2">
<h2 id="org60b23b7"><span class="section-number-2">1</span> Getting Started</h2>
<div class="outline-text-2" id="text-1">
<p>
This guide describes initial setup required to produce your first piece of
digital noise with Ad Libitum. At the moment Ad Libitum is tested only on
MacOS therefore following instructions are MacOS-specific. Any feedback and
improvement for other platforms is more than welcome! Current state of Ad
Libitum dependencies is that it should be easy to port it to Linux and
moderately hard (but possible) to Windows.
</p>
</div>
<div id="outline-container-orgae7fbf2" class="outline-3">
<h3 id="orgae7fbf2"><span class="section-number-3">1.1</span> Chez Scheme</h3>
<div class="outline-text-3" id="text-1-1">
<p>
First, you need Chez Scheme itself. Ad Libitum requires threaded version and
you probably don't want to install x11 dependency, that's why better to do it
from source, not brew. Also we are using Racket's fork to be able to build on M1
while <a href="https://github.com/cisco/ChezScheme/issues/544">https://github.com/cisco/ChezScheme/issues/544</a> is in progress.
</p>
</div>
<div id="outline-container-org832873b" class="outline-4">
<h4 id="org832873b"><span class="section-number-4">1.1.1</span> Clone Chez Scheme repository</h4>
<div class="outline-text-4" id="text-1-1-1">
<div class="org-src-container">
<pre class="src src-shell">git clone https://github.com/racket/ChezScheme.git
<span style="font-weight: bold;">cd</span> ChezScheme
</pre>
</div>
</div>
</div>
<div id="outline-container-orgef9f628" class="outline-4">
<h4 id="orgef9f628"><span class="section-number-4">1.1.2</span> Configure, build and install Chez Scheme</h4>
<div class="outline-text-4" id="text-1-1-2">
<div class="org-src-container">
<pre class="src src-shell">./configure --disable-x11
make
sudo make install
</pre>
</div>
<p>
The first command may suggest you to build boot image first, e.g. on M1:
</p>
<div class="org-src-container">
<pre class="src src-shell">./configure --pb
make tarm64osx.bootquick
</pre>
</div>
</div>
</div>
<div id="outline-container-orgf5c310f" class="outline-4">
<h4 id="orgf5c310f"><span class="section-number-4">1.1.3</span> Test it's working</h4>
<div class="outline-text-4" id="text-1-1-3">
<p>
Run <code>scheme</code> from terminal and try to evaluate simple expression:
</p>
<div class="org-src-container">
<pre class="src src-shell">~/ChezScheme> scheme
Chez Scheme Version 9.5.5.5
Copyright 1984-2020 Cisco Systems, Inc.
> (+ 1 2 3)
6
>
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-orga38fa2c" class="outline-3">
<h3 id="orga38fa2c"><span class="section-number-3">1.2</span> libsoundio</h3>
<div class="outline-text-3" id="text-1-2">
<p>
This is library used by Ad Libitum for communication with your computer's
sound system.
</p>
<div class="org-src-container">
<pre class="src src-shell">brew install libsoundio
</pre>
</div>
</div>
</div>
<div id="outline-container-org4470dca" class="outline-3">
<h3 id="org4470dca"><span class="section-number-3">1.3</span> PortMidi</h3>
<div class="outline-text-3" id="text-1-3">
<p>
You need it if you plan to use MIDI controller.
</p>
<div class="org-src-container">
<pre class="src src-shell">brew install portmidi
</pre>
</div>
</div>
</div>
<div id="outline-container-org4b5d8e8" class="outline-3">
<h3 id="org4b5d8e8"><span class="section-number-3">1.4</span> Ad Libitum itself</h3>
<div class="outline-text-3" id="text-1-4">
</div>
<div id="outline-container-orgd5db719" class="outline-4">
<h4 id="orgd5db719"><span class="section-number-4">1.4.1</span> Install</h4>
<div class="outline-text-4" id="text-1-4-1">
<p>
You need to clone repository and build several helping libraries. You may
need to set <code>SCHEMEH</code> environment variable to your platform-specific
location (default value is <code>/usr/local/lib/csv9.5.5.5/tarm64osx/</code>).
</p>
<div class="org-src-container">
<pre class="src src-shell">git clone https://github.com/ul/ad-libitum.git
<span style="font-weight: bold;">cd</span> ad-libitum
git submodule update --init --recursive --remote
make libs
</pre>
</div>
</div>
</div>
<div id="outline-container-orgb9f4620" class="outline-4">
<h4 id="orgb9f4620"><span class="section-number-4">1.4.2</span> Test</h4>
<div class="outline-text-4" id="text-1-4-2">
<p>
Fire up <code>scheme ad-libitum.ss</code> and play 440Hz tuner (beware of loud sound!
reduce speakers/headphones volume before running). Congratulations, you
livecoded your first Ad Libitum piece!
</p>
<div class="org-src-container">
<pre class="src src-scheme">~/ad-libitum> scheme ad-libitum.ss
Chez Scheme Version 9.5.1
Copyright 1984-2017 Cisco Systems, Inc.
> (play! tuner)
>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgad169ed" class="outline-4">
<h4 id="orgad169ed"><span class="section-number-4">1.4.3</span> Play</h4>
<div class="outline-text-4" id="text-1-4-3">
<p>
Run & <code>geiser-connect</code>
</p>
<div class="org-src-container">
<pre class="src src-shell">scheme --optimize-level 2 violet.ss
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="outline-container-orgeaf5b92" class="outline-2">
<h2 id="orgeaf5b92"><span class="section-number-2">2</span> Contribution</h2>
<div class="outline-text-2" id="text-2">
<p>
Contribution is more than welcome and highly appreciated! Any small or non-code
fix is valuable as well, including spelling and grammar and setting proper
licensing.
</p>
</div>
</div>
<div id="outline-container-org59a8a4c" class="outline-2">
<h2 id="org59a8a4c"><span class="section-number-2">3</span> Kernel</h2>
<div class="outline-text-2" id="text-3">
</div>
<div id="outline-container-orgb79f8fd" class="outline-3">
<h3 id="orgb79f8fd"><span class="section-number-3">3.1</span> Sound I/O</h3>
<div class="outline-text-3" id="text-3-1">
<p>
Ad Libitum relies on <code>chez-soundio</code> bindings and high-level wrapper. We are
going to create and open default i/o (only 'o' at the moment) stream and
provide it globally.
</p>
<p>
For performance reasons <code>chez-sound</code> itself doesn't provide any protection
against broken <code>write-callback</code>. But in livecoding mistakes are the part of
exploration and arguably we want to sacrifice some performance to be able to
not restart entire sound subsystem for fixing our <code>write-callback</code>. That's
why calling <code>*dsp*</code> is wrapped into <code>guard</code>.
</p>
<p>
To keep our scheduler clock in sync with audio we store audio time and return
it from <code>now</code> function which is passed to scheduler later.
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="org034ab78"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><sound></span>
(<span style="font-weight: bold;">define</span> <span style="font-weight: bold;">*time*</span> 0.0)
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">now</span>) *time*)
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">silence</span> time channel) 0.0)
(<span style="font-weight: bold;">define</span> <span style="font-weight: bold;">*dsp*</span> silence)
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">set-dsp!</span> f) (set! *dsp* f))
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">hush!</span>) (set-dsp! silence))
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">write-callback</span> time channel)
(set! *time* time)
(<span style="font-weight: bold;">guard</span> (_ [else 0.0])
(*dsp* time channel)))
(<span style="font-weight: bold;">define</span> <span style="font-weight: bold;">*sound-out*</span> (soundio:open-default-out-stream write-callback))
(<span style="font-weight: bold;">define</span> <span style="font-weight: bold;">*sample-rate*</span> (soundio:sample-rate *sound-out*))
(<span style="font-weight: bold;">define</span> <span style="font-weight: bold;">*channels*</span> (soundio:channel-count *sound-out*))
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">start</span>) (soundio:start-out-stream *sound-out*))
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">stop</span>) (soundio:stop-out-stream *sound-out*))
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></sound></span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgd311c09" class="outline-3">
<h3 id="orgd311c09"><span class="section-number-3">3.2</span> Scheduler</h3>
<div class="outline-text-3" id="text-3-2">
<p>
Much of music is about time. Before we produce any single sample of wave, we
want to control when to start and when to stop doing it. Much of live coding
is about decoupling our commands from their execution. We want to say "play
note a second later" now, but play it a second later. It's where scheduler
comes to play. Essentially, scheduler's API is simple and allows to get
current time mark (whatever it means: system clock, time elapsed from
scheduler start or number of rendered samples) and to callback procedure at
some point of time with more or less guaranteed skew limit.
</p>
<p>
Let's start with scheduler interface. As has been said there are two basic
functions it must provide, <code>now</code> and <code>schedule</code>. First one allows to get
current point in time, and it is usually comes to schedule from external
source like audio stream to be in sync with it. Second one allows to schedule
execution at some point in future.
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="org360784b"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><scheduler-interface></span>
<span style="font-weight: bold; text-decoration: underline;"><<now>></span>
<span style="font-weight: bold; text-decoration: underline;"><<schedule>></span>
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></scheduler-interface></span>
</pre>
</div>
<p>
As far as scheduler is stateful and even involves thread creation, it must
have two other basic methods:
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="org1a7e54e"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><scheduler-interface></span>
<span style="font-weight: bold; text-decoration: underline;"><<start-scheduler>></span>
<span style="font-weight: bold; text-decoration: underline;"><<stop-scheduler>></span>
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></scheduler-interface></span>
</pre>
</div>
<p>
Let's shape scheduler's data. Obviously, <code>now</code> appears here, in form of either
scheduler's own counter or function (which will get system time or related
write thread sample number). Another thing is <code>queue</code>, where <code>schedule</code> will
store callbacks. Because queuing could happen from different threads at the
same time, as well as dequeuing inside scheduler could happen together with
queuing from another thread, we need to protect it with <code>mutex</code>. We also need
<code>thread</code> id or flag or whatever used to control thread exit, because Scheme
doesn't expose <code>pthread_kill</code>. And the last one which comes to the mind at the
moment is <code>resolution</code> as a number of times per second scheduler checks the
<code>queue</code> for expired events.
</p>
<p>
Together with record definition we provide <code>simple-scheduler</code> which creates
schedule with reasonable default parameters. The only thing it accepts is
<code>now</code>, because usually you want you schedule to be in sync with external
clock.
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="org97e9a1d"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><scheduler-record></span>
(<span style="font-weight: bold;">define-record-type</span> scheduler
(fields now (mutable queue) resolution (mutable thread) mutex))
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">simple-scheduler</span> now)
(make-scheduler
now <span style="font-weight: bold; font-style: italic;">; </span><span style="font-weight: bold; font-style: italic;">now</span>
heap/empty <span style="font-weight: bold; font-style: italic;">; </span><span style="font-weight: bold; font-style: italic;">queue</span>
250 <span style="font-weight: bold; font-style: italic;">; </span><span style="font-weight: bold; font-style: italic;">resolution</span>
#f <span style="font-weight: bold; font-style: italic;">; </span><span style="font-weight: bold; font-style: italic;">thread</span>
(make-mutex) <span style="font-weight: bold; font-style: italic;">; </span><span style="font-weight: bold; font-style: italic;">mutex</span>
))
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></scheduler-record></span>
</pre>
</div>
<p>
Let's implement scheduler interface.
</p>
<p>
<code>now</code> then would just call <code>now</code> field:
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="org6048cb2"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><now></span>
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">now</span> scheduler) ((scheduler-now scheduler)))
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></now></span>
</pre>
</div>
<p>
Event queue accepts events which must have <code>f</code> with its
<code>args</code> to execute at <code>time</code>:
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="org187760b"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><event-record></span>
(<span style="font-weight: bold;">define-record-type</span> event
(fields time f args))
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></event-record></span>
</pre>
</div>
<p>
For <code>queue</code> we need some heap implementation, I'm going to jump into <a href="#orgd112e7d">3.2.1</a>!
</p>
<p>
Mutex is used to prevent data race on insert and remove from queue happening
in different threads.
</p>
<p>
<code>schedule</code> should accept either <code>event</code> record, or its fields (and create
record by itself) to unclutter user code.
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="org17a53cd"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><schedule></span>
(<span style="font-weight: bold;">define</span> <span style="font-weight: bold;">schedule</span>
(<span style="font-weight: bold;">case-lambda</span>
[(scheduler event)
(with-mutex (scheduler-mutex scheduler)
(scheduler-queue-set! scheduler (heap/insert event-time event (scheduler-queue scheduler))))]
[(scheduler t f . args)
(schedule scheduler (make-event (inexact t) f args))]))
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></schedule></span>
</pre>
</div>
<p>
Processing events is just executing any expired events' functions and removing
them from the queue.
</p>
<p>
To enable dynamic temporal recursion we support event's <code>f</code> to be a symbol
referring top level function.
</p>
<p>
Of course, live events are error prone, but we don't want flawed event to blow
entire thread. Thus <code>f</code> execution is secured with <code>guard</code>.
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="orgefc1c8b"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><scheduler-process-events></span>
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">process-events</span> scheduler time)
(with-mutex
(scheduler-mutex scheduler)
(<span style="font-weight: bold;">let</span> <span style="font-weight: bold;">next-event</span> ()
(<span style="font-weight: bold;">let</span> ([event (heap/find-min (scheduler-queue scheduler))])
(<span style="font-weight: bold;">when</span> (<span style="font-weight: bold;">and</span> event (<= (event-time event) time))
(scheduler-queue-set!
scheduler
(heap/delete-min event-time (scheduler-queue scheduler)))
(<span style="font-weight: bold;">guard</span> (_ [else #f])
(<span style="font-weight: bold;">let</span> ([f (event-f event)])
(apply (<span style="font-weight: bold;">if</span> (symbol? f)
(top-level-value f)
f)
(event-args event))))
(next-event))))))
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></scheduler-process-events></span>
</pre>
</div>
<p>
Now it's a time for start/stop thread. Stopping thread would be just setting a
flag which I used to call "poison pill".
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="org508b692"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><stop-scheduler></span>
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">stop-scheduler</span> scheduler)
(scheduler-thread-set! scheduler #f))
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></stop-scheduler></span>
</pre>
</div>
<p>
Starting thread will fork and loop calling expired events. We set expire
period for a half of resolution period in future to compensate a little bit
that events could expire during <code>process-events</code>. Proper adjustment require
further investigation taking in account that audio clock is not uniform (it
moves fast inside filling audio buffer process then waits to buffer to be
available again).
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="orgee84bde"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><start-scheduler></span>
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">start-scheduler</span> scheduler)
(fork-thread
(<span style="font-weight: bold;">lambda</span> ()
(scheduler-thread-set! scheduler (get-thread-id))
(<span style="font-weight: bold;">let*</span> ([resolution (scheduler-resolution scheduler)]
[expired-horizon (/ 0.5 resolution)]
[microseconds-to-sleep (exact (floor (/ 1e6 resolution)))])
(<span style="font-weight: bold;">let</span> <span style="font-weight: bold;">loop</span> ()
(<span style="font-weight: bold;">when</span> (scheduler-thread scheduler)
(process-events scheduler (+ (now scheduler) expired-horizon))
(usleep 0 microseconds-to-sleep)
(loop)))))))
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></start-scheduler></span>
</pre>
</div>
<div class="org-src-container">
<pre class="src src-scheme" id="org29a49b9"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><scheduler></span>
<span style="font-weight: bold; text-decoration: underline;"><<scheduler-record>></span>
<span style="font-weight: bold; text-decoration: underline;"><<event-record>></span>
<span style="font-weight: bold; text-decoration: underline;"><<scheduler-process-events>></span>
<span style="font-weight: bold; text-decoration: underline;"><<scheduler-interface>></span>
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></scheduler></span>
</pre>
</div>
<p>
We need just a simple default scheduler at hand for Ad Libitum needs:
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="org525c2fd">(<span style="font-weight: bold;">define</span> <span style="font-weight: bold;">*scheduler*</span> #f)
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">init</span> now) (set! *scheduler* (simple-scheduler now)))
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">start</span>) (start-scheduler *scheduler*))
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">stop</span>) (stop-scheduler *scheduler*))
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">*schedule*</span> t f . args) (schedule *scheduler* (make-event t f args)))
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">*now*</span>) (now *scheduler*))
</pre>
</div>
</div>
<div id="outline-container-orgd112e7d" class="outline-4">
<h4 id="orgd112e7d"><span class="section-number-4">3.2.1</span> Pairing Heap</h4>
<div class="outline-text-4" id="text-3-2-1">
<p>
Wikipedia's type definition for pairing heap structure looks like Scheme's
pairs (surprise =) ). Using them implementation is quite straightforward.
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="orgf3d5ad9"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><pairing-heap></span>
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;">we do some #f-punning and don't throw on empty heaps</span>
(<span style="font-weight: bold;">define</span> <span style="font-weight: bold;">heap/empty</span> '())
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">heap/find-min</span> heap)
(<span style="font-weight: bold;">if</span> (null? heap)
#f
(car heap)))
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">heap/merge</span> comparator h1 h2)
(<span style="font-weight: bold;">cond</span>
[(null? h1) h2]
[(null? h2) h1]
[(< (comparator (car h1)) (comparator (car h2)))
(cons (car h1) (cons h2 (cdr h1)))]
[else
(cons (car h2) (cons h1 (cdr h2)))]))
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">heap/insert</span> comparator elem heap)
(heap/merge comparator (cons elem '()) heap))
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">heap/merge-pairs</span> comparator subheaps)
(<span style="font-weight: bold;">cond</span>
[(null? subheaps) heap/empty]
[(null? (cdr subheaps)) (car subheaps)]
[else (heap/merge comparator
(heap/merge comparator (car subheaps) (cadr subheaps))
(heap/merge-pairs comparator (cddr subheaps)))]))
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">heap/delete-min</span> comparator heap)
(<span style="font-weight: bold;">if</span> (null? heap)
heap/empty
(heap/merge-pairs comparator (cdr heap))))
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></pairing-heap></span>
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-org5d93302" class="outline-3">
<h3 id="org5d93302"><span class="section-number-3">3.3</span> Remote REPL</h3>
<div class="outline-text-3" id="text-3-3">
<p>
NB. REPL is currently disabled as sockets library doesn't work on M1.
To enable it back uncomment <code>(repl:start-repl-server)</code> in <code>ad-libitum-init</code>.
</p>
<p>
We need own repl server because music doesn't work in geiser repl for
somewhat reason. The most universal solution would be to have REPL over
either UDP or TCP with the simplest possible protocol. We want it to be just
a carrier, everything else should happen inside editor and engine. Sadly Chez
Scheme has no sockets in its std lib. We are gonna try Aaron W. Hsu's
<a href="https://github.com/arcfide/chez-sockets">chez-sockets</a> library.
</p>
<p>
Actually, we are still able to use Geiser with our REPL server because it
supports remote REPL. See "Connecting to an external Scheme" at <a href="http://www.nongnu.org/geiser/geiser_3.html#The-REPL">docs</a>. The
only thing required for it is to load <code>scheme/chez/geiser/geiser.ss</code> into the
REPL thread.
</p>
<p>
First, let's create a TCP socket. Here we rely on assumption, that default
protocol is TCP.
</p>
</div>
<div id="outline-container-org6c1f1b3" class="outline-4">
<h4 id="org6c1f1b3"><span class="section-number-4">3.3.1</span> <span class="todo TODO">TODO</span> Ensure that protocol is TCP</h4>
</div>
<div id="outline-container-org481e5de" class="outline-4">
<h4 id="org481e5de"><span class="section-number-4">3.3.2</span> Blocking vs Async sockets</h4>
<div class="outline-text-4" id="text-3-3-2">
<p>
Though Aaron doesn't recommend using blocking sockets, they are so much
easier for our case! No need to implement polling when waiting for
connection or receiving value.
</p>
<p>
Tried blocking sockets. They work fine by themselves, but play bad with
<code>sleep</code> called from other threads! Falling back to async sockets and polling
then.
</p>
</div>
</div>
<div id="outline-container-org4b9a40d" class="outline-4">
<h4 id="org4b9a40d"><span class="section-number-4">3.3.3</span> Open socket</h4>
<div class="outline-text-4" id="text-3-3-3">
<div class="org-src-container">
<pre class="src src-scheme" id="orgc2bdb05"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><open-socket></span>
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">open-socket</span>)
(<span style="font-weight: bold;">let</span> ([socket (sock:create-socket
sock:socket-domain/internet
sock:socket-type/stream
sock:socket-protocol/auto)])
<span style="font-weight: bold; text-decoration: underline;"><<bind-socket>></span>
<span style="font-weight: bold; text-decoration: underline;"><<listen-socket>></span>
socket
))
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></open-socket></span>
</pre>
</div>
<p>
Then we are going to listen address and port for input. We'll make it
configurable later, let's provide some sensible hardcoded defaults for now.
<i>localhost</i> is for security reasons, and <i>37146</i> is default Geiser port.
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="org833e011"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><bind-socket></span>
(sock:bind-socket socket (sock:string->internet-address <span style="font-style: italic;">"127.0.0.1:37146"</span>))
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></bind-socket></span>
</pre>
</div>
<p>
And then let's listen for new connections!
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="orgdeb8006"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><listen-socket></span>
(sock:listen-socket socket 1024)
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></listen-socket></span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org3582e09" class="outline-4">
<h4 id="org3582e09"><span class="section-number-4">3.3.4</span> Accept connections</h4>
<div class="outline-text-4" id="text-3-3-4">
<p>
To actually accept new connections we are going to create new thread and
just run infinite loop with <code>accept-socket</code> inside. Remember, our socket is
non-blocking so we are to make polling to not eat all CPU by eager calls.
After accepting new connection we'll proceed it in new thread.
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="orge22f54e"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><accept-connections></span>
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">accept-connections</span> repl-server-socket)
(fork-thread
(<span style="font-weight: bold;">lambda</span> ()
(<span style="font-weight: bold;">let</span> <span style="font-weight: bold;">loop</span> ()
(usleep 0 polling-microseconds)
(<span style="font-weight: bold;">let-values</span> ([(socket address) (sock:accept-socket repl-server-socket)])
(<span style="font-weight: bold;">when</span> socket
(printf <span style="font-style: italic;">"New REPL @ ~s\r\n"</span> (sock:internet-address->string address))
(spawn-remote-repl socket address)))
(loop)))))
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></accept-connections></span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org934036f" class="outline-4">
<h4 id="org934036f"><span class="section-number-4">3.3.5</span> Spawn remote REPL</h4>
<div class="outline-text-4" id="text-3-3-5">
<p>
Every new connection accepted would spawn new thread with a REPL loop inside
it. Because we are using async sockets, we are forced to run actual loop and
poll socket for values. <i>50ms</i> should be a reasonable polling delay to keep
it responsive and not resource greedy at the same time. Also
<code>receive-from-socket</code> require to limit maximum message length. Here <i>65k</i> is
also is a kind of a guess. Chez Scheme operates UTF-8 strings and messages
are read as bytevectors from sockets, thus we need a transcoder to convert
them back and forth. Let's put all these requirements to values:
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="org3518c0b"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><spawn-remote-repl-options></span>
(<span style="font-weight: bold;">define</span> <span style="font-weight: bold;">polling-microseconds</span> 50000)
(<span style="font-weight: bold;">define</span> <span style="font-weight: bold;">max-chunk-length</span> 65536)
(<span style="font-weight: bold;">define</span> <span style="font-weight: bold;">code-tx</span> (make-transcoder (utf-8-codec) (eol-style lf) (error-handling-mode replace)))
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></spawn-remote-repl-options></span>
</pre>
</div>
<p>
Preparations are straightforward: define some helpers, send initial prompt,
and start loop.
</p>
<div class="org-src-container">
<pre class="src src-scheme" id="org7619b37"><span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"><spawn-remote-repl></span>
<span style="font-weight: bold; text-decoration: underline;"><<spawn-remote-repl-options>></span>
(<span style="font-weight: bold;">define</span> (<span style="font-weight: bold;">spawn-remote-repl</span> socket address)
(fork-thread
(<span style="font-weight: bold;">lambda</span> ()
(<span style="font-weight: bold;">let*</span> (
<span style="font-weight: bold; text-decoration: underline;"><<repl-send-helpers>></span>
)
(send-prompt)
<span style="font-weight: bold; text-decoration: underline;"><<repl-loop>></span>
))))
<span style="font-weight: bold; font-style: italic;">;; </span><span style="font-weight: bold; font-style: italic;"></spawn-remote-repl></span>
</pre>
</div>
<p>
Converting messages to bytevectors and sending to proper port is quite
tedious, let's write a couple of helpers:
</p>