DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/gui/midi_oss.h
00001 /*
00002  *  Copyright (C) 2002-2013  The DOSBox Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #include <fcntl.h>
00020 #define SEQ_MIDIPUTC    5
00021 
00022 class MidiHandler_oss: public MidiHandler {
00023 private:
00024         int  device;
00025         Bit8u device_num;
00026         bool isOpen;
00027 public:
00028         MidiHandler_oss() : MidiHandler(),isOpen(false) {};
00029         const char * GetName(void) { return "oss";};
00030         bool Open(const char * conf) {
00031                 char devname[512];
00032                 if (conf && conf[0]) safe_strncpy(devname,conf,512);
00033                 else strcpy(devname,"/dev/sequencer");
00034                 char * devfind=(strrchr(devname,','));
00035                 if (devfind) {
00036                         *devfind++=0;
00037                         device_num=atoi(devfind);
00038                 } else device_num=0;
00039                 if (isOpen) return false;
00040                 device=open(devname, O_WRONLY, 0);
00041                 if (device<0) return false;
00042                 return true;
00043         };
00044         void Close(void) {
00045                 if (!isOpen) return;
00046                 if (device>0) close(device);
00047         };
00048         void PlayMsg(Bit8u * msg) {
00049                 Bit8u buf[128];Bitu pos=0;
00050                 Bitu len=MIDI_evt_len[*msg];
00051                 for (;len>0;len--) {
00052                         buf[pos++] = SEQ_MIDIPUTC;
00053                         buf[pos++] = *msg;
00054                         buf[pos++] = device_num;
00055                         buf[pos++] = 0;
00056                         msg++;
00057                 }
00058                 write(device,buf,pos);
00059         };
00060         void PlaySysex(Bit8u * sysex,Bitu len) {
00061                 Bit8u buf[SYSEX_SIZE*4];Bitu pos=0;
00062                 for (;len>0;len--) {
00063                         buf[pos++] = SEQ_MIDIPUTC;
00064                         buf[pos++] = *sysex++;
00065                         buf[pos++] = device_num;
00066                         buf[pos++] = 0;
00067                 }
00068                 write(device,buf,pos);  
00069         }
00070 };
00071 
00072 MidiHandler_oss Midi_oss;
00073 
00074 
00075 
00076