Use this module to create a polyphonic generator with virtual tracks.
Example at sine-organ.lua.
This module facilitates the creation of polyphonic instruments. It acts as a layer that covers the plugin.processBlock function, receives MIDI notes and dispatches them to virtual tracks. The polyGen.VTrack prototype is exposed for you to define audio processing in a simple, monophonic, per-note fashion. Initialize this module by calling polyGen.initTracks .
The polyGen global is available to every protoplug script after including the main protoplug header :
|polyGen.initTracks ([n=8])||Set up virtual tracks.|
|polyGen.VTrack:addProcessBlock (samples, smax)||Override to additively process an audio block.|
|polyGen.VTrack:noteOn (note, vel)||Override to recieve note on.|
|polyGen.VTrack:noteOff (note)||Override to recieve note off.|
|polyGen.VTrack:init ()||Override to allow initialisation.|
|polyGen.VTrack.note||Current MIDI note.|
|polyGen.VTrack.noteFreq||Current note frequency.|
|polyGen.VTrack.notePeriod||Current note period.|
|polyGen.VTrack.noteIsOn||Note is on.|
- polyGen.initTracks ([n=8])
Set up virtual tracks.
This function must be called by any script that wishes to use this module.
- n the number of virtual tracks to use (aka. voices or polyphony) (default 8)
- polyGen.VTrack:addProcessBlock (samples, smax)
Override to additively process an audio block.
Define the output of a virtual track in this method.
self.noteFreq, or any fields you defined to determine current the state of the calling track.
This method is called successively on every track, which should add their output to
float**pointing to two channels of samples to add to.
- smax the maximum sample index (nSamples - 1)
- samples a C
- polyGen.VTrack:noteOn (note, vel)
Override to recieve note on.
Override this method to handle a note getting dispatched to a virtual track.
- note the MIDI note number (0-127)
- vel the MIDI velocity (0-127)
- polyGen.VTrack:noteOff (note)
Override to recieve note off.
Override this method to handle a note off on a virtual track.
- note a reminder of the MIDI note number
- polyGen.VTrack:init ()
- Override to allow initialisation. Override this method to perform initialisation tasks on each track, for example to create any per-track fields.
self.ito check which virtual track is being called.
Current MIDI note.
The MIDI note number that is currently being played by this track,
-1if in note off state.
- Current note frequency. The note frequency that is currently being played by this track.
Current note period.
Note is on.
Whether the track is playing a note (