private void MidiLoaded(object sender, TempoChangedEventArgs e) { }
public void LoadMidi(MidiFile file) { MidiFileSequencer sequencer = new MidiFileSequencer(new Synthesizer(44100, 2, 1024, 1)); //temporary needs changed sequencer.Stop(); sequencer.UnloadMidi(); sequencer.LoadMidi(file); midiMessages = sequencer.getData(); division = file.Division; //-------------------parsing midi var currentPosition = 0f; var previousDelta = 0f; foreach (var message in midiMessages) { /*var delta = (message.delta - previousDelta); * currentPosition += delta; * previousDelta += delta;*/ var delta = message.originalDelta; currentPosition += delta; for (int i = 0; i < currentlyDrawing.Count; i++) { currentlyDrawing[i].length += delta; } if ((int)message.command == 0x80 || ((int)message.command == 0x90 && message.data2 == 0)) { var noteToStop = currentlyDrawing.Find(item => item.key == (message.data1 - 21)); if (noteToStop != null) { Draw(noteToStop, magnitude); currentlyDrawing.Remove(noteToStop); } } else if ((int)message.command == 0x90) { var toAdd = new pianoNote() { length = 0f, velocity = message.data2, key = (int)message.data1 - 21, heightPositionOnScreen = currentPosition }; currentlyDrawing.Add(toAdd); } if ((int)message.command == 0xFF && message.data1 == 0x51) { //throw TEMPO CHANGED EVENT Debug.Log($"BPM: {message.BPM}"); } } //------------------------------- //trigger midi loaded event so that any listeners can have access to the midi file division TempoChangedEventArgs args = new TempoChangedEventArgs(120, magnitude); MidiLoaded?.Invoke(this, args); }
private void sr_TempoChanged(object sender, TempoChangedEventArgs e) { OnPropertyChanged("Duration"); }
public void OnTempoChanged(object sender, TempoChangedEventArgs e) { Print($"Tempo changed to {e.TempoBPM} BPM"); }