Skip to content

For more information about the examples, such as how the Python and Mojo files interact with each other, see the Examples Overview

DefaultGraph

A simple default graph example that can be used as a starting point for creating your own graphs.

Python Code

from mmm_python import *

# instantiate and load the graph
mmm_audio = MMMAudio(128, graph_name="DefaultGraph", package_name="examples")
mmm_audio.start_process()
mmm_audio.start_audio() 

mmm_audio.send_float("pan", 0)

# set the frequency to a random value
from random import random
mmm_audio.send_float("freq", random() * 500 + 100) # set the frequency to a random value

Mojo Code

from mmm_audio import *

struct Default_Synth(Representable, Movable, Copyable):
    var world: World  
    var osc: Osc[1,Interp.sinc,1]
    var filt: SVF[1]
    var messenger: Messenger
    var freq: Float64
    var pan: Float64

    fn __init__(out self, world: World):
        self.world = world
        self.osc = Osc[1,Interp.sinc,1](self.world)
        self.filt = SVF[1](self.world)
        self.messenger = Messenger(self.world)
        self.freq = 440.0
        self.pan = -1.0

    fn __repr__(self) -> String:
        return String("Default")

    fn next(mut self) -> MFloat[2]:
        self.messenger.update(self.freq,"freq")
        self.messenger.update(self.pan,"pan")

        osc = self.osc.next(self.freq, osc_type=OscType.saw) 
        osc = self.filt.next[filter_type=SVFModes.lowpass](osc, 2000.0, 1.0)
        osc2 = pan2(osc, self.pan)

        return osc2 * 0.1


# there can only be one graph in an MMMAudio instance
# a graph can have as many synths as you want
struct DefaultGraph(Representable, Movable, Copyable):
    var world: World
    var synth: Default_Synth

    fn __init__(out self, world: World):
        self.world = world
        self.synth = Default_Synth(self.world)

    fn __repr__(self) -> String:
        return String("Default_Graph")

    fn next(mut self) -> MFloat[2]:

        return self.synth.next()  # Get the next sample from the synth