IInstrumentHost
#include "crosspad/instrument/IInstrumentHost.hpp"Generated from crosspad/instrument/IInstrumentHost.hpp in crosspad-core. Edit the header’s doxygen comments to change this page.
crosspad::IInstrumentHost
Section titled “crosspad::IInstrumentHost”Lends the pitched sample engine to an app that plays an instrument of its own (Pitch Play), and keeps that app’s instrument library.
The pitched engine and the kit engine take turns using the same memory, so one of them is active at a time. An app borrows it: a load stops the kits’ engine and builds the app’s bank; release() frees the bank and puts the current kit back as it was. Everything that touches the card reading WAVs, reading and writing instrument files, copying samples runs on the host’s worker, never on the caller’s (UI) thread: a request returns at once and the caller polls state().
An instrument is a kit.json with “engine”:“pitched” (KitInfo::instrument), kept in libraryRoot() rather than among the kits, so the Kits list never shows it. Zone samples resolve the way a kit’s do: relative to the folder of KitInfo::path, or as absolute logical paths (“/crosspad/…”).
| Field | Type | Description |
|---|---|---|
kFileName | constexpr const char * | |
kMaxZoneSeconds | constexpr float | A zone longer than this is cut to it on load: an instrument is notes, and the limit keeps loading fast and the bank small. |
Members
| Member | Description |
|---|---|
requestLoad | Take the engine, if it is not held already, and build spec's bank. |
requestOpen | Read the instrument file at path (logical, like KitInfo::path) and load it. |
requestSave | Write spec to its KitInfo::path, making the folder. |
release | Give the engine back: the bank goes and the current kit is reloaded. |
state | |
instrument | The instrument of the last load, open or save that succeeded, its zones’ roots filled in where the load detected them. |
message | Why the last request failed, or what a load that succeeded had to cut short. |
libraryRoot | The folder instruments live in, logical (“/crosspad/pitchplay”): one sub-folder per instrument, its file named kFileName. |
zoneAudio |
Methods
requestLoad
Section titled “requestLoad”virtual bool requestLoad(const KitInfo &spec) = 0Take the engine, if it is not held already, and build spec's bank.
A request made while another runs waits for it; one already waiting is replaced (newest wins). State stays Busy until the last is through. False only where the host cannot take requests at all.
requestOpen
Section titled “requestOpen”virtual bool requestOpen(const std::string &path) = 0Read the instrument file at path (logical, like KitInfo::path) and load it.
instrument() is what was read once it is Ready.
requestSave
Section titled “requestSave”virtual bool requestSave(const KitInfo &spec) = 0Write spec to its KitInfo::path, making the folder.
A zone whose sample lives outside that folder is copied into it first, so an instrument outlives the takes it was made from. On success instrument() is the spec as written (its zones relative).
release
Section titled “release”virtual void release() = 0Give the engine back: the bank goes and the current kit is reloaded.
Safe when nothing is held. Call from the UI thread.
virtual State state() const =0instrument
Section titled “instrument”virtual KitInfo instrument() const =0The instrument of the last load, open or save that succeeded, its zones’ roots filled in where the load detected them.
message
Section titled “message”virtual std::string message() const =0Why the last request failed, or what a load that succeeded had to cut short.
Empty when there is nothing to say.
libraryRoot
Section titled “libraryRoot”virtual std::string libraryRoot() const =0The folder instruments live in, logical (“/crosspad/pitchplay”): one sub-folder per instrument, its file named kFileName.
zoneAudio
Section titled “zoneAudio”virtual ZoneAudio zoneAudio(uint8_t zoneIdx) constDeclared in crosspad/instrument/IInstrumentHost.hpp:27.
crosspad::IInstrumentHost::ZoneAudio
Section titled “crosspad::IInstrumentHost::ZoneAudio”What the loaded bank made of a zone: the length of its PCM and the rate it ended up at.
A caller setting loop points needs this the spec stores them as frames, and frames mean nothing without a length to put them against, so a UI without it can only guess.
Not pure, and zero where nothing is loaded: a host that does not keep its bank around (the PC simulator) is still a host, and a caller must treat frames == 0 as “cannot say” rather than “empty”.
| Field | Type | Description |
|---|---|---|
frames | uint32_t | |
sampleRate | uint32_t |
Declared in crosspad/instrument/IInstrumentHost.hpp:80.