Class: Musa::Scales::ScaleSystemTuning

Inherits:
Object
  • Object
show all
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
baroque = 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

Examples:

Standard usage

tuning = Scales::Scales.default_system.default_tuning
c_major = tuning.major[60]
a_minor = tuning.minor[69]

Historical pitch

baroque = Scales[:et12][415.0]
scale = baroque.major[60]  # C major at A=415Hz

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

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_frequencyObject (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_systemObject (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.

Examples:

Search G7 in greek mode scales

tuning = Scales.et12[440.0]
g7 = tuning.major[60].dominant.chord :seventh
tuning.chords_of(g7, family: :greek_modes)

Search with brightness filter

tuning.chords_of(g7, brightness: -1..1)

Search in all scale types

tuning.chords_of(g7)

See Also:



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

#chromaticObject



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

#inspectObject 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.

Examples:

All scale kinds

tuning.scale_kinds
# => [major_kind, minor_kind, dorian_kind, ...]

Filter by metadata

tuning.scale_kinds(family: :diatonic)
tuning.scale_kinds(brightness: -1..1)
tuning.scale_kinds(character: :jazz)

Filter with block

tuning.scale_kinds { |klass| klass.[:has_leading_tone] }

Combined

tuning.scale_kinds(family: :greek_modes) { |klass| klass.[:brightness] < 0 }

Yields:

  • (kind_class)

    optional block for custom filtering

Yield Parameters:

  • kind_class (Class)

    the ScaleKind subclass

Yield Returns:

  • (Boolean)

    true to include this scale kind

See Also:



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|
      matches_metadata?(kind.class, )
    end
  end

  if block
    result = result.select { |kind| block.call(kind.class) }
  end

  result
end