ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

sndio.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 // Disable symbol overrides so that we can use system headers.
00024 #define FORBIDDEN_SYMBOL_ALLOW_ALL
00025 
00026 #include "common/scummsys.h"
00027 
00028 #if defined(USE_SNDIO)
00029 
00030 #include "common/error.h"
00031 #include "common/textconsole.h"
00032 #include "common/util.h"
00033 #include "audio/musicplugin.h"
00034 #include "audio/mpu401.h"
00035 
00036 #include <sndio.h>
00037 
00039 //
00040 // sndio MIDI driver
00041 //
00043 
00044 class MidiDriver_Sndio : public MidiDriver_MPU401 {
00045 public:
00046     MidiDriver_Sndio();
00047     int open();
00048     bool isOpen() const { return hdl != NULL; }
00049     void close();
00050     void send(uint32 b);
00051     void sysEx(const byte *msg, uint16 length);
00052 
00053 private:
00054     struct mio_hdl *hdl;
00055 };
00056 
00057 MidiDriver_Sndio::MidiDriver_Sndio() {
00058     hdl = NULL;
00059 }
00060 
00061 int MidiDriver_Sndio::open() {
00062     if (hdl != NULL)
00063         return MERR_ALREADY_OPEN;
00064 
00065     hdl = ::mio_open(NULL, MIO_OUT, 0);
00066     if (hdl == NULL)
00067         warning("Could open MIDI port (no music)");
00068     return 0;
00069 }
00070 
00071 void MidiDriver_Sndio::close() {
00072     MidiDriver_MPU401::close();
00073     if (!hdl)
00074         return;
00075     mio_close(hdl);
00076     hdl = NULL;
00077 }
00078 
00079 void MidiDriver_Sndio::send(uint32 b) {
00080     unsigned char buf[4];
00081     unsigned int len;
00082 
00083     if (!hdl)
00084         return;
00085     buf[0] = b & 0xff;
00086     buf[1] = (b >> 8) & 0xff;
00087     buf[2] = (b >> 16) & 0xff;
00088     buf[3] = (b >> 24) & 0xff;
00089     switch (buf[0] & 0xf0) {
00090     case 0xf0:
00091         return;
00092     case 0xc0:
00093     case 0xd0:
00094         len = 2;
00095         break;
00096     default:
00097         len = 3;
00098     }
00099     mio_write(hdl, buf, len);
00100 }
00101 
00102 void MidiDriver_Sndio::sysEx(const byte *msg, uint16 length) {
00103     if (!hdl)
00104         return;
00105 
00106     unsigned char buf[266];
00107 
00108     assert(length + 2 <= ARRAYSIZE(buf));
00109 
00110     // Add SysEx frame
00111     buf[0] = 0xF0;
00112     memcpy(buf + 1, msg, length);
00113     buf[length + 1] = 0xF7;
00114 
00115     mio_write(hdl, buf, length + 2);
00116 }
00117 
00118 
00119 // Plugin interface
00120 
00121 class SndioMusicPlugin : public MusicPluginObject {
00122 public:
00123     const char *getName() const {
00124         return "Sndio";
00125     }
00126 
00127     const char *getId() const {
00128         return "sndio";
00129     }
00130 
00131     MusicDevices getDevices() const;
00132     Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
00133 };
00134 
00135 MusicDevices SndioMusicPlugin::getDevices() const {
00136     MusicDevices devices;
00137     devices.push_back(MusicDevice(this, "", MT_GM));
00138     return devices;
00139 }
00140 
00141 Common::Error SndioMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
00142     *mididriver = new MidiDriver_Sndio();
00143 
00144     return Common::kNoError;
00145 }
00146 
00147 //#if PLUGIN_ENABLED_DYNAMIC(Sndio)
00148     //REGISTER_PLUGIN_DYNAMIC(SNDIO, PLUGIN_TYPE_MUSIC, SndioMusicPlugin);
00149 //#else
00150     REGISTER_PLUGIN_STATIC(SNDIO, PLUGIN_TYPE_MUSIC, SndioMusicPlugin);
00151 //#endif
00152 
00153 #endif


Generated on Sat Mar 16 2019 05:01:54 for ResidualVM by doxygen 1.7.1
curved edge   curved edge