Skip to content

Messenger

Structs

struct Messenger

Communication between Python and Mojo.

It works by checking for messages sent from Python at the start of each audio block, and updating any parameters registered with it accordingly. Each data type has its own update function and notify_update which will return a Bool indicating whether the parameter was updated.

For example usage, see the MessengerExample.mojo file in the Examples folder.

Traits: AnyType, Copyable, ImplicitlyDeletable, Movable


Messenger Functions

struct Messenger . fn init

Initialize the Messenger. If a 'namespace' is provided, any messages sent from Python need to be prepended with this name. For example, if a Float64 updates with the name 'freq' and this Messenger has the namespace 'synth1', then to update the freq value from Python, the user must send 'synth1.freq'.

fn init Signature

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

fn init Arguments

Name Type Default Description
world UnsafePointer[MMMWorld, MutUntrackedOrigin] An World to the world to check for new messages.
namespace Optional[String] None A String (or by defaut None) to declare as the 'namespace' for this Messenger. If a 'namespace' is provided, any messages sent from Python need to be prepended with this name. For example, if a Float64 updates with the name 'freq' and this Messenger has the namespace 'synth1', then to update the freq value from Python, the user must send 'synth1.freq'.

fn init Returns : Self

Static Method

This is a static method.

struct Messenger . fn update

Update a Bool variable with a value sent from Python.

fn update Signature

def update(mut self, name: String, mut param: Bool)

fn update Arguments

Name Type Default Description
name String A String to identify the Bool sent from Python.
param Bool A Bool variable to be updated.

struct Messenger . fn update

Update a Float64 variable with a value sent from Python.

fn update Signature

def update(mut self, name: String, mut param: Float64)

fn update Arguments

Name Type Default Description
name String A String to identify the Float64 sent from Python.
param Float64 A Float64 variable to be updated.

struct Messenger . fn update

Update a List[Float64] variable with a value sent from Python.

fn update Signature

def update(mut self, name: String, mut param: List[Float64])

fn update Arguments

Name Type Default Description
name String A String to identify the List[Float64] sent from Python.
param List[Float64] A List[Float64] variable to be updated. The List will be resized to match the incoming data.

struct Messenger . fn update

Update a SIMD[DType.float64] variable with a value sent from Python.

fn update Signature

def update[dtype: DType, num_chans: Int](mut self, name: String, mut param: SIMD[dtype, num_chans])

fn update Parameters

Name Type Default Description
dtype DType The scalar dtype stored in the SIMD parameter.
num_chans Int Number of SIMD lanes to update.

fn update Arguments

Name Type Default Description
name String A String to identify the SIMD[DType.float64] sent from Python.
param SIMD[dtype, num_chans] A SIMD[DType.float64] variable to be updated. The SIMD will not be resized to match the incoming data. It is the user's responsibility to ensure the sizes match.

struct Messenger . fn update

Update a Int variable with a value sent from Python.

fn update Signature

def update(mut self, name: String, mut param: Int)

fn update Arguments

Name Type Default Description
name String A String to identify the Int sent from Python.
param Int A Int variable to be updated.

struct Messenger . fn update

Update a List[Int] variable with a value sent from Python.

fn update Signature

def update(mut self, name: String, mut param: List[Int])

fn update Arguments

Name Type Default Description
name String A String to identify the List[Int] sent from Python.
param List[Int] A List[Int] variable to be updated. The List will be resized to match the incoming data.

struct Messenger . fn update

Update a String variable with a value sent from Python.

fn update Signature

def update(mut self, name: String, mut param: String)

fn update Arguments

Name Type Default Description
name String A String to identify the String sent from Python.
param String A String variable to be updated.

struct Messenger . fn update

Update a List[String] variable with a value sent from Python.

fn update Signature

def update(mut self, name: String, mut param: List[String])

fn update Arguments

Name Type Default Description
name String A String to identify the List[String] sent from Python.
param List[String] A List[String] variable to be updated. The List will be resized to match the incoming data.

struct Messenger . fn notify_update

Notify and update a Bool variable with a value sent from Python.

fn notify_update Signature

