Ejemplo n.º 1
0
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            var circle = new CircleOf5ths();

            var triad = new List <Note>()
            {
                new Note()
                {
                    Interval = 1, Register = 2
                },
                new Note()
                {
                    Interval = 3, Register = 2
                },
                new Note()
                {
                    Interval = 5, Register = 2
                },
            };

            var note  = circle[-1].Project(circle[-1][4]);
            var chord = circle[-1].Project(circle[3].Transpose(triad)).ToList();

            //var eMajor = circle[4].Transpose(triad).ToList();

            var xml = OutputMei.Song("", 4, 4, "1f", "major",
                                     OutputMei.Measure(1,
                                                       OutputMei.Note(note, OutputMei.NoteValue.Quarter),
                                                       OutputMei.Chord(chord, OutputMei.NoteValue.Quarter)));

            label.Content = "A\u266Dm";
            DisplayMei(xml);
        }
Ejemplo n.º 2
0
        public void TestCircleOf5ths()
        {
            var circle = new CircleOf5ths();

            Assert.AreEqual(13, circle.Count);

            var expected = new int[] { 0, 1, 2, 3, 4, 5, 6, -6, -5, -4, -3, -2, -1 };
            var keyStr   = new string[] { "0", "1s", "2s", "3s", "4s", "5s", "6s", "6f", "5f", "4f", "3f", "2f", "1f" };

            for (int i = 0; i < circle.Count; i++)
            {
                Assert.AreEqual(keyStr[i], circle[i].KeyAccidentals);

                int count = 0;
                foreach (var n in circle[i])
                {
                    var a    = Accidental.n;
                    var name = circle[i].GetSheetNoteName(n.Interval, out a);

                    if (expected[i] > 0)
                    {
                        Assert.IsTrue((int)a >= 0 && (int)a < 2);
                    }
                    else
                    {
                        Assert.IsTrue((int)a <= 0 && (int)a > -2);
                    }

                    count += (int)a;

                    if (i != 6)
                    {
                        // Assert Tranpose while we are at it
                        var noteToChange   = circle[i][1];
                        var transposedNote = circle[i + 1].Transpose(noteToChange);
                        var projectNote    = circle[i + 1].Project(noteToChange);

                        Assert.AreEqual(noteToChange.AbsolutePitch, projectNote.AbsolutePitch);
                        Assert.AreEqual(circle[i + 1][1].SemitonesFromRoot, transposedNote.SemitonesFromRoot);
                        Assert.AreEqual(circle[i + 1][1].RootSemitone, transposedNote.RootSemitone);
                        Assert.AreEqual(circle[i + 1][1].Interval, transposedNote.Interval);
                        Assert.AreEqual(circle[i][5].RelativePitch, transposedNote.RelativePitch);
                    }
                }

                Assert.AreEqual(expected[i], count);
            }
        }
Ejemplo n.º 3
0
        public void TestProject()
        {
            var circle = new CircleOf5ths();

            var c      = circle["0"][1];
            var gScale = circle["1s"];

            var note = gScale.Project(c);

            Assert.AreEqual(c.AbsolutePitch, note.AbsolutePitch);

            gScale.Mode = Mode.Minor;

            note = gScale.Project(c);
            Assert.AreEqual(c.AbsolutePitch, note.AbsolutePitch);
        }
