Ejemplo n.º 1
0
        private MMSYSERR SetVolume(IntPtr hmixer, MIXERCONTROL mxc, uint volume)
        {
            IntPtr                       hmem = IntPtr.Zero;
            MMSYSERR                     err  = MMSYSERR.NOERROR;
            MIXERCONTROLDETAILS          mxcd = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_UNSIGNED vol  = new MIXERCONTROLDETAILS_UNSIGNED();

            try
            {
                mxcd.hwndOwner   = IntPtr.Zero;
                mxcd.dwControlID = mxc.dwControlID;
                mxcd.cbStruct    = (uint)Marshal.SizeOf(mxcd);
                mxcd.cbDetails   = (uint)Marshal.SizeOf(vol);
                mxcd.cChannels   = 1;
                vol.value        = volume;
                hmem             = malloc(Marshal.SizeOf(vol));
                mxcd.paDetails   = hmem;

                Marshal.StructureToPtr(vol, mxcd.paDetails, true);
                err = mixerSetControlDetails(hmixer, ref mxcd, 0x0);
                if (hmem != IntPtr.Zero)
                {
                    free(hmem, Marshal.SizeOf(vol));
                }
                return(err);
            }
            catch { return(err); }
        }
Ejemplo n.º 2
0
        public static void SetMute(MixerInfo mi, bool mute)
        {
            if (IntPtr.Size == 4)
            {
                MIXERCONTROLDETAILS mcd = new MIXERCONTROLDETAILS();
                mcd.cbStruct       = (uint)Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
                mcd.dwControlID    = mi.muteCtl;
                mcd.cMultipleItems = 0;
                mcd.cChannels      = 1;
                mcd.cbDetails      = 4;
                mcd.paDetails      = Marshal.AllocHGlobal((int)mcd.cbDetails);

                Marshal.WriteInt32(mcd.paDetails, mute ? 1 : 0);

                mixerSetControlDetails(IntPtr.Zero, ref mcd, MIXER.GETCONTROLDETAILSF_VALUE | MIXER.OBJECTF_MIXER);

                Marshal.FreeHGlobal(mcd.paDetails);
            }
            else
            {
                MIXERCONTROLDETAILS64 mcd = new MIXERCONTROLDETAILS64();
                mcd.cbStruct       = (uint)Marshal.SizeOf(typeof(MIXERCONTROLDETAILS64));
                mcd.dwControlID    = mi.muteCtl;
                mcd.cMultipleItems = 0;
                mcd.cChannels      = 1;
                mcd.cbDetails      = 4;
                mcd.paDetails      = Marshal.AllocHGlobal((int)mcd.cbDetails);

                Marshal.WriteInt32(mcd.paDetails, mute ? 1 : 0);

                mixerSetControlDetails(IntPtr.Zero, ref mcd, MIXER.GETCONTROLDETAILSF_VALUE | MIXER.OBJECTF_MIXER);

                Marshal.FreeHGlobal(mcd.paDetails);
            }
        }
Ejemplo n.º 3
0
        [DllImport("winmm.dll", CharSet = CharSet.Ansi)]                                                    // mixerSetControlDetails

        private static extern int mixerSetControlDetails(

            int hmxobj,

            ref MIXERCONTROLDETAILS pmxcd,

            int fdwDetails);
Ejemplo n.º 4
0
        public static void SetVolume(MixerInfo mi, VOLUME volume)
        {
            if (IntPtr.Size == 4)
            {
                MIXERCONTROLDETAILS mcd = new MIXERCONTROLDETAILS();
                mcd.cbStruct       = (uint)Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
                mcd.dwControlID    = mi.volumeCtl;
                mcd.cMultipleItems = 0;
                mcd.cChannels      = 2;
                mcd.cbDetails      = (uint)Marshal.SizeOf(typeof(VOLUME));
                mcd.paDetails      = Marshal.AllocHGlobal((int)mcd.cbDetails);

                Marshal.StructureToPtr(volume, mcd.paDetails, false);

                mixerSetControlDetails(IntPtr.Zero, ref mcd, MIXER.GETCONTROLDETAILSF_VALUE | MIXER.OBJECTF_MIXER);

                Marshal.FreeHGlobal(mcd.paDetails);
            }
            else
            {
                MIXERCONTROLDETAILS64 mcd = new MIXERCONTROLDETAILS64();
                mcd.cbStruct       = (uint)Marshal.SizeOf(typeof(MIXERCONTROLDETAILS64));
                mcd.dwControlID    = mi.volumeCtl;
                mcd.cMultipleItems = 0;
                mcd.cChannels      = 2;
                mcd.cbDetails      = (uint)Marshal.SizeOf(typeof(VOLUME));
                mcd.paDetails      = Marshal.AllocHGlobal((int)mcd.cbDetails);

                Marshal.StructureToPtr(volume, mcd.paDetails, false);

                mixerSetControlDetails(IntPtr.Zero, ref mcd, MIXER.GETCONTROLDETAILSF_VALUE | MIXER.OBJECTF_MIXER);

                Marshal.FreeHGlobal(mcd.paDetails);
            }
        }
Ejemplo n.º 5
0
        void SetMute(bool flag)
        {
            MIXERCONTROLDETAILS         muteCtl = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_BOOLEAN muteVal = new MIXERCONTROLDETAILS_BOOLEAN();

            muteVal.Value = flag ? 1 : 0;

            Debug.WriteLine("MixerAPI.SetMute:" + flag.ToString());

            IntPtr mutePtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(new MIXERCONTROLDETAILS_BOOLEAN()));

            Marshal.StructureToPtr(muteVal, mutePtr, false);

            muteCtl.StructSize      = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS());
            muteCtl.ControlID       = _muteID;
            muteCtl.Channels        = 1;
            muteCtl.MultipleItems   = 0;
            muteCtl.DetailsItemSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS_BOOLEAN());
            muteCtl.DetailsPointer  = mutePtr;

            uint mmresult = mixerSetControlDetails(_hMixer, ref muteCtl,
                                                   MIXER_OBJECTF.HMIXER, MIXER_GETCONTROLDETAILSF.VALUE);

            Marshal.FreeCoTaskMem(mutePtr);

            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                throw new Exception("mixerSetControlDetails" + mmresult.ToString());
            }
        }
Ejemplo n.º 6
0
        bool IsMute()
        {
            MIXERCONTROLDETAILS muteCtl = new MIXERCONTROLDETAILS();
            IntPtr mutePtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(new MIXERCONTROLDETAILS_BOOLEAN()));

            muteCtl.StructSize      = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS());
            muteCtl.ControlID       = _muteID;
            muteCtl.Channels        = 1;
            muteCtl.MultipleItems   = 0;
            muteCtl.DetailsItemSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS_BOOLEAN());
            muteCtl.DetailsPointer  = mutePtr;

            uint mmresult = mixerGetControlDetails(_hMixer, ref muteCtl,
                                                   MIXER_OBJECTF.HMIXER, MIXER_GETCONTROLDETAILSF.VALUE);

            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                Marshal.FreeCoTaskMem(mutePtr);
                throw new MixerException("mixerGetControlDetails", mmresult);
            }

            MIXERCONTROLDETAILS_BOOLEAN muteInfo
                = (MIXERCONTROLDETAILS_BOOLEAN)Marshal.PtrToStructure(mutePtr,
                                                                      typeof(MIXERCONTROLDETAILS_BOOLEAN));

            Marshal.FreeCoTaskMem(mutePtr);

            Debug.WriteLine("MixerAPI.IsMuteret:" + muteInfo.Value.ToString());

            return(muteInfo.Value > 0);
        }
Ejemplo n.º 7
0
        void SetVolume(uint value)
        {
            MIXERCONTROLDETAILS          volCtl = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_UNSIGNED volDat = new MIXERCONTROLDETAILS_UNSIGNED();
            double volValue = (double)value * (double)(_volMax - _volMin) / 100D + _volMin;

            volDat.Value = (uint)volValue;

            Debug.WriteLine(string.Format("MixerAPI.SetCurrentVolume vol:{0} volMax:{1} volMin:{2} param:{3}",
                                          value, _volMax, _volMin, volDat.Value));


            IntPtr volPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(new MIXERCONTROLDETAILS_UNSIGNED()));

            Marshal.StructureToPtr(volDat, volPtr, false);

            volCtl.StructSize      = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS());
            volCtl.ControlID       = _volumeID;
            volCtl.Channels        = 1;
            volCtl.MultipleItems   = 0;
            volCtl.DetailsItemSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS_UNSIGNED());
            volCtl.DetailsPointer  = volPtr;

            uint mmresult = mixerSetControlDetails(_hMixer, ref volCtl,
                                                   MIXER_OBJECTF.HMIXER, MIXER_GETCONTROLDETAILSF.VALUE);

            Marshal.FreeCoTaskMem(volPtr);

            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                throw new MixerException("mixerSetControlDetails", mmresult);
            }
        }
