public void Play(string rttlData) { const int oneBpmWholeNote = 60 * 4 * 1000; //one bpm whole note in ms Rttl rttl = Rttl.Parse(rttlData); int wholeNote = oneBpmWholeNote / rttl.Bpm; foreach (string tone in rttl.Tones) { bool specialDuration; string durationStr, noteStr, scaleStr; ParseCommand(tone, out durationStr, out noteStr, out scaleStr, out specialDuration); int duration = rttl.Duration; if (durationStr.Length > 0) { duration = Int32.Parse(durationStr); } duration = specialDuration ? (3 * wholeNote) / (2 * duration) : wholeNote / duration; int freqIndex; switch (noteStr[0].ToLower()) { case 'c': freqIndex = 0; break; case 'd': freqIndex = 2; break; case 'e': freqIndex = 4; break; case 'f': freqIndex = 5; break; case 'g': freqIndex = 7; break; case 'a': freqIndex = 9; break; case 'b': freqIndex = 11; break; default: freqIndex = -1; break; } if (noteStr.Length > 1) //# { freqIndex++; } int scale = rttl.Octave; if (scaleStr.Length > 0) { scale = Int32.Parse(scaleStr); } if (freqIndex >= 0) { double freq = Scales[scale - 4][freqIndex]; Debug.Print("Playing: (" + tone + ")" + freq + " " + duration); _speaker.Play(freq); Thread.Sleep(duration); _speaker.Pause(); } else { Debug.Print("Pausing: (" + tone + ") " + duration); _speaker.Pause(); Thread.Sleep(duration); } } }
public static void Main(string[] args) { //Select Speaker type: VoiceOutput VoiceOutput = new VoiceOutput(); Dictionary <int, ISpeaker> availableSpeakers = new Dictionary <int, ISpeaker>(); availableSpeakers.Add(1, new IphoneHeadset(VoiceOutput, "IphoneX", true)); availableSpeakers.Add(2, new SamsungHeadset(VoiceOutput, "SamsungA", true)); availableSpeakers.Add(3, new PhoneSpeaker(VoiceOutput, "model-ABC")); ISpeaker Speaker = null; while (Speaker == null) { Menu.ShowHeadsetMenu(); string speakerSelected = Console.ReadLine(); foreach (var item in availableSpeakers) { if (speakerSelected.Equals(item.Key.ToString())) { Speaker = availableSpeakers[item.Key]; VoiceOutput.DataOutput("Speaker selected"); Speaker.Play(null); } ; } if (Speaker == null) { VoiceOutput.DataOutput("There is no such option. Please try again"); } } //Select the Screen type: TextOutput TextOutput = new TextOutput(); Dictionary <int, ScreenBase> availableScreens = new Dictionary <int, ScreenBase>(); availableScreens.Add(1, new MonochromeScreen(TextOutput, 300, 5)); availableScreens.Add(2, new ColorfulScreen(TextOutput, 300, 5, false)); ScreenBase Screen = null; while (Screen == null) { Menu.ShowScreenMenu(); string screenSelected = Console.ReadLine(); foreach (var item in availableScreens) { if (screenSelected.Equals(item.Key.ToString())) { Screen = availableScreens[item.Key]; TextOutput.DataOutput("Set screen to Mobile... Selected screen is "); Screen.DisplayInfo(); } } if (Screen == null) { TextOutput.DataOutput("There is no such option. Please try again"); } } Console.ReadLine(); //From Lab#1: //ScreenBase Screen = new ColorfulScreen(7.0, 500, true); //IBattery Battery = new Battery(2000, "Li-ion"); //Keyboard Keyboard = new SensorKeyboard("Russian", "Samsung"); //Microphone Microphone = new PhoneMicrophone(94, "model-xxx0155"); //ISpeaker Speaker = new SamsungHeadset("model-XXX", false); //SimCard SimCard = new MTSSimCard(SimCardType.NanoSim, 1111); //Mobile Samsung = new MobileSimcorp(Screen, Battery, Keyboard, Microphone, Speaker, SimCard); //Console.WriteLine(Samsung.GetDescription()); }