refactoring the send midi packet function