6.0.0-rc4Source

QtFM::FmSound Class

The FmSound type is one sound effect: a patch, and how it plays. More…

Header#include <QtFMQml/qfmqml.h>
CMaketarget_link_libraries(app PRIVATE Nt::FMQml)
ModuleNt FM QML Types
InheritsQObject, QQmlParserStatus

List of all members, including inherited members

Public Functions

FmSound(QObject *parent = nullptr)
~FmSound()
QUrlsource() const
voidsetSource(const QUrl &source)
FmPatchValue *patch() const
voidsetPatch(FmPatchValue *patch)
intchip() const
voidsetChip(int chip)
doublepitch() const
voidsetPitch(double semitones)
doublegain() const
voidsetGain(double dB)
doublepan() const
voidsetPan(double pan)
boolloop() const
voidsetLoop(bool loop)
doublepitchVariance() const
voidsetPitchVariance(double semitones)
intbus() const
voidsetBus(int bus)
intpriority() const
voidsetPriority(int priority)
intmaxInstances() const
voidsetMaxInstances(int count)
boolisPlaying() const
QStringerror() const
PatchcurrentPatch() const
voidplay()
voidstop(bool immediate = false)

Reimplemented Public Functions

Signals

Detailed Description

Set source to a patch file (JSON, or an AdLib SBI instrument) or patch to an FmPatchValue, then call play(). Each play() starts another voice; maxInstances caps how many run at once. pitch, gain and pan apply to the voices that play, smoothed, so they can be bound to the game:

property FmSound coin: FmSound {
    patch: FmPatch.generate(FmPatch.Pickup, 3)
    pitchVariance: 1            // +/- semitones per play
    maxInstances: 4
}
property FmSound engineHum: FmSound {
    patch: FmPatch.generate(FmPatch.Engine, 42)
    loop: true
    pitch: game.speed / 10      // bound live, smoothed on the audio thread
}
property FmSound laser: FmSound {
    patch: FmPatch.generate(FmPatch.Laser, 4, FmChip.OPL2)
    chip: FmChip.OPL2           // played on the emulated AdLib
}

Setting chip to FmChip.OPL2 or FmChip.OPL3 plays the sound on the emulated chip; FmChip.None, the default, on the native engine.

Differences from Qt

Network urls are not loaded. pan replaces the pan of playing voices rather than adding to it.

Member Function Documentation

[explicit] QtFM::FmSound::FmSound(QObject *parent = nullptr)

Constructs a sound with parent.

[override] QtFM::FmSound::~FmSound()

Destroys the sound. Its voices play on.

int QtFM::FmSound::bus() const

Returns the bus: 0 effects (the default), 1 music, 2 interface.

[signal] void QtFM::FmSound::busChanged()

This signal is emitted when bus() changes.

int QtFM::FmSound::chip() const

Returns the chip to play on, an FmChip value; FmChip.None for the native engine. Set it before the engine plays its first sound.

[signal] void QtFM::FmSound::chipChanged()

This signal is emitted when chip() changes.

[override] void QtFM::FmSound::classBegin()

Reimplements QQmlParserStatus::classBegin().

[override] void QtFM::FmSound::componentComplete()

Reimplements QQmlParserStatus::componentComplete().

Patch QtFM::FmSound::currentPatch() const

Returns the patch that play() plays: patch if set, else the one loaded from source, with loop and chip applied.

QString QtFM::FmSound::error() const

Returns why source could not be loaded, or an empty string.

[signal] void QtFM::FmSound::errorChanged()

This signal is emitted when error() changes.

[signal] void QtFM::FmSound::finished()

This signal is emitted when the last voice of the sound ends.

double QtFM::FmSound::gain() const

Returns the gain in decibels; changing it also affects the voices playing.

[signal] void QtFM::FmSound::gainChanged()

This signal is emitted when gain() changes.

bool QtFM::FmSound::isPlaying() const

Returns true if a voice of the sound plays.

bool QtFM::FmSound::loop() const

Returns true if the sound sustains until stop(); the patch's own setting until it is set.

[signal] void QtFM::FmSound::loopChanged()

This signal is emitted when loop() changes.

int QtFM::FmSound::maxInstances() const

Returns the number of voices of this sound that play at once; 0, the default, for no limit. A play() beyond it stops the oldest.

[signal] void QtFM::FmSound::maxInstancesChanged()

This signal is emitted when maxInstances() changes.

double QtFM::FmSound::pan() const

Returns the pan, from -1 to 1; changing it also moves the voices playing.

[signal] void QtFM::FmSound::panChanged()

This signal is emitted when pan() changes.

FmPatchValue * QtFM::FmSound::patch() const

Returns the patch set from FmPatch, which is played instead of source, or nullptr.

[signal] void QtFM::FmSound::patchChanged()

This signal is emitted when patch() changes.

double QtFM::FmSound::pitch() const

Returns the semitones added to the patch's note; changing them also moves the voices playing.

[signal] void QtFM::FmSound::pitchChanged()

This signal is emitted when pitch() changes.

double QtFM::FmSound::pitchVariance() const

Returns the pitch variance: each play() moves the pitch by a random amount of up to this many semitones either way.

[signal] void QtFM::FmSound::pitchVarianceChanged()

This signal is emitted when pitchVariance() changes.

void QtFM::FmSound::play()

Starts a voice of the sound.

[signal] void QtFM::FmSound::playingChanged()

This signal is emitted when isPlaying() changes.

int QtFM::FmSound::priority() const

Returns the priority of the voices: a higher one survives voice stealing.

[signal] void QtFM::FmSound::priorityChanged()

This signal is emitted when priority() changes.

void QtFM::FmSound::setBus(int bus)

Sets the bus property to bus.

See also bus().

void QtFM::FmSound::setChip(int chip)

Sets the chip property to chip.

See also chip().

void QtFM::FmSound::setGain(double dB)

Sets the gain property to dB.

See also gain().

void QtFM::FmSound::setLoop(bool loop)

Sets the loop property to loop.

See also loop().

void QtFM::FmSound::setMaxInstances(int count)

Sets the maxInstances property to count.

See also maxInstances().

void QtFM::FmSound::setPan(double pan)

Sets the pan property to pan.

See also pan().

void QtFM::FmSound::setPatch(FmPatchValue *patch)

Sets the patch property to patch.

See also patch().

void QtFM::FmSound::setPitch(double semitones)

Sets the pitch property to semitones.

See also pitch().

void QtFM::FmSound::setPitchVariance(double semitones)

Sets the pitchVariance property to semitones.

See also pitchVariance().

void QtFM::FmSound::setPriority(int priority)

Sets the priority property to priority.

See also priority().

void QtFM::FmSound::setSource(const QUrl &source)

Sets the source property to source.

See also source().

QUrl QtFM::FmSound::source() const

Returns the url of a patch file: JSON, or an SBI instrument. Relative urls are relative to the document.

[signal] void QtFM::FmSound::sourceChanged()

This signal is emitted when source() changes.

void QtFM::FmSound::stop(bool immediate = false)

Releases every voice of the sound; if immediate is true, they fade out in 2 ms instead.