public static bool ApplyATransformation(SevenChord chordo, int[] transformation, int transpose = 0) { chordo.ChordType = SevenChord.DetermineChordType(chordo); var mode = SevenChordTypes.SevenChordModeFormula[chordo.Mode]; chordo.ChordNotes[0] = JustNote.moveNoteBySemitones(chordo.ChordNotes[0], transformation[0] + transpose); chordo.ChordNotes[1] = JustNote.moveNoteBySemitones(chordo.ChordNotes[1], transformation[1] + transpose); chordo.ChordNotes[2] = JustNote.moveNoteBySemitones(chordo.ChordNotes[2], transformation[2] + transpose); chordo.ChordNotes[3] = JustNote.moveNoteBySemitones(chordo.ChordNotes[3], transformation[3] + transpose); chordo.ChordType = SevenChord.DetermineChordType(chordo); if (chordo.ChordType == "undefined") { return(false); } try { SevenChord.ResetChordRootStepsModeAndInversion(chordo); if (chordo.ChordNotes.All(cn => cn.unboundOctave > 19 || cn.unboundOctave < -10)) { return(false); } else { return(true); } } catch (Exception) { return(false); } }
public Triad(JustNote baseNote, int[] theFormula, TriadMode mode = TriadMode.I, TriadInversion inv = TriadInversion.I) { TriadType = TriadTypes.TriadsTypes.First(f => f.Value[0] == theFormula[0] && f.Value[1] == theFormula[1] && f.Value[2] == theFormula[2]).Key.ToString(); ChordNotes[0] = baseNote; var tempNote = baseNote; for (int i = 1; i < 3; i++) { tempNote = JustNote.moveNoteBySemitones(tempNote, theFormula[i - 1]); ChordNotes[i] = tempNote; } Mode = mode; switch (Mode) { case TriadMode.I: break; case TriadMode.II: ChordNotes[1] = JustNote.moveNoteBySemitones(ChordNotes[1], 12); break; default: break; } this.InverseForward(inv); Inversion = inv; }
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); } }
public void TransposeTheChord(int semitones) { int j = 0; foreach (var note in ChordNotes) { ChordNotes[j] = JustNote.moveNoteBySemitones(note, semitones); j++; } }
static public string DetermineChordType(SevenChord chordo) { var f = new int[4]; var neuChordo = new SevenChord(chordo.ChordNotes[0], chordo.ChordNotes[1], chordo.ChordNotes[2], chordo.ChordNotes[3], chordo.Mode, chordo.Inversion); int size = neuChordo.GetChordSize(); var notes = neuChordo.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[3] = JustNote.moveNoteBySemitones(notes[3], -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] = notes[3].getNoteNumber() - notes[2].getNoteNumber(); f[3] = 12 - f[0] - f[1] - f[2]; var fTemp = new int[4]; for (int i = 0; i < 4; i++) { fTemp[0] = f[(i + 0) % 4]; fTemp[1] = f[(i + 1) % 4]; fTemp[2] = f[(i + 2) % 4]; fTemp[3] = f[(i + 3) % 4]; if (SevenChordTypes.SevenchordTypes.Select(fff => fff.Value).Any(fo => fo[0] == fTemp[0] && fo[1] == fTemp[1] && fo[2] == fTemp[2] && fo[3] == fTemp[3])) { neuChordo.ChordType = SevenChordTypes.SevenchordTypes.First(fo => fo.Value[0] == fTemp[0] && fo.Value[1] == fTemp[1] && fo.Value[2] == fTemp[2] && fo.Value[3] == fTemp[3]).Key.ToString(); break; } if (i == 3) { neuChordo.ChordType = "undefined"; } } return(neuChordo.ChordType); }
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); }
public SevenChord(JustNote baseNote, int[] theFormula, SevenChordMode mode = SevenChordMode.I, SevenChordInversion inv = SevenChordInversion.I) { ChordType = SevenChordTypes.SevenchordTypes.First(f => f.Value[0] == theFormula[0] && f.Value[1] == theFormula[1] && f.Value[2] == theFormula[2] && f.Value[3] == theFormula[3]).Key.ToString(); ChordNotes[0] = baseNote; var tempNote = baseNote; for (int i = 1; i < 4; i++) { tempNote = JustNote.moveNoteBySemitones(tempNote, theFormula[i - 1]); ChordNotes[i] = tempNote; } Mode = mode; switch (Mode) { case SevenChordMode.I: break; case SevenChordMode.II: ChordNotes[1] = JustNote.moveNoteBySemitones(ChordNotes[1], 12); ChordNotes[3] = JustNote.moveNoteBySemitones(ChordNotes[3], 12); break; case SevenChordMode.III: ChordNotes[2] = JustNote.moveNoteBySemitones(ChordNotes[2], 12); break; case SevenChordMode.IV: ChordNotes[1] = JustNote.moveNoteBySemitones(ChordNotes[1], 12); break; case SevenChordMode.V: ChordNotes[1] = JustNote.moveNoteBySemitones(ChordNotes[1], 12); ChordNotes[2] = JustNote.moveNoteBySemitones(ChordNotes[2], 12); break; case SevenChordMode.VI: ChordNotes[1] = JustNote.moveNoteBySemitones(ChordNotes[1], 24); ChordNotes[2] = JustNote.moveNoteBySemitones(ChordNotes[2], 12); break; default: break; } this.InverseForward(inv); Inversion = inv; }
// TODO : Keep specific chord steps on their place public void InverseForward(TriadInversion inv) { var mode = TriadTypes.TriadModeFormula[Mode]; var b = mode[(0 + (int)inv) % 3]; var c = mode[(1 + (int)inv) % 3]; var a = mode[(2 + (int)inv) % 3]; while (ChordNotes[b].getNoteNumber() > ChordNotes[c].getNoteNumber()) { ChordNotes[c] = JustNote.moveNoteBySemitones(ChordNotes[c], 12); } while (ChordNotes[c].getNoteNumber() > ChordNotes[a].getNoteNumber()) { ChordNotes[a] = JustNote.moveNoteBySemitones(ChordNotes[a], 12); } Inversion = inv; }
// TODO : Keep specific chord steps on their place public void InverseBackward(SevenChordInversion inv) { var mode = SevenChordTypes.SevenChordModeFormula[Mode]; var b = mode[(3 + (int)inv) % 4]; var c = mode[(2 + (int)inv) % 4]; var d = mode[(1 + (int)inv) % 4]; var a = mode[(0 + (int)inv) % 4]; while (ChordNotes[b].getNoteNumber() < ChordNotes[c].getNoteNumber()) { ChordNotes[c] = JustNote.moveNoteBySemitones(ChordNotes[c], -12); } while (ChordNotes[c].getNoteNumber() < ChordNotes[d].getNoteNumber()) { ChordNotes[d] = JustNote.moveNoteBySemitones(ChordNotes[d], -12); } while (ChordNotes[d].getNoteNumber() < ChordNotes[a].getNoteNumber()) { ChordNotes[a] = JustNote.moveNoteBySemitones(ChordNotes[a], -12); } Inversion = inv; }
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); }