Skip to content

Polyphony

Traits

trait PolyObject

PolyObject Required Methods

trait PolyObject . fn init

Create a new instance of the value by copying an existing one.

Signature

def __init__(out self: _Self, *, copy: _Self)

Arguments

  • copy: _Self - The value to copy. Returns

Type: _Self


Create a new instance of the value by moving the value of another.

Signature

def __init__(out self: _Self, *, deinit move: _Self)

Arguments

  • move: _Self - The value to move. Returns

Type: _Self


trait PolyObject . fn check_active

A required, user defined function to check if the voice is active. This is usually done by checking if the envelope is active or if the Line has reached its end. This function is used internally by Poly to keep track of which voices are active and which are not.

Signature

def check_active(mut self: _Self) -> Bool

Returns

Type: Bool True when the voice is active, otherwise False.


trait PolyObject . fn set_trigger

Necessary for PolyObjects that use next_trig or next_mtrig. This function is used internally by Poly to set the PolyObject to triggered. That way, the PolyObject can open its own envelope or trigger other parameters in the subsequent next call.

Usually the function will just be:

self.trigger = trigger

but there might also be some values reset if trigger is True

Signature

def set_trigger(mut self: _Self, trigger: Bool)

Arguments

  • trigger: Bool - When this is True, the PolyObject should set its self.trigger to true and reset any variable that need to be reset.

Default Implementation

This method has a default implementation.


trait PolyObject . fn set_gate

Necessary for PolyObjects that use next_gate or next_mgate. This function is used internally by Poly to open and close the gate of the PolyObject.

Usually the function will just be:

self.gate = gate

Signature

def set_gate(mut self: _Self, gate: Bool)

Arguments

  • gate: Bool - When this is True, the PolyObject should open its gate. When this is False, the PolyObject should close its gate.

Default Implementation

This method has a default implementation.


trait PolyObject . fn reset_Resettable

Goes through every object inside of a PolyObject, checks if the object confroms to the PolyReset trait, and if it does, calls the reset function of that object.

Objects that conform to the PolyReset trait usually need to be reset if a PolyObject is stopped and started. Delays and filters are obvious examples of this. They will have residual information in them when they are stopped, and that information needs to be cleared before the next time they are started.

Signature

def reset_Resettable(mut self: _Self)

Default Implementation

This method has a default implementation.


trait PolyReset

A trait for UGens that need to be reset when a Poly voice is triggered or released. If a UGen implements this trait.

PolyReset Required Methods

trait PolyReset . fn reset

A function called when a voice needs to be reset.

Signature

def reset(mut self: _Self)

trait GrainObject

Trait for objects that can be used as grains in the TGrains struct for triggered granular synthesis.

GrainObject Required Methods

trait GrainObject . fn init

Initialize a GrainObject implementation.

Signature

def __init__(out self: _Self, world: UnsafePointer[MMMWorld, MutUntrackedOrigin])

Arguments

  • world: UnsafePointer[MMMWorld, MutUntrackedOrigin] - Pointer to the MMMWorld instance. Returns

Type: _Self


Create a new instance of the value by copying an existing one.

Signature

def __init__(out self: _Self, *, copy: _Self)

Arguments

  • copy: _Self - The value to copy. Returns

Type: _Self


Create a new instance of the value by moving the value of another.

Signature

def __init__(out self: _Self, *, deinit move: _Self)

Arguments

  • move: _Self - The value to move. Returns

Type: _Self


trait GrainObject . fn next_2

This is the function to create if you want to output 2 channels using pan2 or pan_stereo.

Signature

def next_2[num_buf_chans: Int, num_playback_chans: Int = 2, win_type: WindowType = WindowType.hann, custom_curve: WindowType = WindowType.none, bWrap: Bool = False](mut self: _Self, buffer: SIMDBuffer[num_buf_chans]) -> SIMD[DType.float64, 2]

Parameters

  • num_buf_chans: Int - Number of channels in the source buffer. This is inferred at compile time based on the channel count of the SIMDBuffer that is passed in.- num_playback_chans: Int - Number of source channels to play back before panning.- win_type: WindowType - Window type applied to the grain.- custom_curve: WindowType - Optional custom curve for user-defined envelopes.- bWrap: Bool - Whether reads wrap around the source buffer. Arguments

  • buffer: SIMDBuffer[num_buf_chans] - Source buffer for grain playback. Returns

Type: SIMD[DType.float64, 2] The next stereo grain sample.

Default Implementation

This method has a default implementation.


trait GrainObject . fn next_multi_channel

Get the next sample of the grain as a multi-channel signal. By default, Grain uses azimuth panning with a width of 2.0 and an orientation of 0.5. However, you can use dbap or any other panning algorithm by creating a custom grain with its own next_multi_channel function. This only pans 1 channel of the buffer, specified by buffer_chan. See next_2 for param/arg descriptions.

Signature

def next_multi_channel[num_buf_chans: Int, num_speakers: Int = 2, num_simd_chans: Int = 2, win_type: WindowType = WindowType.hann, custom_curve: WindowType = WindowType.none, bWrap: Bool = False](mut self: _Self, buffer: SIMDBuffer[num_buf_chans], buffer_chan: Int = 0) -> SIMD[DType.float64, num_simd_chans]

