drumstick 2.9.0
C++ MIDI libraries using Qt objects, idioms, and style.

Standard MIDI Files input/output. More...

#include <qsmf.h>

Inheritance diagram for QSmf:

Signals

void signalSMFError (const QString &errorStr)
 Emitted for a SMF read or write error. More...
 
void signalSMFHeader (int format, int ntrks, int division)
 Emitted after reading a SMF header. More...
 
void signalSMFNoteOn (int chan, int pitch, int vol)
 Emitted after reading a Note On message. More...
 
void signalSMFNoteOff (int chan, int pitch, int vol)
 Emitted after reading a Note Off message. More...
 
void signalSMFKeyPress (int chan, int pitch, int press)
 Emitted after reading a Polyphonic Aftertouch message. More...
 
void signalSMFCtlChange (int chan, int ctl, int value)
 Emitted after reading a Control Change message. More...
 
void signalSMFPitchBend (int chan, int value)
 Emitted after reading a Bender message. More...
 
void signalSMFProgram (int chan, int patch)
 Emitted after reading a Program change message. More...
 
void signalSMFChanPress (int chan, int press)
 Emitted after reading a Channel Aftertouch message. More...
 
void signalSMFSysex (const QByteArray &data)
 Emitted after reading a System Exclusive message. More...
 
void signalSMFSeqSpecific (const QByteArray &data)
 Emitted after reading a Sequencer specific message. More...
 
void signalSMFMetaUnregistered (int typ, const QByteArray &data)
 Emitted after reading an unregistered SMF Meta message. More...
 
void signalSMFMetaMisc (int typ, const QByteArray &data)
 Emitted after reading any SMF Meta message. More...
 
void signalSMFSequenceNum (int seq)
 Emitted after reading a Sequence number message. More...
 
void signalSMFforcedChannel (int channel)
 Emitted after reading a Forced channel message. More...
 
void signalSMFforcedPort (int port)
 Emitted after reading a Forced port message. More...
 
Q_DECL_DEPRECATED void signalSMFText (int typ, const QString &data)
 Emitted after reading a SMF text message. More...
 
void signalSMFText2 (int typ, const QByteArray &data)
 Emitted after reading a SMF text message. More...
 
void signalSMFSmpte (int b0, int b1, int b2, int b3, int b4)
 Emitted after reading a SMPT offset message. More...
 
void signalSMFTimeSig (int b0, int b1, int b2, int b3)
 Emitted after reading a SMF Time signature message. More...
 
void signalSMFKeySig (int b0, int b1)
 Emitted after reading a SMF Key Signature smessage. More...
 
void signalSMFTempo (int tempo)
 Emitted after reading a Tempo Change message. More...
 
void signalSMFendOfTrack ()
 Emitted after reading a End-Of-Track message.
 
void signalSMFTrackStart ()
 Emitted after reading a track prefix.
 
void signalSMFTrackEnd ()
 Emitted after a track has finished.
 
void signalSMFWriteTempoTrack ()
 Emitted to request the user to prepare the tempo track. More...
 
void signalSMFWriteTrack (int track)
 Emitted to request the user to write a track. More...
 

Public Member Functions

 QSmf (QObject *parent=nullptr)
 Constructor. More...
 
virtual ~QSmf ()
 Destructor.
 
void readFromStream (QDataStream *stream)
 Reads a SMF stream. More...
 
void readFromFile (const QString &fileName)
 Reads a SMF stream from a disk file. More...
 
void writeToStream (QDataStream *stream)
 Writes a SMF stream. More...
 
void writeToFile (const QString &fileName)
 Writes a SMF stream to a disk file. More...
 
void writeMetaEvent (long deltaTime, int type, const QByteArray &data)
 Writes a variable length Meta Event. More...
 
void writeMetaEvent (long deltaTime, int type, const QString &data)
 Writes a Text Meta Event. More...
 
void writeMetaEvent (long deltaTime, int type, int data)
 Writes a simple Meta event. More...
 
void writeMetaEvent (long deltaTime, int type)
 Writes a simple Meta event. More...
 
