Class: HeadMusic::Content::Note

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/content/note.rb

Overview

A note is a pitch with a duration.

Note quacks like a placement, but requires a different set of construction arguments

  • always has a pitch
  • receives a voice and position if unspecified

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pitch, rhythmic_value, voice = nil, position = nil) ⇒ Note

Returns a new instance of Note.



12
13
14
15
16
17
# File 'lib/head_music/content/note.rb', line 12

def initialize(pitch, rhythmic_value, voice = nil, position = nil)
  @pitch = HeadMusic::Rudiment::Pitch.get(pitch)
  @rhythmic_value = HeadMusic::Content::RhythmicValue.get(rhythmic_value)
  @voice = voice || HeadMusic::Content::Voice.new
  @position = position || HeadMusic::Content::Position.new(@voice.composition, "1:1")
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



27
28
29
# File 'lib/head_music/content/note.rb', line 27

def method_missing(method_name, *args, &block)
  respond_to_missing?(method_name) ? placement.send(method_name, *args, &block) : super
end

Instance Attribute Details

#pitchObject

Returns the value of attribute pitch.



10
11
12
# File 'lib/head_music/content/note.rb', line 10

def pitch
  @pitch
end

#positionObject

Returns the value of attribute position.



10
11
12
# File 'lib/head_music/content/note.rb', line 10

def position
  @position
end

#rhythmic_valueObject

Returns the value of attribute rhythmic_value.



10
11
12
# File 'lib/head_music/content/note.rb', line 10

def rhythmic_value
  @rhythmic_value
end

#voiceObject

Returns the value of attribute voice.



10
11
12
# File 'lib/head_music/content/note.rb', line 10

def voice
  @voice
end

Instance Method Details

#placementObject



19
20
21
# File 'lib/head_music/content/note.rb', line 19

def placement
  @placement ||= HeadMusic::Content::Placement.new(voice, position, rhythmic_value, pitch)
end

#respond_to_missing?(method_name, *_args) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/head_music/content/note.rb', line 31

def respond_to_missing?(method_name, *_args)
  placement.respond_to?(method_name)
end

#to_sObject



23
24
25
# File 'lib/head_music/content/note.rb', line 23

def to_s
  "#{pitch} at #{position}"
end