Parameters

  • num_buf_chans: Int - The number of channels in the buffer. This is inferred at compile time based on the channel count of the SIMDBuffer that is passed in.- num_speakers: Int - The number of speakers in the system. This is used for calculating the azimuth panning.- num_simd_chans: Int - The number of channels in the output sample. This must be a power of two and should be greater than or equal to num_speakers. If num_simd_chans is greater than num_speakers, the extra channels will just be 0.0.- win_type: WindowType - The type of window to apply to the grain. A hann window is used by default, and will give the classic granular synthesis sound. If win_type is WindowType.user_defined, then the user_defined_env (Env) will be used as the window.- custom_curve: WindowType - If win_type is WindowType.user_defined, applies a custom curve to the user defined envelope. This is the win_type parameter of the Env next function.- bWrap: Bool - Whether to wrap around the buffer when reading. If false, the grain will read 0 when it reaches the end of the buffer. If true, the grain will wrap around to the beginning of the buffer when it reaches the end. Arguments

  • buffer: SIMDBuffer[num_buf_chans] - A SIMDBuffer to read from.- buffer_chan: Int = 0 - The channel of the buffer to read from for panning. This should be less than num_buf_chans. Returns

Type: SIMD[DType.float64, num_simd_chans] A multi-channel sample of the grain with azimuth panning applied.

Default Implementation

This method has a default implementation.


trait GrainObject . fn next_all

Get the next sample of the grain. This function returns all channels of the buffer with no panning.

Signature

def next_all[num_chans: Int, win_type: WindowType = WindowType.hann, custom_curve: WindowType = WindowType.none, bWrap: Bool = False](mut self: _Self, buffer: SIMDBuffer[num_chans]) -> SIMD[DType.float64, num_chans]

Parameters

  • num_chans: Int - The number of channels in the buffer. This is inferred at compile time based on the channel count of the SIMDBuffer that is passed in.- win_type: WindowType - The type of window to apply to the grain. A hann window is used by default, and will give the classic granular synthesis sound. If win_type is WindowType.user_defined, then the user_defined_env (env) will be used as the window.- custom_curve: WindowType - If win_type is WindowType.user_defined, applies a custom curve to the user defined envelope. This is the win_type parameter of the Env next function.- bWrap: Bool - Whether to wrap around the buffer when reading. If false, the grain will read 0 when it reaches the end of the buffer. If true, the grain will wrap around to the beginning of the buffer when it reaches the end. Arguments

  • buffer: SIMDBuffer[num_chans] - A SIMDBuffer to read from. Returns

Type: SIMD[DType.float64, num_chans] A multi-channel sample of the grain. The number of channels is the same as the number of channels in the buffer.

Default Implementation

This method has a default implementation.


trait GrainObject . fn set_env_trigger

Sets the envelope trigger for the internal grain. This sets the value so that the next time the grain's next function is called, the grain will know to trigger or not trigger the envelope.

Should probably just be: self.grain.set_env_trigger(trigger).

Signature

def set_env_trigger(mut self: _Self, trigger: Bool)

Arguments

  • trigger: Bool - Sets the envelope trigger for the internal grain to True or False.

Default Implementation

This method has a default implementation.


trait GrainObject . fn get_env_trigger

Checks the root grain to see if it has been triggered. Should probably just be: return self.grain.get_env_trigger().

Signature

def get_env_trigger(mut self: _Self) -> Bool

Returns

Type: Bool True if the grain has been triggered, otherwise False.

Default Implementation

This method has a default implementation.


trait GrainObject . fn set_user_defined_env

Should probably just be: self.grain.set_user_defined_env(env_points).

Signature

def set_user_defined_env(mut self: _Self, env_points: Span[Tuple[Float64, Float64]])

Arguments

  • env_points: Span[Tuple[Float64, Float64]] - A list of (time, value) tuples that define the user defined envelope. The times and values should be between 0 and 1.

trait GrainObject . fn set_play_rate

Set the play ratio of the grain. Normally a grain is triggered with a set playback speed, but this function allows you to change the playback speed of the grain after it has been triggered.

Signature

def set_play_rate(mut self: _Self, ratio: Float64)

Arguments

  • ratio: Float64 - The play ratio of the grain.

Default Implementation

This method has a default implementation.


trait GrainObject . fn reset

Reset the grain to its initial state. This can be used to retrigger the grain with the same parameters.

Signature

def reset(mut self: _Self)

Default Implementation

This method has a default implementation.


trait GrainObject . fn check_active

A required, user defined function to check if the voice is active. This is usually done by checking if the envelope is active or if the Line has reached its end. This function is used internally by Poly to keep track of which voices are active and which are not.

Signature

def check_active(mut self: _Self) -> Bool

Returns

Type: Bool True when the voice is active, otherwise False.


trait GrainObject . fn set_trigger

Necessary for PolyObjects that use next_trig or next_mtrig. This function is used internally by Poly to set the PolyObject to triggered. That way, the PolyObject can open its own envelope or trigger other parameters in the subsequent next call.

Usually the function will just be:

self.trigger = trigger

but there might also be some values reset if trigger is True

Signature

def set_trigger(mut self: _Self, trigger: Bool)

Arguments

  • trigger: Bool - When this is True, the PolyObject should set its self.trigger to true and reset any variable that need to be reset.

Default Implementation

This method has a default implementation.


trait GrainObject . fn set_gate

