Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incoming events - how to get sustain pedal data? #47

Closed
Yorgg opened this issue Nov 1, 2019 · 3 comments
Closed

Incoming events - how to get sustain pedal data? #47

Yorgg opened this issue Nov 1, 2019 · 3 comments
Labels
question Just question about the library
Projects

Comments

@Yorgg
Copy link

Yorgg commented Nov 1, 2019

I am listening to the InputDevice and want to get the noteName and velocity from NoteOn, NoteOff events, and also the sustain pedal event (on piano).

I know the EventType, but don't know what to do next:

       if (e.EventType == DryWetMidi.Smf.MidiEventType.NoteOn)
       {
           // -> NoteName ???
           // -> velocity ???
       }

thank you

@Yorgg
Copy link
Author

Yorgg commented Nov 1, 2019

I just realized I can do a cast: (I'm new to c#)

 if (e.EventType == Melanchall.DryWetMidi.Smf.MidiEventType.NoteOn)
        {
            var note = e as NoteOnEvent;

            Debug.Log(note.Velocity);
            Debug.Log($"{note.GetNoteName()}{note.GetNoteOctave()}");
        }

I have one question remaining: how to get the sustain pedal data?

@Yorgg Yorgg changed the title Incoming events - how to get individual event data? Incoming events - how to get sustain pedal data? Nov 1, 2019
@melanchall
Copy link
Owner

Hi,

According to MIDI standard, sustain pedal on/off is a control change event. So you can use this code:

var controlChangeEvent = e as ControlChangeEvent;
if (controlChangeEvent != null && ControlUtilities.GetControlName(controlChangeEvent) == ControlName.DamperPedal)
{
    var controlValue = controlChangeEvent.ControlValue;
    var sustainOn = controlValue < 64;
}

Values from 0 to 63 correspond to sustain is turned on.

@Yorgg
Copy link
Author

Yorgg commented Nov 2, 2019

Great thanks.

@Yorgg Yorgg closed this as completed Nov 2, 2019
@melanchall melanchall added the question Just question about the library label Feb 2, 2020
@melanchall melanchall added this to Done in DryWetMIDI Mar 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Just question about the library
Projects
DryWetMIDI
  
Done
Development

No branches or pull requests

2 participants