FoscDuration

Returns a FoscDuration.


Description

A musical duration.


Attributes Summary

Class Methods

durationsToNonreducedFractions Changes durations to nonreduced fractions sharing least common denominator.
fromLilypondDurationString
isToken

Instance Properties

dotCount Gets dot count.
equalOrGreaterAssignable Gets assignable duration equal to or just greater than this duration.
equalOrGreaterPowerOfTwo Gets duration equal or just greater power of two.
equalOrLesserAssignable Gets assignable duration equal or just less than this duration.
equalOrLesserPowerOfTwo Gets duration equal to or just less than power of two.
flagCount Gets flag count. Flag count defined equal to number of flags required to notate duration.
hasPowerOfTwoDenominator Is true when duration is an integer power of two. Otherwise false.
impliedProlation Gets implied prolation.
isAssignable Is true when duration is assignable. Otherwise false.
lilypondDurationString Gets LilyPond duration string. Raises assignability error when duration is not assignable.
str (inherited in abjad)
pair Gets numerator and denominator.
prolationString Gets prolation string.
reciprocal Gets reciprocal.

Instance Methods: Special Methods

abs Gets absolute value of duration.
asCompileString
+ Adds duration to expr.
asFloat
/ Divides duration by expr.
divmod Equals the pair (duration // args, duration % args).
== Is true when duration equals arg. Otherwise false.
format Formats duration.
>= Is true when duration is greater than or equal to arg. Otherwise false.
> Is true when duration is greater than arg. Otherwise false.
<= Is true when duration is less than or equal to arg. Otherwise false.
< Is true when duration is less than arg. Otherwise false.
mod Modulus operator applied to duration.
* Duration multiplied by expr.
!= Is true when duration does not equal arg. Otherwise false.
neg Negates duration.
** Raises duration to expr power.
reduce
- Subtracts expr from duration.
truediv Documentation required.

Instance Methods

toClockString
toScoreMarkup
withDenominator Changes duration to nonreduced fraction with denominator.


Usage

  1. FoscDuration

    FoscDuration(1, 4).str;
    1/4
    FoscDuration(0.25).str;
    1/4
    FoscDuration(pi).str;
    355/113
    FoscDuration(inf).str;
    inf
    FoscDuration(4, 4).str;
    1/1
    FoscDuration(3, 8).str;
    3/8
    FoscDuration(7, 16).str;
    7/16
    FoscDuration(17, 16).str;   // not assignable error
    17/16


Class Methods


durationsToNonreducedFractions

Changes durations to nonreduced fractions sharing least common denominator.

  1. Example

    d = [FoscDuration(2, 4), 3, [5, 16]];
    f = FoscDuration.durationsToNonreducedFractions(d);
    f.collect { |each| each.str }.postln;
    [ "8/16", "48/16", "5/16" ]


fromLilypondDurationString


isToken


Instance Properties


dotCount

Gets dot count.

Dot count defined equal to number of dots required to notate duration.

Raises assignability error when duration is not assignable.

Returns positive integer.

  1. Example

    o = [];
    (1..16).do { |num|
        d = FoscDuration(num, 16);
        if (d.isAssignable) { o = o.add("%\t%".format(d.str, d.dotCount)) };
    };
    o.join("\n");
    1/16    0
    1/8 0
    3/16    1
    1/4 0
    3/8 1
    7/16    2
    1/2 0
    3/4 1
    7/8 2
    15/16   3
    1/1 0


equalOrGreaterAssignable

Gets assignable duration equal to or just greater than this duration.

Returns new duration.

  1. Example

    o = [];
    (1..16).do { |num|
        d = FoscDuration(num, 16);
        o = o.add("%\t%".format(d.str, d.equalOrGreaterAssignable.str));
    };
    o.join("\n");
    1/16    1/16
    1/8 1/8
    3/16    3/16
    1/4 1/4
    5/16    3/8
    3/8 3/8
    7/16    7/16
    1/2 1/2
    9/16    3/4
    5/8 3/4
    11/16   3/4
    3/4 3/4
    13/16   7/8
    7/8 7/8
    15/16   15/16
    1/1 1/1


equalOrGreaterPowerOfTwo

Gets duration equal or just greater power of two.

Returns new duration.

  1. Example

    o = [];
    (1..16).do { |num|
        d = FoscDuration(num, 16);
        o = o.add("%\t%".format(d.str, d.equalOrGreaterPowerOfTwo.str));
    };
    o.join("\n");
    1/16    1/16
    1/8 1/8
    3/16    1/4
    1/4 1/4
    5/16    1/2
    3/8 1/2
    7/16    1/2
    1/2 1/2
    9/16    1/1
    5/8 1/1
    11/16   1/1
    3/4 1/1
    13/16   1/1
    7/8 1/1
    15/16   1/1
    1/1 1/1


equalOrLesserAssignable

Gets assignable duration equal or just less than this duration.

Returns new duration.

  1. Example

    o = [];
    (1..16).do { |num|
        d = FoscDuration(num, 16);
        o = o.add("%\t%".format(d.str, d.equalOrLesserAssignable.str));
    };
    o.join("\n");
    1/16    1/16
    1/8 1/8
    3/16    3/16
    1/4 1/4
    5/16    1/4
    3/8 3/8
    7/16    7/16
    1/2 1/2
    9/16    1/2
    5/8 1/2
    11/16   1/2
    3/4 3/4
    13/16   3/4
    7/8 7/8
    15/16   15/16
    1/1 1/1


equalOrLesserPowerOfTwo

Gets duration equal to or just less than power of two.

Returns new duration.

  1. Example

    o = [];
    (1..16).do { |num|
        d = FoscDuration(num, 16);
        o = o.add("%\t%".format(d.str, d.equalOrLesserPowerOfTwo.str));
    };
    o.join("\n");
    1/16    1/16
    1/8 1/8
    3/16    1/8
    1/4 1/4
    5/16    1/4
    3/8 1/4
    7/16    1/4
    1/2 1/2
    9/16    1/2
    5/8 1/2
    11/16   1/2
    3/4 1/2
    13/16   1/2
    7/8 1/2
    15/16   1/2
    1/1 1/1


flagCount

Gets flag count. Flag count defined equal to number of flags required to notate duration.

Returns nonnegative integer.

  1. Example

    o = [];
    (1..16).do { |num|
        d = FoscDuration(num, 64);
        o = o.add("%\t%".format(d.str, d.flagCount));
    };
    o.join("\n");
    1/64    4
    1/32    3
    3/64    3
    1/16    2
    5/64    2
    3/32    2
    7/64    2
    1/8 1
    9/64    1
    5/32    1
    11/64   1
    3/16    1
    13/64   1
    7/32    1
    15/64   1
    1/4 0


hasPowerOfTwoDenominator

Is true when duration is an integer power of two. Otherwise false.

  1. Example

    FoscDuration(1, 4).hasPowerOfTwoDenominator.postln;
    true
    FoscDuration(1, 7).hasPowerOfTwoDenominator.postln;
    false


impliedProlation

Gets implied prolation.

Returns multipler.

  1. Example

    o = [];
    (1..16).do { |num|
        d = FoscDuration(1, num);
        o = o.add("%\t%".format(d.str, d.impliedProlation.str));
    };
    o.join("\n");
    1/1 1/1
    1/2 1/1
    1/3 2/3
    1/4 1/1
    1/5 4/5
    1/6 2/3
    1/7 4/7
    1/8 1/1
    1/9 8/9
    1/10    4/5
    1/11    8/11
    1/12    2/3
    1/13    8/13
    1/14    4/7
    1/15    8/15
    1/16    1/1


isAssignable

Is true when duration is assignable. Otherwise false.

Returns true or false.

  1. Example

    o = [];
    (1..16).do { |num|
        d = FoscDuration(num, 8);
        o = o.add("%\t%".format(d.str, d.isAssignable));
    };
    o.join("\n");
    1/8 true
    1/4 true
    3/8 true
    1/2 true
    5/8 false
    3/4 true
    7/8 true
    1/1 true
    9/8 false
    5/4 false
    11/8    false
    3/2 true
    13/8    false
    7/4 true
    15/8    true
    2/1 true


lilypondDurationString

Gets LilyPond duration string. Raises assignability error when duration is not assignable.

Returns string.

  1. Example

    FoscDuration(3, 16).lilypondDurationString.postln;
    8.
    FoscDuration(5, 16).lilypondDurationString;     // assignability error 
    ERROR: FoscDuration:lilypondDurationString: duration 5/16 is not assignable.


str

(inherited in abjad)

  1. Example

    FoscDuration(1, 4).str;
    1/4
    FoscDuration(inf).str;
    inf


pair

Gets numerator and denominator.

Returns integer pair.

  1. Example

    FoscDuration(3, 16).str;
    3/16


prolationString

Gets prolation string.

Returns string.

  1. Example

    o = [];
    (1..16).do { |num|
        d = FoscDuration(1, num);
        o = o.add("%\t%".format(d.str, d.prolationString));
    };
    o.join("\n");
    1/1 1:1
    1/2 2:1
    1/3 3:1
    1/4 4:1
    1/5 5:1
    1/6 6:1
    1/7 7:1
    1/8 8:1
    1/9 9:1
    1/10    10:1
    1/11    11:1
    1/12    12:1
    1/13    13:1
    1/14    14:1
    1/15    15:1
    1/16    16:1


reciprocal

Gets reciprocal.

Returns new duration.

code:: FoscDuration(1, 2).reciprocal.str;

  1. • reciprocal

    Gets reciprocal.

    Returns new duration.

    FoscDuration(1, 2).reciprocal.str;
    2/1


Instance Methods: Special Methods


abs

Gets absolute value of duration.

Returns nonnegative duration.

  1. Example

    a = FoscDuration(-1, 4);
    b = a.abs;
    b.str;
    1/4


asCompileString

  1. Example

    a = FoscDuration(1, 4);
    a.asCompileString.postln;
    FoscDuration(1, 4)


+

Adds duration to expr.

Returns duration.

  1. Returns duration when expr is a duration.

    a = FoscDuration(1, 2);
    b = FoscDuration(3, 2);
    c = (a + b);
    c.str;
    2/1
  2. Returns nonreduced fraction when expr is a nonreduced fraction.

    a = FoscDuration(1, 2);
    b = FoscNonreducedFraction(3, 2);
    c = (a + b);
    c.str;
    4/2


asFloat

  1. Example

    FoscDuration(3, 2).asFloat.postln;
    1.5


/

Divides duration by expr.

Returns multiplier.

  1. Returns multiplier when expr is a duration.

    a = FoscDuration(2, 4);
    b = FoscDuration(2, 1);
    c = (a / b);
    c.str;
    1/4
  2. Returns nonreduced fraction when expr is a nonreduced fraction.

    a = FoscDuration(2, 4);
    b = FoscNonreducedFraction(2, 1);
    c = (a / b);
    c.str;
    1/4


divmod

Equals the pair (duration // args, duration % args).

Returns pair.

  1. Example

    a = FoscDuration(7, 4);
    b = a.divmod(FoscDuration(4, 4));
    b.collect { |each| each.str };
    [ "1/1", "3/4" ]


==

Is true when duration equals arg. Otherwise false.

Returns true or false.

  1. Example

    (FoscDuration(4, 4) == FoscDuration(4, 4)).postln;
    true
    (FoscDuration(4, 4) == FoscDuration(2, 4)).postln;
    false
    (FoscDuration(4, 4) == FoscDuration(2, 2)).postln;
    true


format

Formats duration.

Set format_specification to ’’ or storage. Interprets ’’ equal to storage.

Returns string.

  1. Example

    FoscDuration(1, 4).format;
    1/4


>=

Is true when duration is greater than or equal to arg. Otherwise false.

Returns true or false.

  1. Example

    (FoscDuration(4, 4) >= FoscDuration(4, 4)).postln;
    true
    (FoscDuration(4, 4) >= FoscDuration(2, 4)).postln;
    true
    (FoscDuration(4, 4) >= FoscDuration(2, 2)).postln;
    true


>

Is true when duration is greater than arg. Otherwise false.

Returns true or false.

  1. Example

    (FoscDuration(4, 4) > FoscDuration(4, 4)).postln;
    false
    (FoscDuration(4, 4) > FoscDuration(2, 4)).postln;
    true
    (FoscDuration(4, 4) > FoscDuration(2, 2)).postln;
    false


<=

Is true when duration is less than or equal to arg. Otherwise false.

Returns true or false.

  1. Example

    (FoscDuration(4, 4) <= FoscDuration(4, 4)).postln;
    true
    (FoscDuration(4, 4) <= FoscDuration(2, 4)).postln;
    false
    (FoscDuration(4, 4) <= FoscDuration(2, 2)).postln;
    true


<

Is true when duration is less than arg. Otherwise false.

Returns true or false.

  1. Example

    (FoscDuration(4, 4) < FoscDuration(4, 4)).postln;
    false
    (FoscDuration(4, 4) < FoscDuration(2, 4)).postln;
    false
    (FoscDuration(4, 4) < FoscDuration(2, 2)).postln;
    false


mod

Modulus operator applied to duration.

Returns duration.

  1. Example

    a = FoscDuration(4, 4);
    b = FoscDuration(2, 4);
    c = (a % b);
    c.str;
    0/1
    d = (b % a);
    d.str;
    1/2


*

Duration multiplied by expr.

Returns duration.

  1. Returns duration when expr is a duration.

    a = FoscDuration(1, 2);
    b = FoscDuration(3, 2);
    c = (a * b);
    c.str;
    3/4
  2. Returns nonreduced fraction when expr is a nonreduced fraction.

    a = FoscDuration(1, 2);
    b = FoscNonreducedFraction(3, 6);
    c = (a * b);
    c.str;
    3/12


!=

Is true when duration does not equal arg. Otherwise false.

Returns true or false.

  1. Example

    (FoscDuration(4, 4) != FoscDuration(4, 4)).postln;
    false
    (FoscDuration(4, 4) != FoscDuration(2, 4)).postln;
    true
    (FoscDuration(4, 4) != FoscDuration(2, 2)).postln;
    false


neg

Negates duration.

Returns new duration.

  1. Example

    a = FoscDuration(1, 4);
    b = a.neg;
    b.str;
    -1/4


**

Raises duration to expr power.

Returns new duration.

  1. Example

    a = FoscDuration(4, 2) ** 2;
    a.str;
    4/1


reduce


-

Subtracts expr from duration.

Returns new duration.

  1. Returns duration when expr is a duration.

    a = FoscDuration(3, 2);
    b = FoscDuration(1, 2);
    c = (a - b);
    c.str;
    1/1
  2. Returns nonreduced fraction when expr is a nonreduced fraction.

    a = FoscDuration(3, 2);
    b = FoscNonreducedFraction(1, 2);
    c = (a - b);
    c.str;
    2/2


truediv

Documentation required.


Instance Methods


toClockString


toScoreMarkup


withDenominator

Changes duration to nonreduced fraction with denominator.

Returns new duration.

  1. Example

    a = FoscDuration(1, 4);
    [4, 8, 16, 32].collect { |each| a.withDenominator(each).str }.postln;
    [ "1/4", "2/8", "4/16", "8/32" ]