6.0.0-rc4Source

QtFM::MusicPlayer Class

The MusicPlayer class plays chip music from register logs. More…

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

List of all members, including inherited members

Public Functions

boolload(const QByteArray &data, MusicFormat format = MusicFormat::Auto, QString *error = nullptr)
voidplay()
voidpause()
voidstop()
voidsetLoops(bool loops)
boolloops() const
voidsetGain(float dB)
boolisLoaded() const
boolisPlaying() const
doubleposition() const
doubleduration() const
ChipTypechip() const
voidsetImfRate(int ticksPerSecond)
intimfRate() const

Detailed Description

The player reads VGM and gzipped VGZ files with an OPL2 or OPL3 part, DOSBox Raw OPL (DRO) captures, and id Software's IMF files, and plays them on a chip core of its own, beside the engine's sound effects. Writes reach the chip on the chip's own clock, so the timing is exact, and VGM loop points are honoured.

EngineConfig config;
config.sampleRate = rate;
Engine engine(config);
QString error;
if (!engine.music()->load(data, MusicFormat::Auto, &error)) {
    std::fprintf(stderr, "fmplay: %s\n", qPrintable(error));
    return 1;
}
engine.music()->setLoops(false);
engine.music()->play();

See also QtFM::Engine::music().

Differences from Qt

RAD files and chips other than the OPL2 and OPL3 (the YM2612 and SN76489 parts of a Mega Drive VGM, for example) are not played. VGZ needs Nt to be built with zlib. Seeking is not supported.

Member Function Documentation

ChipType QtFM::MusicPlayer::chip() const

Returns the chip that the music plays on.

double QtFM::MusicPlayer::duration() const

Returns the length of the music in seconds.

int QtFM::MusicPlayer::imfRate() const

Returns the tick rate of IMF files.

bool QtFM::MusicPlayer::isLoaded() const

Returns true once music has been loaded.

bool QtFM::MusicPlayer::isPlaying() const

Returns true while the music plays, as of the last render.

bool QtFM::MusicPlayer::load(const QByteArray &data, MusicFormat format = MusicFormat::Auto, QString *error = nullptr)

Loads the music in data, in format or, for MusicFormat::Auto, recognised by its header (IMF has none, and is what remains). Returns false, with the reason in error, if it cannot be played. The new music replaces the old, stopped.

bool QtFM::MusicPlayer::loops() const

Returns true if the music loops.

void QtFM::MusicPlayer::pause()

Pauses, keeping the position.

void QtFM::MusicPlayer::play()

Starts or resumes playing.

double QtFM::MusicPlayer::position() const

Returns the position in seconds, as of the last render.

void QtFM::MusicPlayer::setGain(float dB)

Sets the gain of the music to dB.

void QtFM::MusicPlayer::setImfRate(int ticksPerSecond)

Sets the tick rate of IMF files loaded from now on to ticksPerSecond: 560 (the default) for most games, 700 for Wolfenstein 3D, 280 for Duke Nukem II.

void QtFM::MusicPlayer::setLoops(bool loops)

Sets whether the music starts again at its loop point, or at its start if it has none, when it ends, to loops. Music loops by default.

void QtFM::MusicPlayer::stop()

Stops and returns to the start.