File: VSTPlugin-UGen-Reference.md

package info (click to toggle)
pd-vstplugin 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,008 kB
  • sloc: cpp: 22,794; lisp: 2,860; makefile: 37; sh: 26
file content (956 lines) | stat: -rw-r--r-- 27,263 bytes parent folder | download
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
# VSTPlugin v0.6.2 - UGen documentation

This document is meant for developers who want to interface with the VSTPlugin UGen from other programs or build their own client abstractions.

It describes the UGen structure (i.e. its inputs and outputs), the available OSC messages and the format in which larger data is exchanged between UGen and client(s).

Have a look at `VSTPlugin.sc` and `VSTPluginController.sc` in the *classes* folder for a reference implementation in Sclang.

# UGen Structure

### UGen inputs
| name         | rate  ||
| ------------ | ----- |-|
| flags        | ir    | creation flags (reserved for future use)       |
| blockSize    | ir    | desired block size or 0 (= Server block size)  |
| bypass       | ir/kr | bypass state                                   |
| numInputs    | ir    | number of audio input busses; can be 0         |
| inputBus...  |       | (optional) `<numInputs>` audio input busses    |
| numOutputs   | ir    | number of audio output busses; can be 0        |
| outputBus... |       | (optional) `<numOutputs>` audio output busses  |
| numParamCtls | ir    | number of parameter controls; can be 0         |
| paramCtl...  |       | (optional) `<numParamCtls>` parameter controls |

*inputBus*

The number of channels (`ir`), followed by the actual channel inputs (`ar`).
Example: `2, <ch1>, <ch2>`.

*outputBus*

The number of channels (`ir`).

*paramCtl*

A pair of `<index, value>`.

`index` is the index of the parameter to be automated. Supported rates are `ir` and `kr`. You can dynamically switch between different parameters at control rate. A negative number deactivates the control.

`value` is the new state for the given plugin parameter and should be a floating point number between 0.0 and 1.0. All rates are supported, but `ir` and `kr` are recommended. `ar` only makes sense for VST3 plugins - and only for those which actually support sample accurate automation (many VST3 plugins do not!).

**NOTE**: Automation via UGen inputs can be overriden by the `/map` and `/mapa` Unit commands (see below).

*bypass*

If a plugin is bypassed, processing is suspended and each input is passed straight to its corresponding output. The `bypass` parameter can have the following states:

* 0 -> off (processing)
* 1 -> hard bypass; processing is suspended immediately and the plugin's own bypass method is called (if available). Good plugins will do a short crossfade, others will cause a click. |
* 2 -> soft bypass; if the plugin has a tail (e.g. reverb or delay), it will fade out. Also, this doesn't call the plugin's bypass method, so we can always do a nice crossfade. |

---

Here is an example for a VSTPlugin instance with 2 input busses (2 and 1 channels), 2 output busses (2 and 1 channels) and 4 parameter controls:

```
0 0 <bypass> 2 2 <chn1> <chn2> 1 <chn1> 2 2 1 4 <index1> <value1> <index2> <value2> <index3> <value3> <index4> <value4>
```

### UGen outputs

| name          | rate ||
| ------------- | ---- |-|
| outputBus...  | ar   | (optional) `<numOutputs>` output busses

Each *outputBus* contains one or more output channels; the number of channels is determined by the corresponding `outputBus` UGen input.

# Realtime safety

VSTPlugin tries its best to be as realtime safe as possible. Plugins are always opened/closed asynchronously on the NRT resp. UI thread. Some Unit commands, like `/reset` or `/program_read`, offer two options via the `async` parameter:

2) `async: true` means that the plugin method is called on the NRT resp. UI thread and will never block the Server! However, plugin processing is temporarily suspended and the UGen will not accept other messages until the command has finished.

1) `async: false` means that the plugin method is simply called on the RT thread. Depending on the plugin, this might be just fine - or block the server. You have to test yourself! The advantage is that the action is performed synchronously and plugin processing doesn't have to be suspended.

**NOTE**: If the plugin is opened with the GUI editor, the `async` option is automatically set to *true* out of thread safety concerns.

# OSC interface

Abbreviations for OSC data types:

| name   | type           |
| ------ | -------------- |
| int    | 32 bit integer |
| float  | 32 bit float   |
| string | string         |
| bytes  | binary blob    |


### Plugin commands

Plugin commands can be called without any UGen instance and take the following form:

`/cmd <string>cmdName (arguments)...`

##### /vst_search

Search for VST plugins.

