/// <summary> /// A MidiChordDef having msDuration, and containing an ornament having BasicMidiChordDefs with nPitchesPerChord. /// The notated pitch and the pitch of BasicMidiChordDefs[0] are set to rootNotatedPitch. /// The notated velocity of all pitches is set to 127. /// The root pitches of the BasicMidiChordDefs begin with rootNotatedPitch, and follow the ornamentEnvelope, using /// the ornamentEnvelope's values as indices in the gamut. Their durations are as equal as possible, to give the /// overall msDuration. If ornamentEnvelope is null, a single, one-note BasicMidiChordDef will be created. /// This constructor uses Gamut.GetChord(rootNotatedPitch, nPitchesPerChord) which returns pitches that are /// vertically spaced differently according to the absolute height of the rootNotatedPitch. The number of pitches /// in a chord may also be less than nPitchesPerChord (see gamut.GetChord(...) ). /// An exception is thrown if rootNotatedPitch is not in the gamut. /// </summary> /// <param name="msDuration">The duration of this MidiChordDef</param> /// <param name="gamut">The gamut containing all the pitches.</param> /// <param name="rootNotatedPitch">The lowest notated pitch. Also the lowest pitch of BasicMidiChordDefs[0].</param> /// <param name="nPitchesPerChord">The chord density (some chords may have less pitches).</param> /// <param name="ornamentEnvelope">The ornament definition.</param> public MidiChordDef(int msDuration, Gamut gamut, int rootNotatedPitch, int nPitchesPerChord, Envelope ornamentEnvelope = null) : base(msDuration) { NotatedMidiPitches = gamut.GetChord(rootNotatedPitch, nPitchesPerChord); var nmVelocities = new List<byte>(); foreach(byte pitch in NotatedMidiPitches) // can be less than nPitchesPerChord { nmVelocities.Add(127); } NotatedMidiVelocities = nmVelocities; // Sets BasicMidiChords. If ornamentEnvelope == null, BasicMidiChords[0] is set to the NotatedMidiChord. SetOrnament(gamut, ornamentEnvelope); }
/// <summary> /// A BasicMidiChordDef having density notes. Absent fields are set to 0 or null. /// Note that the number of pitches returned can be less than nPitches. Pitches that would be higher than 127 are /// simply not added to the returned list. /// All pitches are given velocity = 127. /// The pitches are found using the function gamut.GetChord(rootPitch, density). See that function for further documentation. /// </summary> /// <param name="msDuration">The duration</param> /// <param name="gamut"></param> /// <param name="rootPitch">The lowest pitch</param> /// <param name="density">The number of pitches. The actual number created can be smaller.</param> public BasicMidiChordDef(int msDuration, Gamut gamut, int rootPitch, int density) { #region conditions Debug.Assert(density > 0 && density <= 12); Debug.Assert(rootPitch >= 0 && rootPitch <= 127); Debug.Assert(msDuration > 0); #endregion conditions _msDuration = msDuration; // read-only! Pitches = gamut.GetChord(rootPitch, density); var newVelocities = new List<byte>(); foreach(byte pitch in Pitches) // can be less than nPitchesPerChord { newVelocities.Add(127); } Velocities = newVelocities; }