Ejemplo n.º 8
0
        uint GetCurrentVolume()
        {
            MIXERCONTROLDETAILS volCtl = new MIXERCONTROLDETAILS();
            IntPtr volPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(new MIXERCONTROLDETAILS_UNSIGNED()));

            volCtl.StructSize      = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS());
            volCtl.ControlID       = _volumeID;
            volCtl.Channels        = 1;
            volCtl.MultipleItems   = 0;
            volCtl.DetailsItemSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS_UNSIGNED());
            volCtl.DetailsPointer  = volPtr;

            uint mmresult = mixerGetControlDetails(_hMixer, ref volCtl,
                                                   MIXER_OBJECTF.HMIXER, MIXER_GETCONTROLDETAILSF.VALUE);

            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                Marshal.FreeCoTaskMem(volPtr);
                throw new MixerException("mixerGetControlDetails", mmresult);
            }

            MIXERCONTROLDETAILS_UNSIGNED volInfo
                = (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(volPtr,
                                                                       typeof(MIXERCONTROLDETAILS_UNSIGNED));

            Marshal.FreeCoTaskMem(volPtr);

            double ret = ((double)(volInfo.Value - _volMin) * 100 + (double)(_volMax - _volMin) / 2)
                         / (double)(_volMax - _volMin);

            Debug.WriteLine(string.Format("MixerAPI.GetCurrentVolume vol:{0} volMax:{1} volMin:{2} ret:{3}",
                                          volInfo.Value, _volMax, _volMin, ret));

            return((uint)ret);
        }
Ejemplo n.º 9
0
        //Added this function since Values didn't seem to be working correctly for MuteSwitch
        //TODO: Re-evaluate what's necessary once thorough testing has been completed for XP
        public void SetMute(bool mute)
        {
            MIXERCONTROLDETAILS mcd = new MIXERCONTROLDETAILS();

            mcd.cbStruct       = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
            mcd.dwControlID    = ctrl.dwControlID;
            mcd.cMultipleItems = 0;
            mcd.cChannels      = 1;
            mcd.cbDetails      = 4;
            mcd.paDetails      = Marshal.AllocHGlobal((int)mcd.cbDetails);

            Marshal.WriteInt32(mcd.paDetails, mute ? 1 : 0);

            mixerSetControlDetails(IntPtr.Zero, ref mcd, 0x0 | 0x0);

            Marshal.FreeHGlobal(mcd.paDetails);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Used to get or set the values of this switch.
        /// </summary>
        ///

        //Added this function since Values didn't seem to be working correctly for MuteSwitch
        //TODO: Re-evaluate what's necessary once thorough testing has been completed for XP
        public bool IsMuted()
        {
            MIXERCONTROLDETAILS mcd = new MIXERCONTROLDETAILS();

            mcd.cbStruct       = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
            mcd.dwControlID    = ctrl.dwControlID;
            mcd.cMultipleItems = 0;
            mcd.cChannels      = 1;
            mcd.cbDetails      = 4;
            mcd.paDetails      = Marshal.AllocHGlobal((int)mcd.cbDetails);

            mixerGetControlDetailsA(IntPtr.Zero, ref mcd, 0x0 | 0x0);

            int rtn = Marshal.ReadInt32(mcd.paDetails);

            Marshal.FreeHGlobal(mcd.paDetails);

            return(rtn != 0);
        }
Ejemplo n.º 11
0
        static VOLUME GetVolume(MixerInfo mi)
        {
            MIXERCONTROLDETAILS mcd = new MIXERCONTROLDETAILS();

            mcd.cbStruct       = (uint)Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
            mcd.dwControlID    = mi.volumeCtl;
            mcd.cMultipleItems = 0;
            mcd.cChannels      = 2;
            mcd.cbDetails      = (uint)Marshal.SizeOf(typeof(int));
            mcd.paDetails      = Marshal.AllocHGlobal((int)mcd.cbDetails);

            mixerGetControlDetails(IntPtr.Zero, ref mcd, MIXER.GETCONTROLDETAILSF_VALUE | MIXER.OBJECTF_MIXER);

            VOLUME rtn = (VOLUME)Marshal.PtrToStructure(mcd.paDetails, typeof(VOLUME));

            Marshal.FreeHGlobal(mcd.paDetails);

            return(rtn);
        }
Ejemplo n.º 12
0
        static bool IsMuted(MixerInfo mi)
        {
            MIXERCONTROLDETAILS mcd = new MIXERCONTROLDETAILS();

            mcd.cbStruct       = (uint)Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
            mcd.dwControlID    = mi.muteCtl;
            mcd.cMultipleItems = 0;
            mcd.cChannels      = 1;
            mcd.cbDetails      = 4;
            mcd.paDetails      = Marshal.AllocHGlobal((int)mcd.cbDetails);

            mixerGetControlDetails(IntPtr.Zero, ref mcd, MIXER.GETCONTROLDETAILSF_VALUE | MIXER.OBJECTF_MIXER);

            int rtn = Marshal.ReadInt32(mcd.paDetails);

            Marshal.FreeHGlobal(mcd.paDetails);

            return(rtn != 0);
        }
Ejemplo n.º 13
0
        private static bool SetVolumeControl(int hmixer, MIXERCONTROL mxc,
                                             int volume)
        {
            // This function sets the value for a volume control.
            // Returns True if successful

            bool retValue;
            int  rc;
            MIXERCONTROLDETAILS          mxcd = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_UNSIGNED vol  = new
                                                MIXERCONTROLDETAILS_UNSIGNED();

            mxcd.item        = 0;
            mxcd.dwControlID = mxc.dwControlID;
            mxcd.cbStruct    = Marshal.SizeOf(mxcd);
            mxcd.cbDetails   = Marshal.SizeOf(vol);

            // Allocate a buffer for the control value buffer
            mxcd.cChannels = 1;
            vol.dwValue    = volume;

            // Copy the data into the control value buffer
            mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(
                                                        typeof(MIXERCONTROLDETAILS_UNSIGNED)));
            Marshal.StructureToPtr(vol, mxcd.paDetails, false);

            // Set the control value
            rc = mixerSetControlDetails(hmixer, ref mxcd,
                                        MIXER_SETCONTROLDETAILSF_VALUE);

            if (MMSYSERR_NOERROR == rc)
            {
                retValue = true;
            }
            else
            {
                retValue = false;
            } return(retValue);
        }
        private static void SetVolumeControl(int hmixer, MIXERCONTROL mxc,
                                             int volume)
        {
            // This function sets the value for a volume control.
            // Returns True if successful
            MIXERCONTROLDETAILS          mxcd = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_UNSIGNED vol  = new
                                                MIXERCONTROLDETAILS_UNSIGNED();

            mxcd.item        = 0;
            mxcd.dwControlID = mxc.dwControlID;
            mxcd.cbStruct    = Marshal.SizeOf(mxcd);
            mxcd.cbDetails   = Marshal.SizeOf(vol);

            // Allocate a buffer for the control value buffer
            mxcd.cChannels = 1;
            vol.dwValue    = volume;

            // Copy the data into the control value buffer
            //mxcd.paDetails = vol;
            //(MIXERCONTROL)Marshal.PtrToStructure(mxlc.pamxctrl,typeof(MIXERCONTROL));
            mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED)));
            Marshal.StructureToPtr(vol, mxcd.paDetails, false);

            // Set the control value
            try
            {
                CheckErr(mixerSetControlDetails(hmixer, ref mxcd,
                                                MIXER_SETCONTROLDETAILSF_VALUE));
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                Marshal.FreeCoTaskMem(mxcd.paDetails);
            }
        }
Ejemplo n.º 15
0
        private bool SetVolumeControl(                                                                       // SetVolumeControl
            int hmixer,
            MIXERCONTROL mxc,
            int volume)
        {
            bool retValue = false;
            int  rc;

            MIXERCONTROLDETAILS          mxcd = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_UNSIGNED vol  = new MIXERCONTROLDETAILS_UNSIGNED();

            mxcd.item        = 0;
            mxcd.dwControlID = mxc.dwControlID;
            mxcd.cbStruct    = Marshal.SizeOf(mxcd);
            mxcd.cbDetails   = Marshal.SizeOf(vol);

            // Allocate a buffer for the control value buffer
            mxcd.cChannels = 1;
            vol.dwValue    = volume;

            // Copy the data into the control value buffer
            mxcd.paDetails = Marshal.AllocCoTaskMem(
                Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED)));

            Marshal.StructureToPtr(
                vol,
                mxcd.paDetails,
                false);

            // Set the control value
            rc = mixerSetControlDetails(
                hmixer,
                ref mxcd,
                MIXER_SETCONTROLDETAILSF_VALUE);

            return(retValue = MMSYSERR_NOERROR == rc ? true : false);
        }
