コード例 #1
0
 public MusicNote(Note note, int octave = 4, RhythmicUnit rhythmicUnit = RhythmicUnit.Whole, int dotCount = 0)
 {
     _note         = note;
     _octave       = octave;
     _rhythmicUnit = rhythmicUnit;
     _dotCount     = dotCount;
 }
コード例 #2
0
        public static IEnumerable <Note> AddRhythm(this IEnumerable <Pitch> pitches, string durations)
        {
            var units = new Queue <RhythmicUnit>(RhythmicUnit.Parse(durations, " "));

            if (pitches.Count() != units.Count)
            {
                throw new Exception("Durations must have the same count as pitches.");
            }
            return(pitches.Select(p => new Note(p, units.Dequeue().Duration)).ToArray());
        }
コード例 #3
0
        public static IEnumerable <Note> AddRhythm(this IEnumerable <Pitch> pitches, params int[] durations)
        {
            if (pitches.Count() != durations.Length)
            {
                throw new Exception("Durations must have the same count as pitches.");
            }
            var units = new Queue <RhythmicUnit>(RhythmicUnit.Parse(durations));

            return(pitches.Select(p => new Note(p, units.Dequeue().Duration)).ToArray());
        }
コード例 #4
0
 /// <summary>
 /// Creates a Note or a Rest from RhythmicUnit.
 /// </summary>
 /// <param name="unit"></param>
 /// <returns></returns>
 public static NoteOrRest FromRhythmicUnit(RhythmicUnit unit)
 {
     return(unit.IsRest ? (NoteOrRest) new Rest(unit.Duration) : new Note(unit.Duration));
 }
コード例 #5
0
 private static double CalculateDurationInBeats(RhythmicUnit rhythmicUnit, int dotCount)
 {
     return((2 * (1 / (double)rhythmicUnit)) - ((1 / (double)rhythmicUnit) / System.Math.Pow(2, dotCount)));
 }