drumstick 2.0.0
qwrk.h
Go to the documentation of this file.
1/*
2 WRK File component
3 Copyright (C) 2010-2020, 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 QDataStream;
27
32
33namespace drumstick { namespace File {
34
74
81class DRUMSTICK_EXPORT QWrk : public QObject
82{
83 Q_OBJECT
84 Q_ENUM(WrkChunkType)
85public:
86 explicit QWrk(QObject * parent = nullptr);
87 virtual ~QWrk();
88
89 void readFromStream(QDataStream *stream);
90 void readFromFile(const QString& fileName);
91 QTextCodec* getTextCodec();
92 void setTextCodec(QTextCodec *codec);
93 long getFilePos();
94
95 int getNow() const;
96 int getFrom() const;
97 int getThru() const;
98 int getKeySig() const;
99 int getClock() const;
100 int getAutoSave() const;
101 int getPlayDelay() const;
102 bool getZeroCtrls() const;
103 bool getSendSPP() const;
104 bool getSendCont() const;
105 bool getPatchSearch() const;
106 bool getAutoStop() const;
107 unsigned int getStopTime() const;
108 bool getAutoRewind() const;
109 int getRewindTime() const;
110 bool getMetroPlay() const;
111 bool getMetroRecord() const;
112 bool getMetroAccent() const;
113 int getCountIn() const;
114 bool getThruOn() const;
115 bool getAutoRestart() const;
116 int getCurTempoOfs() const;
117 int getTempoOfs1() const;
118 int getTempoOfs2() const;
119 int getTempoOfs3() const;
120 bool getPunchEnabled() const;
121 int getPunchInTime() const;
122 int getPunchOutTime() const;
123 int getEndAllTime() const;
124
125 QByteArray getLastChunkRawData() const;
126 double getRealTime(long ticks) const;
127
131 static const QByteArray HEADER;
132
133Q_SIGNALS:
134
140 void signalWRKError(const QString& errorStr);
141
148 void signalWRKUnknownChunk(int type, const QByteArray& data);
149
156 void signalWRKHeader(int verh, int verl);
157
162
167 void signalWRKStreamEnd(long time);
168
179 void signalWRKNote(int track, long time, int chan, int pitch, int vol, int dur);
180
190 void signalWRKKeyPress(int track, long time, int chan, int pitch, int press);
191
201 void signalWRKCtlChange(int track, long time, int chan, int ctl, int value);
202
211 void signalWRKPitchBend(int track, long time, int chan, int value);
212
221 void signalWRKProgram(int track, long time, int chan, int patch);
222
231 void signalWRKChanPress(int track, long time, int chan, int press);
232
240 void signalWRKSysexEvent(int track, long time, int bank);
241
251 void signalWRKSysex(int bank, const QString& name, bool autosend, int port, const QByteArray& data);
252
261 void signalWRKText(int track, long time, int type, const QString& data);
262
270 void signalWRKTimeSig(int bar, int num, int den);
271
278 void signalWRKKeySig(int bar, int alt);
279
289 void signalWRKTempo(long time, int tempo);
290
305 void signalWRKTrack(const QString& name1,
306 const QString& name2,
307 int trackno, int channel, int pitch,
308 int velocity, int port,
309 bool selected, bool muted, bool loop );
310
316 void signalWRKTimeBase(int timebase);
317
327
342 void signalWRKThru(int mode, int port, int channel, int keyPlus, int velPlus, int localPort);
343
350 void signalWRKTrackOffset(int track, int offset);
351
358 void signalWRKTrackReps(int track, int reps);
359
366 void signalWRKTrackPatch(int track, int patch);
367
374 void signalWRKTrackBank(int track, int bank);
375
382 void signalWRKTimeFormat(int frames, int offset);
383
389 void signalWRKComments(const QString& data);
390
398 void signalWRKVariableRecord(const QString& name, const QByteArray& data);
399
406 void signalWRKTrackVol(int track, int vol);
407
421 void signalWRKNewTrack( const QString& name,
422 int trackno, int channel, int pitch,
423 int velocity, int port,
424 bool selected, bool muted, bool loop );
425
431 void signalWRKSoftVer(const QString& version);
432
439 void signalWRKTrackName(int track, const QString& name);
440
446 void signalWRKStringTable(const QStringList& strs);
447
455 void signalWRKSegment(int track, long time, const QString& name);
456
465 void signalWRKChord(int track, long time, const QString& name, const QByteArray& data);
466
475 void signalWRKExpression(int track, long time, int code, const QString& text);
476
485 void signalWRKHairpin(int track, long time, int code, int dur);
486
487private:
488 quint8 readByte();
489 quint16 to16bit(quint8 c1, quint8 c2);
490 quint32 to32bit(quint8 c1, quint8 c2, quint8 c3, quint8 c4);
491 quint16 read16bit();
492 quint32 read24bit();
493 quint32 read32bit();
494 QString readString(int len);
495 QString readVarString();
496 void readRawData(int size);
497 void readGap(int size);
498 bool atEnd();
499 void seek(qint64 pos);
500
501 int readChunk();
502 void processTrackChunk();
503 void processVarsChunk();
504 void processTimebaseChunk();
505 void processNoteArray(int track, int events);
506 void processStreamChunk();
507 void processMeterChunk();
508 void processTempoChunk(int factor = 1);
509 void processSysexChunk();
510 void processSysex2Chunk();
511 void processNewSysexChunk();
512 void processThruChunk();
513 void processTrackOffset();
514 void processTrackReps();
515 void processTrackPatch();
516 void processTrackBank();
517 void processTimeFormat();
518 void processComments();
519 void processVariableRecord(int max);
520 void processNewTrack();
521 void processSoftVer();
522 void processTrackName();
523 void processStringTable();
524 void processLyricsStream();
525 void processTrackVol();
526 void processNewTrackOffset();
527 void processMeterKeyChunk();
528 void processSegmentChunk();
529 void processNewStream();
530 void processUnknown(int id);
531 void processEndChunk();
532 void wrkRead();
533
534 struct RecTempo {
535 long time;
536 double tempo;
537 double seconds;
538 };
539
540 class QWrkPrivate;
541 QScopedPointer<QWrkPrivate> d;
542};
543
545
546}} // namespace drumstick::File
547
548#endif // DRUMSTICK_QWRK_H
The QObject class is the base class of all Qt objects.
void signalWRKTrackPatch(int track, int patch)
Emitted after reading a track patch chunk.
bool getMetroRecord() const
Metronome on during recording?
Definition qwrk.cpp:322
bool getPunchEnabled() const
Auto-Punch enabled?
Definition qwrk.cpp:433
void signalWRKText(int track, long time, int type, const QString &data)
Emitted after reading a text message.
int getRewindTime() const
Auto-rewind time.
Definition qwrk.cpp:304
bool getZeroCtrls() const
Zero continuous controllers?
Definition qwrk.cpp:241
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.
QWrk(QObject *parent=nullptr)
Constructor.
Definition qwrk.cpp:125
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:131
void setTextCodec(QTextCodec *codec)
Sets the text codec for text meta-events.
Definition qwrk.cpp:151
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.
int getAutoSave() const
Auto save (0=disabled, 1..256=minutes).
Definition qwrk.cpp:223
long getFilePos()
Current position in the data stream.
Definition qwrk.cpp:594
bool getThruOn() const
MIDI Thru enabled?
Definition qwrk.cpp:349
void signalWRKGlobalVars()
Emitted after reading the global variables chunk.
void signalWRKSoftVer(const QString &version)
Emitted after reading a software version chunk.
int getNow() const
Now marker time.
Definition qwrk.cpp:178
int getPunchOutTime() const
Punch-out time.
Definition qwrk.cpp:451
void signalWRKComments(const QString &data)
Emitted after reading a comments 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.
bool getAutoStop() const
Auto-stop?
Definition qwrk.cpp:277
int getEndAllTime() const
Time of latest event (incl.
Definition qwrk.cpp:460
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 signalWRKStringTable(const QStringList &strs)
Emitted after reading a string event types chunk.
int getPlayDelay() const
Play Delay.
Definition qwrk.cpp:232
bool getSendSPP() const
Send Song Position Pointer?
Definition qwrk.cpp:250
void signalWRKError(const QString &errorStr)
Emitted for a WRK file read error.
void signalWRKSegment(int track, long time, const QString &name)
Emitted after reading a segment prefix chunk.
void signalWRKTempo(long time, int tempo)
Emitted after reading a Tempo Change message.
void signalWRKExpression(int track, long time, int code, const QString &text)
Emitted after reading an expression indication (notation) chunk.
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.
int getTempoOfs3() const
Fixed-point ratio value of tempo offset 3.
Definition qwrk.cpp:424
int getThru() const
Thru marker time.
Definition qwrk.cpp:196
bool getSendCont() const
Send MIDI Continue?
Definition qwrk.cpp:259
int getTempoOfs2() const
Fixed-point ratio value of tempo offset 2.
Definition qwrk.cpp:405
bool getPatchSearch() const
Patch/controller search-back?
Definition qwrk.cpp:268
void readFromStream(QDataStream *stream)
Reads a stream.
Definition qwrk.cpp:631
void signalWRKThru(int mode, int port, int channel, int keyPlus, int velPlus, int localPort)
Emitted after reading an Extended Thru parameters chunk.
int getPunchInTime() const
Punch-in time.
Definition qwrk.cpp:442
void signalWRKNote(int track, long time, int chan, int pitch, int vol, int dur)
Emitted after reading a Note message.
unsigned int getStopTime() const
Auto-stop time.
Definition qwrk.cpp:286
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 signalWRKTrackName(int track, const QString &name)
Emitted after reading a track name chunk.
void signalWRKTimeBase(int timebase)
Emitted after reading the timebase chunk.
QByteArray getLastChunkRawData() const
Gets the last chunk raw data (undecoded).
Definition qwrk.cpp:161
bool getAutoRewind() const
Auto-rewind?
Definition qwrk.cpp:295
bool getMetroPlay() const
Metronome on during playback?
Definition qwrk.cpp:313
QTextCodec * getTextCodec()
Gets the text codec used for text meta-events I/O.
Definition qwrk.cpp:140
int getFrom() const
From marker time.
Definition qwrk.cpp:187
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.
void readFromFile(const QString &fileName)
Reads a stream from a disk file.
Definition qwrk.cpp:641
int getCountIn() const
Measures of count-in (0=no count-in).
Definition qwrk.cpp:340
int getCurTempoOfs() const
Which of the 3 tempo offsets is used: 0..2.
Definition qwrk.cpp:367
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 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 signalWRKKeySig(int bar, int alt)
Emitted after reading a WRK Key Signature.
bool getAutoRestart() const
Auto-restart?
Definition qwrk.cpp:358
int getClock() const
Clock Source (0=Int, 1=MIDI, 2=FSK, 3=SMPTE).
Definition qwrk.cpp:214
int getKeySig() const
Key signature (0=C, 1=C#, ... 11=B).
Definition qwrk.cpp:205
bool getMetroAccent() const
Metronome accents primary beats?
Definition qwrk.cpp:331
int getTempoOfs1() const
Fixed-point ratio value of tempo offset 1.
Definition qwrk.cpp:386
WrkChunkType
Record types within a WRK file.
Definition qwrk.h:42
@ NTRKOFS_CHUNK
Track offset.
Definition qwrk.h:65
@ NTRACK_CHUNK
Track prefix.
Definition qwrk.h:67
@ TRKPATCH_CHUNK
Track patch.
Definition qwrk.h:55
@ STRTAB_CHUNK
Table of text event types.
Definition qwrk.h:61
@ NTEMPO_CHUNK
New Tempo map.
Definition qwrk.h:56
@ VARS_CHUNK
Global variables.
Definition qwrk.h:45
@ TRKBANK_CHUNK
Track bank.
Definition qwrk.h:66
@ COMMENTS_CHUNK
Comments.
Definition qwrk.h:50
@ SGMNT_CHUNK
Segment prefix.
Definition qwrk.h:70
@ SOFTVER_CHUNK
Software version which saved the file.
Definition qwrk.h:71
@ TRKNAME_CHUNK
Track name.
Definition qwrk.h:63
@ TIMEFMT_CHUNK
SMPTE time format.
Definition qwrk.h:53
@ END_CHUNK
Last chunk, end of file.
Definition qwrk.h:72
@ STREAM_CHUNK
Events stream.
Definition qwrk.h:44
@ TRACK_CHUNK
Track prefix.
Definition qwrk.h:43
@ TIMEBASE_CHUNK
Timebase. If present is the first chunk in the file.
Definition qwrk.h:52
@ TRKOFFS_CHUNK
Track offset.
Definition qwrk.h:51
@ NSYSEX_CHUNK
System exclusive bank.
Definition qwrk.h:68
@ THRU_CHUNK
Extended thru parameters.
Definition qwrk.h:57
@ SYSEX2_CHUNK
System exclusive bank.
Definition qwrk.h:60
@ NSTREAM_CHUNK
Events stream.
Definition qwrk.h:69
@ TEMPO_CHUNK
Tempo map.
Definition qwrk.h:46
@ VARIABLE_CHUNK
Variable record chunk.
Definition qwrk.h:64
@ METER_CHUNK
Meter map.
Definition qwrk.h:47
@ METERKEY_CHUNK
Meter/Key map.
Definition qwrk.h:62
@ MEMRGN_CHUNK
Memory region.
Definition qwrk.h:49
@ TRKREPS_CHUNK
Track repetitions.
Definition qwrk.h:54
@ TRKVOL_CHUNK
Track volume.
Definition qwrk.h:59
@ SYSEX_CHUNK
System exclusive bank.
Definition qwrk.h:48
@ LYRICS_CHUNK
Events stream with lyrics.
Definition qwrk.h:58
Drumstick visibility macros.
Drumstick File library.
Definition qsmf.cpp:35
Drumstick common.