Refactor midi creation