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.
469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/musa-dsl/music/scales.rb', line 469 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.
500 501 502 |
# File 'lib/musa-dsl/music/scales.rb', line 500 def a_frequency @a_frequency end |
#scale_system ⇒ Class<ScaleSystem> (readonly)
The parent scale system.
504 505 506 |
# File 'lib/musa-dsl/music/scales.rb', line 504 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.
684 685 686 687 688 |
# File 'lib/musa-dsl/music/scales.rb', line 684 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.
536 537 538 |
# File 'lib/musa-dsl/music/scales.rb', line 536 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.
554 555 556 |
# File 'lib/musa-dsl/music/scales.rb', line 554 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.
519 520 521 |
# File 'lib/musa-dsl/music/scales.rb', line 519 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.
693 694 695 |
# File 'lib/musa-dsl/music/scales.rb', line 693 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 485
|
#offset_of_interval(name) ⇒ Integer
Returns semitone offset for a named interval. Delegated from Musa::Scales::ScaleSystem.offset_of_interval.
496 |
# File 'lib/musa-dsl/music/scales.rb', line 496 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.
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
# File 'lib/musa-dsl/music/scales.rb', line 587 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.
627 628 629 630 631 632 633 634 |
# File 'lib/musa-dsl/music/scales.rb', line 627 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 |