Arguments:
| type       ||
| ---------- |-|
| int        | a bitset of options (see below)
| int/string | where to write the search results; either a buffer number or a file path; -1 means don't write results.
| float      | timeout (the time to wait for each plugin before it is regarded as stuck and ignored); 0.0 means no timeout.
| int        | the number of user supplied search paths; 0 means none.
| string...  | (optional) list of user supplied search paths
| int        | the number of exclude paths; 0 means none
| string...  | (optional) list of user supplied exclude paths
| string     | (optional) custom cache file directory

This will search the given paths recursively for VST plugins, probe them, and write the results to a file or buffer. Valid plugins are stored in a server-side plugin dictionary. If no plugin could be found, the buffer or file will be empty.

The following options can be combined with a bitwise OR operation:
| value ||
| ----- |-|
| 0x1   | verbose (print plugin paths and probe results)
| 0x2   | write search results to cache file.
| 0x4   | probe in parallel (faster, but might cause audio dropouts because of full CPU utilization)

If there are no user supplied search paths, the standard VST search paths are used instead:

- VST 2.x
  - Windows
    - `%ProgramFiles%`\VSTPlugins
    - `%ProgramFiles%`\Steinberg\VSTPlugins
    - `%ProgramFiles%`\Common Files\VST2
    - `%ProgramFiles%`\Common Files\Steinberg\VST2
  - macOS
    - ~/Library/Audio/Plug-Ins/VST
    - /Library/Audio/Plug-Ins/VST
  - Linux
    - ~/.vst
    - /usr/local/lib/vst
    - /usr/lib/vst
- VST 3.x
  - Windows
    - `%ProgramFiles%`\Common Files\VST3
  - macOS
    - ~/Library/Audio/Plug-Ins/VST3
    - /Library/Audio/Plug-Ins/VST3
  - Linux
    - ~/.vst3
    - /usr/local/lib/vst3
    - /usr/lib/vst3

**NOTE**: Here, `%ProgramFiles%` stands for "C:\Program Files" on a 64 bit Server and "C:\Program Files (x86)" on a 32 bit Server.

##### /vst_search_stop

Stop a running search. (No arguments)

##### /vst_query

Try to obtain a plugin description from the plugin cache.

Arguments:
| type       ||
| ---------- |-|
| string     | plugin path/key (absolute or relative)
| int/string | where to write the result; either a buffer number or a file path. -1 means don't write results.

If the plugin is not contained in the plugin cache, it is searched in the standard VST search paths and probed in a seperate process (so that bad plugins don't crash the server).
On success, the plugin information is written to a file or buffer and the plugin is stored in a server-side plugin dictionary; on fail, nothing is written.

For VST 2.x plugins, you can omit the file extension. Relative paths are resolved recursively based on the standard VST directories.

The probe process can return one of the following results:

- ok -> probe succeeded
- failed -> couldn't load the plugin; possible reasons:
    a) not a VST plugin, b) wrong architecture, c) missing dependencies
- crashed -> the plugin crashed on initialization
- error -> internal failure

##### /vst_cache_read

Read the cache file from a custom location.

Arguments:
| type   ||
| ------ |-|
| string | the cache file directory |

##### /vst_clear

Clear the server-side plugin dictionary.

Arguments:
| type ||
| ---- |-|
| int  | remove cache file; 1 = yes, 0 = no |


##### /dsp_threads

Set the number of DSP threads for multi-threaded plugin processing.
(By default, this is the number of logical CPUs.)

**NOTE**: This command only takes effect if it is sent before any (multi-threaded) plugins have been opened.

Arguments:
| type   ||
| ------ |-|
| int    | number of threads; 0 = default |


### Plugin key

Plugins are stored in a server-side plugin dictionary under its *key*.
For VST 2.x plugins, the key is simply the plugin name; for VST 3.x plugins, the key is the plugin name plus ".vst3" extension.

If a VST2 and VST3 module contains a single plugin (as is the case with most VST2 and VST3 plugins), it can also be referenced by its file path. Since VST2 shell plugins and VST3 plugin factories contain multiple plugins in a single module, each plugin can only be referenced by its *key*.

On big advantage of plugin keys over file paths is that the latter can vary across systems and architectures, whereas the former is always the same!

### Unit commands

Unit commands are used to control a specific UGen instance and take the following form:

`/u_cmd <int>nodeID <int>synthIndex <string>cmdName (arguments)...`

##### /open

Open a new VST plugin. This method is always asynchronous.

