This function changes the note values in a MIDI data frame by a certain number of semitones. It also ensures that the note values stay within the MIDI range (0-127) and mutes any notes that fall outside this range.
Arguments
- midi_df
a midi dataframe, usually imported from
midi_to_object().- semitones
Numeric. The number of semitones to transpose the
notecolumn. If themetacolumn isFALSE, the function will add or subtract this number from the original note value. Default is 0, which means no transposition will occur.
Value
A data frame with the same structure as midi_df, but with the note and
velocity columns modified according to the transposition and MIDI range rules.
Any notes that fall outside the 0-127 range will have their velocity set to 0 (muted),
and their note value will be set to 127.
Examples
if (FALSE) {
# import midi
mario <- midi_to_object("all_overworld.mid")
list2env(mario, .GlobalEnv) #send objects to Global environment
# apply transpose
copy_df <- mangle_transpose(midi_df, -10)
# update miditapyr df
miditapyr_object$midi_frame_unnested$update_unnested_mf(copy_df)
#write midi file to disk
miditapyr_object$write_file("transpose_mario.mid")
}
