2 * Copyright 2006, Haiku.
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.
19 #include <MidiProducer.h>
24 using namespace BPrivate
;
28 _run_thread(void* data
)
30 BMidi
* midi
= (BMidi
*)data
;
32 midi
->fIsRunning
= false;
39 fConnections
= new BList
;
43 fProducer
= new BMidiLocalProducer("MidiGlue(out)");
44 fConsumer
= new BMidiGlue(this, "MidiGlue(in)");
53 wait_for_thread(fThreadId
, &result
);
63 BMidi::NoteOff(uchar channel
, uchar note
, uchar velocity
, uint32 time
)
70 BMidi::NoteOn(uchar channel
, uchar note
, uchar velocity
, uint32 time
)
78 uchar channel
, uchar note
, uchar pressure
, uint32 time
)
86 uchar channel
, uchar controlNumber
, uchar controlValue
, uint32 time
)
93 BMidi::ProgramChange(uchar channel
, uchar programNumber
, uint32 time
)
100 BMidi::ChannelPressure(uchar channel
, uchar pressure
, uint32 time
)
107 BMidi::PitchBend(uchar channel
, uchar lsb
, uchar msb
, uint32 time
)
114 BMidi::SystemExclusive(void* data
, size_t length
, uint32 time
)
121 BMidi::SystemCommon(uchar status
, uchar data1
, uchar data2
, uint32 time
)
128 BMidi::SystemRealTime(uchar status
, uint32 time
)
135 BMidi::TempoChange(int32 beatsPerMinute
, uint32 time
)
142 BMidi::AllNotesOff(bool justChannel
, uint32 time
)
144 for (uchar channel
= 1; channel
<= 16; ++channel
) {
145 SprayControlChange(channel
, B_ALL_NOTES_OFF
, 0, time
);
148 for (uchar note
= 0; note
<= 0x7F; ++note
) {
149 SprayNoteOff(channel
, note
, 0, time
);
162 status_t err
= spawn_thread(
163 _run_thread
, "MidiRunThread", B_URGENT_PRIORITY
, this);
171 err
= resume_thread(fThreadId
);
190 BMidi::IsRunning() const
197 BMidi::Connect(BMidi
* toObject
)
199 if (toObject
!= NULL
) {
200 if (fProducer
->Connect(toObject
->fConsumer
) == B_OK
) {
201 fConnections
->AddItem(toObject
);
208 BMidi::Disconnect(BMidi
* fromObject
)
210 if (fromObject
== NULL
)
213 if (fProducer
->Disconnect(fromObject
->fConsumer
) == B_OK
) {
214 fConnections
->RemoveItem(fromObject
);
220 BMidi::IsConnected(BMidi
* toObject
) const
222 if (toObject
!= NULL
)
223 return fProducer
->IsConnected(toObject
->fConsumer
);
230 BMidi::Connections() const
237 BMidi::SnoozeUntil(uint32 time
) const
239 snooze_until(MAKE_BIGTIME(time
), B_SYSTEM_TIMEBASE
);
246 return (fThreadId
!= -1);
250 void BMidi::_ReservedMidi1() {}
251 void BMidi::_ReservedMidi2() {}
252 void BMidi::_ReservedMidi3() {}
264 uchar channel
, uchar note
, uchar velocity
, uint32 time
) const
266 fProducer
->SprayNoteOff(
267 channel
- 1, note
, velocity
, MAKE_BIGTIME(time
));
273 uchar channel
, uchar note
, uchar velocity
, uint32 time
) const
275 fProducer
->SprayNoteOn(
276 channel
- 1, note
, velocity
, MAKE_BIGTIME(time
));
281 BMidi::SprayKeyPressure(
282 uchar channel
, uchar note
, uchar pressure
, uint32 time
) const
284 fProducer
->SprayKeyPressure(
285 channel
- 1, note
, pressure
, MAKE_BIGTIME(time
));
290 BMidi::SprayControlChange(
291 uchar channel
, uchar controlNumber
, uchar controlValue
,
294 fProducer
->SprayControlChange(
295 channel
- 1, controlNumber
, controlValue
, MAKE_BIGTIME(time
));
300 BMidi::SprayProgramChange(
301 uchar channel
, uchar programNumber
, uint32 time
) const
303 fProducer
->SprayProgramChange(
304 channel
- 1, programNumber
, MAKE_BIGTIME(time
));
309 BMidi::SprayChannelPressure(
310 uchar channel
, uchar pressure
, uint32 time
) const
312 fProducer
->SprayChannelPressure(
313 channel
- 1, pressure
, MAKE_BIGTIME(time
));
318 BMidi::SprayPitchBend(
319 uchar channel
, uchar lsb
, uchar msb
, uint32 time
) const
321 fProducer
->SprayPitchBend(channel
- 1, lsb
, msb
, MAKE_BIGTIME(time
));
326 BMidi::SpraySystemExclusive(
327 void* data
, size_t length
, uint32 time
) const
329 fProducer
->SpraySystemExclusive(data
, length
, MAKE_BIGTIME(time
));
334 BMidi::SpraySystemCommon(
335 uchar status
, uchar data1
, uchar data2
, uint32 time
) const
337 fProducer
->SpraySystemCommon(status
, data1
, data2
, MAKE_BIGTIME(time
));
342 BMidi::SpraySystemRealTime(uchar status
, uint32 time
) const
344 fProducer
->SpraySystemRealTime(status
, MAKE_BIGTIME(time
));
349 BMidi::SprayTempoChange(int32 beatsPerMinute
, uint32 time
) const
351 fProducer
->SprayTempoChange(beatsPerMinute
, MAKE_BIGTIME(time
));