QtFM::FmSound Class
The FmSound type is one sound effect: a patch, and how it plays. More…
| Header | #include <QtFMQml/qfmqml.h> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::FMQml) |
| Module | Nt FM QML Types |
| Inherits | QObject, QQmlParserStatus |
List of all members, including inherited members
Public Functions
| FmSound(QObject *parent = nullptr) | |
| ~FmSound() | |
| QUrl | source() const |
| void | setSource(const QUrl &source) |
| FmPatchValue * | patch() const |
| void | setPatch(FmPatchValue *patch) |
| int | chip() const |
| void | setChip(int chip) |
| double | pitch() const |
| void | setPitch(double semitones) |
| double | gain() const |
| void | setGain(double dB) |
| double | pan() const |
| void | setPan(double pan) |
| bool | loop() const |
| void | setLoop(bool loop) |
| double | pitchVariance() const |
| void | setPitchVariance(double semitones) |
| int | bus() const |
| void | setBus(int bus) |
| int | priority() const |
| void | setPriority(int priority) |
| int | maxInstances() const |
| void | setMaxInstances(int count) |
| bool | isPlaying() const |
| QString | error() const |
| Patch | currentPatch() const |
| void | play() |
| void | stop(bool immediate = false) |
Reimplemented Public Functions
| void | classBegin() |
| void | componentComplete() |
Signals
| void | sourceChanged() |
| void | patchChanged() |
| void | chipChanged() |
| void | pitchChanged() |
| void | gainChanged() |
| void | panChanged() |
| void | loopChanged() |
| void | pitchVarianceChanged() |
| void | busChanged() |
| void | priorityChanged() |
| void | maxInstancesChanged() |
| void | playingChanged() |
| void | errorChanged() |
| void | finished() |
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
QtFM::FmSound::FmSound(QObject *parent = nullptr)
Constructs a sound with parent.
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.
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.
void QtFM::FmSound::chipChanged()
This signal is emitted when chip() changes.
void QtFM::FmSound::classBegin()
Reimplements QQmlParserStatus::classBegin().
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.
void QtFM::FmSound::errorChanged()
This signal is emitted when error() changes.
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.
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.
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.
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.
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.
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.
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.
void QtFM::FmSound::pitchVarianceChanged()
This signal is emitted when pitchVariance() changes.
void QtFM::FmSound::play()
Starts a voice of the sound.
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.
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.
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.