Class: HeadMusic::Content::CantusFirmus::Example
- Inherits:
-
Object
- Object
- HeadMusic::Content::CantusFirmus::Example
- Defined in:
- lib/head_music/content/cantus_firmus/example.rb
Overview
Sample cantus firmus examples from various pedagogical sources. These are traditional melodies used for teaching counterpoint.
Constant Summary collapse
- EXAMPLES_DATA =
YAML.load_file(File.("examples.yml", __dir__)).freeze
Instance Attribute Summary collapse
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#pitches ⇒ Object
readonly
Returns the value of attribute pitches.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#tonal_center ⇒ Object
readonly
Returns the value of attribute tonal_center.
Class Method Summary collapse
-
.all ⇒ Object
-
.by_mode(mode_name) ⇒ Object
-
.by_source(source_identifier) ⇒ Object
-
.by_tonal_center(tonal_center_name) ⇒ Object
-
.sources ⇒ Object
Instance Method Summary collapse
-
#initialize(data:) ⇒ Example
constructor
A new instance of Example.
-
#length ⇒ Object
-
#to_s ⇒ Object
Constructor Details
#initialize(data:) ⇒ Example
Returns a new instance of Example.
39 40 41 42 43 44 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 39 def initialize(data:) @source = Source.get(data["source"]) @tonal_center = data["tonal_center"] @mode = data["mode"]&.to_sym @pitches = data["pitches"] || [] end |
Instance Attribute Details
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
9 10 11 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 9 def mode @mode end |
#pitches ⇒ Object (readonly)
Returns the value of attribute pitches.
9 10 11 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 9 def pitches @pitches end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
9 10 11 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 9 def source @source end |
#tonal_center ⇒ Object (readonly)
Returns the value of attribute tonal_center.
9 10 11 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 9 def tonal_center @tonal_center end |
Class Method Details
.all ⇒ Object
12 13 14 15 16 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 12 def all @all ||= EXAMPLES_DATA["cantus_firmus_examples"].map do |data| new(data: data) end end |
.by_mode(mode_name) ⇒ Object
29 30 31 32 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 29 def by_mode(mode_name) normalized_mode = mode_name.to_s.downcase all.select { |example| example.mode.to_s.downcase == normalized_mode } end |
.by_source(source_identifier) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 18 def by_source(source_identifier) source = Source.get(source_identifier) return [] unless source all.select { |example| example.source == source } end |
.by_tonal_center(tonal_center_name) ⇒ Object
34 35 36 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 34 def by_tonal_center(tonal_center_name) all.select { |example| example.tonal_center.to_s == tonal_center_name.to_s } end |
.sources ⇒ Object
25 26 27 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 25 def sources all.map(&:source).uniq end |
Instance Method Details
#length ⇒ Object
46 47 48 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 46 def length pitches.length end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 50 def to_s "#{tonal_center} #{mode} (#{source})" end |