~ubuntu-branches/ubuntu/precise/kmidimon/precise

« back to all changes in this revision

Viewing changes to aseqmm/include/qsmf.h

  • Committer: Bazaar Package Importer
  • Author(s): Adrian Knoth
  • Date: 2009-12-24 17:59:55 UTC
  • mto: (7.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20091224175955-2h2i1vbd4nhjop6x
Tags: upstream-0.7.3
ImportĀ upstreamĀ versionĀ 0.7.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    Standard MIDI File component
3
 
    Copyright (C) 2006-2009, 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 INCLUDED_SMF_H
23
 
#define INCLUDED_SMF_H
24
 
 
25
 
#include <QObject>
26
 
#include <QDataStream>
27
 
#include <QString>
28
 
#include <QList>
29
 
 
30
 
namespace MIDI
31
 
{
32
 
namespace Utils
33
 
{
34
 
 
35
 
#define MThd 0x4d546864
36
 
#define MTrk 0x4d54726b
37
 
 
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
45
 
#define lyric               0x05
46
 
#define marker              0x06
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
56
 
 
57
 
/* MIDI status commands most significant bit is 1 */
58
 
#define note_off            0x80
59
 
#define note_on             0x90
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
67
 
 
68
 
#define midi_command_mask   0xf0
69
 
#define midi_channel_mask   0x0f
70
 
 
71
 
#define major_mode          0
72
 
#define minor_mode          1
73
 
 
74
 
class QSmf : public QObject
75
 
{
76
 
    Q_OBJECT
77
 
 
78
 
public:
79
 
    QSmf(QObject * parent = 0);
80
 
    virtual ~QSmf();
81
 
 
82
 
    void readFromStream(QDataStream *stream);
83
 
    void readFromFile(const QString& fileName);
84
 
    void writeToStream(QDataStream *stream);
85
 
    void writeToFile(const QString& fileName);
86
 
 
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);
90
 
 
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);
95
 
 
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);
101
 
 
102
 
    long getCurrentTime();
103
 
    long getCurrentTempo();
104
 
    long getRealTime();
105
 
    long getFilePos();
106
 
    int  getDivision();
107
 
    void setDivision(int division);
108
 
    int  getTracks();
109
 
    void setTracks(int tracks);
110
 
    int  getFileFormat();
111
 
    void setFileFormat(int fileFormat);
112
 
 
113
 
signals:
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);
140
 
 
141
 
private:
142
 
    struct QSmfRecTempo
143
 
    {
144
 
        quint64 tempo;
145
 
        quint64 time;
146
 
    };
147
 
 
148
 
    QDataStream *m_IOStream;
149
 
    QByteArray m_MsgBuff;
150
 
    QList<QSmfRecTempo> m_TempoList;
151
 
    quint64 m_ToBeRead;
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;
165
 
    int m_Tracks;
166
 
    int m_fileFormat;
167
 
    int m_LastStatus;
168
 
 
169
 
    void SMFRead();
170
 
    void SMFWrite();
171
 
    quint8 getByte();
172
 
    void putByte(quint8 value);
173
 
    void readHeader();
174
 
    void readTrack();
175
 
    quint16 to16bit(quint8 c1, quint8 c2);
176
 
    quint32 to32bit(quint8 c1, quint8 c2, quint8 c3, quint8 c4);
177
 
    quint16 read16bit();
178
 
    quint32 read32bit();
179
 
    void write16bit(quint16 data);
180
 
    void write32bit(quint32 data);
181
 
    void writeVarLen(quint64 value);
182
 
    double ticksToSecs(quint64 ticks, quint16 division, quint64 tempo);
183
 
    long readVarLen();
184
 
    void readExpected(const QString& s);
185
 
    void addTempo(quint64 tempo, quint64 time);
186
 
    quint64 findTempo();
187
 
    void SMFError(const QString& s);
188
 
    void channelMessage(quint8 status, quint8 c1, quint8 c2);
189
 
    void msgInit();
190
 
    void msgAdd(quint8 b);
191
 
    void metaEvent(quint8 b);
192
 
    void sysEx();
193
 
    void badByte(quint8 b, int p);
194
 
    quint8 lowerByte(quint16 x);
195
 
    quint8 upperByte(quint16 x);
196
 
    bool endOfSmf();
197
 
    void writeHeaderChunk(int format, int ntracks, int division);
198
 
    void writeTrackChunk(int track);
199
 
};
200
 
 
201
 
}
202
 
}
203
 
 
204
 
#endif