drumstick 0.5.0
qwrk.h
Go to the documentation of this file.
1/*
2 WRK File component
3 Copyright (C) 2010, 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 2 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 along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18*/
19
20#ifndef DRUMSTICK_QWRK_H
21#define DRUMSTICK_QWRK_H
22
23#include "macros.h"
24#include <QObject>
25
26class QDataStream;
27
34
35namespace drumstick {
36
72
73const QByteArray HEADER("CAKEWALK");
74
81class DRUMSTICK_EXPORT QWrk : public QObject
82{
83 Q_OBJECT
84
85public:
86 QWrk(QObject * parent = 0);
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
128Q_SIGNALS:
129
135 void signalWRKError(const QString& errorStr);
136
143 void signalWRKUnknownChunk(int type, const QByteArray& data);
144
151 void signalWRKHeader(int verh, int verl);
152
157
161 void signalWRKStreamEnd(long time);
162
173 void signalWRKNote(int track, long time, int chan, int pitch, int vol, int dur);
174
184 void signalWRKKeyPress(int track, long time, int chan, int pitch, int press);
185
195 void signalWRKCtlChange(int track, long time, int chan, int ctl, int value);
196
205 void signalWRKPitchBend(int track, long time, int chan, int value);
206
215 void signalWRKProgram(int track, long time, int chan, int patch);
216
225 void signalWRKChanPress(int track, long time, int chan, int press);
226
234 void signalWRKSysexEvent(int track, long time, int bank);
235
245 void signalWRKSysex(int bank, const QString& name, bool autosend, int port, const QByteArray& data);
246
255 void signalWRKText(int track, long time, int type, const QString& data);
256
264 void signalWRKTimeSig(int bar, int num, int den);
265
272 void signalWRKKeySig(int bar, int alt);
273
283 void signalWRKTempo(long time, int tempo);
284
299 void signalWRKTrack(const QString& name1,
300 const QString& name2,
301 int trackno, int channel, int pitch,
302 int velocity, int port,
303 bool selected, bool muted, bool loop );
304
310 void signalWRKTimeBase(int timebase);
311
321
336 void signalWRKThru(int mode, int port, int channel, int keyPlus, int velPlus, int localPort);
337
344 void signalWRKTrackOffset(int track, int offset);
345
352 void signalWRKTrackReps(int track, int reps);
353
360 void signalWRKTrackPatch(int track, int patch);
361
368 void signalWRKTrackBank(int track, int bank);
369
376 void signalWRKTimeFormat(int frames, int offset);
377
383 void signalWRKComments(const QString& data);
384
392 void signalWRKVariableRecord(const QString& name, const QByteArray& data);
393
400 void signalWRKTrackVol(int track, int vol);
401
415 void signalWRKNewTrack( const QString& name,
416 int trackno, int channel, int pitch,
417 int velocity, int port,
418 bool selected, bool muted, bool loop );
419
425 void signalWRKSoftVer(const QString& version);
426
433 void signalWRKTrackName(int track, const QString& name);
434
440 void signalWRKStringTable(const QStringList& strs);
441
449 void signalWRKSegment(int track, long time, const QString& name);
450
459 void signalWRKChord(int track, long time, const QString& name, const QByteArray& data);
460
469 void signalWRKExpression(int track, long time, int code, const QString& text);
470
479 void signalWRKHairpin(int track, long time, int code, int dur);
480
481private:
482 quint8 readByte();
483 quint16 to16bit(quint8 c1, quint8 c2);
484 quint32 to32bit(quint8 c1, quint8 c2, quint8 c3, quint8 c4);
485 quint16 read16bit();
486 quint32 read24bit();
487 quint32 read32bit();
488 QString readString(int len);
489 QString readVarString();
490 void readRawData(int size);
491 void readGap(int size);
492 bool atEnd();
493 void seek(qint64 pos);
494
495 int readChunk();
496 void processTrackChunk();
497 void processVarsChunk();
498 void processTimebaseChunk();
499 void processNoteArray(int track, int events);
500 void processStreamChunk();
501 void processMeterChunk();
502 void processTempoChunk(int factor = 1);
503 void processSysexChunk();
504 void processSysex2Chunk();
505 void processNewSysexChunk();
506 void processThruChunk();
507 void processTrackOffset();
508 void processTrackReps();
509 void processTrackPatch();
510 void processTrackBank();
511 void processTimeFormat();
512 void processComments();
513 void processVariableRecord(int max);
514 void processNewTrack();
515 void processSoftVer();
516 void processTrackName();
517 void processStringTable();
518 void processLyricsStream();
519 void processTrackVol();
520 void processNewTrackOffset();
521 void processMeterKeyChunk();
522 void processSegmentChunk();
523 void processNewStream();
524 void processUnknown(int id);
525 void processEndChunk();
526 void wrkRead();
527
528 struct RecTempo {
529 long time;
530 double tempo;
531 double seconds;
532 };
533
534 class QWrkPrivate;
535 QWrkPrivate *d;
536};
537
538} // namespace drumstick;
539
541
542#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:324
bool getPunchEnabled() const
Auto-Punch enabled?
Definition qwrk.cpp:435
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:306
bool getZeroCtrls() const
Zero continuous controllers?
Definition qwrk.cpp:243
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.
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.
void setTextCodec(QTextCodec *codec)
Sets the text codec for text meta-events.
Definition qwrk.cpp:153
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:225
long getFilePos()
Current position in the data stream.
Definition qwrk.cpp:596
bool getThruOn() const
MIDI Thru enabled?
Definition qwrk.cpp:351
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:180
int getPunchOutTime() const
Punch-out time.
Definition qwrk.cpp:453
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:279
int getEndAllTime() const
Time of latest event (incl.
Definition qwrk.cpp:462
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:234
bool getSendSPP() const
Send Song Position Pointer?
Definition qwrk.cpp:252
void signalWRKError(const QString &errorStr)
Emitted for a WRK file read error.
QWrk(QObject *parent=0)
Constructor.
Definition qwrk.cpp:125
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:426
int getThru() const
Thru marker time.
Definition qwrk.cpp:198
bool getSendCont() const
Send MIDI Continue?
Definition qwrk.cpp:261
int getTempoOfs2() const
Fixed-point ratio value of tempo offset 2.
Definition qwrk.cpp:407
bool getPatchSearch() const
Patch/controller search-back?
Definition qwrk.cpp:270
void readFromStream(QDataStream *stream)
Reads a stream.
Definition qwrk.cpp:633
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:444
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:288
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:163
bool getAutoRewind() const
Auto-rewind?
Definition qwrk.cpp:297
bool getMetroPlay() const
Metronome on during playback?
Definition qwrk.cpp:315
QTextCodec * getTextCodec()
Gets the text codec used for text meta-events I/O.
Definition qwrk.cpp:142
int getFrom() const
From marker time.
Definition qwrk.cpp:189
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:643
int getCountIn() const
Measures of count-in (0=no count-in)
Definition qwrk.cpp:342
int getCurTempoOfs() const
Which of the 3 tempo offsets is used: 0..2.
Definition qwrk.cpp:369
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:360
int getClock() const
Clock Source (0=Int, 1=MIDI, 2=FSK, 3=SMPTE)
Definition qwrk.cpp:216
int getKeySig() const
Key signature (0=C, 1=C#, ... 11=B)
Definition qwrk.cpp:207
bool getMetroAccent() const
Metronome accents primary beats?
Definition qwrk.cpp:333
int getTempoOfs1() const
Fixed-point ratio value of tempo offset 1.
Definition qwrk.cpp:388
Drumstick visibility macros.
const QByteArray HEADER("CAKEWALK")
Cakewalk WRK File header id.
WrkChunkType
Record types within a WRK file.
Definition qwrk.h:40
@ NTRKOFS_CHUNK
Track offset.
Definition qwrk.h:63
@ NTRACK_CHUNK
Track prefix.
Definition qwrk.h:65
@ TRKPATCH_CHUNK
Track patch.
Definition qwrk.h:53
@ STRTAB_CHUNK
Table of text event types.
Definition qwrk.h:59
@ NTEMPO_CHUNK
New Tempo map.
Definition qwrk.h:54
@ VARS_CHUNK
Global variables.
Definition qwrk.h:43
@ TRKBANK_CHUNK
Track bank.
Definition qwrk.h:64
@ COMMENTS_CHUNK
Comments.
Definition qwrk.h:48
@ SGMNT_CHUNK
Segment prefix.
Definition qwrk.h:68
@ SOFTVER_CHUNK
Software version which saved the file.
Definition qwrk.h:69
@ TRKNAME_CHUNK
Track name.
Definition qwrk.h:61
@ TIMEFMT_CHUNK
SMPTE time format.
Definition qwrk.h:51
@ END_CHUNK
Last chunk, end of file.
Definition qwrk.h:70
@ STREAM_CHUNK
Events stream.
Definition qwrk.h:42
@ TRACK_CHUNK
Track prefix.
Definition qwrk.h:41
@ TIMEBASE_CHUNK
Timebase. If present is the first chunk in the file.
Definition qwrk.h:50
@ TRKOFFS_CHUNK
Track offset.
Definition qwrk.h:49
@ NSYSEX_CHUNK
System exclusive bank.
Definition qwrk.h:66
@ THRU_CHUNK
Extended thru parameters.
Definition qwrk.h:55
@ SYSEX2_CHUNK
System exclusive bank.
Definition qwrk.h:58
@ NSTREAM_CHUNK
Events stream.
Definition qwrk.h:67
@ TEMPO_CHUNK
Tempo map.
Definition qwrk.h:44
@ VARIABLE_CHUNK
Variable record chunk.
Definition qwrk.h:62
@ METER_CHUNK
Meter map.
Definition qwrk.h:45
@ METERKEY_CHUNK
Meter/Key map.
Definition qwrk.h:60
@ MEMRGN_CHUNK
Memory region.
Definition qwrk.h:47
@ TRKREPS_CHUNK
Track repetitions.
Definition qwrk.h:52
@ TRKVOL_CHUNK
Track volume.
Definition qwrk.h:57
@ SYSEX_CHUNK
System exclusive bank.
Definition qwrk.h:46
@ LYRICS_CHUNK
Events stream with lyrics.
Definition qwrk.h:56