Пример #1
0
        public static bool ApplyATransformation(Triad triad, int[] transformation, int transpose = 0)
        {
            triad.TriadType = Triad.DetermineTriadType(triad);
            var mode = TriadTypes.TriadModeFormula[triad.Mode];

            triad.ChordNotes[0] = JustNote.moveNoteBySemitones(triad.ChordNotes[0], transformation[0] + transpose);
            triad.ChordNotes[1] = JustNote.moveNoteBySemitones(triad.ChordNotes[1], transformation[1] + transpose);
            triad.ChordNotes[2] = JustNote.moveNoteBySemitones(triad.ChordNotes[2], transformation[2] + transpose);

            triad.TriadType = Triad.DetermineTriadType(triad);
            if (triad.TriadType == "undefined")
            {
                return(false);
            }

            try
            {
                Triad.ResetTriadRootStepsModeAndInversion(triad);
                if (triad.ChordNotes.All(cn => cn.unboundOctave > 19 || cn.unboundOctave < -10))
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception) { return(false); }
        }
Пример #2
0
        public static int[] GetATransformation(Triad triad1, Triad triad2)
        {
            var notes1 = triad1.ChordNotes.OrderBy(n => n.getNoteNumber()).ToArray();
            var notes2 = triad2.ChordNotes.OrderBy(n => n.getNoteNumber()).ToArray();

            var aTransformation  = new int[3];
            var aTransformation2 = new int[3];

            for (int i = 0; i < 3; i++)
            {
                aTransformation2[i] = notes2[i].getNoteNumber() - notes1[i].getNoteNumber();
            }

            var indexes = new int[3] {
                0, 0, 0
            };

            for (int i = 0; i < 3; i++)
            {
                int ind2 = 0;
                while (triad1.ChordNotes[i] != notes1[ind2])
                {
                    ind2++;
                    indexes[i]++;
                }
            }

            aTransformation[0] = aTransformation2[indexes[0]];
            aTransformation[1] = aTransformation2[indexes[1]];
            aTransformation[2] = aTransformation2[indexes[2]];

            if (aTransformation[0] > 0)
            {
                while (aTransformation[0] > 0)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        aTransformation[i] -= 1;
                    }
                }
            }
            else if (aTransformation[0] < 0)
            {
                while (aTransformation[0] < 0)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        aTransformation[i] += 1;
                    }
                }
            }

            return(aTransformation);
        }
        static public string DetermineTriadType(Triad triad)
        {
            var f        = new int[3];
            var neuTriad = new Triad(triad.ChordNotes[0], triad.ChordNotes[1], triad.ChordNotes[2], triad.Mode, triad.Inversion);

            int size = neuTriad.GetChordSize();

            var notes = neuTriad.ChordNotes.OrderBy(n => n.getNoteNumber()).ToArray();

            while (size > 12)
            {
                notes = notes.OrderBy(n => n.getNoteNumber()).ToArray();

                notes[0] = JustNote.moveNoteBySemitones(notes[0], 12);

                notes = notes.OrderBy(n => n.getNoteNumber()).ToArray();
                size  = notes.Last().getNoteNumber() - notes.First().getNoteNumber();
                if (size > 12)
                {
                    notes[2] = JustNote.moveNoteBySemitones(notes[2], -12);
                    notes    = notes.OrderBy(n => n.getNoteNumber()).ToArray();

                    size = notes.Last().getNoteNumber() - notes.First().getNoteNumber();
                }
            }

            f[0] = notes[1].getNoteNumber() - notes[0].getNoteNumber();
            f[1] = notes[2].getNoteNumber() - notes[1].getNoteNumber();
            f[2] = 12 - f[0] - f[1];

            var fTemp = new int[3];

            for (int i = 0; i < 3; i++)
            {
                fTemp[0] = f[(i + 0) % 3];
                fTemp[1] = f[(i + 1) % 3];
                fTemp[2] = f[(i + 2) % 3];

                if (TriadTypes.TriadsTypes.Select(fff => fff.Value).Any(fo => fo[0] == fTemp[0] && fo[1] == fTemp[1] && fo[2] == fTemp[2]))
                {
                    neuTriad.TriadType = TriadTypes.TriadsTypes.First(fo => fo.Value[0] == fTemp[0] && fo.Value[1] == fTemp[1] && fo.Value[2] == fTemp[2]).Key.ToString();
                    break;
                }

                if (i == 3)
                {
                    neuTriad.TriadType = "undefined";
                }
            }
            return(neuTriad.TriadType);
        }
        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);
                }
            }
        }
Пример #5
0
        public static List <Triad> GetAllPossibleTriads()
        {
            var listo = new List <Triad>();

            foreach (var item in TriadTypes.TriadsTypes)
            {
                for (int m = 0; m < 2; m++)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        var chordo = new Triad(JustNote.getNoteFromNumber(36), item.Value);
                        chordo.Mode = (TriadMode)m;
                        chordo.InverseForward((TriadInversion)i);
                        listo.Add(chordo);
                    }
                }
            }
            return(listo);
        }
        static public void ResetTriadRootStepsModeAndInversion(Triad triad)
        {
            for (int n = 0; n < 3; n++)
            {
                for (int m = 0; m < 2; m++)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        var neuTriad = new Triad(triad.ChordNotes[n], GetChordFormula(triad.TriadType), (TriadMode)m, (TriadInversion)i);

                        var notesNeu  = neuTriad.ChordNotes.OrderBy(n2 => n2.getNoteNumber()).ToArray().Select(nn => nn.nameOfTheNote).ToList();
                        var notesOrig = triad.ChordNotes.OrderBy(n2 => n2.getNoteNumber()).ToArray().Select(nn => nn.nameOfTheNote).ToList();

                        if (
                            notesNeu[0] == notesOrig[0] &&
                            notesNeu[1] == notesOrig[1] &&
                            notesNeu[2] == notesOrig[2]
                            )
                        {
                            JustNote[] notes = new JustNote[4];
                            notes[0] = triad.ChordNotes[0];
                            notes[1] = triad.ChordNotes[1];
                            notes[2] = triad.ChordNotes[2];

                            triad.ChordNotes[0] = notes.Where(no => no.nameOfTheNote == neuTriad.ChordNotes[0].nameOfTheNote).First();
                            triad.ChordNotes[1] = notes.Where(no => no.nameOfTheNote == neuTriad.ChordNotes[1].nameOfTheNote).First();
                            triad.ChordNotes[2] = notes.Where(no => no.nameOfTheNote == neuTriad.ChordNotes[2].nameOfTheNote).First();

                            triad.Mode      = neuTriad.Mode;
                            triad.Inversion = neuTriad.Inversion;
                            return;
                        }
                    }
                }
            }
        }
Пример #7
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);
        }