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 ⇒ Float
readonly
Reference A frequency in Hz.
-
#scale_system ⇒ Class<ScaleSystem>
readonly
The parent scale system.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Checks tuning equality.
-
#chromatic ⇒ ScaleKind
Returns the chromatic scale kind.
-
#frequency_of_pitch(pitch, root) ⇒ Float
Calculates frequency for a MIDI pitch.
-
#get(scale_kind_class_id) ⇒ ScaleKind
(also: #[])
Retrieves a scale kind by ID.
-
#initialize(scale_system, a_frequency) ⇒ ScaleSystemTuning
constructor
private
Creates a tuning instance for a scale system.
-
#inspect ⇒ String
(also: #to_s)
Returns string representation.
-
#notes_in_octave ⇒ Integer
Returns the number of notes in one octave.
-
#offset_of_interval(name) ⇒ Integer
Returns semitone offset for a named interval.
-
#scale_kinds(**metadata_criteria) {|kind_class| ... } ⇒ Array<ScaleKind>
Returns scale kinds matching the given metadata criteria.
-
#search_chord_in_scales(chord, roots: nil, **metadata_criteria) ⇒ Array<Musa::Chords::Chord>
Searches for a chord across multiple scale types.
Constructor Details
#initialize(scale_system, a_frequency) ⇒ ScaleSystemTuning
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a tuning instance for a scale system.
510 511 512 513 514 515 516 517 518 519 520 521 522 |
# File 'lib/musa-dsl/music/scales.rb', line 510 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 ⇒ Float (readonly)
Reference A frequency in Hz.
541 542 543 |
# File 'lib/musa-dsl/music/scales.rb', line 541 def a_frequency @a_frequency end |
#scale_system ⇒ Class<ScaleSystem> (readonly)
The parent scale system.
545 546 547 |
# File 'lib/musa-dsl/music/scales.rb', line 545 def scale_system @scale_system end |
Instance Method Details
#==(other) ⇒ Boolean
Checks tuning equality.
Tunings are equal if they have the same scale system and A frequency.
725 726 727 728 729 |
# File 'lib/musa-dsl/music/scales.rb', line 725 def ==(other) self.class == other.class && @scale_system == other.scale_system && @a_frequency == other.a_frequency end |
#chromatic ⇒ ScaleKind
Returns the chromatic scale kind.
Provides access to the chromatic scale, which contains all pitches in the scale system. Used as fallback for non-diatonic notes.
577 578 579 |
# File 'lib/musa-dsl/music/scales.rb', line 577 def chromatic @chromatic_scale_kind end |
#frequency_of_pitch(pitch, root) ⇒ Float
Calculates frequency for a MIDI pitch.
Delegates to the scale system's frequency calculation using this tuning's A frequency as reference.
595 596 597 |
# File 'lib/musa-dsl/music/scales.rb', line 595 def frequency_of_pitch(pitch, root) @scale_system.frequency_of_pitch(pitch, root, @a_frequency) end |
#get(scale_kind_class_id) ⇒ ScaleKind Also known as: []
Retrieves a scale kind by ID.
Creates and caches Musa::Scales::ScaleKind instances for efficient reuse.
560 561 562 |
# File 'lib/musa-dsl/music/scales.rb', line 560 def get(scale_kind_class_id) @scale_kinds[scale_kind_class_id] ||= @scale_system.scale_kind_class(scale_kind_class_id).new self end |
#inspect ⇒ String Also known as: to_s
Returns string representation.
734 735 736 |
# File 'lib/musa-dsl/music/scales.rb', line 734 def inspect "<ScaleSystemTuning: scale_system = #{@scale_system} a_frequency = #{@a_frequency}>" end |
#notes_in_octave ⇒ Integer
Returns the number of notes in one octave. Delegated from Musa::Scales::ScaleSystem.notes_in_octave.
|
|
# File 'lib/musa-dsl/music/scales.rb', line 526
|
#offset_of_interval(name) ⇒ Integer
Returns semitone offset for a named interval. Delegated from Musa::Scales::ScaleSystem.offset_of_interval.
537 |
# File 'lib/musa-dsl/music/scales.rb', line 537 def_delegators :@scale_system, :notes_in_octave, :offset_of_interval |
#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.
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 |
# File 'lib/musa-dsl/music/scales.rb', line 628 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 |
#search_chord_in_scales(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.
668 669 670 671 672 673 674 675 |
# File 'lib/musa-dsl/music/scales.rb', line 668 def search_chord_in_scales(chord, roots: nil, **) roots ||= 0...notes_in_octave kinds = filtered_scale_kind_ids(**) kinds.flat_map do |kind_id| self[kind_id].find_chord_in_scales(chord, roots: roots) end end |