Class: Musicality::PitchClass

Inherits:
Object
  • Object
show all
Defined in:
lib/musicality/pitch_class.rb,
lib/musicality/printing/lilypond/pitch_class_engraving.rb

Constant Summary collapse

MOD =

semitones per octave

12

Class Method Summary collapse

Class Method Details

.from_i(i) ⇒ Object



6
7
8
# File 'lib/musicality/pitch_class.rb', line 6

def self.from_i i
  i % MOD
end

.invert(val) ⇒ Object



10
11
12
# File 'lib/musicality/pitch_class.rb', line 10

def self.invert val
  (MOD - val.to_pc).to_pc
end

.to_lilypond(pc, sharpit = false) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/musicality/printing/lilypond/pitch_class_engraving.rb', line 4

def self.to_lilypond pc, sharpit = false
  case pc
  when 0 then "c"
  when 1 then sharpit  ? "cis" : "des"
  when 2 then "d"
  when 3 then sharpit  ? "dis" : "ees"
  when 4 then "e"
  when 5 then "f"
  when 6 then sharpit  ? "fis" : "ges"
  when 7 then "g"
  when 8 then sharpit  ? "gis" : "aes"
  when 9 then "a"
  when 10 then sharpit  ? "ais" : "bes"
  when 11 then "b"
  end
end