From 5054b6b3de1026c54689241db7f816bd987dcbef Mon Sep 17 00:00:00 2001
From: Doug Coleman <doug.coleman@gmail.com>
Date: Fri, 26 Apr 2013 11:06:49 -0700
Subject: [PATCH] windows.winmm: Add binding to play mp3s.

---
 basis/windows/windows.factor     |  1 +
 basis/windows/winmm/authors.txt  |  1 +
 basis/windows/winmm/winmm.factor | 40 ++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+)
 create mode 100644 basis/windows/winmm/authors.txt
 create mode 100644 basis/windows/winmm/winmm.factor

diff --git a/basis/windows/windows.factor b/basis/windows/windows.factor
index 83a5689cb3..fff734b0ff 100644
--- a/basis/windows/windows.factor
+++ b/basis/windows/windows.factor
@@ -22,4 +22,5 @@ CONSTANT: MAX_UNICODE_PATH 32768
     { "ole32"       "ole32.dll"          stdcall }
     { "usp10"       "usp10.dll"          stdcall }
     { "psapi"       "psapi.dll"          stdcall }
+    { "winmm"       "winmm.dll"          stdcall }
 } [ first3 add-library ] each
diff --git a/basis/windows/winmm/authors.txt b/basis/windows/winmm/authors.txt
new file mode 100644
index 0000000000..7c1b2f2279
--- /dev/null
+++ b/basis/windows/winmm/authors.txt
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/basis/windows/winmm/winmm.factor b/basis/windows/winmm/winmm.factor
new file mode 100644
index 0000000000..29908c7dc6
--- /dev/null
+++ b/basis/windows/winmm/winmm.factor
@@ -0,0 +1,40 @@
+! Copyright (C) 2013 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: alien.c-types alien.syntax byte-arrays formatting kernel
+math windows.types ;
+IN: windows.winmm
+
+LIBRARY: winmm
+
+TYPEDEF: int MCIERROR
+
+FUNCTION: MCIERROR mciSendStringW (
+  LPCTSTR lpszCommand,
+  LPTSTR lpszReturnString,
+  UINT cchReturn,
+  HANDLE hwndCallback
+) ;
+
+ALIAS: mciSendString mciSendStringW
+
+ERROR: mci-error n ;
+
+: check-mci-error ( n -- )
+    [ mci-error ] unless-zero ;
+
+: open-command ( path -- )
+    "open \"%s\" type mpegvideo alias MediaFile" sprintf f 0 f
+    mciSendString check-mci-error ;
+    
+: play-command ( -- )
+    "play MediaFile" f 0 f mciSendString check-mci-error ;
+
+: pause-command ( -- )
+    "pause MediaFile" f 0 f mciSendString check-mci-error ;
+
+: status-command ( -- bytes )
+    "status MediaFile mode" 128 <byte-array> [ 0 f mciSendString check-mci-error ] keep ;
+
+
+: close-command ( -- )
+    "close MediaFile" f 0 f mciSendString check-mci-error ;
\ No newline at end of file