Arguments:
| type   ||
| ------ |-|
| string | plugin key or path.
| int    | request VST GUI editor; 1 = yes, 0 = no
| int    | request multithreading; 1 = yes, 0 = no
| int    | mode; 0 = normal, 1 = sandbox (dedicated process), 2 = bridge (shared process)

Replies with
| `/vst_open` ||
| --------    |-|
| int         | node ID
| int         | synth index
| float       | 1.0 = success, 0.0 = fail
| float       | VST GUI editor; 1.0 = yes, 0.0 = no
| float       | initial latency in samples

##### /close

Close the current VST plugin.

No Arguments.

##### /vis

Show/hide the VST GUI editor (if enabled).

Arguments:
| type ||
| ---- |-|
| int  | 1 = show, 0 = hide

##### /pos

Set the position of the GUI editor.

Arguments:
| type ||
| ---- |-|
| int  | x-coordinate |
| int  | y-coordinate |

##### /size

Resize the GUI editor.
This only works for VST3 plugins with a resizable GUI.

Arguments:
| type ||
| ---- |-|
| int  | width  |
| int  | height |

##### /reset

Reset the VST plugin's internal state (e.g. clear delay lines).

Arguments:
| type ||
| ---- |-|
| int  | asynchronous; 1 = true, 0 = false

**NOTE**: If the plugin is opened with the VST GUI editor, the command is always performed asynchronously and the `async` argument is ignored.

### Parameters

##### /set

Set a plugin parameter to a new value.

Arguments:
| type         ||
| ------------ |-|
| int/string   | parameter index or name
| float/string | "normalized" float value between 0.0 and 0.1 or "plain" string representation. Depending on the plugin, the latter might only work for certain parameters - or not work at all.
| ...          | (optional) additional pairs of `<index>, <value>` 

Replies with `/vst_param` (see "Events" section).

You can automate several parameters at once, e.g. `/u_cmd, <nodeID>, <synthIndex>, /set, 0, 0.5, 1, "12", "Wet", 0.7` will set parameters 0, 1 and "Wet".

**NOTE**: `/set` will automatically unmap the corresponding parameter(s) from any audio/control busses, see `/unmap`.

##### /setn

Like `/set`, but with a range of subsequent parameters.

Arguments:
| type             ||
| ---------------- |-|
| int/string       | name or index of start parameter
| int              | number of parameters
| float/string ... | parameter values

##### /get

Get a single plugin parameter value.

Arguments:
| type       ||
| ---------- |-|
| int/string | parameter index or name

Replies with:
| `/vst_set`||
| --------- |-|
| int       | node ID
| int       | synth index
| float     | parameter index
| float     | normalized parameter value

##### /getn

Get a range of plugin parameter values.

Arguments:
| type       ||
| ---------- |-|
| int/string | parameter index or name
| int        | number of subsequent parameters (-1: till the end)

Replies with:
| `/vst_set`||
| --------- |-|
| int       | node ID
| int       | synth index
| float     | parameter start index
| float     | number of parameters
| float ... | normalized parameter values

To get all parameter values, you can do `/u_cmd, <nodeID>, <synthIndex>, /getn, 0, -1`.

##### /param_query

Query parameter states.

Arguments:
| type       ||
| ---------- |-|
| int        | start parameter index
| int        | number of parameters

Replies with a series of `/vst_param` messages (see "Events" section). Use this instead of `/getn`, if you also need the string representation, e.g. to update your client GUI after loading a new plugin, switching programs or loading a preset file.

##### /map

Map a subsequent range of parameters to control bus channels.

Arguments:
| type       ||
| ---------- |-|
| int/string | name or index of parameter
| int        | control bus start index
| int        | number of channels

For example, `/u_cmd, <nodeID>, <synthIndex>, /map, 5, 4, 1` will map parameter 5 to control bus 4. `/u_cmd, <nodeID>, <synthIndex>, /map, 5, 4, 2` will map parameter 5 to control bus 4 and also parameter 6 to control bus 5.


##### /mapa

Map a subsequent range of parameters to audio bus channels.

Arguments:
| type       ||
| ---------- |-|
| int/string | name or index of parameter
| int        | audio bus start index
| int        | number of channels

**NOTE**: Mapping a parameter to a audio/control bus has higher precedence than UGen input parameter controls (see "UGen inputs" section).

##### /unmap

Unmap parameters from audio/control busses.

Arguments:
| type           ||
| -------------- |-|
| int/string ... | names or indices of parameters to unmap. If omitted, all parameters are unmapped.

