| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <fcntl.h> |
| 20 |
#define SEQ_MIDIPUTC 5 |
| 21 |
|
| 22 |
class MidiHandler_oss: public MidiHandler { |
| 23 |
private: |
| 24 |
int device; |
| 25 |
Bit8u device_num; |
| 26 |
bool isOpen; |
| 27 |
public: |
| 28 |
MidiHandler_oss() : MidiHandler(),isOpen(false) {}; |
| 29 |
const char * GetName(void) { return "oss";}; |
| 30 |
bool Open(const char * conf) { |
| 31 |
char devname[512]; |
| 32 |
if (conf && conf[0]) safe_strncpy(devname,conf,512); |
| 33 |
else strcpy(devname,"/dev/sequencer"); |
| 34 |
char * devfind=(strrchr(devname,',')); |
| 35 |
if (devfind) { |
| 36 |
*devfind++=0; |
| 37 |
device_num=atoi(devfind); |
| 38 |
} else device_num=0; |
| 39 |
if (isOpen) return false; |
| 40 |
device=open(devname, O_WRONLY, 0); |
| 41 |
if (device<0) return false; |
| 42 |
return true; |
| 43 |
}; |
| 44 |
void Close(void) { |
| 45 |
if (!isOpen) return; |
| 46 |
if (device>0) close(device); |
| 47 |
}; |
| 48 |
void PlayMsg(Bit8u * msg) { |
| 49 |
Bit8u buf[128];Bitu pos=0; |
| 50 |
Bitu len=MIDI_evt_len[*msg]; |
| 51 |
for (;len>0;len--) { |
| 52 |
buf[pos++] = SEQ_MIDIPUTC; |
| 53 |
buf[pos++] = *msg; |
| 54 |
buf[pos++] = device_num; |
| 55 |
buf[pos++] = 0; |
| 56 |
msg++; |
| 57 |
} |
| 58 |
write(device,buf,pos); |
| 59 |
}; |
| 60 |
void PlaySysex(Bit8u * sysex,Bitu len) { |
| 61 |
Bit8u buf[SYSEX_SIZE*4];Bitu pos=0; |
| 62 |
for (;len>0;len--) { |
| 63 |
buf[pos++] = SEQ_MIDIPUTC; |
| 64 |
buf[pos++] = *sysex++; |
| 65 |
buf[pos++] = device_num; |
| 66 |
buf[pos++] = 0; |
| 67 |
} |
| 68 |
write(device,buf,pos); |
| 69 |
} |
| 70 |
}; |
| 71 |
|
| 72 |
MidiHandler_oss Midi_oss; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|