24#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
25#define right Qt::right
56const quint32 CKID_RIFF = 0x46464952;
57const quint32 CKID_LIST = 0x5453494c;
58const quint32 CKID_INFO = 0x4f464e49;
59const quint32 CKID_RMID = 0x44494d52;
60const quint32 CKID_data = 0x61746164;
61const quint32 CKID_DISP = 0x50534944;
62const quint32 CKID_DLS = 0x20534C44;
85 QFile file(m_fileName = fileName);
86 file.open(QIODevice::ReadOnly);
87 QDataStream ds(&file);
101 m_stream->setByteOrder(QDataStream::LittleEndian);
106QString Rmidi::toString(quint32 ckid)
108 QByteArray data(
reinterpret_cast<char *
>(&ckid),
sizeof(quint32));
109 return QString::fromLatin1(data);
112QByteArray Rmidi::readByteArray(
int size)
115 char *buffer =
new char[size];
116 m_stream->readRawData(buffer, size);
117 QByteArray ba(buffer);
122void Rmidi::skip(quint32 cktype,
int size)
126 m_stream->skipRawData(size);
129quint32 Rmidi::readExpectedChunk(quint32 cktype)
131 quint32 chunkType, len = 0;
132 *m_stream >> chunkType;
133 if (chunkType == cktype) {
150quint32 Rmidi::readChunk(quint32& chunkType)
153 *m_stream >> chunkType;
163quint32 Rmidi::readChunkID()
166 *m_stream >> chunkID;
173void Rmidi::processINFO(
int size)
178 while ((size > 0) && !m_stream->atEnd()) {
179 length = readChunk(chunkID);
182 QString cktype = toString(chunkID);
183 QByteArray data = readByteArray(length);
188void Rmidi::processList(
int size)
192 if (m_stream->atEnd())
return;
193 chunkID = readChunkID();
204void Rmidi::processRMID(
int size)
209 while ((size > 0) && !m_stream->atEnd()) {
210 length = readChunk(chunkID);
214 processData(
"RMID", length);
220 skip(chunkID, length);
226 skip(chunkID, length);
232void Rmidi::processRIFF(
int size)
234 quint32 chunkID = readChunkID();
235 quint32 length = size - 4;
243 if (m_stream->device() !=
nullptr && m_stream->device()->pos() >= 12) {
244 m_stream->device()->seek(m_stream->device()->pos() - 12);
245 processData(
"DLS", length + 12);
247 skip(chunkID, length);
251 qWarning() <<
"Unsupported format";
252 skip(chunkID, length);
256void Rmidi::processData(
const QString& dataType,
int size)
259 QByteArray memdata(size,
'\0');
260 m_stream->readRawData(memdata.data(), size);
267 quint32 length = readExpectedChunk(CKID_RIFF);
The QObject class is the base class of all Qt objects.
Rmidi(QObject *parent=nullptr)
Constructor.
virtual ~Rmidi()
Destructor.
void readFromStream(QDataStream *ds)
Reads a stream.
void signalRiffData(const QString &dataType, const QByteArray &data)
signalRiffData is emitted for each RMID data element
void signalRiffInfo(const QString &infoType, const QByteArray &info)
signalRMidInfo is emitted for each RIFF INFO element
void readFromFile(QString fileName)
Reads a stream from a disk file.