Necessary for PolyObjects that use next_gate or next_mgate. This function is used internally by Poly to open and close the gate of the PolyObject.

Usually the function will just be:

self.gate = gate

Signature

def set_gate(mut self: _Self, gate: Bool)

Arguments

  • gate: Bool - When this is True, the PolyObject should open its gate. When this is False, the PolyObject should close its gate.

Default Implementation

This method has a default implementation.


trait GrainObject . fn reset_Resettable

Goes through every object inside of a PolyObject, checks if the object confroms to the PolyReset trait, and if it does, calls the reset function of that object.

Objects that conform to the PolyReset trait usually need to be reset if a PolyObject is stopped and started. Delays and filters are obvious examples of this. They will have residual information in them when they are stopped, and that information needs to be cleared before the next time they are started.

Signature

def reset_Resettable(mut self: _Self)

Default Implementation

This method has a default implementation.


Structs

struct Poly

A Poly implementation for synths triggered by signals, like TGrains and PitchShift.

Traits: AnyType, Copyable, ImplicitlyDeletable, Movable


Poly Functions

struct Poly . fn init

Initialize the Poly.

fn init Signature

def __init__(out self, world: UnsafePointer[MMMWorld, MutUntrackedOrigin], num_voices: Int, namespace: Optional[String] = None)

fn init Arguments

Name Type Default Description
world UnsafePointer[MMMWorld, MutUntrackedOrigin] Pointer to the MMMWorld instance.
num_voices Int The number of voices in the Poly object. This is the maximum number of voices that can be active at once. If all voices are active and a new trigger is received, the trigger will be ignored. You can increase the number of voices with the set_num_voices function, but you cannot decrease the number of voices after initialization.
namespace Optional[String] None Optional message namespace for the internal Messenger.

fn init Returns : Self

Static Method

This is a static method.

struct Poly . fn set_num_voices

This function can be used to change the number of voices that the Poly can use. If more voices are needed than the initial number, you can increase the number of voices with this function.

fn set_num_voices Signature

def set_num_voices(mut self, new_num_voices: Int)

fn set_num_voices Arguments

Name Type Default Description
new_num_voices Int The new number of voices for the Poly. This can only be increased, not decreased. If the new number of voices is less than the current number of voices, this function will do nothing.

struct Poly . fn next_trig

Looks at the value of trig. If trig is True, looks for a free voice and triggers it. Returns the index of the voice that was triggered, or -1 if no voice was triggered.

fn next_trig Signature

def next_trig[T: PolyObject](mut self, mut poly_objects: List[T], trig: Bool) -> Int

fn next_trig Parameters

Name Type Default Description
T PolyObject This value is inferred at compile time based on the type of the poly_objects list. This is the type of the PolyObjects that are being triggered.

fn next_trig Arguments

Name Type Default Description
poly_objects List[T] A list of structs conforming to the PolyObject trait. The Poly will look for a free voice in this list and trigger it when trig is True.
trig Bool A boolean value that triggers a voice when it is True.

fn next_trig Returns : Int The index of the voice that was triggered, or -1 if no voice was triggered.

struct Poly . fn next_trig

fn next_trig Signature

def next_trig[T: PolyObject](mut self, mut poly_objects: List[T], trig: Bool, call_back: def(mut poly_object: T, trig: Bool) capturing -> None) -> Int

fn next_trig Parameters

Name Type Default Description
T PolyObject

fn next_trig Arguments

Name Type Default Description
poly_objects List[T]
trig Bool
call_back def(mut poly_object: T, trig: Bool) capturing -> None

fn next_trig Returns : Int

struct Poly . fn next_mtrig

Convenience function triggered by Python messages. This convenience function achieves all functionality of a Poly that is being triggered by messages from Python. It resets the Poly at the beginning of each block, looks for triggers from Python, and triggers PolyObjects as needed.

The optional call_back function is called whenever a new trigger is received from Python. next_mtrig has to be paired with messages sent from Python as a List[Int], List[Float64], Int, or Float64. The call_back function receives the List or value so the PolyObject can be controlled by the message from Python.

fn next_mtrig Signature

def next_mtrig[T: PolyObject, call_back: def(mut poly_object: T, mut vals: List[Int]) capturing -> None](mut self, mut poly_objects: List[T])

fn next_mtrig Parameters

Name Type Default Description
T PolyObject The type of the PolyObjects that are being triggered. Inferred at compile
time based on the type of the poly_objects list.
call_back def(mut poly_object: T, mut vals: List[Int]) capturing -> None A function called whenever a new trigger is received from Python
used to control the parameters of the triggered PolyObject.
Args:
    poly_object: The specific PolyObject instance being controlled.
    vals: The runtime trigger message parameters sent from Python.

There are four versions of next_mtrig differentiated by the type of this
`vals` parameter (List[Int], List[Float64], Int, or Float64) paired with
send_ints, send_floats, send_int, and send_float on the Python side. |

fn next_mtrig Arguments

Name Type Default Description
poly_objects List[T] A list of structs conforming to the PolyObject trait. This is
the list of PolyObjects that we are controlling.

struct Poly . fn next_mtrig

fn next_mtrig Signature

def next_mtrig[T: PolyObject, call_back: def(mut poly_object: T, mut vals: List[Float64]) capturing -> None](mut self, mut poly_objects: List[T])

fn next_mtrig Parameters

