​processBlock
If processSample function is used, this function is ignored.
This is the main processing function to parse audio and MIDI data. It also receives input parameters values for start and end of the current block, as well as transport info.​
Gain example
- // we'll keep gain value here (0..1 to decrease gain, >1 to increase gain)
- double gain = 0.5;
- // main processing function
- // parse block of samples
- for(uint i = 0; i<data.samplesToProcess; i++) {
- // loop through all channels for current sample
- for(uint ch = 0; ch < audioOutputsCount; ch++) {
- data.samples[ch][i] *= gain;
- }
- }
- }
Input parameters
Note that in comparison to using processSample, here updateInputParameters will be called only once per block (if input parameters change at all). See examples in: "How to make a gain plugin".
MIDI filter example
- // include MIDI helpers
- #include "../library/Midi.hxx"
- // process MIDI messages
- // parse all incoming MIDI events
- for(uint i=0;i<data.inputMidiEvents.length;i++) {
- // get MIDI event type
- MidiEventType type = MidiEventUtils::getType(data.inputMidiEvents[i]);
- if(type == kMidiNoteOn || type == kMidiNoteOff) {
- // pass through only Note On and Off events
- data.outputMidiEvents.push(data.inputMidiEvents[i]);
- }
- }
- }
Transport example
- // accessing transport info if available
- if (@data.transport != null) {
- bool isPlaying = data.transport.isPlaying;
- double bpm = data.transport.bpm;
- double posInSeconds = data.transport.positionInSeconds;
- // print("isPlaying: " + isPlaying + " bpm: " + bpm + " pos: " + posInSeconds);
- }
- }
Note that for C++ API you would use a slighly different syntax:
- if (data.transport != null) {
- bool isPlaying = data.transport->isPlaying;
- double bpm = data.transport->bpm;
- // ... etc
- }
- }
Data structure
Inside processBlock you can access audio samples, MIDI, transport, and input parameters using the data object.
Audio
- data.samplesToProcess // (uint) number of samples in the current block
- data.samples[channel][sampleIndex] // (double) values of samples
MIDI
- data.inputMidiEvents[midiEventIndex] // input MIDI messages (read-only)
- data.outputMidiEvents // you can .push output MIDI events here
For more examples on parsing MIDI see included scripts.
Transport information
- // is playing or recording
- data.transport.isPlaying // (bool) is host application playing
- data.transport.isRecording // (bool) is host application recording
- // tempo and time signature
- data.transport.bpm // (double) current tempo (beats per minute)
- data.transport.timeSigTop // (uint) upper value of time signature (3 for 3/4)
- data.transport.timeSigBottom // (uint) lower value of time signature (4 for 3/4)
- // position in song
- data.transport.positionInSamples // (int64) position in samples of the first sample of the current block since the beginning of the song
- data.transport.positionInQuarterNotes // (double) position in quarter notes of the first sample of the current block since the beginning of the song
- data.transport.positionInSeconds // (double) position in seconds of the first sample of the current block since the beginning of the song
- data.transport.currentMeasureDownBeat // (double) position in quarter notes of the first bar of the current measure
- // loop-related
- data.transport.isLooping // (bool) is host application in a loop
- data.transport.loopStart // (double) pos in quarter notes of the beginning of the loop
- data.transport.loopEnd // (double) position in quarter notes of the end of the loop
Input parameters
You get parameter values for the beginning and end of the current block, so you can interpolate them manually if you need.
- data.beginParamValues[PARAM_INDEX] // values for the beginning of block
- data.endParamValues[PARAM_INDEX] // values for the end of the block
- // example on how to get parameter change delta for every sample
- double paramDelta = (data.endParamValues[PARAM_INDEX] - data.beginParamValues[PARAM_INDEX]) / data.samplesToProcess;