MIDI::Ngram - Find the top repeated note phrases of MIDI files
version 0.1300
use MIDI::Ngram; # Analyze a tune and build a new MIDI file of repetitions my $mng = MIDI::Ngram->new( in_file => [ 'eg/twinkle_twinkle.mid' ], ngram_size => 3, patches => [qw( 68 69 70 71 72 73 )], random_patch => 1, bounds => 1, ); my $analysis = $mng->process; print $analysis; my $playback = $mng->populate; print $playback; $mng->write; # Analyze multitrack tunes $mng = MIDI::Ngram->new( in_file => [ '/multi/channel/tune1.mid', '/multi/channel/tune2.mid' ], ); $mng->process; # Dump out the channel 0 duration phrases in order print Dumper [ map { "$_ => " . $mng->dura->{0}{$_} } sort { $mng->dura->{0}{$a} <=> $mng->dura->{0}{$b} } keys %{ $mng->dura->{0} } ]; # Dump out the channel 0 note phrases in order print Dumper [ map { "$_ => " . $mng->notes->{0}{$_} } sort { $mng->notes->{0}{$a} <=> $mng->notes->{0}{$b} } keys %{ $mng->notes->{0} } ]; # Inspect the phrase transition networks print Dumper $mng->dura_net; print Dumper $mng->note_net;
MIDI::Ngram parses a given list of MIDI files, finds the top repeated note phrases, builds the analysis, transition network, and renders to a MIDI file if desired.
MIDI::Ngram
Required. An Array reference of MIDI files to process.
Ngram phrase size.
Default: 2
2
The maximum number of phrases to analyze/play.
Default: 10
10
Setting this to a value of 0 analyzes all phrases.
0
Beats per minute.
Default: 100
100
The optional MIDI note durations to choose from (at random).
Default: [] (i.e. use the computed dura phrases instead)
[]
Using a setting of ['qn'] allows you to evenly inspect the phrases during audio playback.
['qn']
The patches to choose from (at random) if given the random_patch option.
Default: [0 .. 127]
[0 .. 127]
Boolean. Choose a random patch from patches for each channel.
Default: 0 (meaning "use the piano patch")
MIDI output file.
Default: midi-ngram.mid
midi-ngram.mid
Insert a rest of the given duration after each phrase.
Default: '' (no resting)
''
Array reference of the channels to analyze. If not given, all channels are analyzed.
Default: undef
undef
The number of times to choose a weighted phrase. * This only works in conjunction with the weight option.
Boolean. Play phrases according to the probability of their repetition occurrence with the function "choose_weighted" in List::Util::WeightedChoice.
Default: 0
Boolean. Shuffle the non-weighted phrases before playing them.
Boolean. Allow single occurrence ngrams.
Boolean. Accumulate phrases onto a single channel.
Boolean. Include pitch range in the analysis.
The score object in "MAIN-ROUTINES" in MIDI::Simple. Constructed by the populate method.
The hash-reference bucket of pitch ngrams. Constructed by the process method.
The hash-reference bucket of duration ngrams. Constructed by the process method.
A hash-reference ngram transition network of the durations. Constructed by the process method.
A hash-reference ngram transition network of the notes. Constructed by the process method.
$mng = MIDI::Ngram->new(%arguments);
Create a new MIDI::Ngram object.
$analysis = $mng->process;
Find all ngram phrases and return the note analysis.
$playback = $mng->populate;
Add notes to the MIDI score and return the playback notes.
$mng->write;
Write out the MIDI file.
Moo
Lingua::EN::Ngram
List::Util
List::Util::WeightedChoice
Music::Note
MIDI::Simple
MIDI::Util
Music::Gestalt
Gene Boggs <gene@cpan.org>
This software is copyright (c) 2020 by Gene Boggs.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install MIDI::Ngram, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MIDI::Ngram
CPAN shell
perl -MCPAN -e shell install MIDI::Ngram
For more information on module installation, please visit the detailed CPAN module installation guide.