Module polyGen
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 :
require "include/protoplug"
Functions
polyGen.initTracks ([n=8]) | Set up virtual tracks. |
Class polyGen.VTrack
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.i | Track number. |
polyGen.VTrack.note | Current MIDI note. |
polyGen.VTrack.noteFreq | Current note frequency. |
polyGen.VTrack.notePeriod | Current note period. |
polyGen.VTrack.noteIsOn | Note is on. |
Functions
- polyGen.initTracks ([n=8])
-
Set up virtual tracks.
This function must be called by any script that wishes to use this module.
Parameters:
- n the number of virtual tracks to use (aka. voices or polyphony) (default 8)
Class polyGen.VTrack
Virtual track. A monophonic voice that defines the instrument's sound.- polyGen.VTrack:addProcessBlock (samples, smax)
-
Override to additively process an audio block.
Define the output of a virtual track in this method.
Use
self.noteIsOn
,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
samples
.Parameters:
- samples
a C
float**
pointing to two channels of samples to add to. - smax the maximum sample index (nSamples - 1)
See also:
- 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.
Parameters:
- 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.
Parameters:
- 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.
- polyGen.VTrack.i
-
Track number.
Use
self.i
to check which virtual track is being called. - polyGen.VTrack.note
-
Current MIDI note.
The MIDI note number that is currently being played by this track,
or
-1
if in note off state. - polyGen.VTrack.noteFreq
- Current note frequency. The note frequency that is currently being played by this track.
- polyGen.VTrack.notePeriod
-
Current note period.
1/noteFreq
- polyGen.VTrack.noteIsOn
-
Note is on.
Whether the track is playing a note (
boolean
).