Ejemplo n.º 16
0
        protected static bool GetMuteControl(int hmixer, int componentType, int ctrlType, out MIXERCONTROL mxc, out bool vCurrentMute)
        {
            // This function attempts to obtain a mixer control.
            // Returns True if successful.
            MIXERLINECONTROLS           mxlc  = new MIXERLINECONTROLS();
            MIXERLINE                   mxl   = new MIXERLINE();
            MIXERCONTROLDETAILS         pmxcd = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_BOOLEAN du    = new MIXERCONTROLDETAILS_BOOLEAN();

            mxc = new MIXERCONTROL();
            int  rc;
            bool retValue;

            vCurrentMute = false;

            mxl.cbStruct        = Marshal.SizeOf(mxl);
            mxl.dwComponentType = componentType;

            rc = mixerGetLineInfoA(hmixer, ref mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);

            if (MMSYSERR_NOERROR == rc)
            {
                int sizeofMIXERCONTROL = 152;
                int ctrl = Marshal.SizeOf(typeof(MIXERCONTROL));
                mxlc.pamxctrl  = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL);
                mxlc.cbStruct  = Marshal.SizeOf(mxlc);
                mxlc.dwLineID  = mxl.dwLineID;
                mxlc.dwControl = ctrlType;
                mxlc.cControls = 1;
                mxlc.cbmxctrl  = sizeofMIXERCONTROL;

                // Allocate a buffer for the control
                mxc.cbStruct = sizeofMIXERCONTROL;

                // Get the control
                rc = mixerGetLineControlsA(hmixer, ref mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
                if (MMSYSERR_NOERROR == rc)
                {
                    retValue = true;

                    // Copy the control into the destination structure
                    mxc = (MIXERCONTROL)Marshal.PtrToStructure(
                        mxlc.pamxctrl, typeof(MIXERCONTROL));
                }
                else
                {
                    retValue = false;
                }

                int sizeofMIXERCONTROLDETAILS         = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
                int sizeofMIXERCONTROLDETAILS_BOOLEAN = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_BOOLEAN));
                pmxcd.cbStruct    = sizeofMIXERCONTROLDETAILS;
                pmxcd.dwControlID = mxc.dwControlID;
                pmxcd.paDetails   = Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_BOOLEAN);
                pmxcd.cChannels   = 1;
                pmxcd.item        = 0;
                pmxcd.cbDetails   = sizeofMIXERCONTROLDETAILS_BOOLEAN;

                rc = mixerGetControlDetailsA(hmixer, ref pmxcd, MIXER_GETCONTROLDETAILSF_VALUE);

                du = (MIXERCONTROLDETAILS_BOOLEAN)Marshal.PtrToStructure(pmxcd.paDetails, typeof(MIXERCONTROLDETAILS_BOOLEAN));

                vCurrentMute = (du.fValue != 0);

                return(retValue);
            }

            retValue = false;
            return(retValue);
        }
        private static void GetVolumeControl(int hmixer, int componentType,
                                             int ctrlType, out MIXERCONTROL mxc, out int vCurrentVol)
        {
            // This function attempts to obtain a mixer control.
            // Returns True if successful.
            MIXERLINECONTROLS            mxlc  = new MIXERLINECONTROLS();
            MIXERLINE                    mxl   = new MIXERLINE();
            MIXERCONTROLDETAILS          pmxcd = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_UNSIGNED du    = new
                                                 MIXERCONTROLDETAILS_UNSIGNED();

            mxc = new MIXERCONTROL();

            vCurrentVol = -1;

            //mxl.szShortName = new string(' ', MIXER_SHORT_NAME_CHARS);
            //mxl.szName = new string(' ', MIXER_LONG_NAME_CHARS);
            mxl.cbStruct        = Marshal.SizeOf(mxl);
            mxl.dwComponentType = componentType;

            // Obtain a line corresponding to the component public enum
            CheckErr(mixerGetLineInfoA(hmixer, ref mxl,
                                       MIXER_GETLINEINFOF_COMPONENTTYPE));

            int sizeofMIXERCONTROL = 152;
            //Marshal.SizeOf(typeof(MIXERCONTROL))
            int ctrl = Marshal.SizeOf(typeof(MIXERCONTROL));

            mxlc.pamxctrl  = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL); //new MIXERCONTROL();
            mxlc.cbStruct  = Marshal.SizeOf(mxlc);
            mxlc.dwLineID  = mxl.dwLineID;
            mxlc.dwControl = ctrlType;
            mxlc.cControls = 1;
            mxlc.cbmxctrl  = sizeofMIXERCONTROL;

            // Allocate a buffer for the control
            mxc.cbStruct = sizeofMIXERCONTROL;

            // Get the control
            try
            {
                CheckErr(mixerGetLineControlsA(hmixer, ref mxlc,
                                               MIXER_GETLINECONTROLSF_ONEBYTYPE));
                // Copy the control into the destination structure
                mxc = (MIXERCONTROL)Marshal.PtrToStructure(mxlc.pamxctrl, typeof(MIXERCONTROL));
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                Marshal.FreeCoTaskMem(mxlc.pamxctrl);
            }
            int sizeofMIXERCONTROLDETAILS =
                Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
            int sizeofMIXERCONTROLDETAILS_UNSIGNED =
                Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED));

            pmxcd.cbStruct    = sizeofMIXERCONTROLDETAILS;
            pmxcd.dwControlID = mxc.dwControlID;
            pmxcd.paDetails   =
                Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED);
            pmxcd.cChannels = 1;
            pmxcd.item      = 0;
            pmxcd.cbDetails = sizeofMIXERCONTROLDETAILS_UNSIGNED;

            try
            {
                CheckErr(mixerGetControlDetailsA(hmixer, ref pmxcd,
                                                 MIXER_GETCONTROLDETAILSF_VALUE));
                du =
                    (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(pmxcd.paDetails, typeof(MIXERCONTROLDETAILS_UNSIGNED));
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                Marshal.FreeCoTaskMem(pmxcd.paDetails);
            }
            vCurrentVol = du.dwValue;
        }
Ejemplo n.º 18
0
 static extern uint mixerSetControlDetails(IntPtr hmxobj, ref MIXERCONTROLDETAILS pmxcd, MIXER flags);
Ejemplo n.º 19
0
 public static extern int mixerGetControlDetails(IntPtr hmxobj, ref MIXERCONTROLDETAILS pmxcd, uint fdwDetailsmixer);
Ejemplo n.º 20
0
        uint GetCurrentVolume()
        {
            MIXERCONTROLDETAILS volCtl = new MIXERCONTROLDETAILS();
            IntPtr volPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(new MIXERCONTROLDETAILS_UNSIGNED()));
            volCtl.StructSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS());
            volCtl.ControlID = _volumeID;
            volCtl.Channels = 1;
            volCtl.MultipleItems = 0;
            volCtl.DetailsItemSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS_UNSIGNED());
            volCtl.DetailsPointer = volPtr;

            uint mmresult = mixerGetControlDetails(_hMixer, ref volCtl,
                MIXER_OBJECTF.HMIXER , MIXER_GETCONTROLDETAILSF.VALUE);
            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                Marshal.FreeCoTaskMem(volPtr);
                throw new MixerException("mixerGetControlDetails" , mmresult);
            }

            MIXERCONTROLDETAILS_UNSIGNED volInfo
                = (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(volPtr,
                typeof(MIXERCONTROLDETAILS_UNSIGNED));
            Marshal.FreeCoTaskMem(volPtr);

            double ret = ((double)(volInfo.Value - _volMin) * 100 + (double)(_volMax - _volMin) / 2)
                                                        / (double)(_volMax - _volMin);

            Debug.WriteLine(string.Format("MixerAPI.GetCurrentVolume vol:{0} volMax:{1} volMin:{2} ret:{3}",
                volInfo.Value,_volMax,_volMin,ret));

            return (uint)ret;
        }
Ejemplo n.º 21
0
        static void SetMute(MixerInfo mi, bool mute)
        {
            MIXERCONTROLDETAILS mcd = new MIXERCONTROLDETAILS();
            mcd.cbStruct = (uint)Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
            mcd.dwControlID = mi.muteCtl;
            mcd.cMultipleItems = 0;
            mcd.cChannels = 1;
            mcd.cbDetails = 4;
            mcd.paDetails = Marshal.AllocHGlobal((int)mcd.cbDetails);

            Marshal.WriteInt32(mcd.paDetails, mute ? 1 : 0);

            mixerSetControlDetails(IntPtr.Zero, ref mcd, MIXER.GETCONTROLDETAILSF_VALUE | MIXER.OBJECTF_MIXER);

            Marshal.FreeHGlobal(mcd.paDetails);
        }
Ejemplo n.º 22
0
        void SetVolume(uint value)
        {
            MIXERCONTROLDETAILS volCtl = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_UNSIGNED volDat = new MIXERCONTROLDETAILS_UNSIGNED();
            double volValue = (double)value * (double)(_volMax - _volMin) / 100D + _volMin;
            volDat.Value = (uint)volValue;

            Debug.WriteLine(string.Format("MixerAPI.SetCurrentVolume vol:{0} volMax:{1} volMin:{2} param:{3}",
                value, _volMax, _volMin, volDat.Value));


            IntPtr volPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(new MIXERCONTROLDETAILS_UNSIGNED()));
            Marshal.StructureToPtr(volDat, volPtr, false);

            volCtl.StructSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS());
            volCtl.ControlID = _volumeID;
            volCtl.Channels = 1;
            volCtl.MultipleItems = 0;
            volCtl.DetailsItemSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS_UNSIGNED());
            volCtl.DetailsPointer = volPtr;

            uint mmresult = mixerSetControlDetails(_hMixer, ref volCtl,
                MIXER_OBJECTF.HMIXER, MIXER_GETCONTROLDETAILSF.VALUE);
            Marshal.FreeCoTaskMem(volPtr);

            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                throw new MixerException("mixerSetControlDetails" , mmresult);
            }


        }
