DirectX SDK |
A port is a device that sends or receives musical data. It can correspond to a hardware device, a software synthesizer, or a software filter.
Each port in a DirectMusic application is represented by an IDirectMusicPort interface. Methods of this interface are used to retrieve information about the device, manage the memory on the device, download and unload DLS instruments, read incoming data, and cue playback buffers.
Every performance must have at least one port. If you want to use a port other than the default port to set up special parameters for the default port, first set up a DMUS_PORTPARAMS structure. You do not have to fill in all members, but you must let DirectMusic know which members have valid information by putting the appropriate flags in the dwValidParams member. Then, pass the structure to the IDirectMusic::CreatePort method.
The following C++ code example demonstrates how an object might be created for the default port, setting five channel groups on the port, assuming that pDirectMusic is a valid IDirectMusic pointer.
IDirectMusicPort* pPort; DMUS_PORTPARAMS dmos; ZeroMemory( &dmos, sizeof(DMUS_PORTPARAMS) ); dmos.dwSize = sizeof(DMUS_PORTPARAMS); dmos.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS; dmos.dwChannelGroups = 5; HRESULT hr = pDirectMusic->CreatePort( GUID_NULL, &dmos, &pPort, NULL )
Once you have a port, activate it by calling IDirectMusic::Activate or IDirectMusicPort::Activate and attach it to the performance by using the IDirectMusicPerformance::AddPort method.
When you add a port to a performance, assign a block of PChannels to it by calling the IDirectMusicPerformance::AssignPChannelBlock method. The only time this is not necessary is when you add the default port by passing NULL to IDirectMusicPerformance::AddPort. In that case, PChannels 0 through 15 are assigned to the MIDI channels in the first group on the port.
You can map PChannels differently, add more PChannels, or assign PChannels to a different port by using the IDirectMusicPerformance::AssignPChannelBlock and IDirectMusicPerformance::AssignPChannel methods.
DirectX for Visual Basic supports only a single port for each performance, and all PChannels are mapped to this port. Choose the port after initializing the performance by using DirectMusicPerformance.SetPort. To use the default port, pass –1 as the index parameter.
Available ports are automatically enumerated when you initialize the performance. You can look for a particular port or capabilities by using the DirectMusicPerformance.GetPortCount, DirectMusicPerformance.GetPortCaps, and DirectMusicPerformance.GetPortName methods. The following code example looks for the first software synthesizer and sets this as the port for the performance, with support for up to 16 channel groups:
' perf is a DirectMusicPerformance object. Dim X As Integer Dim portcaps As DMUS_PORTCAPS perf.Init(Nothing, Me.hWnd) For X = 1 to perf.GetPortCount Call perf.GetPortCaps(X, portcaps) If portcaps.lFlags And DMUS_PC_SOFTWARESYNTH Then perf.SetPort(X, 16) Exit For End If Next X ' If no port was set, set the default port, or take other action.
More information about ports is contained in the following topics: