/// <summary> /// Used by the "AudioRecording"-page, gets the note name from the essentia model and visualises it. /// </summary> /// <param name="ct">Token to cancel the current task.</param> /// <param name="label">Label which will visualise the current note.</param> public void VisualiseApiData(CancellationToken ct, Label label) { try { Task.Run(() => { while (!ct.IsCancellationRequested) { //if (DevFlags.LoggingEnabled) Logger.AnalyzerLog("Looping"); if (ResultBuffer.Peek() != null) { ct.ThrowIfCancellationRequested(); var data = ResultBuffer.Get(); if (data != null) { string note = GetNoteFromData(data); MainThread.BeginInvokeOnMainThread(() => { label.Text = note; }); } } } }); } catch (OperationCanceledException e) { //Ignore } }
/// <summary> /// Analyse the data /// </summary> /// <param name="webView">WebView in which the sheet is rendered.</param> /// <param name="ct">Token which is used to cancel the task.</param> /// <returns></returns> private async Task Analyse(WebView webView, CancellationToken ct) { while (!ct.IsCancellationRequested) { //if (DevFlags.LoggingEnabled) Logger.AnalyzerLog("Looping"); if (ResultBuffer.Peek() != null) { if (DevFlags.LoggingEnabled) { Logger.AnalyzerLog("Analysing"); } ct.ThrowIfCancellationRequested(); var data = ResultBuffer.Get(); if (data != null) { var song = CompareWithSheet(data); //Hack: In case something failed in CompareWithSheet skip this cycle, hopefully the next one will work if (song == null) { continue; } AnalysedData.Push(song); if (song.Type == Highlight.Chord) { InfoContainer.HitNote(); if (DevFlags.LoggingEnabled) { Logger.AnalyzerLog("Highlighting " + song.WebId); } string scriptName = $"HighlightCorrectChord('" + song.WebId + "')"; MainThread.BeginInvokeOnMainThread(async() => { await webView.EvaluateJavaScriptAsync(scriptName); }); } else if (song.Type == Highlight.Note) { InfoContainer.HitNote(); if (DevFlags.LoggingEnabled) { Logger.AnalyzerLog("Highlighting " + song.WebId); } string scriptName = $"HighlightCorrectNote('" + song.WebId + "')"; MainThread.BeginInvokeOnMainThread(async() => { await webView.EvaluateJavaScriptAsync(scriptName); }); } } } } ct.ThrowIfCancellationRequested(); }