Name Type Default Description
T PolyObject
call_back def(mut poly_object: T, mut vals: List[Float64]) capturing -> None

fn next_mtrig Arguments

Name Type Default Description
poly_objects List[T]

struct Poly . fn next_mtrig

fn next_mtrig Signature

def next_mtrig[T: PolyObject, call_back: def(mut poly_object: T, mut val: Int) capturing -> None](mut self, mut poly_objects: List[T])

fn next_mtrig Parameters

Name Type Default Description
T PolyObject
call_back def(mut poly_object: T, mut val: Int) capturing -> None

fn next_mtrig Arguments

Name Type Default Description
poly_objects List[T]

struct Poly . fn next_mtrig

fn next_mtrig Signature

def next_mtrig[T: PolyObject, call_back: def(mut poly_object: T, mut val: Float64) capturing -> None](mut self, mut poly_objects: List[T])

fn next_mtrig Parameters

Name Type Default Description
T PolyObject
call_back def(mut poly_object: T, mut val: Float64) capturing -> None

fn next_mtrig Arguments

Name Type Default Description
poly_objects List[T]

struct Poly . fn next_gate

This function is designed to be used with polyphonic synths that have gated controls that are signals.

fn next_gate Signature

def next_gate[T: PolyObject](mut self, mut poly_objects: List[T], gate_sigs: List[Bool]) -> Int

fn next_gate Parameters

Name Type Default Description
T PolyObject The PolyObject type stored in poly_objects.

fn next_gate Arguments

Name Type Default Description
poly_objects List[T] A list of structs conforming to the PolyObject trait. This function calls the set_gate function for each PolyObject to open and close the gates as needed.
gate_sigs List[Bool] A list of boolean signals that control the gates of the voices. This number should be less than or equal to the number of voices in the Poly. Remember that even if a gate is closed that does not mean the voice is free. The voice is free when the envelope or Line of the voice is finished and the check_active function returns False again. Plan the number of gates and voices accordingly.

fn next_gate Returns : Int The index of the voice whose gate was opened, or -1 if no voice was opened.

struct Poly . fn next_mgate

This function is designed to be used with polyphonic synths that have gated controls that are controlled by messages from Python. There are two versions of next_mgate, one that receives messages as a List[Int] and one that receives messages as a List[Float64]. The type of the message is differentiated by the type of the vals parameter in the call_back function. The call_back function is called whenever a new message is received from Python.

fn next_mgate Signature

def next_mgate[T: PolyObject, call_back: def(mut poly_object: T, mut vals: List[Int]) capturing -> None](mut self, mut poly_objects: List[T])

fn next_mgate Parameters

Name Type Default Description
T PolyObject This value is inferred at compile time based on the type of the poly_objects list. This is the type of the PolyObjects that are being triggered.
call_back def(mut poly_object: T, mut vals: List[Int]) capturing -> None A function that is called whenever a new trigger is received from Python. This can be used to control the parameters of the triggered PolyObject with the message from Python. The type of the message from Python is differentiated by the type of the vals parameter in the call_back function. The type can be a List[Int], a List[Float64], which is paired with send_ints and send_floats respectively on the Python side. The call_back function receives the List or value so the PolyObject can be controlled by the message from Python.

fn next_mgate Arguments

Name Type Default Description
poly_objects List[T] A list of structs conforming to the PolyObject trait. This function calls the set_gate function for each PolyObject to open and close the gates as needed.

struct Poly . fn next_mgate

fn next_mgate Signature

def next_mgate[T: PolyObject, call_back: def(mut poly_object: T, mut vals: List[Float64]) capturing -> None](mut self, mut poly_objects: List[T])

fn next_mgate Parameters

Name Type Default Description
T PolyObject
call_back def(mut poly_object: T, mut vals: List[Float64]) capturing -> None

fn next_mgate Arguments

Name Type Default Description
poly_objects List[T]

struct Poly . fn find_voice_and_trigger

fn find_voice_and_trigger Signature

def find_voice_and_trigger[T: PolyObject](mut self, mut poly_objects: List[T], trig: Bool) -> Int

fn find_voice_and_trigger Parameters

Name Type Default Description
T PolyObject

fn find_voice_and_trigger Arguments

Name Type Default Description
poly_objects List[T]
trig Bool

fn find_voice_and_trigger Returns : Int

struct GrainAll

A single grain for granular synthesis. Returns all channels of a SIMDBuffer and does no panning.

Used as part of the TGrains and the PitchShift structs for triggered granular synthesis. It is also used internally by Grain or any custom GrainObject created by the user.

Traits: AnyType, Copyable, GrainObject, ImplicitlyDeletable, Movable, PolyObject


GrainAll Functions

struct GrainAll . fn init

fn init Signature

def __init__(out self, world: UnsafePointer[MMMWorld, MutUntrackedOrigin])

fn init Arguments

Name Type Default Description
world UnsafePointer[MMMWorld, MutUntrackedOrigin]

fn init Returns : Self

Static Method

This is a static method.

struct GrainAll . fn check_active

fn check_active Signature

def check_active(mut self) -> Bool

fn check_active Returns : Bool

struct GrainAll . fn set_trigger

fn set_trigger Signature

def set_trigger(mut self, trigger: Bool)

fn set_trigger Arguments

Name Type Default Description
trigger Bool

struct GrainAll . fn set_env_trigger

fn set_env_trigger Signature

