Esempio n. 1
0
        static bool CoveredByChordOfInterefest(TwelveToneSet set)
        {
            if (set.CoveredByAnySimilar(TwelveToneSet.major7))
            {
                return(true);
            }
            if (set.CoveredByAnySimilar(TwelveToneSet.minor7))
            {
                return(true);
            }
            if (set.CoveredByAnySimilar(TwelveToneSet.augmented))
            {
                return(true);
            }
            if (set.CoveredByAnySimilar(TwelveToneSet.halfDiminished))
            {
                return(true);
            }
            if (set.CoveredByAnySimilar(TwelveToneSet.fullDiminished))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Generated a random sequence of tones
        /// </summary>
        /// <param name="alightWithLast">The number of previous tones, the next should be aligned with in a chord</param>
        /// <param name="diffFromLast">The number of the previous tones it sohuld be different from</param>
        /// <param name="apartFromLast">Maximal distance from the last tone in semitones</param>
        static void RandomSequencer(int alightWithLast = 5, int diffFromLast = 1, int apartFromLast = 6)
        {
            Random     rand     = new Random();
            List <int> list     = new List <int>();
            int        lastTone = 0;

            while (true)
            {
                int tone;
                while (true)
                {
                    // todo: Normal distribution would be more appropriate here
                    tone = rand.Next(40, 80);

                    // Apart from the last tone?
                    if (list.Count > 0 && Math.Abs(list.Last() - tone) > apartFromLast)
                    {
                        continue;
                    }

                    // Different from last few?
                    bool diff = true;
                    for (int i = list.Count - 1; i >= 0 && i >= list.Count - diffFromLast; i--)
                    {
                        if (list[i] == tone)
                        {
                            diff = false;
                            break;
                        }
                    }
                    if (!diff)
                    {
                        continue;
                    }

                    // Last notes contained by a major scale
                    short set = 0;
                    TwelveToneSet.BitOn(set, tone % 12);
                    for (int i = list.Count - 1; i >= list.Count - alightWithLast && i >= 0; i--)
                    {
                        TwelveToneSet.BitOn(set, list[i] % 12);
                    }

                    if (!CoveredByChordOfInterefest(new TwelveToneSet(set)))
                    {
                        continue;
                    }

                    break;
                }

                StaticAndExtensionMethods.midiOut.Send(MidiMessage.StartNote(tone, 100, 1).RawData);
                Console.Write(new tone12(tone).ToString() + " ");
                list.Add(tone);
                StaticAndExtensionMethods.midiOut.Send(MidiMessage.StartNote(lastTone, 0, 1).RawData);
                lastTone = tone;
                Thread.Sleep(200);
            }
        }
Esempio n. 3
0
        public void ShiftInScaleTest_0shift()
        {
            Random rand = new Random(0);

            for (int i = 0; i < 100; i++)
            {
                TwelveToneSet set        = new TwelveToneSet(rand, rand.Next(3, 6), TwelveToneSet.chromatic);
                TwelveToneSet setShifted = set.ShiftInScale(0, TwelveToneSet.majorScale);
                Assert.AreEqual(set, setShifted);
            }
        }
Esempio n. 4
0
 static void Play(TwelveToneSet chord, int startFrom)
 {
     for (int i = startFrom; i < TwelveToneSet.TWELVE + startFrom; i++)
     {
         if (chord[(i + 10 * TwelveToneSet.TWELVE) % TwelveToneSet.TWELVE])
         {
             midiOut.Send(MidiMessage.StartNote(48 + i, 100, 1).RawData);
             Thread.Sleep(100);
         }
     }
 }
Esempio n. 5
0
        public void ShiftInScaleTest_OutScale()
        {
            Assert.AreEqual(
                new TwelveToneSet("BD#"),
                new TwelveToneSet("AC#").ShiftInScale(1, TwelveToneSet.majorScale));
            TwelveToneSet AMajor = new TwelveToneSet("AC#E");

            Assert.AreEqual(
                new TwelveToneSet("BDF"),
                AMajor.ShiftInScale(1, TwelveToneSet.majorScale));
            Assert.AreEqual(
                new TwelveToneSet("GBD"),
                AMajor.ShiftInScale(-1, TwelveToneSet.majorScale));
            Assert.AreEqual(
                new TwelveToneSet("FAC"),
                AMajor.ShiftInScale(-2, TwelveToneSet.majorScale));
            Assert.AreEqual(
                new TwelveToneSet("EG#B"),
                AMajor.ShiftInScale(-3, TwelveToneSet.majorScale));

            TwelveToneSet CSharp = new TwelveToneSet("C#EGB");

            Assert.AreEqual(
                new TwelveToneSet("DFAC"),
                CSharp.ShiftInScale(1, TwelveToneSet.majorScale));
            Assert.AreEqual(
                new TwelveToneSet("F#ACE"),
                CSharp.ShiftInScale(3, TwelveToneSet.majorScale));
            Assert.AreEqual(
                new TwelveToneSet("BDFA"),
                CSharp.ShiftInScale(-1, TwelveToneSet.majorScale));
            Assert.AreEqual(
                new TwelveToneSet("ACEG"),
                CSharp.ShiftInScale(-2, TwelveToneSet.majorScale));

            TwelveToneSet FSharp = new TwelveToneSet("F#G");

            Assert.AreEqual(
                new TwelveToneSet("EF"),
                FSharp.ShiftInScale(-1, TwelveToneSet.majorScale));
            Assert.AreEqual(
                new TwelveToneSet("G#A"),
                FSharp.ShiftInScale(1, TwelveToneSet.majorScale));
            Assert.AreEqual(
                new TwelveToneSet("A#B"),
                FSharp.ShiftInScale(2, TwelveToneSet.majorScale));
            Assert.AreEqual(
                new TwelveToneSet("BC"),
                FSharp.ShiftInScale(3, TwelveToneSet.majorScale));
        }
Esempio n. 6
0
        static void Main2(string[] args)
        {
            Random        rand  = new Random();
            TwelveToneSet chord = TwelveToneSet.major7;
            TwelveToneSet scale = TwelveToneSet.majorScale;
            int           dist  = 0;

            Console.WriteLine($"Chord: {chord.ToString()}");
            int startFrom = chord.First;

            do
            {
                Play(chord, startFrom);
                Thread.Sleep(2000);
                TwelveToneSet chordNew = new TwelveToneSet(rand, 4, scale.ShiftRight(rand.Next(TwelveToneSet.TWELVE)));
                dist = Distance(chord, chordNew);
                for (int i = 0; i < 10; i++)
                {
                    TwelveToneSet chord2 = new TwelveToneSet(rand, 4, scale.ShiftRight(rand.Next(TwelveToneSet.TWELVE)));
                    if (chord.Equals(chord2))
                    {
                        continue;
                    }

                    int dist2 = Distance(chord, chord2);
                    if (dist2 < dist)
                    {
                        dist     = dist2;
                        chordNew = chord2;
                    }
                }
                Console.Write($"Distance: {dist}={chord.DistanceScales(chordNew)}+{chord.DistanceCommonTones(chordNew)}+{chordNew.InScale()}  ");
                Console.WriteLine($"Chord: { chordNew.ToString()}");

                chord = chordNew;
            } while (true);
        }
Esempio n. 7
0
        public void TwelveToneSetCtr()
        {
            // Major and Minor scales
            Assert.AreEqual(TwelveToneSet.majorScale, new TwelveToneSet(MusicalModes.Major));
            Assert.AreEqual(TwelveToneSet.minorScale, new TwelveToneSet(MusicalModes.Minor));

            // Harmonic and Melodic minor scales
            Assert.AreNotEqual(TwelveToneSet.minorScale, new TwelveToneSet(MusicalModes.MinorHarmonic));
            Assert.AreNotEqual(TwelveToneSet.minorScale, new TwelveToneSet(MusicalModes.MinorMelodic));

            foreach (var mode in Enum.GetValues(typeof(MusicalModes)))
            {
                TwelveToneSet toneset = new TwelveToneSet((MusicalModes)mode);
                Assert.IsTrue(toneset.IsRooted);
                if ((MusicalModes)mode == MusicalModes.Chromatic)
                {
                    Assert.AreEqual(TwelveToneSet.TWELVE, toneset.Count);
                }
                else
                {
                    Assert.AreEqual(7, toneset.Count);
                }
            }
        }
Esempio n. 8
0
        public void TwelveToneSetScaleTest()
        {
            // Check major and minor scale
            Assert.AreEqual(new TwelveToneSet(new int[] { 0, 2, 4, 5, 7, 9, 11 }), TwelveToneSet.majorScale);
            Assert.AreEqual(new TwelveToneSet(new int[] { 0, 2, 3, 5, 7, 8, 10 }), TwelveToneSet.minorScale);

            //// Major and minor scale are different but similar
            Assert.AreNotEqual(TwelveToneSet.majorScale, TwelveToneSet.minorScale);
            Assert.IsTrue(TwelveToneSet.majorScale.IsSimilar(TwelveToneSet.minorScale));

            // Minor, minor harmonic, minor melodic are NOT similar
            Assert.IsFalse(TwelveToneSet.minorScale.IsSimilar(TwelveToneSet.minorHarmonicScale));
            Assert.IsFalse(TwelveToneSet.minorScale.IsSimilar(TwelveToneSet.minorMelodicScale));
            Assert.IsFalse(TwelveToneSet.minorHarmonicScale.IsSimilar(TwelveToneSet.minorMelodicScale));

            // Ionian, Dorian, Phrygian, Lydian, Mixolydian, Aoelian, Locrian
            for (MusicalModes mode = MusicalModes.Ionian; mode <= MusicalModes.Locrian; mode++)
            {
                TwelveToneSet set = new TwelveToneSet(mode);
                Assert.IsTrue(set.IsSimilar(TwelveToneSet.majorScale));
                Assert.IsFalse(set.IsSimilar(TwelveToneSet.minorHarmonicScale));
                Assert.IsFalse(set.IsSimilar(TwelveToneSet.minorMelodicScale));
            }
        }
Esempio n. 9
0
 static int Distance(TwelveToneSet chord1, TwelveToneSet chord2)
 {
     return(chord1.TotalDistance(chord2) + chord2.InScale());
 }