public bool Contains(ScaleDegree sd, out ScaleDegreeWithStability found) { foreach (ScaleDegreeWithStability x in scaleDegrees) { if (x.Number == sd.Number && x.Alteration == sd.Alteration) { found = x; return(true); } } found = null; return(false); }
/// <summary> /// /// </summary> /// <param name="aScale">Source scale alphabet</param> /// <param name="numStackedThirds">Set to 2 for a normal triad, 3 for a 7th, 4 for a ninth, etc.</param> /// <param name="scaleDegree">1 to 7</param> /// <returns></returns> private static Alphabet GetStackedTriadAlphabetForScaleDegree(Key k, Alphabet aScale, int numStackedThirds, int scaleDegree) { Alphabet aTriad = new Alphabet(); for (int offset = 0; offset <= numStackedThirds * 2; offset += 2) { int stability; switch (offset) { case 0: stability = 3; // root; break; case 4: stability = 2; // 5th break; default: stability = 1; // other thirds break; } ScaleDegreeWithStability sd = new ScaleDegreeWithStability(aScale[(scaleDegree - 1 + offset) % aScale.Count], stability); aTriad.Add(sd); } aTriad.Name = k.GetScaleDegreePitch(aScale[scaleDegree - 1], 4).ToString(); // Get quality of first interval. int pc1 = k.GetScaleDegreePitchClass(aTriad[0]); int pc2 = k.GetScaleDegreePitchClass(aTriad[1]) + 12; int diff = (pc2 - pc1) % 12; if (diff == 3) { aTriad.Name += "m"; } /* if (numStackedThirds == 2) * //aTriad.Name += " triad"; * else */ if (numStackedThirds > 2) { aTriad.Name += (numStackedThirds * 2 + 1).ToString(); //7, 9, etc. for 7th, 9th chords } aTriad.RootScaleDegree = new ScaleDegree(scaleDegree, Alteration.None); aTriad.RootPitchClass = k.GetScaleDegreePitchClass(aTriad.RootScaleDegree); aTriad.StepCollection = false; return(aTriad); }
static public Alphabet GetAlphabetFromScaleWithTriadOnDegree(Key key, Alphabet scale, ScaleDegree sd) { Alphabet a = (Alphabet)scale.Clone(); // record the index of the root. int rootDegree = -1; for (int i = 0; i < a.Count; i++) { ScaleDegreeWithStability sds = a[i]; if (sds.Number == sd.Number && sds.Alteration == sd.Alteration) { rootDegree = i; break; } } // Assign stability for each alphabet member. for (int j = 0; j < a.Count; j++) { ScaleDegreeWithStability sds = a[(rootDegree + j) % a.Count]; // start at the root, and go up 7 scale degrees (with mod to wrap around) int stability; switch (j) { case 0: stability = 3; // root; break; case 2: stability = 1; // 3rd break; case 3: stability = 2; // 5th break; default: stability = 0; // other thirds break; } sds.Stability = stability; } a.Name = key.GetScaleDegreePitch(sd, 4).ToString(); // Get quality of first third. int pc1 = key.GetScaleDegreePitchClass(a[rootDegree]); int pc2 = key.GetScaleDegreePitchClass(a[(rootDegree + 2) % a.Count]) + 12; int diff = (pc2 - pc1) % 12; if (diff == 3) { a.Name += "m"; } //a.Name += " triad"; a.RootScaleDegree = sd; a.RootPitchClass = key.GetScaleDegreePitchClass(sd); return(a); }
/// <summary> /// Add a new ScaleDegree to the alphabet. ScaleDegrees must be added in the correct order; the order of Add calls determines alphabet adjacency. /// </summary> /// <param name="sd"></param> protected void Add(ScaleDegreeWithStability sd) { scaleDegrees.Add(sd); }