audioinstruments.panel

An instrument as a control panel sees it.

PanelAdapter(inst) wraps an instrument from audioinstruments.create() in the adapter a control panel edits through: sixteen macro values on the MIDI scale, the patch names, bypass, reload, and a callback for changes that come from somewhere else, such as a MIDI controller. It imports no panel, so anything with the same attributes can use it.

import audioinstruments.panel as panel

adapter = panel.create(“poly106”, 48000) audio_out.play(adapter.instrument.output) adapter.note_on(60) # dropped while bypassed adapter.note_cc(0, 96) # a controller moved macro 0: listeners hear it adapter.set_patch(1) # what a pad press does

request_reload() builds the instrument again and swaps it in, so play adapter.instrument.output again after a reload, or register on_reload(callback) to hear about it.

audioinstruments.panel.create(name, sample_rate, channel_count=2, transport=None, **options)[source]

Create instrument name and wrap it. A reload builds it with the same options.

class audioinstruments.panel.PanelAdapter(instrument, rebuild=None, name=None)[source]

Bases: object

What a control panel needs from instrument, and nothing else.

rebuild is a callable that returns a new instrument, used by request_reload(). Without one, a reload creates the same instrument by name at the same sample rate and channel count, with default options. name replaces the instrument’s display name on the faceplate.

set_bypass(enabled)[source]

Bypassed, the instrument is silenced and note_on is dropped.

request_reload()[source]

Build the instrument again and swap it in, keeping the patch and macros.

Returns True when the new instrument is in place. On a failure the old one keeps playing, engine_error is 1 and engine_message says why.

on_external_change(callback)[source]

Register callback(kind, index, value): ("macro", i, v) or ("patch", i, i).

on_reload(callback)[source]

Register callback(new, old), called after a reload swaps instruments.

Play new.output in place of old.output. The old instrument is silenced but not deinitialised: deinit it once nothing pulls from it.

note_cc(index, value)[source]

A controller moved macro index to value (0-127): play it, tell the listeners.

note_program(index)[source]

A program change from outside: play it, tell the listeners the patch and every macro it moved.

note_on(pitch, velocity=127, channel=0)[source]

instrument.note_on, dropped while bypassed.