示例#1
0
文件: Score.cs 项目: solcz/NewWave
 public MidiNote(int start, int length, MidiPitch pitch, Velocity velocity)
 {
     Start    = start;
     End      = start + length;
     Velocity = velocity;
     Pitch    = pitch;
 }
示例#2
0
        public static string NoteName(this MidiPitch pitch)
        {
            var toString = pitch.ToString();
            var letter   = toString.Substring(0, 1);
            var isSharp  = toString.Contains("Sharp");

            return(string.Format("{0}{1}", letter, isSharp ? "#" : ""));
        }
示例#3
0
        public IEnumerable <MidiPitch> PitchesHigherThan(MidiPitch lowestPossiblePitch)
        {
            var pitches = Pitches(-1);

            while (pitches.Any(p => p < lowestPossiblePitch))
            {
                pitches = pitches.Select(p => p + 12);
            }
            return(pitches);
        }
示例#4
0
        private List <Tuple <int, Chord> > GetChordProgression(MidiPitch lowestPossibleNote, ChordProgression progression)
        {
            var chordList = progression
                            .Chords
                            .Take(Randomizer.Clamp(Randomizer.NextNormalized(3, 1), 2, 3))
                            .Select(c => TransposeForLowestNote(lowestPossibleNote, TransposeForKey(_songInfo.Parameters.MajorKey, c)))
                            .ToList();

            return(AssignChords(chordList, _measures * _songInfo.TimeSignature.BeatCount));
        }
示例#5
0
        /// <summary>
        /// Creates a new note instance.
        /// </summary>
        /// <param name="start">The starting position of the note, in ticks.</param>
        /// <param name="length">The length of the note, in ticks.</param>
        /// <param name="pitch">The pitch of the note.</param>
        /// <param name="velocity">The Velocity of the note, 0-127.</param>
        public Note(double start, double length, MidiPitch pitch, Velocity velocity)
        {
            Start    = start;
            Length   = length;
            Pitch    = pitch;
            Velocity = velocity;

            if ((int)velocity > 127 || (int)velocity < 0)
            {
                throw new Exception("Velocity must be between 0 and 127 inclusive.");
            }
        }
示例#6
0
        private static Chord TransposeForLowestNote(MidiPitch lowestPossibleNote, Chord result)
        {
            var rootOctave          = lowestPossibleNote.OctaveOf();
            var currentLowest       = result.Pitches(rootOctave).Min();
            var minPitchToTranspose = lowestPossibleNote.AddOctave(1);

            while (currentLowest >= minPitchToTranspose)
            {
                result.Transpose(-12);
                currentLowest = result.Pitches(rootOctave).Min();
            }
            return(result);
        }
示例#7
0
        public static MidiPitch Step(Pitch root, ScaleType scaleType, MidiPitch start, int steps)
        {
            if (steps == 0)
            {
                return(start);
            }

            var scale      = GetScale(root, scaleType).ToList();
            var pitchScale = scale.Select(s => s.ToMidiPitch(start.OctaveOf())).ToList();
            var octaves    = Math.Abs(steps) / scale.Count + 2;

            for (var i = 1; i <= octaves; i++)
            {
                pitchScale.AddRange(scale.Select(s => s.ToMidiPitch(start.OctaveOf() + (steps > 0 ? i : -i))).ToList());
            }
            pitchScale = pitchScale.OrderBy(p => p).ToList();

            var startIndex  = pitchScale.IndexOf(start);
            var returnIndex = startIndex + steps;

            return(pitchScale[returnIndex]);
        }
示例#8
0
 public static MidiPitch AddOctave(this MidiPitch pitch, int octaves)
 {
     return(pitch + 12 * octaves);
 }
示例#9
0
 public static int OctaveOf(this MidiPitch p)
 {
     return((int)p / 12 - 1);
 }
示例#10
0
 public static Pitch FromMidiPitch(this MidiPitch p)
 {
     return((Pitch)((int)p % 12));
 }