Пример #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>
 /// Creates a new Mixer Source For a Specified Source
 /// </summary>
 /// <param name="mixerHandle">Mixer Handle</param>
 /// <param name="destinationIndex">Destination Index</param>
 /// <param name="sourceIndex">Source Index</param>
 /// <param name="mixerHandleType">Flag indicating the meaning of mixerHandle</param>
 public MixerLine(IntPtr mixerHandle, int destinationIndex, int sourceIndex, MixerFlags mixerHandleType)
 {
     this.mixerHandle        = mixerHandle;
     this.mixerHandleType    = mixerHandleType;
     mixerLine               = new MixerInterop.MIXERLINE();
     mixerLine.cbStruct      = Marshal.SizeOf(mixerLine);
     mixerLine.dwDestination = destinationIndex;
     mixerLine.dwSource      = sourceIndex;
     MmException.Try(MixerInterop.mixerGetLineInfo(mixerHandle, ref mixerLine, mixerHandleType | MixerFlags.GetLineInfoOfSource), "mixerGetLineInfo");
 }
Пример #3
0
 /// <summary>
 /// Creates a new Mixer Source
 /// </summary>
 /// <param name="nMixer">Mixer ID</param>
 /// <param name="nDestination">Destination ID</param>
 /// <param name="nSource">Source ID</param>
 public MixerSource(IntPtr mixerHandle, int nDestination, int nSource)
 {
     mixerLine               = new MixerInterop.MIXERLINE();
     mixerLine.cbStruct      = Marshal.SizeOf(mixerLine);
     mixerLine.dwDestination = nDestination;
     mixerLine.dwSource      = nSource;
     MmException.Try(MixerInterop.mixerGetLineInfo(mixerHandle, ref mixerLine, MixerInterop.MIXER_GETLINEINFOF_SOURCE), "mixerGetLineInfo");
     this.mixerHandle  = mixerHandle;
     this.nDestination = nDestination;
     this.nSource      = nSource;
 }
Пример #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>
        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));
            }
        }
Пример #5
0
 public Mixer(int mixerIndex)
 {
     if (mixerIndex < 0 || mixerIndex >= Mixer.NumberOfDevices)
     {
         throw new ArgumentOutOfRangeException("mixerID");
     }
     this.caps = default(MixerInterop.MIXERCAPS);
     MmException.Try(MixerInterop.mixerGetDevCaps((IntPtr)mixerIndex, ref this.caps, Marshal.SizeOf(this.caps)), "mixerGetDevCaps");
     this.mixerHandle     = (IntPtr)mixerIndex;
     this.mixerHandleType = MixerFlags.Mixer;
 }
Пример #6
0
        /// <summary>Connects to the specified mixer</summary>
        /// <param name="mixerIndex">The index of the mixer to use.
        /// This should be between zero and NumberOfDevices - 1</param>
        public Mixer(int mixerIndex)
        {
            if (mixerIndex < 0 || mixerIndex >= NumberOfDevices)
            {
                throw new ArgumentOutOfRangeException("mixerID");
            }
            caps = new MixerInterop.MIXERCAPS();
            MmException.Try(MixerInterop.mixerGetDevCaps((IntPtr)mixerIndex, ref caps, Marshal.SizeOf(caps)), "mixerGetDevCaps");
            this.mixerHandle     = (IntPtr)mixerIndex;
            this.mixerHandleType = MixerFlags.Mixer;

            //MmException.Try(MixerInterop.mixerOpen(out mixerHandle, mixerIndex, IntPtr.Zero, IntPtr.Zero, 0), "mixerOpen");
        }
Пример #7
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));
        }
Пример #8
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>
        public static IList <MixerControl> GetMixerControls(IntPtr mixerHandle, MixerLine mixerLine,
                                                            MixerFlags mixerHandleType)
        {
            var controls = new List <MixerControl>();

            if (mixerLine.ControlsCount > 0)
            {
                int    mixerControlSize = Marshal.SizeOf(typeof(MixerInterop.MIXERCONTROL));
                var    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));
                try
                {
                    MmResult err =
                        MixerInterop.mixerGetLineControls(mixerHandle, ref mlc, MixerFlags.All | mixerHandleType);
                    if (err != MmResult.NoError)
                    {
                        throw new MmException(err, "mixerGetLineControls");
                    }
                    for (int i = 0; i < mlc.cControls; i++)
                    {
                        Int64 address = pmc.ToInt64() + mixerControlSize * i;

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

                        controls.Add(mixerControl);
                    }
                }
                finally
                {
                    Marshal.FreeHGlobal(pmc);
                }
            }
            return(controls);
        }
