PLUG'N SCRIPT
rapid plugin development
Tutorial
DSP
KUIML
How-to
Scripts
Main functions
  • processBlock
  • processSample
  • updateInputParameters
  • updateInputParametersForBlock
  • computeOutputData
Additional
  • initialize
  • reset
  • shutdown
DSPprocessBlock
June 14, 2020

​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

  1. // we'll keep gain value here (0..1 to decrease gain, >1 to increase gain)
  2. double gain = 0.5;
  3.  
  4. // main processing function
  5. void processBlock(BlockData& data) {
  6. // parse block of samples
  7. for(uint i = 0; i<data.samplesToProcess; i++) {
  8. // loop through all channels for current sample
  9. for(uint ch = 0; ch < audioOutputsCount; ch++) {
  10. data.samples[ch][i] *= gain;
  11. }
  12. }
  13. }

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

  1. // include MIDI helpers
  2. #include "../library/Midi.hxx"
  3.  
  4. // process MIDI messages
  5. void processBlock(BlockData& data) {
  6. // parse all incoming MIDI events
  7. for(uint i=0;i<data.inputMidiEvents.length;i++) {
  8. // get MIDI event type
  9. MidiEventType type = MidiEventUtils::getType(data.inputMidiEvents[i]);
  10. if(type == kMidiNoteOn || type == kMidiNoteOff) {
  11. // pass through only Note On and Off events
  12. data.outputMidiEvents.push(data.inputMidiEvents[i]);
  13. }
  14. }
  15. }

Transport example

  1. void processBlock(BlockData& data) {
  2. // accessing transport info if available
  3. if (@data.transport != null) {
  4. bool isPlaying = data.transport.isPlaying;
  5. double bpm = data.transport.bpm;
  6. double posInSeconds = data.transport.positionInSeconds;
  7. // print("isPlaying: " + isPlaying + " bpm: " + bpm + " pos: " + posInSeconds);
  8. }
  9. }

Note that for C++ API you would use a slighly different syntax:

  1. DSP_EXPORT void processBlock(BlockData& data) {
  2. if (data.transport != null) {
  3. bool isPlaying = data.transport->isPlaying;
  4. double bpm = data.transport->bpm;
  5. // ... etc
  6. }
  7. }

Data structure

Inside processBlock you can access audio samples, MIDI, transport, and input parameters using the data object.

Audio

  1. data.samplesToProcess // (uint) number of samples in the current block
  2. data.samples[channel][sampleIndex] // (double) values of samples

MIDI

  1. data.inputMidiEvents[midiEventIndex] // input MIDI messages (read-only)
  2. data.outputMidiEvents // you can .push output MIDI events here

For more examples on parsing MIDI see included scripts.

Transport information

  1. // is playing or recording
  2. data.transport.isPlaying // (bool) is host application playing
  3. data.transport.isRecording // (bool) is host application recording
  4.  
  5. // tempo and time signature
  6. data.transport.bpm // (double) current tempo (beats per minute)
  7. data.transport.timeSigTop // (uint) upper value of time signature (3 for 3/4)
  8. data.transport.timeSigBottom // (uint) lower value of time signature (4 for 3/4)
  9.  
  10. // position in song
  11. data.transport.positionInSamples // (int64) position in samples of the first sample of the current block since the beginning of the song
  12. data.transport.positionInQuarterNotes // (double) position in quarter notes of the first sample of the current block since the beginning of the song
  13. data.transport.positionInSeconds // (double) position in seconds of the first sample of the current block since the beginning of the song
  14. data.transport.currentMeasureDownBeat // (double) position in quarter notes of the first bar of the current measure
  15.  
  16. // loop-related
  17. data.transport.isLooping // (bool) is host application in a loop
  18. data.transport.loopStart // (double) pos in quarter notes of the beginning of the loop
  19. 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.

  1. data.beginParamValues[PARAM_INDEX] // values for the beginning of block
  2. data.endParamValues[PARAM_INDEX] // values for the end of the block
  3.  
  4. // example on how to get parameter change delta for every sample
  5. double paramDelta = (data.endParamValues[PARAM_INDEX] - data.beginParamValues[PARAM_INDEX]) / data.samplesToProcess;

 


Comments

2020 © Plug'n Script and KUIML by Blue Cat Audio  |  Site by LetiMix