NAME

Music::MelodicDevice::Transposition - Apply chromatic and diatonic transposition to notes

VERSION

version 0.0601

SYNOPSIS

  use Music::MelodicDevice::Transposition;

  my @notes = qw(C4 E4 D4 G4 C5); # either named notes or midinums

  # Chromatic
  my $md = Music::MelodicDevice::Transposition->new(
    notes => \@notes,
  );
  my $transposed = $md->transpose(2); # [D4, F#4, E4, A4, D5]
  $transposed = $md->transpose(4);    # [E4, G#4, F#4, B4, E5]
  $transposed = $md->transpose(4, \@notes); # same thing

  # Diatonic
  $md = Music::MelodicDevice::Transposition->new(scale_name => 'major');
  $md->notes(\@notes);
  $transposed = $md->transpose(2); # [E4, G4, F4, B4, E5]
  $transposed = $md->transpose(4); # [G4, B4, A4, D5, G5]
  $md->notes([qw(C4 E4 G4)]);
  $transposed = $md->transpose(4); # [G4, B4, D5]

DESCRIPTION

Music::MelodicDevice::Transposition applies transposition, both chromatic or diatonic, to a series of ISO or "midinum" formatted notes.

While there are modules on CPAN that do chromatic transposition, none appear to apply diatonic transposition to an arbitrary series of notes. Hence this module.

ATTRIBUTES

scale_note

Default: C

scale_name

Default: chromatic

For the chromatic scale, enharmonic notes are listed as sharps. For a scale with flats, a diatonic scale_name must be used with a flat scale_note.

Please see "SCALES" in Music::Scales for a list of valid scale names.

notes

  $md->notes(\@notes);

The list of notes to use in transposition operations.

This can be overriden with a notes argument given to the transposition method.

Default: [] (no notes)

verbose

Default: 0

METHODS

new

  $md = Music::MelodicDevice::Transposition->new(
    scale_note => $scale_note,
    scale_name => $scale_name,
    notes      => \@notes,
    verbose    => $verbose,
  );

Create a new Music::MelodicDevice::Transposition object.

transpose

  $transposed = $md->transpose($offset);
  $transposed = $md->transpose($offset, \@notes);

Return the transposed list of notes given an offset appropriately based on the number of notes in the chosen scale.

SEE ALSO

The t/01-methods.t test and the eg/* example files

Data::Dumper::Compact

List::SomeUtils

Moo

Music::Scales

AUTHOR

Gene Boggs <gene@cpan.org>

COPYRIGHT AND LICENSE

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