Setup
By using install_miditapyr()
, this should also install
mido which is a dependency of
miditapyr:
pyramidi::install_miditapyr(envname = "r-reticulate")
#> Using virtual environment 'r-reticulate' ...
Now we’ll load some R and the python mido & miditapyr libraries
with the reticulate::import()
function. The loading of
import_builtins()
into pb
will allow to work
with python objects from R:
library(reticulate)
library(pyramidi)
library(tidyr)
library(purrr)
library(details)
mido <- import("mido")
#> Error in python_config_impl(python) :
#> Error running '/home/runner/.virtualenvs/r-reticulate/python': No such file.
#> The Python installation used to create the virtualenv has been moved or removed:
#> '/opt/hostedtoolcache/Python/3.11.8/x64/bin'
mt <- import("miditapyr")
pb <- import_builtins()
Load file
Here we’ll load the midi file included in the package into a mido.MidiFile
object:
midi_file_string <- system.file("extdata", "test_midi_file.mid", package = "pyramidi")
midi_file <- mido$MidiFile(midi_file_string)
midi_file
Click here to show the printed mido
MidiFile()
object
MidiFile(type=1, ticks_per_beat=960, tracks=[
MidiTrack([
MetaMessage('track_name', name='drum-t1-1-t1', time=0),
Message('note_on', channel=9, note=43, velocity=72, time=0),
Message('note_on', channel=9, note=39, velocity=64, time=0),
Message('note_on', channel=9, note=36, velocity=101, time=0),
MetaMessage('set_tempo', tempo=666666, time=0),
MetaMessage('time_signature', numerator=4, denominator=4, clocks_per_click=24, notated_32nd_notes_per_beat=8, time=0),
Message('note_off', channel=9, note=43, velocity=72, time=240),
Message('note_off', channel=9, note=39, velocity=64, time=0),
Message('note_off', channel=9, note=36, velocity=101, time=0),
Message('note_on', channel=9, note=42, velocity=101, time=240),
Message('note_on', channel=9, note=38, velocity=101, time=0),
Message('note_on', channel=9, note=43, velocity=64, time=240),
Message('note_off', channel=9, note=42, velocity=101, time=0),
Message('note_off', channel=9, note=38, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=64, time=240),
Message('note_on', channel=9, note=36, velocity=101, time=0),
Message('note_off', channel=9, note=36, velocity=101, time=240),
Message('note_on', channel=9, note=43, velocity=60, time=240),
Message('note_on', channel=9, note=42, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=60, time=240),
Message('note_off', channel=9, note=42, velocity=101, time=0),
Message('note_on', channel=9, note=43, velocity=60, time=240),
Message('note_on', channel=9, note=39, velocity=66, time=0),
Message('note_on', channel=9, note=36, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=60, time=240),
Message('note_off', channel=9, note=39, velocity=66, time=0),
Message('note_off', channel=9, note=36, velocity=101, time=0),
Message('note_on', channel=9, note=42, velocity=101, time=240),
Message('note_on', channel=9, note=38, velocity=101, time=0),
Message('note_on', channel=9, note=43, velocity=53, time=240),
Message('note_off', channel=9, note=42, velocity=101, time=0),
Message('note_off', channel=9, note=38, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=53, time=240),
Message('note_on', channel=9, note=36, velocity=101, time=0),
Message('note_off', channel=9, note=36, velocity=101, time=240),
Message('note_on', channel=9, note=43, velocity=52, time=240),
Message('note_on', channel=9, note=42, velocity=66, time=0),
Message('note_off', channel=9, note=43, velocity=52, time=240),
Message('note_off', channel=9, note=42, velocity=66, time=0),
Message('note_on', channel=9, note=43, velocity=72, time=240),
Message('note_on', channel=9, note=39, velocity=64, time=0),
Message('note_on', channel=9, note=36, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=72, time=240),
Message('note_off', channel=9, note=39, velocity=64, time=0),
Message('note_off', channel=9, note=36, velocity=101, time=0),
Message('note_on', channel=9, note=42, velocity=101, time=240),
Message('note_on', channel=9, note=38, velocity=101, time=0),
Message('note_on', channel=9, note=43, velocity=64, time=240),
Message('note_off', channel=9, note=42, velocity=101, time=0),
Message('note_off', channel=9, note=38, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=64, time=240),
Message('note_on', channel=9, note=36, velocity=101, time=0),
Message('note_off', channel=9, note=36, velocity=101, time=240),
Message('note_on', channel=9, note=43, velocity=60, time=240),
Message('note_on', channel=9, note=42, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=60, time=240),
Message('note_off', channel=9, note=42, velocity=101, time=0),
Message('note_on', channel=9, note=43, velocity=60, time=240),
Message('note_on', channel=9, note=39, velocity=66, time=0),
Message('note_on', channel=9, note=36, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=60, time=240),
Message('note_off', channel=9, note=39, velocity=66, time=0),
Message('note_off', channel=9, note=36, velocity=101, time=0),
Message('note_on', channel=9, note=42, velocity=101, time=240),
Message('note_on', channel=9, note=38, velocity=101, time=0),
Message('note_on', channel=9, note=43, velocity=53, time=240),
Message('note_off', channel=9, note=42, velocity=101, time=0),
Message('note_off', channel=9, note=38, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=53, time=240),
Message('note_on', channel=9, note=36, velocity=101, time=0),
Message('note_off', channel=9, note=36, velocity=101, time=240),
Message('note_on', channel=9, note=43, velocity=52, time=240),
Message('note_on', channel=9, note=42, velocity=66, time=0),
Message('note_off', channel=9, note=43, velocity=52, time=240),
Message('note_off', channel=9, note=42, velocity=66, time=0),
Message('note_on', channel=9, note=43, velocity=72, time=240),
Message('note_on', channel=9, note=39, velocity=64, time=0),
Message('note_on', channel=9, note=36, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=72, time=240),
Message('note_off', channel=9, note=39, velocity=64, time=0),
Message('note_off', channel=9, note=36, velocity=101, time=0),
Message('note_on', channel=9, note=42, velocity=101, time=240),
Message('note_on', channel=9, note=38, velocity=101, time=0),
Message('note_on', channel=9, note=43, velocity=64, time=240),
Message('note_off', channel=9, note=42, velocity=101, time=0),
Message('note_off', channel=9, note=38, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=64, time=240),
Message('note_on', channel=9, note=36, velocity=101, time=0),
Message('note_off', channel=9, note=36, velocity=101, time=240),
Message('note_on', channel=9, note=43, velocity=60, time=240),
Message('note_on', channel=9, note=42, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=60, time=240),
Message('note_off', channel=9, note=42, velocity=101, time=0),
Message('note_on', channel=9, note=43, velocity=60, time=240),
Message('note_on', channel=9, note=39, velocity=66, time=0),
Message('note_on', channel=9, note=36, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=60, time=240),
Message('note_off', channel=9, note=39, velocity=66, time=0),
Message('note_off', channel=9, note=36, velocity=101, time=0),
Message('note_on', channel=9, note=42, velocity=101, time=240),
Message('note_on', channel=9, note=38, velocity=101, time=0),
Message('note_on', channel=9, note=43, velocity=53, time=240),
Message('note_off', channel=9, note=42, velocity=101, time=0),
Message('note_off', channel=9, note=38, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=53, time=240),
Message('note_on', channel=9, note=36, velocity=101, time=0),
Message('note_off', channel=9, note=36, velocity=101, time=240),
Message('note_on', channel=9, note=43, velocity=52, time=240),
Message('note_on', channel=9, note=42, velocity=66, time=0),
Message('note_off', channel=9, note=43, velocity=52, time=240),
Message('note_off', channel=9, note=42, velocity=66, time=0),
Message('note_on', channel=9, note=43, velocity=81, time=240),
Message('note_on', channel=9, note=36, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=81, time=240),
Message('note_off', channel=9, note=36, velocity=101, time=0),
Message('note_on', channel=9, note=42, velocity=101, time=240),
Message('note_on', channel=9, note=39, velocity=57, time=0),
Message('note_on', channel=9, note=38, velocity=101, time=0),
Message('note_on', channel=9, note=43, velocity=60, time=240),
Message('note_off', channel=9, note=42, velocity=101, time=0),
Message('note_off', channel=9, note=39, velocity=57, time=0),
Message('note_off', channel=9, note=38, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=60, time=240),
Message('note_on', channel=9, note=36, velocity=101, time=0),
Message('note_off', channel=9, note=36, velocity=101, time=240),
Message('note_on', channel=9, note=43, velocity=66, time=240),
Message('note_on', channel=9, note=42, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=66, time=240),
Message('note_off', channel=9, note=42, velocity=101, time=0),
Message('note_on', channel=9, note=43, velocity=66, time=240),
Message('note_on', channel=9, note=36, velocity=101, time=0),
Message('note_off', channel=9, note=43, velocity=66, time=240),
Message('note_off', channel=9, note=36, velocity=101, time=0),
Message('note_on', channel=9, note=46, velocity=81, time=240),
Message('note_on', channel=9, note=45, velocity=67, time=0),
Message('note_on', channel=9, note=39, velocity=60, time=0),
Message('note_on', channel=9, note=38, velocity=101, time=0),
Message('note_off', channel=9, note=46, velocity=81, time=240),
Message('note_off', channel=9, note=45, velocity=67, time=0),
Message('note_off', channel=9, note=39, velocity=60, time=0),
Message('note_off', channel=9, note=38, velocity=101, time=0),
Message('note_on', channel=9, note=39, velocity=59, time=240),
Message('note_on', channel=9, note=36, velocity=101, time=0),
Message('note_off', channel=9, note=39, velocity=59, time=240),
Message('note_on', channel=9, note=39, velocity=55, time=0),
Message('note_off', channel=9, note=36, velocity=101, time=0),
Message('note_on', channel=9, note=45, velocity=63, time=240),
Message('note_on', channel=9, note=43, velocity=52, time=0),
Message('note_on', channel=9, note=42, velocity=101, time=0),
Message('note_off', channel=9, note=39, velocity=55, time=0),
Message('note_on', channel=9, note=39, velocity=55, time=0),
Message('note_off', channel=9, note=45, velocity=63, time=240),
Message('note_off', channel=9, note=43, velocity=52, time=0),
Message('note_off', channel=9, note=42, velocity=101, time=0),
Message('note_on', channel=9, note=42, velocity=59, time=0),
Message('note_off', channel=9, note=39, velocity=55, time=0),
Message('note_on', channel=9, note=39, velocity=57, time=0),
Message('note_off', channel=9, note=42, velocity=59, time=240),
Message('note_off', channel=9, note=39, velocity=57, time=0),
MetaMessage('end_of_track', time=1)]),
MidiTrack([
MetaMessage('track_name', name='Audio+MIDI', time=0),
Message('note_on', channel=15, note=50, velocity=82, time=0),
Message('note_off', channel=15, note=50, velocity=82, time=240),
Message('note_on', channel=15, note=45, velocity=85, time=3000),
Message('note_on', channel=15, note=50, velocity=81, time=600),
Message('note_off', channel=15, note=45, velocity=85, time=0),
Message('note_off', channel=15, note=50, velocity=81, time=240),
Message('note_on', channel=15, note=45, velocity=69, time=3120),
Message('note_on', channel=15, note=50, velocity=69, time=480),
Message('note_off', channel=15, note=45, velocity=69, time=0),
Message('note_off', channel=15, note=50, velocity=69, time=360),
Message('note_on', channel=15, note=45, velocity=82, time=2400),
Message('note_off', channel=15, note=45, velocity=82, time=960),
Message('note_on', channel=15, note=50, velocity=72, time=120),
Message('note_off', channel=15, note=50, velocity=72, time=1080),
Message('note_on', channel=15, note=57, velocity=79, time=360),
Message('note_off', channel=15, note=57, velocity=79, time=480),
Message('note_on', channel=15, note=55, velocity=50, time=0),
Message('note_off', channel=15, note=55, velocity=50, time=480),
Message('note_on', channel=15, note=53, velocity=73, time=0),
Message('note_off', channel=15, note=53, velocity=73, time=480),
Message('note_on', channel=15, note=52, velocity=69, time=0),
Message('note_off', channel=15, note=52, velocity=69, time=480),
Message('note_on', channel=15, note=48, velocity=85, time=0),
Message('note_off', channel=15, note=48, velocity=85, time=480),
MetaMessage('end_of_track', time=1)]),
MidiTrack([
MetaMessage('track_name', name='Audio+MIDI 1', time=0),
Message('note_on', channel=15, note=62, velocity=78, time=54),
Message('note_on', channel=15, note=57, velocity=78, time=10),
Message('note_on', channel=15, note=65, velocity=72, time=6),
Message('note_off', channel=15, note=65, velocity=72, time=283),
Message('note_off', channel=15, note=62, velocity=78, time=16),
Message('note_off', channel=15, note=57, velocity=78, time=55),
Message('note_on', channel=15, note=62, velocity=57, time=1049),
Message('note_on', channel=15, note=57, velocity=53, time=9),
Message('note_on', channel=15, note=65, velocity=58, time=8),
Message('note_off', channel=15, note=65, velocity=58, time=1652),
Message('note_off', channel=15, note=62, velocity=57, time=8),
Message('note_off', channel=15, note=57, velocity=53, time=47),
Message('note_on', channel=15, note=62, velocity=61, time=142),
Message('note_on', channel=15, note=57, velocity=53, time=9),
Message('note_on', channel=15, note=65, velocity=58, time=8),
Message('note_off', channel=15, note=62, velocity=61, time=188),
Message('note_off', channel=15, note=65, velocity=58, time=8),
Message('note_off', channel=15, note=57, velocity=53, time=24),
Message('note_on', channel=15, note=62, velocity=47, time=275),
Message('note_on', channel=15, note=57, velocity=42, time=8),
Message('note_on', channel=15, note=65, velocity=46, time=9),
Message('note_off', channel=15, note=65, velocity=46, time=337),
Message('note_off', channel=15, note=62, velocity=47, time=266),
Message('note_off', channel=15, note=57, velocity=42, time=119),
Message('note_on', channel=15, note=62, velocity=56, time=657),
Message('note_on', channel=15, note=57, velocity=53, time=9),
Message('note_on', channel=15, note=65, velocity=58, time=8),
Message('note_off', channel=15, note=65, velocity=58, time=1651),
Message('note_off', channel=15, note=62, velocity=56, time=24),
Message('note_off', channel=15, note=57, velocity=53, time=24),
Message('note_on', channel=15, note=62, velocity=49, time=173),
Message('note_on', channel=15, note=57, velocity=42, time=9),
Message('note_on', channel=15, note=65, velocity=49, time=8),
Message('note_off', channel=15, note=65, velocity=49, time=266),
Message('note_off', channel=15, note=62, velocity=49, time=24),
Message('note_off', channel=15, note=57, velocity=42, time=24),
Message('note_on', channel=15, note=62, velocity=37, time=212),
Message('note_on', channel=15, note=57, velocity=34, time=9),
Message('note_on', channel=15, note=65, velocity=51, time=8),
Message('note_off', channel=15, note=65, velocity=51, time=314),
Message('note_off', channel=15, note=62, velocity=37, time=8),
Message('note_off', channel=15, note=57, velocity=34, time=79),
Message('note_on', channel=15, note=57, velocity=58, time=1018),
Message('note_on', channel=15, note=62, velocity=60, time=8),
Message('note_on', channel=15, note=65, velocity=56, time=8),
Message('note_off', channel=15, note=65, velocity=56, time=1746),
Message('note_off', channel=15, note=62, velocity=60, time=8),
Message('note_off', channel=15, note=57, velocity=58, time=71),
Message('note_on', channel=15, note=62, velocity=50, time=447),
Message('note_on', channel=15, note=57, velocity=40, time=8),
Message('note_on', channel=15, note=65, velocity=52, time=8),
Message('note_off', channel=15, note=62, velocity=50, time=431),
Message('note_off', channel=15, note=65, velocity=52, time=9),
Message('note_off', channel=15, note=57, velocity=40, time=70),
Message('note_on', channel=15, note=62, velocity=63, time=917),
Message('note_on', channel=15, note=59, velocity=69, time=8),
Message('note_on', channel=15, note=67, velocity=58, time=8),
Message('note_off', channel=15, note=62, velocity=63, time=252),
Message('note_off', channel=15, note=67, velocity=58, time=8),
Message('note_off', channel=15, note=59, velocity=69, time=23),
Message('note_on', channel=15, note=59, velocity=58, time=268),
Message('note_on', channel=15, note=62, velocity=58, time=8),
Message('note_on', channel=15, note=67, velocity=58, time=8),
Message('note_off', channel=15, note=62, velocity=58, time=587),
Message('note_off', channel=15, note=67, velocity=58, time=9),
Message('note_off', channel=15, note=59, velocity=58, time=63),
Message('note_on', channel=15, note=59, velocity=52, time=87),
Message('note_on', channel=15, note=67, velocity=60, time=8),
Message('note_on', channel=15, note=62, velocity=65, time=8),
Message('note_off', channel=15, note=62, velocity=65, time=251),
Message('note_off', channel=15, note=67, velocity=60, time=32),
Message('note_off', channel=15, note=59, velocity=52, time=48),
Message('note_on', channel=15, note=59, velocity=57, time=337),
Message('note_on', channel=15, note=62, velocity=60, time=9),
Message('note_on', channel=15, note=67, velocity=57, time=8),
Message('note_off', channel=15, note=62, velocity=60, time=173),
Message('note_off', channel=15, note=59, velocity=57, time=31),
Message('note_off', channel=15, note=67, velocity=57, time=9),
Message('note_on', channel=15, note=62, velocity=82, time=266),
Message('note_off', channel=15, note=62, velocity=82, time=5),
MetaMessage('end_of_track', time=1)])
])
This object is a list object, containing besides some meta
information multiple MidiTrack()
s which are themselves also
lists containing the midi event messages.
Transform to unnested dataframe
We can transform the midi data to a data.frame similar to the one
returned by unnest_midi()
from the miditapyr package. We’ll only use the data of the first track
of the midi file:
# access first track:
track1 <- midi_file$tracks[[1]]
# transform MidiTrack() object to an R list of mido Message()s and MetaMessage()s:
track1list <- pb$list(track1)
track1list
Show details of list in R
[[1]]
MetaMessage('track_name', name='drum-t1-1-t1', time=0)
[[2]]
Message('note_on', channel=9, note=43, velocity=72, time=0)
[[3]]
Message('note_on', channel=9, note=39, velocity=64, time=0)
[[4]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[5]]
MetaMessage('set_tempo', tempo=666666, time=0)
[[6]]
MetaMessage('time_signature', numerator=4, denominator=4, clocks_per_click=24, notated_32nd_notes_per_beat=8, time=0)
[[7]]
Message('note_off', channel=9, note=43, velocity=72, time=240)
[[8]]
Message('note_off', channel=9, note=39, velocity=64, time=0)
[[9]]
Message('note_off', channel=9, note=36, velocity=101, time=0)
[[10]]
Message('note_on', channel=9, note=42, velocity=101, time=240)
[[11]]
Message('note_on', channel=9, note=38, velocity=101, time=0)
[[12]]
Message('note_on', channel=9, note=43, velocity=64, time=240)
[[13]]
Message('note_off', channel=9, note=42, velocity=101, time=0)
[[14]]
Message('note_off', channel=9, note=38, velocity=101, time=0)
[[15]]
Message('note_off', channel=9, note=43, velocity=64, time=240)
[[16]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[17]]
Message('note_off', channel=9, note=36, velocity=101, time=240)
[[18]]
Message('note_on', channel=9, note=43, velocity=60, time=240)
[[19]]
Message('note_on', channel=9, note=42, velocity=101, time=0)
[[20]]
Message('note_off', channel=9, note=43, velocity=60, time=240)
[[21]]
Message('note_off', channel=9, note=42, velocity=101, time=0)
[[22]]
Message('note_on', channel=9, note=43, velocity=60, time=240)
[[23]]
Message('note_on', channel=9, note=39, velocity=66, time=0)
[[24]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[25]]
Message('note_off', channel=9, note=43, velocity=60, time=240)
[[26]]
Message('note_off', channel=9, note=39, velocity=66, time=0)
[[27]]
Message('note_off', channel=9, note=36, velocity=101, time=0)
[[28]]
Message('note_on', channel=9, note=42, velocity=101, time=240)
[[29]]
Message('note_on', channel=9, note=38, velocity=101, time=0)
[[30]]
Message('note_on', channel=9, note=43, velocity=53, time=240)
[[31]]
Message('note_off', channel=9, note=42, velocity=101, time=0)
[[32]]
Message('note_off', channel=9, note=38, velocity=101, time=0)
[[33]]
Message('note_off', channel=9, note=43, velocity=53, time=240)
[[34]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[35]]
Message('note_off', channel=9, note=36, velocity=101, time=240)
[[36]]
Message('note_on', channel=9, note=43, velocity=52, time=240)
[[37]]
Message('note_on', channel=9, note=42, velocity=66, time=0)
[[38]]
Message('note_off', channel=9, note=43, velocity=52, time=240)
[[39]]
Message('note_off', channel=9, note=42, velocity=66, time=0)
[[40]]
Message('note_on', channel=9, note=43, velocity=72, time=240)
[[41]]
Message('note_on', channel=9, note=39, velocity=64, time=0)
[[42]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[43]]
Message('note_off', channel=9, note=43, velocity=72, time=240)
[[44]]
Message('note_off', channel=9, note=39, velocity=64, time=0)
[[45]]
Message('note_off', channel=9, note=36, velocity=101, time=0)
[[46]]
Message('note_on', channel=9, note=42, velocity=101, time=240)
[[47]]
Message('note_on', channel=9, note=38, velocity=101, time=0)
[[48]]
Message('note_on', channel=9, note=43, velocity=64, time=240)
[[49]]
Message('note_off', channel=9, note=42, velocity=101, time=0)
[[50]]
Message('note_off', channel=9, note=38, velocity=101, time=0)
[[51]]
Message('note_off', channel=9, note=43, velocity=64, time=240)
[[52]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[53]]
Message('note_off', channel=9, note=36, velocity=101, time=240)
[[54]]
Message('note_on', channel=9, note=43, velocity=60, time=240)
[[55]]
Message('note_on', channel=9, note=42, velocity=101, time=0)
[[56]]
Message('note_off', channel=9, note=43, velocity=60, time=240)
[[57]]
Message('note_off', channel=9, note=42, velocity=101, time=0)
[[58]]
Message('note_on', channel=9, note=43, velocity=60, time=240)
[[59]]
Message('note_on', channel=9, note=39, velocity=66, time=0)
[[60]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[61]]
Message('note_off', channel=9, note=43, velocity=60, time=240)
[[62]]
Message('note_off', channel=9, note=39, velocity=66, time=0)
[[63]]
Message('note_off', channel=9, note=36, velocity=101, time=0)
[[64]]
Message('note_on', channel=9, note=42, velocity=101, time=240)
[[65]]
Message('note_on', channel=9, note=38, velocity=101, time=0)
[[66]]
Message('note_on', channel=9, note=43, velocity=53, time=240)
[[67]]
Message('note_off', channel=9, note=42, velocity=101, time=0)
[[68]]
Message('note_off', channel=9, note=38, velocity=101, time=0)
[[69]]
Message('note_off', channel=9, note=43, velocity=53, time=240)
[[70]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[71]]
Message('note_off', channel=9, note=36, velocity=101, time=240)
[[72]]
Message('note_on', channel=9, note=43, velocity=52, time=240)
[[73]]
Message('note_on', channel=9, note=42, velocity=66, time=0)
[[74]]
Message('note_off', channel=9, note=43, velocity=52, time=240)
[[75]]
Message('note_off', channel=9, note=42, velocity=66, time=0)
[[76]]
Message('note_on', channel=9, note=43, velocity=72, time=240)
[[77]]
Message('note_on', channel=9, note=39, velocity=64, time=0)
[[78]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[79]]
Message('note_off', channel=9, note=43, velocity=72, time=240)
[[80]]
Message('note_off', channel=9, note=39, velocity=64, time=0)
[[81]]
Message('note_off', channel=9, note=36, velocity=101, time=0)
[[82]]
Message('note_on', channel=9, note=42, velocity=101, time=240)
[[83]]
Message('note_on', channel=9, note=38, velocity=101, time=0)
[[84]]
Message('note_on', channel=9, note=43, velocity=64, time=240)
[[85]]
Message('note_off', channel=9, note=42, velocity=101, time=0)
[[86]]
Message('note_off', channel=9, note=38, velocity=101, time=0)
[[87]]
Message('note_off', channel=9, note=43, velocity=64, time=240)
[[88]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[89]]
Message('note_off', channel=9, note=36, velocity=101, time=240)
[[90]]
Message('note_on', channel=9, note=43, velocity=60, time=240)
[[91]]
Message('note_on', channel=9, note=42, velocity=101, time=0)
[[92]]
Message('note_off', channel=9, note=43, velocity=60, time=240)
[[93]]
Message('note_off', channel=9, note=42, velocity=101, time=0)
[[94]]
Message('note_on', channel=9, note=43, velocity=60, time=240)
[[95]]
Message('note_on', channel=9, note=39, velocity=66, time=0)
[[96]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[97]]
Message('note_off', channel=9, note=43, velocity=60, time=240)
[[98]]
Message('note_off', channel=9, note=39, velocity=66, time=0)
[[99]]
Message('note_off', channel=9, note=36, velocity=101, time=0)
[[100]]
Message('note_on', channel=9, note=42, velocity=101, time=240)
[[101]]
Message('note_on', channel=9, note=38, velocity=101, time=0)
[[102]]
Message('note_on', channel=9, note=43, velocity=53, time=240)
[[103]]
Message('note_off', channel=9, note=42, velocity=101, time=0)
[[104]]
Message('note_off', channel=9, note=38, velocity=101, time=0)
[[105]]
Message('note_off', channel=9, note=43, velocity=53, time=240)
[[106]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[107]]
Message('note_off', channel=9, note=36, velocity=101, time=240)
[[108]]
Message('note_on', channel=9, note=43, velocity=52, time=240)
[[109]]
Message('note_on', channel=9, note=42, velocity=66, time=0)
[[110]]
Message('note_off', channel=9, note=43, velocity=52, time=240)
[[111]]
Message('note_off', channel=9, note=42, velocity=66, time=0)
[[112]]
Message('note_on', channel=9, note=43, velocity=81, time=240)
[[113]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[114]]
Message('note_off', channel=9, note=43, velocity=81, time=240)
[[115]]
Message('note_off', channel=9, note=36, velocity=101, time=0)
[[116]]
Message('note_on', channel=9, note=42, velocity=101, time=240)
[[117]]
Message('note_on', channel=9, note=39, velocity=57, time=0)
[[118]]
Message('note_on', channel=9, note=38, velocity=101, time=0)
[[119]]
Message('note_on', channel=9, note=43, velocity=60, time=240)
[[120]]
Message('note_off', channel=9, note=42, velocity=101, time=0)
[[121]]
Message('note_off', channel=9, note=39, velocity=57, time=0)
[[122]]
Message('note_off', channel=9, note=38, velocity=101, time=0)
[[123]]
Message('note_off', channel=9, note=43, velocity=60, time=240)
[[124]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[125]]
Message('note_off', channel=9, note=36, velocity=101, time=240)
[[126]]
Message('note_on', channel=9, note=43, velocity=66, time=240)
[[127]]
Message('note_on', channel=9, note=42, velocity=101, time=0)
[[128]]
Message('note_off', channel=9, note=43, velocity=66, time=240)
[[129]]
Message('note_off', channel=9, note=42, velocity=101, time=0)
[[130]]
Message('note_on', channel=9, note=43, velocity=66, time=240)
[[131]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[132]]
Message('note_off', channel=9, note=43, velocity=66, time=240)
[[133]]
Message('note_off', channel=9, note=36, velocity=101, time=0)
[[134]]
Message('note_on', channel=9, note=46, velocity=81, time=240)
[[135]]
Message('note_on', channel=9, note=45, velocity=67, time=0)
[[136]]
Message('note_on', channel=9, note=39, velocity=60, time=0)
[[137]]
Message('note_on', channel=9, note=38, velocity=101, time=0)
[[138]]
Message('note_off', channel=9, note=46, velocity=81, time=240)
[[139]]
Message('note_off', channel=9, note=45, velocity=67, time=0)
[[140]]
Message('note_off', channel=9, note=39, velocity=60, time=0)
[[141]]
Message('note_off', channel=9, note=38, velocity=101, time=0)
[[142]]
Message('note_on', channel=9, note=39, velocity=59, time=240)
[[143]]
Message('note_on', channel=9, note=36, velocity=101, time=0)
[[144]]
Message('note_off', channel=9, note=39, velocity=59, time=240)
[[145]]
Message('note_on', channel=9, note=39, velocity=55, time=0)
[[146]]
Message('note_off', channel=9, note=36, velocity=101, time=0)
[[147]]
Message('note_on', channel=9, note=45, velocity=63, time=240)
[[148]]
Message('note_on', channel=9, note=43, velocity=52, time=0)
[[149]]
Message('note_on', channel=9, note=42, velocity=101, time=0)
[[150]]
Message('note_off', channel=9, note=39, velocity=55, time=0)
[[151]]
Message('note_on', channel=9, note=39, velocity=55, time=0)
[[152]]
Message('note_off', channel=9, note=45, velocity=63, time=240)
[[153]]
Message('note_off', channel=9, note=43, velocity=52, time=0)
[[154]]
Message('note_off', channel=9, note=42, velocity=101, time=0)
[[155]]
Message('note_on', channel=9, note=42, velocity=59, time=0)
[[156]]
Message('note_off', channel=9, note=39, velocity=55, time=0)
[[157]]
Message('note_on', channel=9, note=39, velocity=57, time=0)
[[158]]
Message('note_off', channel=9, note=42, velocity=59, time=240)
[[159]]
Message('note_off', channel=9, note=39, velocity=57, time=0)
[[160]]
MetaMessage('end_of_track', time=1)
The list contains mido Message()
&
MetaMessage()
objects (Message()
s seem to have
a special print method).
With the function pb$vars()
we can extract all variables
for every event into a list of named R lists:
track1Rlist[1:10]
Show details of first 10 elements of track events list in R
[[1]]
[[1]]$type
[1] "track_name"
[[1]]$name
[1] "drum-t1-1-t1"
[[1]]$time
[1] 0
[[2]]
[[2]]$type
[1] "note_on"
[[2]]$time
[1] 0
[[2]]$note
[1] 43
[[2]]$velocity
[1] 72
[[2]]$channel
[1] 9
[[3]]
[[3]]$type
[1] "note_on"
[[3]]$time
[1] 0
[[3]]$note
[1] 39
[[3]]$velocity
[1] 64
[[3]]$channel
[1] 9
[[4]]
[[4]]$type
[1] "note_on"
[[4]]$time
[1] 0
[[4]]$note
[1] 36
[[4]]$velocity
[1] 101
[[4]]$channel
[1] 9
[[5]]
[[5]]$type
[1] "set_tempo"
[[5]]$tempo
[1] 666666
[[5]]$time
[1] 0
[[6]]
[[6]]$type
[1] "time_signature"
[[6]]$numerator
[1] 4
[[6]]$denominator
[1] 4
[[6]]$clocks_per_click
[1] 24
[[6]]$notated_32nd_notes_per_beat
[1] 8
[[6]]$time
[1] 0
[[7]]
[[7]]$type
[1] "note_off"
[[7]]$time
[1] 240
[[7]]$note
[1] 43
[[7]]$velocity
[1] 72
[[7]]$channel
[1] 9
[[8]]
[[8]]$type
[1] "note_off"
[[8]]$time
[1] 0
[[8]]$note
[1] 39
[[8]]$velocity
[1] 64
[[8]]$channel
[1] 9
[[9]]
[[9]]$type
[1] "note_off"
[[9]]$time
[1] 0
[[9]]$note
[1] 36
[[9]]$velocity
[1] 101
[[9]]$channel
[1] 9
[[10]]
[[10]]$type
[1] "note_on"
[[10]]$time
[1] 240
[[10]]$note
[1] 42
[[10]]$velocity
[1] 101
[[10]]$channel
[1] 9
We can put this list of message lists in a dataframe and write the values of each key in their own column:
track1Rlist %>%
tibble(temp = .) %>%
unnest_wider(temp)
#> # A tibble: 160 × 11
#> type name time note velocity channel tempo numerator denominator
#> <chr> <chr> <int> <int> <int> <int> <int> <int> <int>
#> 1 track_name drum… 0 NA NA NA NA NA NA
#> 2 note_on NA 0 43 72 9 NA NA NA
#> 3 note_on NA 0 39 64 9 NA NA NA
#> 4 note_on NA 0 36 101 9 NA NA NA
#> 5 set_tempo NA 0 NA NA NA 666666 NA NA
#> 6 time_signatu… NA 0 NA NA NA NA 4 4
#> 7 note_off NA 240 43 72 9 NA NA NA
#> 8 note_off NA 0 39 64 9 NA NA NA
#> 9 note_off NA 0 36 101 9 NA NA NA
#> 10 note_on NA 240 42 101 9 NA NA NA
#> # ℹ 150 more rows
#> # ℹ 2 more variables: clocks_per_click <int>, notated_32nd_notes_per_beat <int>
Compare with pyramidi
For comparison, we plot the results of unnest_midi()
mfr <- MidiFramer$new(midi_file_string)
mt$unnest_midi(dfc = mfr$mf$midi_frame_raw) %>%
as_tibble()
#> # A tibble: 268 × 13
#> i_track meta type name time note velocity channel tempo numerator
#> <dbl> <lgl> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0 TRUE track_name drum… 0 NaN NaN NaN NaN NaN
#> 2 0 FALSE note_on NA 0 43 72 9 NaN NaN
#> 3 0 FALSE note_on NA 0 39 64 9 NaN NaN
#> 4 0 FALSE note_on NA 0 36 101 9 NaN NaN
#> 5 0 TRUE set_tempo NA 0 NaN NaN NaN 666666 NaN
#> 6 0 TRUE time_signa… NA 0 NaN NaN NaN NaN 4
#> 7 0 FALSE note_off NA 240 43 72 9 NaN NaN
#> 8 0 FALSE note_off NA 0 39 64 9 NaN NaN
#> 9 0 FALSE note_off NA 0 36 101 9 NaN NaN
#> 10 0 FALSE note_on NA 240 42 101 9 NaN NaN
#> # ℹ 258 more rows
#> # ℹ 3 more variables: denominator <dbl>, clocks_per_click <dbl>,
#> # notated_32nd_notes_per_beat <dbl>
There are some differences in the types and track1Rlist
only contains the data of track 1, but you can see that apart from that,
the output is the same.