Guest User

Untitled

a guest
Nov 17th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. require "Set"
  2. class ModeScale
  3.  
  4. attr_accessor :key, :mode
  5. attr_reader :mode_scale
  6. def initialize(key, mode)
  7. @key, @mode = key, mode
  8. showScale
  9. end
  10.  
  11.  
  12. def to_s
  13. "KEY:#{@key} in #{@mode} \n" +
  14. "Scale: #{@mode_scale.to_a}"
  15. end
  16.  
  17.  
  18. def showScale
  19. scale = ["C","#C/bD","D","#D/bE","E","F","#F/bG","G","#G/bA","A","#A/bB","B"]
  20. @mode_scale= Set.new
  21.  
  22. mode_hash = {
  23. # 1 means a semitone and 2 means two semitone
  24. "Ionian" => [0,2,2,1,2,2,2,1],
  25. "Dorian" => [0,2,1,2,2,2,1,2],
  26. "Phrygian" => [0,1,2,2,2,1,2,2],
  27. "Lydian" => [0,2,2,2,1,2,2,1],
  28. "Mixolydian"=> [0,2,2,1,2,2,1,2],
  29. "Aeolian" => [0,2,1,2,2,1,2,2],
  30. "Locrian" => [0,1,2,2,1,2,2,2]
  31. }
  32. # ==============================
  33. pos = scale.index(key)
  34. for i in (0..7)
  35. pos += (mode_hash[mode]).at(i)
  36. pos %= 12
  37. @mode_scale << scale[pos]
  38. end
  39. # ==============================
  40. end
  41.  
  42.  
  43. end
Add Comment
Please, Sign In to add comment