Ejemplo n.º 4
0
        public void TestSheetMusicNoteNames()
        {
            var circle = new CircleOf5ths();

            var expected = new Dictionary <int, string>()
            {
                { 0, "cdefgab" },
                { 1, "gabcdef#" },
                { 2, "def#gabc#" },
                { 3, "abc#def#g#" },
                { 4, "ef#g#abc#d#" },
                { 5, "bc#d#ef#g#a#" },
                { 6, "f#g#a#bc#d#e#" },
                { -1, "fgab-cde" },
                { -2, "b-cde-fga" },
                { -3, "e-fga-b-cd" },
                { -4, "a-b-cd-e-fg" },
                { -5, "d-e-fg-a-b-c" },
                { -6, "g-a-b-c-d-e-f" },
            };

            foreach (var kvp in expected)
            {
                var names = GetNoteNames(circle[kvp.Key], circle[kvp.Key].Select(n => n.Interval).ToList());
                Assert.AreEqual(kvp.Value, names, $"The key on the circle of 5ths with index {kvp.Key} failed to generate correct note names.  Expected {kvp.Value} != Actual {names}");
            }

            var cf      = new Key(NoteLetters.c, Accidental.f);
            var cfNames = GetNoteNames(cf, cf.Select(n => n.Interval).ToList());

            Assert.AreEqual("c-d-e-f-g-a-b-", cfNames, $"C Flat key names were not correct Expected c-d-e-f-g-a-b- != Actual {cfNames}");

            var cs      = new Key(NoteLetters.c, Accidental.s);
            var csNames = GetNoteNames(cs, cs.Select(n => n.Interval).ToList());

            Assert.AreEqual("c#d#e#f#g#a#b#", csNames, $"C Sharp key names were not correct Expected c#d#e#f#g#a#b# != Actual {csNames}");

            var gs      = new Key(NoteLetters.g, Accidental.s);
            var gsNames = GetNoteNames(gs, gs.Select(n => n.Interval).ToList());

            Assert.AreEqual("g#a#b#c#d#e#fx", gsNames, $"G Sharp key names were not correct Expected g#a#b#c#d#e#fx != Actual {gsNames}");

            var ff      = new Key(NoteLetters.f, Accidental.f);
            var ffNames = GetNoteNames(ff, ff.Select(n => n.Interval).ToList());

            Assert.AreEqual("f-g-a-b--c-d-e-", ffNames, $"F Flat key names were not correct Expected f-g-a-b--c-d-e- != Actual {ffNames}");
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            var circle = new CircleOf5ths();
            //var cMajor = new Scale(Note.c);
            //var gMinor = new Scale(Note.g, mode: Mode.Minor);

            //var notes = "";
            //foreach(var ns in cMajor.SelectNotes(group))
            //{
            //    var a = Accidental.n;
            //    var n = cMajor.GetNoteName(ns.interval, out a);
            //    notes += a != Accidental.n ? n.ToString() + a.ToString() : n.ToString();
            //    notes += " ";
            //}
            //Console.WriteLine(notes);
            //Console.WriteLine();

            //notes = "";
            //foreach (var ns in gMinor.SelectNotes(cMajor.SelectNotes(group)))
            //{
            //    var a = Accidental.n;
            //    var n = gMinor.GetNoteName(ns.interval, out a);
            //    notes += a != Accidental.n ? n.ToString() + a.ToString() : n.ToString();
            //    notes += " ";
            //}
            //Console.WriteLine(notes);
            //Console.WriteLine();

            //Console.ReadKey();
            //var k = circle[0];
            //k.Mode = Mode.Minor;

            //var aChord = k.SelectNotes(new List<KeyNote>()
            //{
            //    new KeyNote(){ interval = 1 },
            //    new KeyNote(){ interval = 3 },
            //    new KeyNote(){ interval = 5 },
            //});

            //Console.WriteLine(GetNoteNames(k, aChord.Select(o => o.interval).ToList()));

            //foreach (var key in circle)
            //{
            //    key.Mode = Mode.Ionian;
            //    Console.WriteLine(GetNoteNames(key, key.Select(o => o.Interval).ToList()));
            //    key.Mode = Mode.Dorian;
            //    Console.WriteLine(GetNoteNames(key, key.Select(o => o.Interval).ToList()));
            //    key.Mode = Mode.Phrygian;
            //    Console.WriteLine(GetNoteNames(key, key.Select(o => o.Interval).ToList()));
            //    key.Mode = Mode.Lydian;
            //    Console.WriteLine(GetNoteNames(key, key.Select(o => o.Interval).ToList()));
            //    key.Mode = Mode.Mixolydian;
            //    Console.WriteLine(GetNoteNames(key, key.Select(o => o.Interval).ToList()));
            //    key.Mode = Mode.Aeolian;
            //    Console.WriteLine(GetNoteNames(key, key.Select(o => o.Interval).ToList()));
            //    key.Mode = Mode.Locrian;
            //    Console.WriteLine(GetNoteNames(key, key.Select(o => o.Interval).ToList()));

            //    Console.WriteLine();
            //}
            //Console.ReadKey();

            //var cMajorTrebble = new List<int>()
            //{
            //    MidiKeyboard.Key.ToPitch((int)Note.c, 4),
            //    MidiKeyboard.Key.ToPitch((int)Note.e, 4),
            //    MidiKeyboard.Key.ToPitch((int)Note.g, 4),
            //};
            //var cMajorClef = new List<int>()
            //{
            //    MidiKeyboard.Key.ToPitch((int)Note.c, 3),
            //    MidiKeyboard.Key.ToPitch((int)Note.e, 3),
            //    MidiKeyboard.Key.ToPitch((int)Note.g, 3),
            //};

            //var xml = OutputMei.Song("", 4, 4, "0", "major",
            //    OutputMei.Measure(1,
            //        OutputMei.Chord(cMajorTrebble, OutputMei.NoteValue.Quarter),
            //        OutputMei.Chord(cMajorClef, OutputMei.NoteValue.Quarter)));

            //File.WriteAllText(@"C:\Users\tyni\Desktop\test.xml", xml);


            List <Note> triad = new List <Note>()
            {
                new Note()
                {
                    Interval = 1
                },
                new Note()
                {
                    Interval = 3
                },
                new Note()
                {
                    Interval = 5
                },
            };

            Deck deck = new Deck();

            foreach (var scale in circle)
            {
                scale.Mode = Mode.Major;
                deck.Add(new Card(
                             new KeyValuePair <string, List <int> >
                             (
                                 GetNoteName(scale, 1).ToUpper(),
                                 scale.Transpose(triad)
                                 .Select(n => (int)n.RelativePitch)
                                 .ToList()
                             )));

                scale.Mode = Mode.Minor;
                deck.Add(new Card(
                             new KeyValuePair <string, List <int> >
                             (
                                 GetNoteName(scale, 1).ToUpper() + $"m",
                                 scale.Transpose(triad)
                                 .Select(n => (int)n.RelativePitch)
                                 .ToList()
                             )));
            }

            if (InputDevice.DeviceCount < 1)
            {
                Console.WriteLine("No MIDI device found. Connect device and restart.");
                return;
            }
            for (int i = 0; i < InputDevice.DeviceCount; i++)
            {
                Console.WriteLine($"{i + 1}: {InputDevice.GetDeviceCapabilities(i).name}");
            }
            var key = Console.ReadKey();

            int deviceId = 0;

            // We check input for a Digit
            if (char.IsDigit(key.KeyChar))
            {
                deviceId = int.Parse(key.KeyChar.ToString()) - 1; // use Parse if it's a Digit
            }

            Console.WriteLine("Using Device: " + InputDevice.GetDeviceCapabilities(deviceId).name);
            using (InputDevice inDevice = new InputDevice(deviceId))
            {
                keyboard = new MidiKeyboard.MidiKeyboard(inDevice);
                keyboard.StartRecording(inDevice, KeyActions);

                while (true)
                {
                    Card card = deck.Pick();
                    var  kvp  = (KeyValuePair <string, List <int> >)card.Get();

                    Console.WriteLine($"Play {kvp.Key}");
                    var       playAction = new PlayChord(kvp.Value);
                    Stopwatch watch      = new Stopwatch();
                    watch.Start();
                    do
                    {
                        playAction.WaitForKeyInput(KeyActions);
                        Console.WriteLine(playAction.Played ? "You did it!" : "Nope...");
                    }while (!playAction.Played);
                    watch.Stop();
                }
            }
        }