Class: HeadMusic::Rudiment::UnpitchedNote
- Inherits:
-
RhythmicElement
- Object
- Base
- RhythmicElement
- HeadMusic::Rudiment::UnpitchedNote
- Includes:
- Named
- 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.
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
- #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.
29 30 31 32 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 29 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.
9 10 11 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 9 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)
23 24 25 26 27 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 23 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
14 15 16 17 18 19 20 21 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 14 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
52 53 54 55 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 52 def ==(other) return false unless other.is_a?(self.class) rhythmic_value == other.rhythmic_value && instrument_name == other.instrument_name end |
#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
34 35 36 37 38 39 40 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 34 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
57 58 59 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 57 def sounded? true end |
#with_instrument(new_instrument_name) ⇒ Object
Create a new unpitched note with a different instrument
48 49 50 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 48 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
43 44 45 |
# File 'lib/head_music/rudiment/unpitched_note.rb', line 43 def with_rhythmic_value(new_rhythmic_value) self.class.get(new_rhythmic_value, instrument: instrument_name) end |