# os2_m.cpp

Go to the documentation of this file.

    00001 /* $Id: os2_m.cpp 17248 2009-08-21 20:21:05Z rubidium $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #include "../stdafx.h"
    00013 #include "../openttd.h"
    00014 #include "os2_m.h"
    00015
    00016 #define INCL_DOS
    00017 #define INCL_OS2MM
    00018 #define INCL_WIN
    00019
    00020 #include <stdarg.h>
    00021 #include <os2.h>
    00022 #include <os2me.h>
    00023
    00024 /**********************
    00025  * OS/2 MIDI PLAYER
    00026  **********************/
    00027
    00028 /* Interesting how similar the MCI API in OS/2 is to the Win32 MCI API,
    00029  * eh? Anyone would think they both came from the same place originally! ;)
    00030  */
    00031
    00032 static long CDECL MidiSendCommand(const char *cmd, ...)
    00033 {
    00034   va_list va;
    00035   char buf[512];
    00036   va_start(va, cmd);
    00037   vseprintf(buf, lastof(buf), cmd, va);
    00038   va_end(va);
    00039   return mciSendString(buf, NULL, 0, NULL, 0);
    00040 }
    00041
    00042 static FMusicDriver_OS2 iFMusicDriver_OS2;
    00043
    00044 void MusicDriver_OS2::PlaySong(const char *filename)
    00045 {
    00046   MidiSendCommand("close all");
    00047
    00048   if (MidiSendCommand("open %s type sequencer alias song", filename) != 0) {
    00049     return;
    00050   }
    00051
    00052   MidiSendCommand("play song from 0");
    00053 }
    00054
    00055 void MusicDriver_OS2::StopSong()
    00056 {
    00057   MidiSendCommand("close all");
    00058 }
    00059
    00060 void MusicDriver_OS2::SetVolume(byte vol)
    00061 {
    00062   MidiSendCommand("set song audio volume %d", ((vol/127)*100));
    00063 }
    00064
    00065 bool MusicDriver_OS2::IsSongPlaying()
    00066 {
    00067   char buf[16];
    00068   mciSendString("status song mode", buf, sizeof(buf), NULL, 0);
    00069   return strcmp(buf, "playing") == 0 || strcmp(buf, "seeking") == 0;
    00070 }
    00071
    00072 const char *MusicDriver_OS2::Start(const char * const *parm)
    00073 {
    00074   return 0;
    00075 }
    00076
    00077 void MusicDriver_OS2::Stop()
    00078 {
    00079   MidiSendCommand("close all");
    00080 }