|
1 | | -import Foundation |
2 | | - |
3 | 1 | class ScaleGenerator { |
4 | | - let flatTones = ["Ab", "A", "Bb", "B", "C", "Db", "D", "Eb", "E" ,"F", "Gb", "G"] |
5 | | - let sharpTones = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F" ,"F#", "G", "G#"] |
6 | | - let sharpTonesTypes = ["G", "D", "A","a", "E", "B","F#", "f#","e", "b", "c♯", "g♯", "d♯", "C"] |
7 | | - let translator = ["A": 3, "M": 2, "m": 1] |
8 | | - var tones: [String] = [] |
9 | | - |
10 | | - init (tonic: String) { |
11 | | - if sharpTonesTypes.contains(tonic) { |
12 | | - let tonic = tonic.capitalized |
13 | | - let index = sharpTones.firstIndex(of: tonic)! |
14 | | - self.tones = Array(sharpTones[index...] + sharpTones[...index]) |
15 | | - }else { |
16 | | - let tonic = tonic.capitalized |
17 | | - let index = flatTones.firstIndex(of: tonic)! |
18 | | - self.tones = Array(flatTones[index...] + flatTones[...index]) |
19 | | - } |
20 | | - } |
21 | | - |
22 | | - func chromatic() -> [String] { |
23 | | - return Array(tones[0...(tones.count - 2)]) |
24 | | - } |
25 | | - |
26 | | - func interval(_ intervals : String) -> [String] { |
27 | | - var steps : [Int] = [0] |
28 | | - for char in intervals { |
29 | | - steps.append(steps.last! + translator[String(char)]!) |
30 | | - } |
31 | | - var result : [String] = [] |
32 | | - for step in steps[0...(steps.count - 2)] { |
33 | | - result.append(tones[step]) |
34 | | - } |
35 | | - result.append(tones[0]) |
36 | | - return result |
37 | | - } |
| 2 | + // Write your code for the 'ScaleGenerator' exercise in this file. |
38 | 3 | } |
0 commit comments