public async IAsyncEnumerable <Sample[]> EnumerateSamplesAsync(InputOption option, [EnumeratorCancellation] CancellationToken token = default) { if (string.IsNullOrEmpty(option.OptionName)) { throw new ConfigurationNeededException(); } var devices = GetDevices(); var device = devices.First(d => d.FriendlyName == option.OptionName); using var capture = new WasapiLoopbackCapture(device); capture.ShareMode = AudioClientShareMode.Shared; option.SamplingFrequency = capture.WaveFormat.SampleRate; bytesPerSample = capture.WaveFormat.BitsPerSample / 8; EventHandler <WaveInEventArgs> handler = GetHandlerByEncoding(capture.WaveFormat.Encoding); capture.DataAvailable += handler; channels = capture.WaveFormat.Channels; //capture.WaveFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 44100, 1, 44100 * 2, 2, 8 * 2); capture.StartRecording(); while (await sampleQueue.OutputAvailableAsync(token)) { var samples = await sampleQueue.TakeAsync(token); yield return(samples); } capture.DataAvailable -= handler; }
public void ExecuteInputOption(InputOption inputOption) { if (Device != null) { Device.doKeyPress(inputOption.keyPress); } }
/// <summary> /// Changes a keybind if the button being assigned isnt already assigned /// </summary> /// <param name="bind">The InputOption to bind</param> /// <param name="key">The key we want to assign to the InputOption</param> /// <returns></returns> public bool ChangeKeybind(PlayerOption pl, InputOption bind, KeyCode key) { List <KeyCode> allValues = new List <KeyCode>(); allValues.AddRange(keybinds.player1.Keys); allValues.AddRange(keybinds.player2.Keys); foreach (KeyCode kc in allValues) { if (kc == key) { throw new ArgumentException("That key is already bound!"); } } allValues = null; if (pl == PlayerOption.Player_1) { keybinds.player1[key] = bind; } else { keybinds.player2[key] = bind; } SaveKeybindsToFile(); return(true); }
public async IAsyncEnumerable <Sample[]> EnumerateSamplesAsync(InputOption option, [EnumeratorCancellation] CancellationToken token = default) { using var pcmStream = new WaveFileReader("G:\\test.wav"); //using var pcmStream = WaveFormatConversionStream.CreatePcmStream(audio); option.SamplingFrequency = pcmStream.WaveFormat.SampleRate; var bytesCount = samplesBatchSize * pcmStream.BlockAlign; var buffer = new byte[bytesCount]; //if pcmStream.BitsPerSample == 16 && pcmStream.Channels == 1 Func <byte[], int, float[]> getValues = Get16BitMono; while (pcmStream.Position < pcmStream.Length) { int bytesRead = await pcmStream.ReadAsync(buffer, 0, buffer.Length, token); if (bytesRead == 0) { continue; } var samples = new Sample[bytesRead / pcmStream.BlockAlign]; for (var i = 0; i < samples.Length; i++) { var values = getValues(buffer, i * pcmStream.BlockAlign); samples[i] = new Sample(values); } yield return(samples); await Task.Delay(50); } }
private static RouteInfo GetRoute(Map map, InputOption inputOption) { ISearchAlgorithm algorithm = new DijkstraSearch(); var directionService = new DirectionService(algorithm, inputOption); return(directionService.PrepareRouteInfoFrom(map)); }
public void InvokeInputOption(HttpListenerContext context) { InputOption message = ParseRequest <InputOption>(context); GetServer.CloverConnector.InvokeInputOption(message); this.SendTextResponse(context, ""); }
private void txtRichInput_Leave(object sender, EventArgs e) { if (string.IsNullOrEmpty(this._textInput)) { this.groupFile.Enabled = true; this._inputOption = InputOption.eFile; } }
private void AddInputOption(InputComboBox combo, string text, string tag) { InputOption io = new InputOption(); io.Text = text; io.Tag = tag; combo.Items.Add(io); }
public void _onPress(InputOption io, int num) { if (collecting != null || GetNode <Timer>("BounceTimer").TimeLeft > 0) { return; } ClickPlayer.Play(); startCollecting(io, num); }
/// <summary> /// Returns true if specified input was released this frame. /// </summary> /// <param name="option">The input option to check.</param> /// <returns>True if input was released, false otherwise.</returns> public static bool GetUp(InputOption option) { if (inputLocked) { return(false); } return(releasedInputs.Contains(option)); }
/// <summary> /// Returns true if specified input is being held down this frame. /// </summary> /// <param name="option">The input option to check.</param> /// <returns>True if input is being held, false otherwise.</returns> public static bool Get(InputOption option) { if (inputLocked) { return(false); } return(heldInputs.Contains(option)); }
/// <summary> /// Returns the value of the specified input. Non-zero means the input is active. /// This is especially useful for analog sticks, since the value determines which /// direction they're being held, and how far they're being held. /// </summary> /// <param name="option">The input option to check.</param> /// <returns>A float value representing the input value this frame. </returns> public static float GetInputValue(InputOption option) { if (inputLocked) { return(0.0f); } return(Input.GetAxis(inputOptions[option])); }
public void InvokeInputOption(InputOption io) { if (websocket != null) { InvokeInputOptionRequestMessage message = new InvokeInputOptionRequestMessage(); message.payload = io; websocket.Send(JsonUtils.serialize(message)); } }
private void finishCollecting() { GetNode <Timer>("BounceTimer").Start(); collecting.refreshButtons(); collecting = null; GetNode <Control>("KeyPrompt").Visible = false; GetNode <Button>("BackButton").Disabled = false; GetNode <Button>("BackButton").FocusMode = FocusModeEnum.All; }
private void startCollecting(InputOption io, int num) { collecting = io; cnum = num; io.setCollecting(num); GetNode <Control>("KeyPrompt").Visible = true; GetNode <Button>("BackButton").Disabled = true; GetNode <Button>("BackButton").FocusMode = FocusModeEnum.None; }
public void Validate_ShouldThrowException_If_End_Is_NotPassed() { var ex = Assert.Throws <Exception>(() => { InputOption.Get(new[] { "--start=Ubi", @"--csvpath=c:\Station.csv" }); }); Assert.AreEqual("Invalid Start or destination! Program Terminates!", ex.Message); }
public void Returns_Temperature_Options() { InputOption options = new InputOption(); var temperature = options.GetTemperatureOptions(); Assert.IsTrue(temperature.Contains(Temperature.Hot.ToString())); Assert.IsTrue(temperature.Contains(Temperature.Cold.ToString())); Assert.IsTrue(temperature.Length == 2); }
public void Validate_ShouldThrowException_If_Csv_Path_Is_NotPassed() { var ex = Assert.Throws <Exception>(() => { InputOption.Get(new[] { "--start=Ubi", "--end=Kovan" }); }); Assert.AreEqual("Invalid CSV Path! Program Terminates!", ex.Message); }
public void TestInputOptionValues() { InputOption longOption = new InputOption("--foo"); Assert.Equal("foo", longOption.Name); InputOption shortOption = new InputOption("--foo", "-f"); Assert.Equal("f", shortOption.Shortcut); }
public async IAsyncEnumerable <Sample[]> EnumerateSamplesAsync(InputOption option, [EnumeratorCancellation] CancellationToken token = default) { option.SamplingFrequency = 44100; while (!token.IsCancellationRequested) { var samples = Enumerable.Repeat(0f, samplesBatchSize).Select(sample => new Sample(new[] { sample })).ToArray(); yield return(samples); await Task.Delay(1000, token); } }
public decimal GetCost(InputOption inputOption, Edge cnn, Station station) { var commonStations = cnn.ConnectedStation.Lines.Intersect(station.Lines).ToList(); var isInNeOrNs = commonStations.Intersect(new List <string> { "NE", "NS" }).Any(); var isPeakHour = inputOption.JourneyTime.IsPeak(); var interchange = !commonStations.Any(); return((!isInNeOrNs && !interchange && isPeakHour ? 10 : 0) + _inner.GetCost(inputOption, cnn, station)); }
private void InputHold(InputOption input) { if (downInputs.Contains(input)) { downInputs.Remove(input); if (debug) { Debug.LogFormat("Input {0} hold", input.ToString()); } } }
public void GetOptions_Should_GetParsedOptions() { var options = InputOption.Get(new[] { "--start=Ubi", "--end=Kovan", @"--csvpath=c:\Station.csv" }); var expected = new InputOption { Start = "Ubi", End = "Kovan", CsvPath = @"c:\Station.csv" }; expected.Should().BeEquivalentTo(options); }
public static void ReceiveNumberInputs(MyList <string> inputedList, InputOption inputMethod) { switch (inputMethod) { case InputOption.Group: ReceiveNumbersByGroup(inputedList); break; case InputOption.Individual: ReceiveNumbersIdividually(inputedList); break; } }
public static void Main(string[] args) { var option = InputOption.Get(args); var rawRecords = ReadRawStationData(option); var map = GetMap(rawRecords); option.ValidateStations(map); var routeInfo = GetRoute(map, option); PrintTheJourney(routeInfo); }
private static void ProcessInput() { do { ConsoleKey key = Console.ReadKey(true).Key; if (_terminated || key == ConsoleKey.Escape) { break; } InputOption.Execute(key); } while (true); }
public void Given_3_Stations_We_Can_Trace_To_BeginingStation_FromEndStation() { _sengkangStation.Connections.Add(new Edge { ConnectedStation = _kovanStation, Cost = 1 }); _kovanStation.Connections.Add(new Edge { ConnectedStation = _sengkangStation, Cost = 1 }); _kovanStation.Connections.Add(new Edge { ConnectedStation = _harborStation, Cost = 1 }); _harborStation.Connections.Add(new Edge { ConnectedStation = _kovanStation, Cost = 1 }); _stations = new List <Station> { _sengkangStation, _kovanStation, _harborStation }; var dijkstraSearch = new DijkstraSearch(); var option = new InputOption { Start = _sengkangStation.StationName, End = _harborStation.StationName }; var path = dijkstraSearch.FillShortestPath(_stations, option); var expected = new List <Station> { new Station("Harbor") { NearestToStart = _kovanStation, MinimumCost = 2 }, new Station("Kovan") { NearestToStart = _sengkangStation, MinimumCost = 1 }, new Station("Sengkang") { NearestToStart = null, MinimumCost = 0 }, }; path.Should().NotBeEmpty() .And.HaveCount(3) .And.BeEquivalentTo(expected, options => options .Including(o => o.StationName) .Including(o => o.MinimumCost) .Including(a => a.NearestToStart)); }
private void InputRelease(InputOption input) { if (heldInputs.Contains(input)) { heldInputs.Remove(input); releasedInputs.Add(input); if (debug) { Debug.LogFormat("Input {0} release", input.ToString()); } } }
public void InvokeInputOption(HttpListenerContext context) { try { InputOption message = ParseRequest <InputOption>(context); GetServer.CloverConnector.InvokeInputOption(message); this.SendTextResponse(context, ""); } catch (Exception e) { context.Response.StatusCode = 400; context.Response.StatusDescription = e.Message; this.SendTextResponse(context, "error processing request"); } }
private void InputDown(InputOption input) { if (!heldInputs.Contains(input)) { timeSinceLastInput = 0.0f; downInputs.Add(input); heldInputs.Add(input); if (debug) { Debug.LogFormat("Input {0} down", input.ToString()); } } }
private List<Input> GetFormInputs(string html) { List<Input> ip = new List<Input>(); HtmlDocument doc = new HtmlDocument(); if(html == null) { return ip; } try { doc.LoadHtml(html); IEnumerable<HtmlNode> nodes = doc.DocumentNode.DescendantNodes(); foreach(HtmlNode node in nodes) { string tagName = node.Name; if(tagName == "select" || tagName == "input") { Input i = new Input(node.GetAttributeValue("name", ""), ""); if(tagName == "select") { List<InputOption> ips = new List<InputOption>(); foreach(HtmlNode opt in node.ChildNodes) { InputOption o = new InputOption(); o.Value = opt.GetAttributeValue("value", ""); o.InnerText = opt.InnerText; i.Options.Add(o); } } else { string inputType = node.GetAttributeValue("type", ""); string maxlength = node.GetAttributeValue("maxlength", ""); i.Type = inputType; i.MaxLength = maxlength; } /* add all the attributes */ foreach(HtmlAttribute atr in node.Attributes) { i.Attributes.Add(atr.Name, atr.Value); } ip.Add(i); } } } catch(Exception ex) { String.Format("getFormInputs exception. Form:{0}, Item:{1} =>{2}", this.Name, this.Item.Number, ex.Message).Debug(3); } return ip; }
private static void Create(ConsoleKey key, string description, InputOptionDelegate inputDelegate) { InputOption option = new InputOption(key, description, inputDelegate); Options.Add(key, option); }