xref: /haiku/headers/os/midi/Midi.h (revision d0ac609964842f8cdb6d54b3c539c6c15293e172)
1 
2 #ifndef _MIDI_H
3 #define _MIDI_H
4 
5 #include <BeBuild.h>
6 #include <MidiDefs.h>
7 #include <OS.h>
8 
9 class BList;
10 class BMidiLocalProducer;
11 class BMidiLocalConsumer;
12 
13 class BMidi {
14 public:
15 
16 	BMidi();
17 	virtual ~BMidi();
18 
19 	virtual void NoteOff(
20 		uchar channel, uchar note, uchar velocity, uint32 time = B_NOW);
21 
22 	virtual void NoteOn(
23 		uchar channel, uchar note, uchar velocity, uint32 time = B_NOW);
24 
25 	virtual void KeyPressure(
26 		uchar channel, uchar note, uchar pressure, uint32 time = B_NOW);
27 
28 	virtual void ControlChange(
29 		uchar channel, uchar controlNumber, uchar controlValue,
30 		uint32 time = B_NOW);
31 
32 	virtual void ProgramChange(
33 		uchar channel, uchar programNumber, uint32 time = B_NOW);
34 
35 	virtual void ChannelPressure(
36 		uchar channel, uchar pressure, uint32 time = B_NOW);
37 
38 	virtual void PitchBend(
39 		uchar channel, uchar lsb, uchar msb, uint32 time = B_NOW);
40 
41 	virtual void SystemExclusive(
42 		void* data, size_t length, uint32 time = B_NOW);
43 
44 	virtual void SystemCommon(
45 		uchar status, uchar data1, uchar data2, uint32 time = B_NOW);
46 
47 	virtual void SystemRealTime(uchar status, uint32 time = B_NOW);
48 
49 	virtual void TempoChange(int32 beatsPerMinute, uint32 time = B_NOW);
50 
51 	virtual void AllNotesOff(bool justChannel = true, uint32 time = B_NOW);
52 
53 	virtual status_t Start();
54 	virtual void Stop();
55 
56 	bool IsRunning() const;
57 
58 	void Connect(BMidi* toObject);
59 	void Disconnect(BMidi* fromObject);
60 	bool IsConnected(BMidi* toObject) const;
61 	BList* Connections() const;
62 
63 	void SnoozeUntil(uint32 time) const;
64 
65 protected:
66 
67 	void SprayNoteOff(
68 		uchar channel, uchar note, uchar velocity, uint32 time) const;
69 
70 	void SprayNoteOn(
71 		uchar channel, uchar note, uchar velocity, uint32 time) const;
72 
73 	void SprayKeyPressure(
74 		uchar channel, uchar note, uchar pressure, uint32 time) const;
75 
76 	void SprayControlChange(
77 		uchar channel, uchar controlNumber, uchar controlValue,
78 		uint32 time) const;
79 
80 	void SprayProgramChange(
81 		uchar channel, uchar programNumber, uint32 time) const;
82 
83 	void SprayChannelPressure(
84 		uchar channel, uchar pressure, uint32 time) const;
85 
86 	void SprayPitchBend(
87 		uchar channel, uchar lsb, uchar msb, uint32 time) const;
88 
89 	void SpraySystemExclusive(
90 		void* data, size_t length, uint32 time = B_NOW) const;
91 
92 	void SpraySystemCommon(
93 		uchar status, uchar data1, uchar data2, uint32 time) const;
94 
95 	void SpraySystemRealTime(uchar status, uint32 time) const;
96 
97 	void SprayTempoChange(int32 beatsPerMinute, uint32 time) const;
98 
99 	bool KeepRunning();
100 
101 private:
102 
103 	friend status_t _run_thread(void* data);
104 
105 	virtual void _ReservedMidi1();
106 	virtual void _ReservedMidi2();
107 	virtual void _ReservedMidi3();
108 
109 	virtual void Run();
110 
111 	BMidiLocalProducer* fProducer;
112 	BMidiLocalConsumer* fConsumer;
113 
114 	BList* fConnections;
115 	volatile thread_id fThreadId;
116 	volatile bool fIsRunning;
117 
118 	uint32 _reserved2[5];
119 };
120 
121 #endif // _MIDI_H
122