QtFM::PatchBank Class
The PatchBank class holds a named set of patches, such as all the sounds of a game. More…
| Header | #include <QtFM> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::FM) |
| Module | Nt FM C++ Classes |
List of all members, including inherited members
Public Functions
| PatchBank() | |
| QByteArray | toJson() const |
| QByteArray | toCbor() const |
| QByteArray | toChipBank(InstrumentFormat format, QString *error = nullptr) const |
| QByteArray | toCHeader(const QString &symbol) const |
| QString | name() const |
| void | setName(const QString &name) |
| int | size() const |
| bool | isEmpty() const |
| QStringList | names() const |
| bool | contains(const QString &name) const |
| Patch | patch(const QString &name) const |
| Patch | at(int index) const |
| void | insert(const QString &name, const Patch &patch) |
| bool | remove(const QString &name) |
| bool | operator==(const PatchBank &other) const |
| bool | operator!=(const PatchBank &other) const |
Static Public Members
| PatchBank | fromJson(const QByteArray &json, QString *error = nullptr) |
| PatchBank | fromCbor(const QByteArray &cbor, QString *error = nullptr) |
| PatchBank | fromChipBank(const QByteArray &data, InstrumentFormat format, QString *error = nullptr) |
| PatchBank | generalMidi(ChipType chip = ChipType::None) |
Detailed Description
A bank is stored as one JSON document, which names each patch, or as CBOR. toCHeader() turns it into a C array for targets without a file system; fromChipBank() reads the 128 instruments of an AdLib IBK bank.
const QtFM::PatchBank bank = QtFM::PatchBank::fromJson(file.readAll());
engine.play(bank.patch(QStringLiteral("coin")));
See also QtFM::Patch.
Differences from Qt
The IBK percussion fields are ignored. BNK, INS and WOPL banks are not read.
Member Function Documentation
QtFM::PatchBank::PatchBank()
Constructs an empty bank.
Patch QtFM::PatchBank::at(int index) const
Returns the patch at index, or an invalid patch.
bool QtFM::PatchBank::contains(const QString &name) const
Returns true if the bank has a patch named name.
PatchBank QtFM::PatchBank::fromCbor(const QByteArray &cbor, QString *error = nullptr)
Returns the bank in the CBOR encoding cbor, as toCbor() writes it, or an empty bank, with the reason in error.
PatchBank QtFM::PatchBank::fromChipBank(const QByteArray &data, InstrumentFormat format, QString *error = nullptr)
Returns the instruments of the chip bank data in format as patches, or an empty bank, with the reason in error. An IBK bank gives its 128 OPL2 instruments, named as in the bank; an SBI instrument gives a bank of one.
PatchBank QtFM::PatchBank::fromJson(const QByteArray &json, QString *error = nullptr)
Returns the bank in the JSON document json, or an empty bank, with the reason in error. The document is an object with format "qtfm-bank", a name and an array of patches in patches, each named by its name field.
PatchBank QtFM::PatchBank::generalMidi(ChipType chip = ChipType::None)
Returns a General MIDI bank of FM instruments for chip: one patch for each family of eight programs, named gm-piano, gm-chromatic, gm-organ, gm-guitar, gm-bass, gm-strings, gm-ensemble, gm-brass, gm-reed, gm-pipe, gm-lead, gm-pad, gm-synth, gm-ethnic, gm-percussive and gm-effects, all at middle C; and a drum kit of one-shot patches named drum-kick, drum-snare, drum-clap, drum-rim, drum-hihat, drum-openhat, drum-tom, drum-crash and drum-ride.
For ChipType::OPL2 or ChipType::OPL3, the families are two-operator OPL2 instruments, as an AdLib driver would program them, and play on that chip when the engine has it (EngineConfig::chips); the velocity of each note sets the chip's total level. The drums stay on the native engine. For other chips, the native bank is returned.
See also QtFM::MidiPlayer::setInstruments().
void QtFM::PatchBank::insert(const QString &name, const Patch &patch)
Adds patch as name, replacing a patch of that name. The patch in the bank takes name as its Patch::name().
bool QtFM::PatchBank::isEmpty() const
Returns true if the bank has no patches.
QString QtFM::PatchBank::name() const
Returns the name of the bank.
QStringList QtFM::PatchBank::names() const
Returns the names of the patches, in order.
bool QtFM::PatchBank::operator!=(const PatchBank &other) const
Returns true if this bank and other differ.
bool QtFM::PatchBank::operator==(const PatchBank &other) const
Returns true if this bank and other have the same name and patches.
Patch QtFM::PatchBank::patch(const QString &name) const
Returns the patch named name, or an invalid patch.
bool QtFM::PatchBank::remove(const QString &name)
Removes the patch named name; returns false if there is none.
void QtFM::PatchBank::setName(const QString &name)
Sets the name of the bank to name.
int QtFM::PatchBank::size() const
Returns the number of patches.
QByteArray QtFM::PatchBank::toCbor() const
Returns the bank encoded as CBOR.
QByteArray QtFM::PatchBank::toCHeader(const QString &symbol) const
Returns a C header that defines the bank's CBOR encoding as static const unsigned char symbol and its size as symbol_size, for targets without a file system. Load it with fromCbor(), through QByteArray::fromRawData().
QByteArray QtFM::PatchBank::toChipBank(InstrumentFormat format, QString *error = nullptr) const
Returns the bank as a chip bank in format, or an empty array, with the reason in error. For InstrumentFormat::Ibk, the bank must have at most 128 patches of two operators; the rest of the 128 instruments are left empty.
QByteArray QtFM::PatchBank::toJson() const
Returns the bank as a JSON document.