void writeMidiEvent (long deltaTime, int type, int chan, int b1)
 Writes a MIDI message with a single parameter. More...
 
void writeMidiEvent (long deltaTime, int type, int chan, int b1, int b2)
 Writes a MIDI message with two parameters. More...
 
void writeMidiEvent (long deltaTime, int type, int chan, const QByteArray &data)
 Writes a variable length MIDI message. More...
 
void writeMidiEvent (long deltaTime, int type, long len, char *data)
 Writes a variable length MIDI message. More...
 
void writeTempo (long deltaTime, long tempo)
 Writes a Tempo change message. More...
 
void writeBpmTempo (long deltaTime, int tempo)
 Writes a Tempo change message. More...
 
void writeTimeSignature (long deltaTime, int num, int den, int cc, int bb)
 Writes a Time Signature message. More...
 
void writeKeySignature (long deltaTime, int tone, int mode)
 Writes a key Signature message. More...
 
void writeSequenceNumber (long deltaTime, int seqnum)
 Writes a MIDI Sequence number. More...
 
long getCurrentTime ()
 Gets the current time in ticks. More...
 
long getCurrentTempo ()
 Gets the current tempo. More...
 
long getRealTime ()
 Gets the real time in seconds. More...
 
long getFilePos ()
 Gets the position in the SMF stream. More...
 
int getDivision ()
 Gets the resolution. More...
 
void setDivision (int division)
 Sets the resolution. More...
 
int getTracks ()
 Gets the number of tracks. More...
 
void setTracks (int tracks)
 Sets the number of tracks. More...
 
int getFileFormat ()
 Gets the SMF file format. More...
 
void setFileFormat (int fileFormat)
 Sets the SMF file format. More...
 
Q_DECL_DEPRECATED QTextCodec * getTextCodec ()
 Gets the text codec used for text meta-events I/O. More...
 
Q_DECL_DEPRECATED void setTextCodec (QTextCodec *codec)
 Sets the text codec for text meta-events. More...
 

Detailed Description

Standard MIDI Files input/output.

This class is used to parse and encode Standard MIDI Files (SMF)

Examples
dumprmi.cpp, dumpsmf.cpp, guiplayer.cpp, and playsmf.cpp.

Definition at line 102 of file qsmf.h.

Constructor & Destructor Documentation

◆ QSmf()

QSmf ( QObject parent = nullptr)
explicit

Constructor.

Parameters
parentOptional parent object

Definition at line 103 of file qsmf.cpp.

Member Function Documentation

◆ getCurrentTempo()

long getCurrentTempo ( )

Gets the current tempo.

Returns
Tempo in us per quarter

Definition at line 1143 of file qsmf.cpp.

◆ getCurrentTime()

long getCurrentTime ( )

Gets the current time in ticks.

Returns
Time in ticks

Definition at line 1134 of file qsmf.cpp.

◆ getDivision()

int getDivision ( )

Gets the resolution.

Returns
Resolution in ticks per quarter note

Definition at line 1161 of file qsmf.cpp.

◆ getFileFormat()

int getFileFormat ( )

Gets the SMF file format.

Returns
File format (0, 1, or 2)

Definition at line 1197 of file qsmf.cpp.

◆ getFilePos()

long getFilePos ( )

Gets the position in the SMF stream.

Returns
Position offset in the stream

Definition at line 1215 of file qsmf.cpp.

◆ getRealTime()

long getRealTime ( )

Gets the real time in seconds.

Returns
Time in seconds

Definition at line 1152 of file qsmf.cpp.

◆ getTextCodec()

QTextCodec * getTextCodec ( )

Gets the text codec used for text meta-events I/O.

Returns
QTextCodec pointer
Since
0.2.0
Deprecated:
because the class QTextCodec was removed from QtCore since Qt6.

Definition at line 1226 of file qsmf.cpp.

◆ getTracks()

int getTracks ( )

Gets the number of tracks.

Returns
Number of tracks

Definition at line 1179 of file qsmf.cpp.

◆ readFromFile()

void readFromFile ( const QString &  fileName)

Reads a SMF stream from a disk file.

Parameters
fileNameName of an existing file.

Definition at line 452 of file qsmf.cpp.

