knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
JUST A DRAFT!!!
This is a rewrite of TuneR::readMidi()
, with a counterpart to write midi.
We don't create a data.frame but a R6 object.
It's still very brittle and changes frequently significantly.
I'd like to be able to change scales/modes, apply arpeggios etc, maybe do some analysis on big amounts of midi files to detect patterns in styles of music or specific artists, but we're far from there.
I'd like to do something similar with guitar pro files too as their structure is more suited to songwriting and the gp5 file format has been reverse engineered.
Install with:
remotes::install_github("moodymudskipper/midi")
Load a simple music file with 2 instruments (that's 3 tracks here)
library(midi) mid <- midi$new("https://www.8notes.com/school/midi/violin/vivaldi_spring.mid") # it prints nicely mid # we can show separately header or tracks mid$header # print names, tempo, key mid$names mid$tempo # plot mid$plot() # re-encode to midi local_file <- tempfile(fileext = ".mid") mid$encode(local_file) # and reimport to check if our back and forth transformation was reliable mid_reimported <- midi$new(local_file) all.equal(mid, mid_reimported)
We can play one track or two in stereo, this is done by converting to wave, directly inspired by David Solito's work (see https://www.davidsolito.com/post/midiplayer-avec-r-part-2/ ).
mid$play("Piano","Violin")
We can also use $cut()
to restrict the song to a time window, $rename()
and $select()
to manipulate tracks, $set_tempo()
to assign a tempo,
$shift_hstep()
to move all notes of chosen tracks by half steps or $shift_degree
to shift chosen tracks by a chosen interval on a chosen scale.
These modifications don't produce yet an obejct that one can re-encode back to midi,
but we can already use our $play()
method on them.
Harmonize Vivaldi :
mid$ # select Violin track twice (i.e. subset and duplicate) select(Violin1=Violin, Violin3=Violin)$ # shift all notes by 2 intervals in A maj so Violin3 is the third of Violin1 shift_degree(2, scale_major("a"), at = Violin3)$ # mix and play play("Violin","Violin3")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.