How VST (AU, AAX) plugins work
When you start making a plugin in Plug'n Script you should understand that it's not a solid application like you may expect, it's more like two (at least) separate parts running independently and communicating with each other.
- the part that is processing audio or MIDI, let's call it DSP (Digital Signal Processing).
- the part that you see on the screen with all the controls, knobs, meters, etc - the GUI (Graphical User Interface)
In some plugin formats, these parts are more connected, in some, they are more separated, but if we talk about Plug'n Script, as it abstracts us from exact plugin format, we have it like that.
The DSP part is running when the DAW is calling it. And the main function the DAW is calling is processBlock, which receives the current block of data (audio samples, MIDI data), processes it, and returns back to DAW. The size of this block (in samples) depends on the (ASIO) buffer settings the user has set. So if the buffer size is set to 1024 samples and the sample rate is 48000, the DSP's processBlock function will be usually called 46-47 times a second. (*Some DAWs can split audio buffer into smaller chunks during automation or under other conditions, so in that case processBlock will be called more often).
The DSP has to be really quick and efficient, cause usually there are many plugins to run, so it should not be blocked by GUI or other time-consuming things, like memory allocation, synchronous disk or network access, etc. It should be independent and as quick as possible, so it just grabs the block of data, calculates/processes it, returns back, and sleeps until the next block.
Just a note
There are some other functions in the Plug'n Script API that are also called regularly (but usually within processBlock call), for example, updateInputParametersForBlock which is called when some input parameter has changed, so we can recalculate our processing variables based on new input values.
The GUI part on the other hand has to run when the user opens the plugin window. GUI should be nice and responsive, and if this window is closed, so the plugin just works in the background, the GUI in Plug'n Script is "dead" and doesn't take any CPU.
GUI and DSP parts in PnS communicate with help of parameters (floating-point values) and strings (text data). In Plug'n Script you can have up to 48 input parameters (they transfer data from GUI to DSP, and can be connected to controls like knobs, sliders, etc) and up to 32 output parameters (they transfer data from DSP to GUI - so we can display some output information like levels, gain reduction, etc). These input/output parameters are also "visible" to the DAW and to the user, so their automation can be recorded in the DAW.
There are also 16 input and 16 output strings, that can be used to transfer data between DSP and GUI. The strings can be large, so you can send big chunks from DSP to GUI via output strings, for example. Or if you make a really complex plugin and need more than 48 input params, you can use input strings to send more data from GUI to DSP (though it cannot be recorded and automated in the DAW).
Keep in mind
When you update a parameter value in GUI (turn the knob), the DSP doesn't immediately receive it, and vice versa, because these parts access the data model independently and are not synchronized. Though it happens fast (depends on the block size and few other factors), but not immediately.
That is basically how these parts communicate.