jdxi_editor.audio.soundfont_output
SoundFont playback through an output the application chooses.
FluidSynth renders each block. sounddevice opens the device. The synth’s own audio driver is left closed, so a device name never has to match CoreAudio’s list.
Attributes
Classes
Structure base class |
|
FluidSynth's own MIDI input: a virtual MIDI port (on macOS a CoreMIDI |
|
A FluidSynth and the output stream that plays it. |
Functions
|
Whether sounddevice imported. |
|
Output devices as |
|
Which output label to put back after the combo is rebuilt. |
|
The sounddevice index to open. |
|
|
CoreAudio, loaded once. None when the framework cannot be opened. |
|
|
|
|
A device's own name, without the suffix added for a repeated one. |
|
True for the built-in speaker and headphone-jack names. |
|
Output devices as |
|
CoreAudio transport of the output named label ( |
|
|
|
The output data source ( |
|
The name of the output a stream actually opened. |
|
Convert interleaved int16 stereo into a float32 |
|
Give all sixteen MIDI channels a program from the SoundFont. |
pyfluidsynth binds new_fluid_midi_driver but not its delete. |
|
|
The label listed for an index, or |
|
Module Contents
- jdxi_editor.audio.soundfont_output.sounddevice_available() bool[source]
Whether sounddevice imported.
- Returns:
bool
- jdxi_editor.audio.soundfont_output.output_devices(module=_INSTALLED) list[tuple[str, int]][source]
Output devices as
(display name, sounddevice index).A repeated name is told apart by its host API; see
label_devices().module=Nonereports that sounddevice is absent. Omitmoduleto query the installed library.- Parameters:
module – sounddevice, or None when the library did not import
- Returns:
list
- jdxi_editor.audio.soundfont_output.chosen_output(current: str, saved: str, labels: list[str]) str[source]
Which output label to put back after the combo is rebuilt.
The label on screen wins, then the saved name.
""means the default output. An explicit(Default)stays the default, so a saved device does not replace it.- Parameters:
current – str the label showing before the rebuild
saved – str the stored preference
labels – list device labels, without the default entry
- Returns:
str a label from
labels, or""for the default
- jdxi_editor.audio.soundfont_output.output_device_for(index: int | None, devices: list[tuple[str, int]], *, platform: str | None = None, transport_type: Callable[[str], str | None] | None = None) int | None[source]
The sounddevice index to open.
On macOS the built-in output is opened as the system default (
None), so CoreAudio follows the headphone jack. Every other selected device keeps its index.Nonestays the default on every platform.- Parameters:
index – Optional[int] chosen sounddevice index
devices – list of
(label, index)platform – str override for tests; the running OS otherwise
transport_type – Callable name -> CoreAudio transport, or None to read it.
"bltn"is the built-in output
- Returns:
Optional[int]
- jdxi_editor.audio.soundfont_output.default_output_route() tuple | None[source]
(device id, data source)of the macOS default output.The data source changes when the headphone jack is plugged or unplugged on the same device.
Noneoff macOS, or when CoreAudio cannot be read.- Returns:
Optional[tuple]
- class jdxi_editor.audio.soundfont_output._AudioAddress[source]
Bases:
ctypes.StructureStructure base class
- jdxi_editor.audio.soundfont_output._coreaudio_library()[source]
CoreAudio, loaded once. None when the framework cannot be opened.
- jdxi_editor.audio.soundfont_output._audio_property(obj: int, selector: int, scope: int, size: int)[source]
(ok, buffer)for one CoreAudio property.
- jdxi_editor.audio.soundfont_output._unindexed_name(label: str) str[source]
A device’s own name, without the suffix added for a repeated one.
- Parameters:
label – str device label
- Returns:
str
- jdxi_editor.audio.soundfont_output._builtin_output_name(label: str) bool[source]
True for the built-in speaker and headphone-jack names.
- jdxi_editor.audio.soundfont_output._coreaudio_outputs() list[tuple[int, str]][source]
Output devices as
(CoreAudio id, name).
- jdxi_editor.audio.soundfont_output._coreaudio_transport(label: str) str | None[source]
CoreAudio transport of the output named label (
bltn, ``usb ``, …).Nonewhen it cannot be read, or when several outputs share the name and disagree.- Parameters:
label – str sounddevice label
- Returns:
Optional[str]
- jdxi_editor.audio.soundfont_output._coreaudio_data_source(device: int) bytes[source]
The output data source (
ispk,hdpn), or empty when it has none.
- jdxi_editor.audio.soundfont_output.opened_output_name(device_index: int | None, devices: list[tuple[str, int]]) str[source]
The name of the output a stream actually opened.
Looked up from the device index the stream reports, so a default combo entry cannot rename it.
- Parameters:
device_index – Optional[int]
devices – list of
(name, index)
- Returns:
str the name, or
""when the index is unknown
- jdxi_editor.audio.soundfont_output.copy_s16(pcm: numpy.ndarray, out: numpy.ndarray) None[source]
Convert interleaved int16 stereo into a float32
(frames, 2)buffer.Samples are scaled by
1/32768. Frames past the int16 block are silence. The float buffer is filled in place.- Parameters:
pcm – np.ndarray int16, interleaved left, right
out – np.ndarray float32, shape
(frames, 2)
- Returns:
None
- jdxi_editor.audio.soundfont_output._select_every_channel(synth, sfid: int) None[source]
Give all sixteen MIDI channels a program from the SoundFont.
Only channel 1 used to be selected. A note sent to it was heard – which is what the Test Note button does – while a MIDI file, the keyboard and every JD-Xi part but Digital 1 play on other channels and were silent.
- Parameters:
synth – the FluidSynth instance
sfid – int the loaded SoundFont’s id
- Returns:
None
- class jdxi_editor.audio.soundfont_output.SoundfontMidiPort(synth, port_name: str = MIDI_PORT_NAME)[source]
FluidSynth’s own MIDI input: a virtual MIDI port (on macOS a CoreMIDI destination) that plays the synth.
Synth.startused to open one along with FluidSynth’s audio driver, and that port is what offered the SoundFont as a MIDI Output. Rendering now goes through our own stream, so the port is opened here on its own: a MIDI router into the synth, and a MIDI driver feeding the router.
- jdxi_editor.audio.soundfont_output._delete_midi_driver(fs)[source]
pyfluidsynth binds new_fluid_midi_driver but not its delete.
- class jdxi_editor.audio.soundfont_output.SoundfontOutput(lock: threading.RLock)[source]
A FluidSynth and the output stream that plays it.
startdoes not callSynth.start. Rendering happens in the stream callback, into a buffer allocated with the stream.- _pcm: numpy.ndarray | None = None[source]
- start(sf_path: str, device: int | None = None, stream_factory: Callable | None = None, synth_factory: Callable | None = None, midi_port_factory: Callable | None = None) int[source]
Load a SoundFont and open the output.
An output that is already open is stopped first.
deviceNone is the default output. On macOS the built-in output is opened the same way, so the headphone jack follows the system route.- Parameters:
sf_path – str
device – Optional[int] sounddevice index
stream_factory – Optional[Callable] builds the output stream
synth_factory – Optional[Callable] builds the synth
midi_port_factory – Optional[Callable] opens the synth’s MIDI port (SoundfontMidiPort); it is optional, so playback carries on without it
- Returns:
int SoundFont id
- _resolve_device() int | None[source]
The index to open now, for the device whose name was chosen.
Looked up afresh every time. An index is a position in PortAudio’s list, and that list is rebuilt whenever the hardware changes, so a remembered one can point at a different device or at nothing. A chosen device that has gone falls back to the system default rather than to whatever now sits at its old position.
- Returns:
Optional[int] sounddevice index, None for the default
- _open_stream(opener: Callable)[source]
Open the output, rereading PortAudio’s device list if it refuses.
PortAudio reads the hardware once, at startup, so a stream opened after headphones have come and gone asks for a device that has moved or disappeared – paInternalError, and the same for the default output, whose identity was resolved just as early. One retry on a freshly read list is the difference between playback following the route and nothing working until restart. The index is resolved again for that retry: the reread is what moves it.
- Parameters:
opener – Callable builds the stream
- Returns:
tuple (the open stream, the index it opened)
- reopen() int[source]
Open the same SoundFont on the route chosen last time.
Used when the macOS default output changes underneath a stream that is following it.
- Returns:
int SoundFont id
- take_route_change() bool[source]
True once when the followed system route has changed.
- Returns:
bool