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