public MidiNote(int start, int length, MidiPitch pitch, Velocity velocity) { Start = start; End = start + length; Velocity = velocity; Pitch = pitch; }
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 ? "#" : "")); }
public IEnumerable <MidiPitch> PitchesHigherThan(MidiPitch lowestPossiblePitch) { var pitches = Pitches(-1); while (pitches.Any(p => p < lowestPossiblePitch)) { pitches = pitches.Select(p => p + 12); } return(pitches); }
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)); }
/// <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."); } }
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); }
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]); }
public static MidiPitch AddOctave(this MidiPitch pitch, int octaves) { return(pitch + 12 * octaves); }
public static int OctaveOf(this MidiPitch p) { return((int)p / 12 - 1); }
public static Pitch FromMidiPitch(this MidiPitch p) { return((Pitch)((int)p % 12)); }