public class RationalDuration extends Object implements DurationIndication, Comparable<RationalDuration>
RationalDuration.DottedBaseDuration
, which represents
the combination of basic note symbols and Prolongation Dots.
RationalDuration.DottedBaseDuration
.
Modifier and Type | Class and Description |
---|---|
static class |
RationalDuration.DottedBaseDuration
Convenience class which allows to retrieve base value, effective value,
dot count, dots as a text string, etc.
|
Modifier and Type | Field and Description |
---|---|
protected static Map<Rational,RationalDuration.DottedBaseDuration> |
cache_dotted
Maps from rational duration values to the representing dotted notation.
|
protected static Map<Integer,PrimeFactors> |
cache_int
A cache for the prime factors of the integers serving as key.
|
protected static Map<Integer,Integer> |
cache_nearest_pot
Caches the nearest power of two, as found by the algorithm
{@link #nearest_power_of_two(int):
|
protected static Map<Rational,PrimeFactors> |
cache_rat
A cache for the prime factors of the rationals.
|
static Translet.Parser<RationalDuration> |
parser
Evident
|
static RationalDuration |
QUARTER
The duration of a quarter note = 1/4
|
(package private) Rational |
rat
The rational value of the duration.
|
static RetractableFunction<RationalDuration,Rational> |
toRational
retract .
|
static RationalDuration |
WHOLE
The duration of a whole note = 1/1
|
static RationalDuration |
ZERO
Evident
|
Constructor and Description |
---|
RationalDuration(int num,
int den)
Make a duration n/d for n>=0 and d>0.
|
RationalDuration(Rational rat)
Make a duration for rat>=0/1.
|
Modifier and Type | Method and Description |
---|---|
static List<Integer> |
binarySectioning(int i)
Returns the unique descending list of powers of two which sum up to the argument.
|
int |
compareTo(RationalDuration o) |
static @Opt RationalDuration.DottedBaseDuration |
dottedNotation(Rational rat)
Return the representation as base duration plus zero or more DOTs,
or null if no such exists.
|
static @Opt RationalDuration.DottedBaseDuration |
dottedNotation(RationalDuration d)
Return the duration's representation as base duration plus zero or more DOTs,
|
static boolean |
e_writable(int enumerator,
int maxdots)
Quick test whether a numerator alone is writable as
RationalDuration.DottedBaseDuration ,
with given maximal dot count. |
boolean |
equals(Object o) |
static RationalDuration |
fromRational(Rational rat) |
static int |
highest_odd_factor(int value)
Divides repeatedly by 2 as long as the result is even.
|
static boolean |
isPowerOfTwo(int i)
Whether an integer is a power of two.
|
static boolean |
isPowerOfTwo(Rational rat)
Returns true for 1/n or n/1, with n power of two(2), including 0/1.
|
static int |
logTwo(int i)
Delivers the exponent of two.
|
static int |
nearest_power_of_two(int i)
Used to find the most sensible denominator for to introduce a
proportion with the numerator i.
|
static int |
nextNotLowerPowerOfTwo(int i)
Returns the next power of two which is not lower than the argument.
|
static PrimeFactors |
primeFactors_mod_2(BigInteger value) |
static PrimeFactors |
primeFactors_mod_2(int value)
Delivers a
PrimeFactors object after removing all powers of two(2),
since these are ubiquituous in CWN notation and not subject to dedicated
calculation. |
static PrimeFactors |
primeFactors_mod_2(Rational value)
Delivers a
PrimeFactors object after removing all powers of two(2),
since these are ubiquituous in CWN notation and not subject to dedicated
calculation. |
Rational |
toRational()
Returns the "Notated CWN Duration", which is a rational, standing for
a note duration (1/4 for a quater note, 3/8 for a dotted quater note, etc.)
|
String |
toString()
Same as
Rational.toString() . |
protected static int |
x_nearest_power_of_two(int i)
Internal aux function.
|
protected static Map<Integer,PrimeFactors> cache_int
protected static Map<Rational,PrimeFactors> cache_rat
protected static final Map<Rational,RationalDuration.DottedBaseDuration> cache_dotted
protected static final Map<Integer,Integer> cache_nearest_pot
final Rational rat
public static final RationalDuration ZERO
public static final RationalDuration WHOLE
public static final RationalDuration QUARTER
public static RetractableFunction<RationalDuration,Rational> toRational
public static final Translet.Parser<RationalDuration> parser
public RationalDuration(int num, int den)
public RationalDuration(Rational rat)
public static PrimeFactors primeFactors_mod_2(int value)
PrimeFactors
object after removing all powers of two(2),
since these are ubiquituous in CWN notation and not subject to dedicated
calculation.public static PrimeFactors primeFactors_mod_2(BigInteger value)
primeFactors_mod_2(int)
public static PrimeFactors primeFactors_mod_2(Rational value)
PrimeFactors
object after removing all powers of two(2),
since these are ubiquituous in CWN notation and not subject to dedicated
calculation.public static int highest_odd_factor(int value)
@Opt public static @Opt RationalDuration.DottedBaseDuration dottedNotation(Rational rat)
rat nextFullNote factors nextFactors 7 8 1 1 8 => 2^3 => 2 is dot count (rat=) -- => -- = - => - (=base) 16 16 2 4 3 4 1 1 4 => 2^2 => 1 is dot count (rat=) -- => --- = - => -- 32 32 8 16 1 2 1 1 2 => 2^1 => 0 is dot count (rat=) -- => --- = - => -- 8 8 4 8
@Opt public static @Opt RationalDuration.DottedBaseDuration dottedNotation(RationalDuration d)
dottedNotation(Rational)
public static boolean e_writable(int enumerator, int maxdots)
RationalDuration.DottedBaseDuration
,
with given maximal dot count.
(This is called "e-writable". If dot-count==0, it is even "d-writable").
This test is sensible, since prime factors in the denominator must be
eliminated anyhow (by some proportional bracket).
So all durations with a numerator of
(2^x)*[(2^n)-1] are writable in one single symbol, using (n-1) dots:
1/2 -> 0 dots 1+1 = 2^1 = 00 0010 3/4 -> 1 dot 3+1 = 2^2 = 00 0100 7/8 -> 2 dots 7+1 = 2^3 = 00 1000
public static int nearest_power_of_two(int i)
| | , | , | , | , | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 .. 23 24 25 .. 32 1 2 2 4 4 8 8 8 8 8 8 16 16 16 16 16 16 16 16 32 32 32So you get proportions like 5/4, 7/8, 11/8, 17/16, 33/32.
protected static int x_nearest_power_of_two(int i)
public static boolean isPowerOfTwo(int i)
public static int nextNotLowerPowerOfTwo(int i)
public static int logTwo(int i)
public static boolean isPowerOfTwo(Rational rat)
public static List<Integer> binarySectioning(int i)
public String toString()
Rational.toString()
.public int compareTo(RationalDuration o)
compareTo
in interface Comparable<RationalDuration>
public Rational toRational()
DurationIndication
toRational
in interface DurationIndication
public static RationalDuration fromRational(Rational rat)