2
Standard MIDI File component
3
Copyright (C) 2006-2009, Pedro Lopez-Cabanillas <plcl@users.sf.net>
5
Based on midifile.c by Tim Thompson, M.Czeiszperger and Greg Lee
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.
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.
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.
22
#ifndef INCLUDED_SMF_H
23
#define INCLUDED_SMF_H
26
#include <QDataStream>
35
#define MThd 0x4d546864
36
#define MTrk 0x4d54726b
38
/* Standard MIDI Files meta event definitions */
39
#define meta_event 0xff
40
#define sequence_number 0x00
41
#define text_event 0x01
42
#define copyright_notice 0x02
43
#define sequence_name 0x03
44
#define instrument_name 0x04
47
#define cue_point 0x07
48
#define forced_channel 0x20
49
#define forced_port 0x21
50
#define end_of_track 0x2f
51
#define set_tempo 0x51
52
#define smpte_offset 0x54
53
#define time_signature 0x58
54
#define key_signature 0x59
55
#define sequencer_specific 0x7f
57
/* MIDI status commands most significant bit is 1 */
60
#define poly_aftertouch 0xa0
61
#define control_change 0xb0
62
#define program_chng 0xc0
63
#define channel_aftertouch 0xd0
64
#define pitch_wheel 0xe0
65
#define system_exclusive 0xf0
66
#define end_of_sysex 0xf7
68
#define midi_command_mask 0xf0
69
#define midi_channel_mask 0x0f
74
class QSmf : public QObject
79
QSmf(QObject * parent = 0);
82
void readFromStream(QDataStream *stream);
83
void readFromFile(const QString& fileName);
84
void writeToStream(QDataStream *stream);
85
void writeToFile(const QString& fileName);
87
void writeMetaEvent(long deltaTime, int type, const QByteArray& data);
88
void writeMetaEvent(long deltaTime, int type, const QString& data);
89
void writeMetaEvent(long deltaTime, int type);
91
void writeMidiEvent(long deltaTime, int type, int chan, int b1);
92
void writeMidiEvent(long deltaTime, int type, int chan, int b1, int b2);
93
void writeMidiEvent(long deltaTime, int type, int chan, const QByteArray& data);
94
void writeMidiEvent(long deltaTime, int type, long len, char* data);
96
void writeTempo(long deltaTime, long tempo);
97
void writeBpmTempo(long deltaTime, int tempo);
98
void writeTimeSignature(long deltaTime, int num, int den, int cc, int bb);
99
void writeKeySignature(long deltaTime, int tone, int mode);
100
void writeSequenceNumber(long deltaTime, int seqnum);
102
long getCurrentTime();
103
long getCurrentTempo();
107
void setDivision(int division);
109
void setTracks(int tracks);
111
void setFileFormat(int fileFormat);
114
void signalSMFError(const QString& errorStr);
115
void signalSMFHeader(int format, int ntrks, int division);
116
void signalSMFNoteOn(int chan, int pitch, int vol);
117
void signalSMFNoteOff(int chan, int pitch, int vol);
118
void signalSMFKeyPress(int chan, int pitch, int press);
119
void signalSMFCtlChange(int chan, int ctl, int value);
120
void signalSMFPitchBend(int chan, int value);
121
void signalSMFProgram(int chan, int patch);
122
void signalSMFChanPress(int chan, int press);
123
void signalSMFSysex(const QByteArray& data);
124
void signalSMFVariable(const QByteArray& data);
125
void signalSMFSeqSpecific(const QByteArray& data);
126
void signalSMFMetaMisc(int typ, const QByteArray& data);
127
void signalSMFSequenceNum(int seq);
128
void signalSMFforcedChannel(int channel);
129
void signalSMFforcedPort(int port);
130
void signalSMFText(int typ, const QString& data);
131
void signalSMFSmpte(int b0, int b1, int b2, int b3, int b4);
132
void signalSMFTimeSig(int b0, int b1, int b2, int b3);
133
void signalSMFKeySig(int b0, int b1);
134
void signalSMFTempo(int tempo);
135
void signalSMFendOfTrack();
136
void signalSMFTrackStart();
137
void signalSMFTrackEnd();
138
void signalSMFWriteTempoTrack();
139
void signalSMFWriteTrack(int track);
148
QDataStream *m_IOStream;
149
QByteArray m_MsgBuff;
150
QList<QSmfRecTempo> m_TempoList;
152
quint64 m_NumBytesWritten;
153
bool m_Interactive; // file and track headers are not required
154
quint64 m_CurrTime; // current time in delta-time units
155
quint64 m_RealTime; // current time in 1/16 centisecond-time units
156
double m_DblRealTime; // as above, floating
157
int m_Division; // ticks per beat. Default = 96
158
quint64 m_CurrTempo; // microseconds per quarter note
159
quint64 m_OldCurrTempo;
160
quint64 m_OldRealTime;
161
double m_DblOldRealtime;
162
quint64 m_OldCurrTime;
163
quint64 m_RevisedTime;
164
quint64 m_TempoChangeTime;
172
void putByte(quint8 value);
175
quint16 to16bit(quint8 c1, quint8 c2);
176
quint32 to32bit(quint8 c1, quint8 c2, quint8 c3, quint8 c4);
179
void write16bit(quint16 data);
180
void write32bit(quint32 data);
181
void writeVarLen(quint64 value);
182
double ticksToSecs(quint64 ticks, quint16 division, quint64 tempo);
184
void readExpected(const QString& s);
185
void addTempo(quint64 tempo, quint64 time);
187
void SMFError(const QString& s);
188
void channelMessage(quint8 status, quint8 c1, quint8 c2);
190
void msgAdd(quint8 b);
191
void metaEvent(quint8 b);
193
void badByte(quint8 b, int p);
194
quint8 lowerByte(quint16 x);
195
quint8 upperByte(quint16 x);
197
void writeHeaderChunk(int format, int ntracks, int division);
198
void writeTrackChunk(int track);