class Mystic::Note
- Mystic::Note
- Reference
- Object
Overview
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))
Defined in:
mystic/note.crConstant Summary
-
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
-
.new(s : String)
Returns a note corresponding to a given string representation
Class Method Summary
-
.from_midi(i : Int32)
Returns a note corresponding to a given midi value
Instance Method Summary
- #+(interval : Interval) : Note
- #-(interval : Interval) : Note
- #-(other : self) : Interval
- #<(other : self) : Bool
-
#<=>(other : self) : Int32
Note: this compares notes as ordered on a staff rather than by pitch.
-
#==(other : self) : Bool
Returns
true
if this reference is the same as other. - #>(other : self) : Bool
- #accidental : String
- #accidental_offset : Int32
-
#chroma : Int32
Returns the numerical pitch class (0-11)
-
#coords : Coords
Returns
Coords
representation -
#frequency(tuning = 440.0) : Float64
Returns the frequency in Hz
- #letter : String
-
#midi : Int32
Returns the midi value
- #name : String
- #octave : Int32
-
#pitch_class : PitchClass
Returns the
PitchClass
-
#to_s(io : IO) : Nil
Appends a short String representation of this object which includes its class name and its object address.
Constructor Detail
Returns a note corresponding to a given Coords
Class Method Detail
Instance Method Detail
Note: this compares notes as ordered on a staff rather than by pitch.
For example, a Cx4 < Db4 even though Cx4 sounds higher.
Returns true
if this reference is the same as other. Invokes same?
.
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>