예제 #1
0
void CDMManager::RemoveSegment(long handle)
{
	
	if (m_Segments.find(handle) != m_Segments.end())
	{
		IDirectMusicSegment8* pSegment = m_Segments.find(handle)->second;
		HRESULT hr = pSegment->Unload(m_pPerformance);
		RELEASE(pSegment);
	}
	m_Segments.erase(handle);
}
예제 #2
0
//-----------------------------------------------------------------------------
// Name: CMusicManager::Create3DSegmentFromFile()
// Desc: 
//-----------------------------------------------------------------------------
HRESULT CMusicManager::Create3DSegmentFromFile( C3DMusicSegment** pp3DMusicSegment, 
                                                TCHAR* strFileName, 
                                                BOOL bDownloadNow,
                                                BOOL bIsMidiFile,
                                                IDirectMusicAudioPath8* p3DAudioPath )
{
    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( TEXT("LoadObjectFromFile"), hr );
    }

	if( *pp3DMusicSegment != NULL ) SAFE_DELETE(*pp3DMusicSegment);
    *pp3DMusicSegment = new C3DMusicSegment( m_pPerformance, m_pLoader, pSegment, p3DAudioPath );


    if (!*pp3DMusicSegment)
        return E_OUTOFMEMORY;

    if( FAILED( hr = (*pp3DMusicSegment)->Init() ) ) 
        return DXTRACE_ERR( TEXT("SetParam"), hr );

    if( bIsMidiFile )
    {
        if( FAILED( hr = pSegment->SetParam( GUID_StandardMIDIFile, 
                                             0xFFFFFFFF, 0, 0, NULL ) ) )
            return DXTRACE_ERR( TEXT("SetParam"), hr );
    }

    if( bDownloadNow )
    {
        if( FAILED( hr = (*pp3DMusicSegment)->Download() ) )
            return DXTRACE_ERR( TEXT("Download"), hr );
    }

    return S_OK;
}
예제 #3
0
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;
}
예제 #4
0
파일: dmutil.cpp 프로젝트: widmoser/lotus
//-----------------------------------------------------------------------------
// Name: CMusicManager::CreateSegmentFromResource()
// Desc: 
//-----------------------------------------------------------------------------
HRESULT CMusicManager::CreateSegmentFromResource( CMusicSegment** ppSegment, 
                                                  TCHAR* strResource,
                                                  TCHAR* strResourceType,
                                                  BOOL bDownloadNow,
                                                  BOOL bIsMidiFile )
{
    HRESULT               hr;
    IDirectMusicSegment8* pSegment      = NULL;
    HRSRC                 hres          = NULL;
    void*                 pMem          = NULL;
    DWORD                 dwSize        = 0;
    DMUS_OBJECTDESC       objdesc;

    // Find the resource
    hres = FindResource( NULL,strResource,strResourceType );
    if( NULL == hres ) 
        return E_FAIL;

    // Load the resource
    pMem = (void*)LoadResource( NULL, hres );
    if( NULL == pMem ) 
        return E_FAIL;

    // Store the size of the resource
    dwSize = SizeofResource( NULL, hres ); 
    
    // Set up our object description 
    ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
    objdesc.dwSize = sizeof(DMUS_OBJECTDESC);
    objdesc.dwValidData = DMUS_OBJ_MEMORY | DMUS_OBJ_CLASS;
    objdesc.guidClass = CLSID_DirectMusicSegment;
    objdesc.llMemLength =(LONGLONG)dwSize;
    objdesc.pbMemData = (BYTE*)pMem;
    
    if (FAILED ( hr = m_pLoader->GetObject( &objdesc,
                                            IID_IDirectMusicSegment8,
                                            (void**)&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( NULL == *ppSegment )
        return E_OUTOFMEMORY;

    if( bIsMidiFile )
    {
        // Do this to make sure that the default General MIDI set 
        // is connected appropriately to the MIDI file and 
        // all instruments sound correct.                  
        if( FAILED( hr = pSegment->SetParam( GUID_StandardMIDIFile, 
                                             0xFFFFFFFF, 0, 0, NULL ) ) )
            return DXTRACE_ERR_MSGBOX( TEXT("SetParam"), hr );
    }

    if( bDownloadNow )
    {
        // The segment needs to be download first before playing.  
        // However, some apps may want to wait before calling this 
        // to because the download allocates memory for the 
        // instruments. The more instruments currently downloaded, 
        // the more memory is in use by the synthesizer.
        if( FAILED( hr = (*ppSegment)->Download() ) )
            return DXTRACE_ERR_MSGBOX( TEXT("Download"), hr );
    }

    return S_OK;
}
예제 #5
0
파일: sound.cpp 프로젝트: viscuit/viscuit6
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;
}
예제 #6
0
파일: dmutil.cpp 프로젝트: gthgame/gth
HRESULT CMusicManager::CreateSegmentFromResource( CMusicSegment** ppSegment, 
                                                  TCHAR* strResource,
                                                  TCHAR* strResourceType,
                                                  BOOL bDownloadNow,
                                                  BOOL bIsMidiFile )
{
    HRESULT               hr;
    IDirectMusicSegment8* pSegment      = NULL;
    HRSRC                 hres          = NULL;
    void*                 pMem          = NULL;
    DWORD                 dwSize        = 0;
    DMUS_OBJECTDESC       objdesc;

    
    hres = FindResource( NULL,strResource,strResourceType );
    if( NULL == hres ) 
        return E_FAIL;

    
    pMem = (void*)LoadResource( NULL, hres );
    if( NULL == pMem ) 
        return E_FAIL;

    
    dwSize = SizeofResource( NULL, hres ); 
    
    
    ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
    objdesc.dwSize = sizeof(DMUS_OBJECTDESC);
    objdesc.dwValidData = DMUS_OBJ_MEMORY | DMUS_OBJ_CLASS;
    objdesc.guidClass = CLSID_DirectMusicSegment;
    objdesc.llMemLength =(LONGLONG)dwSize;
    objdesc.pbMemData = (BYTE*)pMem;
    
    if (FAILED ( hr = m_pLoader->GetObject( &objdesc,
                                            IID_IDirectMusicSegment8,
                                            (void**)&pSegment ) ) )
    {
        if( hr == DMUS_E_LOADER_FAILEDOPEN )
            return hr;
        return DXTRACE_ERR( TEXT("LoadObjectFromFile"), hr );
    }

    *ppSegment = new CMusicSegment( m_pPerformance, m_pLoader, pSegment );
    if( NULL == *ppSegment )
        return E_OUTOFMEMORY;

    if( bIsMidiFile )
    {
        
        
        
        if( FAILED( hr = pSegment->SetParam( GUID_StandardMIDIFile, 
                                             0xFFFFFFFF, 0, 0, NULL ) ) )
            return DXTRACE_ERR( TEXT("SetParam"), hr );
    }

    if( bDownloadNow )
    {
        
        
        
        
        
        if( FAILED( hr = (*ppSegment)->Download() ) )
            return DXTRACE_ERR( TEXT("Download"), hr );
    }

    return S_OK;
}