DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/gui/midi_oss.h
00001 /*
00002  *  Copyright (C) 2002-2020  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 along
00015  *  with this program; if not, write to the Free Software Foundation, Inc.,
00016  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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         ssize_t writeResult = write(device, buf, pos);
00059         if (writeResult == -1) {
00060             LOG(LOG_IO, LOG_ERROR) ("Writing error in PlayMsg\n");
00061         }
00062         };
00063         void PlaySysex(Bit8u * sysex,Bitu len) {
00064                 Bit8u buf[SYSEX_SIZE*4];Bitu pos=0;
00065                 for (;len>0;len--) {
00066                         buf[pos++] = SEQ_MIDIPUTC;
00067                         buf[pos++] = *sysex++;
00068                         buf[pos++] = device_num;
00069                         buf[pos++] = 0;
00070                 }
00071         ssize_t writeResult = write(device, buf, pos);
00072         if (writeResult == -1) {
00073             LOG(LOG_IO, LOG_ERROR) ("Writing error in PlaySysex\n");
00074         }
00075         }
00076 };
00077 
00078 MidiHandler_oss Midi_oss;
00079 
00080 
00081 
00082