Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/mtk/numeric_extensions.rb

Overview

Note:

you must require ‘mtk/numeric_extensions’ to use these methods.

Optional Numeric methods for converting to MTK::Core objects.

Instance Method Summary collapse

Instance Method Details

#centsObject Also known as: cent

Convert a Numeric cents value to a MTK::Core::Interval

Examples:

100.cents => 1.semitone



54
55
56
# File 'lib/mtk/numeric_extensions.rb', line 54

def cents
  MTK::Core::Interval.from_f(self/100.0)
end

#octavesObject Also known as: octave

Convert a Numeric octaves value to a MTK::Core::Interval

Examples:

1.octave => 12.semitones



61
62
63
# File 'lib/mtk/numeric_extensions.rb', line 61

def octaves
  MTK::Core::Interval.from_f(self * 12)
end

#percent_intensityObject

Note:

The standard range of intensity percentages is from 0 - 100

Convert a Numeric percentage to a MTK::Core::Intensity

Examples:

100.percent_intensity => fff



40
41
42
# File 'lib/mtk/numeric_extensions.rb', line 40

def percent_intensity
  MTK::Core::Intensity.from_f(self/100.0)
end

#to_durationObject Also known as: beats, beat

Convert a Numeric to a MTK::Core::Duration

Examples:

3.5.to_duration + 1.beat + 2.beats



23
24
25
# File 'lib/mtk/numeric_extensions.rb', line 23

def to_duration
  MTK::Core::Duration.from_f(self)
end

#to_intensityObject

Note:

The standard range of intensity values is from 0.0 - 1.0

Convert a Numeric to a MTK::Core::Intensity

Examples:

1.to_pitch => fff



33
34
35
# File 'lib/mtk/numeric_extensions.rb', line 33

def to_intensity
  MTK::Core::Intensity.from_f(self)
end

#to_intervalObject Also known as: semitones, semitone

Convert a Numeric to a MTK::Core::Interval

Examples:

3.5.to_interval + 1.semitone + 2.semitones



46
47
48
# File 'lib/mtk/numeric_extensions.rb', line 46

def to_interval
  MTK::Core::Interval.from_f(self)
end

#to_pitchObject

Convert a Numeric to a MTK::Core::Pitch

Examples:

60.to_pitch => C4



9
10
11
# File 'lib/mtk/numeric_extensions.rb', line 9

def to_pitch
  MTK::Core::Pitch.from_f(self)
end

#to_pitch_classObject

Convert a Numeric to a MTK::Core::PitchClass

Examples:

2.to_pitch_class => D



16
17
18
# File 'lib/mtk/numeric_extensions.rb', line 16

def to_pitch_class
  MTK::Core::PitchClass.from_f(self)
end