Beispiel #1
0
        /// <summary>
        /// Gets all the mixer controls
        /// </summary>
        /// <param name="mixerHandle"></param>
        /// <param name="mixerLine"></param>
        /// <param name="mixerHandleType"></param>
        /// <returns></returns>
        public static IList <MixerControl> GetMixerControls(IntPtr mixerHandle, MixerLine mixerLine, MixerFlags mixerHandleType)
        {
            List <MixerControl> controls = new List <MixerControl>();

            if (mixerLine.ControlsCount > 0)
            {
                int mixerControlSize = Marshal.SizeOf(typeof(MixerInterop.MIXERCONTROL));
                MixerInterop.MIXERLINECONTROLS mlc = new MixerInterop.MIXERLINECONTROLS();
                IntPtr pmc = Marshal.AllocHGlobal(mixerControlSize * mixerLine.ControlsCount);
                mlc.cbStruct  = Marshal.SizeOf(mlc);
                mlc.dwLineID  = mixerLine.LineId;
                mlc.cControls = mixerLine.ControlsCount;
                mlc.pamxctrl  = pmc;
                mlc.cbmxctrl  = Marshal.SizeOf(typeof(MixerInterop.MIXERCONTROL));

                MmResult err = MixerInterop.mixerGetLineControls(mixerHandle, ref mlc, MixerFlags.All | mixerHandleType);
                if (err != MmResult.NoError)
                {
                    Marshal.FreeHGlobal(pmc);
                    throw new MmException(err, "mixerGetLineControls");
                }
                for (int i = 0; i < mlc.cControls; i++)
                {
                    Int64 address = pmc.ToInt64() + mixerControlSize * i;

                    MixerInterop.MIXERCONTROL mc = (MixerInterop.MIXERCONTROL)Marshal.PtrToStructure((IntPtr)address, typeof(MixerInterop.MIXERCONTROL));
                    MixerControl mixerControl    = MixerControl.GetMixerControl(mixerHandle, mixerLine.LineId, mc.dwControlID, mixerLine.Channels, mixerHandleType);

                    controls.Add(mixerControl);
                }
            }
            return(controls);
        }
Beispiel #2
0
 /// <summary>
 /// Retrieves the specified control
 /// </summary>
 /// <param name="nControl"></param>
 /// <returns></returns>
 public MixerControl GetControl(int nControl)
 {
     if (nControl < 0 || nControl >= ControlsCount)
     {
         throw new ArgumentOutOfRangeException("nControl");
     }
     return(MixerControl.GetMixerControl(mixerHandle, (int)mixerLine.dwLineID, nControl, Channels));
 }
Beispiel #3
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));
            }
        }
Beispiel #4
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>
        // Token: 0x060005CC RID: 1484 RVA: 0x00012DC8 File Offset: 0x00010FC8
        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));
        }
Beispiel #5
0
        /// <summary>
        /// Gets all the mixer controls
        /// </summary>
        /// <param name="mixerHandle">Mixer Handle</param>
        /// <param name="mixerLine">Mixer Line</param>
        /// <param name="mixerHandleType">Mixer Handle Type</param>
        /// <returns></returns>
        // Token: 0x060005CB RID: 1483 RVA: 0x00012C9C File Offset: 0x00010E9C
        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, mixerHandleType);
                    if (mmResult != MmResult.NoError)
                    {
                        throw new MmException(mmResult, "mixerGetLineControls");
                    }
                    for (int i = 0; i < mixerlinecontrols.cControls; i++)
                    {
                        long value = intPtr.ToInt64() + (long)(num * i);
                        MixerInterop.MIXERCONTROL mixercontrol = (MixerInterop.MIXERCONTROL)Marshal.PtrToStructure((IntPtr)value, 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 #6
0
 private bool VolumeAndMicLevelAssigned(MixerControl control)
 {
     if (control.ControlType != MixerControlType.Volume) return false;
     _volumeControl = control as UnsignedMixerControl;
     InputLevel = _limitingInput;
     return true;
 }