Skip to content

Duration.IsDenominatorPowerOfTwo

Chanan edited this page Aug 15, 2020 · 1 revision

Duration.IsDenominatorPowerOfTwo Method

Namespace: CW.Soloist.CompositionService.MusicTheory
Assembly: CW.Soloist.CompositionService.dll


Summary

Utility method which determines whether this duration's denominator is a power of two or not.
This could be helpful for musical quantization process.


Returns

True if this duration's denominator is a power of two, and false else-wise.


Source Code

public bool IsDenominatorPowerOfTwo()
{
    byte num = this.Denominator;

    int remainder = 0;
    while (remainder == 0)
    {
        remainder = num % 2;
        num /= 2;
    }
                
    if (num == 0)
        return true;
    else return false;

    /* // alternative implemntation which is more compact but less clear 
    return (int)Math.Ceiling(Math.Log(Denominator) / Math.Log(2))
        == (int)Math.Floor(Math.Log(Denominator) / Math.Log(2)); */
}
  • Home
  • Getting Started
  • Design
    • Business Logical Layer (CW.Soloist.CompositionService)
    • Data Access Layer
    • Presentation Layer
Clone this wiki locally