Read MIDI file into a data frame and inspect the music data with supporting functions.
Usage
read_midi(file, ticks_per_qtr = 480)
midi_metadata(x)
midi_notes(x, channel = NULL, track = NULL, noteworthy = TRUE)
midi_time(x)
midi_key(x)
ticks_to_duration(x, ticks_per_qtr = 480)
duration_to_ticks(x, ticks_per_qtr = 480)
Arguments
- file
character, path to MIDI file.
- ticks_per_qtr
ticks per quarter note. Used to compute durations from MIDI file ticks.
- x
a data frame returned by
read_midi()
. An integer vector forticks_to_duration()
; a character vector (may be a space-delimited string) forduration_to_ticks()
.- channel, track
integer, filter rows on channel or track.
- noteworthy
logical, convert to
noteworthy
andnoteinfo
data.
Details
The read_midi()
function wraps around tuneR::readMidi()
by Uwe Ligges and
Johanna Mielke. midi_notes()
is a work in progress, but converts MIDI data
to noteworthy strings and note info formats. This makes it easy to analyze,
transform and edit the music data as well as render it to sheet music and a
new MIDI file.
read_midi()
does not parse the ticks per quarter note from the MIDI file
input at this time. It must be specified with ticks_per_qtr
.
Examples
ticks_to_duration(c(120, 160))
#> [1] "16" "t8"
ticks_to_duration(c(128, 192, 512), ticks_per_qtr = 384)
#> [1] "t8" "8" "t2"
duration_to_ticks(c("t8", "8", "8.", "8.."))
#> [1] 160 240 360 420
duration_to_ticks(c("t8 8 8. 8.."), ticks_per_qtr = 384)
#> [1] 128 192 288 336
file <- system.file("example2.mid", package = "tabr")
if(require("tuneR")){
x <- read_midi(file, ticks_per_qtr = 384)
midi_metadata(x)
midi_time(x)
midi_key(x)
midi_notes(x, channel = 0, noteworthy = FALSE)
(x <- midi_notes(x, channel = 0))
(x <- as_music(x$pitch, x$duration))
# requires LilyPond installation
if(tabr_options()$lilypond != ""){
out <- file.path(tempdir(), "out.pdf")
phrase(x) |> track_bc() |> score() |> tab(out, details = FALSE)
}
}
#> Loading required package: tuneR