public Pitch TranslatePitch(Pitch pitch, DiatonicInterval interval) { var stepNumber = StepToStepNumber(pitch.ToStep()); var halfTones = 0; if (interval.Steps == 0) { throw new ArithmeticException("There is no interval with 0 steps."); } if (interval.Steps > 0) { for (var i = 0; i < interval.Steps - 1; i++) { halfTones += Mode.GetIntervalAfterStep(stepNumber + i); } } else if (interval.Steps < 0) { for (var i = 0; i > interval.Steps + 1; i--) { halfTones -= Mode.GetIntervalBeforeStep(stepNumber + i); } } return(Pitch.FromMidiPitch(pitch.MidiPitch + halfTones, MidiPitchTranslationMode)); }
public bool IsIntervalDiatonic(Pitch pitch, Interval interval) { if (!FullScale.Contains(pitch.ToStep())) { throw new ArgumentException(string.Format("Starting pitch {0} does not belong to scale.", pitch), "pitch"); } var newStep = pitch.Translate(interval, MidiPitchTranslationMode).ToStep(); return(FullScale.Contains(newStep)); }
/// <summary> /// Returns an interval between two pitches. /// </summary> /// <param name="p1">First pitch</param> /// <param name="p2">Second pitch</param> /// <returns>Interval between two pitches.</returns> public static Interval Between(Pitch p1, Pitch p2) { return(new Interval(p2.ToStep().ToStepNumber() - p1.ToStep().ToStepNumber() + 1, (p2.MidiPitch - p1.MidiPitch) % 12)); }