Exemple #1
0
        public static List <int[]> GetRawListOfAcceptableTransormations(List <Triad> triads)
        {
            var Transformations = new List <int[]>();

            foreach (var triad1 in triads)
            {
                foreach (var triad2 in triads)
                {
                    Transformations.Add(TriadTransformation.GetATransformation(triad1, triad2));
                }
            }
            return(Transformations);
        }
        static public void playsomeTriads(List <TriadTransformationWithData> transdata, int times = 5)
        {
            for (int ttt = 0; ttt < times; ttt++)
            {
                var goodone      = transdata[Utils.FairRandom.Next(transdata.Count)];
                var interestings = goodone.ApplicationsOnVariosTriads; //.Where(tt => tt.StayInPlace == true).ToList();

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

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

                var testTriad = new Triad(
                    JustNote.getNoteFromNumber(48),
                    TriadTypes.GetChordFormula(item.InitialTriadType),
                    item.InitialTriadMode,
                    item.InitialTriadInversion
                    );

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

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

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

                    using (var player = new Player())
                    {
                        Pattern p1     = new Pattern($"T140 V0 I[Piano] {testTriad.ChordNotes[0].GetNFugueName()}w ");
                        Pattern p2     = new Pattern($"T140 V1 I[Flute] {testTriad.ChordNotes[1].GetNFugueName()}w ");
                        Pattern p3     = new Pattern($"T140 V2 I[Flute] {testTriad.ChordNotes[2].GetNFugueName()}w ");
                        int     k21111 = 0;
                        player.Play(p1, p2, p3);
                    }
                    int k1111 = 0;
                    TriadTransformation.ApplyATransformation(testTriad, goodone.Formula);
                }
            }
        }
Exemple #3
0
        public static List <TriadTransformationWithData> CalculateTransDataForTriads(List <int[]> triadsTransformations)
        {
            var TransData = new List <TriadTransformationWithData>();

            int counttt = 0;

            foreach (var item in triadsTransformations)
            {
                var a = new TriadTransformationWithData();
                a.Formula = item;
                a.ApplicationsOnVariosTriads = new List <TriadTransformationWithDetailedInfo>();

                foreach (var triadtype in TriadTypes.TriadsTypes.Keys)
                {
                    foreach (TriadMode mode in (TriadMode[])Enum.GetValues(typeof(TriadMode)))
                    {
                        foreach (TriadInversion inv in (TriadInversion[])Enum.GetValues(typeof(TriadInversion)))
                        {
                            var b = new TriadTransformationWithDetailedInfo();

                            b.InitialTriadType      = triadtype;
                            b.InitialTriadMode      = mode;
                            b.InitialTriadInversion = inv;

                            var testTriad = new Triad(JustNote.getNoteFromNumber(48), TriadTypes.GetChordFormula(triadtype), mode, inv);

                            b.TheApplications     = new List <TriadSignature>();
                            b.TheStepsTransitions = new List <TriadStepsTransition>();

                            var bb = new TriadSignature();
                            bb.ChordType = testTriad.TriadType;
                            bb.Mode      = testTriad.Mode;
                            bb.Inversion = testTriad.Inversion;
                            b.TheApplications.Add(bb);

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

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

                            int simpleLoopFound = 0;
                            int fullLoopFound   = 0;

                            int stepsTaken = 0;
                            while (TriadTransformation.ApplyATransformation(testTriad, a.Formula) && !b.Cyclic)
                            {
                                var bbb = new TriadSignature();
                                bbb.ChordType = testTriad.TriadType;
                                bbb.Mode      = testTriad.Mode;
                                bbb.Inversion = testTriad.Inversion;
                                b.TheApplications.Add(bbb);

                                var bbc = new TriadStepsTransition();
                                bbc.TonicMoved = testTriad.ChordNotes[0].getNoteNumber() - prevNotes[0].getNoteNumber();
                                bbc.ThirdMoved = testTriad.ChordNotes[1].getNoteNumber() - prevNotes[1].getNoteNumber();
                                bbc.FifthMoved = testTriad.ChordNotes[2].getNoteNumber() - prevNotes[2].getNoteNumber();

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

                                if (prevNotes[0].getNoteNumber() == testTriad.ChordNotes[0].getNoteNumber())
                                {
                                    bbc.TonicInto = TriadStep.T;
                                }
                                else if (prevNotes[0].getNoteNumber() == testTriad.ChordNotes[1].getNoteNumber())
                                {
                                    bbc.TonicInto = TriadStep.III;
                                }
                                else if (prevNotes[0].getNoteNumber() == testTriad.ChordNotes[2].getNoteNumber())
                                {
                                    bbc.TonicInto = TriadStep.V;
                                }

                                if (prevNotes[1].getNoteNumber() == testTriad.ChordNotes[0].getNoteNumber())
                                {
                                    bbc.ThirdInto = TriadStep.T;
                                }
                                else if (prevNotes[1].getNoteNumber() == testTriad.ChordNotes[1].getNoteNumber())
                                {
                                    bbc.ThirdInto = TriadStep.III;
                                }
                                else if (prevNotes[1].getNoteNumber() == testTriad.ChordNotes[2].getNoteNumber())
                                {
                                    bbc.ThirdInto = TriadStep.V;
                                }

                                if (prevNotes[2].getNoteNumber() == testTriad.ChordNotes[0].getNoteNumber())
                                {
                                    bbc.FifthInto = TriadStep.T;
                                }
                                else if (prevNotes[2].getNoteNumber() == testTriad.ChordNotes[1].getNoteNumber())
                                {
                                    bbc.FifthInto = TriadStep.III;
                                }
                                else if (prevNotes[2].getNoteNumber() == testTriad.ChordNotes[2].getNoteNumber())
                                {
                                    bbc.FifthInto = TriadStep.V;
                                }

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

                                b.TheStepsTransitions.Add(bbc);

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

                                stepsTaken++;

                                // TODO : More complicated and trusted way to determine exact cycle
                                if (testTriad.TriadType == triadtype)
                                {
                                    simpleLoopFound++;
                                }
                                if (testTriad.TriadType == triadtype && testTriad.Mode == mode && testTriad.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.ApplicationsOnVariosTriads.Add(b);
                            }
                        }
                    }
                }
                if (a.ApplicationsOnVariosTriads.Count > 0)
                {
                    TransData.Add(a);
                }
                counttt++;
                Console.WriteLine(TransData.Count + " :: " + counttt + " :: " + " [" + a.Formula[0] + "  " + a.Formula[1] + "  " + a.Formula[2] + "] " + a.ApplicationsOnVariosTriads.Count);
            }


            return(TransData);
        }