Пример #1
0
        public IEnumerable <Pitch> BuildScale(int startingMidiPitch, Pitch.MidiPitchTranslationMode translationMode, int startingStep, int numberOfSteps)
        {
            if (startingStep < 1)
            {
                throw new ArgumentException("Starting step must be greater than 0.", "startingStep");
            }
            if (numberOfSteps < 1)
            {
                throw new ArgumentException("Number of steps must be greater than 0.", "numberOfSteps");
            }

            var pitches   = new List <Pitch>();
            var midiPitch = startingMidiPitch;

            for (int step = startingStep; step < startingStep + numberOfSteps; step++)
            {
                pitches.Add(Pitch.FromMidiPitch(midiPitch, translationMode));
                midiPitch = midiPitch + GetIntervalAfterStep(step);
            }
            return(pitches);
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of BoundInterval which is generated by translation of specific pitch by specific interval.
 /// </summary>
 /// <param name="pitch">Pitch to translate</param>
 /// <param name="interval">Interval</param>
 /// <param name="translationMode">Translation mode</param>
 public BoundInterval(Pitch pitch, Interval interval, Pitch.MidiPitchTranslationMode translationMode)
     : base(interval.Steps, interval.Halftones)
 {
     StartingPitch = pitch;
     EndingPitch   = pitch.Translate(interval, translationMode);
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of BoundInterval that represents an interval between two pitches.
 /// </summary>
 /// <param name="pitch1"></param>
 /// <param name="pitch2"></param>
 public BoundInterval(Pitch pitch1, Pitch pitch2) : base(Pitch.StepDistance(pitch1, pitch2) + 1, pitch2.MidiPitch - pitch1.MidiPitch)
 {
     StartingPitch = pitch1;
     EndingPitch   = pitch2;
 }
Пример #4
0
 /// <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));
 }
Пример #5
0
 public Pitch ToPitch(int octaveNumber = 4)
 {
     return(Pitch.FromStep(this, octaveNumber));
 }
Пример #6
0
 /// <summary>
 /// Creates a new instance of step from specified pitch
 /// </summary>
 /// <param name="pitch"></param>
 /// <returns></returns>
 public static Step FromPitch(Pitch pitch)
 {
     return(new Step {
         StepName = pitch.StepName, Alter = pitch.Alter
     });
 }
 /// <summary>
 /// Initializes a new instance of TunedPitch with specific pitch and frequency.
 /// </summary>
 /// <param name="pitch">Pitch</param>
 /// <param name="freq">Frequency [Hz]</param>
 public TunedPitch(Pitch pitch, double freq) : base(pitch.StepName, pitch.Alter, pitch.Octave)
 {
     Frequency = freq;
 }
Пример #8
0
 public Pitch TranslatePitch(Pitch pitch, Interval interval)
 {
     return(Pitch.FromMidiPitch(pitch.MidiPitch + interval.Halftones, MidiPitchTranslationMode));
 }