private void btnFollowSequence_Click(object sender, EventArgs e) { tbInputSequence.Enabled = false; if (!timerFollowSequence.Enabled) { if (!_musicHmmModelOnline.Started) { _musicFollower = new MusicalFollower(_musicHmmModelOnline, (int)nudTempo.Value, _musicXmlDecoder.Beats, _musicXmlDecoder.BeatType); timerFollowSequence.Interval = _musicFollower.GetTimerInterval((int)nudTempo.Value); timerMetronome.Interval = _musicFollower.GetMetronomeInterval((int)nudTempo.Value); _inputSequence = tbInputSequence.Text.Split(',').Select(s => int.Parse(s)).ToArray(); } timerFollowSequence.Start(); timerMetronome.Start(); btnFollowSequence.Text = "Stop"; } else { timerFollowSequence.Stop(); timerMetronome.Stop(); btnFollowSequence.Text = "Follow the Sequence"; } }
private void ResetOnline() { tbInputSequence.Enabled = true; _musicHmmModelOnline = new MusicalHmmOnline(_musicHmmData, (int)nudWindowSize.Value, (int)nudObservsCount.Value); _musicFollower = new MusicalFollower(_musicHmmModelOnline, (int)nudTempo.Value, _musicXmlDecoder.Beats, _musicXmlDecoder.BeatType); _inputSequence = tbInputSequence.Text.Split(',').Select(s => int.Parse(s)).ToArray(); _currentNoteInd = 0; _currentBeat = 1; timerFollowSequence.Stop(); timerMetronome.Stop(); if (_waveIn != null) { _waveIn.StopRecording(); } if (cbUpdateMatrixes.Checked) { GuiUtils.NavigateToItem(dgvTransitions, 0, 0); GuiUtils.NavigateToItem(dgvEmissions, 0, 0); GuiUtils.NavigateToItem(dgvInitial, 0, 0); } tbObservations.Text = ""; tbLastObservations.Text = ""; tbPath.Text = ""; tbLastPath.Text = ""; tbCurNoteName.Text = ""; tbCurMidiNote.Text = ""; tbCurHmmMidiNote.Text = ""; tbOnlineStepTime.Text = ""; tbMetronome.Text = ""; tbEventEstimation.Text = ""; tbKvantEstimation.Text = ""; tbTempoEstimation.Text = ""; tbRating.Text = ""; btnFollowSequence.Text = "Follow the Sequence"; btnMicFollowing.Text = "Realtime mic following"; musicalNotesViewer.NavigateToEvent(-1); pbNoteProgress.Minimum = 0; pbNoteProgress.Maximum = _musicHmmData.EventKvants.Count; pbNoteProgress.Value = 0; pnlNotesViewer.HorizontalScroll.Value = pnlNotesViewer.HorizontalScroll.Minimum; }
private void btnMicFollowing_Click(object sender, EventArgs e) { _musicFollower = new MusicalFollower(_musicHmmModelOnline, (int)nudTempo.Value, _musicXmlDecoder.BeatType, _musicXmlDecoder.Beats); _audioDecoder = new WaveMp3FileDecoder(); _audioDecoder.DetectLevelThreshold = AudioUtils.DecibelToPower(tbSoundAmplitude.Value); _waveIn = new WaveIn(); _waveIn.WaveFormat = new WaveFormat(44100, 1); _waveIn.DataAvailable += OnDataAvailable; _waveIn.RecordingStopped += OnRecordingStopped; var stopwatch = new Stopwatch(); TimeSpan oldTime = new TimeSpan(); lblPitchsCount.Text = "0"; _audioDecoder.InitRealtimeMode(_waveIn.WaveFormat.Channels, _waveIn.WaveFormat.BitsPerSample, _waveIn.WaveFormat.SampleRate, _musicFollower.GetTimerInterval((int)nudTempo.Value), (PitchTracker tracker, PitchRecord record) => { lblPitchsCount.Text = (int.Parse(lblPitchsCount.Text) + 1).ToString(); lblTime.Text = (stopwatch.Elapsed - oldTime).ToString(); oldTime = stopwatch.Elapsed; tbCurNoteName.Text = MusicalTemperament.MidiNoteToNoteName(record.MidiNote); tbCurMidiNote.Text = record.MidiNote <= -1 ? "-" : record.MidiNote.ToString(); tbCurHmmMidiNote.Text = _musicHmmData.MidiNoteToHmmMidiNote(record.MidiNote).ToString(); FollowObservation(record.MidiNote); }); _waveIn.StartRecording(); stopwatch.Start(); oldTime = stopwatch.Elapsed; timerMetronome.Interval = _musicFollower.GetMetronomeInterval((int)nudTempo.Value); timerMetronome.Start(); btnMicFollowing.Text = "Stop"; }