xref: /haiku/headers/os/midi/Midi.h (revision 2807c36668a1730dd59bc39de65e0b8f88cd5d0d)
1 #ifndef _MIDI_H
2 #define _MIDI_H
3 
4 #ifndef _BE_BUILD_H
5 #include <BeBuild.h>
6 #endif
7 #include <MidiDefs.h>
8 #include <OS.h>
9 
10 class BMidiEvent;
11 class BList;
12 
13 class BMidi
14 {
15 public:
16 				BMidi();
17 virtual			~BMidi();
18 
19 virtual	void	NoteOff(uchar channel,
20 						uchar note,
21 						uchar velocity,
22 						uint32 time = B_NOW);
23 
24 virtual	void	NoteOn(uchar channel,
25 					   uchar note,
26 					   uchar velocity,
27 			    	   uint32 time = B_NOW);
28 
29 virtual	void	KeyPressure(uchar channel,
30 							uchar note,
31 							uchar pressure,
32 							uint32 time = B_NOW);
33 
34 virtual	void	ControlChange(uchar channel,
35 							  uchar controlNumber,
36 							  uchar controlValue,
37 							  uint32 time = B_NOW);
38 
39 virtual	void	ProgramChange(uchar channel,
40 								uchar programNumber,
41 							  	uint32 time = B_NOW);
42 
43 virtual	void	ChannelPressure(uchar channel,
44 								uchar pressure,
45 								uint32 time = B_NOW);
46 
47 virtual	void	PitchBend(uchar channel,
48 						  uchar lsb,
49 						  uchar msb,
50 			    		  uint32 time = B_NOW);
51 
52 virtual	void	SystemExclusive(void* data,
53 								size_t dataLength,
54 								uint32 time = B_NOW);
55 
56 virtual	void	SystemCommon(uchar statusByte,
57 							 uchar data1,
58 							 uchar data2,
59 							 uint32 time = B_NOW);
60 
61 virtual	void	SystemRealTime(uchar statusByte, uint32 time = B_NOW);
62 
63 virtual	void	TempoChange(int32 bpm, uint32 time = B_NOW);
64 
65 virtual void	AllNotesOff(bool justChannel = true, uint32 time = B_NOW);
66 
67 virtual	status_t	Start();
68 virtual	void		Stop();
69 		bool		IsRunning() const;
70 
71 		void	Connect(BMidi* toObject);
72 		void	Disconnect(BMidi* fromObject);
73 		bool	IsConnected(BMidi* toObject) const;
74 		BList*	Connections() const;
75 
76 		void	SnoozeUntil(uint32 time) const;
77 
78 protected:
79 		void	SprayNoteOff(uchar channel,
80 							 uchar note,
81 							 uchar velocity,
82 							 uint32 time) const;
83 
84 		void	SprayNoteOn(uchar channel,
85 							uchar note,
86 							uchar velocity,
87 							uint32 time) const;
88 
89 		void	SprayKeyPressure(uchar channel,
90 								 uchar note,
91 								 uchar pressure,
92 								 uint32 time) const;
93 
94 		void	SprayControlChange(uchar channel,
95 								   uchar controlNumber,
96 							 	   uchar controlValue,
97 								   uint32 time) const;
98 
99 		void	SprayProgramChange(uchar channel,
100 								   uchar programNumber,
101 								   uint32 time) const;
102 
103 		void	SprayChannelPressure(uchar channel,
104 										uchar pressure,
105 										uint32 time) const;
106 
107 		void	SprayPitchBend(uchar channel,
108 							   uchar lsb,
109 							   uchar msb,
110 							   uint32 time) const;
111 
112 		void	SpraySystemExclusive(void* data,
113 									size_t dataLength,
114 									uint32 time = B_NOW) const;
115 
116 		void	SpraySystemCommon(uchar statusByte,
117 							 uchar data1,
118 							 uchar data2,
119 							 uint32 time) const;
120 
121 		void	SpraySystemRealTime(uchar statusByte, uint32 time) const;
122 
123 		void	SprayTempoChange(int32 bpm, uint32 time) const;
124 
125 		bool	KeepRunning();
126 
127 private:
128 
129 friend class BMidiPort;	/* for debugging */
130 friend class BMidiStore;	/* for debugging */
131 
132 virtual	void		_ReservedMidi1();
133 virtual	void		_ReservedMidi2();
134 virtual	void		_ReservedMidi3();
135 
136 friend	status_t	_run_thread_(void *arg);
137 friend	status_t	_inflow_task_(void *arg);
138 
139 		void	SprayMidiEvent(BMidiEvent* event) const;
140 		port_id	ID() const;
141 
142 virtual	void	Run();
143 
144 		status_t	StartInflow();
145 		void	StopInflow();
146 		bool	IsInflowing();
147 		void	InflowTask();
148 		bool	InflowIsAlive();
149 
150 		BList*		fConnectionList;
151 volatile	thread_id	fRunTask;
152 volatile	bool		fIsRunning;
153 volatile	thread_id	fInflowTask;
154 volatile	bool		fInflowAlive;
155 		port_id		fInflowPort;
156 		uint32		_reserved[4];
157 };
158 
159 
160 
161 #endif
162