Sha256: 9066e5fc0290d5c7ae1ca43dd3c581e0bfce1091ac7ea89f442f2a42010b954e

Contents?: true

Size: 1018 Bytes

Versions: 18

Compression:

Stored size: 1018 Bytes

Contents

# frozen_string_literal: true

# 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::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::RhythmicValue.get(rhythmic_value)
    @voice = voice || HeadMusic::Voice.new
    @position = position || HeadMusic::Position.new(@voice.composition, '1:1')
  end

  def placement
    @placement ||= HeadMusic::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

18 entries across 18 versions & 1 rubygems

Version Path
head_music-0.27.0 lib/head_music/content/note.rb
head_music-0.26.3 lib/head_music/content/note.rb
head_music-0.26.2 lib/head_music/content/note.rb
head_music-0.26.1 lib/head_music/content/note.rb
head_music-0.26.0 lib/head_music/content/note.rb
head_music-0.25.0 lib/head_music/content/note.rb
head_music-0.24.5 lib/head_music/content/note.rb
head_music-0.24.4 lib/head_music/content/note.rb
head_music-0.24.3 lib/head_music/content/note.rb
head_music-0.24.2 lib/head_music/content/note.rb
head_music-0.24.1 lib/head_music/content/note.rb
head_music-0.24.0 lib/head_music/content/note.rb
head_music-0.23.4 lib/head_music/content/note.rb
head_music-0.23.3 lib/head_music/content/note.rb
head_music-0.23.2 lib/head_music/content/note.rb
head_music-0.23.1 lib/head_music/content/note.rb
head_music-0.23.0 lib/head_music/content/note.rb
head_music-0.22.0 lib/head_music/content/note.rb