Ejemplo n.º 23
0
		public static bool SetMux(int mixerID, int index)
		{
			int mixer;
			int retval = -1;
			MIXERCONTROL ctrl = new MIXERCONTROL();

			mixerOpen(out mixer, mixerID, 0, 0, 0);
			GetControlByType(mixer,MIXERLINE_COMPONENTTYPE_DST_WAVEIN, 0, MIXERCONTROL_CONTROLTYPE_MUX, out ctrl);

			MIXERCONTROLDETAILS details = new MIXERCONTROLDETAILS();
			int size = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_SIGNED));
			details.dwControlID = ctrl.dwControlID; 
			details.cbDetails = size; 
			details.item = ctrl.cMultipleItems;
			if(details.item > 0) size *= details.item;
			details.paDetails = Marshal.AllocCoTaskMem(size); 
			details.cbStruct = Marshal.SizeOf(details); 
			details.cChannels = 1; 
	
			if(details.item > 0)
			{
				int[] val = new int[details.item];
				for(int m=0; m<details.item; m++)
				{
					if(m == index) val[m] = 1;
					else val[m] = 0;
				}
				Marshal.Copy(val, 0, details.paDetails, details.item);

				retval = mixerSetControlDetails(mixer, ref details, MIXER_GETCONTROLDETAILSF_VALUE); 
			}
			if(retval == MMSYSERR_NOERROR)
				return true;
			else return false;
		}
Ejemplo n.º 24
0
        // This function attempts to obtain a specified mixer control/component pair -
        // returns true if successful.
        private static bool GetMixerControl(                                                                        // GetMixerControl
            int hmixer,
            int component,
            int control,
            out MIXERCONTROL mxc,
            out int vCurrentVol)
        {
            bool retValue = false;

            mxc = new MIXERCONTROL();

            MIXERLINECONTROLS            mxlc  = new MIXERLINECONTROLS();
            MIXERLINE                    mxl   = new MIXERLINE();
            MIXERCONTROLDETAILS          pmxcd = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_UNSIGNED du    = new MIXERCONTROLDETAILS_UNSIGNED();

            vCurrentVol = -1;                   // A dummy value

            mxl.cbStruct        = Marshal.SizeOf(mxl);
            mxl.dwComponentType = component;

            int rc = mixerGetLineInfoA(
                hmixer,
                ref mxl,
                MIXER_GETLINEINFOF_COMPONENTTYPE);

            if (MMSYSERR_NOERROR == rc)
            {
                int sizeofMIXERCONTROL = 152;
                int ctrl = Marshal.SizeOf(typeof(MIXERCONTROL));
                mxlc.pamxctrl  = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL);
                mxlc.cbStruct  = Marshal.SizeOf(mxlc);
                mxlc.dwLineID  = mxl.dwLineID;
                mxlc.dwControl = control;
                mxlc.cControls = 1;
                mxlc.cbmxctrl  = sizeofMIXERCONTROL;

                // Allocate a buffer for the control
                mxc.cbStruct = sizeofMIXERCONTROL;

                // Get the control
                rc = mixerGetLineControlsA(
                    hmixer,
                    ref mxlc,
                    MIXER_GETLINECONTROLSF_ONEBYTYPE);

                if (MMSYSERR_NOERROR == rc)
                {
                    retValue = true;
                    // Copy the control into the destination structure
                    mxc = (MIXERCONTROL)Marshal.PtrToStructure(
                        mxlc.pamxctrl,
                        typeof(MIXERCONTROL));
                }

                int sizeofMIXERCONTROLDETAILS =
                    Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));

                int sizeofMIXERCONTROLDETAILS_UNSIGNED =
                    Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED));

                pmxcd.cbStruct    = sizeofMIXERCONTROLDETAILS;
                pmxcd.dwControlID = mxc.dwControlID;
                pmxcd.paDetails   = Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED);
                pmxcd.cChannels   = 1;
                pmxcd.item        = 0;
                pmxcd.cbDetails   = sizeofMIXERCONTROLDETAILS_UNSIGNED;

                rc = mixerGetControlDetailsA(
                    hmixer,
                    ref pmxcd,
                    MIXER_GETCONTROLDETAILSF_VALUE);

                du = (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(
                    pmxcd.paDetails,
                    typeof(MIXERCONTROLDETAILS_UNSIGNED));

                vCurrentVol = du.dwValue;

                return(retValue);                   // true
            }

            return(retValue);                   // false
        }
Ejemplo n.º 25
0
		public static bool GetMuxLineNames(int mixerID, out ArrayList a)
		{
			int mixer;
			MIXERCONTROL ctrl = new MIXERCONTROL();
			a = new ArrayList();

			mixerOpen(out mixer, mixerID, 0, 0, 0);
			GetControlByType(mixer, MIXERLINE_COMPONENTTYPE_DST_WAVEIN, 0, MIXERCONTROL_CONTROLTYPE_MUX, out ctrl);

			int n = ctrl.cMultipleItems;
			MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS();
			mxcd.cbStruct = Marshal.SizeOf(mxcd);
			mxcd.dwControlID = ctrl.dwControlID;     // <== MIXERCONTROL.dwControlID
			mxcd.cChannels = 1;
			mxcd.item = n;   // <== MIXERCONTROL.cMultipleItems

			int size = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_LISTTEXT))*n;
			mxcd.cbDetails = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_LISTTEXT));
			mxcd.paDetails = Marshal.AllocCoTaskMem(size);

			int result = mixerGetControlDetails(mixer, ref mxcd, MIXER_GETCONTROLDETAILSF_LISTTEXT);

			if(result != MMSYSERR_NOERROR)
			{
				mixerClose(mixer);
				return false;
			}

			for(int i=0; i<mxcd.item; i++)
			{
				MIXERCONTROLDETAILS_LISTTEXT ltxt = new MIXERCONTROLDETAILS_LISTTEXT();
				IntPtr ptr = new IntPtr(mxcd.paDetails.ToInt32() + i*mxcd.cbDetails);
				
				ltxt = (MIXERCONTROLDETAILS_LISTTEXT)Marshal.PtrToStructure(ptr, typeof(MIXERCONTROLDETAILS_LISTTEXT));
				a.Add(ltxt.szName);
			}
			mixerClose(mixer);
			return true;
		}
Ejemplo n.º 26
0
		public static int GetMux(int mixerID)
		{
			int mixer;
			MIXERCONTROL ctrl = new MIXERCONTROL();

			mixerOpen(out mixer, mixerID, 0, 0, 0);
			GetControlByType(mixer, MIXERLINE_COMPONENTTYPE_DST_WAVEIN, 0, MIXERCONTROL_CONTROLTYPE_MUX, out ctrl);
			
			MIXERCONTROLDETAILS details = new MIXERCONTROLDETAILS();
			int size = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED));
			details.dwControlID = ctrl.dwControlID; 
			details.item = ctrl.cMultipleItems;
			details.cbDetails = size;
			if(details.item > 0) size *= ctrl.cMultipleItems;
			details.paDetails = Marshal.AllocCoTaskMem(size); 
			details.cbStruct = Marshal.SizeOf(details); 
			details.cChannels = 1;									
																		
			int retval = mixerGetControlDetails(mixer, ref details, MIXER_GETCONTROLDETAILSF_VALUE); 
			if(retval == MMSYSERR_NOERROR)
			{
				if(details.item > 0)
				{
					MIXERCONTROLDETAILS_UNSIGNED[] val = new MIXERCONTROLDETAILS_UNSIGNED[details.item];
					for(int m=0; m<details.item; m++)
					{
						IntPtr ptr = new IntPtr(details.paDetails.ToInt32() + m*details.cbDetails);
						val[m] = new MIXERCONTROLDETAILS_UNSIGNED();
						val[m] = (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(ptr, typeof(MIXERCONTROLDETAILS_UNSIGNED));
						if(val[m].dwValue == 1)
						{
							retval = m;
							m = details.item;
						}
					}
				}
			}
			mixerClose(mixer);
			return retval;
		}
Ejemplo n.º 27
0
        private static int GetVolume_RealtekHDaudio(int mixerID, int dst_type, int src_type)        // yt7pwr
        {
            if (mixerID > mixerGetNumDevs() - 1 ||
                mixerID < 0)
                return -1;

            int mixer;
            int val;
            MIXERCONTROL volCtrl = new MIXERCONTROL();

            int retval = mixerOpen(out mixer, mixerID, 0, 0, 0);
            if (retval != MMSYSERR_NOERROR)
                return -1;

            bool success = GetControlByID(mixer, dst_type, src_type, MIXERCONTROL_CONTROLTYPE_VOLUME, out volCtrl);
            if (success == true)
            {
                MIXERCONTROLDETAILS details = new MIXERCONTROLDETAILS();

                int sizeofMIXERCONTROLDETAILS = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
                int sizeofMIXERCONTROLDETAILS_UNSIGNED = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED));
                details.cbStruct = sizeofMIXERCONTROLDETAILS;
                details.dwControlID = volCtrl.dwControlID;
                details.paDetails = Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED);
                details.cChannels = 1;
                details.item = 0;
                details.cbDetails = sizeofMIXERCONTROLDETAILS_UNSIGNED;

                retval = mixerGetControlDetails(mixer, ref details, MIXER_GETCONTROLDETAILSF_VALUE);
                if (retval == MMSYSERR_NOERROR)
                {
                    MIXERCONTROLDETAILS_UNSIGNED du = (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(details.paDetails, typeof(MIXERCONTROLDETAILS_UNSIGNED));
                    val = du.dwValue;
                }
                else val = -1;
                Marshal.FreeCoTaskMem(details.paDetails);
            }
            else val = -1;
            mixerClose(mixer);
            return val;
        }
