CP_COMPOSITEFILE CF_Create_FromResource(HMODULE hModule, UINT uiResourceID, const char* pcResourceType) { CPs_CompositeContext* pContext; HRSRC hResource; HGLOBAL hResourceData; // Lock resource hResource = FindResource(hModule, MAKEINTRESOURCE(uiResourceID), pcResourceType); CP_ASSERT(hResource); hResourceData = LoadResource(hModule, hResource); CP_ASSERT(hResourceData); // Form a memory mapped file from the source pContext = (CPs_CompositeContext*)malloc(sizeof(CPs_CompositeContext)); pContext->m_dwFileSize = SizeofResource(hModule, hResource); pContext->m_hFileMapping = NULL; pContext->m_pFileBase = LockResource(hResourceData); // Form a directory over memory if (CP_BuildDirectory(pContext) == FALSE) { CF_Destroy(pContext); return NULL; } // Success return pContext; }
void CircleBufferWrite(CPs_CircleBuffer* pCBuffer, const void* _pSourceBuffer, const unsigned int _iNumBytes) { unsigned int iBytesToWrite = _iNumBytes; BYTE* pReadCursor = (BYTE*)_pSourceBuffer; CP_ASSERT(iBytesToWrite <= pCBuffer->GetFreeSize(pCBuffer)); CP_ASSERT(pCBuffer->m_bComplete == FALSE); EnterCriticalSection(&pCBuffer->m_csCircleBuffer); // We *know* there is enough space in the buffer for this // entire stream - write all the data until the end of the block if (pCBuffer->m_iWriteCursor >= pCBuffer->m_iReadCursor) { // Determine how much data we can fit into the end part of the CBuffer unsigned int iChunkSize = pCBuffer->m_iBufferSize - pCBuffer->m_iWriteCursor; if (iChunkSize > iBytesToWrite) iChunkSize = iBytesToWrite; // Copy the data memcpy(pCBuffer->m_pBuffer + pCBuffer->m_iWriteCursor, pReadCursor, iChunkSize); pReadCursor += iChunkSize; iBytesToWrite -= iChunkSize; // Update write cursor (wrapping if needed) pCBuffer->m_iWriteCursor += iChunkSize; if (pCBuffer->m_iWriteCursor >= pCBuffer->m_iBufferSize) pCBuffer->m_iWriteCursor -= pCBuffer->m_iBufferSize; } // Fill the start part of the CBuffer with any data that may be left if (iBytesToWrite) { memcpy(pCBuffer->m_pBuffer + pCBuffer->m_iWriteCursor, pReadCursor, iBytesToWrite); pCBuffer->m_iWriteCursor += iBytesToWrite; CP_ASSERT(pCBuffer->m_iWriteCursor < pCBuffer->m_iBufferSize); } SetEvent(pCBuffer->m_evtDataAvailable); LeaveCriticalSection(&pCBuffer->m_csCircleBuffer); }
void IF_PostAppMessage(CP_HINTERFACE hInterface, const UINT uiMessage, const WPARAM wParam, const LPARAM lParam) { CPs_InterfaceWindowState* pState; // Init pState = (CPs_InterfaceWindowState*)hInterface; CP_CHECKOBJECT(pState); CP_ASSERT(uiMessage >= WM_APP); PostMessage(pState->m_hWnd, uiMessage, wParam, lParam); }
void CPP_OMFL_Flush(CPs_OutputModule* pModule) { #ifdef _DEBUG CPs_OutputContext_File* pContext = (CPs_OutputContext_File*)pModule->m_pModuleCookie; CP_CHECKOBJECT(pContext); // Stop any pending playing CP_ASSERT(CPP_OMFL_IsOutputComplete(pModule)); #endif }
void CPP_OMFL_Initialise(CPs_OutputModule* pModule, const CPs_FileInfo* pFileInfo, CP_HEQUALISER hEqualiser) { // This is called when some playing is required. // Do all allocation here so that we do not hold // resources while we are just sitting waiting for // something to happen. // Create a context CPs_OutputContext_File* pContext; CP_ASSERT(pModule->m_pModuleCookie == NULL); pContext = (CPs_OutputContext_File*)malloc(sizeof(CPs_OutputContext_File)); pModule->m_pModuleCookie = pContext; CP_TRACE0("File out initialising"); // Create sync object pModule->m_evtBlockFree = CreateEvent(NULL, FALSE, FALSE, NULL); // Setup thread prioity to lowest SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL); pModule->m_pEqualiser = hEqualiser; pContext->m_bPaused = FALSE; pContext->m_hFile = NULL; }
void IF_UpdateSubPartLayout(CP_HINTERFACE hInterface) { CPs_InterfaceWindowState* pState; CPs_InterfacePart* pSubPart_Cursor; // Init pState = (CPs_InterfaceWindowState*)hInterface; CP_CHECKOBJECT(pState); // Walk through list setting position for (pSubPart_Cursor = pState->m_pFirstSubPart; pSubPart_Cursor; pSubPart_Cursor = (CPs_InterfacePart*)pSubPart_Cursor->m_hNext) { if (pSubPart_Cursor->m_bRectAlignMode == TRUE) { // Set position // - left if (pSubPart_Cursor->m_dwAlign & CPC_COMMANDTARGET_ALIGN_LEFT) pSubPart_Cursor->m_rLocation.left = pSubPart_Cursor->m_rPosition.left; else { CP_ASSERT(pSubPart_Cursor->m_dwAlign & CPC_COMMANDTARGET_ALIGN_RIGHT); pSubPart_Cursor->m_rLocation.left = pState->m_szWindowSize.cx - pSubPart_Cursor->m_rPosition.right - pSubPart_Cursor->m_rPosition.left; } // - right if (pSubPart_Cursor->m_dwAlign & CPC_COMMANDTARGET_ALIGN_RIGHT) pSubPart_Cursor->m_rLocation.right = pState->m_szWindowSize.cx - pSubPart_Cursor->m_rPosition.right; else { CP_ASSERT(pSubPart_Cursor->m_dwAlign & CPC_COMMANDTARGET_ALIGN_LEFT); pSubPart_Cursor->m_rLocation.right = pSubPart_Cursor->m_rLocation.left + pSubPart_Cursor->m_rPosition.right; } // - top if (pSubPart_Cursor->m_dwAlign & CPC_COMMANDTARGET_ALIGN_TOP) pSubPart_Cursor->m_rLocation.top = pSubPart_Cursor->m_rPosition.top; else { // CP_ASSERT(pSubPart_Cursor->m_dwAlign & CPC_COMMANDTARGET_ALIGN_BOTTOM); pSubPart_Cursor->m_rLocation.top = pState->m_szWindowSize.cy - pSubPart_Cursor->m_rPosition.bottom - pSubPart_Cursor->m_rPosition.top; } // - bottom if (pSubPart_Cursor->m_dwAlign & CPC_COMMANDTARGET_ALIGN_BOTTOM) pSubPart_Cursor->m_rLocation.bottom = pState->m_szWindowSize.cy - pSubPart_Cursor->m_rPosition.bottom; else { // CP_ASSERT(pSubPart_Cursor->m_dwAlign & CPC_COMMANDTARGET_ALIGN_TOP); pSubPart_Cursor->m_rLocation.bottom = pSubPart_Cursor->m_rLocation.top + pSubPart_Cursor->m_rPosition.bottom; } } else { // Set position if (pSubPart_Cursor->m_dwAlign & CPC_COMMANDTARGET_ALIGN_LEFT) pSubPart_Cursor->m_rLocation.left = pSubPart_Cursor->m_ptOffset.x; else { CP_ASSERT(pSubPart_Cursor->m_dwAlign & CPC_COMMANDTARGET_ALIGN_RIGHT); pSubPart_Cursor->m_rLocation.left = pState->m_szWindowSize.cx - pSubPart_Cursor->m_szSize.cx - pSubPart_Cursor->m_ptOffset.x; } pSubPart_Cursor->m_rLocation.right = pSubPart_Cursor->m_rLocation.left + pSubPart_Cursor->m_szSize.cx; if (pSubPart_Cursor->m_dwAlign & CPC_COMMANDTARGET_ALIGN_TOP) pSubPart_Cursor->m_rLocation.top = pSubPart_Cursor->m_ptOffset.y; else { CP_ASSERT(pSubPart_Cursor->m_dwAlign & CPC_COMMANDTARGET_ALIGN_BOTTOM); pSubPart_Cursor->m_rLocation.top = pState->m_szWindowSize.cy - pSubPart_Cursor->m_szSize.cy - pSubPart_Cursor->m_ptOffset.y; } pSubPart_Cursor->m_rLocation.bottom = pSubPart_Cursor->m_rLocation.top + pSubPart_Cursor->m_szSize.cy; } } }