Messenger
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, Movable, UnknownDestructibility
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
fn init Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| world | UnsafePointer |
— | An UnsafePointer[MMMWorld] to the world to check for new messages. |
| namespace | Optional |
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
fn update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | Bool |
— | A Bool variable to be updated. |
| name | String |
— | A String to identify the Bool sent from Python. |
struct Messenger . fn update¶
Update a Float64 variable with a value sent from Python.
fn update Signature
fn update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | Float64 |
— | A Float64 variable to be updated. |
| name | String |
— | A String to identify the Float64 sent from Python. |
struct Messenger . fn update¶
Update a List[Float64] variable with a value sent from Python.
fn update Signature
fn update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | List |
— | A List[Float64] variable to be updated. The List will be resized to match the incoming data. |
| name | String |
— | A String to identify the List[Float64] sent from Python. |
struct Messenger . fn update¶
Update a SIMD[DType.float64] variable with a value sent from Python.
fn update Signature
fn update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | SIMD |
— | 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. |
| name | String |
— | A String to identify the SIMD[DType.float64] sent from Python. |
struct Messenger . fn update¶
Update a Int64 variable with a value sent from Python.
fn update Signature
fn update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | Int64 |
— | A Int64 variable to be updated. |
| name | String |
— | A String to identify the Int64 sent from Python. |
struct Messenger . fn update¶
Update a List[Int64] variable with a value sent from Python.
fn update Signature
fn update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | List |
— | A List[Int64] variable to be updated. The List will be resized to match the incoming data. |
| name | String |
— | A String to identify the List[Int64] sent from Python. |
fn update Returns
: Bool
struct Messenger . fn update¶
Update a String variable with a value sent from Python.
fn update Signature
fn update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | String |
— | A String variable to be updated. |
| name | String |
— | A String to identify the String sent from Python. |
struct Messenger . fn update¶
Update a List[String] variable with a value sent from Python.
fn update Signature
fn update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | List |
— | A List[String] variable to be updated. The List will be resized to match the incoming data. |
| name | String |
— | A String to identify the List[String] sent from Python. |
struct Messenger . fn notify_update¶
Notify and update a Bool variable with a value sent from Python.
fn notify_update Signature
fn notify_update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | Bool |
— | A Bool variable to be updated. |
| name | String |
— | A String to identify the Bool sent from Python. |
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
fn notify_update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | Float64 |
— | A Float64 variable to be updated. |
| name | String |
— | A String to identify the Float64 sent from Python. |
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
fn notify_update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | List |
— | A List[Float64] variable to be updated. The List will be resized to match the incoming data. |
| name | String |
— | A String to identify the List[Float64] sent from Python. |
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
fn notify_update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | SIMD |
— | 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. |
| name | String |
— | A String to identify the SIMD[DType.float64] sent from Python. |
fn notify_update Returns
: Bool
A Bool indicating whether the parameter was updated.
struct Messenger . fn notify_update¶
Notify and update a Int64 variable with a value sent from Python.
fn notify_update Signature
fn notify_update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | Int64 |
— | A Int64 variable to be updated. |
| name | String |
— | A String to identify the Int64 sent from Python. |
fn notify_update Returns
: Bool
A Bool indicating whether the parameter was updated.
struct Messenger . fn notify_update¶
Notify and update a List[Int64] variable with a value sent from Python.
fn notify_update Signature
fn notify_update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | List |
— | A List[Int64] variable to be updated. The List will be resized to match the incoming data. |
| name | String |
— | A String to identify the List[Int64] sent from Python. |
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
fn notify_update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | String |
— | A String variable to be updated. |
| name | String |
— | A String to identify the String sent from Python. |
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
fn notify_update Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| param | List |
— | A List[String] variable to be updated. The List will be resized to match the incoming data. |
| name | String |
— | A String to identify the List[String] sent from Python. |
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
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 0.25.6.1