6.0.0-rc4Source

QtFM::PatchBank Class

The PatchBank class holds a named set of patches, such as all the sounds of a game. More…

Header#include <QtFM>
CMaketarget_link_libraries(app PRIVATE Nt::FM)
ModuleNt FM C++ Classes

List of all members, including inherited members

Public Functions

PatchBank()
QByteArraytoJson() const
QByteArraytoCbor() const
QByteArraytoChipBank(InstrumentFormat format, QString *error = nullptr) const
QByteArraytoCHeader(const QString &symbol) const
QStringname() const
voidsetName(const QString &name)
intsize() const
boolisEmpty() const
QStringListnames() const
boolcontains(const QString &name) const
Patchpatch(const QString &name) const
Patchat(int index) const
voidinsert(const QString &name, const Patch &patch)
boolremove(const QString &name)
booloperator==(const PatchBank &other) const
booloperator!=(const PatchBank &other) const

Static Public Members

PatchBankfromJson(const QByteArray &json, QString *error = nullptr)
PatchBankfromCbor(const QByteArray &cbor, QString *error = nullptr)
PatchBankfromChipBank(const QByteArray &data, InstrumentFormat format, QString *error = nullptr)
PatchBankgeneralMidi(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.

[static] 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.

[static] 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.

[static] 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.

[static] 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.