Ejemplo n.º 28
0
        bool IsMute()
        {
            MIXERCONTROLDETAILS muteCtl = new MIXERCONTROLDETAILS();
            IntPtr mutePtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(new MIXERCONTROLDETAILS_BOOLEAN()));
            muteCtl.StructSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS());
            muteCtl.ControlID = _muteID;
            muteCtl.Channels = 1;
            muteCtl.MultipleItems = 0;
            muteCtl.DetailsItemSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS_BOOLEAN());
            muteCtl.DetailsPointer = mutePtr;

            uint mmresult = mixerGetControlDetails(_hMixer, ref muteCtl,
                MIXER_OBJECTF.HMIXER, MIXER_GETCONTROLDETAILSF.VALUE);
            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                Marshal.FreeCoTaskMem(mutePtr);
                throw new MixerException("mixerGetControlDetails" , mmresult);
            }

            MIXERCONTROLDETAILS_BOOLEAN muteInfo
                = (MIXERCONTROLDETAILS_BOOLEAN)Marshal.PtrToStructure(mutePtr,
                typeof(MIXERCONTROLDETAILS_BOOLEAN));
            Marshal.FreeCoTaskMem(mutePtr);

            Debug.WriteLine("MixerAPI.IsMuteret:" + muteInfo.Value.ToString());

            return muteInfo.Value > 0;

        }
Ejemplo n.º 29
0
 private static extern MMSYSERR mixerSetControlDetails(IntPtr hmxobj, ref MIXERCONTROLDETAILS pmxcd, UInt32 fdwDetails);
Ejemplo n.º 30
0
 internal static extern int mixerSetControlDetails(IntPtr hmxobj, ref
                                                   MIXERCONTROLDETAILS pmxcd, int fdwDetails);
Ejemplo n.º 31
0
 internal static extern int mixerSetControlDetails(IntPtr hmxobj, ref 
     MIXERCONTROLDETAILS pmxcd, int fdwDetails);
Ejemplo n.º 32
0
 static extern uint mixerSetControlDetails(IntPtr hmxobj, ref MIXERCONTROLDETAILS pmxcd, MIXER flags);
Ejemplo n.º 33
0
        //Added this function since Values didn't seem to be working correctly for MuteSwitch
        //TODO: Re-evaluate what's necessary once thorough testing has been completed for XP
        public void SetMute(bool mute)
        {
            MIXERCONTROLDETAILS mcd = new MIXERCONTROLDETAILS();
            mcd.cbStruct = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
            mcd.dwControlID = ctrl.dwControlID; 
            mcd.cMultipleItems = 0;
            mcd.cChannels = 1;
            mcd.cbDetails = 4;
            mcd.paDetails = Marshal.AllocHGlobal((int)mcd.cbDetails);

            Marshal.WriteInt32(mcd.paDetails, mute ? 1 : 0);

            mixerSetControlDetails(IntPtr.Zero, ref mcd, 0x0 | 0x0);

            Marshal.FreeHGlobal(mcd.paDetails);
        }
Ejemplo n.º 34
0
        static void SetVolume(MixerInfo mi, VOLUME volume)
        {
            MIXERCONTROLDETAILS mcd = new MIXERCONTROLDETAILS();
            mcd.cbStruct = (uint)Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
            mcd.dwControlID = mi.volumeCtl;
            mcd.cMultipleItems = 0;
            mcd.cChannels = 2;
            mcd.cbDetails = (uint)Marshal.SizeOf(typeof(int));
            mcd.paDetails = Marshal.AllocHGlobal((int)mcd.cbDetails);

            Marshal.StructureToPtr(volume, mcd.paDetails, false);

            mixerSetControlDetails(IntPtr.Zero, ref mcd, MIXER.GETCONTROLDETAILSF_VALUE | MIXER.OBJECTF_MIXER);

            Marshal.FreeHGlobal(mcd.paDetails);
        }
Ejemplo n.º 35
0
    private static bool SetVolumeControl(int hmixer, MIXERCONTROL mxc, int volume)
    {
      // This function sets the value for a volume control. 
      // Returns True if successful 

      bool retValue;
      int rc;
      MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS();
      MIXERCONTROLDETAILS_UNSIGNED vol = new MIXERCONTROLDETAILS_UNSIGNED();

      mxcd.item = 0;
      mxcd.dwControlID = mxc.dwControlID;
      mxcd.cbStruct = Marshal.SizeOf(mxcd);
      mxcd.cbDetails = Marshal.SizeOf(vol);

      // Allocate a buffer for the control value buffer 
      mxcd.cChannels = 1;
      vol.dwValue = volume;

      // Copy the data into the control value buffer 
      mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof (MIXERCONTROLDETAILS_UNSIGNED)));
      Marshal.StructureToPtr(vol, mxcd.paDetails, false);

      // Set the control value 
      rc = mixerSetControlDetails(hmixer, ref mxcd, MIXER_SETCONTROLDETAILSF_VALUE);

      if (MMSYSERR_NOERROR == rc)
      {
        retValue = true;
      }
      else
      {
        retValue = false;
      }
      return retValue;
    }
Ejemplo n.º 36
0
 static uint mixerSetControlDetails(IntPtr hmxobj, ref MIXERCONTROLDETAILS pmxcd, MIXER_OBJECTF fdwDetails, MIXER_GETCONTROLDETAILSF getControlDetails)
 {
     uint flags = ((uint)fdwDetails | (uint)getControlDetails);
     return mixerSetControlDetails(hmxobj, ref pmxcd, flags);
 }
Ejemplo n.º 37
0
 public static extern MmResult mixerSetControlDetails(IntPtr hMixer, ref MIXERCONTROLDETAILS mixerControlDetails, MixerFlags dwDetailsFlags);
Ejemplo n.º 38
0
 public static extern int mixerSetControlDetails(IntPtr hmxobj, ref MIXERCONTROLDETAILS pmxcd, MIXER_SETCONTROLDETAILSFLAG fdwDetails);
Ejemplo n.º 39
0
        static uint mixerSetControlDetails(IntPtr hmxobj, ref MIXERCONTROLDETAILS pmxcd, MIXER_OBJECTF fdwDetails, MIXER_GETCONTROLDETAILSF getControlDetails)
        {
            uint flags = ((uint)fdwDetails | (uint)getControlDetails);

            return(mixerSetControlDetails(hmxobj, ref pmxcd, flags));
        }
Ejemplo n.º 40
0
 public static extern MmResult mixerSetControlDetails(IntPtr hMixer, ref MIXERCONTROLDETAILS mixerControlDetails, MixerFlags dwDetailsFlags);
