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

NAME

Music::Duration - Add 32nd, 64th, fractional and tuple durations to MIDI-Perl

VERSION

version 0.0505

SYNOPSIS

  # Compare:
  # perl -MMIDI::Simple -MData::Dumper -e'$Data::Dumper::Sortkeys=1; print Dumper \%MIDI::Simple::Length'
  # perl -MMusic::Duration -MData::Dumper -e'$Data::Dumper::Sortkeys=1; print Dumper \%MIDI::Simple::Length'

  # In a program:
  use MIDI::Simple;
  use Music::Duration;

  # Create and set up a new_score...

  Music::Duration::fractional('z', 5);
  n('zsn', 'n38') for 1 .. 4; # 4 sixteenth snares in bars of 5 notes

  Music::Duration::tuple( 'qn', 'z', 5 );
  n('zqn', 'n38') for 1 .. 5; # 5 snares in place of a standard quarter note

DESCRIPTION

This module adds thirty-second and sixty-fourth note divisions to MIDI::Simple. These are 32nd: yn, dyn, ddyn, tyn and 64th: xn, dxn, ddxn, txn.

Also, this module allows the addition of non-standard note divisions with the fractional() and tuple() functions, detailed below.

FUNCTIONS

fractional()

  Music::Duration::fractional( 'z', 5 )
  # Then: $score->n( 'zqn', ... );

Add a fractional division to the MIDI::Simple Length hash.

For the given example of z5, this function adds the following durations:

  zwn = 5
  zhn = 2.5
  zqn = 1.25
  zen = 0.625
  zsn = 0.3125
  zyn = 0.15625
  zxn = 0.078125

This means that a whole note is 5 beats long, and the duration for each subsequent division is "half as long as the last."

tuple()

  Music::Duration::tuple( 'wn', 'z', 5 );
  # Then: $score->n( 'zwn', ... );

Add a fractional division for a given duration of the MIDI::Simple Length hash.

Musically, this creates a "cluster" of notes in place of the given duration.

So instead of a whole note of four beats, we instead play 5 beats. A triplet is a 3-tuple.

TO DO

Add dot, double-dot and triplet to the fractional durations.

SEE ALSO

The "Parameters for n/r/noop" section in MIDI::Simple

The code in the t/ directory

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.