class Mystic::Interval

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.cr

Constant 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

Constructor Detail

def self.from_coords(coords : Coords) : Interval #

[View source]
def self.new(s : String) #

[View source]

Instance Method Detail

def +(other : self) : Interval #

[View source]
def +(note : Note) : Note #

Adding intervals to notes is defined in the Note class


[View source]
def -(other : self) : Interval #

[View source]
def <(other : self) : Bool #

[View source]
def <=>(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


[View source]
def ==(other : self) : Bool #
Description copied from class Reference

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


[View source]
def >(other : self) : Bool #

[View source]
def compound? : Bool #

Returns if compound (greater than an octave)


[View source]
def coords : Coords #

Returns Coords representation


[View source]
def direction : Int32 #

Returns 1 if ascending and -1 if descending


[View source]
def invert : self #

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


[View source]
def number : Int32 #

Returns the (positive) number


[View source]
def octaves : Int32 #

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


[View source]
def quality : String #

[View source]
def quality_offset : Int32 #

Returns the accidental offset based on the quality


[View source]
def reverse : Interval #

Returns the same interval going in the opposite direction


[View source]
def semitones : Int32 #

Returns the number of semitones the interval spans


[View source]
def simple : Interval #

Returns the simple form


[View source]
def simple? : Bool #

Returns if simple (an octave or smaller)


[View source]
def to_s(io : IO) #
Description copied from class Reference

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>

[View source]
def value : Int32 #

[View source]