Play midi from MidiFramer object. Helper function to synthesize midi, either:
directly in the console,
or generate audio files and include a small player in html documents.
This helper function is also called in the MidiFramer$play()
method.
WARNING: Setting overwrite = TRUE
(the default!!) will DELETE the specified audio files!!!
(see more details below)
Usage
player(
midifile,
soundfont = fluidsynth::soundfont_path(),
output = gsub(".mid$", ".mp3", midifile),
live = interactive(),
verbose = interactive(),
overwrite = TRUE,
...
)
Arguments
- midifile
Path to the midi file to synthesize on; character string.
- soundfont
path to sf2 sound font (character string); if not specified, the default soundfont of the fluidsynth package (
fluidsynth::soundfont_path()
) will be (downloaded if not present and) used.- output
Path to the audiofile to be synthesized. (character string).
- live
logical; if
TRUE
the synthesized midi is directly played in the console. IfFALSE
an audio html tag is written. This will generate a small audio player when knitting an Rmd document (and probably also Quarto qmd files; I didn't check).- verbose
logical whether to print command line output; defaults to FALSE
- overwrite
logical; defaults to TRUE; if file exists and overwrite = FALSE, the existing files will not be overwritten and the function errors out.
- ...
Arguments passed to the fluidsynth functions (
fluidsynth::midi_play
orfluidsynth::midi_convert
depending on the value oflive
).
Value
If live = TRUE
, nothing is returned. If live = FALSE
, a html
audio tag is returned that will render as a small audio player when knitting
an Rmd document. The audio player can then play the generated output
audio file.
Examples
midi_file_string <- system.file("extdata", "test_midi_file.mid", package = "pyramidi")
midi_file_string |> player()
#> <audio controls="">
#> <source src="/tmp/RtmpcdQMVt/temp_libpath1e2a167c2fce/pyramidi/extdata/test_midi_file.mp3" type="audio/mp3"/>
#> </audio>
# The player is a small helper function to do basically this:
if (FALSE) {
midifile <- system.file("extdata", "test_midi_file.mid", package = "pyramidi")
mp3file <- "test.mp3"
fluidsynth::midi_convert(midifile, output = mp3file)
# `overwrite` = TRUE overwrites the mp3 file if previously existing.
}