References QSmf::readFromStream().

◆ readFromStream()

void readFromStream ( QDataStream *  stream)

Reads a SMF stream.

Parameters
streamPointer to an existing and opened stream

Definition at line 442 of file qsmf.cpp.

Referenced by QSmf::readFromFile().

◆ setDivision()

void setDivision ( int  division)

Sets the resolution.

Parameters
divisionResolution in ticks per quarter note

Definition at line 1170 of file qsmf.cpp.

◆ setFileFormat()

void setFileFormat ( int  fileFormat)

Sets the SMF file format.

Parameters
fileFormatFile format (0, 1, or 2)

Definition at line 1206 of file qsmf.cpp.

◆ setTextCodec()

void setTextCodec ( QTextCodec *  codec)

Sets the text codec for text meta-events.

The engine doesn't take ownership of the codec instance.

Parameters
codecQTextCodec pointer
Since
0.2.0
Deprecated:
because the class QTextCodec was removed from QtCore since Qt6.

Definition at line 1239 of file qsmf.cpp.

◆ setTracks()

void setTracks ( int  tracks)

Sets the number of tracks.

Parameters
tracksNumber of tracks

Definition at line 1188 of file qsmf.cpp.

◆ signalSMFChanPress

void signalSMFChanPress ( int  chan,
int  press 
)
signal

Emitted after reading a Channel Aftertouch message.

Parameters
chanMIDI Channel
pressPressure amount

◆ signalSMFCtlChange

void signalSMFCtlChange ( int  chan,
int  ctl,
int  value 
)
signal

Emitted after reading a Control Change message.

Parameters
chanMIDI Channel
ctlMIDI Controller
valueControl value

◆ signalSMFError

void signalSMFError ( const QString &  errorStr)
signal

Emitted for a SMF read or write error.

Parameters
errorStrError string

◆ signalSMFforcedChannel

void signalSMFforcedChannel ( int  channel)
signal

Emitted after reading a Forced channel message.

Parameters
channelMIDI Channel

◆ signalSMFforcedPort

void signalSMFforcedPort ( int  port)
signal

Emitted after reading a Forced port message.

Parameters
portPort number

◆ signalSMFHeader

void signalSMFHeader ( int  format,
int  ntrks,
int  division 
)
signal

Emitted after reading a SMF header.

Parameters
formatSMF format (0/1)
ntrksNumber pof tracks
divisionDivision (resolution in ticks per quarter note)

◆ signalSMFKeyPress

void signalSMFKeyPress ( int  chan,
int  pitch,
int  press 
)
signal

Emitted after reading a Polyphonic Aftertouch message.

Parameters
chanMIDI Channel
pitchMIDI Note
pressPressure amount

◆ signalSMFKeySig

void signalSMFKeySig ( int  b0,
int  b1 
)
signal

Emitted after reading a SMF Key Signature smessage.

Parameters
b0Number of alterations (negative=flats, positive=sharps)
b1Scale Mode (0=major, 1=minor)

◆ signalSMFMetaMisc

void signalSMFMetaMisc ( int  typ,
const QByteArray &  data 
)
signal

Emitted after reading any SMF Meta message.

Parameters
typMessage type
dataMessage data

◆ signalSMFMetaUnregistered

void signalSMFMetaUnregistered ( int  typ,
const QByteArray &  data 
)
signal

Emitted after reading an unregistered SMF Meta message.

Parameters
typMessage type
dataMessage data
Since
0.2.0

◆ signalSMFNoteOff

void signalSMFNoteOff ( int  chan,
int  pitch,
int  vol 
)
signal

Emitted after reading a Note Off message.

Parameters
chanMIDI Channel
pitchMIDI Note
volVelocity

◆ signalSMFNoteOn

void signalSMFNoteOn ( int  chan,
int  pitch,
int  vol 
)
signal

Emitted after reading a Note On message.

Parameters
chanMIDI Channel
pitchMIDI Note
volVelocity

◆ signalSMFPitchBend

void signalSMFPitchBend ( int  chan,
int  value 
)
signal

Emitted after reading a Bender message.

Parameters
chanMIDI Channel
valueBender value

