]> code.delx.au - virtualtones/blob - midiengine.h
README update
[virtualtones] / midiengine.h
1 // midiengine.h - Class to play to a sequencer or write to a MIDI file
2 // Written by James Bunton <james@delx.net.au>
3 // Licensed under the GPL, see COPYING.txt for more details
4
5
6 #ifndef MIDIENGINE_H
7 #define MIDIENGINE_H
8
9
10 #include <QObject>
11 #include <QEvent>
12 #include <QString>
13
14
15 class MidiEngine : public QObject
16 {
17 Q_OBJECT
18 public:
19 /* initSuccess() - returns true if the object is ready to be used */
20 bool initSuccess();
21
22 /* getError() - returns an error message describing why the object isn't ready */
23 QString getError();
24
25
26 public slots:
27 /* setPatch() - Allows you to set the instrument
28 'num' - the number of the patchset you wish to use
29 Note: The patchset had better exist!
30 */
31 virtual void setInstrument(int num)=0;
32
33
34 /* playNote() - Plays a midi note
35 'num' - the note to play (between 0 and 127. 69 in middle C)
36 'vel' - the note volume (between 0 and 127), if 0 then the note is stopped
37 'len' - the duration in milliseconds, if 0, then note will play until stopped
38 returns false if it received incorrect parameters
39 */
40 virtual bool playNote(int num, int vel, int len)=0;
41
42
43 /* stopNote() - Stops a midi note
44 'num' - the note to stop
45 */
46 bool stopNote(int num);
47
48
49 /* stopAll() - Stops all currently playing MIDI notes */
50 void stopAll();
51
52 protected:
53 virtual void timerEvent(QTimerEvent *);
54
55 // For dealing with errors
56 QString errorMessage;
57 bool error;
58
59 // For turning notes off
60 long int noteEndings[128];
61 long int timer; // In milliseconds, only approximate
62 };
63
64
65 class MidiReal : public MidiEngine
66 {
67 Q_OBJECT
68 public:
69 MidiReal();
70 ~MidiReal();
71
72 public slots:
73 void setInstrument(int num);
74 bool playNote(int num, int vel, int len);
75
76 private:
77 class Private;
78 Private *d;
79 };
80
81
82
83 class MidiFile : public MidiEngine {
84 Q_OBJECT
85 public:
86 MidiFile(QString outFile);
87 ~MidiFile();
88
89 public slots:
90 void setInstrument(int num);
91 bool playNote(int num, int vel, int len);
92
93 private:
94 class Private;
95 Private *d;
96 };
97
98
99
100 #endif