OpenTTD: src/music/os2_m.cpp Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

os2_m.cpp
Go to the documentation of this file.
1 /* $Id: os2_m.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
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
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, NULL, 0, NULL, 0);
47 }
48
50 static FMusicDriver_OS2 iFMusicDriver_OS2;
51
52 void MusicDriver_OS2::PlaySong(const char *filename)
53 {
54 MidiSendCommand("close all");
55
56 if (MidiSendCommand("open %s type sequencer alias song", filename) != 0) {
57 return;
58 }
59
60 MidiSendCommand("play song from 0");
61 }
62
63 void MusicDriver_OS2::StopSong()
64 {
65 MidiSendCommand("close all");
66 }
67
68 void MusicDriver_OS2::SetVolume(byte vol)
69 {
70 MidiSendCommand("set song audio volume %d", ((vol/127)*100));
71 }
72
73 bool MusicDriver_OS2::IsSongPlaying()
74 {
75 char buf[16];
76 mciSendString("status song mode", buf, sizeof(buf), NULL, 0);
77 return strcmp(buf, "playing") == 0 || strcmp(buf, "seeking") == 0;
78 }
79
80 const char *MusicDriver_OS2::Start(const char * const *parm)
81 {
82 return 0;
83 }
84
85 void MusicDriver_OS2::Stop()
86 {
87 MidiSendCommand("close all");
88 }