◆ signalSMFProgram

void signalSMFProgram ( int  chan,
int  patch 
)
signal

Emitted after reading a Program change message.

Parameters
chanMIDI Channel
patchProgram number

◆ signalSMFSeqSpecific

void signalSMFSeqSpecific ( const QByteArray &  data)
signal

Emitted after reading a Sequencer specific message.

Parameters
dataMessage data

◆ signalSMFSequenceNum

void signalSMFSequenceNum ( int  seq)
signal

Emitted after reading a Sequence number message.

Parameters
seqSequence number

◆ signalSMFSmpte

void signalSMFSmpte ( int  b0,
int  b1,
int  b2,
int  b3,
int  b4 
)
signal

Emitted after reading a SMPT offset message.

Parameters
b0Hours
b1Minutes
b2Seconds
b3Frames
b4Fractional frames

◆ signalSMFSysex

void signalSMFSysex ( const QByteArray &  data)
signal

Emitted after reading a System Exclusive message.

Parameters
dataSysex bytes

◆ signalSMFTempo

void signalSMFTempo ( int  tempo)
signal

Emitted after reading a Tempo Change message.

Parameters
tempoMicroseconds per quarter note

◆ signalSMFText

Q_DECL_DEPRECATED void signalSMFText ( int  typ,
const QString &  data 
)
signal

Emitted after reading a SMF text message.

Parameters
typText type
dataText data
Deprecated:
because the class QTextCodec was removed from QtCore since Qt6. use signalSMFText2() instead.

◆ signalSMFText2

void signalSMFText2 ( int  typ,
const QByteArray &  data 
)
signal

Emitted after reading a SMF text message.

Parameters
typText type
dataText data

◆ signalSMFTimeSig

void signalSMFTimeSig ( int  b0,
int  b1,
int  b2,
int  b3 
)
signal

Emitted after reading a SMF Time signature message.

Parameters
b0Numerator
b1Denominator (exponent in a power of two)
b2Number of MIDI clocks per metronome click
b3Number of notated 32nd notes per 24 MIDI clocks

◆ signalSMFWriteTempoTrack

void signalSMFWriteTempoTrack ( )
signal

Emitted to request the user to prepare the tempo track.

The signal handler should not call the writeTempo() or writeBpmTempo() methods directly, but instead it should fill the Conductor track with tempo and other SMF meta events like key and time signatures to be written later, at the signalSMFWriteTrack() handler.

The Conductor track is the first track in a format 1 SMF.

◆ signalSMFWriteTrack

void signalSMFWriteTrack ( int  track)
signal

Emitted to request the user to write a track.

Parameters
trackTrack number

◆ writeBpmTempo()

void writeBpmTempo ( long  deltaTime,
int  tempo 
)

Writes a Tempo change message.

Parameters
deltaTimeTime offset in ticks
tempoTempo expressed in quarter notes per minute

Definition at line 767 of file qsmf.cpp.

References QSmf::writeTempo().

◆ writeKeySignature()

void writeKeySignature ( long  deltaTime,
int  tone,
int  mode 
)

Writes a key Signature message.

Parameters
deltaTimeTime offset in ticks
toneNumber of alterations (positive=sharps, negative=flats)
modeScale mode (0=major, 1=minor)

Definition at line 799 of file qsmf.cpp.

References drumstick::File::key_signature, and drumstick::File::meta_event.

◆ writeMetaEvent() [1/4]

void writeMetaEvent ( long  deltaTime,
int  type 
)

Writes a simple Meta event.

Parameters
deltaTimeTime offset in ticks
typeMeta event type

Definition at line 587 of file qsmf.cpp.

References drumstick::File::meta_event.

◆ writeMetaEvent() [2/4]

void writeMetaEvent ( long  deltaTime,
int  type,
const QByteArray &  data 
)

Writes a variable length Meta Event.

Parameters
deltaTimeTime offset in ticks
typeMeta event type
dataMessage data

Definition at line 534 of file qsmf.cpp.

References drumstick::File::meta_event.

◆ writeMetaEvent() [3/4]

void writeMetaEvent ( long  deltaTime,
int  type,
const QString &  data 
)

