-
Notifications
You must be signed in to change notification settings - Fork 1
/
clapdefs.pas
3326 lines (2806 loc) · 141 KB
/
clapdefs.pas
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
unit clapdefs;
//Delphi translation of the CLAP audio plugin header files from https://github.com/free-audio/clap
//MIT license
{
* CLAP - CLever Audio Plugin
* ~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Copyright (c) 2014...2022 Alexandre BIQUE <bique.alexandre@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
}
interface
uses
System.SysUtils;
type
uint16_t = UInt16;
uint32_t = UInt32;
uint64_t = UInt64;
int16_t = Int16;
int32_t = Int32;
int64_t = Int64;
size_t = NativeUInt;
//version.h
// This is the major ABI and API design
// Version 0.X.Y correspond to the development stage, API and ABI are not stable
// Version 1.X.Y correspond to the release stage, API and ABI are stable
Tclap_version = record
major: uint32_t;
minor: uint32_t;
revision: uint32_t;
end;
const
CLAP_VERSION_MAJOR = 1;
CLAP_VERSION_MINOR = 2;
CLAP_VERSION_REVISION = 0;
CLAP_VERSION: Tclap_version = (
major: CLAP_VERSION_MAJOR;
minor: CLAP_VERSION_MINOR;
revision: CLAP_VERSION_REVISION;
);
// versions 0.x.y were used during development stage and aren't compatible
function clap_version_is_compatible(const v: Tclap_version): boolean; inline;
//string-sizes.h
const
// String capacity for names that can be displayed to the user.
CLAP_NAME_SIZE = 256;
// String capacity for describing a path, like a parameter in a module hierarchy or path within a
// set of nested track groups.
//
// This is not suited for describing a file path on the disk, as NTFS allows up to 32K long
// paths.
CLAP_PATH_SIZE = 1024;
//id.h
type
Tclap_id = uint32_t;
const
CLAP_INVALID_ID = UINT32.MaxValue;
//fixedpoint.h
/// We use fixed point representation of beat time and seconds time
/// Usage:
/// double x = ...; // in beats
/// clap_beattime y = round(CLAP_BEATTIME_FACTOR * x);
// This will never change
const
CLAP_BEATTIME_FACTOR = int64_t(1) shl 31;
CLAP_SECTIME_FACTOR = int64_t(1) shl 31;
type
Tclap_beattime = int64_t;
Tclap_sectime = int64_t;
//color.h
type
Tclap_color = record
alpha: byte;
red: byte;
green: byte;
blue: byte;
end;
Pclap_color = ^Tclap_color;
//events.h
// event header
// must be the first attribute of the event
type
Tclap_event_header = record
size: uint32_t; // event size including this header, eg: sizeof (clap_event_note)
time: uint32_t; // sample offset within the buffer for this event
space_id: uint16_t; // event space, see clap_host_event_registry
&type: uint16_t; // event type
flags: uint32_t; // see clap_event_flags
end;
Pclap_event_header = ^Tclap_event_header;
// The clap core event space
const
CLAP_CORE_EVENT_SPACE_ID = 0;
// Indicate a live user event, for example a user turning a physical knob
// or playing a physical key.
CLAP_EVENT_IS_LIVE = 1 shl 0;
// indicate that the event should not be recorded.
// For example this is useful when a parameter changes because of a MIDI CC,
// because if the host records both the MIDI CC automation and the parameter
// automation there will be a conflict.
CLAP_EVENT_DONT_RECORD = 1 shl 1;
// Some of the following events overlap, a note on can be expressed with:
// - CLAP_EVENT_NOTE_ON
// - CLAP_EVENT_MIDI
// - CLAP_EVENT_MIDI2
//
// The preferred way of sending a note event is to use CLAP_EVENT_NOTE_*.
//
// The same event must not be sent twice: it is forbidden to send a the same note on
// encoded with both CLAP_EVENT_NOTE_ON and CLAP_EVENT_MIDI.
//
// The plugins are encouraged to be able to handle note events encoded as raw midi or midi2,
// or implement clap_plugin_event_filter and reject raw midi and midi2 events.
// NOTE_ON and NOTE_OFF represents a key pressed and key released event, respectively.
// A NOTE_ON with a velocity of 0 is valid and should not be interpreted as a NOTE_OFF.
//
// NOTE_CHOKE is meant to choke the voice(s), like in a drum machine when a closed hihat
// chokes an open hihat. This event can be sent by the host to the plugin. Here are two use
// cases:
// - a plugin is inside a drum pad in Bitwig Studio's drum machine, and this pad is choked by
// another one
// - the user double-clicks the DAW's stop button in the transport which then stops the sound on
// every track
//
// NOTE_END is sent by the plugin to the host. The port, channel, key and note_id are those given
// by the host in the NOTE_ON event. In other words, this event is matched against the
// plugin's note input port.
// NOTE_END is useful to help the host to match the plugin's voice life time.
//
// When using polyphonic modulations, the host has to allocate and release voices for its
// polyphonic modulator. Yet only the plugin effectively knows when the host should terminate
// a voice. NOTE_END solves that issue in a non-intrusive and cooperative way.
//
// CLAP assumes that the host will allocate a unique voice on NOTE_ON event for a given port,
// channel and key. This voice will run until the plugin will instruct the host to terminate
// it by sending a NOTE_END event.
//
// Consider the following sequence:
// - process()
// Host->Plugin NoteOn(port:0, channel:0, key:16, time:t0)
// Host->Plugin NoteOn(port:0, channel:0, key:64, time:t0)
// Host->Plugin NoteOff(port:0, channel:0, key:16, t1)
// Host->Plugin NoteOff(port:0, channel:0, key:64, t1)
// # on t2, both notes did terminate
// Host->Plugin NoteOn(port:0, channel:0, key:64, t3)
// # Here the plugin finished processing all the frames and will tell the host
// # to terminate the voice on key 16 but not 64, because a note has been started at t3
// Plugin->Host NoteEnd(port:0, channel:0, key:16, time:ignored)
//
// Those four events use clap_event_note.
CLAP_EVENT_NOTE_ON = 0;
CLAP_EVENT_NOTE_OFF = 1;
CLAP_EVENT_NOTE_CHOKE = 2;
CLAP_EVENT_NOTE_END = 3;
// Represents a note expression.
// Uses clap_event_note_expression.
CLAP_EVENT_NOTE_EXPRESSION = 4;
// PARAM_VALUE sets the parameter's value; uses clap_event_param_value.
// PARAM_MOD sets the parameter's modulation amount; uses clap_event_param_mod.
//
// The value heard is: param_value + param_mod.
//
// In case of a concurrent global value/modulation versus a polyphonic one,
// the voice should only use the polyphonic one and the polyphonic modulation
// amount will already include the monophonic signal.
CLAP_EVENT_PARAM_VALUE = 5;
CLAP_EVENT_PARAM_MOD = 6;
// Indicates that the user started or finished adjusting a knob.
// This is not mandatory to wrap parameter changes with gesture events, but this improves
// the user experience a lot when recording automation or overriding automation playback.
// Uses clap_event_param_gesture.
CLAP_EVENT_PARAM_GESTURE_BEGIN = 7;
CLAP_EVENT_PARAM_GESTURE_END = 8;
CLAP_EVENT_TRANSPORT = 9; // update the transport info; clap_event_transport
CLAP_EVENT_MIDI = 10; // raw midi event; clap_event_midi
CLAP_EVENT_MIDI_SYSEX = 11; // raw midi sysex event; clap_event_midi_sysex
CLAP_EVENT_MIDI2 = 12; // raw midi 2 event; clap_event_midi2
type
// Note on, off, end and choke events.
//
// Clap addresses notes and voices using the 4-value tuple
// (port, channel, key, note_id). Note on/off/end/choke
// events and parameter modulation messages are delivered with
// these values populated.
//
// Values in a note and voice address are either >= 0 if they
// are specified, or -1 to indicate a wildcard. A wildcard
// means a voice with any value in that part of the tuple
// matches the message.
//
// For instance, a (PCKN) of (0, 3, -1, -1) will match all voices
// on channel 3 of port 0. And a PCKN of (-1, 0, 60, -1) will match
// all channel 0 key 60 voices, independent of port or note id.
//
// Especially in the case of note-on note-off pairs, and in the
// absence of voice stacking or polyphonic modulation, a host may
// choose to issue a note id only at note on. So you may see a
// message stream like
//
// CLAP_EVENT_NOTE_ON [0,0,60,184]
// CLAP_EVENT_NOTE_OFF [0,0,60,-1]
//
// and the host will expect the first voice to be released.
// Well constructed plugins will search for voices and notes using
// the entire tuple.
//
// In the case of note choke or end events:
// - the velocity is ignored.
// - key and channel are used to match active notes
// - note_id is optionally provided by the host
Tclap_event_note = record
header: Tclap_event_header;
note_id: int32_t; // host provided note id >= 0, or -1 if unspecified or wildcard
port_index: int16_t; // port index from ext/note-ports; -1 for wildcard
channel: int16_t; // 0..15, same as MIDI1 Channel Number, -1 for wildcard
key: int16_t; // 0..127, same as MIDI1 Key Number (60==Middle C), -1 for wildcard
velocity: double; // 0..1
end;
// Note Expressions are well named modifications of a voice targeted to
// voices using the same wildcard rules described above. Note Expressions are delivered
// as sample accurate events and should be applied at the sample when received.
//
// Note expressions are a statement of value, not cumulative. A PAN event of 0 followed by 1
// followed by 0.5 would pan hard left, hard right, and center. They are intended as
// an offset from the non-note-expression voice default. A voice which had a volume of
// -20db absent note expressions which received a +4db note expression would move the
// voice to -16db.
//
// A plugin which receives a note expression at the same sample as a NOTE_ON event
// should apply that expression to all generated samples. A plugin which receives
// a note expression after a NOTE_ON event should initiate the voice with default
// values and then apply the note expression when received. A plugin may make a choice
// to smooth note expression streams.
const
// with 0 < x <= 4, plain = 20 * log(x)
CLAP_NOTE_EXPRESSION_VOLUME = 0;
// pan, 0 left, 0.5 center, 1 right
CLAP_NOTE_EXPRESSION_PAN = 1;
// Relative tuning in semitones, from -120 to +120. Semitones are in
// equal temperament and are doubles; the resulting note would be
// retuned by `100 * evt->value` cents.
CLAP_NOTE_EXPRESSION_TUNING = 2;
// 0..1
CLAP_NOTE_EXPRESSION_VIBRATO = 3;
CLAP_NOTE_EXPRESSION_EXPRESSION = 4;
CLAP_NOTE_EXPRESSION_BRIGHTNESS = 5;
CLAP_NOTE_EXPRESSION_PRESSURE = 6;
type
Tclap_note_expression = int32_t;
Tclap_event_note_expression = record
header: Tclap_event_header;
expression_id: Tclap_note_expression;
// target a specific note_id, port, key and channel, with
// -1 meaning wildcard, per the wildcard discussion above
note_id: int32_t;
port_index: int16_t;
channel: int16_t;
key: int16_t;
value: double; // see expression for the range
end;
Tclap_event_param_value = record
header: Tclap_event_header;
// target parameter
param_id: Tclap_id; // @ref clap_param_info.id
cookie: pointer; // @ref clap_param_info.cookie
// target a specific note_id, port, key and channel, with
// -1 meaning wildcard, per the wildcard discussion above
note_id: int32_t;
port_index: int16_t;
channel: int16_t;
key: int16_t;
value: double;
end;
Tclap_event_param_mod = record
header: Tclap_event_header;
// target parameter
param_id: Tclap_id; // @ref clap_param_info.id
cookie: pointer; // @ref clap_param_info.cookie
// target a specific note_id, port, key and channel, with
// -1 meaning wildcard, per the wildcard discussion above
note_id: int32_t;
port_index: int16_t;
channel: int16_t;
key: int16_t;
amount: double; // modulation amount
end;
Tclap_event_param_gesture = record
header: Tclap_event_header;
// target parameter
param_id: Tclap_id; // @ref clap_param_info.id
end;
const
CLAP_TRANSPORT_HAS_TEMPO = 1 shl 0;
CLAP_TRANSPORT_HAS_BEATS_TIMELINE = 1 shl 1;
CLAP_TRANSPORT_HAS_SECONDS_TIMELINE = 1 shl 2;
CLAP_TRANSPORT_HAS_TIME_SIGNATURE = 1 shl 3;
CLAP_TRANSPORT_IS_PLAYING = 1 shl 4;
CLAP_TRANSPORT_IS_RECORDING = 1 shl 5;
CLAP_TRANSPORT_IS_LOOP_ACTIVE = 1 shl 6;
CLAP_TRANSPORT_IS_WITHIN_PRE_ROLL = 1 shl 7;
type
Tclap_event_transport = record
header: Tclap_event_header;
flags: uint32_t; // see clap_transport_flags
song_pos_beats: Tclap_beattime; // position in beats
song_pos_seconds: Tclap_sectime; // position in seconds
tempo: double; // in bpm
tempo_inc: double; // tempo increment for each sample and until the next
// time info event
loop_start_beats: Tclap_beattime;
loop_end_beats: Tclap_beattime;
loop_start_seconds: Tclap_sectime;
loop_end_seconds: Tclap_sectime;
bar_start: Tclap_beattime; // start pos of the current bar
bar_number: int32_t; // bar at song pos 0 has the number 0
tsig_num: uint16_t; // time signature numerator
tsig_denom: uint16_t; // time signature denominator
end;
Pclap_event_transport = ^Tclap_event_transport;
Tclap_event_midi = record
header: Tclap_event_header;
port_index: uint16_t;
data: array[0..2] of byte;
end;
Tclap_event_midi_sysex = record
header: Tclap_event_header;
port_index: uint16_t;
buffer: pointer; // midi buffer
size: uint32_t;
end;
// While it is possible to use a series of midi2 event to send a sysex,
// prefer clap_event_midi_sysex if possible for efficiency.
Tclap_event_midi2 = record
header: Tclap_event_header;
port_index: uint16_t;
data: array[0..3] of uint32_t;
end;
// Input event list. The host will deliver these sorted in sample order.
Pclap_input_events = ^Tclap_input_events;
Tclap_input_events = record
ctx: TObject; // reserved pointer for the list
// returns the number of events in the list
//uint32_t (*size)(const struct clap_input_events *list);
size: function(list: Pclap_input_events): uint32_t; cdecl;
// Don't free the returned event, it belongs to the list
//const clap_event_header_t *(*get)(const struct clap_input_events *list, uint32_t index);
get: function(list: Pclap_input_events; index: uint32_t): Pclap_event_header; cdecl;
end;
// Output event list. The plugin must insert events in sample sorted order when inserting events
Pclap_output_events = ^Tclap_output_events;
Tclap_output_events = record
ctx: TObject; // reserved pointer for the list
// Pushes a copy of the event
// returns false if the event could not be pushed to the queue (out of memory?)
//bool (*try_push)(const struct clap_output_events *list, const clap_event_header_t *event);
try_push: function(list: Pclap_output_events; event: Pclap_event_header): boolean; cdecl;
end;
//audio-buffer.h
type
// Sample code for reading a stereo buffer:
//
// bool isLeftConstant = (buffer->constant_mask & (1 << 0)) != 0;
// bool isRightConstant = (buffer->constant_mask & (1 << 1)) != 0;
//
// for (int i = 0; i < N; ++i) {
// float l = data32[0][isLeftConstant ? 0 : i];
// float r = data32[1][isRightConstant ? 0 : i];
// }
//
// Note: checking the constant mask is optional, and this implies that
// the buffer must be filled with the constant value.
// Rationale: if a buffer reader doesn't check the constant mask, then it may
// process garbage samples and in result, garbage samples may be transmitted
// to the audio interface with all the bad consequences it can have.
//
// The constant mask is a hint.
Tclap_audio_buffer = record
// Either data32 or data64 pointer will be set.
data32: PPointerArray;
data64: PPointerArray;
channel_count: uint32_t;
latency: uint32_t; // latency from/to the audio interface
constant_mask: uint64_t;
end;
//process.h
const
// Processing failed. The output buffer must be discarded.
CLAP_PROCESS_ERROR = 0;
// Processing succeeded, keep processing.
CLAP_PROCESS_CONTINUE = 1;
// Processing succeeded, keep processing if the output is not quiet.
CLAP_PROCESS_CONTINUE_IF_NOT_QUIET = 2;
// Rely upon the plugin's tail to determine if the plugin should continue to process.
// see clap_plugin_tail
CLAP_PROCESS_TAIL = 3;
// Processing succeeded, but no more processing is required,
// until the next event or variation in audio input.
CLAP_PROCESS_SLEEP = 4;
type
Tclap_process_status = int32_t;
Tclap_process = record
// A steady sample time counter.
// This field can be used to calculate the sleep duration between two process calls.
// This value may be specific to this plugin instance and have no relation to what
// other plugin instances may receive.
//
// Set to -1 if not available, otherwise the value must be greater or equal to 0,
// and must be increased by at least `frames_count` for the next call to process.
steady_time: uint64_t;
// Number of frame to process
frames_count: uint32_t;
// time info at sample 0
// If null, then this is a free running host, no transport events will be provided
transport: Pclap_event_transport;
// Audio buffers, they must have the same count as specified
// by clap_plugin_audio_ports->count().
// The index maps to clap_plugin_audio_ports->get().
// Input buffer and its contents are read-only.
audio_inputs: pointer { Pclap_audio_buffer_t };
audio_outputs: pointer { Pclap_audio_buffer_t };
audio_inputs_count: uint32_t;
audio_outputs_count: uint32_t;
// The input event list can't be modified.
// Input read-only event list. The host will deliver these sorted in sample order.
in_events: Pclap_input_events;
// Output event list. The plugin must insert events in sample sorted order when inserting events
out_events: Pclap_output_events;
end;
Pclap_process = ^Tclap_process;
//host.h
Pclap_host = ^Tclap_host;
Tclap_host = record
clap_version: Tclap_version; // initialized to CLAP_VERSION
host_data: TObject; // reserved pointer for the host
// name and version are mandatory.
name: PAnsiChar; // eg: "Bitwig Studio"
vendor: PAnsiChar; // eg: "Bitwig GmbH"
url: PAnsiChar; // eg: "https://bitwig.com"
version: PAnsiChar; // eg: "4.3", see plugin.h for advice on how to format the version
// Query an extension.
// The returned pointer is owned by the host.
// It is forbidden to call it before plugin->init().
// You can call it within plugin->init() call, and after.
// [thread-safe]
//const void *(*get_extension)(const struct clap_host *host, const char *extension_id);
get_extension: function(host: Pclap_host; extension_id: PAnsiChar): pointer; cdecl;
// Request the host to deactivate and then reactivate the plugin.
// The operation may be delayed by the host.
// [thread-safe]
//void (*request_restart)(const struct clap_host *host);
request_restart: procedure(host: Pclap_host); cdecl;
// Request the host to activate and start processing the plugin.
// This is useful if you have external IO and need to wake up the plugin from "sleep".
// [thread-safe]
//void (*request_process)(const struct clap_host *host);
request_process: procedure(host: Pclap_host); cdecl;
// Request the host to schedule a call to plugin->on_main_thread(plugin) on the main thread.
// [thread-safe]
//void (*request_callback)(const struct clap_host *host);
request_callback: procedure(host: Pclap_host); cdecl;
end;
//plugin.h
type
TPAnsiCharArray = array[0..(High(Integer) div SizeOf(PChar))-1] of PAnsiChar;
PPAnsiCharArray = ^TPAnsiCharArray;
Tclap_plugin_descriptor = record
clap_version: Tclap_version; // initialized to CLAP_VERSION
// Mandatory fields must be set and must not be blank.
// Otherwise the fields can be null or blank, though it is safer to make them blank.
//
// Some indications regarding id and version
// - id is an arbitrary string which should be unique to your plugin,
// we encourage you to use a reverse URI eg: "com.u-he.diva"
// - version is an arbitrary string which describes a plugin,
// it is useful for the host to understand and be able to compare two different
// version strings, so here is a regex like expression which is likely to be
// understood by most hosts: MAJOR(.MINOR(.REVISION)?)?( (Alpha|Beta) XREV)?
id: PAnsiChar; // eg: "com.u-he.diva, mandatory"
name: PAnsiChar; // eg: "Diva", mandatory
vendor: PAnsiChar; // eg: "u-he"
url: PAnsiChar; // eg: "https://u-he.com/products/diva/"
manual_url: PAnsiChar; // eg: "https://dl.u-he.com/manuals/plugins/diva/Diva-user-guide.pdf"
support_url: PAnsiChar; // eg: "https://u-he.com/support/"
version: PAnsiChar; // eg: "1.4.4"
description: PAnsiChar; // eg: "The spirit of analogue"
// Arbitrary list of keywords.
// They can be matched by the host indexer and used to classify the plugin.
// The array of pointers must be null terminated.
// For some standard features see plugin-features.h
features: PPAnsiCharArray;
end;
Pclap_plugin_descriptor = ^Tclap_plugin_descriptor;
Pclap_plugin = ^Tclap_plugin;
Tclap_plugin = record
desc: Pclap_plugin_descriptor;
plugin_data: pointer; // reserved pointer for the plugin
// Must be called after creating the plugin.
// If init returns false, the host must destroy the plugin instance.
// If init returns true, then the plugin is initialized and in the deactivated state.
// Unlike in `plugin-factory::create_plugin`, in init you have complete access to the host
// and host extensions, so clap related setup activities should be done here rather than in
// create_plugin.
// [main-thread]
//bool (*init)(const struct clap_plugin *plugin);
init: function(plugin: Pclap_plugin): boolean; cdecl;
// Free the plugin and its resources.
// It is required to deactivate the plugin prior to this call. */}
// [main-thread & !active]
//void (*destroy)(const struct clap_plugin *plugin);
destroy: procedure(plugin: Pclap_plugin); cdecl;
// Activate and deactivate the plugin.
// In this call the plugin may allocate memory and prepare everything needed for the process
// call. The process's sample rate will be constant and process's frame count will included in
// the [min, max] range, which is bounded by [1, INT32_MAX].
// Once activated the latency and port configuration must remain constant, until deactivation.
// Returns true on success.
// [main-thread & !active]
//bool (*activate)(const struct clap_plugin *plugin,
// double sample_rate,
// uint32_t min_frames_count,
// uint32_t max_frames_count);
activate: function(plugin: Pclap_plugin; sample_rate: double; min_frames_count: uint32_t; max_frames_count: uint32_t): boolean; cdecl;
// [main-thread & active]
//void (*deactivate)(const struct clap_plugin *plugin);
deactivate: procedure(plugin: Pclap_plugin); cdecl;
// Call start processing before processing.
// Returns true on success.
// [audio-thread & active & !processing]
//bool (*start_processing)(const struct clap_plugin *plugin);
start_processing: function(plugin: Pclap_plugin): boolean; cdecl;
// Call stop processing before sending the plugin to sleep.
// [audio-thread & active & processing]
//void (*stop_processing)(const struct clap_plugin *plugin);
stop_processing: procedure(plugin: Pclap_plugin); cdecl;
// - Clears all buffers, performs a full reset of the processing state (filters, oscillators,
// envelopes, lfo, ...) and kills all voices.
// - The parameter's value remain unchanged.
// - clap_process.steady_time may jump backward.
//
// [audio-thread & active]
//void (*reset)(const struct clap_plugin *plugin);
reset: procedure(plugin: Pclap_plugin); cdecl;
// process audio, events, ...
// All the pointers coming from clap_process_t and its nested attributes,
// are valid until process() returns.
// [audio-thread & active & processing]
//clap_process_status (*process)(const struct clap_plugin *plugin, const clap_process_t *process);
process: function(plugin: Pclap_plugin; process: Pclap_process): Tclap_process_status; cdecl;
// Query an extension.
// The returned pointer is owned by the plugin.
// It is forbidden to call it before plugin->init().
// You can call it within plugin->init() call, and after.
// [thread-safe]
//const void *(*get_extension)(const struct clap_plugin *plugin, const char *id);
get_extension: function(plugin: Pclap_plugin; id: PAnsiChar): pointer; cdecl;
// Called by the host on the main thread in response to a previous call to:
// host->request_callback(host);
// [main-thread]
//void (*on_main_thread)(const struct clap_plugin *plugin);
on_main_thread: procedure(plugin: Pclap_plugin); cdecl;
end;
//plugin-features.h
// This files provides a set of standard plugin features meant to be used
// within clap_plugin_descriptor.features.
//
// For practical reasons we'll avoid spaces and use `-` instead to facilitate
// scripts that generate the feature array.
//
// Non-standard features should be formatted as follow: "$namespace:$feature"
const
/////////////////////
// Plugin category //
/////////////////////
// Add this feature if your plugin can process note events and then produce audio
CLAP_PLUGIN_FEATURE_INSTRUMENT = 'instrument';
// Add this feature if your plugin is an audio effect
CLAP_PLUGIN_FEATURE_AUDIO_EFFECT = 'audio-effect';
// Add this feature if your plugin is a note effect or a note generator/sequencer
CLAP_PLUGIN_FEATURE_NOTE_EFFECT = 'note-effect';
// Add this feature if your plugin converts audio to notes
CLAP_PLUGIN_FEATURE_NOTE_DETECTOR = 'note-detector';
// Add this feature if your plugin is an analyzer
CLAP_PLUGIN_FEATURE_ANALYZER = 'analyzer';
/////////////////////////
// Plugin sub-category //
/////////////////////////
CLAP_PLUGIN_FEATURE_SYNTHESIZER = 'synthesizer';
CLAP_PLUGIN_FEATURE_SAMPLER = 'sampler';
CLAP_PLUGIN_FEATURE_DRUM = 'drum'; // For single drum
CLAP_PLUGIN_FEATURE_DRUM_MACHINE = 'drum-machine';
CLAP_PLUGIN_FEATURE_FILTER = 'filter';
CLAP_PLUGIN_FEATURE_PHASER = 'phaser';
CLAP_PLUGIN_FEATURE_EQUALIZER = 'equalizer';
CLAP_PLUGIN_FEATURE_DEESSER = 'de-esser';
CLAP_PLUGIN_FEATURE_PHASE_VOCODER = 'phase-vocoder';
CLAP_PLUGIN_FEATURE_GRANULAR = 'granular';
CLAP_PLUGIN_FEATURE_FREQUENCY_SHIFTER = 'frequency-shifter';
CLAP_PLUGIN_FEATURE_PITCH_SHIFTER = 'pitch-shifter';
CLAP_PLUGIN_FEATURE_DISTORTION = 'distortion';
CLAP_PLUGIN_FEATURE_TRANSIENT_SHAPER = 'transient-shaper';
CLAP_PLUGIN_FEATURE_COMPRESSOR = 'compressor';
CLAP_PLUGIN_FEATURE_EXPANDER = 'expander';
CLAP_PLUGIN_FEATURE_GATE = 'gate';
CLAP_PLUGIN_FEATURE_LIMITER = 'limiter';
CLAP_PLUGIN_FEATURE_FLANGER = 'flanger';
CLAP_PLUGIN_FEATURE_CHORUS = 'chorus';
CLAP_PLUGIN_FEATURE_DELAY = 'delay';
CLAP_PLUGIN_FEATURE_REVERB = 'reverb';
CLAP_PLUGIN_FEATURE_TREMOLO = 'tremolo';
CLAP_PLUGIN_FEATURE_GLITCH = 'glitch';
CLAP_PLUGIN_FEATURE_UTILITY = 'utility';
CLAP_PLUGIN_FEATURE_PITCH_CORRECTION = 'pitch-correction';
CLAP_PLUGIN_FEATURE_RESTORATION = 'restoration'; // repair the sound
CLAP_PLUGIN_FEATURE_MULTI_EFFECTS = 'multi-effects';
CLAP_PLUGIN_FEATURE_MIXING = 'mixing';
CLAP_PLUGIN_FEATURE_MASTERING = 'mastering';
////////////////////////
// Audio Capabilities //
////////////////////////
CLAP_PLUGIN_FEATURE_MONO = 'mono';
CLAP_PLUGIN_FEATURE_STEREO = 'stereo';
CLAP_PLUGIN_FEATURE_SURROUND = 'surround';
CLAP_PLUGIN_FEATURE_AMBISONIC = 'ambisonic';
//universal-plugin-id.h
// Pair of plugin ABI and plugin identifier
type
Tclap_universal_plugin_id = record
// The plugin ABI name, in lowercase and null-terminated.
// eg: "clap", "vst3", "vst2", "au", ...
abi: PAnsiChar;
// The plugin ID, null-terminated and formatted as follow:
//
// CLAP: use the plugin id
// eg: "com.u-he.diva"
//
// AU: format the string like "type:subt:manu"
// eg: "aumu:SgXT:VmbA"
//
// VST2: print the id as a signed 32-bits integer
// eg: "-4382976"
//
// VST3: print the id as a standard UUID
// eg: "123e4567-e89b-12d3-a456-426614174000"
id: PAnsiChar;
end;
Pclap_universal_plugin_id = ^Tclap_universal_plugin_id;
//factory\plugin-factory.h
// Use it to retrieve const clap_plugin_factory_t* from
// clap_plugin_entry.get_factory()
const
CLAP_PLUGIN_FACTORY_ID = AnsiString('clap.plugin-factory');
type
Pclap_plugin_factory = ^Tclap_plugin_factory;
// Every method must be thread-safe.
// It is very important to be able to scan the plugin as quickly as possible.
//
// The host may use clap_plugin_invalidation_factory to detect filesystem changes
// which may change the factory's content.
Tclap_plugin_factory = record
// Get the number of plugins available.
// [thread-safe]
//uint32_t (*get_plugin_count)(const struct clap_plugin_factory *factory);
get_plugin_count: function(factory: Pclap_plugin_factory): uint32_t; cdecl;
// Retrieves a plugin descriptor by its index.
// Returns null in case of error.
// The descriptor must not be freed.
// [thread-safe]
//const clap_plugin_descriptor_t *(*get_plugin_descriptor)(
// const struct clap_plugin_factory *factory, uint32_t index);
get_plugin_descriptor: function(factory: Pclap_plugin_factory; index: uint32_t): Pclap_plugin_descriptor; cdecl;
// Create a clap_plugin by its plugin_id.
// The returned pointer must be freed by calling plugin->destroy(plugin);
// The plugin is not allowed to use the host callbacks in the create method.
// Returns null in case of error.
// [thread-safe]
//const clap_plugin_t *(*create_plugin)(const struct clap_plugin_factory *factory,
// const clap_host_t *host,
// const char *plugin_id);
create_plugin: function(factory: Pclap_plugin_factory; host: Pclap_host; plugin_id: PAnsiChar): Pclap_plugin; cdecl;
end;
//factory\draft\plugin-invalidation.h
// Use it to retrieve const clap_plugin_invalidation_factory_t* from
// clap_plugin_entry.get_factory()
const
CLAP_PLUGIN_INVALIDATION_FACTORY_ID = AnsiString('clap.plugin-invalidation-factory/1');
type
Tclap_plugin_invalidation_source = record
// Directory containing the file(s) to scan, must be absolute
directory: PAnsiChar;
// globing pattern, in the form *.dll
filename_glob: PAnsiChar;
// should the directory be scanned recursively?
recursive_scan: boolean;
end;
Pclap_plugin_invalidation_source = ^Tclap_plugin_invalidation_source;
// Used to figure out when a plugin needs to be scanned again.
// Imagine a situation with a single entry point: my-plugin.clap which then scans itself
// a set of "sub-plugins". New plugin may be available even if my-plugin.clap file doesn't change.
// This interfaces solves this issue and gives a way to the host to monitor additional files.
type
Pclap_plugin_invalidation_factory = ^Tclap_plugin_invalidation_factory;
Tclap_plugin_invalidation_factory = record
// Get the number of invalidation source.
//uint32_t (*count)(const struct clap_plugin_invalidation_factory *factory);
count: function(factory: Pclap_plugin_invalidation_factory): uint32_t; cdecl;
// Get the invalidation source by its index.
// [thread-safe]
//const clap_plugin_invalidation_source_t *(*get)(
// const struct clap_plugin_invalidation_factory *factory, uint32_t index);
get: function(factory: Pclap_plugin_invalidation_factory; index: uint32_t): Pclap_plugin_invalidation_source; cdecl;
// In case the host detected a invalidation event, it can call refresh() to let the
// plugin_entry update the set of plugins available.
// If the function returned false, then the plugin needs to be reloaded.
//bool (*refresh)(const struct clap_plugin_invalidation_factory *factory);
refresh: function(factory: Pclap_plugin_invalidation_factory): boolean; cdecl;
end;
//entry.h
// This interface is the entry point of the dynamic library.
//
// CLAP plugins standard search path:
//
// Linux
// - ~/.clap
// - /usr/lib/clap
//
// Windows
// - %COMMONPROGRAMFILES%\CLAP
// - %LOCALAPPDATA%\Programs\Common\CLAP
//
// MacOS
// - /Library/Audio/Plug-Ins/CLAP
// - ~/Library/Audio/Plug-Ins/CLAP
//
// In addition to the OS-specific default locations above, a CLAP host must query the environment
// for a CLAP_PATH variable, which is a list of directories formatted in the same manner as the host
// OS binary search path (PATH on Unix, separated by `:` and Path on Windows, separated by ';', as
// of this writing).
//
// Each directory should be recursively searched for files and/or bundles as appropriate in your OS
// ending with the extension `.clap`.
//
// init and deinit in most cases are called once, in a matched pair, when the dso is loaded / unloaded.
// In some rare situations it may be called multiple times in a process, so the functions must be defensive,
// mutex locking and counting calls if undertaking non trivial non idempotent actions.
//
// Rationale:
//
// The intent of the init() and deinit() functions is to provide a "normal" initialization patterh
// which occurs when the shared object is loaded or unloaded. As such, hosts will call each once and
// in matched pairs. In CLAP specifications prior to 1.2.0, this single-call was documented as a
// requirement.
//
// We realized, though, that this is not a requirement hosts can meet. If hosts load a plugin
// which itself wraps another CLAP for instance, while also loading that same clap in its memory
// space, both the host and the wrapper will call init() and deinit() and have no means to communicate
// the state.
//
// With CLAP 1.2.0 and beyond we are changing the spec to indicate that a host should make an
// absolute best effort to call init() and deinit() once, and always in matched pairs (for every
// init() which returns true, one deinit() should be called).
//
// This takes the de-facto burden on plugin writers to deal with multiple calls into a hard requirement.
//
// Most init() / deinit() pairs we have seen are the relatively trivial {return true;} and {}. But
// if your init() function does non-trivial one time work, the plugin author must maintain a counter
// and must manage a mutex lock. The most obvious implementation will maintain a static counter and a
// global mutex, increment the counter on each init, decrement it on each deinit, and only undertake
// the init or deinit action when the counter is zero.
Tclap_plugin_entry = record
clap_version: Tclap_version; // initialized to CLAP_VERSION
// Initializes the DSO.
//
// This function must be called first, before any-other CLAP-related function or symbol from this
// DSO.
//
// It also must only be called once, until a later call to deinit() is made, after which init()
// can be called once more to re-initialize the DSO.
// This enables hosts to e.g. quickly load and unload a DSO for scanning its plugins, and then
// load it again later to actually use the plugins if needed.
//
// As stated above, even though hosts are forbidden to do so directly, multiple calls before any
// deinit() call may still happen. Implementations *should* take this into account, and *must*
// do so as of CLAP 1.2.0.
//
// It should be as fast as possible, in order to perform a very quick scan of the plugin
// descriptors.
//
// It is forbidden to display graphical user interfaces in this call.
// It is forbidden to perform any user interaction in this call.
//
// If the initialization depends upon expensive computation, maybe try to do them ahead of time
// and cache the result.
//
// Returns true on success. If init() returns false, then the DSO must be considered
// uninitialized, and the host must not call deinit() nor any other CLAP-related symbols from the
// DSO.
// This function also returns true in the case where the DSO is already initialized, and no
// actual initialization work is done in this call, as explain above.
//
// plugin_path is the path to the DSO (Linux, Windows), or the bundle (macOS).
//
// This function may be called on any thread, including a different one from the one a later call
// to deinit() (or a later init()) can be made.
// However, it is forbidden to call this function simultaneously from multiple threads.
// It is also forbidden to call it simultaneously with *any* other CLAP-related symbols from the
// DSO, including (but not limited to) deinit().
//bool (*init)(const char *plugin_path);
init: function (plugin_path: PAnsiChar): boolean; cdecl;
// De-initializes the DSO, freeing any resources allocated or initialized by init().
//
// After this function is called, no more calls into the DSO must be made, except calling init()
// again to re-initialize the DSO.
// This means that after deinit() is called, the DSO can be considered to be in the same state
// as if init() was never called at all yet, enabling it to be re-initialized as needed.
//
// As stated above, even though hosts are forbidden to do so directly, multiple calls before any
// new init() call may still happen. Implementations *should* take this into account, and *must*
// do so as of CLAP 1.2.0.
//
// Just like init(), this function may be called on any thread, including a different one from
// the one init() was called from, or from the one a later init() call can be made.
// However, it is forbidden to call this function simultaneously from multiple threads.
// It is also forbidden to call it simultaneously with *any* other CLAP-related symbols from the
// DSO, including (but not limited to) deinit().