nbplay.app

Serve a Session as a web page with every instrument in a resizable panel.

The widgets are the same objects a notebook displays: each hosts its models in its own transports session, which the app serves over one WebSocket per instrument, and the page binds each element to those models under the panel’s namespace. The panels are a regular-layout split/tab tree that the browser can rearrange.

python -m nbplay.app serves a demo session on http://127.0.0.1:8020.

The same page also runs with no server: Standalone is the Python side for a Pyodide Web Worker, with postMessage in place of the WebSockets (js/examples/pyodide.html, built by make pyodide-example).

Classes

Standalone

The Python side of the page with no server: what a Pyodide Web Worker runs.

Functions

panel_widgets(session)

Panel name to widget: the session views, then each track's sequencer and sound source.

panel_titles(session)

Panel name to the title on its tab: Mixer, or the track's name and the instrument (Lead synth).

default_layout(names)

The transport across the top, launcher, timeline and mixer in the middle, instruments below.

build(session, *[, layout, title, probes])

A Starlette app serving session: one WebSocket per instrument and a panel layout page.

demo_session()

Two tracks: a saw lead on a sequencer and a sampler kit with a kick.

Module Contents

nbplay.app.panel_widgets(session)

Panel name to widget: the session views, then each track’s sequencer and sound source.

nbplay.app.panel_titles(session)

Panel name to the title on its tab: Mixer, or the track’s name and the instrument (Lead synth).

nbplay.app.default_layout(names)

The transport across the top, launcher, timeline and mixer in the middle, instruments below.

nbplay.app.build(session, *, layout=None, title='nbplay', probes=False, **options)

A Starlette app serving session: one WebSocket per instrument and a panel layout page.

The page is a top bar (title, the panel palette, save and load, and a theme select) over the panels. layout is a regular-layout split/tab tree over the panel names from panel_widgets(); probes adds the JSON routes the browser tests drive. Other keyword options go to spaday.backends.starlette.build_routes().

GET /session.nbplay downloads the session as a .nbplay archive and PUT /session.nbplay replaces the served session with an uploaded one, after which the page has to be reloaded. app.state.session is the session being served.

class nbplay.app.Standalone(session, *, layout=None, title='nbplay')

The Python side of the page with no server: what a Pyodide Web Worker runs.

Each panel’s transports server talks to one in-browser connection; the worker passes wire frames between this object and the page with postMessage. Every method takes and returns JSON text, the form that crosses the worker boundary.

session
panels
servers
_page
page()

The tree, the page styles, and each panel’s model-to-namespace wires.

open()

Connect the page to every panel; the frames that bring it up to date, by panel.

receive(panel, frame)

Apply one frame from the page; the frames to send back, by panel.

A browser edit can change other widgets’ models (the session mirrors theme, mute and solo), so every server is flushed.

call(panel, method)

Call a widget method ("transport", "play") the way Python driving the session would; the frames to send.

_flush(out)
nbplay.app.demo_session()

Two tracks: a saw lead on a sequencer and a sampler kit with a kick.