Debian Codegraph @

src/gui/midi_win32.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2002-2010 The DOSBox Team
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 /* $Id: midi_win32.h,v 1.16 2009-05-27 09:15:41 qbix79 Exp $ */
20
21 #ifndef WIN32_LEAN_AND_MEAN
22 #define WIN32_LEAN_AND_MEAN
23 #endif
24 #include <windows.h>
25 #include <mmsystem.h>
26 #include <string>
27 #include <sstream>
28
29 class MidiHandler_win32: public MidiHandler {
30 private:
31 HMIDIOUT m_out;
32 MIDIHDR m_hdr;
33 HANDLE m_event;
34 bool isOpen;
35 public:
36 MidiHandler_win32() : MidiHandler(),isOpen(false) {};
37 const char * GetName(void) { return "win32";};
38 bool Open(const char * conf) {
39 if (isOpen) return false;
40 m_event = CreateEvent (NULL, true, true, NULL);
41 MMRESULT res = MMSYSERR_NOERROR;
42 if(conf && *conf) {
43 std::string strconf(conf);
44 std::istringstream configmidi(strconf);
45 unsigned int nummer = midiOutGetNumDevs();
46 configmidi >> nummer;
47 if(nummer < midiOutGetNumDevs()){
48 MIDIOUTCAPS mididev;
49 midiOutGetDevCaps(nummer, &mididev, sizeof(MIDIOUTCAPS));
50 LOG_MSG("MIDI:win32 selected %s",mididev.szPname);
51 res = midiOutOpen(&m_out, nummer, (DWORD)m_event, 0, CALLBACK_EVENT);
52 }
53 } else {
54 res = midiOutOpen(&m_out, MIDI_MAPPER, (DWORD)m_event, 0, CALLBACK_EVENT);
55 }
56 if (res != MMSYSERR_NOERROR) return false;
57 isOpen=true;
58 return true;
59 };
60
61 void Close(void) {
62 if (!isOpen) return;
63 isOpen=false;
64 midiOutClose(m_out);
65 CloseHandle (m_event);
66 };
67 void PlayMsg(Bit8u * msg) {
68 midiOutShortMsg(m_out, *(Bit32u*)msg);
69 };
70 void PlaySysex(Bit8u * sysex,Bitu len) {
71 if (WaitForSingleObject (m_event, 2000) == WAIT_TIMEOUT) {
72 LOG(LOG_MISC,LOG_ERROR)("Can't send midi message");
73 return;
74 }
75 midiOutUnprepareHeader (m_out, &m_hdr, sizeof (m_hdr));
76
77 m_hdr.lpData = (char *) sysex;
78 m_hdr.dwBufferLength = len ;
79 m_hdr.dwBytesRecorded = len ;
80 m_hdr.dwUser = 0;
81
82 MMRESULT result = midiOutPrepareHeader (m_out, &m_hdr, sizeof (m_hdr));
83 if (result != MMSYSERR_NOERROR) return;
84 ResetEvent (m_event);
85 result = midiOutLongMsg (m_out,&m_hdr,sizeof(m_hdr));
86 if (result != MMSYSERR_NOERROR) {
87 SetEvent (m_event);
88 return;
89 }
90 }
91 };
92
93 MidiHandler_win32 Midi_win32;
94
95