Sha256: 3729e4f000a185b9efc0379bbdb8d5d14db3ce7cede1a92efe752a02d3cc414e

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

# A module for musical content
module HeadMusic::Content; end

# 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
class HeadMusic::Content::Note
  attr_accessor :pitch, :rhythmic_value, :voice, :position

  def initialize(pitch, rhythmic_value, voice = nil, position = nil)
    @pitch = HeadMusic::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

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

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

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
head_music-4.0.1 lib/head_music/content/note.rb
head_music-4.0.0 lib/head_music/content/note.rb
head_music-3.0.1 lib/head_music/content/note.rb
head_music-3.0.0 lib/head_music/content/note.rb
head_music-2.0.1 lib/head_music/content/note.rb
head_music-2.0.0 lib/head_music/content/note.rb
head_music-1.0.0 lib/head_music/content/note.rb