OSDN Git Service

DTXMania089リリースに際してのtag付け。
[dtxmania/dtxmania.git] / 110401(DTXMania089) / SlimDXc_Jun2010(VC++2008) / source / xact3 / RuntimeParameters.cpp
1 /*\r
2 * Copyright (c) 2007-2010 SlimDX Group\r
3\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy\r
5 * of this software and associated documentation files (the "Software"), to deal\r
6 * in the Software without restriction, including without limitation the rights\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
8 * copies of the Software, and to permit persons to whom the Software is\r
9 * furnished to do so, subject to the following conditions:\r
10\r
11 * The above copyright notice and this permission notice shall be included in\r
12 * all copies or substantial portions of the Software.\r
13\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
20 * THE SOFTWARE.\r
21 */\r
22 #include "stdafx.h"\r
23 \r
24 #include "../DataStream.h"\r
25 \r
26 #include "RuntimeParameters.h"\r
27 \r
28 using namespace System;\r
29 \r
30 namespace SlimDX\r
31 {\r
32 namespace XACT3\r
33 {\r
34         XACT_RUNTIME_PARAMETERS RuntimeParameters::ToUnmanaged()\r
35         {\r
36                 XACT_RUNTIME_PARAMETERS results;\r
37                 memset(&results, 0, sizeof(XACT_RUNTIME_PARAMETERS));\r
38 \r
39                 try\r
40                 {\r
41                         results.lookAheadTime = LookAheadTime;\r
42 \r
43                         if (!String::IsNullOrEmpty(RendererId))\r
44                         {\r
45                                 pin_ptr<const wchar_t> pinnedId = PtrToStringChars(RendererId);\r
46                                 results.pRendererID = new WCHAR[RendererId->Length];\r
47                                 \r
48                                 memcpy(results.pRendererID, pinnedId, sizeof(wchar_t) * RendererId->Length);\r
49                         }\r
50 \r
51                         if (AudioDevice != nullptr)\r
52                                 results.pXAudio2 = AudioDevice->InternalPointer;\r
53                         if (MasteringVoice != nullptr)\r
54                                 results.pMasteringVoice = reinterpret_cast<IXAudio2MasteringVoice*>(MasteringVoice->InternalPointer);\r
55 \r
56                         if (SettingsBuffer != nullptr)\r
57                         {\r
58                                 int size = static_cast<int>(SettingsBuffer->Length - SettingsBuffer->Position);\r
59                                 results.pGlobalSettingsBuffer = CoTaskMemAlloc(size);\r
60                                 results.globalSettingsBufferSize = size;\r
61                                 results.globalSettingsFlags = XACT_FLAG_ENGINE_CREATE_MANAGEDATA;\r
62 \r
63                                 DataStream^ ds = dynamic_cast<DataStream^>(SettingsBuffer);\r
64                                 if (ds != nullptr)\r
65                                         memcpy(results.pGlobalSettingsBuffer, ds->PositionPointer, size);\r
66                                 else\r
67                                 {\r
68                                         array<Byte>^ buffer = gcnew array<Byte>(size); \r
69                                         int bytesRead = 0;\r
70                                         while (bytesRead < size)\r
71                                                 bytesRead += SettingsBuffer->Read(buffer, bytesRead, size - bytesRead);\r
72 \r
73                                         pin_ptr<Byte> pinnedBuffer = &buffer[0];\r
74                                         memcpy(results.pGlobalSettingsBuffer, pinnedBuffer, size);\r
75                                 }\r
76                         }\r
77                 }\r
78                 catch (...)\r
79                 {\r
80                         delete[] results.pRendererID;\r
81                         CoTaskMemFree(results.pGlobalSettingsBuffer);\r
82 \r
83                         throw;\r
84                 }\r
85 \r
86                 return results;\r
87         }\r
88 }\r
89 }