Feature: Purchase land multiple tiles at a time
[openttd-github.git] / src / music / os2_m.cpp
blob4736065678e3b7b6b83234cab41b730de5e6621b
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 */
8 /** @file os2_m.cpp Music playback on OS/2. */
10 #include "../stdafx.h"
11 #include "../openttd.h"
12 #include "os2_m.h"
13 #include "midifile.hpp"
14 #include "../base_media_base.h"
16 #define INCL_DOS
17 #define INCL_OS2MM
18 #define INCL_WIN
20 #include <stdarg.h>
21 #include <os2.h>
22 #include <os2me.h>
24 #include "../safeguards.h"
26 /**********************
27 * OS/2 MIDI PLAYER
28 **********************/
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! ;)
34 /**
35 * Send a midi command.
36 * @param cmd The command to send.
37 * @return The result of sending it.
39 static long CDECL MidiSendCommand(const char *cmd, ...)
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);
49 /** OS/2's music player's factory. */
50 static FMusicDriver_OS2 iFMusicDriver_OS2;
52 void MusicDriver_OS2::PlaySong(const MusicSongInfo &song)
54 std::string filename = MidiFile::GetSMFFile(song);
56 MidiSendCommand("close all");
57 if (filename.empty()) return;
59 if (MidiSendCommand("open %s type sequencer alias song", filename.c_str()) != 0) {
60 return;
63 MidiSendCommand("play song from 0");
66 void MusicDriver_OS2::StopSong()
68 MidiSendCommand("close all");
71 void MusicDriver_OS2::SetVolume(byte vol)
73 MidiSendCommand("set song audio volume %d", ((vol/127)*100));
76 bool MusicDriver_OS2::IsSongPlaying()
78 char buf[16];
79 mciSendString("status song mode", buf, sizeof(buf), nullptr, 0);
80 return strcmp(buf, "playing") == 0 || strcmp(buf, "seeking") == 0;
83 const char *MusicDriver_OS2::Start(const StringList &parm)
85 return 0;
88 void MusicDriver_OS2::Stop()
90 MidiSendCommand("close all");