Example #1
0
        public static List <int[]> GetRawListOfAcceptableTransormations(List <SevenChord> chords)
        {
            var Transformations = new List <int[]>();

            foreach (var chord1 in chords)
            {
                foreach (var chord2 in chords)
                {
                    Transformations.Add(SevenChordTransformation.GetATransformation(chord1, chord2));
                }
            }
            return(Transformations);
        }
Example #2
0
        public static List <SevenChordTransformationWithData> CalculateTransDataForSevenChords(List <int[]> sChordsTransformations)
        {
            var TransData = new List <SevenChordTransformationWithData>();

            int counttt = 0;

            foreach (var item in sChordsTransformations)
            {
                var a = new SevenChordTransformationWithData();
                a.Formula = item;
                a.ApplicationsOnVariosChords = new List <SevenChordTransformationDetailedInfo>();

                foreach (var chordtype in SevenChordTypes.SevenchordTypes.Keys)
                {
                    foreach (SevenChordMode mode in (SevenChordMode[])Enum.GetValues(typeof(SevenChordMode)))
                    {
                        foreach (SevenChordInversion inv in (SevenChordInversion[])Enum.GetValues(typeof(SevenChordInversion)))
                        {
                            var b = new SevenChordTransformationDetailedInfo();

                            b.InitialChordType      = chordtype;
                            b.InitialChordMode      = mode;
                            b.InitialChordInversion = inv;

                            var testChord = new SevenChord(JustNote.getNoteFromNumber(48), SevenChordTypes.GetChordFormula(chordtype), mode, inv);

                            b.TheApplications     = new List <SevenChordSignature>();
                            b.TheStepsTransitions = new List <ChordStepsTransition>();

                            var bb = new SevenChordSignature();
                            bb.ChordType = testChord.ChordType;
                            bb.Mode      = testChord.Mode;
                            bb.Inversion = testChord.Inversion;
                            b.TheApplications.Add(bb);

                            var prevNotes = new JustNote[4];
                            for (int i = 0; i < 4; i++)
                            {
                                prevNotes[i] = testChord.ChordNotes[i];
                            }

                            var prevSize = testChord.GetChordSize();
                            var origSize = testChord.GetChordSize();

                            int simpleLoopFound = 0;
                            int fullLoopFound   = 0;

                            int stepsTaken = 0;
                            while (SevenChordTransformation.ApplyATransformation(testChord, a.Formula) && !b.Cyclic)
                            {
                                var bbb = new SevenChordSignature();
                                bbb.ChordType = testChord.ChordType;
                                bbb.Mode      = testChord.Mode;
                                bbb.Inversion = testChord.Inversion;
                                b.TheApplications.Add(bbb);

                                var bbc = new ChordStepsTransition();
                                bbc.TonicMoved   = testChord.ChordNotes[0].getNoteNumber() - prevNotes[0].getNoteNumber();
                                bbc.ThirdMoved   = testChord.ChordNotes[1].getNoteNumber() - prevNotes[1].getNoteNumber();
                                bbc.FifthMoved   = testChord.ChordNotes[2].getNoteNumber() - prevNotes[2].getNoteNumber();
                                bbc.SeventhMoved = testChord.ChordNotes[3].getNoteNumber() - prevNotes[3].getNoteNumber();

                                for (int i = 0; i < 4; i++)
                                {
                                    prevNotes[i] = JustNote.moveNoteBySemitones(prevNotes[i], a.Formula[i]);
                                }

                                if (prevNotes[0].getNoteNumber() == testChord.ChordNotes[0].getNoteNumber())
                                {
                                    bbc.TonicInto = SevenChordStep.T;
                                }
                                else if (prevNotes[0].getNoteNumber() == testChord.ChordNotes[1].getNoteNumber())
                                {
                                    bbc.TonicInto = SevenChordStep.III;
                                }
                                else if (prevNotes[0].getNoteNumber() == testChord.ChordNotes[2].getNoteNumber())
                                {
                                    bbc.TonicInto = SevenChordStep.V;
                                }
                                else if (prevNotes[0].getNoteNumber() == testChord.ChordNotes[3].getNoteNumber())
                                {
                                    bbc.TonicInto = SevenChordStep.VII;
                                }

                                if (prevNotes[1].getNoteNumber() == testChord.ChordNotes[0].getNoteNumber())
                                {
                                    bbc.ThirdInto = SevenChordStep.T;
                                }
                                else if (prevNotes[1].getNoteNumber() == testChord.ChordNotes[1].getNoteNumber())
                                {
                                    bbc.ThirdInto = SevenChordStep.III;
                                }
                                else if (prevNotes[1].getNoteNumber() == testChord.ChordNotes[2].getNoteNumber())
                                {
                                    bbc.ThirdInto = SevenChordStep.V;
                                }
                                else if (prevNotes[1].getNoteNumber() == testChord.ChordNotes[3].getNoteNumber())
                                {
                                    bbc.ThirdInto = SevenChordStep.VII;
                                }

                                if (prevNotes[2].getNoteNumber() == testChord.ChordNotes[0].getNoteNumber())
                                {
                                    bbc.FifthInto = SevenChordStep.T;
                                }
                                else if (prevNotes[2].getNoteNumber() == testChord.ChordNotes[1].getNoteNumber())
                                {
                                    bbc.FifthInto = SevenChordStep.III;
                                }
                                else if (prevNotes[2].getNoteNumber() == testChord.ChordNotes[2].getNoteNumber())
                                {
                                    bbc.FifthInto = SevenChordStep.V;
                                }
                                else if (prevNotes[2].getNoteNumber() == testChord.ChordNotes[3].getNoteNumber())
                                {
                                    bbc.FifthInto = SevenChordStep.VII;
                                }

                                if (prevNotes[3].getNoteNumber() == testChord.ChordNotes[0].getNoteNumber())
                                {
                                    bbc.SeventhInto = SevenChordStep.T;
                                }
                                else if (prevNotes[3].getNoteNumber() == testChord.ChordNotes[1].getNoteNumber())
                                {
                                    bbc.SeventhInto = SevenChordStep.III;
                                }
                                else if (prevNotes[3].getNoteNumber() == testChord.ChordNotes[2].getNoteNumber())
                                {
                                    bbc.SeventhInto = SevenChordStep.V;
                                }
                                else if (prevNotes[3].getNoteNumber() == testChord.ChordNotes[3].getNoteNumber())
                                {
                                    bbc.SeventhInto = SevenChordStep.VII;
                                }

                                bbc.SizeDifference = testChord.GetChordSize() - prevSize;
                                prevSize           = testChord.GetChordSize();

                                b.TheStepsTransitions.Add(bbc);

                                for (int i = 0; i < 4; i++)
                                {
                                    prevNotes[i] = testChord.ChordNotes[i];
                                }

                                stepsTaken++;

                                // TODO : More complicated and trusted way to determine exact cycle
                                if (testChord.ChordType == chordtype)
                                {
                                    simpleLoopFound++;
                                }
                                if (testChord.ChordType == chordtype && testChord.Mode == mode && testChord.Inversion == inv)
                                {
                                    fullLoopFound++;
                                }
                                if (fullLoopFound == 2)
                                {
                                    b.Cyclic = true;
                                }

                                if (stepsTaken > 27 && simpleLoopFound < 1)
                                {
                                    break;
                                }
                                if (stepsTaken > 55)
                                {
                                    break;
                                }
                            }


                            if (b.Cyclic)
                            {
                                b.LoopByTypeDistance = (stepsTaken / 2 + 1) / (simpleLoopFound / 2) - 1;
                                b.FullLoopDistance   = stepsTaken / 2;

                                var sum = b.TheStepsTransitions.Sum(st => st.TonicMoved);
                                if (sum == 0)
                                {
                                    b.StayInPlace = true;
                                }
                                else if (sum > 0)
                                {
                                    b.MovingUp = true;
                                }
                                else
                                {
                                    b.MovingDown = true;
                                }

                                b.TheApplications.RemoveRange(b.FullLoopDistance, b.TheApplications.Count - b.FullLoopDistance - 1);
                                b.TheStepsTransitions.RemoveRange((b.FullLoopDistance - 1), b.TheStepsTransitions.Count - b.FullLoopDistance);

                                if (origSize - prevSize == 0)
                                {
                                    b.SizeKept = true;
                                }

                                a.ApplicationsOnVariosChords.Add(b);
                            }
                        }
                    }
                }
                if (a.ApplicationsOnVariosChords.Count > 0)
                {
                    TransData.Add(a);
                }
                counttt++;
                Console.WriteLine(TransData.Count + " :: " + counttt + " :: " + " [" + a.Formula[0] + "  " + a.Formula[1] + "  " + a.Formula[2] + "  " + a.Formula[3] + "] " + a.ApplicationsOnVariosChords.Count);
            }
            return(TransData);
        }
