OpenTTD
os2_m.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #include "../stdafx.h"
13 #include "../openttd.h"
14 #include "os2_m.h"
15 #include "midifile.hpp"
16 #include "../base_media_base.h"
17 
18 #define INCL_DOS
19 #define INCL_OS2MM
20 #define INCL_WIN
21 
22 #include <stdarg.h>
23 #include <os2.h>
24 #include <os2me.h>
25 
26 #include "../safeguards.h"
27 
28 /**********************
29  * OS/2 MIDI PLAYER
30  **********************/
31 
32 /* Interesting how similar the MCI API in OS/2 is to the Win32 MCI API,
33  * eh? Anyone would think they both came from the same place originally! ;)
34  */
35 
41 static long CDECL MidiSendCommand(const char *cmd, ...)
42 {
43  va_list va;
44  char buf[512];
45  va_start(va, cmd);
46  vseprintf(buf, lastof(buf), cmd, va);
47  va_end(va);
48  return mciSendString(buf, NULL, 0, NULL, 0);
49 }
50 
53 
55 {
56  std::string filename = MidiFile::GetSMFFile(song);
57 
58  MidiSendCommand("close all");
59  if (filename.empty()) return;
60 
61  if (MidiSendCommand("open %s type sequencer alias song", filename.c_str()) != 0) {
62  return;
63  }
64 
65  MidiSendCommand("play song from 0");
66 }
67 
69 {
70  MidiSendCommand("close all");
71 }
72 
74 {
75  MidiSendCommand("set song audio volume %d", ((vol/127)*100));
76 }
77 
79 {
80  char buf[16];
81  mciSendString("status song mode", buf, sizeof(buf), NULL, 0);
82  return strcmp(buf, "playing") == 0 || strcmp(buf, "seeking") == 0;
83 }
84 
85 const char *MusicDriver_OS2::Start(const char * const *parm)
86 {
87  return 0;
88 }
89 
91 {
92  MidiSendCommand("close all");
93 }
Metadata about a music track.
Base for OS2 music playback.
int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap)
Safer implementation of vsnprintf; same as vsnprintf except:
Definition: string.cpp:62
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:50
Factory for OS/2&#39;s music player.
Definition: os2_m.h:35
bool IsSongPlaying()
Are we currently playing a song?
Definition: os2_m.cpp:78
const char * Start(const char *const *param)
Start this driver.
Definition: os2_m.cpp:85
static long CDECL MidiSendCommand(const char *cmd,...)
Send a midi command.
Definition: os2_m.cpp:41
void PlaySong(const MusicSongInfo &song)
Play a particular song.
Definition: os2_m.cpp:54
void Stop()
Stop this driver.
Definition: os2_m.cpp:90
static std::string GetSMFFile(const MusicSongInfo &song)
Get the name of a Standard MIDI File for a given song.
Definition: midifile.cpp:1041
void StopSong()
Stop playing the current song.
Definition: os2_m.cpp:68
void SetVolume(byte vol)
Set the volume, if possible.
Definition: os2_m.cpp:73
static FMusicDriver_OS2 iFMusicDriver_OS2
OS/2&#39;s music player&#39;s factory.
Definition: os2_m.cpp:52