def set_env_trigger(mut self, trigger: Bool)

fn set_env_trigger Arguments

Name Type Default Description
trigger Bool

struct GrainAll . fn get_env_trigger

fn get_env_trigger Signature

def get_env_trigger(self) -> Bool

fn get_env_trigger Returns : Bool

struct GrainAll . fn set_user_defined_env

fn set_user_defined_env Signature

def set_user_defined_env(mut self, env_points: Span[Tuple[Float64, Float64]])

fn set_user_defined_env Arguments

Name Type Default Description
env_points Span[Tuple[Float64, Float64]]

struct GrainAll . fn set_vals

Set the Grain's variables.

fn set_vals Signature

def set_vals(mut self, rate: Float64 = 1, start_frame: Int = 0, duration: Float64 = 0, pan: Float64 = 0, gain: Float64 = 1, curve: Float64 = 1)

fn set_vals Arguments

Name Type Default Description
rate Float64 1 Playback rate of the grain (1.0 = normal speed).
start_frame Int 0 Starting frame position in the buffer.
duration Float64 0 Duration of the grain in seconds.
pan Float64 0 Panning position from -1.0 (left) to 1.0 (right). As this function is used by the panning functions, the pan value is saved to self.pan in this function when a trigger is received, but there is no direct use of it here.
gain Float64 1 Amplitude scaling factor for the grain.
curve Float64 1 The curve shape for the user-defined envelope.

struct GrainAll . fn set_play_rate

Set the play rate of the grain. Normally a grain is triggered with a set playback speed, but this function allows you to change the playback speed of the grain after it has been triggered.

fn set_play_rate Signature

def set_play_rate(mut self, ratio: Float64)

fn set_play_rate Arguments

Name Type Default Description
ratio Float64 The play rate of the grain.

struct GrainAll . fn next_all

Get the next sample of the grain. This function returns all channels of the buffer with no panning.

fn next_all Signature

def next_all[num_chans: Int, win_type: WindowType = WindowType.hann, custom_curve: WindowType = WindowType.none, bWrap: Bool = False](mut self, buffer: SIMDBuffer[num_chans]) -> SIMD[DType.float64, num_chans]

fn next_all Parameters

Name Type Default Description
num_chans Int The number of channels in the buffer. This is inferred at compile time based on the channel count of the SIMDBuffer that is passed in.
win_type WindowType WindowType.hann The type of window to apply to the grain. A hann window is used by default, and will give the classic granular synthesis sound. If win_type is WindowType.user_defined, then the user_defined_env (env) will be used as the window.
custom_curve WindowType WindowType.none If win_type is WindowType.user_defined, applies a custom curve to the user defined envelope. This is the win_type parameter of the Env next function.
bWrap Bool False Whether to wrap around the buffer when reading. If false, the grain will read 0 when it reaches the end of the buffer. If true, the grain will wrap around to the beginning of the buffer when it reaches the end.

fn next_all Arguments

Name Type Default Description
buffer SIMDBuffer[num_chans] A SIMDBuffer to read from.

fn next_all Returns : SIMD[DType.float64, num_chans] A multi-channel sample of the grain. The number of channels is the same as the number of channels in the buffer.

struct GrainAll . fn reset

fn reset Signature

def reset(mut self)

struct Grain

A single grain for granular synthesis with multiple output options: next_2, next_multi_channel, next_all. Used as part of the TGrains and the PitchShift structs for triggered granular synthesis.

Traits: AnyType, Copyable, GrainObject, ImplicitlyDeletable, Movable, PolyObject


Grain Functions

struct Grain . fn init

Initialize the grain.

fn init Signature

def __init__(out self, world: UnsafePointer[MMMWorld, MutUntrackedOrigin])

fn init Arguments

Name Type Default Description
world UnsafePointer[MMMWorld, MutUntrackedOrigin] Pointer to the MMMWorld instance.

fn init Returns : Self

Static Method

This is a static method.

struct Grain . fn set_user_defined_env

Set a the EnvParams of a user-defined envelope for the grain. This allows you to use a custom envelope shape instead of the built-in window types.

fn set_user_defined_env Signature

def set_user_defined_env(mut self, env_points: Span[Tuple[Float64, Float64]])

fn set_user_defined_env Arguments

Name Type Default Description
env_points Span[Tuple[Float64, Float64]] The points for the user-defined envelope. This should be a list of tuples with the desired envelope settings.

struct Grain . fn set_vals

Set the Grain's variables.

fn set_vals Signature

def set_vals(mut self, rate: Float64 = 1, start_frame: Int = 0, duration: Float64 = 0, pan: Float64 = 0, gain: Float64 = 1, start_chan: Int = 0, curve: Float64 = 1)

fn set_vals Arguments

Name Type Default Description
rate Float64 1 Playback rate of the grain (1.0 = normal speed).
start_frame Int 0 Starting frame position in the buffer.
duration Float64 0 Duration of the grain in seconds.
pan Float64 0 Panning position from -1.0 (left) to 1.0 (right). As this function is used by the panning functions, the pan value is saved to self.pan in this function when a trigger is received, but there is no direct use of it here.
gain Float64 1 Amplitude scaling factor for the grain.
start_chan Int 0 The first buffer channel to read from for the grain (default: 0). If num_playback_chans is 2, the grain will read from start_chan and start_chan+1 for the left and right channels, respectively.
curve Float64 1 The curve shape for the user-defined envelope.

