![]() |
| [[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]] |
|
|
#1 |
|
New Member
Join Date: Oct 2004
Posts: 3
|
hello!
any DirectMusic and MIDI experts out there? im having trouble with changing a MIDI file's program/patch number using a DirectMusic tool. Here's the code for the tool: HRESULT STDMETHODCALLTYPE ProgramChangeTool::ProcessPMsg( IDirectMusicPerformance* pPerf, DMUS_PMSG* pDMUS_PMSG ) { if (pDMUS_PMSG->dwType == DMUS_PMSGT_PATCH) { if(( NULL == pDMUS_PMSG->pGraph ) || FAILED(pDMUS_PMSG->pGraph->StampPMsg(pDMUS_PMSG))) { return DMUS_S_FREE; } DMUS_PATCH_PMSG* pMsgNote = (DMUS_PATCH_PMSG*) pDMUS_PMSG; pMsgNote->byInstrument = 0x1D; //overdriven guitar pPerf->SendPMsg((DMUS_PMSG*)pMsgNote); } return S_OK; } HRESULT STDMETHODCALLTYPE ProgramChangeTool::Flush( IDirectMusicPerformance* pPerf, DMUS_PMSG* pDMUS_PMSG, REFERENCE_TIME rt ) { return S_OK; } ProgramChangeTool::ProgramChangeTool() { m_cRef = 1; m_boolToolOn= false; } ProgramChangeTool::~ProgramChangeTool() { } STDMETHODIMP ProgramChangeTool::QueryInterface(const IID &iid, void **ppv) { if (iid == IID_IUnknown || iid == IID_IDirectMusicTool) { *ppv = static_cast<IDirectMusicTool*>(this); } else { *ppv = NULL; return E_NOINTERFACE; } reinterpret_cast<IUnknown*>(this)->AddRef(); return S_OK; } STDMETHODIMP_(ULONG) ProgramChangeTool::AddRef() { return InterlockedIncrement(&m_cRef); } STDMETHODIMP_(ULONG) ProgramChangeTool::Release() { if( 0 == InterlockedDecrement(&m_cRef) ) { delete this; return 0; } return m_cRef; } HRESULT STDMETHODCALLTYPE ProgramChangeTool::Init(IDirectMusicGraph *pGraph) { return S_OK; } HRESULT STDMETHODCALLTYPE ProgramChangeTool::GetMsgDeliveryType(DWORD* pdwDeliveryType) { *pdwDeliveryType = DMUS_PMSGF_TOOL_IMMEDIATE; return S_OK; } HRESULT STDMETHODCALLTYPE ProgramChangeTool::GetMediaTypeArraySize( DWORD* pdwNumElements ) { *pdwNumElements = 1; return S_OK; } HRESULT STDMETHODCALLTYPE ProgramChangeTool::GetMediaTypes( DWORD** padwMediaTypes, DWORD dwNumElements) { (*padwMediaTypes)[0] = DMUS_PMSGT_PATCH; return S_OK; } Below is the code for inserting the tool into the graph: m_pProgChangeTool = new ProgramChangeTool(); IDirectMusicGraph* pGraph; IDirectMusicAudioPath8* pDefaultAudioPath; m_pPerformance->GetDefaultAudioPath(&pDefaultAudioPath); HRESULT hr = pDefaultAudioPath->GetObjectInPath( 0, DMUS_PATH_PERFORMANCE_GRAPH, 0,GUID_NULL, 0, IID_IDirectMusicGraph, (LPVOID*) &pGraph ); pGraph->InsertTool(m_pProgChangeTool, NULL, 0, 0); pGraph->Release(); So what the tool basically does is to just intercept patch messages and then change the instrument number into 0x1D for an overdriven guitar. This worked on some MIDIs (try c:\winnt\media\canyon.mid if it exists) but not for all (try c:\winnt\media\passport.mid if it exists). I also have a short plain and simple sample midi (plays a few notes using acoustic guitar (nylon) instrument) that simply gets muted when the tool is applied. When the code doesn't work, it simply mutes the sound when played. What could be the reason for this? Is it because some notes on some instruments don't apply on other instruments? Or is there something wrong with my implementation? Is there other alternatives for changing the patch number of a channel programatically? Thanks for your help! |
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|