Class: Musa::Scales::NoteInScale
- Inherits:
-
Object
- Object
- Musa::Scales::NoteInScale
- Defined in:
- lib/musa-dsl/music/scales.rb
Instance Attribute Summary collapse
-
#background_scale ⇒ Object
readonly
Returns the value of attribute background_scale.
-
#background_sharps ⇒ Object
readonly
Returns the value of attribute background_sharps.
-
#grade ⇒ Object
readonly
Returns the value of attribute grade.
-
#pitch ⇒ Object
readonly
Returns the value of attribute pitch.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #background_note ⇒ Object
- #chord(*feature_values, allow_chromatic: nil, move: nil, duplicate: nil, **features_hash) ⇒ Object
- #down(interval_name_or_interval, natural_or_chromatic = nil) ⇒ Object
- #flat(count = nil) ⇒ Object
- #frequency ⇒ Object
- #functions ⇒ Object
-
#initialize(scale, grade, octave, pitch, background_scale: nil, background_grade: nil, background_octave: nil, background_sharps: nil) ⇒ NoteInScale
constructor
A new instance of NoteInScale.
- #inspect ⇒ Object (also: #to_s)
- #octave(octave = nil, absolute: false) ⇒ Object
- #on(scale) ⇒ Object
- #scale(kind_id_or_kind = nil) ⇒ Object
- #sharp(count = nil) ⇒ Object
- #up(interval_name_or_interval, natural_or_chromatic = nil, sign: nil) ⇒ Object
- #wide_grade ⇒ Object
- #with_background(scale:, grade: nil, octave: nil, sharps: nil) ⇒ Object
Constructor Details
#initialize(scale, grade, octave, pitch, background_scale: nil, background_grade: nil, background_octave: nil, background_sharps: nil) ⇒ NoteInScale
Returns a new instance of NoteInScale.
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
# File 'lib/musa-dsl/music/scales.rb', line 434 def initialize(scale, grade, octave, pitch, background_scale: nil, background_grade: nil, background_octave: nil, background_sharps: nil) @scale = scale @grade = grade @octave = octave @pitch = pitch @background_scale = background_scale @background_grade = background_grade @background_octave = background_octave @background_sharps = background_sharps @scale.kind.tuning.scale_system.scale_kind_classes.each_key do |name| define_singleton_method name do scale(name) end end end |
Instance Attribute Details
#background_scale ⇒ Object (readonly)
Returns the value of attribute background_scale.
476 477 478 |
# File 'lib/musa-dsl/music/scales.rb', line 476 def background_scale @background_scale end |
#background_sharps ⇒ Object (readonly)
Returns the value of attribute background_sharps.
482 483 484 |
# File 'lib/musa-dsl/music/scales.rb', line 482 def background_sharps @background_sharps end |
#grade ⇒ Object (readonly)
Returns the value of attribute grade.
452 453 454 |
# File 'lib/musa-dsl/music/scales.rb', line 452 def grade @grade end |
#pitch ⇒ Object (readonly)
Returns the value of attribute pitch.
452 453 454 |
# File 'lib/musa-dsl/music/scales.rb', line 452 def pitch @pitch end |
Instance Method Details
#==(other) ⇒ Object
578 579 580 581 582 583 584 |
# File 'lib/musa-dsl/music/scales.rb', line 578 def ==(other) self.class == other.class && @scale == other.scale && @grade == other.grade && @octave == other.octave && @pitch == other.pitch end |
#background_note ⇒ Object
478 479 480 |
# File 'lib/musa-dsl/music/scales.rb', line 478 def background_note @background_scale[@background_grade + (@background_octave || 0) * @background_scale.kind.class.grades] if @background_grade end |
#chord(*feature_values, allow_chromatic: nil, move: nil, duplicate: nil, **features_hash) ⇒ Object
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/musa-dsl/music/scales.rb', line 562 def chord(*feature_values, allow_chromatic: nil, move: nil, duplicate: nil, **features_hash) features = { size: :triad } if feature_values.empty? && features_hash.empty? features ||= Musa::Chords::ChordDefinition.features_from(feature_values, features_hash) Musa::Chords::Chord.with_root(self, allow_chromatic: allow_chromatic, move: move, duplicate: duplicate, **features) end |
#down(interval_name_or_interval, natural_or_chromatic = nil) ⇒ Object
528 529 530 |
# File 'lib/musa-dsl/music/scales.rb', line 528 def down(interval_name_or_interval, natural_or_chromatic = nil) up(interval_name_or_interval, natural_or_chromatic, sign: -1) end |
#flat(count = nil) ⇒ Object
537 538 539 540 |
# File 'lib/musa-dsl/music/scales.rb', line 537 def flat(count = nil) count ||= 1 sharp(-count) end |
#frequency ⇒ Object
542 543 544 |
# File 'lib/musa-dsl/music/scales.rb', line 542 def frequency @scale.kind.tuning.frequency_of_pitch(@pitch, @scale.root) end |
#functions ⇒ Object
454 455 456 |
# File 'lib/musa-dsl/music/scales.rb', line 454 def functions @scale.kind.class.pitches[grade][:functions] end |
#inspect ⇒ Object Also known as: to_s
586 587 588 |
# File 'lib/musa-dsl/music/scales.rb', line 586 def inspect "<NoteInScale: grade = #{@grade} octave = #{@octave} pitch = #{@pitch} scale = (#{@scale.kind.class.name} on #{scale.root_pitch})>" end |
#octave(octave = nil, absolute: false) ⇒ Object
458 459 460 461 462 463 464 465 466 |
# File 'lib/musa-dsl/music/scales.rb', line 458 def octave(octave = nil, absolute: false) if octave.nil? @octave else raise ArgumentError, "#{octave} is not integer" unless octave == octave.to_i @scale[@grade + ((absolute ? 0 : @octave) + octave) * @scale.kind.class.grades] end end |
#on(scale) ⇒ Object
558 559 560 |
# File 'lib/musa-dsl/music/scales.rb', line 558 def on(scale) scale.note_of_pitch @pitch end |
#scale(kind_id_or_kind = nil) ⇒ Object
546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/musa-dsl/music/scales.rb', line 546 def scale(kind_id_or_kind = nil) if kind_id_or_kind.nil? @scale else if kind_id_or_kind.is_a? ScaleKind kind_id_or_kind[@pitch] else @scale.kind.tuning[kind_id_or_kind][@pitch] end end end |
#sharp(count = nil) ⇒ Object
532 533 534 535 |
# File 'lib/musa-dsl/music/scales.rb', line 532 def sharp(count = nil) count ||= 1 calculate_note_of_pitch(@pitch, count) end |
#up(interval_name_or_interval, natural_or_chromatic = nil, sign: nil) ⇒ Object
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/musa-dsl/music/scales.rb', line 488 def up(interval_name_or_interval, natural_or_chromatic = nil, sign: nil) sign ||= 1 if interval_name_or_interval.is_a?(Numeric) natural_or_chromatic ||= :natural else natural_or_chromatic = :chromatic end if natural_or_chromatic == :chromatic interval = if interval_name_or_interval.is_a?(Symbol) @scale.kind.tuning.offset_of_interval(interval_name_or_interval) else interval_name_or_interval end calculate_note_of_pitch(@pitch, sign * interval) else @scale[@grade + sign * interval_name_or_interval] end end |
#wide_grade ⇒ Object
484 485 486 |
# File 'lib/musa-dsl/music/scales.rb', line 484 def wide_grade @grade + @octave * @scale.kind.class.grades end |
#with_background(scale:, grade: nil, octave: nil, sharps: nil) ⇒ Object
468 469 470 471 472 473 474 |
# File 'lib/musa-dsl/music/scales.rb', line 468 def with_background(scale:, grade: nil, octave: nil, sharps: nil) NoteInScale.new(@scale, @grade, @octave, @pitch, background_scale: scale, background_grade: grade, background_octave: octave, background_sharps: sharps) end |