Ejemplo n.º 41
0
		public static void RestoreState()
		{
			int index = 0;
			uint[] ctrl_list =
			{
				MIXERCONTROL_CONTROLTYPE_CUSTOM,
				MIXERCONTROL_CONTROLTYPE_BOOLEANMETER,
				MIXERCONTROL_CONTROLTYPE_SIGNEDMETER,
				MIXERCONTROL_CONTROLTYPE_PEAKMETER,
				MIXERCONTROL_CONTROLTYPE_BOOLEAN,
				MIXERCONTROL_CONTROLTYPE_ONOFF,
				MIXERCONTROL_CONTROLTYPE_MUTE,
				MIXERCONTROL_CONTROLTYPE_MONO,
				MIXERCONTROL_CONTROLTYPE_LOUDNESS,
				MIXERCONTROL_CONTROLTYPE_STEREOENH,
				MIXERCONTROL_CONTROLTYPE_BUTTON,
				MIXERCONTROL_CONTROLTYPE_DECIBELS,
				MIXERCONTROL_CONTROLTYPE_SIGNED,
				MIXERCONTROL_CONTROLTYPE_SLIDER,
				MIXERCONTROL_CONTROLTYPE_PAN,
				MIXERCONTROL_CONTROLTYPE_QSOUNDPAN,
				MIXERCONTROL_CONTROLTYPE_SINGLESELECT,
				MIXERCONTROL_CONTROLTYPE_MUX,
				MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT,
				MIXERCONTROL_CONTROLTYPE_MIXER,
				MIXERCONTROL_CONTROLTYPE_UNSIGNEDMETER,
				MIXERCONTROL_CONTROLTYPE_UNSIGNED,
				MIXERCONTROL_CONTROLTYPE_BASS,
				MIXERCONTROL_CONTROLTYPE_EQUALIZER,
				MIXERCONTROL_CONTROLTYPE_FADER,
				MIXERCONTROL_CONTROLTYPE_TREBLE,
				MIXERCONTROL_CONTROLTYPE_VOLUME,
				MIXERCONTROL_CONTROLTYPE_MICROTIME,
				MIXERCONTROL_CONTROLTYPE_MILLITIME,
				MIXERCONTROL_CONTROLTYPE_PERCENT,
			};
            
			int num_mixers = mixerGetNumDevs();
			int mixer = -1;
			int retval = -1;

			for(int i=0; i<num_mixers; i++)	// for each mixer
			{
				mixerOpen(out mixer, i, 0, 0, 0);
				MIXERCAPS mc = new MIXERCAPS();

				retval = mixerGetDevCaps(mixer, ref mc, Marshal.SizeOf(mc));
				if(retval == MMSYSERR_NOERROR)
				{
					int num_dest = mc.cDestinations;
					for(int j=0; j<num_dest; j++)		// for each destination line in this mixer
					{
						MIXERLINE dst_line = new MIXERLINE();
						dst_line.cbStruct = Marshal.SizeOf(dst_line);
						dst_line.dwDestination = j;

						retval = mixerGetLineInfo(mixer, ref dst_line, MIXER_GETLINEINFOF_DESTINATION);
						if(retval == MMSYSERR_NOERROR)
						{
							for(int k=0; k<30; k++)		// for each control in this destination line
							{
								MIXERLINECONTROLS dst_lc = new MIXERLINECONTROLS();
								int mcSize = 152;
								dst_lc.pamxctrl = Marshal.AllocCoTaskMem(mcSize);
								dst_lc.cbStruct = Marshal.SizeOf(dst_lc); 
								dst_lc.dwLineID = dst_line.dwLineID; 
								dst_lc.dwControl = ctrl_list[k]; 
								dst_lc.cControls = 1; 
								dst_lc.cbmxctrl = mcSize;

								// Get the control 
								retval = mixerGetLineControls(mixer, ref dst_lc, MIXER_GETLINECONTROLSF_ONEBYTYPE); 
								if(retval == MMSYSERR_NOERROR) 
								{ 
									MIXERCONTROL ctrl = new MIXERCONTROL();
									ctrl.cbStruct = mcSize; 
									// Copy the control into the destination structure 
									ctrl = (MIXERCONTROL)Marshal.PtrToStructure(dst_lc.pamxctrl, typeof(MIXERCONTROL)); 
									MIXERCONTROLDETAILS details = new MIXERCONTROLDETAILS();
									int size = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_SIGNED));
									details.dwControlID = ctrl.dwControlID; 
									details.cbDetails = size; 
									details.item = ctrl.cMultipleItems;
									if(details.item > 0) size *= details.item;
									details.paDetails = Marshal.AllocCoTaskMem(size); 
									details.cbStruct = Marshal.SizeOf(details); 
									details.cChannels = 1; 
									
									if(details.item > 0)
									{
										if(index != save.Count)
										{
											int rec_index = (int)save[index];
											int[] val = new int[details.item];
											for(int m=0; m<details.item; m++)
											{
												if(m == rec_index) val[m] = 1;
												else val[m] = 0;
											}
											Marshal.Copy(val, 0, details.paDetails, details.item);

											retval = mixerSetControlDetails(mixer, ref details, MIXER_GETCONTROLDETAILSF_VALUE); 
											if(retval == MMSYSERR_NOERROR)
												index++;
										}
									}
									else
									{
										MIXERCONTROLDETAILS_UNSIGNED val = new MIXERCONTROLDETAILS_UNSIGNED();
										val.dwValue = (int)save[index];
										Marshal.StructureToPtr(val, details.paDetails, false);

										retval = mixerSetControlDetails(mixer, ref details, MIXER_GETCONTROLDETAILSF_VALUE); 
										if(retval == MMSYSERR_NOERROR)
											index++;
									}
									Marshal.FreeCoTaskMem(details.paDetails);
								}
								Marshal.FreeCoTaskMem(dst_lc.pamxctrl);
							}

							int num_src = dst_line.cConnections;
							for(int k=0; k<num_src; k++)	// for each source line connected to this destination
							{
								MIXERLINE src_line = new MIXERLINE();
								src_line.cbStruct = dst_line.cbStruct;
								src_line.dwDestination = dst_line.dwDestination;
								src_line.dwSource = k;

								retval = mixerGetLineInfo(mixer, ref src_line, MIXER_GETLINEINFOF_SOURCE);
								if(retval == MMSYSERR_NOERROR)
								{
									for(int l=0; l<30; l++)	// for each control in this source line
									{
										MIXERLINECONTROLS src_lc = new MIXERLINECONTROLS();
										int mcSize = 152;
										src_lc.pamxctrl = Marshal.AllocCoTaskMem(mcSize);
										src_lc.cbStruct = Marshal.SizeOf(src_lc); 
										src_lc.dwLineID = src_line.dwLineID; 
										src_lc.dwControl = ctrl_list[l]; 
										src_lc.cControls = 1; 
										src_lc.cbmxctrl = mcSize;

										// Get the control 
										retval = mixerGetLineControls(mixer, ref src_lc, MIXER_GETLINECONTROLSF_ONEBYTYPE); 
										if(retval == MMSYSERR_NOERROR) 
										{ 
											MIXERCONTROL ctrl = new MIXERCONTROL();
											ctrl.cbStruct = mcSize; 
											// Copy the control into the destination structure 
											ctrl = (MIXERCONTROL)Marshal.PtrToStructure(src_lc.pamxctrl, typeof(MIXERCONTROL)); 
											MIXERCONTROLDETAILS details = new MIXERCONTROLDETAILS();
											int size;
											if(l<20) size = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_SIGNED));
											else size = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED));
											details.dwControlID = ctrl.dwControlID; 
											details.paDetails = Marshal.AllocCoTaskMem(size); 
											details.cbStruct = Marshal.SizeOf(details); 
											details.cChannels = 1; 
											details.item = ctrl.cMultipleItems; 
											details.cbDetails = size; 
									
											if(details.item > 0)
											{
												int rec_index = (int)save[index];
												MIXERCONTROLDETAILS_UNSIGNED[] val = new MIXERCONTROLDETAILS_UNSIGNED[details.item];
												for(int m=0; m<details.item; m++)
													val[m] = new MIXERCONTROLDETAILS_UNSIGNED();
												val[rec_index].dwValue = 1;
												Marshal.StructureToPtr(val[0], details.paDetails, false);
											}
											else
											{
												MIXERCONTROLDETAILS_UNSIGNED val = new MIXERCONTROLDETAILS_UNSIGNED();
												val.dwValue = (int)save[index];
												Marshal.StructureToPtr(val, details.paDetails, false);
											}

											retval = mixerSetControlDetails(mixer, ref details, MIXER_GETCONTROLDETAILSF_VALUE); 
											if(retval == MMSYSERR_NOERROR)
												index++;

											Marshal.FreeCoTaskMem(details.paDetails);
										}
										Marshal.FreeCoTaskMem(src_lc.pamxctrl);
									}
								}
							}							
						}
					}
				}
			}
			mixerClose(mixer);
		}
Ejemplo n.º 42
0
        public static void Mute(bool mute)
        {
            // Check if this is vista or XP
            if (System.Environment.OSVersion.Version.Major >= 6)
            {
                EndpointVolume epVol = new EndpointVolume();
                epVol.Mute = mute;
                epVol.Dispose();
            }
            else
            {
                int mixerID = 0;

                if (mixerOpen(out mixerID, 0, 0, 0, 0) == MMSYSERR_NOERROR)
                {
                    MIXERLINE line = new MIXERLINE();
                    line.cbStruct        = Marshal.SizeOf(line);
                    line.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;

                    if (mixerGetLineInfoA(mixerID, ref line, MIXER_GETLINEINFOF_COMPONENTTYPE) == MMSYSERR_NOERROR)
                    {
                        int          sizeofMIXERCONTROL = 152;
                        MIXERCONTROL mixerControl       = new MIXERCONTROL();

                        MIXERLINECONTROLS lineControl = new MIXERLINECONTROLS();

                        lineControl.pamxctrl  = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL);
                        lineControl.cbStruct  = Marshal.SizeOf(lineControl);
                        lineControl.dwLineID  = line.dwLineID;
                        lineControl.dwControl = MIXERCONTROL_CONTROLTYPE_MUTE;
                        lineControl.cControls = 1;
                        lineControl.cbmxctrl  = sizeofMIXERCONTROL;

                        mixerControl.cbStruct = sizeofMIXERCONTROL;

                        if (mixerGetLineControlsA(mixerID, ref lineControl, MIXER_GETLINECONTROLSF_ONEBYTYPE) == MMSYSERR_NOERROR)
                        {
                            mixerControl = (MIXERCONTROL)Marshal.PtrToStructure(lineControl.pamxctrl, typeof(MIXERCONTROL));

                            MIXERCONTROLDETAILS         controlDetails = new MIXERCONTROLDETAILS();
                            MIXERCONTROLDETAILS_BOOLEAN muteValue      = new MIXERCONTROLDETAILS_BOOLEAN();

                            controlDetails.item        = 0;
                            controlDetails.dwControlID = mixerControl.dwControlID;
                            controlDetails.cbStruct    = Marshal.SizeOf(controlDetails);
                            controlDetails.cbDetails   = Marshal.SizeOf(muteValue);
                            controlDetails.cChannels   = 1;

                            muteValue.dwValue = Convert.ToInt32(mute);

                            controlDetails.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(muteValue));

                            Marshal.StructureToPtr(muteValue, controlDetails.paDetails, false);

                            int rc = mixerSetControlDetails(mixerID, ref controlDetails, MIXER_SETCONTROLDETAILSF_VALUE);

                            Marshal.FreeCoTaskMem(controlDetails.paDetails);
                            Marshal.FreeCoTaskMem(lineControl.pamxctrl);
                        }
                    }
                }
            }
        }
Ejemplo n.º 43
0
        static VOLUME GetVolume(MixerInfo mi)
        {
            MIXERCONTROLDETAILS mcd = new MIXERCONTROLDETAILS();
            mcd.cbStruct = (uint)Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
            mcd.dwControlID = mi.volumeCtl;
            mcd.cMultipleItems = 0;
            mcd.cChannels = 2;
            mcd.cbDetails = (uint)Marshal.SizeOf(typeof(int));
            mcd.paDetails = Marshal.AllocHGlobal((int)mcd.cbDetails);

            mixerGetControlDetails(IntPtr.Zero, ref mcd, MIXER.GETCONTROLDETAILSF_VALUE | MIXER.OBJECTF_MIXER);

            VOLUME rtn = (VOLUME)Marshal.PtrToStructure(mcd.paDetails, typeof(VOLUME));

            Marshal.FreeHGlobal(mcd.paDetails);

            return rtn;
        }