**NOTE**: `/set` will automatically unmap the corresponding parameter(s) from any audio/control busses!

### Preset management

##### /program_set

Select program from program list.

Arguments:
| type ||
| ---- |-|
| int  | program index |

##### /program_name

Change the current program name.

Arguments:
| type   ||
| ------ |-|
| string | new program name

Replies with `/vst_program`, see "Events" section.

##### /program_read

Read a VST program from a file or sound buffer.

Arguments:
| type       ||
| ---------- |-|
| int/string | buffer number of file path, see "Data transfer" section.
| int        | asynchronous; 1 = yes, 0 = no

Replies with:
| `/vst_program_read` ||
| ------------------- |-|
| int                 | node ID
| int                 | synth index
| float               | 1.0 = success, 0.0 = fail

Also sends `/vst_program` (see "Event" section).

##### /bank_read

Read a preset bank from a file or buffer.

Arguments:
| type       ||
| ---------- |-|
| int/string | buffer number of file path, see "Data transfer" section.
| int        | asynchronous; 1 = yes, 0 = no

Replies with:
| `/vst_bank_read` ||
| ---------------- |-|
| int              | node ID
| int              | synth index
| float            | 1.0 = success, 0.0 = fail

Also sends `/vst_program` and `/vst_program_index` (see "Events" section).

##### /program_write

Write a preset program to a file or buffer.

Arguments:
| type       ||
| ---------- |-|
| int/string | buffer number of file path, see "Data transfer" section.
| int        | asynchronous; 1 = yes, 0 = no

Replies with:
| `/vst_program_write` ||
| -------------------- |-|
| int                  | node ID
| int                  | synth index
| float                | 1.0 = success, 0.0 = fail

##### /bank_write

Write a preset bank to a file or buffer.

Arguments:
| type       ||
| ---------- |-|
| int/string | buffer number of file path, see "Data transfer" section.
| int        | asynchronous; 1 = yes, 0 = no

Replies with:
| `/vst_bank_write` ||
| ----------------- |-|
| int               | node ID
| int               | synth index
| float             | 1.0 = success, 0.0 = fail

##### /program_query

Query program names.

Arguments:
| type ||
| ---- |-|
| int  | start program index
| int  | number of programs

Replies with a series of `/vst_program` messages (see "Event" section). For example, you can use this to update the program list in your client after loading a new plugin or reading a preset bank.

### MIDI

##### /midi_msg

Send a MIDI message.

Arguments:
| type  ||
| ----- |-|
| bytes | MIDI message (1-3) bytes
| float | (optional) detune in cent

The optional detune argument allows to detune a single note-on or note-off message; this feature is not part of the MIDI standard and only a few VST plugins suppport it.

##### /midi_sysex

Send a SysEx message.

| type  ||
| ----- |-|
| bytes | SysEx message

### Timing and transport

##### /tempo

Set the tempo.

Arguments:
| type  ||
| ----- |-|
| float | BPM (beats per minute)

##### /time_sig

Setthe time signature.

Arguments:
| type ||
| ---- |-|
| int  | numerator
| int  | denominator

##### /transport_play

Set the transport state.

Arguments:
| type ||
| ---- |-|
| int  | 1 = play, 0 = stop

##### /transport_set

Set the transport position.

Arguments:
| type  ||
| ----- |-|
| float | transport position in beats.

##### /transport_get

Get the current transport position.

Replies with:
| `/vst_transport` ||
| ---------------- |-|
| int              | node ID
| int              | synth index
| float            | position in beats

### VST 2.x

**NOTE**: The following methods only work for VST 2.x plugins and are meant for expert users. Please check the VST 2.x SDK for more information.

##### /can_do

Ask the plugin if it can do something.

Arguments:
| type   ||
| ------ |-|
| string | what

Replies with:
| `/vst_can_do` ||
| ------------- |-|
| int           | node ID
| int           | synth index
| float         | 1.0 = yes, -1.0 = no, 0.0 = don't know

##### /vendor_method

Call a vendor specific method.

Arguments:
| type   ||
| ------ |-|
| int    | index
| int    | value
| int    | ptr
| int    | opt
| int    | asynchronous; 1 = yes, 0 = no

Replies with:
| `/vst_vendor_method` ||
| -------------------- |-|
| int                  | node ID
| int                  | synth index
| float                | result


### Events

The VSTPlugin UGen may send the following events as Node reply messages:

##### /vst_param

