Class: Clef::Core::Note

Inherits:
Object
  • Object
show all
Defined in:
lib/clef/core/note.rb

Constant Summary collapse

VALID_ARTICULATIONS =
%i[staccato tenuto accent marcato fermata].freeze
TIE_STATES =
%i[start continue stop].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pitch, duration, articulations: [], tied: false) ⇒ Note

Returns a new instance of Note.

Parameters:

  • pitch (Pitch)
  • duration (Duration)
  • articulations (Array<Symbol>) (defaults to: [])
  • tied (Boolean, Symbol) (defaults to: false)


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/clef/core/note.rb', line 17

def initialize(pitch, duration, articulations: [], tied: false)
  validate_pitch!(pitch)
  validate_duration!(duration)

  @pitch = pitch
  @duration = duration
  self.articulations = articulations
  @tie_state = normalize_tie_state(tied)
  @slur_start = false
  @slur_end = false
  @beam_start = false
  @beam_end = false
end

Instance Attribute Details

#articulationsObject

Returns the value of attribute articulations.



10
11
12
# File 'lib/clef/core/note.rb', line 10

def articulations
  @articulations
end

#beam_endObject

Returns the value of attribute beam_end.



11
12
13
# File 'lib/clef/core/note.rb', line 11

def beam_end
  @beam_end
end

#beam_startObject

Returns the value of attribute beam_start.



11
12
13
# File 'lib/clef/core/note.rb', line 11

def beam_start
  @beam_start
end

#durationObject (readonly)

Returns the value of attribute duration.



9
10
11
# File 'lib/clef/core/note.rb', line 9

def duration
  @duration
end

#pitchObject (readonly)

Returns the value of attribute pitch.



9
10
11
# File 'lib/clef/core/note.rb', line 9

def pitch
  @pitch
end

#slur_endObject

Returns the value of attribute slur_end.



11
12
13
# File 'lib/clef/core/note.rb', line 11

def slur_end
  @slur_end
end

#slur_startObject

Returns the value of attribute slur_start.



11
12
13
# File 'lib/clef/core/note.rb', line 11

def slur_start
  @slur_start
end

#tie_stateObject (readonly)

Returns the value of attribute tie_state.



10
11
12
# File 'lib/clef/core/note.rb', line 10

def tie_state
  @tie_state
end

Instance Method Details

#add_articulation(articulation) ⇒ Note

Parameters:

  • articulation (Symbol)

Returns:



53
54
55
56
# File 'lib/clef/core/note.rb', line 53

def add_articulation(articulation)
  self.articulations = articulations + [articulation]
  self
end

#lengthRational

Returns:

  • (Rational)


32
33
34
# File 'lib/clef/core/note.rb', line 32

def length
  duration.length
end

#tiedBoolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/clef/core/note.rb', line 37

def tied
  !tie_state.nil?
end

#tied=(value) ⇒ Object

Parameters:

  • value (Boolean, Symbol)


42
43
44
# File 'lib/clef/core/note.rb', line 42

def tied=(value)
  @tie_state = normalize_tie_state(value)
end