drumstick  2.7.2
qwrk.h
Go to the documentation of this file.
1 /*
2  WRK File component
3  Copyright (C) 2010-2022, 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 QTextCodec;
27 class QDataStream;
28 
34 namespace drumstick { namespace File {
35 
46  VARS_CHUNK = 3,
57  NTEMPO_CHUNK = 15,
58  THRU_CHUNK = 16,
59  LYRICS_CHUNK = 18,
60  TRKVOL_CHUNK = 19,
61  SYSEX2_CHUNK = 20,
63  STRTAB_CHUNK = 22,
69  NTRACK_CHUNK = 36,
70  NSYSEX_CHUNK = 44,
72  SGMNT_CHUNK = 49,
74  END_CHUNK = 255
75 };
76 
85 class DRUMSTICK_EXPORT QWrk : public QObject
86 {
87  Q_OBJECT
88  Q_ENUM(WrkChunkType)
89 public:
90  explicit QWrk(QObject * parent = nullptr);
91  virtual ~QWrk();
92 
93  void readFromStream(QDataStream *stream);
94  void readFromFile(const QString& fileName);
95  Q_DECL_DEPRECATED QTextCodec* getTextCodec();
96  Q_DECL_DEPRECATED void setTextCodec(QTextCodec *codec);
97  long getFilePos();
98 
99  int getNow() const;
100  int getFrom() const;
101  int getThru() const;
102  int getKeySig() const;
103  int getClock() const;
104  int getAutoSave() const;
105  int getPlayDelay() const;
106  bool getZeroCtrls() const;
107  bool getSendSPP() const;
108  bool getSendCont() const;
109  bool getPatchSearch() const;
110  bool getAutoStop() const;
111  unsigned int getStopTime() const;
112  bool getAutoRewind() const;
113  int getRewindTime() const;
114  bool getMetroPlay() const;
115  bool getMetroRecord() const;
116  bool getMetroAccent() const;
117  int getCountIn() const;
118  bool getThruOn() const;
119  bool getAutoRestart() const;
120  int getCurTempoOfs() const;
121  int getTempoOfs1() const;
122  int getTempoOfs2() const;
123  int getTempoOfs3() const;
124  bool getPunchEnabled() const;
125  int getPunchInTime() const;
126  int getPunchOutTime() const;
127  int getEndAllTime() const;
128 
129  QByteArray getLastChunkRawData() const;
130  double getRealTime(long ticks) const;
131 
135  static const QByteArray HEADER;
136 
137 Q_SIGNALS:
138 
144  void signalWRKError(const QString& errorStr);
145 
152  void signalWRKUnknownChunk(int type, const QByteArray& data);
153 
160  void signalWRKHeader(int verh, int verl);
161 
165  void signalWRKEnd();
166 
171  void signalWRKStreamEnd(long time);
172 
183  void signalWRKNote(int track, long time, int chan, int pitch, int vol, int dur);
184 
194  void signalWRKKeyPress(int track, long time, int chan, int pitch, int press);
195 
205  void signalWRKCtlChange(int track, long time, int chan, int ctl, int value);
206 
215  void signalWRKPitchBend(int track, long time, int chan, int value);
216 
225  void signalWRKProgram(int track, long time, int chan, int patch);
226 
235  void signalWRKChanPress(int track, long time, int chan, int press);
236 
244  void signalWRKSysexEvent(int track, long time, int bank);
245 
255  void signalWRKSysex(int bank, const QString& name, bool autosend, int port, const QByteArray& data);
256 
267  Q_DECL_DEPRECATED void signalWRKText(int track, long time, int type, const QString& data);
268 
276  void signalWRKTimeSig(int bar, int num, int den);
277 
284  void signalWRKKeySig(int bar, int alt);
285 
295  void signalWRKTempo(long time, int tempo);
296 
313  Q_DECL_DEPRECATED
314  void signalWRKTrack(const QString& name1,
315  const QString& name2,
316  int trackno, int channel, int pitch,
317  int velocity, int port,
318  bool selected, bool muted, bool loop );
319 
325  void signalWRKTimeBase(int timebase);
326 
335  void signalWRKGlobalVars();
336 
351  void signalWRKThru(int mode, int port, int channel, int keyPlus, int velPlus, int localPort);
352 
359  void signalWRKTrackOffset(int track, int offset);
360 
367  void signalWRKTrackReps(int track, int reps);
368 
375  void signalWRKTrackPatch(int track, int patch);
376 
383  void signalWRKTrackBank(int track, int bank);
384 
391  void signalWRKTimeFormat(int frames, int offset);
392 
400  Q_DECL_DEPRECATED void signalWRKComments(const QString& data);
401 
409  void signalWRKVariableRecord(const QString& name, const QByteArray& data);
410 
417  void signalWRKTrackVol(int track, int vol);
418 
434  Q_DECL_DEPRECATED
435  void signalWRKNewTrack( const QString& name,
436  int trackno, int channel, int pitch,
437  int velocity, int port,
438  bool selected, bool muted, bool loop );
439 
445  void signalWRKSoftVer(const QString& version);
446 
455  Q_DECL_DEPRECATED void signalWRKTrackName(int track, const QString& name);
456 
464  Q_DECL_DEPRECATED void signalWRKStringTable(const QStringList& strs);
465 
475  Q_DECL_DEPRECATED void signalWRKSegment(int track, long time, const QString& name);
476 
485  void signalWRKChord(int track, long time, const QString& name, const QByteArray& data);
486 
497  Q_DECL_DEPRECATED void signalWRKExpression(int track, long time, int code, const QString& text);
498 
507  void signalWRKHairpin(int track, long time, int code, int dur);
508 
518  void signalWRKText2(int track, long time, int type, const QByteArray& data);
519 
535  void signalWRKTrack2(const QByteArray& name1,
536  const QByteArray& name2,
537  int trackno, int channel, int pitch,
538  int velocity, int port,
539  bool selected, bool muted, bool loop );
540 
547  void signalWRKComments2(const QByteArray& data);
548 
563  void signalWRKNewTrack2(const QByteArray& name,
564  int trackno, int channel, int pitch,
565  int velocity, int port,
566  bool selected, bool muted, bool loop );
574  void signalWRKTrackName2(int track, const QByteArray& name);
575 
582  void signalWRKStringTable2(const QList<QByteArray>& strs);
583 
592  void signalWRKSegment2(int track, long time, const QByteArray& name);
593 
603  void signalWRKExpression2(int track, long time, int code, const QByteArray& text);
604 
616  Q_DECL_DEPRECATED void signalWRKMarker(long time, int type, const QString& data);
617 
626  void signalWRKMarker2(long time, int type, const QByteArray& data);
627 
628 private:
629  quint8 readByte();
630  quint16 to16bit(quint8 c1, quint8 c2);
631  quint32 to32bit(quint8 c1, quint8 c2, quint8 c3, quint8 c4);
632  quint16 read16bit();
633  quint32 read24bit();
634  quint32 read32bit();
635  QString readString(int len);
636  QString readVarString();
637  void readRawData(int size);
638  void readGap(int size);
639  bool atEnd();
640  void seek(qint64 pos);
641 
642  int readChunk();
643  void processTrackChunk();
644  void processVarsChunk();
645  void processTimebaseChunk();
646  void processNoteArray(int track, int events);
647  void processStreamChunk();
648  void processMeterChunk();
649  void processTempoChunk(int factor = 1);
650  void processSysexChunk();
651  void processSysex2Chunk();
652  void processNewSysexChunk();
653  void processThruChunk();
654  void processTrackOffset();
655  void processTrackReps();
656  void processTrackPatch();
657  void processTrackBank();
658  void processTimeFormat();
659  void processComments();
660  void processVariableRecord(int max);
661  void processNewTrack();
662  void processSoftVer();
663  void processTrackName();
664  void processStringTable();
665  void processLyricsStream();
666  void processTrackVol();
667  void processNewTrackOffset();
668  void processMeterKeyChunk();
669  void processSegmentChunk();
670  void processNewStream();
671  void processUnknown(int id);
672  void processEndChunk();
673  void wrkRead();
674  QByteArray readByteArray(int len);
675  QByteArray readVarByteArray();
676  void processMarkers();
677 
678  struct RecTempo {
679  long time;
680  double tempo;
681  double seconds;
682  };
683 
684  class QWrkPrivate;
685  QScopedPointer<QWrkPrivate> d;
686 };
687 
690 }} // namespace drumstick::File
691 
692 #endif // DRUMSTICK_QWRK_H
Memory region.
Definition: qwrk.h:50
Events stream.
Definition: qwrk.h:45
System exclusive bank.
Definition: qwrk.h:70
Track repetitions.
Definition: qwrk.h:55
Track prefix.
Definition: qwrk.h:44
Meter/Key map.
Definition: qwrk.h:64
static const QByteArray HEADER
Cakewalk WRK file format header string id.
Definition: qwrk.h:135
Track prefix.
Definition: qwrk.h:69
The QObject class is the base class of all Qt objects.
Events stream.
Definition: qwrk.h:71
Track offset.
Definition: qwrk.h:67
Drumstick visibility macros.
SMPTE time format.
Definition: qwrk.h:54
System exclusive bank.
Definition: qwrk.h:61
System exclusive bank.
Definition: qwrk.h:49
Timebase. If present is the first chunk in the file.
Definition: qwrk.h:53
Drumstick common.
Definition: alsaclient.cpp:68
Global variables.
Definition: qwrk.h:46
Events stream with lyrics.
Definition: qwrk.h:59
New Tempo map.
Definition: qwrk.h:57
Software version which saved the file.
Definition: qwrk.h:73
Track offset.
Definition: qwrk.h:52
Track volume.
Definition: qwrk.h:60
Last chunk, end of file.
Definition: qwrk.h:74
Cakewalk WRK file format (input only)
Definition: qwrk.h:85
Table of text event types.
Definition: qwrk.h:63
Segment prefix.
Definition: qwrk.h:72
Extended thru parameters.
Definition: qwrk.h:58
Variable record chunk.
Definition: qwrk.h:66
WrkChunkType
Record types within a WRK file.
Definition: qwrk.h:43