Writes a Text Meta Event.

Parameters
deltaTimeTime offset in ticks
typeMeta event type
dataMessage text

Definition at line 551 of file qsmf.cpp.

References drumstick::File::meta_event.

◆ writeMetaEvent() [4/4]

void writeMetaEvent ( long  deltaTime,
int  type,
int  data 
)

Writes a simple Meta event.

Parameters
deltaTimeTime offset in ticks
typeMeta event type
dataMeta event data
Since
0.2.0

Definition at line 573 of file qsmf.cpp.

References drumstick::File::meta_event.

◆ writeMidiEvent() [1/4]

void writeMidiEvent ( long  deltaTime,
int  type,
int  chan,
const QByteArray &  data 
)

Writes a variable length MIDI message.

Parameters
deltaTimeTime offset in ticks
typeMIDI event type
chanMIDI Channel
dataMessage data

Definition at line 602 of file qsmf.cpp.

References drumstick::File::end_of_sysex, and drumstick::File::system_exclusive.

◆ writeMidiEvent() [2/4]

void writeMidiEvent ( long  deltaTime,
int  type,
int  chan,
int  b1 
)

Writes a MIDI message with a single parameter.

Parameters
deltaTimeTime offset in ticks
typeMIDI event type
chanMIDI Channel
b1Message parameter

Definition at line 648 of file qsmf.cpp.

References drumstick::File::end_of_sysex, and drumstick::File::system_exclusive.

◆ writeMidiEvent() [3/4]

void writeMidiEvent ( long  deltaTime,
int  type,
int  chan,
int  b1,
int  b2 
)

Writes a MIDI message with two parameters.

Parameters
deltaTimeTime offset in ticks
typeMIDI event type
chanMIDI Channel
b1Message parameter 1
b2Message parameter 2

Definition at line 677 of file qsmf.cpp.

References drumstick::File::end_of_sysex, and drumstick::File::system_exclusive.

◆ writeMidiEvent() [4/4]

void writeMidiEvent ( long  deltaTime,
int  type,
long  len,
char *  data 
)

Writes a variable length MIDI message.

Parameters
deltaTimeTime offset in ticks
typeMIDI event type
lenMessage length
dataMessage data

Definition at line 706 of file qsmf.cpp.

References drumstick::File::end_of_sysex, and drumstick::File::system_exclusive.

◆ writeSequenceNumber()

void writeSequenceNumber ( long  deltaTime,
int  seqnum 
)

Writes a MIDI Sequence number.

Parameters
deltaTimeTime offset in ticks
seqnumSequence number

Definition at line 735 of file qsmf.cpp.

References drumstick::File::meta_event, and drumstick::File::sequence_number.

◆ writeTempo()

void writeTempo ( long  deltaTime,
long  tempo 
)

Writes a Tempo change message.

Parameters
deltaTimeTime offset in ticks
tempoTempo in microseconds per quarter note

Definition at line 751 of file qsmf.cpp.

References drumstick::File::meta_event, and drumstick::File::set_tempo.

Referenced by QSmf::writeBpmTempo().

◆ writeTimeSignature()

void writeTimeSignature ( long  deltaTime,
int  num,
int  den,
int  cc,
int  bb 
)

Writes a Time Signature message.

Parameters
deltaTimeTime offset in ticks
numNumerator
denDenominator (exponent for a power of two)
ccNumber of MIDI clocks in a metronome click
bbNumber of notated 32nd notes in 24 MIDI clocks

Definition at line 781 of file qsmf.cpp.

References drumstick::File::meta_event, and drumstick::File::time_signature.

◆ writeToFile()

void writeToFile ( const QString &  fileName)

Writes a SMF stream to a disk file.

Parameters
fileNameFile name

Definition at line 475 of file qsmf.cpp.

References QSmf::writeToStream().

◆ writeToStream()

void writeToStream ( QDataStream *  stream)

Writes a SMF stream.

Parameters
streamPointer to an existing and opened stream

Definition at line 465 of file qsmf.cpp.

Referenced by QSmf::writeToFile().


The documentation for this class was generated from the following files: