コード例 #1
0
 internal CustomMixerControl(MixerInterop.MIXERCONTROL mixerControl, IntPtr mixerHandle, MixerFlags mixerHandleType, int nChannels)
 {
     this.mixerControl        = mixerControl;
     this.mixerHandle         = mixerHandle;
     this.mixerHandleType     = mixerHandleType;
     this.nChannels           = nChannels;
     this.mixerControlDetails = new MixerInterop.MIXERCONTROLDETAILS();
     GetControlDetails();
 }
コード例 #2
0
        /// <summary>
        /// Gets a specified Mixer Control
        /// </summary>
        /// <param name="mixerHandle">Mixer Handle</param>
        /// <param name="nLineID">Line ID</param>
        /// <param name="controlId">Control ID</param>
        /// <param name="nChannels">Number of Channels</param>
        /// <param name="mixerFlags">Flags to use (indicates the meaning of mixerHandle)</param>
        /// <returns></returns>
        public static MixerControl GetMixerControl(IntPtr mixerHandle, int nLineID, int controlId, int nChannels,
                                                   MixerFlags mixerFlags)
        {
            MixerInterop.MIXERLINECONTROLS mlc = new MixerInterop.MIXERLINECONTROLS();
            MixerInterop.MIXERCONTROL      mc  = new MixerInterop.MIXERCONTROL();

            // set up the pointer to a structure
            IntPtr pMixerControl = Marshal.AllocCoTaskMem(Marshal.SizeOf(mc));

            //Marshal.StructureToPtr(mc, pMixerControl, false);

            mlc.cbStruct    = Marshal.SizeOf(mlc);
            mlc.cControls   = 1;
            mlc.dwControlID = controlId;
            mlc.cbmxctrl    = Marshal.SizeOf(mc);
            mlc.pamxctrl    = pMixerControl;
            mlc.dwLineID    = nLineID;
            MmResult err = MixerInterop.mixerGetLineControls(mixerHandle, ref mlc, MixerFlags.OneById | mixerFlags);

            if (err != MmResult.NoError)
            {
                Marshal.FreeCoTaskMem(pMixerControl);
                throw new MmException(err, "mixerGetLineControls");
            }

            // retrieve the structure from the pointer
            mc = (MixerInterop.MIXERCONTROL)Marshal.PtrToStructure(mlc.pamxctrl, typeof(MixerInterop.MIXERCONTROL));
            Marshal.FreeCoTaskMem(pMixerControl);

            if (MixerControl.IsControlBoolean(mc.dwControlType))
            {
                return(new BooleanMixerControl(mc, mixerHandle, mixerFlags, nChannels));
            }
            else if (MixerControl.IsControlSigned(mc.dwControlType))
            {
                return(new SignedMixerControl(mc, mixerHandle, mixerFlags, nChannels));
            }
            else if (MixerControl.IsControlUnsigned(mc.dwControlType))
            {
                return(new UnsignedMixerControl(mc, mixerHandle, mixerFlags, nChannels));
            }
            else if (MixerControl.IsControlListText(mc.dwControlType))
            {
                return(new ListTextMixerControl(mc, mixerHandle, mixerFlags, nChannels));
            }
            else if (MixerControl.IsControlCustom(mc.dwControlType))
            {
                return(new CustomMixerControl(mc, mixerHandle, mixerFlags, nChannels));
            }
            else
            {
                throw new InvalidOperationException(String.Format("Unknown mixer control type {0}", mc.dwControlType));
            }
        }