def notify_update(mut self, name: String, mut param: Bool) -> Bool

fn notify_update Arguments

Name Type Default Description
name String A String to identify the Bool sent from Python.
param Bool A Bool variable to be updated.

fn notify_update Returns : Bool A Bool indicating whether the parameter was updated.

struct Messenger . fn notify_update

Notify and update a Float64 variable with a value sent from Python.

fn notify_update Signature

def notify_update(mut self, name: String, mut param: Float64) -> Bool

fn notify_update Arguments

Name Type Default Description
name String A String to identify the Float64 sent from Python.
param Float64 A Float64 variable to be updated.

fn notify_update Returns : Bool A Bool indicating whether the parameter was updated.

struct Messenger . fn notify_update

Notify and update a List[Float64] variable with a value sent from Python.

fn notify_update Signature

def notify_update(mut self, name: String, mut param: List[Float64]) -> Bool

fn notify_update Arguments

Name Type Default Description
name String A String to identify the List[Float64] sent from Python.
param List[Float64] A List[Float64] variable to be updated. The List will be resized to match the incoming data.

fn notify_update Returns : Bool A Bool indicating whether the parameter was updated.

struct Messenger . fn notify_update

Notify and update a SIMD[DType.float64] variable with a value sent from Python.

fn notify_update Signature

def notify_update[dtype: DType, num_chans: Int](mut self, name: String, mut param: SIMD[dtype, num_chans]) -> Bool

fn notify_update Parameters

Name Type Default Description
dtype DType The scalar dtype stored in the SIMD parameter.
num_chans Int Number of SIMD lanes to update.

fn notify_update Arguments

Name Type Default Description
name String A String to identify the SIMD[DType.float64] sent from Python.
param SIMD[dtype, num_chans] A SIMD[DType.float64] variable to be updated. The SIMD will not be resized to match the incoming data. It is the user's responsibility to ensure the sizes match.

fn notify_update Returns : Bool A Bool indicating whether the parameter was updated.

struct Messenger . fn notify_update

Notify and update a Int variable with a value sent from Python.

fn notify_update Signature

def notify_update(mut self, name: String, mut param: Int) -> Bool

fn notify_update Arguments

Name Type Default Description
name String A String to identify the Int sent from Python.
param Int A Int variable to be updated.

fn notify_update Returns : Bool A Bool indicating whether the parameter was updated.

struct Messenger . fn notify_update

Notify and update a List[Int] variable with a value sent from Python.

fn notify_update Signature

def notify_update(mut self, name: String, mut param: List[Int]) -> Bool

fn notify_update Arguments

Name Type Default Description
name String A String to identify the List[Int] sent from Python.
param List[Int] A List[Int] variable to be updated. The List will be resized to match the incoming data.

fn notify_update Returns : Bool A Bool indicating whether the parameter was updated.

struct Messenger . fn notify_update

Notify and update a String variable with a value sent from Python.

fn notify_update Signature

def notify_update(mut self, name: String, mut param: String) -> Bool

fn notify_update Arguments

Name Type Default Description
name String A String to identify the String sent from Python.
param String A String variable to be updated.

fn notify_update Returns : Bool A Bool indicating whether the parameter was updated.

struct Messenger . fn notify_update

Notify and update a List[String] variable with a value sent from Python.

fn notify_update Signature

def notify_update(mut self, name: String, mut param: List[String]) -> Bool

fn notify_update Arguments

Name Type Default Description
name String A String to identify the List[String] sent from Python.
param List[String] A List[String] variable to be updated. The List will be resized to match the incoming data.

fn notify_update Returns : Bool A Bool indicating whether the parameter was updated.

struct Messenger . fn notify_trig

Get notified if a send_trig message was sent under the specified name.

fn notify_trig Signature

def notify_trig(mut self, name: String) -> Bool

fn notify_trig Arguments

Name Type Default Description
name String A String to identify the trigger sent from Python.

fn notify_trig Returns : Bool A Bool indicating whether a trigger was sent from Python under the specified name.


Documentation generated with mojo doc from Mojo version 1.0.0b2