//----------------------------------------------------------------------------- // Name: CMusicManager::CreateSegmentFromFile() // Desc: //----------------------------------------------------------------------------- HRESULT CMusicManager::CreateSegmentFromFile( CMusicSegment** ppSegment, TCHAR* strFileName, BOOL bDownloadNow, BOOL bIsMidiFile ) { HRESULT hr; IDirectMusicSegment8* pSegment = NULL; // DMusic only takes wide strings WCHAR wstrFileName[MAX_PATH]; DXUtil_ConvertGenericStringToWideCb( wstrFileName, strFileName, sizeof(wstrFileName) ); if ( FAILED( hr = m_pLoader->LoadObjectFromFile( CLSID_DirectMusicSegment, IID_IDirectMusicSegment8, wstrFileName, (LPVOID*) &pSegment ) ) ) { if( hr == DMUS_E_LOADER_FAILEDOPEN ) return hr; return DXTRACE_ERR_MSGBOX( TEXT("LoadObjectFromFile"), hr ); } *ppSegment = new CMusicSegment( m_pPerformance, m_pLoader, pSegment ); if (!*ppSegment) return E_OUTOFMEMORY; if( bIsMidiFile ) { if( FAILED( hr = pSegment->SetParam( GUID_StandardMIDIFile, 0xFFFFFFFF, 0, 0, NULL ) ) ) return DXTRACE_ERR_MSGBOX( TEXT("SetParam"), hr ); //g_lpSegment->Download( g_lpPerformance ); pSegment->Download(m_pLoader); } if( bDownloadNow ) { if( FAILED( hr = (*ppSegment)->Download() ) ) return DXTRACE_ERR_MSGBOX( TEXT("Download"), hr ); } return S_OK; }
void CDMManager::CreateWaveSegment(long handle, const std::vector<unsigned char>& data) { std::vector<unsigned char> wav =data; CVFSStream stream(wav); DMUS_OBJECTDESC dmod; memset(&dmod, 0, sizeof(dmod)); dmod.dwSize = sizeof(dmod); dmod.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_STREAM; dmod.pStream = &stream; dmod.guidClass = CLSID_DirectMusicSegment; //wcscpy(dmod.wszFileName, L"1.wav"); IDirectMusicSegment8* pSegment = NULL; IDirectMusicSegmentState *pState = NULL; HRESULT hr = m_Loader.GetObject(&dmod, IID_IDirectMusicSegment8, (void**)&pSegment); if (SUCCEEDED(hr)) { hr = pSegment->Download(m_pPerformance); } m_Segments[handle] = pSegment; }
int soundPlay(QString fname) { #ifdef MIDI if (fname.right(4)==".mid") { { IDirectMusicInstrument *pDMInst; HRESULT hr; if( pDlInst != NULL ) { g_pOutPort->UnloadInstrument( pDlInst ); pDlInst->Release(); pDlInst = NULL; } hr = pDLSCollection->GetInstrument( 0x55 , &pDMInst ); if( FAILED( hr ) ) return 1; hr = g_pOutPort->DownloadInstrument( pDMInst , &pDlInst , NULL , 0 ); if( FAILED( hr ) ) return 2; pDMInst->Release(); } dmc_OutShortMsg(0x000055c0,0); dmc_OutShortMsg(0x007f3090,0); Sleep(1000); dmc_OutShortMsg(0x007f3080,1000000); return 0; } #endif IDirectMusicSegment8 *segment; segment = gPtrDict->find(fname); if (!segment) { if (FAILED(g_pLoader->LoadObjectFromFile( CLSID_DirectMusicSegment, // Class identifier. IID_IDirectMusicSegment8, // ID of desired interface. (unsigned short *)fname.ucs2(), // Filename. (LPVOID*) &segment // Pointer that receives interface. ))){ qDebug("file not found %s", fname.ascii()); return 0; } // qDebug("file read %s", fname.ascii()); gPtrDict->insert(fname, segment); } else { // qDebug("file found %s", fname.ascii()); } segment->Download( g_pPerformance ); g_pPerformance->PlaySegmentEx( segment, // Segment to play. NULL, // Used for songs; not implemented. NULL, // For transitions. DMUS_SEGF_SECONDARY, // Flags. 0, // Start time; 0 is immediate. NULL, // Pointer that receives segment state. NULL, // Object to stop. NULL // Audiopath, if not default. ); return 1; }