Exemplo n.º 1
0
        private void AddChord(ChordName chordName)
        {
            long elapsed  = stopwatch.ElapsedMilliseconds;
            long duration = elapsed - lastElapsedMillis;

            lastElapsedMillis = elapsed;
            recorder.AddChord(chordName, duration);
        }
Exemplo n.º 2
0
        private void automaticHarmonyButton_Click(object sender, EventArgs e)
        {
            // automatic harmony can only be added when beat was specified
            // (otherwise there is no way to know the correct placement of chords)
            if (bpm == 0)
            {
                MessageBox.Show("You can't add harmony automatically if there is no beat!");
                return;
            }

            // user must specify which progression they want generated
            if (chordProgSelector.SelectedIndex == -1 || (string)chordProgSelector.SelectedItem == "N/A")
            {
                MessageBox.Show("You must select a chord progression!");
                return;
            }

            // reset harmony and check if it is possible to add a new one
            try
            {
                recorder.AddHarmony(false);
            }
            catch (ApplicationException)
            {
                MessageBox.Show("You must select a scale first!");
                return;
            }

            // get the correct chords from the given chord progression
            List <ChordName> chords = new List <ChordName> {
            };

            switch ((string)chordProgSelector.SelectedItem)
            {
            case "ii - v - i":
            {
                chords.Add(ChordName.ii);
                chords.Add(ChordName.v);
                chords.Add(ChordName.ilow);
                break;
            }

            case "i - iv - v":
            {
                chords.Add(ChordName.ilow);
                chords.Add(ChordName.iv);
                chords.Add(ChordName.v);
                break;
            }

            case "i - v - vi - iv":
            {
                chords.Add(ChordName.ilow);
                chords.Add(ChordName.v);
                chords.Add(ChordName.vi);
                chords.Add(ChordName.iv);
                break;
            }

            case "i - vi - iv - v":
            {
                chords.Add(ChordName.ilow);
                chords.Add(ChordName.vi);
                chords.Add(ChordName.iv);
                chords.Add(ChordName.v);
                break;
            }

            case "i - v - i - iv":
            {
                chords.Add(ChordName.ilow);
                chords.Add(ChordName.v);
                chords.Add(ChordName.ihigh);
                chords.Add(ChordName.iv);
                break;
            }

            case "vi - v - iv - iii":
            {
                chords.Add(ChordName.vi);
                chords.Add(ChordName.v);
                chords.Add(ChordName.iv);
                chords.Add(ChordName.iii);
                break;
            }

            default:
            {
                chords.Add(ChordName.None);
                break;
            }
            }

            // a new chord is to be played on every chordFreqTrackBar.Value-th beat
            int chordFrequency   = bpm / chordFreqTrackBar.Value;
            int oneChordDuration = Convert.ToInt32(1 / ((float)chordFrequency / 60) * 1000);                    // milliseconds

            // add all chords with the correct duration to harmony
            foreach (ChordName chord in chords)
            {
                recorder.AddChord(chord, oneChordDuration);
            }

            // generate recording with new harmony
            recorder.RegenerateRecording();

            // alert user that the process has finished
            if (showMessageWhenHarmonyGenerated)
            {
                MessageBox.Show("Done! Hear the result by clicking Play.");
            }
        }