Example #3
0
        static void Main(string[] args)
        {
            Utils.FairRandom = new Random();

            // Neeeded 'cause of symbols used to name chords
            // Without it works fine, but prints '?' all around
            Console.OutputEncoding = System.Text.Encoding.UTF8;


            /* TRIADS TESTING */
            var triads      = CalculateAllTransformations.GetAllPossibleTriads();
            int countTriads = triads.Count;

            var TriadsTransformations = CalculateAllTransformations.GetRawListOfAcceptableTransormations(triads);

            int initialTriadsTransormationsFound = TriadsTransformations.Count;

            TriadsTransformations = CalculateAllTransformations.SortAndDistintTheTransformations(TriadsTransformations);

            Console.WriteLine("\nTriads transformations ::: " + initialTriadsTransormationsFound + " -> " + TriadsTransformations.Count);

            triads.Sort(delegate(Triad tr1, Triad tr2) { return(tr1.GetChordSize().CompareTo(tr2.GetChordSize())); });

            Console.WriteLine();
            Console.WriteLine("Total triads variations count is: " + countTriads);
            Console.WriteLine();


            var TriadsTransData = CalculateAllTransformations.CalculateTransDataForTriads(TriadsTransformations);

            int triadsMaxDistance = 0;

            triadsMaxDistance = TriadsTransData.Max(t => t.ApplicationsOnVariosTriads.Max(tt => tt.FullLoopDistance));


            var stopme = 1;

            NFugueUsage.playsomeTriads(TriadsTransData, 5);


            stopme = 1;


            /* SEVEN CHORDS TESTING */
            var neg          = CalculateAllTransformations.GetAllPossibleSevenChords();
            int countChordos = neg.Count;

            var Transformations = CalculateAllTransformations.GetRawListOfAcceptableTransormations(neg);

            int initialTransormationsFound = Transformations.Count;

            Transformations = CalculateAllTransformations.SortAndDistintTheTransformations(Transformations);

            Console.WriteLine("\nSevenChords transformations ::: " + initialTransormationsFound + " -> " + Transformations.Count);


            neg.Sort(delegate(SevenChord ch1, SevenChord ch22) { return(ch1.GetChordSize().CompareTo(ch22.GetChordSize())); });

            Console.WriteLine();
            Console.WriteLine("Total chords variations count is: " + countChordos);
            Console.WriteLine();



            int counttt   = 0;
            var TransData = CalculateAllTransformations.CalculateTransDataForSevenChords(Transformations);
            // TODO: Inspect transformations on different chords for being equal

            int kk = 0;

            kk = TransData.Max(t => t.ApplicationsOnVariosChords.Max(tt => tt.FullLoopDistance));

            int kasdf = 0;


            kasdf = 1;
            var rand = new Random();

            //var goodone = TransData[rand.Next(TransData.Count)];
            //foreach (var item in goodone.ApplicationsOnVariosChords)
            //{

            //    //var testChord = new SevenChord(JustNote.getNoteFromNumber(48),
            //    //    SevenChordTypes.GetChordFormula(item.InitialChordType),
            //    //    item.InitialChordMode, item.InitialChordInversion);

            //    for (int i = 0; i < item.FullLoopDistance; i++)
            //    {

            //       // Console.WriteLine("After :: " + " [" + goodone.Formula[0] + "  " + goodone.Formula[1] + "  " + goodone.Formula[2] + "  " + goodone.Formula[3] + "] ");
            //       // Console.WriteLine(testChord.ToString());

            //        //using (var player = new Player())
            //        //{
            //        //    Pattern p1 = new Pattern($"T140 V0 I[Piano] {testChord.ChordNotes[0].GetNFugueName()}w ");
            //        //    Pattern p2 = new Pattern($"T140 V1 I[Flute] {testChord.ChordNotes[1].GetNFugueName()}w ");
            //        //    Pattern p3 = new Pattern($"T140 V2 I[Flute] {testChord.ChordNotes[2].GetNFugueName()}w ");
            //        //    Pattern p4 = new Pattern($"T140 V3 I[Flute] {testChord.ChordNotes[3].GetNFugueName()}w ");

            //        //    //player.Play(p1, p2, p3, p4);
            //        //}
            //        int k1111 = 0;
            //        //SevenChordTransformation.ApplyATransformation(testChord, goodone.Formula);
            //    }
            //}


            playsmthn();
            for (int i = 0; i < 5; i++)
            {
                playsmthn();
            }

            kasdf = 1;

            void playsmthn()
            {
                var goodone = TransData[rand.Next(TransData.Count)];

                var interestings = goodone.ApplicationsOnVariosChords; //.Where(tt => tt.StayInPlace == true).ToList();

                if (interestings.Count() == 0)
                {
                    return;
                }

                var item = interestings[rand.Next(interestings.Count)];

                var testChord = new SevenChord(JustNote.getNoteFromNumber(48),
                                               SevenChordTypes.GetChordFormula(item.InitialChordType),
                                               item.InitialChordMode, item.InitialChordInversion);

                using (var player = new Player())
                {
                    Pattern p1 = new Pattern($"T100 V0 I[Piano] {testChord.ChordNotes[0].GetNFugueName()}q ");
                    Pattern p2 = new Pattern($"T100 V1 I[Flute] {testChord.ChordNotes[1].GetNFugueName()}q ");
                    Pattern p3 = new Pattern($"T100 V2 I[Flute] {testChord.ChordNotes[2].GetNFugueName()}q ");
                    Pattern p4 = new Pattern($"T100 V3 I[Flute] {testChord.ChordNotes[3].GetNFugueName()}q ");

                    player.Play(p1, p2, p3, p4);
                }

                for (int i = 0; i < item.FullLoopDistance * 2; i++)
                {
                    Console.WriteLine("After :: " + " [" + goodone.Formula[0] + "  " + goodone.Formula[1] + "  " + goodone.Formula[2] + "  " + goodone.Formula[3] + "] ");
                    Console.WriteLine(testChord.ToString());

                    using (var player = new Player())
                    {
                        Pattern p1     = new Pattern($"T140 V0 I[Piano] {testChord.ChordNotes[0].GetNFugueName()}w ");
                        Pattern p2     = new Pattern($"T140 V1 I[Flute] {testChord.ChordNotes[1].GetNFugueName()}w ");
                        Pattern p3     = new Pattern($"T140 V2 I[Flute] {testChord.ChordNotes[2].GetNFugueName()}w ");
                        Pattern p4     = new Pattern($"T140 V3 I[Flute] {testChord.ChordNotes[3].GetNFugueName()}w ");
                        int     k21111 = 0;
                        player.Play(p1, p2, p3, p4);
                    }
                    int k1111 = 0;
                    SevenChordTransformation.ApplyATransformation(testChord, goodone.Formula);
                }
            }

            //foreach (var chordtype in SevenChordTypes.SevenchordTypes.Keys)
            //{
            //    var infos = new List<SimpleTransformationInfo>();
            //    foreach (var item in Transformations)
            //    {
            //        var testChord = new SevenChord(JustNote.getNoteFromNumber(48), SevenChordTypes.GetChordFormula(chordtype));

            //        var typeOfChord = testChord.ChordType;
            //        var typeOfChord2 = testChord.ChordType;

            //        var modeOfChord = testChord.Mode;
            //        var modeOfChord2 = testChord.Mode;

            //        var invOfChord = testChord.Inversion;
            //        var invOfChord2 = testChord.Inversion;


            //        int typeRepTwice = 0;
            //        int cycleCount = 0;
            //        if (item[0] == 0 && item[1] == 0 && item[2] == 0 && item[3] == -2)
            //        {
            //            // Console.WriteLine(testChord);
            //            // Console.WriteLine(SevenChord.DetermineChordType(testChord));
            //        }

            //        while (SevenChordTransformation.ApplyATransformation(testChord, new int[] { item[0], item[1], item[2], item[3] }))
            //        {
            //            typeOfChord2 = testChord.ChordType;
            //            modeOfChord2 = testChord.Mode;
            //            invOfChord2 = testChord.Inversion;


            //            if (typeOfChord2 == typeOfChord && modeOfChord2 == modeOfChord && invOfChord2 == invOfChord) typeRepTwice++;
            //            if (typeRepTwice == 2)
            //                break;

            //            if (item[0] == 0 && item[1] == 0 && item[2] == 0 && item[3] == -2)
            //            {
            //                // Console.WriteLine(testChord);
            //                // Console.WriteLine(SevenChord.DetermineChordType(testChord));
            //            }
            //            // Console.WriteLine(ch3);
            //            //Console.WriteLine(SevenChord.DetermineChordType(ch3));
            //            cycleCount++;

            //            if (cycleCount > 100)
            //                break;
            //        }

            //        if (typeRepTwice == 2)
            //        {
            //            var ku = new SimpleTransformationInfo();
            //            ku.count = cycleCount / 2 + 1;
            //            ku.mess = "The cycle [" + item[0] + "  " + item[1] + "  " + item[2] + "  " + item[3] + "] looped on " + (cycleCount / 2 + 1) + " turn.";

            //            infos.Add(ku);
            //            //Console.WriteLine("The cycle [" + item[0] + "  " + item[1] + "  " + item[2] + "  " + item[3] + "] looped on " + (cycleCount / 2 + 1) + " turn.");
            //        }
            //        else
            //        {
            //            //    if (cycleCount < 10 && cycleCount > 0)
            //            //        Console.WriteLine("The cycle [" + item[0] + "  " + item[1] + "  " + item[2] + "  " + item[3] + "] crashed on " + cycleCount + " turn.");
            //        }
            //    }
            //    infos.Sort(delegate (SimpleTransformationInfo ti1, SimpleTransformationInfo ti2) { return ti1.count.CompareTo(ti2.count); });

            //    var ninfos = infos.GroupBy(iii => iii.count).ToList();
            //    Console.WriteLine(chordtype + " loops by steps: ");
            //    ninfos.ForEach(niii => Console.WriteLine(niii.Key + ": " + niii.Count()));
            //}

            Console.Read();
        }