Ejemplo n.º 44
0
        public static void Mute(bool mute)
        {
            // Check if this is vista or XP
            if (System.Environment.OSVersion.Version.Major >= 6)
            {
                EndpointVolume epVol = new EndpointVolume();
                epVol.Mute = mute;
                epVol.Dispose();
            }
            else
            {
                int mixerID = 0;

                if (mixerOpen(out mixerID, 0, 0, 0, 0) == MMSYSERR_NOERROR)
                {
                    MIXERLINE line = new MIXERLINE();
                    line.cbStruct = Marshal.SizeOf(line);
                    line.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;

                    if (mixerGetLineInfoA(mixerID, ref line, MIXER_GETLINEINFOF_COMPONENTTYPE) == MMSYSERR_NOERROR)
                    {
                        int sizeofMIXERCONTROL = 152;
                        MIXERCONTROL mixerControl = new MIXERCONTROL();

                        MIXERLINECONTROLS lineControl = new MIXERLINECONTROLS();

                        lineControl.pamxctrl = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL);
                        lineControl.cbStruct = Marshal.SizeOf(lineControl);
                        lineControl.dwLineID = line.dwLineID;
                        lineControl.dwControl = MIXERCONTROL_CONTROLTYPE_MUTE;
                        lineControl.cControls = 1;
                        lineControl.cbmxctrl = sizeofMIXERCONTROL;

                        mixerControl.cbStruct = sizeofMIXERCONTROL;

                        if (mixerGetLineControlsA(mixerID, ref lineControl, MIXER_GETLINECONTROLSF_ONEBYTYPE) == MMSYSERR_NOERROR)
                        {
                            mixerControl = (MIXERCONTROL)Marshal.PtrToStructure(lineControl.pamxctrl, typeof(MIXERCONTROL));

                            MIXERCONTROLDETAILS controlDetails = new MIXERCONTROLDETAILS();
                            MIXERCONTROLDETAILS_BOOLEAN muteValue = new MIXERCONTROLDETAILS_BOOLEAN();

                            controlDetails.item = 0;
                            controlDetails.dwControlID = mixerControl.dwControlID;
                            controlDetails.cbStruct = Marshal.SizeOf(controlDetails);
                            controlDetails.cbDetails = Marshal.SizeOf(muteValue);
                            controlDetails.cChannels = 1;

                            muteValue.dwValue = Convert.ToInt32(mute);

                            controlDetails.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(muteValue));

                            Marshal.StructureToPtr(muteValue, controlDetails.paDetails, false);

                            int rc = mixerSetControlDetails(mixerID, ref controlDetails, MIXER_SETCONTROLDETAILSF_VALUE);

                            Marshal.FreeCoTaskMem(controlDetails.paDetails);
                            Marshal.FreeCoTaskMem(lineControl.pamxctrl);
                        }
                    }
                }
            }
        }
Ejemplo n.º 45
0
        static bool IsMuted(MixerInfo mi)
        {
            MIXERCONTROLDETAILS mcd = new MIXERCONTROLDETAILS();
            mcd.cbStruct = (uint)Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
            mcd.dwControlID = mi.muteCtl;
            mcd.cMultipleItems = 0;
            mcd.cChannels = 1;
            mcd.cbDetails = 4;
            mcd.paDetails = Marshal.AllocHGlobal((int)mcd.cbDetails);

            mixerGetControlDetails(IntPtr.Zero, ref mcd, MIXER.GETCONTROLDETAILSF_VALUE | MIXER.OBJECTF_MIXER);

            int rtn = Marshal.ReadInt32(mcd.paDetails);

            Marshal.FreeHGlobal(mcd.paDetails);

            return rtn != 0;
        }
Ejemplo n.º 46
0
		private static bool SetVolume(int mixerID, uint dst_type, uint src_type, int val)
		{
			int mixer;
			MIXERCONTROL volCtrl = new MIXERCONTROL();
			int currentVol = GetVolume(mixerID, dst_type, src_type);
			if(currentVol == val) return true;

			mixerOpen(out mixer, mixerID, 0, 0, 0);
			bool success = GetControlByType(mixer, dst_type, src_type, MIXERCONTROL_CONTROLTYPE_VOLUME, out volCtrl);
			if(success == true)
			{
				if(val>volCtrl.lMaximum) val = volCtrl.lMaximum; 
				if(val<volCtrl.lMinimum) val = volCtrl.lMinimum; 

				MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS(); 
				MIXERCONTROLDETAILS_UNSIGNED vol = new MIXERCONTROLDETAILS_UNSIGNED(); 

				mxcd.item = 0; 
				mxcd.dwControlID = volCtrl.dwControlID; 
				mxcd.cbStruct = Marshal.SizeOf(mxcd); 
				mxcd.cbDetails = Marshal.SizeOf(vol); 

				// Allocate a buffer for the control value buffer 
				mxcd.cChannels = 1; 
				vol.dwValue = val; 

				// Copy the data into the control value buffer 
				mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED))); 
				Marshal.StructureToPtr(vol, mxcd.paDetails,false); 

				// Set the control value 
				int retval = mixerSetControlDetails(mixer, ref mxcd, MIXER_SETCONTROLDETAILSF_VALUE); 
				if(retval == MMSYSERR_NOERROR) 
				{
					currentVol = GetVolume(mixerID, dst_type, src_type);
					if(currentVol != val)
						success = false;
					else success = true;
				}
				else success = false;
				Marshal.FreeCoTaskMem(mxcd.paDetails);
			}
			else success = false;
			mixerClose(mixer);
			return success;
		}
Ejemplo n.º 47
0
        void SetMute(bool flag)
        {
            MIXERCONTROLDETAILS muteCtl = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_BOOLEAN muteVal = new MIXERCONTROLDETAILS_BOOLEAN();
            muteVal.Value = flag ? 1 : 0;

            Debug.WriteLine("MixerAPI.SetMute:" + flag.ToString());

            IntPtr mutePtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(new MIXERCONTROLDETAILS_BOOLEAN()));
            Marshal.StructureToPtr(muteVal, mutePtr, false);

            muteCtl.StructSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS());
            muteCtl.ControlID = _muteID;
            muteCtl.Channels = 1;
            muteCtl.MultipleItems = 0;
            muteCtl.DetailsItemSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS_BOOLEAN());
            muteCtl.DetailsPointer = mutePtr;

            uint mmresult = mixerSetControlDetails(_hMixer, ref muteCtl,
                MIXER_OBJECTF.HMIXER, MIXER_GETCONTROLDETAILSF.VALUE);
            Marshal.FreeCoTaskMem(mutePtr);

            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                throw new Exception("mixerSetControlDetails" + mmresult.ToString());
            }
        }
Ejemplo n.º 48
0
 public static extern int mixerGetControlDetailsA(int hmxobj, ref MIXERCONTROLDETAILS pmxcd, int fdwDetails);
Ejemplo n.º 49
0
		private static bool GetMute(int mixerID, uint dst_type, uint src_type)
		{
			int mixer;
			MIXERCONTROL muteCtrl = new MIXERCONTROL();
			int val;

			mixerOpen(out mixer, mixerID, 0, 0, 0);
			bool success = GetControlByType(mixer, dst_type, src_type, MIXERCONTROL_CONTROLTYPE_MUTE, out muteCtrl);
			if(success == true)
			{
				MIXERCONTROLDETAILS details = new MIXERCONTROLDETAILS();

				int sizeofMIXERCONTROLDETAILS = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS)); 
				int sizeofMIXERCONTROLDETAILS_UNSIGNED = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED)); 
				details.cbStruct = sizeofMIXERCONTROLDETAILS; 
				details.dwControlID = muteCtrl.dwControlID; 
				details.paDetails = Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED); 
				details.cChannels = 1; 
				details.item = 0; 
				details.cbDetails = sizeofMIXERCONTROLDETAILS_UNSIGNED; 

				int retval = mixerGetControlDetails(mixer, ref details, MIXER_GETCONTROLDETAILSF_VALUE); 
				if(retval == MMSYSERR_NOERROR)				
				{
					MIXERCONTROLDETAILS_UNSIGNED du = (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(details.paDetails, typeof(MIXERCONTROLDETAILS_UNSIGNED)); 
					val = du.dwValue; 
				}
				else val = -1;
				Marshal.FreeCoTaskMem(details.paDetails);
			}
			else val = -1;
			mixerClose(mixer);
			return (val == 1);
		}
Ejemplo n.º 50
0
        /// <summary>
        /// Used to get or set the values of this switch.
        /// </summary>
        /// 

        //Added this function since Values didn't seem to be working correctly for MuteSwitch
        //TODO: Re-evaluate what's necessary once thorough testing has been completed for XP
        public bool IsMuted()
        {
            MIXERCONTROLDETAILS mcd = new MIXERCONTROLDETAILS();
            mcd.cbStruct = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
            mcd.dwControlID = ctrl.dwControlID;
            mcd.cMultipleItems = 0;
            mcd.cChannels = 1;
            mcd.cbDetails = 4;
            mcd.paDetails = Marshal.AllocHGlobal((int)mcd.cbDetails);

            mixerGetControlDetailsA(IntPtr.Zero, ref mcd, 0x0 | 0x0);

            int rtn = Marshal.ReadInt32(mcd.paDetails);

            Marshal.FreeHGlobal(mcd.paDetails);

            return rtn != 0;
        }