struct Grain . fn next_2

Get the next sample of the grain as a stereo signal with panning.

fn next_2 Signature

def next_2[num_buf_chans: Int, num_playback_chans: Int = 2, win_type: WindowType = WindowType.hann, custom_curve: WindowType = WindowType.none, bWrap: Bool = False](mut self, buffer: SIMDBuffer[num_buf_chans]) -> SIMD[DType.float64, 2]

fn next_2 Parameters

Name Type Default Description
num_buf_chans Int The number of channels in the buffer. This is inferred at compile time based on the channel count of the SIMDBuffer that is passed in.
num_playback_chans Int 2 Either 1 or 2, depending on whether you want to pan 1 channel of the buffer out 2 channels or 2 channels of the buffer with equal power panning.
win_type WindowType WindowType.hann The type of window to apply to the grain. A hann window is used by default, and will give the classic granular synthesis sound. If win_type is WindowType.user_defined, then the user_defined_env (Env) will be used as the window.
custom_curve WindowType WindowType.none If win_type is WindowType.user_defined, applies a custom curve to the user defined envelope. This is the win_type parameter of the Env next function.
bWrap Bool False Whether to wrap around the buffer when reading. If false, the grain will read 0 when it reaches the end of the buffer. If true, the grain will wrap around to the beginning of the buffer when it reaches the end.

fn next_2 Arguments

Name Type Default Description
buffer SIMDBuffer[num_buf_chans] A SIMDBuffer to read from.

fn next_2 Returns : SIMD[DType.float64, 2] A stereo sample of the grain with panning applied.

struct Grain . fn next_multi_channel

Get the next sample of the grain as a multi-channel signal. By default, Grain uses azimuth panning with a width of 2.0 and an orientation of 0.5. This only pans 1 channel of the buffer, specified by buffer_chan. See next_2 for param/arg descriptions and pan_az for details on the panning parameters.

fn next_multi_channel Signature

def next_multi_channel[num_buf_chans: Int, num_speakers: Int = 2, num_simd_chans: Int = 2, win_type: WindowType = WindowType.hann, custom_curve: WindowType = WindowType.none, bWrap: Bool = False](mut self, buffer: SIMDBuffer[num_buf_chans], buffer_chan: Int = 0) -> SIMD[DType.float64, num_simd_chans]

fn next_multi_channel Parameters

Name Type Default Description
num_buf_chans Int The number of channels in the buffer. This is inferred at compile time based on the channel count of the SIMDBuffer that is passed in.
num_speakers Int 2 The number of speakers in the system. This is used for calculating the azimuth panning.
num_simd_chans Int 2 The number of channels in the output sample. This must be a power of two and should be greater than or equal to num_speakers. If num_simd_chans is greater than num_speakers, the extra channels will just be 0.0.
win_type WindowType WindowType.hann The type of window to apply to the grain. A hann window is used by default, and will give the classic granular synthesis sound. If win_type is WindowType.user_defined, then the user_defined_env (Env) will be used as the window.
custom_curve WindowType WindowType.none If win_type is WindowType.user_defined, applies a custom curve to the user defined envelope. This is the win_type parameter of the Env next function.
bWrap Bool False Whether to wrap around the buffer when reading. If false, the grain will read 0 when it reaches the end of the buffer. If true, the grain will wrap around to the beginning of the buffer when it reaches the end.

fn next_multi_channel Arguments

Name Type Default Description
buffer SIMDBuffer[num_buf_chans] A SIMDBuffer to read from.
buffer_chan Int 0 The channel of the buffer to read from for panning. This should be less than num_buf_chans.

fn next_multi_channel Returns : SIMD[DType.float64, num_simd_chans] A multi-channel sample of the grain with azimuth panning applied.

struct Grain . fn next_all

Get the next sample of the grain with no panning. This returns all channels of the buffer.

fn next_all Signature

def next_all[num_chans: Int, win_type: WindowType = WindowType.hann, custom_curve: WindowType = WindowType.none, bWrap: Bool = False](mut self, buffer: SIMDBuffer[num_chans]) -> SIMD[DType.float64, num_chans]

fn next_all Parameters

Name Type Default Description
num_chans Int The number of channels in the buffer. This is inferred at compile time based on the channel count of the SIMDBuffer that is passed in.
win_type WindowType WindowType.hann The type of window to apply to the grain. A hann window is used by default, and will give the classic granular synthesis sound. If win_type is WindowType.user_defined, then the user_defined_env (Env) will be used as the window.
custom_curve WindowType WindowType.none If win_type is WindowType.user_defined, applies a custom curve to the user defined envelope. This is the win_type parameter of the Env next function.
bWrap Bool False Whether to wrap around the buffer when reading. If false, the grain will read 0 when it reaches the end of the buffer. If true, the grain will wrap around to the beginning of the buffer when it reaches the end.

fn next_all Arguments

Name Type Default Description
buffer SIMDBuffer[num_chans] A SIMDBuffer to read from.

fn next_all Returns : SIMD[DType.float64, num_chans] A sample of the grain with num_chans channels.

struct Grain . fn reset

Reset the grain to its initial state. This can be used to retrigger the grain with the same parameters.

fn reset Signature

def reset(mut self)

struct Grain . fn set_play_rate

