# os2_m.cpp

Go to the documentation of this file.

    00001 /* $Id: os2_m.cpp 14542 2008-10-28 16:04:41Z rubidium $ */
    00002
    00005 #include "../stdafx.h"
    00006 #include "../openttd.h"
    00007 #include "os2_m.h"
    00008
    00009 #define INCL_DOS
    00010 #define INCL_OS2MM
    00011 #define INCL_WIN
    00012
    00013 #include <stdarg.h>
    00014 #include <os2.h>
    00015 #include <os2me.h>
    00016
    00017 /**********************
    00018  * OS/2 MIDI PLAYER
    00019  **********************/
    00020
    00021 /* Interesting how similar the MCI API in OS/2 is to the Win32 MCI API,
    00022  * eh? Anyone would think they both came from the same place originally! ;)
    00023  */
    00024
    00025 static long CDECL MidiSendCommand(const char *cmd, ...)
    00026 {
    00027   va_list va;
    00028   char buf[512];
    00029   va_start(va, cmd);
    00030   vseprintf(buf, lastof(buf), cmd, va);
    00031   va_end(va);
    00032   return mciSendString(buf, NULL, 0, NULL, 0);
    00033 }
    00034
    00035 static FMusicDriver_OS2 iFMusicDriver_OS2;
    00036
    00037 void MusicDriver_OS2::PlaySong(const char *filename)
    00038 {
    00039   MidiSendCommand("close all");
    00040
    00041   if (MidiSendCommand("open %s type sequencer alias song", filename) != 0)
    00042     return;
    00043
    00044   MidiSendCommand("play song from 0");
    00045 }
    00046
    00047 void MusicDriver_OS2::StopSong()
    00048 {
    00049   MidiSendCommand("close all");
    00050 }
    00051
    00052 void MusicDriver_OS2::SetVolume(byte vol)
    00053 {
    00054   MidiSendCommand("set song audio volume %d", ((vol/127)*100));
    00055 }
    00056
    00057 bool MusicDriver_OS2::IsSongPlaying()
    00058 {
    00059   char buf[16];
    00060   mciSendString("status song mode", buf, sizeof(buf), NULL, 0);
    00061   return strcmp(buf, "playing") == 0 || strcmp(buf, "seeking") == 0;
    00062 }
    00063
    00064 const char *MusicDriver_OS2::Start(const char * const *parm)
    00065 {
    00066   return 0;
    00067 }
    00068
    00069 void MusicDriver_OS2::Stop()
    00070 {
    00071   MidiSendCommand("close all");
    00072 }