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
Development of this project is largely stalled. Minor fixes will be released when necessary.
The project is stable but documentation is limited.
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+okrr53aD7OLFFEtdIKMGlifaEufgDGe6JSHJ9ihsn2BlFE
cEiia.ijPZcLNdb+Fa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seWUqw787Q85WsEQylUSaQqkV3etTV33FVSYU6VVn6gdt5G9
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.
Source Distribution
Built Distribution
File details
Details for the file maxosc-0.0.6.tar.gz
.
File metadata
- Download URL: maxosc-0.0.6.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72f8a7415f7b83521e2ad0c82c624934256ee2bdd78d38e0ad8855e82dcea30a |
|
MD5 | 8ca55ff17b71fbcd3c0e6744231784ef |
|
BLAKE2b-256 | 6a2d44865f97c537d2b0d6d4970e129b792523f5c77e191026a003c5a7aa68ed |
File details
Details for the file maxosc-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: maxosc-0.0.6-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 286fb5f6f5d5d7ecbd02f86f8892a49dc0ff96c272439d3ca24367257c31aa4a |
|
MD5 | 16be8c27f37b24a7b5c9dc365117e9e3 |
|
BLAKE2b-256 | ddca733fc0f1bad4237592ab6a34b53f9d73e4de65749999aff53cce7d54e624 |