Пример #9
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);
        }
Пример #10
0
        /// <summary>
        /// Gets the control details
        /// </summary>
        protected void GetControlDetails()
        {
            mixerControlDetails.cbStruct    = Marshal.SizeOf(mixerControlDetails);
            mixerControlDetails.dwControlID = mixerControl.dwControlID;
            if (IsCustom)
            {
                mixerControlDetails.cChannels = 0;
            }
            else if ((mixerControl.fdwControl & MixerInterop.MIXERCONTROL_CONTROLF_UNIFORM) != 0)
            {
                mixerControlDetails.cChannels = 1;
            }
            else
            {
                mixerControlDetails.cChannels = nChannels;
            }


            if ((mixerControl.fdwControl & MixerInterop.MIXERCONTROL_CONTROLF_MULTIPLE) != 0)
            {
                mixerControlDetails.cMultipleItems = mixerControl.cMultipleItems;
            }
            else if (IsCustom)
            {
                mixerControlDetails.cMultipleItems = 0;                 // TODO: special cases
            }
            else
            {
                mixerControlDetails.cMultipleItems = 0;
            }

            if (IsBoolean)
            {
                mixerControlDetails.cbDetails = Marshal.SizeOf(new MixerInterop.MIXERCONTROLDETAILS_BOOLEAN());
            }
            else if (IsListText)
            {
                mixerControlDetails.cbDetails = Marshal.SizeOf(new MixerInterop.MIXERCONTROLDETAILS_LISTTEXT());
            }
            else if (IsSigned)
            {
                mixerControlDetails.cbDetails = Marshal.SizeOf(new MixerInterop.MIXERCONTROLDETAILS_SIGNED());
            }
            else if (IsUnsigned)
            {
                mixerControlDetails.cbDetails = Marshal.SizeOf(new MixerInterop.MIXERCONTROLDETAILS_UNSIGNED());
            }
            else
            {             // must be custom
                mixerControlDetails.cbDetails = mixerControl.Metrics.customData;
            }
            // from the structs sample in MSDN (see MyPerson2)
            IntPtr buffer = Marshal.AllocCoTaskMem(mixerControlDetails.cbDetails * mixerControlDetails.cChannels);

            // To copy stuff in:
            // Marshal.StructureToPtr( theStruct, buffer, false );
            mixerControlDetails.paDetails = buffer;
            MmResult err = MixerInterop.mixerGetControlDetails(mixerHandle, ref mixerControlDetails, MixerFlags.Value | mixerHandleType);

            // let the derived classes get the details before we free the handle
            if (err == MmResult.NoError)
            {
                GetDetails(mixerControlDetails.paDetails);
            }
            Marshal.FreeCoTaskMem(buffer);
            if (err != MmResult.NoError)
            {
                throw new MmException(err, "mixerGetControlDetails");
            }
        }
