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 
26 class QDataStream;
27 
35 namespace drumstick {
36 
43  VARS_CHUNK = 3,
54  NTEMPO_CHUNK = 15,
55  THRU_CHUNK = 16,
56  LYRICS_CHUNK = 18,
57  TRKVOL_CHUNK = 19,
58  SYSEX2_CHUNK = 20,
59  STRTAB_CHUNK = 22,
65  NTRACK_CHUNK = 36,
66  NSYSEX_CHUNK = 44,
68  SGMNT_CHUNK = 49,
70  END_CHUNK = 255
71 };
72 
73 const QByteArray HEADER("CAKEWALK");
74 
81 class DRUMSTICK_EXPORT QWrk : public QObject
82 {
83  Q_OBJECT
84 
85 public:
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 
128 Q_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 
156  void signalWRKEnd();
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 
320  void signalWRKGlobalVars();
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 
481 private:
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 
542 #endif // DRUMSTICK_QWRK_H
New Tempo map.
Definition: qwrk.h:54
const QByteArray HEADER("CAKEWALK")
Cakewalk WRK File header id.
Track volume.
Definition: qwrk.h:57
Cakewalk WRK file format (input only)
Definition: qwrk.h:81
Extended thru parameters.
Definition: qwrk.h:55
Track patch.
Definition: qwrk.h:53
System exclusive bank.
Definition: qwrk.h:58
The QObject class is the base class of all Qt objects.
Global variables.
Definition: qwrk.h:43
Events stream.
Definition: qwrk.h:42
Tempo map.
Definition: qwrk.h:44
Drumstick visibility macros.
Track name.
Definition: qwrk.h:61
Last chunk, end of file.
Definition: qwrk.h:70
SMPTE time format.
Definition: qwrk.h:51
Track offset.
Definition: qwrk.h:49
System exclusive bank.
Definition: qwrk.h:66
Track prefix.
Definition: qwrk.h:65
Variable record chunk.
Definition: qwrk.h:62
System exclusive bank.
Definition: qwrk.h:46
Events stream with lyrics.
Definition: qwrk.h:56
Meter/Key map.
Definition: qwrk.h:60
Track repetitions.
Definition: qwrk.h:52
Track bank.
Definition: qwrk.h:64
Table of text event types.
Definition: qwrk.h:59
Memory region.
Definition: qwrk.h:47
Meter map.
Definition: qwrk.h:45
Segment prefix.
Definition: qwrk.h:68
WrkChunkType
Record types within a WRK file.
Definition: qwrk.h:40
Software version which saved the file.
Definition: qwrk.h:69
Timebase. If present is the first chunk in the file.
Definition: qwrk.h:50
Events stream.
Definition: qwrk.h:67
Track prefix.
Definition: qwrk.h:41
Track offset.
Definition: qwrk.h:63