Class: Musa::Scales::ScaleSystemTuning
- Extended by:
- Forwardable
- Defined in:
- lib/musa-dsl/music/scales.rb
Overview
Scale system with specific A frequency tuning.
ScaleSystemTuning combines a ScaleSystem with a specific reference A frequency, providing access to scale kinds (major, minor, chromatic, etc.) tuned to that frequency.
Usage
Tunings are created via Musa::Scales::ScaleSystem.[]:
tuning = Scales[:et12][440.0] # Standard pitch
= Scales[:et12][415.0] # Baroque pitch
Accessing Scales
By symbol:
tuning[:major][60] # C major scale
By method name:
tuning.major[60] # C major scale
tuning.minor[69] # A minor scale
Chromatic scale:
tuning.chromatic[60] # C chromatic scale
Instance Attribute Summary collapse
-
#a_frequency ⇒ Object
readonly
Returns the value of attribute a_frequency.
-
#scale_system ⇒ Object
readonly
Returns the value of attribute scale_system.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](scale_kind_class_id) ⇒ Object
-
#chords_of(chord, roots: nil, **metadata_criteria) ⇒ Array<Musa::Chords::Chord>
Searches for a chord across multiple scale types.
- #chromatic ⇒ Object
- #frequency_of_pitch(pitch, root) ⇒ Object
-
#initialize(scale_system, a_frequency) ⇒ ScaleSystemTuning
constructor
A new instance of ScaleSystemTuning.
- #inspect ⇒ Object (also: #to_s)
-
#scale_kinds(**metadata_criteria) {|kind_class| ... } ⇒ Array<ScaleKind>
Returns scale kinds matching the given metadata criteria.
Constructor Details
#initialize(scale_system, a_frequency) ⇒ ScaleSystemTuning
455 456 457 458 459 460 461 462 463 464 465 466 467 |
# File 'lib/musa-dsl/music/scales.rb', line 455 def initialize(scale_system, a_frequency) @scale_system = scale_system @a_frequency = a_frequency @scale_kinds = {} @chromatic_scale_kind = self[@scale_system.chromatic_class.id] @scale_system.scale_kind_classes.each_key do |name| define_singleton_method name do self[name] end end end |
Instance Attribute Details
#a_frequency ⇒ Object (readonly)
Returns the value of attribute a_frequency.
473 474 475 |
# File 'lib/musa-dsl/music/scales.rb', line 473 def a_frequency @a_frequency end |
#scale_system ⇒ Object (readonly)
Returns the value of attribute scale_system.
473 474 475 |
# File 'lib/musa-dsl/music/scales.rb', line 473 def scale_system @scale_system end |
Instance Method Details
#==(other) ⇒ Object
594 595 596 597 598 |
# File 'lib/musa-dsl/music/scales.rb', line 594 def ==(other) self.class == other.class && @scale_system == other.scale_system && @a_frequency == other.a_frequency end |
#[](scale_kind_class_id) ⇒ Object
475 476 477 |
# File 'lib/musa-dsl/music/scales.rb', line 475 def [](scale_kind_class_id) @scale_kinds[scale_kind_class_id] ||= @scale_system.scale_kind_class(scale_kind_class_id).new self end |
#chords_of(chord, roots: nil, **metadata_criteria) ⇒ Array<Musa::Chords::Chord>
Searches for a chord across multiple scale types.
Iterates through the specified scale kinds and pitch roots to find all scales that contain the given chord. Returns chords with their containing scale as context.
556 557 558 559 560 561 562 563 |
# File 'lib/musa-dsl/music/scales.rb', line 556 def chords_of(chord, roots: nil, **) roots ||= 0...notes_in_octave kinds = filtered_scale_kind_ids(**) kinds.flat_map do |kind_id| self[kind_id].scales_containing(chord, roots: roots) end end |
#chromatic ⇒ Object
479 480 481 |
# File 'lib/musa-dsl/music/scales.rb', line 479 def chromatic @chromatic_scale_kind end |
#frequency_of_pitch(pitch, root) ⇒ Object
483 484 485 |
# File 'lib/musa-dsl/music/scales.rb', line 483 def frequency_of_pitch(pitch, root) @scale_system.frequency_of_pitch(pitch, root, @a_frequency) end |
#inspect ⇒ Object Also known as: to_s
600 601 602 |
# File 'lib/musa-dsl/music/scales.rb', line 600 def inspect "<ScaleSystemTuning: scale_system = #{@scale_system} a_frequency = #{@a_frequency}>" end |
#scale_kinds(**metadata_criteria) {|kind_class| ... } ⇒ Array<ScaleKind>
Returns scale kinds matching the given metadata criteria.
Without arguments, returns all registered scale kinds. With keyword arguments, filters by metadata values. With a block, filters using custom predicate on ScaleKind class.
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
# File 'lib/musa-dsl/music/scales.rb', line 516 def scale_kinds(**, &block) result = @scale_system.scale_kind_classes.keys.map { |id| self[id] } unless .empty? result = result.select do |kind| (kind.class, ) end end if block result = result.select { |kind| block.call(kind.class) } end result end |