Major refactor of Poly and TGrains

I just pushed a major refactor of Poly and TGrains.

Poly:

I simplified the interface a bit. One no longer has to indicate the initial number of internal UGens and the max. It is now just one number. You can always increase the number of available voices by calling set_num_voices.

Poly is no longer 4 objects. It is just one.

The UGen now works like this:

Poly.next_trig - this is used for any situation where you are triggering UGens from a Mojo-side trigger. There are two versions of this function, one without a callback and one with.

Poly.next_mtrig - this is used for any situation where you are triggering UGens from Python. It should be paired with a PolyPal on the Python side. See the MidiSequencer example. There are different versions of this function depending on whether you are sending a Float, an Int, a list of floats or a list of ints.

Poly.next_gate - This may never be used, but it allows you to send a list of gate signals to the Poly to gate open synths. See TestPolyGate.mojo for an example

Poly.next_mgate - this is used for sending gates from Python to Mojo, like when making a polyphonic keyboard. It should be used with a PolyPal. There are two versions, one that receives ints and stores the gates in a dictionary indexed by ints. The other receives floats and stores the gates in a dictionary indexed as Strings.

TGrains:

The main update, but really the point of all this, is that by the magic of Traits, TGrains can now use a user-defined GrainObject. This means you can put filters and delays and such inside of the individual grains. There is an example called Grains_Custom.mojo (paired with Grains.py) that shows how this works. By default, TGrains will use Grain as its GrainObject, but you can define your own and use that. TGrains also now has user_defined envelopes, so any envelope definable in an Env is possible.

Let me know if there are any questions. This is a syntax change, but I don’t see this changing again in the future…

1 Like