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.
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.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
-
#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
- .find_by_slug(slug) ⇒ Object
- .sources ⇒ Object
Instance Method Summary collapse
-
#initialize(data:) ⇒ Example
constructor
A new instance of Example.
-
#key_signature_name ⇒ Object
The mode named on its own tonal center, which KeySignature reads as a collection while retaining the scale type.
- #length ⇒ Object
-
#to_flow(rhythmic_value: :whole, meter: "4/4") ⇒ Object
An example is a catalog datum -- a pitch list with a mode and a citation -- not content, so rhythm and meter are the realization's choice rather than the datum's, and are parameters.
- #to_s ⇒ Object
Constructor Details
#initialize(data:) ⇒ Example
Returns a new instance of Example.
42 43 44 45 46 47 48 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 42 def initialize(data:) @slug = data["slug"] @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.
8 9 10 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 8 def mode @mode end |
#pitches ⇒ Object (readonly)
Returns the value of attribute pitches.
8 9 10 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 8 def pitches @pitches end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
8 9 10 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 8 def slug @slug end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
8 9 10 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 8 def source @source end |
#tonal_center ⇒ Object (readonly)
Returns the value of attribute tonal_center.
8 9 10 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 8 def tonal_center @tonal_center end |
Class Method Details
.all ⇒ Object
11 12 13 14 15 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 11 def all @all ||= EXAMPLES_DATA["cantus_firmus_examples"].map do |data| new(data: data) end end |
.by_mode(mode_name) ⇒ Object
32 33 34 35 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 32 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
21 22 23 24 25 26 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 21 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
37 38 39 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 37 def by_tonal_center(tonal_center_name) all.select { |example| example.tonal_center.to_s == tonal_center_name.to_s } end |
.find_by_slug(slug) ⇒ Object
17 18 19 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 17 def find_by_slug(slug) all.find { |example| example.slug == slug.to_s } end |
.sources ⇒ Object
28 29 30 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 28 def sources all.map(&:source).uniq end |
Instance Method Details
#key_signature_name ⇒ Object
The mode named on its own tonal center, which KeySignature reads as a collection while retaining the scale type.
67 68 69 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 67 def key_signature_name [tonal_center, mode].compact.join(" ") end |
#length ⇒ Object
50 51 52 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 50 def length pitches.length end |
#to_flow(rhythmic_value: :whole, meter: "4/4") ⇒ Object
An example is a catalog datum -- a pitch list with a mode and a citation -- not content, so rhythm and meter are the realization's choice rather than the datum's, and are parameters.
57 58 59 60 61 62 63 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 57 def to_flow(rhythmic_value: :whole, meter: "4/4") flow = HeadMusic::Content::Flow.new(name: to_s, key_signature: key_signature_name, meter: meter) flow.source = source voice = flow.add_voice(role: "cantus firmus") pitches.each_with_index { |pitch, index| voice.place("#{index + 1}:1", rhythmic_value, pitch) } flow end |
#to_s ⇒ Object
71 72 73 |
# File 'lib/head_music/content/cantus_firmus/example.rb', line 71 def to_s "#{tonal_center} #{mode} (#{source})" end |