class

Mystic::Note

Inherits Reference < Object

Represents a note, consisting of a note name (letter and accidental) and octave

To create a Note:

# Middle C
Note.new("C4")

# Middle C. Octave defaults to 4 if not provided
Note.new("C")

# Middle C
# In the case of accidentals, will default to using sharps.
Note.from_midi(60)

# The A above middle C
# This is used internally and may be less useful for most end users.
# See `Coords` for more information on Coordinate representation of pitches
Note.from_coords(Coords.new(-1, 3))

Constants

ALL_PITCHES = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
BASE_OCTAVE = 4

Coordinates assume starting from C4

LETTER_PITCH_CLASSES = { C: 0, D: 2, E: 4, F: 5, G: 7, A: 9, B: 11, }
NAME_PATTERN = "(?<letter>[abcdefgABCDEFG])(?<accidental>[b♭𝄫]+|[#♯x𝄪]*)"

Regex pattern for a note name

PITCH_COORDS = { C: Coords.new(0, 0), D: Coords.new(-1, 2), E: Coords.new(-2, 4), F: Coords.new(1, -1), G: Coords.new(0, 1), A: Coords.new(-1, 3), B: Coords.new(-2, 5), }
PITCHES = ["C", "D", "E", "F", "G", "A", "B"]

Constructors

from_coords(coords : Coords) : self

Returns a note corresponding to a given Coords

Source
new(s : String)

Returns a note corresponding to a given string representation

Source

Class methods

from_midi(i : Int32)

Returns a note corresponding to a given midi value

Source

Instance methods

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

Note: this compares notes as ordered on a staff rather than by pitch.

For example, a Cx4 < Db4 even though Cx4 sounds higher.

Source
==(other : self) : Bool

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

Source
>(other : self) : Bool
Source
accidental
Source
accidental_offset
Source
chroma

Returns the numerical pitch class (0-11)

Source
coords

Returns Coords representation

Source
frequency(tuning = 440.0) : Float64

Returns the frequency in Hz

Source
letter
Source
midi

Returns the midi value

Source
name
Source
octave
Source
pitch_class

Returns the PitchClass

Source
to_s(io : IO) : Nil

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