drumstick 2.9.0
C++ MIDI libraries using Qt objects, idioms, and style.
qwrk.h
Go to the documentation of this file.
1/*
2 WRK File component
3 Copyright (C) 2010-2023, Pedro Lopez-Cabanillas <plcl@users.sf.net>
4
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifndef DRUMSTICK_QWRK_H
20#define DRUMSTICK_QWRK_H
21
22#include "macros.h"
23#include <QObject>
24#include <QScopedPointer>
25
26class QTextCodec;
27class QDataStream;
28
34#if defined(DRUMSTICK_STATIC)
35#define DRUMSTICK_FILE_EXPORT
36#else
37#if defined(drumstick_file_EXPORTS)
38#define DRUMSTICK_FILE_EXPORT Q_DECL_EXPORT
39#else
40#define DRUMSTICK_FILE_EXPORT Q_DECL_IMPORT
41#endif
42#endif
43
44namespace drumstick { namespace File {
45
84 END_CHUNK = 255
85};
86
95class DRUMSTICK_FILE_EXPORT QWrk : public QObject
96{
97 Q_OBJECT
98 Q_ENUM(WrkChunkType)
99public:
100 explicit QWrk(QObject * parent = nullptr);
101 virtual ~QWrk();
102
103 void readFromStream(QDataStream *stream);
104 void readFromFile(const QString& fileName);
105 Q_DECL_DEPRECATED QTextCodec* getTextCodec();
106 Q_DECL_DEPRECATED void setTextCodec(QTextCodec *codec);
107 long getFilePos();
108
109 int getNow() const;
110 int getFrom() const;
111 int getThru() const;
112 int getKeySig() const;
113 int getClock() const;
114 int getAutoSave() const;
115 int getPlayDelay() const;
116 bool getZeroCtrls() const;
117 bool getSendSPP() const;
118 bool getSendCont() const;
119 bool getPatchSearch() const;
120 bool getAutoStop() const;
121 unsigned int getStopTime() const;
122 bool getAutoRewind() const;
123 int getRewindTime() const;
124 bool getMetroPlay() const;
125 bool getMetroRecord() const;
126 bool getMetroAccent() const;
127 int getCountIn() const;
128 bool getThruOn() const;
129 bool getAutoRestart() const;
130 int getCurTempoOfs() const;
131 int getTempoOfs1() const;
132 int getTempoOfs2() const;
133 int getTempoOfs3() const;
134 bool getPunchEnabled() const;
135 int getPunchInTime() const;
136 int getPunchOutTime() const;
137 int getEndAllTime() const;
138
139 QByteArray getLastChunkRawData() const;
140 double getRealTime(long ticks) const;
141
145 static const QByteArray HEADER;
146
147Q_SIGNALS:
148
154 void signalWRKError(const QString& errorStr);
155
162 void signalWRKUnknownChunk(int type, const QByteArray& data);
163
170 void signalWRKHeader(int verh, int verl);
171
176
181 void signalWRKStreamEnd(long time);
182
193 void signalWRKNote(int track, long time, int chan, int pitch, int vol, int dur);
194
204 void signalWRKKeyPress(int track, long time, int chan, int pitch, int press);
205
215 void signalWRKCtlChange(int track, long time, int chan, int ctl, int value);
216
225 void signalWRKPitchBend(int track, long time, int chan, int value);
226
235 void signalWRKProgram(int track, long time, int chan, int patch);
236
245 void signalWRKChanPress(int track, long time, int chan, int press);
246
254 void signalWRKSysexEvent(int track, long time, int bank);
255
265 void signalWRKSysex(int bank, const QString& name, bool autosend, int port, const QByteArray& data);
266
277 Q_DECL_DEPRECATED void signalWRKText(int track, long time, int type, const QString& data);
278
286 void signalWRKTimeSig(int bar, int num, int den);
287
294 void signalWRKKeySig(int bar, int alt);
295
305 void signalWRKTempo(long time, int tempo);
306
323 Q_DECL_DEPRECATED
324 void signalWRKTrack(const QString& name1,
325 const QString& name2,
326 int trackno, int channel, int pitch,
327 int velocity, int port,
328 bool selected, bool muted, bool loop );
329
335 void signalWRKTimeBase(int timebase);
336
346
361 void signalWRKThru(int mode, int port, int channel, int keyPlus, int velPlus, int localPort);
362
369 void signalWRKTrackOffset(int track, int offset);
370
377 void signalWRKTrackReps(int track, int reps);
378
385 void signalWRKTrackPatch(int track, int patch);
386
393 void signalWRKTrackBank(int track, int bank);
394
401 void signalWRKTimeFormat(int frames, int offset);
402
410 Q_DECL_DEPRECATED void signalWRKComments(const QString& data);
411
419 void signalWRKVariableRecord(const QString& name, const QByteArray& data);
420
427 void signalWRKTrackVol(int track, int vol);
428
444 Q_DECL_DEPRECATED
445 void signalWRKNewTrack( const QString& name,
446 int trackno, int channel, int pitch,
447 int velocity, int port,
448 bool selected, bool muted, bool loop );
449
455 void signalWRKSoftVer(const QString& version);
456
465 Q_DECL_DEPRECATED void signalWRKTrackName(int track, const QString& name);
466
474 Q_DECL_DEPRECATED void signalWRKStringTable(const QStringList& strs);
475
485 Q_DECL_DEPRECATED void signalWRKSegment(int track, long time, const QString& name);
486
495 void signalWRKChord(int track, long time, const QString& name, const QByteArray& data);
496
507 Q_DECL_DEPRECATED void signalWRKExpression(int track, long time, int code, const QString& text);
508
517 void signalWRKHairpin(int track, long time, int code, int dur);
518
528 void signalWRKText2(int track, long time, int type, const QByteArray& data);
529
545 void signalWRKTrack2(const QByteArray& name1,
546 const QByteArray& name2,
547 int trackno, int channel, int pitch,
548 int velocity, int port,
549 bool selected, bool muted, bool loop );
550
557 void signalWRKComments2(const QByteArray& data);
558
573 void signalWRKNewTrack2(const QByteArray& name,
574 int trackno, int channel, int pitch,
575 int velocity, int port,
576 bool selected, bool muted, bool loop );
584 void signalWRKTrackName2(int track, const QByteArray& name);
585
592 void signalWRKStringTable2(const QList<QByteArray>& strs);
593
602 void signalWRKSegment2(int track, long time, const QByteArray& name);
603
613 void signalWRKExpression2(int track, long time, int code, const QByteArray& text);
614
626 Q_DECL_DEPRECATED void signalWRKMarker(long time, int type, const QString& data);
627
636 void signalWRKMarker2(long time, int type, const QByteArray& data);
637
638private:
639 quint8 readByte();
640 quint16 to16bit(quint8 c1, quint8 c2);
641 quint32 to32bit(quint8 c1, quint8 c2, quint8 c3, quint8 c4);
642 quint16 read16bit();
643 quint32 read24bit();
644 quint32 read32bit();
645 QString readString(int len);
646 QString readVarString();
647 void readRawData(int size);
648 void readGap(int size);
649 bool atEnd();
650 void seek(qint64 pos);
651
652 int readChunk();
653 void processTrackChunk();
654 void processVarsChunk();
655 void processTimebaseChunk();
656 void processNoteArray(int track, int events);
657 void processStreamChunk();
658 void processMeterChunk();
659 void processTempoChunk(int factor = 1);
660 void processSysexChunk();
661 void processSysex2Chunk();
662 void processNewSysexChunk();
663 void processThruChunk();
664 void processTrackOffset();
665 void processTrackReps();
666 void processTrackPatch();
667 void processTrackBank();
668 void processTimeFormat();
669 void processComments();
670 void processVariableRecord(int max);
671 void processNewTrack();
672 void processSoftVer();
673 void processTrackName();
674 void processStringTable();
675 void processLyricsStream();
676 void processTrackVol();
677 void processNewTrackOffset();
678 void processMeterKeyChunk();
679 void processSegmentChunk();
680 void processNewStream();
681 void processUnknown(int id);
682 void processEndChunk();
683 void wrkRead();
684 QByteArray readByteArray(int len);
685 QByteArray readVarByteArray();
686 void processMarkers();
687
688 struct RecTempo {
689 long time;
690 double tempo;
691 double seconds;
692 };
693
694 class QWrkPrivate;
695 QScopedPointer<QWrkPrivate> d;
696};
697
700}} // namespace drumstick::File
701
702#endif // DRUMSTICK_QWRK_H
The QObject class is the base class of all Qt objects.
Cakewalk WRK file format (input only)
Definition: qwrk.h:96
void signalWRKTrackPatch(int track, int patch)
Emitted after reading a track patch chunk.
Q_DECL_DEPRECATED void signalWRKSegment(int track, long time, const QString &name)
Emitted after reading a segment prefix chunk.
void signalWRKProgram(int track, long time, int chan, int patch)
Emitted after reading a Program change message.
void signalWRKChord(int track, long time, const QString &name, const QByteArray &data)
Emitted after reading a chord diagram chunk.
static const QByteArray HEADER
Cakewalk WRK file format header string id.
Definition: qwrk.h:145
void signalWRKHeader(int verh, int verl)
Emitted after reading a WRK header.
void signalWRKSysexEvent(int track, long time, int bank)
Emitted after reading a System Exclusive event.
void signalWRKMarker2(long time, int type, const QByteArray &data)
Emitted after reading a text marker This signal is emitted when getTextCodec() is nullptr.
void signalWRKGlobalVars()
Emitted after reading the global variables chunk.
void signalWRKSoftVer(const QString &version)
Emitted after reading a software version chunk.
void signalWRKSegment2(int track, long time, const QByteArray &name)
Emitted after reading a segment prefix chunk.
void signalWRKTrackOffset(int track, int offset)
Emitted after reading a track offset chunk.
void signalWRKChanPress(int track, long time, int chan, int press)
Emitted after reading a Channel Aftertouch message.
void signalWRKStreamEnd(long time)
Emitted after reading the last event of a event stream.
void signalWRKText2(int track, long time, int type, const QByteArray &data)
Emitted after reading a text message This signal is emitted when getTextCodec() is nullptr.
void signalWRKKeyPress(int track, long time, int chan, int pitch, int press)
Emitted after reading a Polyphonic Aftertouch message.
void signalWRKVariableRecord(const QString &name, const QByteArray &data)
Emitted after reading a variable chunk.
void signalWRKTrackVol(int track, int vol)
Emitted after reading a track volume chunk.
void signalWRKExpression2(int track, long time, int code, const QByteArray &text)
Emitted after reading an expression indication (notation) chunk.
void signalWRKTrackName2(int track, const QByteArray &name)
Emitted after reading a track name chunk.
Q_DECL_DEPRECATED void signalWRKNewTrack(const QString &name, int trackno, int channel, int pitch, int velocity, int port, bool selected, bool muted, bool loop)
Emitted after reading a new track prefix.
void signalWRKTrack2(const QByteArray &name1, const QByteArray &name2, int trackno, int channel, int pitch, int velocity, int port, bool selected, bool muted, bool loop)
Emitted after reading a track prefix chunk This signal is emitted when getTextCodec() is nullptr.
void signalWRKError(const QString &errorStr)
Emitted for a WRK file read error.
void signalWRKTempo(long time, int tempo)
Emitted after reading a Tempo Change message.
void signalWRKTimeSig(int bar, int num, int den)
Emitted after reading a WRK Time signature.
void signalWRKHairpin(int track, long time, int code, int dur)
Emitted after reading a hairpin symbol (notation) chunk.
void signalWRKPitchBend(int track, long time, int chan, int value)
Emitted after reading a Bender message.
void signalWRKEnd()
Emitted after reading the last chunk of a WRK file.
Q_DECL_DEPRECATED void signalWRKTrackName(int track, const QString &name)
Emitted after reading a track name chunk.
void signalWRKNewTrack2(const QByteArray &name, int trackno, int channel, int pitch, int velocity, int port, bool selected, bool muted, bool loop)
Emitted after reading a new track prefix This signal is emitted when getTextCodec() is nullptr.
void signalWRKThru(int mode, int port, int channel, int keyPlus, int velPlus, int localPort)
Emitted after reading an Extended Thru parameters chunk.
void signalWRKNote(int track, long time, int chan, int pitch, int vol, int dur)
Emitted after reading a Note message.
Q_DECL_DEPRECATED void signalWRKStringTable(const QStringList &strs)
Emitted after reading a string event types chunk.
void signalWRKUnknownChunk(int type, const QByteArray &data)
Emitted after reading an unknown chunk.
void signalWRKTrackBank(int track, int bank)
Emitted after reading a track bank chunk.
void signalWRKComments2(const QByteArray &data)
Emitted after reading a comments chunk This signal is emitted when getTextCodec() is nullptr.
void signalWRKTimeBase(int timebase)
Emitted after reading the timebase chunk.
Q_DECL_DEPRECATED void signalWRKExpression(int track, long time, int code, const QString &text)
Emitted after reading an expression indication (notation) chunk.
Q_DECL_DEPRECATED void signalWRKText(int track, long time, int type, const QString &data)
Emitted after reading a text message.
void signalWRKTimeFormat(int frames, int offset)
Emitted after reading a SMPTE time format chunk.
void signalWRKSysex(int bank, const QString &name, bool autosend, int port, const QByteArray &data)
Emitted after reading a System Exclusive Bank.
Q_DECL_DEPRECATED void signalWRKComments(const QString &data)
Emitted after reading a comments chunk.
void signalWRKCtlChange(int track, long time, int chan, int ctl, int value)
Emitted after reading a Control Change message.
void signalWRKTrackReps(int track, int reps)
Emitted after reading a track offset chunk.
void signalWRKKeySig(int bar, int alt)
Emitted after reading a WRK Key Signature.
Q_DECL_DEPRECATED void signalWRKTrack(const QString &name1, const QString &name2, int trackno, int channel, int pitch, int velocity, int port, bool selected, bool muted, bool loop)
Emitted after reading a track prefix chunk.
Q_DECL_DEPRECATED void signalWRKMarker(long time, int type, const QString &data)
Emitted after reading a text marker This is deprecated because the class QTextCodec was removed from ...
void signalWRKStringTable2(const QList< QByteArray > &strs)
Emitted after reading a string event types chunk.
WrkChunkType
Record types within a WRK file.
Definition: qwrk.h:53
@ NTRKOFS_CHUNK
Track offset.
Definition: qwrk.h:77
@ NTRACK_CHUNK
Track prefix.
Definition: qwrk.h:79
@ TRKPATCH_CHUNK
Track patch.
Definition: qwrk.h:66
@ MARKERS_CHUNK
Markers.
Definition: qwrk.h:72
@ STRTAB_CHUNK
Table of text event types.
Definition: qwrk.h:73
@ NTEMPO_CHUNK
New Tempo map.
Definition: qwrk.h:67
@ VARS_CHUNK
Global variables.
Definition: qwrk.h:56
@ TRKBANK_CHUNK
Track bank.
Definition: qwrk.h:78
@ COMMENTS_CHUNK
Comments.
Definition: qwrk.h:61
@ SGMNT_CHUNK
Segment prefix.
Definition: qwrk.h:82
@ SOFTVER_CHUNK
Software version which saved the file.
Definition: qwrk.h:83
@ TRKNAME_CHUNK
Track name.
Definition: qwrk.h:75
@ TIMEFMT_CHUNK
SMPTE time format.
Definition: qwrk.h:64
@ END_CHUNK
Last chunk, end of file.
Definition: qwrk.h:84
@ STREAM_CHUNK
Events stream.
Definition: qwrk.h:55
@ TRACK_CHUNK
Track prefix.
Definition: qwrk.h:54
@ TIMEBASE_CHUNK
Timebase. If present is the first chunk in the file.
Definition: qwrk.h:63
@ TRKOFFS_CHUNK
Track offset.
Definition: qwrk.h:62
@ NSYSEX_CHUNK
System exclusive bank.
Definition: qwrk.h:80
@ THRU_CHUNK
Extended thru parameters.
Definition: qwrk.h:68
@ SYSEX2_CHUNK
System exclusive bank.
Definition: qwrk.h:71
@ NSTREAM_CHUNK
Events stream.
Definition: qwrk.h:81
@ TEMPO_CHUNK
Tempo map.
Definition: qwrk.h:57
@ VARIABLE_CHUNK
Variable record chunk.
Definition: qwrk.h:76
@ METER_CHUNK
Meter map.
Definition: qwrk.h:58
@ METERKEY_CHUNK
Meter/Key map.
Definition: qwrk.h:74
@ MEMRGN_CHUNK
Memory region.
Definition: qwrk.h:60
@ TRKREPS_CHUNK
Track repetitions.
Definition: qwrk.h:65
@ TRKVOL_CHUNK
Track volume.
Definition: qwrk.h:70
@ SYSEX_CHUNK
System exclusive bank.
Definition: qwrk.h:59
@ LYRICS_CHUNK
Events stream with lyrics.
Definition: qwrk.h:69
Drumstick common.
Definition: alsaclient.cpp:68