Set the play rate of the grain. Normally a grain is triggered with a set playback speed, but this function allows you to change the playback speed of the grain after it has been triggered.

fn set_play_rate Signature

def set_play_rate(mut self, rate: Float64)

fn set_play_rate Arguments

Name Type Default Description
rate Float64 The play rate of the grain.

struct TGrains

Triggered granular synthesis. Each trigger starts a new grain.

Traits: AnyType, Copyable, ImplicitlyDeletable, Movable, PolyReset

TGrains Parameters

Name Type Default Description
T GrainObject Grain
win_type WindowType WindowType.hann
custom_curve WindowType WindowType.none

TGrains Functions

struct TGrains . fn init

Initialize the TGrains struct.

fn init Signature

def __init__(out self, world: UnsafePointer[MMMWorld, MutUntrackedOrigin], num_grains: Int = 1)

fn init Arguments

Name Type Default Description
world UnsafePointer[MMMWorld, MutUntrackedOrigin] Pointer to the MMMWorld instance.
num_grains Int 1 Number of grains to initialize.

fn init Returns : Self

Static Method

This is a static method.

struct TGrains . fn set_num_grains

This function can be used to change the number of grains that the Poly can use. If more grains are needed than the initial number, you can increase the number of grains with this function.

fn set_num_grains Signature

def set_num_grains(mut self, new_num_grains: Int)

fn set_num_grains Arguments

Name Type Default Description
new_num_grains Int The new number of grains that the Poly should be able to use. This should be greater than the current number of grains. If it is less than the current number of grains, this function will do nothing.

struct TGrains . fn set_env_points

Set the envelope points for all grains by providing Span (List or InlineArray) of tuples. This allows you to use a custom envelope shape instead of the built-in window types. Will update each grain on its next trigger. The tuples should be in the format (x, y), where x is the position in the grain from 0.0 to 1.0 and y is the amplitude at that point. For example, set_env_points((0.0, 0.0), (0.5, 1.0), (1.0, 0.0)) would be a simple triangle envelope.

fn set_env_points Signature

def set_env_points(mut self, env_points: Span[Tuple[Float64, Float64]])

fn set_env_points Arguments

Name Type Default Description
env_points Span[Tuple[Float64, Float64]] A List or other Span of tuples defining the envelope shape.

struct TGrains . fn set_env_points

Set the envelope points for all grains by providing a list of values. This allows you to use a custom envelope shape instead of the built-in window types. Will update each grain on its next trigger.

fn set_env_points Signature

def set_env_points(mut self, env_points: List[Float64])

fn set_env_points Arguments

Name Type Default Description
env_points List[Float64] A List or other Span of values defining the envelope shape. Each 2 values represent an env_point, so the list should be in the format [x1, y1, x2, y2, ...], where x is the position in the grain from 0.0 to 1.0 and y is the amplitude at that point. For example, [0.0, 0.0, 0.5, 1.0, 1.0, 0.0] would be a simple triangle envelope.

struct TGrains . fn trig

Send the trigger signal to the TGrains. If trig is True, looks for a free grain, sets its self.trigger flag to True, and makes the grain active.

fn trig Signature

def trig(mut self, trig: Bool) -> Int

fn trig Arguments

Name Type Default Description
trig Bool A boolean trigger signal. When True, the TGrains will look for a free grain to trigger. When False, no new grains will be triggered.

fn trig Returns : Int The index of the grain that was triggered, or -1 if no grain was triggered.

struct TGrains . fn next_2

Generate the next set of grains. Depending on num_playback_chans, will either pan a mono signal out 2 channels or a stereo signal out 2 channels.

fn next_2 Signature

def next_2[num_playback_chans: Int = 1, bWrap: Bool = False](mut self, buffer: SIMDBuffer, gain: Float64 = 1) -> SIMD[DType.float64, 2]

fn next_2 Parameters

Name Type Default Description
num_playback_chans Int 1 Either 1 or 2, depending on whether you want to pan 1 channel of a buffer out 2 channels or 2 channels of the buffer with equal power panning.
bWrap Bool False Whether to interpolate between the end and start of the buffer when reading (default: False). When False, reading beyond the end of the buffer will return 0. When True, the index into the buffer will wrap around to the beginning using a modulus.

fn next_2 Arguments

Name Type Default Description
buffer SIMDBuffer Audio buffer containing the source sound.
gain Float64 1 Amplitude scaling factor for the output of the grains.

fn next_2 Returns : SIMD[DType.float64, 2] Output samples for the left and right channels.

struct TGrains . fn next_multi_channel

Get the next sample of the grain as a multi-channel signal with azimuth panning. This only pans 1 channel of the buffer, specified by buffer_chan. See next_2 for param/arg descriptions and pan_az for details on the panning parameters.

fn next_multi_channel Signature

def next_multi_channel[num_buf_chans: Int, num_speakers: Int = 2, num_simd_chans: Int = 2, bWrap: Bool = False](mut self, buffer: SIMDBuffer[num_buf_chans], buffer_chan: Int = 0, gain: Float64 = 1) -> SIMD[DType.float64, num_simd_chans]

fn next_multi_channel Parameters

