Skip to content

Commit f4a33f5

Browse files
author
Nathan Ho
committed
Merge branch 'master' of github.com:snappizz/plugin-example
2 parents 405acf0 + fb19710 commit f4a33f5

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

01-BoringMixer/BoringMixer.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,52 @@
11
#include "SC_PlugIn.h"
22

3+
// InterfaceTable contains pointers to functions in the host (server).
34
static InterfaceTable *ft;
45

6+
// declare struct to hold unit generator state
57
struct BoringMixer : public Unit {
8+
// in later examples, we will declare state variables here.
69
};
710

8-
static void BoringMixer_next(BoringMixer *unit, int inNumSamples);
11+
// older plugins wrap these function declarations in 'extern "C" { ... }'
12+
// no need to do that these days.
13+
static void BoringMixer_next(BoringMixer* unit, int inNumSamples);
914
static void BoringMixer_Ctor(BoringMixer* unit);
1015

16+
// the constructor function is called when a Synth containing this ugen is played.
17+
// it MUST be named "PluginName_Ctor", and the argument must be "unit."
1118
void BoringMixer_Ctor(BoringMixer* unit) {
19+
// in later examples, we will initialize state variables here.
20+
21+
// set a calculation function. for now, we only have one calculation function.
1222
SETCALC(BoringMixer_next);
23+
// calculate one sample of output.
24+
// this allows plugging into other ugens with initial-rate inputs
1325
BoringMixer_next(unit, 1);
1426
}
1527

28+
// the calculation function can have any name, but this is conventional. the first argument must be "unit."
29+
// this function is called every control period (64 samples is typical)
30+
// Don't change the names of the arguments, or the helper macros won't work.
1631
void BoringMixer_next(BoringMixer* unit, int inNumSamples) {
1732

18-
float *left = IN(0);
19-
float *right = IN(1);
20-
float *out = OUT(0);
33+
// IN and OUT are helper macros that return audio-rate input and output buffers.
34+
// In old ugens you'll see ZIN and ZOUT, which are not recommended.
35+
float *left = IN(0); // first input
36+
float *right = IN(1); // second input
37+
float *out = OUT(0); // first output
2138

39+
// Loop through samples and do the computation.
2240
for (int i = 0; i < inNumSamples; i++) {
2341
out[i] = (left[i] + right[i]) * 0.5;
2442
}
2543
}
2644

45+
// the entry point is called by the host when the plug-in is loaded
2746
PluginLoad(BoringMixerUGens) {
28-
ft = inTable;
47+
// InterfaceTable *inTable implicitly given as argument to the load function
48+
ft = inTable; // store pointer to InterfaceTable
49+
// DefineSimpleUnit is one of four macros defining different kinds of ugens.
50+
// In later examples involving memory allocation, we'll see DefineDtorUnit.
2951
DefineSimpleUnit(BoringMixer);
30-
}
52+
}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
This is a series of examples demonstrating how to write SuperCollider plugins.
1+
This repository a series of examples demonstrating how to write server plugins for [SuperCollider](https://github.com/supercollider/supercollider) (not to be confused with quarks, which are libraries for the language).
2+
3+
Beyond this repository, the reader is encouraged to look at [sc3-plugins](https://github.com/supercollider/sc3-plugins) for more complex, real-world examples.
24

35
## Compiling
46

0 commit comments

Comments
 (0)