Subversion Repositories group.NITPanels

Rev

Rev 16 | Blame | Compare with Previous | Last modification | View Log | RSS feed

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace NITNavComm {

    public class VolumeControl {

        [DllImport("VolControlLib.dll")]
        public static extern int _getDevCount(out uint count);

        [DllImport("VolControlLib.dll",CharSet = CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.LPWStr)]
        public static extern string _getDevName(uint dev);

        [DllImport("VolControlLib.dll")]
        public static extern uint _getDevVolume(uint dev, out float volume);

        [DllImport("VolControlLib.dll")]
        public static extern uint _setDevVolume(uint dev, float volume);

        public uint deviceCount { get; set; }
        public List<string> devices { get; set; }

        public uint selectedDeviceIndex { get; set; }


        public VolumeControl() {
            uint count = 0;
            _getDevCount(out count);
            this.deviceCount = count;

            devices = new List<string>();
            if (this.deviceCount > 0) {
                for (uint i = 0; i < this.deviceCount; i++) {
                    this.devices.Add(this.getDeviceName(i));
                }
            }

        }

        public String getDeviceName(uint dev) {
            string s = _getDevName(dev);
            return s;
        }

        public String getDeviceName() {
            return this.getDeviceName(this.selectedDeviceIndex);
        }

        public float getDeviceVolume(uint dev) {
            float volume = 0.0F;
            _getDevVolume(dev, out volume);
            return volume;
        }

        public float getDeviceVolume() {
            return this.getDeviceVolume(this.selectedDeviceIndex);
        }

        public void setDeviceVolume(uint dev, float volume) {
            _setDevVolume(dev, volume);
        }

        public void setDeviceVolume(float volume) {
            this.setDeviceVolume(this.selectedDeviceIndex, volume);
        }

    }
}