Ejemplo n.º 51
0
		private static bool SetBool(int mixer, MIXERCONTROL ctrl, bool b)
		{
			bool current;
			if(!GetBool(mixer, ctrl, out current))
				return false;

			if(current == b) 
				return true;

            MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS(); 
			MIXERCONTROLDETAILS_UNSIGNED val = new MIXERCONTROLDETAILS_UNSIGNED(); 

			mxcd.item = 0; 
			mxcd.dwControlID = ctrl.dwControlID; 
			mxcd.cbStruct = Marshal.SizeOf(mxcd); 
			mxcd.cbDetails = Marshal.SizeOf(val); 

			// Allocate a buffer for the control value buffer 
			mxcd.cChannels = 1; 
			if(b) val.dwValue = 1;
			else val.dwValue = 0;

			// Copy the data into the control value buffer 
			mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(val)); 
			Marshal.StructureToPtr(val, mxcd.paDetails, false); 

			// Set the control value 
			int retval = mixerSetControlDetails(mixer, ref mxcd, MIXER_SETCONTROLDETAILSF_VALUE); 
			if(retval != MMSYSERR_NOERROR) 
			{
				Marshal.FreeCoTaskMem(mxcd.paDetails);
				return false;
			}
			Marshal.FreeCoTaskMem(mxcd.paDetails);

			if(!GetBool(mixer, ctrl, out current))
				return false;
			
			if(current != b)
				return false;
			else return true;
		}
Ejemplo n.º 52
0
    private static bool GetVolumeControl(int hmixer, int componentType, int ctrlType, out MIXERCONTROL mxc,
                                         out int vCurrentVol)
    {
      // This function attempts to obtain a mixer control. 
      // Returns True if successful. 
      MIXERLINECONTROLS mxlc = new MIXERLINECONTROLS();
      MIXERLINE mxl = new MIXERLINE();
      MIXERCONTROLDETAILS pmxcd = new MIXERCONTROLDETAILS();
      MIXERCONTROLDETAILS_UNSIGNED du = new MIXERCONTROLDETAILS_UNSIGNED();
      mxc = new MIXERCONTROL();
      int rc;
      bool retValue;
      vCurrentVol = -1;

      mxl.cbStruct = Marshal.SizeOf(mxl);
      mxl.dwComponentType = componentType;

      rc = mixerGetLineInfoA(hmixer, ref mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);

      if (MMSYSERR_NOERROR == rc)
      {
        int sizeofMIXERCONTROL = 152;
        int ctrl = Marshal.SizeOf(typeof (MIXERCONTROL));
        mxlc.pamxctrl = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL);
        mxlc.cbStruct = Marshal.SizeOf(mxlc);
        mxlc.dwLineID = mxl.dwLineID;
        mxlc.dwControl = ctrlType;
        mxlc.cControls = 1;
        mxlc.cbmxctrl = sizeofMIXERCONTROL;

        // Allocate a buffer for the control 
        mxc.cbStruct = sizeofMIXERCONTROL;

        // Get the control 
        rc = mixerGetLineControlsA(hmixer, ref mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);

        if (MMSYSERR_NOERROR == rc)
        {
          retValue = true;

          // Copy the control into the destination structure 
          mxc = (MIXERCONTROL)Marshal.PtrToStructure(mxlc.pamxctrl, typeof (MIXERCONTROL));
        }
        else
        {
          retValue = false;
        }
        int sizeofMIXERCONTROLDETAILS = Marshal.SizeOf(typeof (MIXERCONTROLDETAILS));
        int sizeofMIXERCONTROLDETAILS_UNSIGNED = Marshal.SizeOf(typeof (MIXERCONTROLDETAILS_UNSIGNED));
        pmxcd.cbStruct = sizeofMIXERCONTROLDETAILS;
        pmxcd.dwControlID = mxc.dwControlID;
        pmxcd.paDetails =
          Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED);
        pmxcd.cChannels = 1;
        pmxcd.item = 0;
        pmxcd.cbDetails = sizeofMIXERCONTROLDETAILS_UNSIGNED;

        rc = mixerGetControlDetailsA(hmixer, ref pmxcd, MIXER_GETCONTROLDETAILSF_VALUE);

        du =
          (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(pmxcd.paDetails, typeof (MIXERCONTROLDETAILS_UNSIGNED));

        vCurrentVol = du.dwValue;

        return retValue;
      }

      retValue = false;
      return retValue;
    }
Ejemplo n.º 53
0
		private static bool GetUnsigned(int mixer, MIXERCONTROL ctrl, out int num)
		{
			MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS();
			num = 0;

			int sizeofMIXERCONTROLDETAILS = Marshal.SizeOf(mxcd);
			int sizeofMIXERCONTROLDETAILS_UNSIGNED = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED)); 
			mxcd.cbStruct = sizeofMIXERCONTROLDETAILS; 
			mxcd.dwControlID = ctrl.dwControlID; 
			mxcd.paDetails = Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED); 
			mxcd.cChannels = 1; 
			mxcd.item = 0; 
			mxcd.cbDetails = sizeofMIXERCONTROLDETAILS_UNSIGNED; 

			int retval = mixerGetControlDetails(mixer, ref mxcd, MIXER_GETCONTROLDETAILSF_VALUE);
			if(retval != MMSYSERR_NOERROR)
			{
				Marshal.FreeCoTaskMem(mxcd.paDetails);
				return false;
			}

			MIXERCONTROLDETAILS_UNSIGNED du = 
				(MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(mxcd.paDetails, typeof(MIXERCONTROLDETAILS_UNSIGNED));
			num = du.dwValue;

			Marshal.FreeCoTaskMem(mxcd.paDetails);
			return true;
		}
Ejemplo n.º 54
0
 private static extern int mixerSetControlDetails(int hmxobj, ref MIXERCONTROLDETAILS pmxcd, int fdwDetails);
Ejemplo n.º 55
0
		private static bool SetUnsigned(int mixer, MIXERCONTROL ctrl, int num)
		{
			int current_val;
			if(!GetUnsigned(mixer, ctrl, out current_val))
				return false;

			if(current_val == num)
				return true;
            
			if(num > ctrl.lMaximum) num = ctrl.lMaximum;
			if(num < ctrl.lMinimum) num = ctrl.lMinimum;

			MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS();
			MIXERCONTROLDETAILS_UNSIGNED val = new MIXERCONTROLDETAILS_UNSIGNED();

			mxcd.item = 0;
			mxcd.dwControlID = ctrl.dwControlID;
			mxcd.cbStruct = Marshal.SizeOf(mxcd);
			mxcd.cbDetails = Marshal.SizeOf(val);

			mxcd.cChannels = 1;
			val.dwValue = num;

			mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(val));
			Marshal.StructureToPtr(val, mxcd.paDetails, false);

			int retval = mixerSetControlDetails(mixer, ref mxcd, MIXER_SETCONTROLDETAILSF_VALUE);
			Marshal.FreeCoTaskMem(mxcd.paDetails);

			if(retval != MMSYSERR_NOERROR)
				return false;
		
			if(!GetUnsigned(mixer, ctrl, out current_val))
				return false;

			if(current_val == num)
				return true;
			else
				return false;
		}
Ejemplo n.º 56
0
		public static extern uint mixerGetControlDetails(uint hmxobj, ref MIXERCONTROLDETAILS pmxcd, uint fdwDetails);
Ejemplo n.º 57
0
		private static bool SetMute(int mixerID, uint dst_type, uint src_type, bool val)
		{
			int mixer;
			MIXERCONTROL muteCtrl = new MIXERCONTROL();
			bool currentMute = GetMute(mixerID, dst_type, src_type);
			if(currentMute == val) return true;

			mixerOpen(out mixer, mixerID, 0, 0, 0);
			bool success = GetControlByType(mixer, dst_type, src_type, MIXERCONTROL_CONTROLTYPE_MUTE, out muteCtrl);
			if(success == true)
			{

				MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS(); 
				MIXERCONTROLDETAILS_UNSIGNED mute = new MIXERCONTROLDETAILS_UNSIGNED(); 

				mxcd.item = 0; 
				mxcd.dwControlID = muteCtrl.dwControlID; 
				mxcd.cbStruct = Marshal.SizeOf(mxcd); 
				mxcd.cbDetails = Marshal.SizeOf(mute); 

				// Allocate a buffer for the control value buffer 
				mxcd.cChannels = 1; 
				if(val)	mute.dwValue = 1;
				else mute.dwValue = 0;

				// Copy the data into the control value buffer 
				mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED))); 
				Marshal.StructureToPtr(mute, mxcd.paDetails,false); 

				// Set the control value 
				int retval = mixerSetControlDetails(mixer, ref mxcd, MIXER_SETCONTROLDETAILSF_VALUE); 
				if(retval == MMSYSERR_NOERROR) 
				{
					currentMute = GetMute(mixerID, dst_type, src_type);
					if(currentMute != val)
						success = false;
					else success = true;
				}
				else success = false;
				Marshal.FreeCoTaskMem(mxcd.paDetails);
			}
			else success = false;
			mixerClose(mixer);
			return success;
		}