drumstick  1.1.0
qsmf.h
Go to the documentation of this file.
1 /*
2  Standard MIDI File component
3  Copyright (C) 2006-2016, Pedro Lopez-Cabanillas <plcl@users.sf.net>
4 
5  Based on midifile.c by Tim Thompson, M.Czeiszperger and Greg Lee
6 
7  This library is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License along
18  with this program; if not, write to the Free Software Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 
22 #ifndef DRUMSTICK_QSMF_H
23 #define DRUMSTICK_QSMF_H
24 
25 #include "macros.h"
26 #include <QObject>
27 
28 class QDataStream;
29 
37 namespace drumstick {
38 
39 #define MThd 0x4d546864
40 #define MTrk 0x4d54726b
42 /* Standard MIDI Files meta event definitions */
43 #define meta_event 0xff
44 #define sequence_number 0x00
45 #define text_event 0x01
46 #define copyright_notice 0x02
47 #define sequence_name 0x03
48 #define instrument_name 0x04
49 #define lyric 0x05
50 #define marker 0x06
51 #define cue_point 0x07
52 #define forced_channel 0x20
53 #define forced_port 0x21
54 #define end_of_track 0x2f
55 #define set_tempo 0x51
56 #define smpte_offset 0x54
57 #define time_signature 0x58
58 #define key_signature 0x59
59 #define sequencer_specific 0x7f
61 /* MIDI status commands most significant bit is 1 */
62 #define note_off 0x80
63 #define note_on 0x90
64 #define poly_aftertouch 0xa0
65 #define control_change 0xb0
66 #define program_chng 0xc0
67 #define channel_aftertouch 0xd0
68 #define pitch_wheel 0xe0
69 #define system_exclusive 0xf0
70 #define end_of_sysex 0xf7
72 #define midi_command_mask 0xf0
73 #define midi_channel_mask 0x0f
75 #define major_mode 0
76 #define minor_mode 1
83 class DRUMSTICK_EXPORT QSmf : public QObject
84 {
85  Q_OBJECT
86 
87 public:
88  QSmf(QObject * parent = 0);
89  virtual ~QSmf();
90 
91  void readFromStream(QDataStream *stream);
92  void readFromFile(const QString& fileName);
93  void writeToStream(QDataStream *stream);
94  void writeToFile(const QString& fileName);
95 
96  void writeMetaEvent(long deltaTime, int type, const QByteArray& data);
97  void writeMetaEvent(long deltaTime, int type, const QString& data);
98  void writeMetaEvent(long deltaTime, int type, int data);
99  void writeMetaEvent(long deltaTime, int type);
100 
101  void writeMidiEvent(long deltaTime, int type, int chan, int b1);
102  void writeMidiEvent(long deltaTime, int type, int chan, int b1, int b2);
103  void writeMidiEvent(long deltaTime, int type, int chan, const QByteArray& data);
104  void writeMidiEvent(long deltaTime, int type, long len, char* data);
105 
106  void writeTempo(long deltaTime, long tempo);
107  void writeBpmTempo(long deltaTime, int tempo);
108  void writeTimeSignature(long deltaTime, int num, int den, int cc, int bb);
109  void writeKeySignature(long deltaTime, int tone, int mode);
110  void writeSequenceNumber(long deltaTime, int seqnum);
111 
112  long getCurrentTime();
113  long getCurrentTempo();
114  long getRealTime();
115  long getFilePos();
116  int getDivision();
117  void setDivision(int division);
118  int getTracks();
119  void setTracks(int tracks);
120  int getFileFormat();
121  void setFileFormat(int fileFormat);
122  QTextCodec* getTextCodec();
123  void setTextCodec(QTextCodec *codec);
124 
125 signals:
130  void signalSMFError(const QString& errorStr);
137  void signalSMFHeader(int format, int ntrks, int division);
144  void signalSMFNoteOn(int chan, int pitch, int vol);
151  void signalSMFNoteOff(int chan, int pitch, int vol);
158  void signalSMFKeyPress(int chan, int pitch, int press);
165  void signalSMFCtlChange(int chan, int ctl, int value);
171  void signalSMFPitchBend(int chan, int value);
177  void signalSMFProgram(int chan, int patch);
183  void signalSMFChanPress(int chan, int press);
188  void signalSMFSysex(const QByteArray& data);
193  void signalSMFSeqSpecific(const QByteArray& data);
200  void signalSMFMetaUnregistered(int typ, const QByteArray& data);
206  void signalSMFMetaMisc(int typ, const QByteArray& data);
211  void signalSMFSequenceNum(int seq);
216  void signalSMFforcedChannel(int channel);
221  void signalSMFforcedPort(int port);
227  void signalSMFText(int typ, const QString& data);
236  void signalSMFSmpte(int b0, int b1, int b2, int b3, int b4);
244  void signalSMFTimeSig(int b0, int b1, int b2, int b3);
250  void signalSMFKeySig(int b0, int b1);
255  void signalSMFTempo(int tempo);
259  void signalSMFendOfTrack();
263  void signalSMFTrackStart();
267  void signalSMFTrackEnd();
272  void signalSMFWriteTempoTrack();
277  void signalSMFWriteTrack(int track);
278 
279 private:
283  struct QSmfRecTempo
284  {
285  quint64 tempo;
286  quint64 time;
287  };
288 
289  class QSmfPrivate;
290  QSmfPrivate *d;
291 
292  void SMFRead();
293  void SMFWrite();
294  quint8 getByte();
295  void putByte(quint8 value);
296  void readHeader();
297  void readTrack();
298  quint16 to16bit(quint8 c1, quint8 c2);
299  quint32 to32bit(quint8 c1, quint8 c2, quint8 c3, quint8 c4);
300  quint16 read16bit();
301  quint32 read32bit();
302  void write16bit(quint16 data);
303  void write32bit(quint32 data);
304  void writeVarLen(quint64 value);
305  double ticksToSecs(quint64 ticks, quint16 division, quint64 tempo);
306  long readVarLen();
307  void readExpected(const QString& s);
308  void addTempo(quint64 tempo, quint64 time);
309  quint64 findTempo();
310  void SMFError(const QString& s);
311  void channelMessage(quint8 status, quint8 c1, quint8 c2);
312  void msgInit();
313  void msgAdd(quint8 b);
314  void metaEvent(quint8 b);
315  void sysEx();
316  void badByte(quint8 b, int p);
317  quint8 lowerByte(quint16 x);
318  quint8 upperByte(quint16 x);
319  bool endOfSmf();
320  void writeHeaderChunk(int format, int ntracks, int division);
321  void writeTrackChunk(int track);
322 };
323 
324 } /* namespace drumstick */
325 
328 #endif /* DRUMSTICK_QSMF_H */
Standard MIDI Files input/output.
Definition: qsmf.h:83
The QObject class is the base class of all Qt objects.
Drumstick visibility macros.