A parameter has changed state.

Arguments:
| type      ||
| --------- |-|
| int       | node ID
| int       | synth index
| float     | parameter index
| float     | normalized parameter value
| float ... | "plain" string representation, see "String encoding" section.

`/vst_param` messages are sent after `/set`, `/setn`, `/param_query` or when automating parameters in the VST GUI editor. They are *not* sent when parameters are automated via UGen input parameter controls (see "UGen inputs" section) or audio/control bus mappings (see `/map`), because this would lead to excessive OSC traffic.

**NOTE**: A single parameter change might produce several `/vst_param` messages, e.g. in the case of linked parameters.

##### /vst_program

A program name has changed.

Arguments:
| type      ||
| --------- |-|
| int       | node ID
| int       | synth index
| float     | program index
| float ... | program name, see "String encoding" section.

This message is sent after `/program_name`, `/program_read` or `/bank_read`.

##### /vst_program_index

The current program index has changed.

Arguments:
| type      ||
| --------- |-|
| int       | node ID
| int       | synth index
| float     | program index

This message is sent after `/program_set` and `/bank_read`.

##### /vst_auto

A parameter has been automated in the VST GUI editor.

Arguments:
| type      ||
| --------- |-|
| int       | node ID
| int       | synth index
| float     | parameter index
| float     | normalized parameter value

This message is always sent together with `/vst_param`.

##### /vst_latency

The plugin's processing latency has changed. This includes the additional latency caused by multithreading (see `/open`).

Arguments:
| type      ||
| --------- |-|
| int       | node ID
| int       | synth index
| float     | latency in samples

##### /vst_midi

The plugin has sent a MIDI message.

Arguments:
| type       ||
| ---------- |-|
| int        | node ID
| int        | synth index
| float  ... | MIDI message (one float per byte)

### /vst_sysex

The plugin has sent a SysEx message.

Arguments:
| type       ||
| ---------- |-|
| int        | node ID
| int        | synth index
| float  ... | SysEx message (one float per byte)

### /vst_update

Multiple parameters have changed internally,
e.g. because the user loaded a preset in the plugin UI.

Arguments:
| type       ||
| ---------- |-|
| int        | node ID
| int        | synth index

### /vst_crash

The plugin has crashed.
Naturally, this message can only be sent if the plugin has been bridged or sandboxed.

Arguments:
| type       ||
| ---------- |-|
| int        | node ID
| int        | synth index


# String encoding

Because of limitations in the SuperCollider plugin API, Node reply messages can only contain float arguments. Our solution is to encode string arguments as a list of bytes with a length prefix ("Pascal strings"), where each byte takes up a single float.

For example, the string "Dry" is encoded as `3.0, 44.0, 72.0, 79.0`.


# Data transfer

To reliably exchange larger data sets between server and clients, you can use temp files or sound buffers. For locals servers, temp files should be preferred. For remote servers, you have to use sound buffers (unless you can use FTP :-). Usually, client frameworks already have abstractions to (more or less) reliably stream data from/to sound buffers.

Files are always read and written in binary. In case of sound buffers, each float corresponds to a single byte.

Whenever VSTPlugin writes data to a sound buffer, it will allocate the data for you, but because of limitations in the SuperCollider plugin API, it can't safely deallocate a sound buffer. There are two consequences:

- Whenever you ask VSTPlugin to *write* data, make sure that the target sound buffer is empty!
- Whenever you ask VSTPlugin to *read* data, it's your job to free the sound buffer after the command has finished.

VSTPlugin uses a custom format similar to .ini files to exchange plugin description data between server and clients. It is also used in the plugin cache file.

### Plugin info

This is the structure of a single plugin description, as used by `/vst_query`:

```
[plugin]
id=<unique ID string>
path=<file path>
name=<plugin name>
vendor=<vendor name>
category=<category name>
version=<plugin version string>
sdkversion=<VST SDK version string>
flags=<bitset>
pgmchange=<program change parameter index in hex> (optional)
bypass=<bypass parameter index in hex> (optional)
[inputs]
n=<input bus count>
<channel count #0>, <type #0>, <name #0>
<channel count #1>, <type #1>, <name #1>
...
<channel count #N-1>, <type #N-1>, <name #N-1>
[outputs]
n=<output bus count>
<channel count #0>, <type #0>, <name #0>
<channel count #1>, <type #1>, <name #1>
...
<channel count #N-1>, <type #N-1>, <name #N-1>
[parameters]
n=<parameter count>
<name #0>, <label #0>, <ID #0>, <flags #0>
<name #1>, <label #1>, <ID #1> <flags #1>
...
<name #N-1>, <label #N-1>, <ID #N-1>, <flags #N-1>
[programs]
n=<program count>
<name #0>
<name #1>
...
<name #N-1>
[keys]
n=<number of keys>
<key #0>
<key #1>
...
<key #N-1>
```

