NAME

Music::Dice - Define and roll musical dice

VERSION

version 0.0105

SYNOPSIS

use Music::Dice ();
my $d = Music::Dice->new;
# basics
my $roll = $d->note->roll;
$roll = $d->interval->roll;
$roll = $d->note_chromatic->roll;
$roll = $d->interval_chromatic->roll;
$roll = $d->note_major->roll;
$roll = $d->interval_major->roll;
$roll = $d->note_minor->roll;
$roll = $d->interval_minor->roll;
$roll = $d->chord_triad->roll;
$roll = $d->chord_quality_major->roll;
$roll = $d->chord_quality_major_7->roll;
$roll = $d->chord_quality_minor->roll;
$roll = $d->chord_quality_minor_7->roll;
$roll = $d->chord_quality_diminished->roll;
$roll = $d->chord_quality_augmented->roll;
$roll = $d->chord_quality_augmented_7->roll;
$roll = $d->chord_quality_triad_roll('C', 'major');
$roll = $d->mode->roll;
$roll = $d->ionian->roll;
$roll = $d->dorian->roll;
$roll = $d->phrygian->roll;
$roll = $d->lydian->roll;
$roll = $d->mixolydian->roll;
$roll = $d->aeolian->roll;
$roll = $d->locrian->roll;
$roll = $d->tonnetz->roll;
$roll = $d->tonnetz_7->roll;
$roll = $d->rhythm->roll;
$roll = $d->rhythmic_phrase->roll;
$roll = $d->rhythmic_phrase_constrained->roll;

# for example:
my $phrase = $d->rhythmic_phrase->roll;
my @notes  = map { $d->note->roll } 1 .. @$phrase;
my @triads = map { $d->chord_triad->roll } 1 .. @$phrase;
my @named  = map { "$notes[$_] $triads[$_] | $phrase->[$_]" } 0 .. $#$phrase;
print join("\n", @named), "\n";

DESCRIPTION

Music::Dice defines and rolls musical dice.

ATTRIBUTES

scale_note

$note = $d->scale_note;

The (uppercase) tonic of the scale.

Default: C

scale_name

$note = $d->scale_name;

The (lowercase) name of the scale.

Default: chromatic

flats

$flats = $d->flats;

Use either flats or sharps in the returned notes.

Default: 1 (use flats not sharps)

beats

$beats = $d->beats;

The number of quarter-note beats in a rhythmic phrase.

Default: 4 (standard measure)

pool

$pool = $d->pool;

The pool of durations in a rhythmic phrase.

Default: [wn dhn hn dqn qn den en]

The keyword all may also be given, which will use the keys of the MIDI::Simple::Length hash (all the known MIDI-Perl durations).

octaves

$octaves = $d->octaves;

The octaves to choose from.

Default: [2 3 4 5 6]

notes

$notes = $d->notes;

The user-definable named pitches from which to choose.

This list is computed, if the scale_note and scale_name are given, and the notes are not given in the object constructor.

Default: [C Db D Eb E F Gb G Ab A Bb B] (the chromatic scale)