Name Type Default Description
num_buf_chans Int The number of channels in the buffer. This is inferred at compile time based on the channel count of the SIMDBuffer that is passed in.
num_speakers Int 2 The number of speakers in the system. This is used for calculating the azimuth panning.
num_simd_chans Int 2 The number of channels in the output sample. This must be a power of two and should be greater than or equal to num_speakers. If num_simd_chans is greater than num_speakers, the extra channels will just be 0.0.
bWrap Bool False Whether to wrap around the buffer when reading. If false, the grain will read 0 when it reaches the end of the buffer. If true, the grain will wrap around to the beginning of the buffer when it reaches the end.

fn next_multi_channel Arguments

Name Type Default Description
buffer SIMDBuffer[num_buf_chans] A SIMDBuffer to read from.
buffer_chan Int 0 The channel of the buffer to read from for panning. This should be less than num_buf_chans.
gain Float64 1 Amplitude scaling factor for the output of the grains.

fn next_multi_channel Returns : SIMD[DType.float64, num_simd_chans] A multi-channel sample of the grain with azimuth panning applied.

struct TGrains . fn next_all

Generate the next set of grains. Depending on num_out_chans, will either pan a mono signal out 2 channels or a stereo signal out 2 channels.

fn next_all Signature

def next_all[num_chans: Int, bWrap: Bool = False](mut self, buffer: SIMDBuffer[num_chans], gain: Float64 = 1) -> SIMD[DType.float64, num_chans]

fn next_all Parameters

Name Type Default Description
num_chans Int A power of two num out channels that will determine the size of the SIMD output.
bWrap Bool False Whether to interpolate between the end and start of the buffer when reading (default: False). When False, reading beyond the end of the buffer will return 0. When True, the index into the buffer will wrap around to the beginning using a modulus.

fn next_all Arguments

Name Type Default Description
buffer SIMDBuffer[num_chans] Audio buffer containing the source sound.
gain Float64 1 Amplitude scaling factor for the output of the grains.

fn next_all Returns : SIMD[DType.float64, num_chans] Output samples for left and right channels as a SIMD vector.

struct TGrains . fn reset

Reset all grains to be inactive and set their triggers to False. This can be used to stop all grains immediately.

fn reset Signature

def reset(mut self)

struct TGrains . fn set_play_rate

Set the play ratio of all active grains. This allows you to change the playback speed of all currently active grains at once.

fn set_play_rate Signature

def set_play_rate(mut self, ratio: Float64)

fn set_play_rate Arguments

Name Type Default Description
ratio Float64 The play ratio to set for all active grains.

struct PitchShift

An N channel granular pitchshifter. Each channel is processed in parallel.

Args: world: Pointer to the MMMWorld instance. buf_dur: Duration of the internal buffer in seconds.

Traits: AnyType, Copyable, ImplicitlyDeletable, Movable, PolyReset

PitchShift Parameters

Name Type Default Description
num_chans Int 1 Number of input/output channels.
win_type WindowType WindowType.hann Type of window to apply to each grain (default is Hann window (WinType.hann)).

PitchShift Functions

struct PitchShift . fn init

Initialize the PitchShift struct.

fn init Signature

def __init__(out self, world: UnsafePointer[MMMWorld, MutUntrackedOrigin], buf_dur: Float64 = 2, num_grains: Int = 12)

fn init Arguments

Name Type Default Description
world UnsafePointer[MMMWorld, MutUntrackedOrigin] Pointer to the MMMWorld instance.
buf_dur Float64 2 Duration of the internal buffer in seconds.
num_grains Int 12 Number of grains to initialize for simultaneous playback.

fn init Returns : Self

Static Method

This is a static method.

struct PitchShift . fn next

Generate the next set of grains for pitch shifting.

fn next Signature

def next(mut self, in_sig: SIMD[DType.float64, num_chans], grain_dur: Float64 = 0.20000000000000001, overlaps: Int = 4, pitch_ratio: Float64 = 1, pitch_dispersion: Float64 = 0, time_dispersion: Float64 = 0, added_delay_low: Float64 = 0, added_delay_high: Float64 = 0, gain: Float64 = 1) -> SIMD[DType.float64, num_chans]

fn next Arguments

Name Type Default Description
in_sig SIMD[DType.float64, num_chans] Input signal to be pitch shifted.
grain_dur Float64 0.20000000000000001 Duration of each grain in seconds.
overlaps Int 4 Number of overlapping grains (default is 4).
pitch_ratio Float64 1 Pitch shift ratio (1.0 = no shift, 2.0 = one octave up, 0.5 = one octave down, etc).
pitch_dispersion Float64 0 Amount of random variation in pitch ratio.
time_dispersion Float64 0 Amount of random variation in grain triggering time. Value between 0.0 and 1.0, where 0.0 is no variation and 1.0 is maximum variation of up to the grain duration.
added_delay_low Float64 0 Minimum amount of delay to add to the start of each grain in seconds.
added_delay_high Float64 0 Maximum amount of delay to add to the start of each grain in seconds. (Maximum added delay should be set so that it does not exceed the internal buffer size when combined with the grain duration and time dispersion).
gain Float64 1 Amplitude scaling factor for the output.

fn next Returns : SIMD[DType.float64, num_chans] The next sample of the pitch-shifted signal as a SIMD vector with num_chans channels.

struct PitchShift . fn reset

Reset the PitchShift to its initial state. This will clear the internal buffer and reset all grains.

fn reset Signature

def reset(mut self)

Documentation generated with mojo doc from Mojo version 1.0.0b2