示例#1
0
        public SwitcherLib(string configFile, bool useDefault)
        {
            string exeDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            ConfigPath = Path.Combine(exeDir, configFile);
            LoadConfig();
            malCtrl = getAndInitMalcolmControl();
            if (config.DefaultProfile != null && useDefault)
            {
                SetProfile(int.Parse(config.DefaultProfile.ToString()));
            }
        }
示例#2
0
        private static MalcolmControl getAndInitMalcolmControl()
        {
            MalcolmControl malCtrl = new MalcolmControl();

            string appId       = "Sound Blaster Z-Series Control Panel";
            string playbackId  = null;
            string recordId    = null;
            string adapterName = null;

            MalLgcyLib.GetLastEndpointID(appId, ref playbackId, ref recordId, ref adapterName);

            string malcolmClsId = MalLgcyLib.GetMalcolmCLSID(playbackId);

            MalCtrlInitResult bindResult = MalCtrlInitResult.Unknown;

            // Binding does usually not succeed on the first try, so try until it does or I tell it to quit.
            int       tryCounter = 0;
            const int maxTries   = 5;

            while (bindResult != MalCtrlInitResult.Success && tryCounter <= maxTries)
            {
                bindResult = malCtrl.BindPlaybackEndpoint(malcolmClsId, playbackId);
                tryCounter++;
            }

            if (bindResult != MalCtrlInitResult.Success)
            {
                throw new Exception("Could not bind to the playback endpoint. ({bindResult})");
            }
            else
            {
                bool selectResult = malCtrl.SelectPlaybackEndpoint(playbackId);
            }

            return(malCtrl);
        }