void UpdateDisplay() { // Show the detector results if (detector.Pitch > 1.0f) { if (detector.Pitch >= 1000.0f) { detectorPitch.text = (detector.Pitch / 1000.0f).ToString("F4"); detectorUnits.text = "kHz"; } else { detectorPitch.text = detector.Pitch.ToString("F3"); detectorUnits.text = "Hz"; } detectorMidiNote.text = PitchDsp.GetNoteName(detector.MidiNote, true, true); detectorMidiCents.text = detector.MidiCents.ToString(); //var diffPercent = 100.0 - (100.0f * this.GeneratorPitch / curPitchRecord.Pitch); //if (diffPercent >= 0.0f) // detectorError.text = "+" + diffPercent.ToString("F3"); //else //detectorError.text = diffPercent.ToString("F3"); } else { detectorPitch.text = "--"; detectorUnits.text = "Hz"; detectorError.text = "--"; detectorMidiNote.text = "--"; detectorMidiCents.text = "--"; } }
//Before i looked in to using MIDI , i had attempted to create methods that as it turns out, worked the same way. //private void Note_start() //{ // var curPitchRecord = m_pitchTracker.CurrentPitchRecord; // float freq = curPitchRecord.Pitch; // StartDuration = this.TimeInterval; // CurrentFrequency = ((int)freq); //} //private void Note_End() //{ // EndDuration = this.TimeInterval; // if (Recording) // { // RecordString = TheRecorder.AddNextNote(CurrentFrequency, (int)(EndDuration - StartDuration)); // } //} private void UpdateDisplay() { // Show the detector results var curPitchRecord = m_pitchTracker.CurrentPitchRecord; // places the current pitch in to the curpitchrecord variable var curNote = PitchDsp.GetNoteName(curPitchRecord.MidiNote, true, true); if (curPitchRecord.Pitch > 1.0f) // if a significant value is given { if (curPitchRecord.Pitch >= 1000.0f) // for the purpose of converting the units from khz to hz { pFrequencyValueLbl.Text = (curPitchRecord.Pitch / 1000.0f).ToString("F4"); // converts given value in to khz pFrequencyUnitsLbl.Text = "kHz"; // sho9ws that value is in khz } else //if pitch !>= 1000, then it is in hz { pFrequencyValueLbl.Text = curPitchRecord.Pitch.ToString("F3"); //no need to convert to khz pFrequencyUnitsLbl.Text = "Hz"; // shows that value is in hz } noteValueLbl.Text = curNote; noteList.Add(curNote); nListView.SubItems.Add(curNote); } }
public static string NoteToName(int note) { return(PitchDsp.GetNoteName(note, true, true)); }