class Mystic::Interval
- Mystic::Interval
- Reference
- Object
Overview
Represents an interval
To create an Interval:
# Ascending Major 3rd
Interval.new("M3")
# Descending intervals have a negative value
# Descending Perfect 5th
Interval.new("P-5")
Available qualities are: M (major), m (minor), P (perfect), d (diminished), A (augmented). Going further is also possible, for example dd (doubly diminished) and AAA (triply augmented)
Defined in:
mystic/interval.crConstant Summary
-
BASE_SEMITONES =
[0, 2, 3, 5, 7, 8, 10] -
INTERVAL_COORDS =
{"1": Coords.new(0, 0), "2": Coords.new(3, -5), "3": Coords.new(2, -3), "4": Coords.new(1, -1), "5": Coords.new(0, 1), "6": Coords.new(3, -4), "7": Coords.new(2, -2), "8": Coords.new(1, 0)} -
QUALITY_SEMITONE_OFFSETS =
{P: 0, m: 0, M: 1, A: 1, d: -1} -
SHARP_COORDS =
Coords.new(-4, 7)
Constructors
Instance Method Summary
- #+(other : self) : Interval
-
#+(note : Note) : Note
Adding intervals to notes is defined in the Note class
- #-(other : self) : Interval
- #<(other : self) : Bool
-
#<=>(other : self) : Int32
Note: this compares intervals as ordered on a staff rather than by pitch.
-
#==(other : self) : Bool
Returns
trueif this reference is the same as other. - #>(other : self) : Bool
-
#compound? : Bool
Returns if compound (greater than an octave)
-
#coords : Coords
Returns
Coordsrepresentation -
#direction : Int32
Returns 1 if ascending and -1 if descending
-
#invert : self
Returns the inversion If compound, returns the inversion of the simple form
-
#number : Int32
Returns the (positive) number
-
#octaves : Int32
Returns number of octaves above the simple interval Note: an octave is considered a simple interval
- #quality : String
-
#quality_offset : Int32
Returns the accidental offset based on the quality
-
#reverse : Interval
Returns the same interval going in the opposite direction
-
#semitones : Int32
Returns the number of semitones the interval spans
-
#simple : Interval
Returns the simple form
-
#simple? : Bool
Returns if simple (an octave or smaller)
-
#to_s(io : IO)
Appends a short String representation of this object which includes its class name and its object address.
- #value : Int32
Constructor Detail
Instance Method Detail
Note: this compares intervals as ordered on a staff rather than by pitch. For example, an A2 < d3 even though an A2 spans more semitones Also note: this compares magnitude only, so direction is not taken into account
Returns true if this reference is the same as other. Invokes same?.
Returns number of octaves above the simple interval Note: an octave is considered a simple interval
Appends a short String representation of this object which includes its class name and its object address.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>