} // cmdStop_Click private void cmdUseDevices_Click(object sender, EventArgs e) { try { // logging MethodBase myMethod = new StackTrace().GetFrame(0).GetMethod(); MethodBeginLogging(myMethod); DeviceInNo = (int)comboWaveIn.SelectedValue; DeviceOutNo = (int)comboWaveOut.SelectedValue; SetText(string.Format("DeviceIn set to {0} -- DeviceOut set to {1}", DeviceInNo.ToString(), DeviceOutNo.ToString())); micIn.BufferMilliseconds = 100; micIn.NumberOfBuffers = 3; micIn.DeviceNumber = DeviceInNo; MyState = DTMFCommandStates.ignore; SpeakIt("Welcome to Rumble!"); LoadConfig("0"); analyzer = new LiveAudioDtmfAnalyzer(micIn, forceMono: false); analyzer.DtmfToneStarted += Analyzer_DtmfToneStarted; analyzer.DtmfToneStopped += Analyzer_DtmfToneStopped; cmdListen.Enabled = true; // logging MethodEndLogging(myMethod); } // try catch (Exception ex) { UtilityMethods.ExceptionHandler(ex, TraceString); } // catch } // cmdUseDevices_Click
} // Disconnect private void ResetDTMFCommandState() { try { // logging MethodBase myMethod = new StackTrace().GetFrame(0).GetMethod(); MethodBeginLogging(myMethod); CurrentDTMFCommand = string.Empty; FinalDTMFCommand = string.Empty; MyState = DTMFCommandStates.ignore; MumbleUnmute(); // logging MethodEndLogging(myMethod); } // try catch (Exception ex) { UtilityMethods.ExceptionHandler(ex, TraceString); } // catch } // ResetDTMFCommandState
} // StopIDTimerJob private void ProcessDTMFCommand(string DTMFCommand, DTMFCommandStates CommandState) { try { // logging MethodBase myMethod = new StackTrace().GetFrame(0).GetMethod(); MethodBeginLogging(myMethod); SetText("Processing Command -- " + DTMFCommand); // only proceed is there's a complete command to process if (!string.IsNullOrEmpty(DTMFCommand)) { switch (CommandState) { case DTMFCommandStates.ignore: case DTMFCommandStates.isCommand: case DTMFCommandStates.isNotDisconnect: case DTMFCommandStates.isAdminSettingORChannelChange: case DTMFCommandStates.isAdminSetting: case DTMFCommandStates.isChangeChannel: case DTMFCommandStates.isAdminSettingNotFinal: case DTMFCommandStates.isChannelChangeNoChannelNumber: case DTMFCommandStates.isChannelChangeNotFinal: break; case DTMFCommandStates.isDisconnect: // disconnect Disconnect(); ResetDTMFCommandState(); break; case DTMFCommandStates.isLoadConfig: // load config // get config # string configNumber = DTMFCommand.Substring(1, 1); LoadConfig(configNumber); ResetDTMFCommandState(); break; case DTMFCommandStates.isAdminSettingFinal: // change admin setting // get admin setting number and setting value number string adminSetting = DTMFCommand.Substring(1, 2); string adminSettingValue = DTMFCommand.Substring(4, 1); ChangeAdminSetting(adminSetting, adminSettingValue); ResetDTMFCommandState(); break; case DTMFCommandStates.isChannelChangeFinal: // change channel // get server number and channel number string serverNumber = DTMFCommand.Substring(1, 3); string channelNumber = DTMFCommand.Substring(5, 1); ChangeChannel(serverNumber, channelNumber); ResetDTMFCommandState(); break; default: break; } // switch } // if // logging MethodEndLogging(myMethod); } // try catch (Exception ex) { UtilityMethods.ExceptionHandler(ex, TraceString); } // catch } // ProcessDTMFCommand
} // Analyzer_DtmfToneStarted private void Analyzer_DtmfToneStopped(DtmfToneEnd obj) { try { // logging MethodBase myMethod = new StackTrace().GetFrame(0).GetMethod(); MethodBeginLogging(myMethod); string currentDTMFChar = GetDTMFShortHand(obj.DtmfTone.Key.ToString()); bool fallThrough = false; // GET FIRST CHARACTER // is this the beginning of a new command? if (string.IsNullOrEmpty(CurrentDTMFCommand)) { // is this character initiating a new command? (#) if (currentDTMFChar == @"#") { MyState = DTMFCommandStates.isCommand; CurrentDTMFCommand = currentDTMFChar; fallThrough = true; } // if else { ResetDTMFCommandState(); } // else } // if // GET SECOND CHARACTER // command has started, get 2nd char if (MyState == DTMFCommandStates.isCommand && fallThrough == false) { if (currentDTMFChar == @"*") { // 2nd position is *, command is #* MyState = DTMFCommandStates.isDisconnect; CurrentDTMFCommand += currentDTMFChar; FinalDTMFCommand = CurrentDTMFCommand; } // if // 2nd char is NOT *, so it MUST be 0-9 else if (IsNumeric(currentDTMFChar)) { MyState = DTMFCommandStates.isNotDisconnect; CurrentDTMFCommand += currentDTMFChar; fallThrough = true; } // else if // illegal char passed, reset else { ResetDTMFCommandState(); } // else } // if // GET THIRD CHARACTER // command has started and is not a disconnect, get 3rd char if (MyState == DTMFCommandStates.isNotDisconnect && fallThrough == false) { // if 3rd char is * this is a config change if (currentDTMFChar == @"*") { MyState = DTMFCommandStates.isLoadConfig; CurrentDTMFCommand += currentDTMFChar; FinalDTMFCommand = CurrentDTMFCommand; } // if // if 3rd char is 0-9, this is isAdminSettingORChannelChange else if (IsNumeric(currentDTMFChar)) { MyState = DTMFCommandStates.isAdminSettingORChannelChange; CurrentDTMFCommand += currentDTMFChar; fallThrough = true; } // else if // illegal char passed, reset else { ResetDTMFCommandState(); } // else } // if // GET FOURTH CHARACTER //command has started, and is either Admin Setting or Channel Change, get 4th char if (MyState == DTMFCommandStates.isAdminSettingORChannelChange && fallThrough == false) { // if 4th char is # this is an Admin Setting change if (currentDTMFChar == @"#") { MyState = DTMFCommandStates.isAdminSetting; CurrentDTMFCommand += currentDTMFChar; fallThrough = true; } // if // if 4th char is 0-9, this is a channel change else if (IsNumeric(currentDTMFChar)) { MyState = DTMFCommandStates.isChangeChannel; CurrentDTMFCommand += currentDTMFChar; fallThrough = true; } // else if // illegal char passed, reset else { ResetDTMFCommandState(); } // else } // if // GET FIFTH CHARACTER //command has started, and is Admin Setting, get 5th char if (MyState == DTMFCommandStates.isAdminSetting && fallThrough == false) { // Admin Setting change, 5th char is 0-9 if (IsNumeric(currentDTMFChar)) { MyState = DTMFCommandStates.isAdminSettingNotFinal; CurrentDTMFCommand += currentDTMFChar; fallThrough = true; } // if // illegal char passed, reset else { ResetDTMFCommandState(); } // else } // if //command has started, and is Channel Change, get 5th char if (MyState == DTMFCommandStates.isChangeChannel && fallThrough == false) { // Admin Setting change, 5th char is # if (currentDTMFChar == @"#") { MyState = DTMFCommandStates.isChannelChangeNoChannelNumber; CurrentDTMFCommand += currentDTMFChar; fallThrough = true; } // if // illegal char passed, reset else { ResetDTMFCommandState(); } // else } // if //GET SIXTH CHARACTER // command has started, is Admin Setting, get 6th char if (MyState == DTMFCommandStates.isAdminSettingNotFinal && fallThrough == false) { // Admin Setting change, 6th char is * if (currentDTMFChar == @"*") { MyState = DTMFCommandStates.isAdminSettingFinal; CurrentDTMFCommand += currentDTMFChar; FinalDTMFCommand = CurrentDTMFCommand; fallThrough = true; } // if // illegal char passed, reset else { ResetDTMFCommandState(); } // else } // if // command has started, is Channel Change, get 6th char if (MyState == DTMFCommandStates.isChannelChangeNoChannelNumber && fallThrough == false) { // Channel Change, 6th char is 0-9 if (IsNumeric(currentDTMFChar)) { MyState = DTMFCommandStates.isChannelChangeNotFinal; CurrentDTMFCommand += currentDTMFChar; fallThrough = true; } // if // illegal char passed, reset else { ResetDTMFCommandState(); } // else } // if //GET SEVENTH CHARACTER if (MyState == DTMFCommandStates.isChannelChangeNotFinal && fallThrough == false) { // Channel Change, 7th char is * if (currentDTMFChar == @"*") { MyState = DTMFCommandStates.isChannelChangeFinal; CurrentDTMFCommand += currentDTMFChar; FinalDTMFCommand = CurrentDTMFCommand; fallThrough = true; } // if // illegal char passed, reset else { ResetDTMFCommandState(); } // else } // if ProcessDTMFCommand(FinalDTMFCommand, MyState); SetText(currentDTMFChar + "-" + CurrentDTMFCommand); // logging MethodEndLogging(myMethod); } // try catch (Exception ex) { UtilityMethods.ExceptionHandler(ex, TraceString); } // catch } // Analyzer_DtmfToneStopped