Пример #11
0
        /// <summary>
        /// Gets the control details
        /// </summary>
        protected void GetControlDetails()
        {
            mixerControlDetails.cbStruct    = Marshal.SizeOf(mixerControlDetails);
            mixerControlDetails.dwControlID = mixerControl.dwControlID;
            if (IsCustom)
            {
                mixerControlDetails.cChannels = 0;
            }
            else if ((mixerControl.fdwControl & MixerInterop.MIXERCONTROL_CONTROLF_UNIFORM) != 0)
            {
                mixerControlDetails.cChannels = 1;
            }
            else
            {
                mixerControlDetails.cChannels = nChannels;
            }


            if ((mixerControl.fdwControl & MixerInterop.MIXERCONTROL_CONTROLF_MULTIPLE) != 0)
            {
                mixerControlDetails.hwndOwner = (IntPtr)mixerControl.cMultipleItems;
            }
            else if (IsCustom)
            {
                mixerControlDetails.hwndOwner = IntPtr.Zero;
            }
            else
            {
                mixerControlDetails.hwndOwner = IntPtr.Zero;
            }

            if (IsBoolean)
            {
                mixerControlDetails.cbDetails = Marshal.SizeOf(new MixerInterop.MIXERCONTROLDETAILS_BOOLEAN());
            }
            else if (IsListText)
            {
                mixerControlDetails.cbDetails = Marshal.SizeOf(new MixerInterop.MIXERCONTROLDETAILS_LISTTEXT());
            }
            else if (IsSigned)
            {
                mixerControlDetails.cbDetails = Marshal.SizeOf(new MixerInterop.MIXERCONTROLDETAILS_SIGNED());
            }
            else if (IsUnsigned)
            {
                mixerControlDetails.cbDetails = Marshal.SizeOf(new MixerInterop.MIXERCONTROLDETAILS_UNSIGNED());
            }
            else
            {
                // must be custom
                mixerControlDetails.cbDetails = mixerControl.Metrics.customData;
            }
            var detailsSize = mixerControlDetails.cbDetails * mixerControlDetails.cChannels;

            if ((mixerControl.fdwControl & MixerInterop.MIXERCONTROL_CONTROLF_MULTIPLE) != 0)
            {
                // fixing issue 16390 - calculating size correctly for multiple items
                detailsSize *= (int)mixerControl.cMultipleItems;
            }
            IntPtr buffer = Marshal.AllocCoTaskMem(detailsSize);

            // To copy stuff in:
            // Marshal.StructureToPtr( theStruct, buffer, false );
            mixerControlDetails.paDetails = buffer;
            MmResult err = MixerInterop.mixerGetControlDetails(mixerHandle, ref mixerControlDetails,
                                                               MixerFlags.Value | mixerHandleType);

            // let the derived classes get the details before we free the handle
            if (err == MmResult.NoError)
            {
                GetDetails(mixerControlDetails.paDetails);
            }
            Marshal.FreeCoTaskMem(buffer);
            if (err != MmResult.NoError)
            {
                throw new MmException(err, "mixerGetControlDetails");
            }
        }
Пример #12
0
        /// <summary>
        /// Gets the control details
        /// </summary>
        // Token: 0x060005CD RID: 1485 RVA: 0x00012F18 File Offset: 0x00011118
        protected void GetControlDetails()
        {
            this.mixerControlDetails.cbStruct    = Marshal.SizeOf(this.mixerControlDetails);
            this.mixerControlDetails.dwControlID = this.mixerControl.dwControlID;
            if (this.IsCustom)
            {
                this.mixerControlDetails.cChannels = 0;
            }
            else if ((this.mixerControl.fdwControl & 1u) != 0u)
            {
                this.mixerControlDetails.cChannels = 1;
            }
            else
            {
                this.mixerControlDetails.cChannels = this.nChannels;
            }
            if ((this.mixerControl.fdwControl & 2u) != 0u)
            {
                this.mixerControlDetails.hwndOwner = (IntPtr)((long)((ulong)this.mixerControl.cMultipleItems));
            }
            else if (this.IsCustom)
            {
                this.mixerControlDetails.hwndOwner = IntPtr.Zero;
            }
            else
            {
                this.mixerControlDetails.hwndOwner = IntPtr.Zero;
            }
            if (this.IsBoolean)
            {
                this.mixerControlDetails.cbDetails = Marshal.SizeOf(default(MixerInterop.MIXERCONTROLDETAILS_BOOLEAN));
            }
            else if (this.IsListText)
            {
                this.mixerControlDetails.cbDetails = Marshal.SizeOf(default(MixerInterop.MIXERCONTROLDETAILS_LISTTEXT));
            }
            else if (this.IsSigned)
            {
                this.mixerControlDetails.cbDetails = Marshal.SizeOf(default(MixerInterop.MIXERCONTROLDETAILS_SIGNED));
            }
            else if (this.IsUnsigned)
            {
                this.mixerControlDetails.cbDetails = Marshal.SizeOf(default(MixerInterop.MIXERCONTROLDETAILS_UNSIGNED));
            }
            else
            {
                this.mixerControlDetails.cbDetails = this.mixerControl.Metrics.customData;
            }
            int num = this.mixerControlDetails.cbDetails * this.mixerControlDetails.cChannels;

            if ((this.mixerControl.fdwControl & 2u) != 0u)
            {
                num *= (int)this.mixerControl.cMultipleItems;
            }
            IntPtr intPtr = Marshal.AllocCoTaskMem(num);

            this.mixerControlDetails.paDetails = intPtr;
            MmResult mmResult = MixerInterop.mixerGetControlDetails(this.mixerHandle, ref this.mixerControlDetails, this.mixerHandleType);

            if (mmResult == MmResult.NoError)
            {
                this.GetDetails(this.mixerControlDetails.paDetails);
            }
            Marshal.FreeCoTaskMem(intPtr);
            if (mmResult != MmResult.NoError)
            {
                throw new MmException(mmResult, "mixerGetControlDetails");
            }
        }