Christian Costa : dmusic: Implement IDirectMusicBufferImpl_PackStructured.

Alexandre Julliard julliard at winehq.org
Fri Apr 27 10:55:46 CDT 2012


Module: wine
Branch: master
Commit: fbd0aba73975d850c6677bd2ca55e7e9575ee064
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=fbd0aba73975d850c6677bd2ca55e7e9575ee064

Author: Christian Costa <titan.costa at gmail.com>
Date:   Thu Apr 26 08:08:34 2012 +0200

dmusic: Implement IDirectMusicBufferImpl_PackStructured.

---

 dlls/dmusic/buffer.c         |   26 ++++++++++++++++++++++++--
 dlls/dmusic/dmusic_private.h |    1 +
 dlls/dmusic/tests/dmusic.c   |    5 +++++
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/dlls/dmusic/buffer.c b/dlls/dmusic/buffer.c
index 0626276..fd1d217 100644
--- a/dlls/dmusic/buffer.c
+++ b/dlls/dmusic/buffer.c
@@ -96,11 +96,33 @@ static HRESULT WINAPI IDirectMusicBufferImpl_TotalTime(LPDIRECTMUSICBUFFER iface
     return S_OK;
 }
 
-static HRESULT WINAPI IDirectMusicBufferImpl_PackStructured(LPDIRECTMUSICBUFFER iface, REFERENCE_TIME rt, DWORD dwChannelGroup, DWORD dwChannelMessage)
+static HRESULT WINAPI IDirectMusicBufferImpl_PackStructured(LPDIRECTMUSICBUFFER iface, REFERENCE_TIME ref_time, DWORD channel_group, DWORD channel_message)
 {
     IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
+    DWORD new_write_pos = This->write_pos + sizeof(DMUS_EVENTHEADER) + sizeof(DWORD);
+    DMUS_EVENTHEADER header;
 
-    FIXME("(%p, 0x%s, %d, %d): stub\n", This, wine_dbgstr_longlong(rt), dwChannelGroup, dwChannelMessage);
+    TRACE("(%p)->(0x%s, %u, 0x%x)\n", iface, wine_dbgstr_longlong(ref_time), channel_group, channel_message);
+
+    if (new_write_pos > This->size)
+        return DMUS_E_BUFFER_FULL;
+
+    /* Channel_message 0xZZYYXX is a midi message where XX = status byte, YY = byte 1 and ZZ = byte 2 */
+
+    if (!(channel_message & 0x80))
+    {
+        /* Status byte MSB is always set */
+        return DMUS_E_INVALID_EVENT;
+    }
+
+    header.cbEvent = sizeof(channel_message);
+    header.dwChannelGroup = channel_group;
+    header.rtDelta = ref_time;
+    header.dwFlags = DMUS_EVENT_STRUCTURED;
+
+    memcpy(This->data + This->write_pos, &header, sizeof(header));
+    *(DWORD*)(This->data + This->write_pos + sizeof(header)) = channel_message;
+    This->write_pos = new_write_pos;
 
     return S_OK;
 }
diff --git a/dlls/dmusic/dmusic_private.h b/dlls/dmusic/dmusic_private.h
index 1001bf5..f4897ac 100644
--- a/dlls/dmusic/dmusic_private.h
+++ b/dlls/dmusic/dmusic_private.h
@@ -113,6 +113,7 @@ struct IDirectMusicBufferImpl {
     GUID format;
     DWORD size;
     LPBYTE data;
+    DWORD write_pos;
 };
 
 /*****************************************************************************
diff --git a/dlls/dmusic/tests/dmusic.c b/dlls/dmusic/tests/dmusic.c
index 21607cb..c6d4ad3 100644
--- a/dlls/dmusic/tests/dmusic.c
+++ b/dlls/dmusic/tests/dmusic.c
@@ -135,6 +135,11 @@ static void test_dmbuffer(void)
     ok(hr == S_OK, "IDirectMusicBuffer_GetMaxBytes returned %x\n", hr);
     ok(size == 1024, "Buffer size is %u instead of 1024\n", size);
 
+    hr = IDirectMusicBuffer_PackStructured(dmbuffer, 10, 0, 0);
+    ok(hr == DMUS_E_INVALID_EVENT, "IDirectMusicBuffer_PackStructured returned %x\n", hr);
+    hr = IDirectMusicBuffer_PackStructured(dmbuffer, 10, 0, 0x000090); /* note on : chan 0, note 0 & vel 0 */
+    ok(hr == S_OK, "IDirectMusicBuffer_PackStructured returned %x\n", hr);
+
     if (dmbuffer)
         IDirectMusicBuffer_Release(dmbuffer);
     IDirectMusic_Release(dmusic);




More information about the wine-cvs mailing list