The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MIDI::Ngram - Find the top repeated note phrases of a MIDI file

VERSION

version 0.02

SYNOPSIS

  use MIDI::Ngram;
  my $mng = MIDI::Ngram->new(
    file      => 'eg/twinkle_twinkle.mid',
    size      => 3,
    patches   => [qw( 68 69 70 71 72 73 )],
    randpatch => 1,
    verbose   => 1,
  );
  $mng->process;
  $mng->populate;
  $mng->write;

DESCRIPTION

MIDI::Ngram parses a given MIDI file and finds the top repeated note phrases.

ATTRIBUTES

file

Required. The MIDI file to process.

size

Ngram phrase size. Default: 2

max

The maximum number of phrases to play. Default: 10

bpm

Beats per minute. Default: 100

durations

The note durations to choose from (at random). Default: [qn tqn]

patches

The patches to choose from (at random) if given the randpatch option. Otherwise 0 (piano) is used. Default: [0 .. 127]

out_file

MIDI output file. Default: midi-ngram.mid

pause

Insert a rest of the given duration after each phrase. Default: '' (no resting)

loop

The number of times to choose a weighted phrase. * Only works with the weight option. Default: 4

weight

Boolean. Play phrases by their ngram repetition occurrence. Default: 0

randpatch

Boolean. Choose a random patch from patches for each channel. Default: 0 (piano)

shuffle_phrases

Boolean. Shuffle the non-weighted phrases before playing them. Default: 0

single

Boolean. Allow single occurrence ngrams. Default: 0

verbose

Boolean. Output progress print statements.

opus

The MIDI opus object. Constructed at runtime. Constructor argument if given will be ignored.

score

The MIDI score object. Constructed at runtime. Constructor argument if given will be ignored.

notes

The bucket of ngrams. Constructed at runtime. Constructor argument if given will be ignored.

METHODS

new()

  $mng = MIDI::Ngram->new(%arguments);

Create a new MIDI::Ngram object.

process()

  $mng->process;

Find all ngram phrases.

populate()

  $mng->populate;

Add notes to the MIDI score.

write()

  $mng->write;

Write out the MIDI file.

TO DO

Preserve note durations instead of random assignment.

SEE ALSO

Moo

Lingua::EN::Ngram

List::Util

List::Util::WeightedChoice

Music::Note

MIDI::Simple

Music::Tempo

AUTHOR

Gene Boggs <gene@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2018 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.