Simple Mixer Control Wrapper

This is small and useful C++ class which can encapsulate any windows multimedia mixer control.

I wrote a simple class CAlexfMixer to wrap any multimedia mixer control. You can manipulate the Master Volume, Mute or someone elses mixer control with this class, as long as the control support these operations. You can also retrieve information such as the Peak Meter.

Let's look at class definition:

class CAlexfMixer
{
protected:
  HMIXER m_HMixer;
  INT m_iMixerControlID;
  MMRESULT mmr;
  DWORD m_dwChannels;
  BOOL m_bSuccess;
  void ZeroAll();
public:
  BOOL IsOk() {return m_bSuccess;};
  BOOL On();
  BOOL Off();
  DWORD GetControlValue();
  BOOL SetControlValue(DWORD dw);
  CAlexfMixer(DWORD DstType, DWORD SrcType, DWORD ControlType);
  CAlexfMixer(HWND hwnd, DWORD DstType, DWORD SrcType, DWORD ControlType);
  virtual ~CAlexfMixer();
};

The class has two constructors - with and without the callback window.

The class has member IsOk to check whether the specified control can be manipulated, and member functions to get and set the control's state.

How it works

Example 1. Master Volume Control.

 

CAlexfMixer mixer(m_hWnd, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,
                  NO_SOURCE, MIXERCONTROL_CONTROLTYPE_VOLUME);
if (!mixer.IsOk())
   return;

mixer.SetControlValue(500);

 

First we create an object associated with the Master Volume meter control. The third parameter NO_SOURCE is a constant defined in the header file. It means that the control does not have a source line, only a destination line.

Second we check if is this type of control available or not.

Finally, we set the volume to 500.

Example 2. Master Mute.

Collapse Copy Code
CAlexfMixer mixer(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,
                  NO_SOURCE, MIXERCONTROL_CONTROLTYPE_MUTE );
mixer.Off();

Here we create an object associated with Master Mute control, and turn it off.

From: http://www.codeproject.com/KB/audio-video/alexfmixer.aspx

你可能感兴趣的:(Simple Mixer Control Wrapper)