public IntervalPattern( IntervalQuality quality, IntervalQuantity quantity = IntervalQuantity.Unison) { this.quantity = quantity; this.semitones = GetSemitones(); this.quality = quality; }
public static IntervalQuality GetQuality(IntervalQuantity quantity, int semitones) { var intQuantity = (int) quantity; var quant = intQuantity > 7 ? intQuantity % 7 : intQuantity; var quality = IntervalToSemitones[quant].First(s => s == semitones); if (quality != null) return (IntervalQuality) quality; throw new Exception(); }
public static Interval GetC4BasedInterval(IntervalQuality quality, IntervalQuantity quantity) { var C4 = new Pitch(new Step(StepLetter.C)); switch (quantity) { case IntervalQuantity.Unison: if (quality == IntervalQuality.Perfect) return new Interval(C4, C4); else throw new ArgumentException(string.Format(exceptionFormatString, quantity, quality)); break; case IntervalQuantity.Second: if (quality == IntervalQuality.Minor) return new Interval(C4, new Pitch(new Step(StepLetter.D), accidental: Accidentals.Flat)); if (quality == IntervalQuality.Major) return new Interval(C4, new Pitch(new Step(StepLetter.D))); if (quality == IntervalQuality.Augmented) return new Interval(C4, new Pitch(new Step(StepLetter.D), accidental: Accidentals.Sharp)); if (quality == IntervalQuality.Diminished) return new Interval(C4, new Pitch(new Step(StepLetter.D), accidental: Accidentals.DoubleFlat)); else throw new ArgumentException(string.Format(exceptionFormatString, quantity, quality)); break; case IntervalQuantity.Third: if (quality == IntervalQuality.Minor) return new Interval(C4, new Pitch(new Step(StepLetter.E), accidental: Accidentals.Flat)); if (quality == IntervalQuality.Major) return new Interval(C4, new Pitch(new Step(StepLetter.E))); if (quality == IntervalQuality.Augmented) return new Interval(C4, new Pitch(new Step(StepLetter.E), accidental: Accidentals.Sharp)); if (quality == IntervalQuality.Diminished) return new Interval(C4, new Pitch(new Step(StepLetter.E), accidental: Accidentals.DoubleFlat)); else throw new ArgumentException(string.Format(exceptionFormatString, quantity, quality)); break; case IntervalQuantity.Fourth: if (quality == IntervalQuality.Perfect) return new Interval(C4, new Pitch(new Step(StepLetter.F))); if (quality == IntervalQuality.Augmented) return new Interval(C4, new Pitch(new Step(StepLetter.F), accidental: Accidentals.Sharp)); if (quality == IntervalQuality.Diminished) return new Interval(C4, new Pitch(new Step(StepLetter.F), accidental: Accidentals.Flat)); else throw new ArgumentException(string.Format(exceptionFormatString, quantity, quality)); break; case IntervalQuantity.Fifth: if (quality == IntervalQuality.Perfect) return new Interval(C4, new Pitch(new Step(StepLetter.G))); if (quality == IntervalQuality.Augmented) return new Interval(C4, new Pitch(new Step(StepLetter.G), accidental: Accidentals.Sharp)); if (quality == IntervalQuality.Diminished) return new Interval(C4, new Pitch(new Step(StepLetter.G), accidental: Accidentals.Flat)); else throw new ArgumentException(string.Format(exceptionFormatString, quantity, quality)); break; case IntervalQuantity.Sixth: if (quality == IntervalQuality.Minor) return new Interval(C4, new Pitch(new Step(StepLetter.A), accidental: Accidentals.Flat)); if (quality == IntervalQuality.Major) return new Interval(C4, new Pitch(new Step(StepLetter.A))); if (quality == IntervalQuality.Augmented) return new Interval(C4, new Pitch(new Step(StepLetter.A), accidental: Accidentals.Sharp)); if (quality == IntervalQuality.Diminished) return new Interval(C4, new Pitch(new Step(StepLetter.A), accidental: Accidentals.DoubleFlat)); else throw new ArgumentException(string.Format(exceptionFormatString, quantity, quality)); break; case IntervalQuantity.Seventh: if (quality == IntervalQuality.Minor) return new Interval(C4, new Pitch(new Step(StepLetter.B), accidental: Accidentals.Flat)); if (quality == IntervalQuality.Major) return new Interval(C4, new Pitch(new Step(StepLetter.B))); if (quality == IntervalQuality.Augmented) return new Interval(C4, new Pitch(new Step(StepLetter.A), accidental: Accidentals.Sharp)); if (quality == IntervalQuality.Diminished) return new Interval(C4, new Pitch(new Step(StepLetter.A), accidental: Accidentals.DoubleFlat)); else throw new ArgumentException(string.Format(exceptionFormatString, quantity, quality)); break; case IntervalQuantity.Octave: var tempInterval = GetC4BasedInterval(quality, IntervalQuantity.Unison); if (quality == IntervalQuality.Perfect) return new Interval(tempInterval.Root, tempInterval.Top.TransposeOctaves(1)); if (quality == IntervalQuality.Augmented) return new Interval(C4, new Pitch(new Step(StepLetter.A), accidental: Accidentals.Sharp)); if (quality == IntervalQuality.Diminished) return new Interval(C4, new Pitch(new Step(StepLetter.A), accidental: Accidentals.DoubleFlat)); else throw new ArgumentException(string.Format(exceptionFormatString, quantity, quality)); break; case IntervalQuantity.Ninth: break; case IntervalQuantity.Tenth: break; case IntervalQuantity.Eleventh: break; case IntervalQuantity.Twelfth: break; case IntervalQuantity.Thirteenth: break; case IntervalQuantity.Fourteenth: break; case IntervalQuantity.Fifteenth: break; default: break; } return default(Interval); }