Class: HeadMusic::Rudiment::UnpitchedNote
- Inherits:
-
RhythmicElement
- Object
- Base
- RhythmicElement
- HeadMusic::Rudiment::UnpitchedNote
- Includes:
- Named, ValueEquality
- Defined in:
- lib/head_music/rudiment/unpitched_note.rb
Overview
An UnpitchedNote represents a percussion note with rhythm but no specific pitch. It inherits from RhythmicElement and can optionally have an instrument name. Intended future composition: UnpitchedNote ≈ UnpitchedSound + rhythmic value.
Instance Attribute Summary collapse
-
#alias_name_keys ⇒ Object
included
from Named
readonly
Returns the value of attribute alias_name_keys.
-
#instrument_name ⇒ Object
readonly
Returns the value of attribute instrument_name.
-
#name_key ⇒ Object
included
from Named
readonly
Returns the value of attribute name_key.
Class Method Summary collapse
-
.fetch_or_create(rhythmic_value, instrument_name) ⇒ Object
private
-
.get(rhythmic_value, instrument: nil) ⇒ Object
Instance Method Summary collapse
-
#==(other) ⇒ Object
included
from ValueEquality
-
#ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) ⇒ Object
included
from Named
-
#initialize(rhythmic_value, instrument_name = nil) ⇒ UnpitchedNote
constructor
A new instance of UnpitchedNote.
-
#localized_name(locale_code: Locale::DEFAULT_CODE) ⇒ Object
included
from Named
-
#localized_name_in_default_locale ⇒ Object
included
from Named
private
-
#localized_name_in_locale_matching_language(locale) ⇒ Object
included
from Named
private
-
#localized_name_in_matching_locale(locale) ⇒ Object
included
from Named
private
-
#localized_names ⇒ Object
included
from Named
Returns an array of LocalizedName instances that are synonymous with the name.
-
#name ⇒ Object
-
#name=(name) ⇒ Object
included
from Named
-
#sounded? ⇒ Boolean
-
#with_instrument(new_instrument_name) ⇒ Object
Create a new unpitched note with a different instrument.
-
#with_rhythmic_value(new_rhythmic_value) ⇒ Object
Override with_rhythmic_value to preserve instrument.
Constructor Details
#initialize(rhythmic_value, instrument_name = nil) ⇒ UnpitchedNote
Returns a new instance of UnpitchedNote.
33 34 35 36 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 33 def initialize(rhythmic_value, instrument_name = nil) super(rhythmic_value) @instrument_name = instrument_name end |
Instance Attribute Details
#alias_name_keys ⇒ Object (readonly) Originally defined in module Named
Returns the value of attribute alias_name_keys.
#instrument_name ⇒ Object (readonly)
Returns the value of attribute instrument_name.
11 12 13 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 11 def instrument_name @instrument_name end |
#name_key ⇒ Object (readonly) Originally defined in module Named
Returns the value of attribute name_key.
Class Method Details
.fetch_or_create(rhythmic_value, instrument_name) ⇒ Object (private)
27 28 29 30 31 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 27 def self.fetch_or_create(rhythmic_value, instrument_name) @unpitched_notes ||= {} hash_key = [rhythmic_value.to_s, instrument_name].compact.join("_") @unpitched_notes[hash_key] ||= new(rhythmic_value, instrument_name) end |
.get(rhythmic_value, instrument: nil) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 18 def self.get(rhythmic_value, instrument: nil) return rhythmic_value if rhythmic_value.is_a?(HeadMusic::Rudiment::UnpitchedNote) rhythmic_value = HeadMusic::Rudiment::RhythmicValue.get(rhythmic_value) return nil unless rhythmic_value fetch_or_create(rhythmic_value, instrument) end |
Instance Method Details
#==(other) ⇒ Object Originally defined in module ValueEquality
#ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) ⇒ Object Originally defined in module Named
#localized_name(locale_code: Locale::DEFAULT_CODE) ⇒ Object Originally defined in module Named
#localized_name_in_default_locale ⇒ Object (private) Originally defined in module Named
#localized_name_in_locale_matching_language(locale) ⇒ Object (private) Originally defined in module Named
#localized_name_in_matching_locale(locale) ⇒ Object (private) Originally defined in module Named
#localized_names ⇒ Object Originally defined in module Named
Returns an array of LocalizedName instances that are synonymous with the name.
#name ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 38 def name if instrument_name "#{rhythmic_value} #{instrument_name}" else "#{rhythmic_value} unpitched note" end end |
#name=(name) ⇒ Object Originally defined in module Named
#sounded? ⇒ Boolean
56 57 58 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 56 def sounded? true end |
#with_instrument(new_instrument_name) ⇒ Object
Create a new unpitched note with a different instrument
52 53 54 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 52 def with_instrument(new_instrument_name) self.class.get(rhythmic_value, instrument: new_instrument_name) end |
#with_rhythmic_value(new_rhythmic_value) ⇒ Object
Override with_rhythmic_value to preserve instrument
47 48 49 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 47 def with_rhythmic_value(new_rhythmic_value) self.class.get(new_rhythmic_value, instrument: instrument_name) end |