Any scale may be given in the constructor. For accidentals, either sharps (#) or flats (b) may be provided.

Additionally, midi pitch numbers may be used.

intervals

$intervals = $d->intervals;

Return the note intervals.

This list is computed, if the scale_name is given, and the intervals are not given in the object constructor.

Default: 12 1s (for the chromatic scale)

chord_triads

$chord_triads = $d->chord_triads;

The named chord triads, from which to choose. Rolling custom means that three individual notes, or two intervals must be chosen.

Default:

major
minor
diminished
augmented
custom

chord_triad_weights

$chord_triad_weights = $d->chord_triad_weights;

The chord triad weights.

Default: [2 2 1 1 1] (major and minor are twice as likely)

chord_qualities_major

$chord_qualities_major = $d->chord_qualities_major;

The named chord qualities that specify a single note addition or transformation to major chords.

Please see Music::Chord::Note for the known chords.

Default:

add2 sus2
add4 sus4
-5
-6 6
M7 7
add9

chord_qualities_major_7

$chord_qualities_major_7 = $d->chord_qualities_major_7;

The named chord qualities that specify additions or transformations to 7th chords.

Please see Music::Chord::Note for the known chords.

Default:

7sus4 7b5 7#5
69
M79
7b9 9 7#9
7(b9,13) 7(9,13)
9b5
M11 11 7#11
M13 13 7#13

chord_qualities_minor

$chord_qualities_minor = $d->chord_qualities_minor;

The named chord qualities that specify a single note addition or transformation to minor chords.

Please see Music::Chord::Note for the known chords.

Default:

madd4
m6
mM7 m7

chord_qualities_minor_7

$chord_qualities_minor_7 = $d->chord_qualities_minor_7;

The named chord qualities that specify additions or transformations to minor 7th chords.

Please see Music::Chord::Note for the known chords.

Default:

m7b5 m7#5
m9
m7(9,11)
m11
m13

chord_qualities_diminished

$chord_qualities_diminished = $d->chord_qualities_diminished;

The named chord qualities that specify a single note addition or transformation to diminished chords.

Please see Music::Chord::Note for the known chords.

Default:

dim6
dim7

chord_qualities_augmented

$chord_qualities_augmented = $d->chord_qualities_augmented;

The named chord qualities that specify a single note addition or transformation to augmented chords.

Please see Music::Chord::Note for the known chords.

Default:

augM7 aug7

chord_qualities_augmented_7

$chord_qualities_augmented_7 = $d->chord_qualities_augmented_7;

The named chord qualities that specify additions or transformations to augmented 7th chords.

Please see Music::Chord::Note for the known chords.

Default:

aug9

modes

$modes = $d->modes;

The named modes, from which to choose.

Default:

ionian
dorian
phrygian
lydian
mixolydian
aeolian
locrian

ionian_mask

$ionian_mask = $d->ionian_mask;

The mask of Ionian mode triad types.

Default: [I ii iii IV V vi viio]

dorian_mask

$dorian_mask = $d->dorian_mask;

The mask of Dorian mode triad types.

Default: [i ii III IV v vio VII]

phrygian_mask

$phrygian_mask = $d->phrygian_mask;

The mask of Phrygian mode triad types.

Default: [i II III iv vo VI vii]

lydian_mask

$lydian_mask = $d->lydian_mask;

The mask of Lydian mode triad types.

Default: [I II iii ivo V vi vii]

mixolydian_mask

$mixolydian_mask = $d->mixolydian_mask;

The mask of Mixolydian mode triad types.

Default: [I ii iiio IV v vi VII]

aeolian_mask

$aeolian_mask = $d->aeolian_mask;

The mask of Aeolian mode triad types.

Default: [i iio III iv v VI VII]

locrian_mask

$locrian_mask = $d->locrian_mask;

The mask of Locrian mode triad types.

Default: [io II iii iv V VI vii]

tonnetzen

$tonnetzen = $d->tonnetzen;

The named tonnetz values for triad transformations.

Default:

P  # Parallel
R  # Relative
L  # Leittonwechsel
N  # Nebenverwandt (RLP)
S  # Slide (LPR)
H  # "hexatonic pole exchange" (LPL)

tonnetzen_7

$tonnetzen_7 = $d->tonnetzen_7;

The named tonnetz values for 7th chord transformations.

Default:

S23
S32
S34
S43
S56
S65
C32
C34
C65

rhythmic_phrase_constraints

$rhythmic_phrase_constraints = $d->rhythmic_phrase_constraints;

The number of rhythmic values in a phrase, given as an array reference.

Default: [3,4,5]

mdp

$mdp = $d->mdp;

The Music::Duration::Partition object.

METHODS

new

$d = Music::Dice->new;
$d = Music::Dice->new( # override defaults
  scale_note                  => $note,
  scale_name                  => $name,
  flats                       => $bool,
  beats                       => $beats,
  pool                        => \@pool, # or 'all'
  notes                       => \@notes,
  intervals                   => \@intervals,
  chord_triads                => \@triads,
  chord_triad_weights         => \@triad_weights,
  chord_qualities_major       => \@chord_qualities_major,
  chord_qualities_major_7     => \@chord_qualities_major_7,
  chord_qualities_minor       => \@chord_qualities_minor,
  chord_qualities_minor_7     => \@chord_qualities_minor_7,
  chord_qualities_diminished  => \@chord_qualities_diminished,
  chord_qualities_augmented   => \@chord_qualities_augmented,
  chord_qualities_augmented_7 => \@chord_qualities_augmented_7,
  modes                       => \@modes,
  tonnetzen                   => \@tonnetzen,
  tonnetzen_7                 => \@tonnetzen_7,
  rhythmic_phrase_constraints => \@constraints,
);

Create a new Music::Dice object.

octave

$result = $d->octave->roll;

Return an octave number.

note

$result = $d->note->roll;

Return one of the notes, with equal probability.

interval

$result = $d->interval->roll;

Return one of the note intervals, with equal probability.

note_chromatic

$result = $d->note_chromatic->roll;

Return one of the chromatic scale notes, based on the given scale_note, with equal probability.

interval_chromatic

$result = $d->interval_chromatic->roll;

Return one of the chromatic intervals (12 1s), with equal probability.

note_major

$result = $d->note_major->roll;

Return one of the major scale notes, based on the given scale_note, with equal probability.

interval_major

$result = $d->interval_major->roll;

Return one of the major intervals, with equal probability.

note_minor

$result = $d->note_minor->roll;

Return one of the natural minor scale notes, based on the given scale_note, with equal probability.

interval_minor

$result = $d->interval_minor->roll;

Return one of the minor intervals, with equal probability.

chord_triad

$result = $d->chord_triad->roll;

Return a chord triad. If custom is rolled, then three notes must be rolled for, separately.

chord_quality_major

$result = $d->chord_quality_major->roll;

Return a chord quality to modify a major chord triad.

chord_quality_major_7

$result = $d->chord_quality_major_7->roll;

Return a chord quality to modify a 7th chord.

chord_quality_minor

$result = $d->chord_quality_minor->roll;

Return a chord quality to modify a minor chord triad.

chord_quality_minor_7

$result = $d->chord_quality_minor_7->roll;

Return a chord quality to modify a minor 7th chord.

chord_quality_diminished

$result = $d->chord_quality_diminished->roll;

Return a chord quality to modify a diminished chord triad.

chord_quality_augmented

$result = $d->chord_quality_augmented->roll;

Return a chord quality to modify an augmented chord triad.

chord_quality_augmented_7

$result = $d->chord_quality_augmented_7->roll;

Return a chord quality to modify an augmented 7th chord.

chord_quality_triad_roll

$result = $d->chord_quality_triad_roll($note, $triad);

Return a chord quality, given a note and a known triad.

mode

$result = $d->mode->roll;

Return a mode.

ionian

$result = $d->ionian->roll;

Return a value from the Ionian mode mask of chord types.

dorian

$result = $d->dorian->roll;

Return a value from the Dorian mode mask of chord types.

phrygian

$result = $d->phrygian->roll;

Return a value from the Phrygian mode mask of chord types.

lydian

$result = $d->lydian->roll;

Return a value from the Lydian mode mask of chord types.

mixolydian

$result = $d->mixolydian->roll;

Return a value from the Mixolydian mode mask of chord types.

aeolian

$result = $d->aeolian->roll;

Return a value from the Aeolian mode mask of chord types.

locrian

$result = $d->locrian->roll;

Return a value from the Ionian mode mask of chord types.

mode_degree_triad_roll

($degree, $triad) = $d->mode_degree_triad_roll($mode);

Return a modal degree and triad type (major, minor, diminished), given a mode name.

tonnetz

$result = $d->tonnetz->roll;

Return one of the tonnetzen, with equal probability.

tonnetz_7

$result = $d->tonnetz_7->roll;

Return one of the tonnetzen_7, with equal probability.

rhythmic_value

$result = $d->rhythmic_value->roll;

Return a single rhythmic value.

rhythmic_phrase

$result = $d->rhythmic_phrase->roll;

Return a rhythmic phrase, given the number of beats.

rhythmic_phrase_constrained

$result = $d->rhythmic_phrase_constrained->roll;

Return a constrained rhythmic phrase, given the rhythmic_phrase_constraints (number of rhythmic values).

unique_item

$item = $mb->unique_item(\@excludes);
$item = $mb->unique_item(\@excludes, \@items);

Return an item from the items list, that is not in the excludes list. If an item list is not given in the arguments, the object notes are used.

SEE ALSO

The t/01-methods.t file

Games::Dice::Advanced

List::Util::WeightedChoice

MIDI::Util

Moo

Music::Duration::Partition

Music::Scales

Types::Standard

AUTHOR

Gene Boggs <gene.boggs@gmail.com>

COPYRIGHT AND LICENSE

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