Beispiel #1
0
        public void TestAllChords()
        {
            // This test runs over every possible note/pattern/inversion combination over
            // pitches in a range extending beyond the MIDI range, and performs several
            // consistency checks on every one of those chords.

            // For every pitch in the range...
            for (Pitch pitch = (Pitch)(-50); pitch < (Pitch)200; ++pitch)
            {
                // Find the one or two common notes for this pitch.
                List <Note> notes = new List <Note>();
                notes.Add(pitch.NotePreferringSharps());
                if (pitch.NotePreferringFlats() != pitch.NotePreferringSharps())
                {
                    notes.Add(pitch.NotePreferringFlats());
                }
                // For the one or two notes for this pitch...
                foreach (Note note in notes)
                {
                    // For every chord pattern...
                    foreach (ChordPattern pattern in Chord.Patterns)
                    {
                        // For every legal inversion of the pattern...
                        for (int inversion = 0; inversion < pattern.Ascent.Length; ++inversion)
                        {
                            // Construct the chord.
                            Chord c = new Chord(note, pattern, inversion);
                            // Make sure the chord's name, when parsed, is equivalent to the chord.
                            Assert.AreEqual(c, new Chord(c.Name));
                            // Generated a set of pitches based on the chord, starting at or above
                            // the original pitch.
                            Pitch        p       = pitch;
                            List <Pitch> pitches = new List <Pitch>();
                            foreach (Note n in c.NoteSequence)
                            {
                                p = n.PitchAtOrAbove(p);
                                pitches.Add(p);
                            }
                            Assert.True(Chord.FindMatchingChords(pitches).Contains(c));
                        }
                    }
                }
            }
        }
            private void PrintStatus()
            {
                Console.Clear();
                Console.WriteLine("Play notes and chords on the MIDI input device, and watch");
                Console.WriteLine("their names printed here.  Press any QUERTY key to quit.");
                Console.WriteLine();

                // Print the currently pressed notes.
                var pitches = new List <Pitch>(_pitchesPressed.Keys);

                pitches.Sort();
                Console.Write("Notes: ");
                for (var i = 0; i < pitches.Count; ++i)
                {
                    var pitch = pitches[i];
                    if (i > 0)
                    {
                        Console.Write(", ");
                    }
                    Console.Write("{0}", pitch.NotePreferringSharps());
                    if (pitch.NotePreferringSharps() != pitch.NotePreferringFlats())
                    {
                        Console.Write(" or {0}", pitch.NotePreferringFlats());
                    }
                }
                Console.WriteLine();
                // Print the currently held down chord.
                var chords = Chord.FindMatchingChords(pitches);

                Console.Write("Chords: ");
                for (var i = 0; i < chords.Count; ++i)
                {
                    var chord = chords[i];
                    if (i > 0)
                    {
                        Console.Write(", ");
                    }
                    Console.Write("{0}", chord);
                }
                Console.WriteLine();
            }