PCem
view src/win-midi.c @ 154:d0d530adce12
Initial port to Linux (using Allegro).
64-bit fixes.
Some changes to aid portability.
A few other tweaks.
| author | TomW |
|---|---|
| date | Thu Sep 04 21:07:24 2014 +0100 |
| parents | ee7a3f8ad75d |
| children |
line source
1 #include <windows.h>
2 #include <mmsystem.h>
3 #include "ibm.h"
4 #include "plat-midi.h"
6 static int midi_id;
7 static HMIDIOUT midi_out_device = NULL;
9 void midi_close();
11 void midi_init()
12 {
13 int c;
14 int n;
15 MIDIOUTCAPS ocaps;
16 MMRESULT hr;
18 midi_id=0;
20 hr = midiOutOpen(&midi_out_device, midi_id, 0,
21 0, CALLBACK_NULL);
22 if (hr != MMSYSERR_NOERROR) {
23 printf("midiOutOpen error - %08X\n",hr);
24 return;
25 }
27 midiOutReset(midi_out_device);
28 }
30 void midi_close()
31 {
32 if (midi_out_device != NULL)
33 {
34 midiOutReset(midi_out_device);
35 midiOutClose(midi_out_device);
36 midi_out_device = NULL;
37 }
38 }
40 static int midi_pos, midi_len;
41 static uint32_t midi_command;
42 static int midi_lengths[8] = {3, 3, 3, 3, 2, 2, 3, 0};
44 void midi_write(uint8_t val)
45 {
46 if (val & 0x80)
47 {
48 midi_pos = 0;
49 midi_len = midi_lengths[(val >> 4) & 7];
50 midi_command = 0;
51 }
53 if (midi_len)
54 {
55 midi_command |= (val << (midi_pos * 8));
57 midi_pos++;
59 if (midi_pos == midi_len)
60 midiOutShortMsg(midi_out_device, midi_command);
61 }
62 }
