Skip to main content

Call python code from MaxMSP over OSC

Project description

MaxOsc is a package designed to conveniently call python code from MaxMSP over OSC. It's a wrapper of the python-osc package with a built-in parser.

The python code should be run independently of Max (in a terminal or similar) and can be used in conjuncture with the set of Max abstractions available here or directly through the CNMAT externals for OSC (also available through the Max package manager).

Project Status

The project is currently in development.

Documentation is currently limited, further documentation will be available later.

Minimal Example

Run the following code in a separate terminal. Note that MaxOsc.run() will instantiate a blocking OSC server, hence no code below that point will ever be executed.

from maxosc import MaxOsc

class Flipper(MaxOsc):

    def __init__(self):
        super().__init__()
        self.run()

    def flip(self, a1: int, a2: int):
        return a2, a1

    def flip_list(self, a: [int]):
        return list(reversed(a))

if __name__ == '__main__':
    Flipper()

If the pyosc abstractions are available in your path, the following Max patcher can be used:

Show Max patcher
<pre><code>
----------begin_max5_patcher----------
432.3ocwU9saBBCEF+Z3onoWyL.BLcWs2ikESEqtZv1l1hhw369n+AmNItlg
QuvZ5omxW+w2oGNDF.myZvRH3MvGfffCgAAlP5.At4AvMnlxJjzjFjh2wluF
FYWRgaTlv78LY4nJhTsSf3cKSq2vpUUXkYuItnjElsz9XdI40tTs4o1yw1SC
DB9zsDGoJ+hPWMSfKU1UGmlNJNBLMWONISOpibZKsBSnmzUG6XXndHZfXJHT
E3cNiWyAI8iYbOXV.+SVRiiMHkb+gYCVJQqvWQSBHELFjAx82uxGjeUXPLO+
1Hl978q3a3WIYOQ+xamZ5+ynbvYMpzoixeTFko+wxZZIXYEgOS2IoeVytl0a
zDI5redTfl39Kt3w0R4Rx8F5hgCsyrcPOI2elMY.qHze+wCiJ53W9hPxpEkc
mutF+feDZAVpHTjhvnmkjKmdeW6sP4dHTx8PIeHR+gfAKTgOBEeGDZpGBcMP
1ZCDmuEKjtjMRzdcXMSnmNIxLkPsSMsufB7VRW91HHQaEqpsbsVXNVvlhLnc
qrEXAsl3pKagqURyUMJps6IGY4vbiL7X32.J7svT
-----------end_max5_patcher-----------
</code></pre>

Elaborate Example

Python Code:
from maxosc import MaxOsc


class Instrument:
    def __init__(self, name: str, midi_range: (int, int), supported_techniques: [str], concert_pitch: float,
                 transposing: bool):
        self.name: str = name
        self.midi_range: (int, int) = midi_range
        self.supported_techniques: [str] = supported_techniques
        self.concert_pitch: float = concert_pitch
        self.transposing: bool = transposing

    def max_getter(self):
        return self.name, self.midi_range, self.supported_techniques, self.concert_pitch, self.transposing


class InstrumentBank(MaxOsc):
    def __init__(self):
        super().__init__()
        self.instruments: [Instrument] = []
        self.run()

    def add_instrument(self, name: str, midi_range: (int, int), supported_techniques: [str],
                       concert_pitch: float = 440.0, transposing: bool = False):
        instrument = Instrument(name, midi_range, supported_techniques, concert_pitch, transposing)
        self.instruments.append(instrument)
        print(f"Added instrument '{name}' with range={midi_range}, techniques={supported_techniques}, "
              f"concert pitch={concert_pitch} and transposing={transposing}.")

    def get_instruments(self):
        return [instr.max_getter() for instr in self.instruments]


if __name__ == '__main__':
    InstrumentBank()
Max Code:
Show Max patcher

----------begin_max5_patcher----------
1581.3ocyZF0bahCDG+YmOE6vKocFWeHDfgNSd35C2SW6K2My8PhmLXrrM4v
HJRjX2N86dWIgcH01Dpwl1YRLFYEzt+j1c+K470qFXMkulIrf2C2BCF70qFL
P2jpgAU2OvZUz53zHgtaVw7UqXYRqglOSxVK0s+wxTYx6dhWLCDxhjrEBPf8
Cjb3iQqgmRRSgoLHOpPvlAQBcqhMqlxSEPxH1HXFubZJC9bIWFIS3Yvpnh+W
.uQTN8AVr9IEuLJaA6si1N5oIYrXdYl1DbqZLqbEuTlxjZC1tp0jYZyjO8g2
E5s8uOORFuDs06KvAvPA5X+Q1CApuq5BwOPcw2djML44meR11GOQ012t5J0K
C6HB+DOigTfIxtVBr0IBIjjo3zH3+1Ce2g1QZ5cVWB9PZfOiscqyGGR+wmOv
4ornLAxn8IztOr4Uc1.u.HW.nED1.z777pCMZOtn5CafYr4QXz4PHiIjHFRQ
tI1wl4oQRIKCa+okrr53aD7OLFFEtdIKMGlifaEufgDGe6JSHJ9ih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QpxNge2BGrnBL4m
XClGfKNm3x6pseWUqw787Q85WsEQylUSaQqkV3etTV33FVSYU6VVn6gdt5G9
d00ihp8WhDAurHdq8s8b.gmGnYLgLISqhuVmT6ZT0oCh8VORNsYjnmiQhzlQ
hbNFI6VLRNmC5oNKjWcjTpb69H41F58h9fasLGKSHEaOr.SwXmwpKnxps2zU
Ki1UKyOz0XLg0srvNaYaAeiVlZeW3d7NhoYLFpqlYjwA6tqqPizUn4NlZ3TP
cnEzYKi1FKSomPAstM8zlvT54HgfaaRxQOGIDntskdNccjb57JncAZ10i55L
BBZKB57H0pruNuNCpNb8w5u.vf5k34EyXE5cB0CVpcaszfcueeCkb4MzeXFt
AC0sAC0oSFpSmqGRsCLJ5Zb8uQJWTd9irBQ0SWaTnN1G3ZGIXn91jLysZ82V
ErGS11eSKnx9kIRTcYYg1QrVWcr+Vq3HRxJSpl9PbfCoVir9+xD0+9Cls1iR
ou5aW8cPshRPJ
-----------end_max5_patcher-----------

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for maxosc, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size maxosc-0.0.2-py3-none-any.whl (13.6 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size maxosc-0.0.2.tar.gz (17.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page