Beispiel #1
0
        public static IList <MixerControl> GetMixerControls(IntPtr mixerHandle, MixerLine mixerLine, MixerFlags mixerHandleType)
        {
            List <MixerControl> list = new List <MixerControl>();

            if (mixerLine.ControlsCount > 0)
            {
                int num = Marshal.SizeOf(typeof(MixerInterop.MIXERCONTROL));
                MixerInterop.MIXERLINECONTROLS mIXERLINECONTROLS = default(MixerInterop.MIXERLINECONTROLS);
                IntPtr intPtr = Marshal.AllocHGlobal(num * mixerLine.ControlsCount);
                mIXERLINECONTROLS.cbStruct  = Marshal.SizeOf(mIXERLINECONTROLS);
                mIXERLINECONTROLS.dwLineID  = mixerLine.LineId;
                mIXERLINECONTROLS.cControls = mixerLine.ControlsCount;
                mIXERLINECONTROLS.pamxctrl  = intPtr;
                mIXERLINECONTROLS.cbmxctrl  = Marshal.SizeOf(typeof(MixerInterop.MIXERCONTROL));
                try
                {
                    MmResult mmResult = MixerInterop.mixerGetLineControls(mixerHandle, ref mIXERLINECONTROLS, MixerFlags.Mixer | mixerHandleType);
                    if (mmResult != MmResult.NoError)
                    {
                        throw new MmException(mmResult, "mixerGetLineControls");
                    }
                    for (int i = 0; i < mIXERLINECONTROLS.cControls; i++)
                    {
                        MixerInterop.MIXERCONTROL mIXERCONTROL = (MixerInterop.MIXERCONTROL)Marshal.PtrToStructure((IntPtr)(intPtr.ToInt64() + (long)(num * i)), typeof(MixerInterop.MIXERCONTROL));
                        MixerControl item = MixerControl.GetMixerControl(mixerHandle, mixerLine.LineId, mIXERCONTROL.dwControlID, mixerLine.Channels, mixerHandleType);
                        list.Add(item);
                    }
                }
                finally
                {
                    Marshal.FreeHGlobal(intPtr);
                }
            }
            return(list);
        }
Beispiel #2
0
        public static MixerControl GetMixerControl(IntPtr mixerHandle, int nLineID, int controlId, int nChannels, MixerFlags mixerFlags)
        {
            MixerInterop.MIXERLINECONTROLS mIXERLINECONTROLS = default(MixerInterop.MIXERLINECONTROLS);
            MixerInterop.MIXERCONTROL      mIXERCONTROL      = default(MixerInterop.MIXERCONTROL);
            IntPtr intPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(mIXERCONTROL));

            mIXERLINECONTROLS.cbStruct    = Marshal.SizeOf(mIXERLINECONTROLS);
            mIXERLINECONTROLS.cControls   = 1;
            mIXERLINECONTROLS.dwControlID = controlId;
            mIXERLINECONTROLS.cbmxctrl    = Marshal.SizeOf(mIXERCONTROL);
            mIXERLINECONTROLS.pamxctrl    = intPtr;
            mIXERLINECONTROLS.dwLineID    = nLineID;
            MmResult mmResult = MixerInterop.mixerGetLineControls(mixerHandle, ref mIXERLINECONTROLS, MixerFlags.ListText | mixerFlags);

            if (mmResult != MmResult.NoError)
            {
                Marshal.FreeCoTaskMem(intPtr);
                throw new MmException(mmResult, "mixerGetLineControls");
            }
            mIXERCONTROL = (MixerInterop.MIXERCONTROL)Marshal.PtrToStructure(mIXERLINECONTROLS.pamxctrl, typeof(MixerInterop.MIXERCONTROL));
            Marshal.FreeCoTaskMem(intPtr);
            if (MixerControl.IsControlBoolean(mIXERCONTROL.dwControlType))
            {
                return(new BooleanMixerControl(mIXERCONTROL, mixerHandle, mixerFlags, nChannels));
            }
            if (MixerControl.IsControlSigned(mIXERCONTROL.dwControlType))
            {
                return(new SignedMixerControl(mIXERCONTROL, mixerHandle, mixerFlags, nChannels));
            }
            if (MixerControl.IsControlUnsigned(mIXERCONTROL.dwControlType))
            {
                return(new UnsignedMixerControl(mIXERCONTROL, mixerHandle, mixerFlags, nChannels));
            }
            if (MixerControl.IsControlListText(mIXERCONTROL.dwControlType))
            {
                return(new ListTextMixerControl(mIXERCONTROL, mixerHandle, mixerFlags, nChannels));
            }
            if (MixerControl.IsControlCustom(mIXERCONTROL.dwControlType))
            {
                return(new CustomMixerControl(mIXERCONTROL, mixerHandle, mixerFlags, nChannels));
            }
            throw new InvalidOperationException(string.Format("Unknown mixer control type {0}", mIXERCONTROL.dwControlType));
        }