Class: Clef::Core::Clef

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

Constant Summary collapse

TYPES =
%i[treble bass alto tenor soprano mezzo_soprano baritone percussion tab].freeze
REFERENCE =
{
  treble: [[:b, 4], 2],
  bass: [[:d, 3], 2],
  alto: [[:c, 4], 2],
  tenor: [[:a, 3], 2],
  soprano: [[:g, 4], 2],
  mezzo_soprano: [[:e, 4], 2],
  baritone: [[:f, 3], 2],
  percussion: [[:b, 4], 2],
  tab: [[:b, 4], 2]
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Clef

Returns a new instance of Clef.

Parameters:

  • type (Symbol)

Raises:

  • (ArgumentError)


22
23
24
25
26
# File 'lib/clef/core/clef.rb', line 22

def initialize(type)
  raise ArgumentError, "unsupported clef type: #{type}" unless TYPES.include?(type)

  @type = type
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



19
20
21
# File 'lib/clef/core/clef.rb', line 19

def type
  @type
end

Instance Method Details

#reference_lineInteger

Returns:

  • (Integer)


35
36
37
# File 'lib/clef/core/clef.rb', line 35

def reference_line
  REFERENCE.fetch(type).last
end

#reference_pitchPitch

Returns:



29
30
31
32
# File 'lib/clef/core/clef.rb', line 29

def reference_pitch
  note_name, octave = REFERENCE.fetch(type).first
  Pitch.new(note_name, octave)
end