drumstick  2.9.0
C++MIDIlibrariesusingQtobjects,idioms,andstyle.
qwrk.h
Go to the documentation of this file.
1 /*
2  WRK File component
3  Copyright (C) 2010-2023, 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 #if defined(DRUMSTICK_STATIC)
35 #define DRUMSTICK_FILE_EXPORT
36 #else
37 #if defined(drumstick_file_EXPORTS)
38 #define DRUMSTICK_FILE_EXPORT Q_DECL_EXPORT
39 #else
40 #define DRUMSTICK_FILE_EXPORT Q_DECL_IMPORT
41 #endif
42 #endif
43 
44 namespace drumstick { namespace File {
45 
56  VARS_CHUNK = 3,
67  NTEMPO_CHUNK = 15,
68  THRU_CHUNK = 16,
69  LYRICS_CHUNK = 18,
70  TRKVOL_CHUNK = 19,
71  SYSEX2_CHUNK = 20,
73  STRTAB_CHUNK = 22,
79  NTRACK_CHUNK = 36,
80  NSYSEX_CHUNK = 44,
82  SGMNT_CHUNK = 49,
84  END_CHUNK = 255
85 };
86 
95 class DRUMSTICK_FILE_EXPORT QWrk : public QObject
96 {
97  Q_OBJECT
98  Q_ENUM(WrkChunkType)
99 public:
100  explicit QWrk(QObject * parent = nullptr);
101  virtual ~QWrk();
102 
103  void readFromStream(QDataStream *stream);
104  void readFromFile(const QString& fileName);
105  Q_DECL_DEPRECATED QTextCodec* getTextCodec();
106  Q_DECL_DEPRECATED void setTextCodec(QTextCodec *codec);
107  long getFilePos();
108 
109  int getNow() const;
110  int getFrom() const;
111  int getThru() const;
112  int getKeySig() const;
113  int getClock() const;
114  int getAutoSave() const;
115  int getPlayDelay() const;
116  bool getZeroCtrls() const;
117  bool getSendSPP() const;
118  bool getSendCont() const;
119  bool getPatchSearch() const;
120  bool getAutoStop() const;
121  unsigned int getStopTime() const;
122  bool getAutoRewind() const;
123  int getRewindTime() const;
124  bool getMetroPlay() const;
125  bool getMetroRecord() const;
126  bool getMetroAccent() const;
127  int getCountIn() const;
128  bool getThruOn() const;
129  bool getAutoRestart() const;
130  int getCurTempoOfs() const;
131  int getTempoOfs1() const;
132  int getTempoOfs2() const;
133  int getTempoOfs3() const;
134  bool getPunchEnabled() const;
135  int getPunchInTime() const;
136  int getPunchOutTime() const;
137  int getEndAllTime() const;
138 
139  QByteArray getLastChunkRawData() const;
140  double getRealTime(long ticks) const;
141 
145  static const QByteArray HEADER;
146 
147 Q_SIGNALS:
148 
154  void signalWRKError(const QString& errorStr);
155 
162  void signalWRKUnknownChunk(int type, const QByteArray& data);
163 
170  void signalWRKHeader(int verh, int verl);
171 
175  void signalWRKEnd();
176 
181  void signalWRKStreamEnd(long time);
182 
193  void signalWRKNote(int track, long time, int chan, int pitch, int vol, int dur);
194 
204  void signalWRKKeyPress(int track, long time, int chan, int pitch, int press);
205 
215  void signalWRKCtlChange(int track, long time, int chan, int ctl, int value);
216 
225  void signalWRKPitchBend(int track, long time, int chan, int value);
226 
235  void signalWRKProgram(int track, long time, int chan, int patch);
236 
245  void signalWRKChanPress(int track, long time, int chan, int press);
246 
254  void signalWRKSysexEvent(int track, long time, int bank);
255 
265  void signalWRKSysex(int bank, const QString& name, bool autosend, int port, const QByteArray& data);
266 
277  Q_DECL_DEPRECATED void signalWRKText(int track, long time, int type, const QString& data);
278 
286  void signalWRKTimeSig(int bar, int num, int den);
287 
294  void signalWRKKeySig(int bar, int alt);
295 
305  void signalWRKTempo(long time, int tempo);
306 
323  Q_DECL_DEPRECATED
324  void signalWRKTrack(const QString& name1,
325  const QString& name2,
326  int trackno, int channel, int pitch,
327  int velocity, int port,
328  bool selected, bool muted, bool loop );
329 
335  void signalWRKTimeBase(int timebase);
336 
345  void signalWRKGlobalVars();
346 
361  void signalWRKThru(int mode, int port, int channel, int keyPlus, int velPlus, int localPort);
362 
369  void signalWRKTrackOffset(int track, int offset);
370 
377  void signalWRKTrackReps(int track, int reps);
378 
385  void signalWRKTrackPatch(int track, int patch);
386 
393  void signalWRKTrackBank(int track, int bank);
394 
401  void signalWRKTimeFormat(int frames, int offset);
402 
410  Q_DECL_DEPRECATED void signalWRKComments(const QString& data);
411 
419  void signalWRKVariableRecord(const QString& name, const QByteArray& data);
420 
427  void signalWRKTrackVol(int track, int vol);
428 
444  Q_DECL_DEPRECATED
445  void signalWRKNewTrack( const QString& name,
446  int trackno, int channel, int pitch,
447  int velocity, int port,
448  bool selected, bool muted, bool loop );
449 
455  void signalWRKSoftVer(const QString& version);
456 
465  Q_DECL_DEPRECATED void signalWRKTrackName(int track, const QString& name);
466 
474  Q_DECL_DEPRECATED void signalWRKStringTable(const QStringList& strs);
475 
485  Q_DECL_DEPRECATED void signalWRKSegment(int track, long time, const QString& name);
486 
495  void signalWRKChord(int track, long time, const QString& name, const QByteArray& data);
496 
507  Q_DECL_DEPRECATED void signalWRKExpression(int track, long time, int code, const QString& text);
508 
517  void signalWRKHairpin(int track, long time, int code, int dur);
518 
528  void signalWRKText2(int track, long time, int type, const QByteArray& data);
529 
545  void signalWRKTrack2(const QByteArray& name1,
546  const QByteArray& name2,
547  int trackno, int channel, int pitch,
548  int velocity, int port,
549  bool selected, bool muted, bool loop );
550 
557  void signalWRKComments2(const QByteArray& data);
558 
573  void signalWRKNewTrack2(const QByteArray& name,
574  int trackno, int channel, int pitch,
575  int velocity, int port,
576  bool selected, bool muted, bool loop );
584  void signalWRKTrackName2(int track, const QByteArray& name);
585 
592  void signalWRKStringTable2(const QList<QByteArray>& strs);
593 
602  void signalWRKSegment2(int track, long time, const QByteArray& name);
603 
613  void signalWRKExpression2(int track, long time, int code, const QByteArray& text);
614 
626  Q_DECL_DEPRECATED void signalWRKMarker(long time, int type, const QString& data);
627 
636  void signalWRKMarker2(long time, int type, const QByteArray& data);
637 
638 private:
639  quint8 readByte();
640  quint16 to16bit(quint8 c1, quint8 c2);
641  quint32 to32bit(quint8 c1, quint8 c2, quint8 c3, quint8 c4);
642  quint16 read16bit();
643  quint32 read24bit();
644  quint32 read32bit();
645  QString readString(int len);
646  QString readVarString();
647  void readRawData(int size);
648  void readGap(int size);
649  bool atEnd();
650  void seek(qint64 pos);
651 
652  int readChunk();
653  void processTrackChunk();
654  void processVarsChunk();
655  void processTimebaseChunk();
656  void processNoteArray(int track, int events);
657  void processStreamChunk();
658  void processMeterChunk();
659  void processTempoChunk(int factor = 1);
660  void processSysexChunk();
661  void processSysex2Chunk();
662  void processNewSysexChunk();
663  void processThruChunk();
664  void processTrackOffset();
665  void processTrackReps();
666  void processTrackPatch();
667  void processTrackBank();
668  void processTimeFormat();
669  void processComments();
670  void processVariableRecord(int max);
671  void processNewTrack();
672  void processSoftVer();
673  void processTrackName();
674  void processStringTable();
675  void processLyricsStream();
676  void processTrackVol();
677  void processNewTrackOffset();
678  void processMeterKeyChunk();
679  void processSegmentChunk();
680  void processNewStream();
681  void processUnknown(int id);
682  void processEndChunk();
683  void wrkRead();
684  QByteArray readByteArray(int len);
685  QByteArray readVarByteArray();
686  void processMarkers();
687 
688  struct RecTempo {
689  long time;
690  double tempo;
691  double seconds;
692  };
693 
694  class QWrkPrivate;
695  QScopedPointer<QWrkPrivate> d;
696 };
697 
700 }} // namespace drumstick::File
701 
702 #endif // DRUMSTICK_QWRK_H
Memory region.
Definition: qwrk.h:60
Events stream.
Definition: qwrk.h:55
System exclusive bank.
Definition: qwrk.h:80
Track repetitions.
Definition: qwrk.h:65
Track prefix.
Definition: qwrk.h:54
Meter/Key map.
Definition: qwrk.h:74
static const QByteArray HEADER
Cakewalk WRK file format header string id.
Definition: qwrk.h:145
Track prefix.
Definition: qwrk.h:79
The QObject class is the base class of all Qt objects.
Events stream.
Definition: qwrk.h:81
Track offset.
Definition: qwrk.h:77
SMPTE time format.
Definition: qwrk.h:64
System exclusive bank.
Definition: qwrk.h:71
System exclusive bank.
Definition: qwrk.h:59
Timebase. If present is the first chunk in the file.
Definition: qwrk.h:63
Drumstick common.
Definition: alsaclient.cpp:68
Global variables.
Definition: qwrk.h:56
Events stream with lyrics.
Definition: qwrk.h:69
New Tempo map.
Definition: qwrk.h:67
Software version which saved the file.
Definition: qwrk.h:83
Track offset.
Definition: qwrk.h:62
Track volume.
Definition: qwrk.h:70
Last chunk, end of file.
Definition: qwrk.h:84
Cakewalk WRK file format (input only)
Definition: qwrk.h:95
Table of text event types.
Definition: qwrk.h:73
Segment prefix.
Definition: qwrk.h:82
Extended thru parameters.
Definition: qwrk.h:68
Variable record chunk.
Definition: qwrk.h:76
WrkChunkType
Record types within a WRK file.
Definition: qwrk.h:53