class

Mystic::Interval

Inherits Reference < Object

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)

Constants

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

from_coords(coords : Coords) : Interval
Source
new(s : String)
Source

Instance methods

+(other : self) : Interval
Source
+(note : Note) : Note

Adding intervals to notes is defined in the Note class

Source
-(other : self) : Interval
Source
<(other : self) : Bool
Source
<=>(other : self) : Int32

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

Source
==(other : self) : Bool

Returns true if this reference is the same as other. Invokes same?.

Source
>(other : self) : Bool
Source
compound?

Returns if compound (greater than an octave)

Source
coords

Returns Coords representation

Source
direction

Returns 1 if ascending and -1 if descending

Source
invert

Returns the inversion If compound, returns the inversion of the simple form

Source
number

Returns the (positive) number

Source
octaves

Returns number of octaves above the simple interval Note: an octave is considered a simple interval

Source
quality
Source
quality_offset

Returns the accidental offset based on the quality

Source
reverse

Returns the same interval going in the opposite direction

Source
semitones

Returns the number of semitones the interval spans

Source
simple

Returns the simple form

Source
simple?

Returns if simple (an octave or smaller)

Source
to_s(io : IO)

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>
Source
value
Source