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