String values, like plugin/parameter/program names, can contain any characters except newlines and commas (those are bashed to a replacement symbol by the UGen).

**NOTE**: do not rely on the order of entries in the `[plugin]` section!
In the future we might add/insert more entries and possibly reorder them.

##### flags

`flags` is a bitset of boolean properties, written as a hexidecimal number. The following flags can be combined with a bitwise OR operation:

| value ||
| ----- |-|
| 0x001 | supports the GUI editor
| 0x002 | is a VST instrument
| 0x004 | supports single precision processing
| 0x008 | supports double precision processing
| 0x010 | has MIDI input
| 0x020 | has MIDI output
| 0x040 | has SysEx input
| 0x080 | has SysEx output
| 0x100 | is bridged

##### input/output busses

Each bus entry takes up a single line and consists of three fields, separated by a comma: `<channel count>, <type>, <name>`.

`<type>` can be either 0 (= main) or 1 (= aux). `<name` is always empty for VST2 plugins (because they only have a single input/output bus).

In the future we might add more fields.

##### parameters

Each parameter entry takes up a single line and consists of three fields, separated by a comma: `<name>, <label>, <ID> <flags>`.

`<label>` is the unit of measurement (e.g. "dB", "ms", "%"); it can be an empty string!

The parameter ID is a hexidecimal number. For VST 2.x plugins it is the same as the parameter index, but for VST 3.x plugins it can be an arbitrary 32 bit integer.

`flags` is a bitset of boolean properties, written as a hexidecimal number. The following flags can be combined with a bitwise OR operation:

| value ||
| ----- |-|
| 0x01  | is automatable |

In the future we might add more fields.

##### programs

Every program consists of a single field, which is the program name.

**NOTE**: Program names can be empty strings; this means that empty lines after the `[programs]` section are significant and must not be ignored!

In the future we might add more fields.

---

Each plugin can be referred to by one or more *keys*. The primary key always comes first in the list.

*EXAMPLE:*
```
[plugin]
path=C:/Program Files/VSTPlugins/GVST/GChorus.dll
id=6779416F
name=GChorus
vendor=GVST
category=Effect
version=1200
sdkversion=VST 2.4
flags=10d
[inputs]
n=1
2,0,
[outputs]
n=1
2,0,
[parameters]
n=4
Depth,cents,0
Freq,Hz,1
R Phase,deg,2
Mix,%,3
[programs]
n=10
Subtle Insert
Wide Insert
Heavy Insert
Subtle Send
Wide Send
Heavy Send
Defaults
Defaults
Defaults
Defaults
[keys]
n=2
GChorus
C:/Program Files/VSTPlugins/GVST/GChorus.dll
```

### Search results

This is used by `/vst_search` to transmit search results to the client. It has the following structure:

```
[plugins]
n=<number of plugins>
<plugin info #0>
<plugin info #1>
...
<plugin info #N-1>
```

Each `<plugin info>` entry has the same structure as in "Plugin info".


### Plugin cache file

Probing lots of (large) VST plugins can be a slow process.
To speed up subsequent searches, the search results can be written to a cache file (see `/vst_search`), which is located in a platform specific directory:
`%LOCALAPPDATA%\vstplugin\sc` on Windows, `~/Library/Application Support/vstplugin/sc` on macOS and `$XDG_DATA_HOME/vstplugin/sc` resp. `~/.local/share/vstplugin/sc` on Linux.
The cache file itself is named `cache_<arch>.ini`, so that cache files for different CPU architectures can co-exist.

The cache file structure is very similar to that in "Search results".
The only difference is that it also contains a version header (`[version]`) and a plugin black-list (`[ignore]`).

```
[version]
<major>.<minor>.<patch>
[ignore]
n=<number of paths>
<path #0>
<path #1>
...
<path #N-1>
[plugins]
n=<number of plugins>
<plugin info #0>
<plugin info #1>
...
<plugin info #N-1>
```

Plugins are black-listed if the probe process failed (see `/vst_query`).
If you want to replace a "bad" plugin with a "good" one, you have to first remove the cache file (see `/vst_clear`).