Skip to contents

This function randomly changes individual 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.

Usage

mangle_note_wiggler(midi_df, semitones = c(2, 7), keep_same = 2)

Arguments

midi_df

a midi dataframe, usually imported from midi_to_object().

semitones

numeric vector. default is c(2,7). The function automatically appends negative values as well.

keep_sam

integer, number of 0s to add in semitpones vector, when this value is selected a given note is not shifted

Value

A data frame with the same structure as midi_df, but with the note and velocity columns modified according to the randomly sampled note offsets. 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)

# make sure midi_df has a tempo
midi_df <- midiblender::set_midi_tempo_midi_df(midi_df)

# apply random note offsets
copy_df <- mangle_note_wiggler(midi_df, c(4,7), keep_same = 2)

# update miditapyr df
miditapyr_object$midi_frame_unnested$update_unnested_mf(copy_df)

#write midi file to disk
miditapyr_object$write_file("note_wiggler_mario.mid")
}