public MidiSequence(float[] times, int[] notes, float[] lengths, float[] velocities, double length, ManualMidiEvents eventSender, AudioEngine engine) { FEngine = engine; FEventSender = eventSender; //note count FCount = times.Length; //arrays for on and off events FStartTimes = new float[FCount]; FEndTimes = new float[FCount]; FNoteOns = new MidiNoteData[FCount]; FNoteOffs = new MidiNoteData[FCount]; var i = 0; foreach (var time in times) { FStartTimes[i] = Math.Max(time, 0); //end times must be at least about one sample after the note on FEndTimes[i] = FStartTimes[i] + Math.Max(lengths[i % lengths.Length], 0.00000520833f); var noteOn = new MidiNoteData() { NoteNumber = (byte)notes[i % notes.Length], Velocity = (byte)(velocities[i % velocities.Length] * 255) }; var noteOff = new MidiNoteData() { NoteNumber = noteOn.NoteNumber, Velocity = (byte)0 }; FNoteOns[i] = noteOn; FNoteOffs[i] = noteOff; i++; } FLength = Math.Max(Math.Abs(length), 0.00000520833f); }
public MidiSequence(float[] times, int[] notes, float[] lengths, float[] velocities, double length, ManualMidiEvents eventSender, AudioEngine engine) { FEngine = engine; FEventSender = eventSender; //note count FCount = times.Length; //arrays for on and off events FStartTimes = new float[FCount]; FEndTimes = new float[FCount]; FNoteOns = new MidiNoteData[FCount]; FNoteOffs = new MidiNoteData[FCount]; var i = 0; foreach (var time in times) { FStartTimes[i] = Math.Max(time, 0); //end times must be at least about one sample after the note on FEndTimes[i] = FStartTimes[i] + Math.Max(lengths[i % lengths.Length], 0.00000520833f); var noteOn = new MidiNoteData() { NoteNumber = (byte)notes[i % notes.Length], Velocity = (byte) (velocities[i % velocities.Length]*255) }; var noteOff = new MidiNoteData() { NoteNumber = noteOn.NoteNumber, Velocity = (byte)0 }; FNoteOns[i] = noteOn; FNoteOffs[i] = noteOff; i++; } FLength = Math.Max(Math.Abs(length), 0.00000520833f); }