README.md 21.6 KB
Newer Older
1
## Pd-L2Ork
pokergaming's avatar
pokergaming committed
2

Jonathan Wilkes's avatar
Jonathan Wilkes committed
3
maintainer: Ivica Ico Bukvic <ico@vt.edu>
pokergaming's avatar
pokergaming committed
4

Jonathan Wilkes's avatar
Jonathan Wilkes committed
5
6
maintainer: Albert Graef <aggraef@gmail.com>

pokergaming's avatar
pokergaming committed
7
8
maintainer: Jonathan Wilkes <jancsika@yahoo.com>

9
10
11
12
13
* [One Paragraph Overview](#one-paragraph-overview)
* [Flavors of Pure Data](#flavors-of-pure-data)
* [Three Paragraph Overview](#three-paragraph-overview)
* [Goals](#goals)
* [Installation Guide](#installation-guide)
Jonathan Wilkes's avatar
Jonathan Wilkes committed
14
* [Code of Conduct](#code-of-conduct)
15
* [Contributor Guide](#contributor-guide)
Jonathan Wilkes's avatar
Jonathan Wilkes committed
16
* [Human Interface Guidelines](#human-interface-guidelines)
17
* [Core Pd Notes](#core-pd-notes)
Jonathan Wilkes's avatar
Jonathan Wilkes committed
18
* [GUI Message Spec](#gui-messaging-specification)
Jonathan Wilkes's avatar
Jonathan Wilkes committed
19

pokergaming's avatar
pokergaming committed
20
### One Paragraph Overview
pokergaming's avatar
pokergaming committed
21

Jonathan Wilkes's avatar
Jonathan Wilkes committed
22
Pure Data (aka Pd) is a visual programming language.  That means you can use it to
pokergaming's avatar
pokergaming committed
23
create software graphically by drawing diagrams instead of writing lines of
Jonathan Wilkes's avatar
Jonathan Wilkes committed
24
code.  These diagrams show how data flows through the software, displaying on
pokergaming's avatar
pokergaming committed
25
26
the screen what text-based languages require you to piece together in your mind.

Jonathan Wilkes's avatar
Jonathan Wilkes committed
27
### Flavors of Pure Data
pokergaming's avatar
pokergaming committed
28
29

There are currently three main distributions of Pure Data:
pokergaming's avatar
pokergaming committed
30

31
32
1. Pd-L2Ork.  Version used by Ivica Bukvic for his laptop orchestra.  This
   guide is for Pd-L2Ork.
pokergaming's avatar
pokergaming committed
33
34
35
36
2. Pure Data "Vanilla".  Miller Puckette's personal version which he hosts on
   his website and maintains.  It doesn't include external libraries like
   objects for doing graphics, video, etc.
2. Pure Data Extended.  A monolithic distribution which ships with lots of
Jonathan Wilkes's avatar
Jonathan Wilkes committed
37
   external libraries.  As of August 2015 it hasn't been updated since January 2014.
pokergaming's avatar
pokergaming committed
38
39

### Three Paragraph Overview
pokergaming's avatar
pokergaming committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

Pd has been designed with an emphasis on generating sound, video,
2D/3D graphics, and connecting through sensors, input devices, and MIDI as well
as OSC devices.

Pd has a special emphasis on generating audio and/or video in real time, with
low latency.  Much of its design focuses on receiving, manipulating, and
delivering high-quality audio signals.  Specifically, the software addresses
the problem of how to do this efficiently and reliably on general purpose
operating systems like OSX, Windows, Debian, etc.-- i.e., systems designed
mainly for multi-tasking.

Pd can easily work over local and remote networks.  It can be used to integrate
wearable technology, motor systems, lighting rigs, and other equipment. Pd is
also suitable for learning basic multimedia processing and visual programming
methods, as well as for realizing complex systems for large-scale projects.

Jonathan Wilkes's avatar
Jonathan Wilkes committed
57
### Goals
pokergaming's avatar
pokergaming committed
58

59
Pd-L2ork has the following goals:
pokergaming's avatar
pokergaming committed
60

pokergaming's avatar
pokergaming committed
61
62
1. Documentation.  We like documentation.  It's like code, except friendly.
2. Be reliable.  Binary releases must be usable for performances and
pokergaming's avatar
pokergaming committed
63
64
   installations.  The git repo must always be in a workable state that can be
   compiled.  Regressions must be fixed quickly.
pokergaming's avatar
pokergaming committed
65
3. Be discoverable.  Undocumented features are buggy.  Missing help files are
pokergaming's avatar
pokergaming committed
66
   bugs.  Patches for new functionality that lack documentation are spam.
pokergaming's avatar
pokergaming committed
67
4. Be consistent.  Consistent interfaces are themselves a kind of
pokergaming's avatar
pokergaming committed
68
   documentation.  We like documentation, so it follows that we like consistent
69
   interfaces
pokergaming's avatar
pokergaming committed
70

Jonathan Wilkes's avatar
Jonathan Wilkes committed
71
### Installation Guide
72
73

#### Linux
74
Time to build: *40 minutes to 1.5 hours*
pokergaming's avatar
pokergaming committed
75
76
77
78
79
80
81
82
83
84
To install using a pre-compiled binary, follow these instructions:
http://l2ork.music.vt.edu/main/?page_id=56

To set up a development environment, first make sure you have the following
package dependencies listed here:
http://l2ork.music.vt.edu/main/?page_id=56

Then follow the steps outlined here:
http://l2ork.music.vt.edu/main/?page_id=56#install-dev

85
#### OSX
86
Homebrew build (supported) *40 minutes to 1.5 hours*
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
1. Install [Homebrew](http://brew.sh) *(15 minutes)*
   (asks for password twice-- once for command line tools, once for homebrew)
2. Install the dependencies *10 minutes*:<code>
   brew install wget
   brew install autoconf
   brew install automake
   brew install libtool
   brew install fftw
   brew install python
   brew install fluidsynth
   brew install lame
   brew install libvorbis
   brew install speex
   brew install gsl
   brew install libquicktime
   brew install pkg-config
</code>
3. git clone https://git.purrdata.net/jwilkes/purr-data.git
4. Change to the directory<code>
cd purr-data/l2ork_addons</code>
5. Run the installer<code>
108
./tar_em_up.sh -X *15 minutes*</code>
109
110
111
112
6. When the installer finishes, there should be a dmg file in<code>
purr-data/packages/darwin_app</code>

Macports build (unsupported, unfinished)
113
114
115
116
117
118
119
120
121
122
123
124
Time to build: *1 day*

1. Install Xcode from the Mac App Store. *1.5 hours*
2. Install Xcode command line tools in a terminal window *4 minutes*:<code>
   xcode-select --install</code>
3. Agree to the Xcode license in a terminal
   window:<code>sudo xcodebuild -license</code>
3. Install [MacPorts](https://www.macports.org) *12 minutes*
4. Check for updates:<code>sudo port selfupdate</code>
5. Install the dependencies *6 minutes*:<code>
   sudo port install wget
   sudo port install autoconf
125
126
127
128
129
130
131
132
133
   sudo port install automake
   sudo port install libtool
   sudo port install fftw-3
   sudo port install fftw-3-single
   sudo port install python27
   sudo port install fluidsynth
   sudo port install lame
   sudo port install speex
   sudo port install gsl
134
   sudo port install libquicktime-devel
135
</code>
136
137
138
139
6. Download the source code *(3-6 minutes)*
   Issue the following command to create a new directory "purr-data" and clone
   the repository to it:<code>
git clone https://git.purrdata.net/jwilkes/purr-data.git</code>
140
141
142
143
144
145
146
147
148
149
150
7. ...
8. Set the environment variables on the command line:<code>
   export CPATH=/opt/local/include
   export LIBRARY_PATH=/opt/local/lib</code>
9. In externals/Makefile, remove the following libraries from from LIB_TARGETS:
   * plugin
   * hid
   * pdp
   * gem2pdp
10. In packages/darwin_app/Makefile, remove rez_install from build instructions
11. In packages/darwin_app/Makefile, comment out installation of libquicktime
151
152
153
12. Run `make install`
13. In the app in the "build" directory, find the en.lproj/InfoPlist.strings
    and change the CFBundleDisplayName and CFBundleName to "purr-data"
154
155
14. Note: the script `embed-MacOSX-dependencies.sh` doesn't work with
    macports paths.
156

157
#### Windows 32-bit Using msys2
158
Time to build: *roughly 1.5 hours-- 30 minutes of this is for Gem alone*
Jonathan Wilkes's avatar
Jonathan Wilkes committed
159

160
161
162
163
Important note: check the name of your Windows user account. If it has a space
in it-- like "My Home Computer" or "2nd Laptop", then **stop**. You may not
use this guide.  (Actually you can probably just install everything in ~/.. in
that case, but I haven't tested doing it like that. Sorry. Get a better OS...)
Jonathan Wilkes's avatar
Jonathan Wilkes committed
164
165
166
167
168
1. Download and install [msys2](https://msys2.github.io/) *(5 minutes)*  
  There are two installers-- one for 32-bit Windows systems (i386) and one for
  64-bit Windows (x_64). Be sure you know which
  [version](http://windows.microsoft.com/en-us/windows/32-bit-and-64-bit-windows#1TC=windows-7)
  of Windows you are running and download the appropriate installer.  
169
170
171
172
  Note: don't run it after it installs. You'll open it manually in the next
  step.
2. Download and install [inno setup](http://www.jrsoftware.org/isdl.php) *(5 minutes)*
3. Run MinGW-w64 Win32 Shell *(less than a minute)*  
Jonathan Wilkes's avatar
Jonathan Wilkes committed
173
   msys2 adds three Start Menu items for different "flavors" of shell:  
Jonathan Wilkes's avatar
Jonathan Wilkes committed
174
   + MinGW-w64 __Win32__ Shell <- click this one!
Jonathan Wilkes's avatar
Jonathan Wilkes committed
175
   + MinGW-w64 Win64 Shell
Jonathan Wilkes's avatar
Jonathan Wilkes committed
176
   + MSYS Shell
177
4. Install the dependencies *(5-10 minutes)*  
Jonathan Wilkes's avatar
Jonathan Wilkes committed
178
179
   Once the shell opens, we need to install the dependencies for building
   Purr Data. Issue the following command:<code>
180
181
pacman -S autoconf automake git libtool \
          make mingw-w64-i686-dlfcn mingw-w64-i686-fftw \
182
          mingw-w64-i686-fluidsynth \
183
          mingw-w64-i686-ftgl mingw-w64-i686-fribidi \
184
185
          mingw-w64-i686-ladspa-sdk mingw-w64-i686-lame \
          mingw-w64-i686-libsndfile mingw-w64-i686-libvorbis \
186
          mingw-w64-i686-lua mingw-w64-i686-toolchain \
187
          rsync unzip wget</code>
188
5. Download the source code *(3-6 minutes)*
Jonathan Wilkes's avatar
Jonathan Wilkes committed
189
190
   Issue the following command to create a new directory "purr-data" and clone
   the repository to it:<code>
191
git clone https://git.purrdata.net/jwilkes/purr-data.git</code>
192
6. Enter the purr-data/l2ork_addons directory *(less than a minute)*<code>
193
cd purr-data/l2ork_addons</code>
194
7. Finally, build Purr-Data *(45-80 minutes)*<code>
195
./tar_em_up.sh -Z</code>
196
8. Look in purr-data/packages/win32_inno/Output and click the setup file to
197
   start installing Purr Data to your machine.
198

199
200
### Code of Conduct

201
1. No sarcasm, please
202
2. Don't appear to lack empathy
Jonathan Wilkes's avatar
Jonathan Wilkes committed
203
204
205
206
207
208
209
210
3. You can't live here. If you're spending hours a day writing Purr Data
   code or-- worse-- spending hours a day *writing emails about* code that 
   has yet to be written, you're doing it wrong
4. If working on something for the first time, ask to be mentored
5. If no one asked you to mentor them, don't teach
6. It is better to let small things go then to risk taking time away from
   solving bigger problems

Jonathan Wilkes's avatar
Jonathan Wilkes committed
211
212
It is a bad idea to break this Code of Conduct *even if* no one complains
about your behavior.
213

Jonathan Wilkes's avatar
Jonathan Wilkes committed
214
### Contributor Guide
pokergaming's avatar
pokergaming committed
215

pokergaming's avatar
pokergaming committed
216
Contributing is easy:
pokergaming's avatar
pokergaming committed
217

pokergaming's avatar
pokergaming committed
218
219
220
221
222
223
224
225
226
1. Join the development list:
   http://disis.music.vt.edu/cgi-bin/mailman/listinfo/l2ork-dev
2. Tell us what you'd like to work on.  Unfortunately there are _lots_ of
   externals and even core features that are poorly documented.  We can help 
   make sure you aren't duplicating functionality (or that you at least know
   what's already been implemented).
3. Send us your patch and we'll try it out.  If it's well-documented and
   there aren't any bugs we'll add it to the software.
4. If you want to do regular development and have commit access, just request
227
   it, then follow the Pd-L2Ork goals above.
pokergaming's avatar
pokergaming committed
228

pokergaming's avatar
pokergaming committed
229
230
231
Here are some of the current tasks:

* writing small audio/visual Pd games or demos to include in the next release
pokergaming's avatar
pokergaming committed
232
  * skills needed: ability to write Pd programs
pokergaming's avatar
pokergaming committed
233
  * status: I wrote a little sprite-based game that will ship with the next
234
    version of Pd-L2Ork.  In it, the character walks around in an actual
pokergaming's avatar
pokergaming committed
235
236
237
238
239
    Pd diagram shoots at the objects to progress, and to make realtime
    changes to the music.
    What I'd like is to include a new, smallish game with each release
    that has a link in the Pd console.  It can be a little demo or game,
    just something fun that shows off what can be done using Pure Data.
pokergaming's avatar
pokergaming committed
240
* designing/implementing regression test template
pokergaming's avatar
pokergaming committed
241
  * skills needed: knowledge about... regression tests. :)  But also some
pokergaming's avatar
pokergaming committed
242
243
244
245
246
247
248
249
250
251
252
253
254
    expertise in using Pd so that the tests themselves can
    be written in Pure Data.  At the same time, they should
    be able to be run as part of the automated packaging
    process (i.e., in -nogui mode).
  * status: some externals have their own testing environments, but they are
    limited as they require manual intervention to run and read the
    results inside a graphical window.
    Here's an email thread with Katja Vetter's design, which looks to
    be automatable:
    http://markmail.org/message/t7yitfc55anus76i#query:+page:1+mid:chb56ve7kea2qumn+state:results
    And Mathieu Bouchard's "pure unity" (not sure if this is the most
    recent link...):
    http://sourceforge.net/p/pure-data/svn/HEAD/tree/tags/externals/pureunity/pureunity-0.0/
pokergaming's avatar
pokergaming committed
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
### Human Interface Guidelines

#### General Look and Feel

Pd is a multi-window application that consists of three parts:

1. A main window, called the "Pd Window" or "Console Window". This window
   displays informational and error messages for Pd programs.
2. One or more "canvas" windows-- aka "patch" windows, used to display the
   diagrams that make up a Pd program.
3. One or more dialog windows used to configure the various parts of Pd.

All should look simple and uncluttered. Although "canvas" windows cannot
(yet) be traversed and edited using only the keyboard, all three parts of Pd
should be designed so that they can be manipulated using only the keyboard.

### Hooks for new users
It should also be possible to produce sound and interact when a new user runs
program for the very first time. In every release, there should be a link at
the bottom of the Console Window to a short game written in Pd that demonstrates
one or more of the capabilities of the Pd environment. The game should be
designed to be fun outside of its efficacy as a demonstration of Pd.

#### Fonts
Pd ships with "DejaVu Sans Mono", which is used for the text in canvas windows.
Fonts are sized to fit the hard-coded constraints in Pd Vanilla. This way box
sizes will match as closely as possible across distributions and OSes.

These hard-coded sizes are maximum character widths and heights. No font
fits these maximums exactly, so it's currently impossible to tell when looking
at a Pd canvas whether the objects will collide on a system using a different
font (or even a different font-rendering engine).

Dialogs and console button labels may use variable-width fonts. There is not
yet a suggested default to use for these.

The console printout area currently uses "DejaVu Sans Mono". Errors are printed
as a link so that the user can click them to highlight the corresponded canvas
or object that triggered the error.

#### Colors

Nothing set in stone yet.

Jonathan Wilkes's avatar
Jonathan Wilkes committed
300
### Core Pd Notes
pokergaming's avatar
pokergaming committed
301

pokergaming's avatar
pokergaming committed
302
303
The following is adapted from Pd Vanilla's original source notes.  (Found
in pd/src/CHANGELOG.txt for some reason...)
pokergaming's avatar
pokergaming committed
304
305
306
307

Sections 2-3 below are quite old.  Someone needs to check whether they even
hold true for Pd Vanilla any more.

pokergaming's avatar
pokergaming committed
308
309
310
#### Structure definition roadmap.

First, the containment tree of things
pokergaming's avatar
pokergaming committed
311
312
313
314
that can be sent messages ("pure data").  (note that t_object and t_text,
and t_graph and t_canvas, should be unified...)

BEFORE 0.35:
pokergaming's avatar
pokergaming committed
315

pokergaming's avatar
pokergaming committed
316
317
318
319
320
321
322
323
    m_pd.h	    t_pd    	    	    anything with a class
                    t_gobj	    	    "graphic object"
                        t_text  	    text object
    g_canvas.h  
                        t_glist 	    list of graphic objects
    g_canvas.c  	    	t_canvas    Pd "document"

AFTER 0.35:
pokergaming's avatar
pokergaming committed
324

pokergaming's avatar
pokergaming committed
325
326
327
328
329
330
    m_pd.h	    t_pd    	    	    anything with a class
                    t_gobj	    	    "graphic object"
                        t_text  	    patchable object, AKA t_object
    g_canvas.h     	    	t_glist     list of graphic objects, AKA t_canvas

Other structures:
pokergaming's avatar
pokergaming committed
331
332
333
334
335
336
337

    g_canvas.h  t_selection -- linked list of gobjs
                t_editor -- editor state, allocated for visible glists
    m_imp.h     t_methodentry -- method handler
                t_widgetbehavior -- class-dependent editing behavior for gobjs
                t_parentwidgetbehavior -- objects' behavior on parent window
                t_class -- method definitions, instance size, flags, etc.
pokergaming's avatar
pokergaming committed
338

pokergaming's avatar
pokergaming committed
339
#### 1. Coding Style
pokergaming's avatar
pokergaming committed
340

pokergaming's avatar
pokergaming committed
341
1.0  C coding style.  The source should pass most "warnings" of C compilers
pokergaming's avatar
pokergaming committed
342
343
344
345
346
347
(-Wall on linux, for instance; see the makefile.)  Some informalities
are intentional, for instance the loose use of function prototypes (see
below) and uncast conversions from longer to shorter numerical formats.
The code doesn't respect "const" yet.

1.1.  Prefixes in structure elements.  The names of structure elements always
348
have a K&R-style prefix, as in `((t_atom)x)->a_type`, where the `a_` prefix
pokergaming's avatar
pokergaming committed
349
indicates "atom."  This is intended to enhance readability (although the
350
351
352
353
354
355
356
357
358
359
360
361
convention arose from a limitation of early C compilers.)  Common prefixes are:
  * `w_` (word)
  * `a_` (atom)
  * `s_` (symbol)
  * `ob_` (object)
  * `te_` (text object)
  * `g_` (graphical object)
  * `gl_` (glist, a list of graphical objects).

Also, global symbols sometimes get prefixes, as in `s_float` (the symbol whose
string is "float").  Typedefs are prefixed by `t_`.  Most _private_ structures,
i.e., structures whose definitions appear in a ".c" file, are prefixed by `x_`.
pokergaming's avatar
pokergaming committed
362
363

1.2.   Function arguments.  Many functions take as their first
364
365
366
argument a pointer named `x`, which is a pointer to a structure suggested
by the function prefix; e.g., `canvas_dirty(x, n)` where `x` points to a canvas
`(t_canvas *x)`.
pokergaming's avatar
pokergaming committed
367
368
369
370
371
372
373
374
375
376
377
378
379

1.3.  Function Prototypes.  Functions which are used in at least two different
files (besides where they originate) are prototyped in the appropriate include
file. Functions which are provided in one file and used in one other are
prototyped right where they are used.  This is just to keep the size of the
".h" files down for readability's sake.

1.4.  Whacko private terminology.  Some terms are lifted from other historically
relevant programs, notably "ugen" (which is just a tilde object; see d_ugen.c.)

1.5.  Spacing.  Tabs are 8 spaces; indentation is 4 spaces.  Indenting
curly brackets are by themselves on their own lines, as in:

Jonathan Wilkes's avatar
Jonathan Wilkes committed
380
381
382
383
384
385
```c
if (x)
{
    x = 0;
}
```
pokergaming's avatar
pokergaming committed
386
387
388

Lines should fit within 80 spaces.

pokergaming's avatar
pokergaming committed
389
390
391
#### 2. Compatibility with Max

2.0.  Max patch-level compatibility.  "Import" and "Export" functions are
pokergaming's avatar
pokergaming committed
392
393
394
395
396
397
398
provided which aspire to strict compatibility with 0.26 patches (ISPW version),
but which don't get anywhere close to that yet.  Where possible, features
appearing on the Mac will someday also be provided; for instance, the connect
message on the Mac offers segmented patch cords; these will devolve into
straight lines in Pd.  Many, many UI objects in Opcode Max will not appear in
Pd, at least at first.

pokergaming's avatar
pokergaming committed
399
400
401
#### 3. Source-level Compatibility with Max

3.0.  Compatibility with Max 0.26 "externs"-- source-level compatibility. Pd
pokergaming's avatar
pokergaming committed
402
403
404
405
406
407
408
409
410
objects follow the style of 0.26 objects as closely as possible, making
exceptions in cases where the 0.26 model is clearly deficient.  These are:

3.1.  Anything involving the MacIntosh "Handle" data type is changed to use
char * or void * instead.

3.2.  Pd passes true single-precision floating-point arguments to methods;
Max uses double.
Typedefs are provided:
411

pokergaming's avatar
pokergaming committed
412
413
414
415
416
417
418
419
420
421
    t_floatarg, t_intarg for arguments passed by the message system
    t_float, t_int for the "word" union (in atoms, for example.)

3.3.  Badly-named entities got name changes:

    w_long --> w_int (in the "union word" structure)

3.4.  Many library functions are renamed and have different arguments;
I hope to provide an include file to alias them when compiling Max externs.

pokergaming's avatar
pokergaming committed
422
423
424
#### 4. Function name prefixes

4.0.  Function name prefixes.
pokergaming's avatar
pokergaming committed
425
426
Many function names have prefixes which indicate what "package" they belong
to.  The exceptions are:
pokergaming's avatar
pokergaming committed
427

pokergaming's avatar
pokergaming committed
428
429
430
431
432
    typedmess, vmess, getfn, gensym (m_class.c)
    getbytes, freebytes, resizebytes (m_memory.c)
    post, error, bug (s_print.c)
which are all frequently called and which don't fit into simple categories.
Important packages are:
433

pokergaming's avatar
pokergaming committed
434
435
436
437
438
439
440
    (pd-gui:)   pdgui -- everything
    (pd:)	    pd -- functions common to all "pd" objects
                obj -- fuctions common to all "patchable" objects ala Max
                sys -- "system" level functions
                binbuf -- functions manipulating binbufs
                class -- functions manipulating classes
                (other) -- functions common to the named Pd class
pokergaming's avatar
pokergaming committed
441

pokergaming's avatar
pokergaming committed
442
443
444
#### 5. Source file prefixes

5.0. Source file prefixes. 
445

pokergaming's avatar
pokergaming committed
446
PD:
447

Jonathan Wilkes's avatar
Jonathan Wilkes committed
448
449
450
451
452
453
    s    system interface
    m    message system
    g    graphics stuff
    d    DSP objects
    x    control objects
    z    other
pokergaming's avatar
pokergaming committed
454
455

PD-GUI:
456

Jonathan Wilkes's avatar
Jonathan Wilkes committed
457
    gui    GUI front end
458
459
460
461
462
463

#### 6. Javascript style
1. Brackets on the same line as declaration or expression: `if (a) {`
2. Single line comments only: `//`
3. Use double-quotes for strings
4. Use underscores to separate words of function names and variables
Jonathan Wilkes's avatar
Jonathan Wilkes committed
464
465

### GUI Messaging Specification
Jonathan Wilkes's avatar
Jonathan Wilkes committed
466
#### Public GUI interface
Jonathan Wilkes's avatar
Jonathan Wilkes committed
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481

Purpose: a set of functions to communicate with the gui without putting
language-specific strings (like tcl) into the C code.  The new interface is a
step toward separating some (but not all) of the GUI logic out from the C code.
Of course the GUI can still be designed to parse and evaluate incoming messages
as commands.  But the idiosyncracies of the GUI toolkit can be limited to
either the GUI code itself or to a small set of modular wrappers around
sys_vgui.

The public interface consists of the following:

```c
gui_vmess(const char *msg, const char *format, ...);
```

482
where `const char *format` consists of zero or more of the following:
Jonathan Wilkes's avatar
Jonathan Wilkes committed
483

484
485
486
* f - floating point value (`t_float`)
* i - integer (`int`)
* s - c string (`char*	)
Jonathan Wilkes's avatar
Jonathan Wilkes committed
487
* x - hexadecimal integer value, with a precision of at least six digits.
488
      (hex value is preceded by an 'x', like `x123456`)
Jonathan Wilkes's avatar
Jonathan Wilkes committed
489
490
491
492
493

For some of Pd's internals like array visualization, the message length may
vary. For these _special_ cases, the following functions allow the developer
to iteratively build up a message to send to the GUI.

Jonathan Wilkes's avatar
Jonathan Wilkes committed
494
495
```c
gui_start_vmess(const char *msg, const char *format, ...);
Jonathan Wilkes's avatar
Jonathan Wilkes committed
496
497
498
499
500
501
gui_start_array();      // start an array
gui_f(t_float float);   // floating point array element (t_float)
gui_i(int int);         // integer array element (int)
gui_s(const char *str); // c string array element
gui_end_array();        // end an array
gui_end_vmess();        // terminate the message
Jonathan Wilkes's avatar
Jonathan Wilkes committed
502
503
504
505
506
507
508
509
510
511
512
513
```

The above will send a well-formed message to the GUI, where the number of array
elements are limited by the amount of memory available to the GUI. Because of
the complexity of this approach, it may _only_ be used when it is necessary to
send a variable length message to the GUI. (Some of the current code may
violate this rule, but that can be viewed as a bug which needs to get fixed.)

The array element functions gui_f, gui_i, and gui_s may only be used inside an
array.  Arrays may be nested, but this adds complexity and should be avoided if
possible.

Jonathan Wilkes's avatar
Jonathan Wilkes committed
514
#### Private Wrapper for Nw.js Port
Jonathan Wilkes's avatar
Jonathan Wilkes committed
515
516
517
518
519
520
521
522
523
524
525
526
527
528

The public functions above should fit any sensible message format.
Unfortunately, Pd's message format (FUDI) is too simplistic to handle arbitrary
c-strings and arrays, so it cannot be used here. (But if it happens to improve
in the future it should be trivial to make a wrapper for the public interface
above.)

The current wrapper was made with the assumption that there is a Javascript
Engine at the other end of the message. Messages consist of a selector,
followed by whitespace, followed by a comman-delimited list of valid Javascript
primitives (numbers, strings, and arrays). For the arrays, Javascript's array
notation is used. This is a highly idiosyncratic, quick-and-dirty approach.
But the point is that the idiosyncracy exists in a single file of the source
code, and can be easily made more modular (or replaced entirely by something
529
else) without affecting _any_ of the rest of the C code.