Module: Key

Extended by:
Key
Included in:
Key
Defined in:
lib/kuromusic/Key.rb

Defined Under Namespace

Modules: A, B, C, D, E, F, G

Instance Method Summary collapse

Instance Method Details

#degree_to_key(number) ⇒ Object



58
59
60
61
62
# File 'lib/kuromusic/Key.rb', line 58

def degree_to_key(number)
  {
    0=>"C", 1=>"C#", 2=>"D", 3=>"D#", 4=>"E", 5=>"F", 6=>"F#", 7=>"G", 8=>"G#", 9=>"A", 10=>"A#", 11=>"B"
  }[number % 12]
end

#key_to_degree(key) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/kuromusic/Key.rb', line 38

def key_to_degree(key)
  {
    #positive
    Key::C::NATURAL => 0, Key::B::SHARP => 0,
    Key::C::SHARP => 1, Key::D::FLAT => 1,
    Key::D::NATURAL => 2,
    Key::D::SHARP => 3, Key::E::FLAT => 3,
    Key::E::NATURAL => 4, Key::F::FLAT => 4,
    Key::E::SHARP => 5, Key::F::NATURAL => 5,

    #negative
    Key::C::FLAT => -1, Key::B::NATURAL => -1,
    Key::A::SHARP => -2, Key::B::FLAT => -2,
    Key::A::NATURAL => -3,
    Key::A::FLAT => -4, Key::G::SHARP => -4,
    Key::G::NATURAL => -5,
    Key::G::FLAT => -6, Key::F::SHARP => -6
  }[key]
end