Esempio n. 1
0
        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";
            }
        }
Esempio n. 2
0
        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";
        }