tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / kits / midi / Midi.cpp
blob6df0ef7117b8bb5a0cfc1ffbcbfa817a7fbbf721
1 /*
2 * Copyright 2006, Haiku.
3 *
4 * Copyright (c) 2002-2003 Matthijs Hollemans
5 * Copyright (c) 2002 Michael Pfeiffer
6 * Copyright (c) 2002 Jerome Leveque
7 * Copyright (c) 2002 Paul Stadler
8 * Distributed under the terms of the MIT License.
10 * Authors:
11 * Matthijs Hollemans
12 * Michael Pfeiffer
13 * Jérôme Leveque
14 * Paul Stadler
17 #include <List.h>
18 #include <Midi.h>
19 #include <MidiProducer.h>
21 #include "MidiGlue.h"
22 #include "debug.h"
24 using namespace BPrivate;
27 status_t
28 _run_thread(void* data)
30 BMidi* midi = (BMidi*)data;
31 midi->Run();
32 midi->fIsRunning = false;
33 return 0;
37 BMidi::BMidi()
39 fConnections = new BList;
40 fThreadId = -1;
41 fIsRunning = false;
43 fProducer = new BMidiLocalProducer("MidiGlue(out)");
44 fConsumer = new BMidiGlue(this, "MidiGlue(in)");
48 BMidi::~BMidi()
50 Stop();
52 status_t result;
53 wait_for_thread(fThreadId, &result);
55 fProducer->Release();
56 fConsumer->Release();
58 delete fConnections;
62 void
63 BMidi::NoteOff(uchar channel, uchar note, uchar velocity, uint32 time)
65 // do nothing
69 void
70 BMidi::NoteOn(uchar channel, uchar note, uchar velocity, uint32 time)
72 // do nothing
76 void
77 BMidi::KeyPressure(
78 uchar channel, uchar note, uchar pressure, uint32 time)
80 // do nothing
84 void
85 BMidi::ControlChange(
86 uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
88 // do nothing
92 void
93 BMidi::ProgramChange(uchar channel, uchar programNumber, uint32 time)
95 // do nothing
99 void
100 BMidi::ChannelPressure(uchar channel, uchar pressure, uint32 time)
102 // do nothing
106 void
107 BMidi::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time)
109 // do nothing
113 void
114 BMidi::SystemExclusive(void* data, size_t length, uint32 time)
116 // do nothing
120 void
121 BMidi::SystemCommon(uchar status, uchar data1, uchar data2, uint32 time)
123 // do nothing
127 void
128 BMidi::SystemRealTime(uchar status, uint32 time)
130 // do nothing
134 void
135 BMidi::TempoChange(int32 beatsPerMinute, uint32 time)
137 // do nothing
141 void
142 BMidi::AllNotesOff(bool justChannel, uint32 time)
144 for (uchar channel = 1; channel <= 16; ++channel) {
145 SprayControlChange(channel, B_ALL_NOTES_OFF, 0, time);
147 if (!justChannel) {
148 for (uchar note = 0; note <= 0x7F; ++note) {
149 SprayNoteOff(channel, note, 0, time);
156 status_t
157 BMidi::Start()
159 if (fIsRunning)
160 return B_OK;
162 status_t err = spawn_thread(
163 _run_thread, "MidiRunThread", B_URGENT_PRIORITY, this);
165 if (err < B_OK)
166 return err;
168 fThreadId = err;
169 fIsRunning = true;
171 err = resume_thread(fThreadId);
172 if (err != B_OK) {
173 fThreadId = -1;
174 fIsRunning = false;
177 return err;
181 void
182 BMidi::Stop()
184 AllNotesOff();
185 fThreadId = -1;
189 bool
190 BMidi::IsRunning() const
192 return fIsRunning;
196 void
197 BMidi::Connect(BMidi* toObject)
199 if (toObject != NULL) {
200 if (fProducer->Connect(toObject->fConsumer) == B_OK) {
201 fConnections->AddItem(toObject);
207 void
208 BMidi::Disconnect(BMidi* fromObject)
210 if (fromObject == NULL)
211 return;
213 if (fProducer->Disconnect(fromObject->fConsumer) == B_OK) {
214 fConnections->RemoveItem(fromObject);
219 bool
220 BMidi::IsConnected(BMidi* toObject) const
222 if (toObject != NULL)
223 return fProducer->IsConnected(toObject->fConsumer);
225 return false;
229 BList*
230 BMidi::Connections() const
232 return fConnections;
236 void
237 BMidi::SnoozeUntil(uint32 time) const
239 snooze_until(MAKE_BIGTIME(time), B_SYSTEM_TIMEBASE);
243 bool
244 BMidi::KeepRunning()
246 return (fThreadId != -1);
250 void BMidi::_ReservedMidi1() {}
251 void BMidi::_ReservedMidi2() {}
252 void BMidi::_ReservedMidi3() {}
255 void
256 BMidi::Run()
258 // do nothing
262 void
263 BMidi::SprayNoteOff(
264 uchar channel, uchar note, uchar velocity, uint32 time) const
266 fProducer->SprayNoteOff(
267 channel - 1, note, velocity, MAKE_BIGTIME(time));
271 void
272 BMidi::SprayNoteOn(
273 uchar channel, uchar note, uchar velocity, uint32 time) const
275 fProducer->SprayNoteOn(
276 channel - 1, note, velocity, MAKE_BIGTIME(time));
280 void
281 BMidi::SprayKeyPressure(
282 uchar channel, uchar note, uchar pressure, uint32 time) const
284 fProducer->SprayKeyPressure(
285 channel - 1, note, pressure, MAKE_BIGTIME(time));
289 void
290 BMidi::SprayControlChange(
291 uchar channel, uchar controlNumber, uchar controlValue,
292 uint32 time) const
294 fProducer->SprayControlChange(
295 channel - 1, controlNumber, controlValue, MAKE_BIGTIME(time));
299 void
300 BMidi::SprayProgramChange(
301 uchar channel, uchar programNumber, uint32 time) const
303 fProducer->SprayProgramChange(
304 channel - 1, programNumber, MAKE_BIGTIME(time));
308 void
309 BMidi::SprayChannelPressure(
310 uchar channel, uchar pressure, uint32 time) const
312 fProducer->SprayChannelPressure(
313 channel - 1, pressure, MAKE_BIGTIME(time));
317 void
318 BMidi::SprayPitchBend(
319 uchar channel, uchar lsb, uchar msb, uint32 time) const
321 fProducer->SprayPitchBend(channel - 1, lsb, msb, MAKE_BIGTIME(time));
325 void
326 BMidi::SpraySystemExclusive(
327 void* data, size_t length, uint32 time) const
329 fProducer->SpraySystemExclusive(data, length, MAKE_BIGTIME(time));
333 void
334 BMidi::SpraySystemCommon(
335 uchar status, uchar data1, uchar data2, uint32 time) const
337 fProducer->SpraySystemCommon(status, data1, data2, MAKE_BIGTIME(time));
341 void
342 BMidi::SpraySystemRealTime(uchar status, uint32 time) const
344 fProducer->SpraySystemRealTime(status, MAKE_BIGTIME(time));
348 void
349 BMidi::SprayTempoChange(int32 beatsPerMinute, uint32 time) const
351 fProducer->SprayTempoChange(beatsPerMinute, MAKE_BIGTIME(time));