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

stmidi.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 /*
00024  * Raw MIDI output for the Atari ST line of computers.
00025  * Based on the ScummVM SEQ & CoreMIDI drivers.
00026  * Atari code by Keith Scroggins
00027  * We, unfortunately, could not use the SEQ driver because the /dev/midi under
00028  * FreeMiNT (and hence in libc) is considered to be a serial port for machine
00029  * access.  So, we just use OS calls then to send the data to the MIDI ports
00030  * directly.  The current implementation is sending 1 byte at a time because
00031  * in most cases we are only sending up to 3 bytes, I believe this saves a few
00032  * cycles.  I might change so sysex messages are sent the other way later.
00033  */
00034 
00035 // Disable symbol overrides so that we can use system headers.
00036 #define FORBIDDEN_SYMBOL_ALLOW_ALL
00037 
00038 #include "common/scummsys.h"
00039 
00040 #if defined(__MINT__)
00041 
00042 #include <osbind.h>
00043 #include "audio/mpu401.h"
00044 #include "common/error.h"
00045 #include "common/util.h"
00046 #include "audio/musicplugin.h"
00047 
00048 class MidiDriver_STMIDI : public MidiDriver_MPU401 {
00049 public:
00050     MidiDriver_STMIDI() : _isOpen (false) { }
00051     int open();
00052     bool isOpen() const { return _isOpen; }
00053     void close();
00054     void send(uint32 b);
00055     void sysEx(const byte *msg, uint16 length);
00056 
00057 private:
00058     bool _isOpen;
00059 };
00060 
00061 int MidiDriver_STMIDI::open() {
00062     if (_isOpen && (!Bcostat(4)))
00063         return MERR_ALREADY_OPEN;
00064     warning("ST Midi Port Open");
00065     _isOpen = true;
00066     return 0;
00067 }
00068 
00069 void MidiDriver_STMIDI::close() {
00070     MidiDriver_MPU401::close();
00071     _isOpen = false;
00072 }
00073 
00074 void MidiDriver_STMIDI::send(uint32 b) {
00075 
00076     byte status_byte = (b & 0x000000FF);
00077     byte first_byte = (b & 0x0000FF00) >> 8;
00078     byte second_byte = (b & 0x00FF0000) >> 16;
00079 
00080 //  warning("ST MIDI Packet sent");
00081 
00082     switch (b & 0xF0) {
00083     case 0x80:  // Note Off
00084     case 0x90:  // Note On
00085     case 0xA0:  // Polyphonic Key Pressure
00086     case 0xB0:  // Controller
00087     case 0xE0:  // Pitch Bend
00088         Bconout(3, status_byte);
00089         Bconout(3, first_byte);
00090         Bconout(3, second_byte);
00091         break;
00092     case 0xC0:  // Program Change
00093     case 0xD0:  // Aftertouch
00094         Bconout(3, status_byte);
00095         Bconout(3, first_byte);
00096         break;
00097     default:
00098         fprintf(stderr, "Unknown : %08x\n", (int)b);
00099         break;
00100     }
00101 }
00102 
00103 void MidiDriver_STMIDI::sysEx (const byte *msg, uint16 length) {
00104     // FIXME: LordHoto doesn't know if this will still work
00105     // when sending 264 byte sysEx data, as needed by KYRA,
00106     // feel free to revert it to 254 again if needed.
00107     if (length > 264) {
00108         warning ("Cannot send SysEx block - data too large");
00109         return;
00110     }
00111 
00112     const byte *chr = msg;
00113     warning("Sending SysEx Message");
00114 
00115     Bconout(3, '0xF0');
00116     for (; length; --length, ++chr) {
00117         Bconout(3,((unsigned char) *chr & 0x7F));
00118     }
00119     Bconout(3, '0xF7');
00120 }
00121 
00122 // Plugin interface
00123 
00124 class StMidiMusicPlugin : public MusicPluginObject {
00125 public:
00126     const char *getName() const {
00127         return "STMIDI";
00128     }
00129 
00130     const char *getId() const {
00131         return "stmidi";
00132     }
00133 
00134     MusicDevices getDevices() const;
00135     Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
00136 };
00137 
00138 MusicDevices StMidiMusicPlugin::getDevices() const {
00139     MusicDevices devices;
00140     // TODO: Return a different music type depending on the configuration
00141     // TODO: List the available devices
00142     devices.push_back(MusicDevice(this, "", MT_GM));
00143     return devices;
00144 }
00145 
00146 Common::Error StMidiMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
00147     *mididriver = new MidiDriver_STMIDI();
00148 
00149     return Common::kNoError;
00150 }
00151 
00152 //#if PLUGIN_ENABLED_DYNAMIC(STMIDI)
00153     //REGISTER_PLUGIN_DYNAMIC(STMIDI, PLUGIN_TYPE_MUSIC, StMidiMusicPlugin);
00154 //#else
00155     REGISTER_PLUGIN_STATIC(STMIDI, PLUGIN_TYPE_MUSIC, StMidiMusicPlugin);
00156 //#endif
00157 
00158 #endif


Generated on Sat Mar 23 2019 05:02:13 for ResidualVM by doxygen 1.7.1
curved edge   curved edge