-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (69 loc) · 1.52 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
transpositionMap := map[string]string{
"C": "F",
"C#": "F#",
"D♭": "G♭",
"D": "G",
"D#": "G#",
"E♭": "A♭",
"E": "A",
"F": "B♭",
"F#": "B",
"G♭": "B",
"G": "C",
"G#": "C#",
"A♭": "D♭",
"A": "D",
"A#": "D#",
"B♭": "E♭",
"B": "E",
"C'": "F'",
"C#'": "F#'",
"D♭'": "G♭'",
"D'": "G'",
"D#'": "G#'",
"E♭'": "A♭'",
"E'": "A'",
"F'": "B♭'",
"F#'": "B'",
"G♭'": "B'",
"G'": "C'",
}
fmt.Print("🎼 ")
reader := bufio.NewReader(os.Stdin)
notes, _ := reader.ReadString('\n')
notes = strings.TrimSpace(notes)
notes = strings.ToUpper(notes)
notes = strings.ReplaceAll(notes, "’", "'")
notesArray := strings.Fields(notes)
for i, note := range notesArray {
if len(note) > 1 && note[1] == 'B' {
notesArray[i] = note[:1] + "♭" + note[2:]
}
}
var transposedNotesArray []string
for i, note := range notesArray {
if transposedNote, exists := transpositionMap[note]; exists {
if len(transposedNote) > len(note) {
notesArray[i] += " "
} else if len(transposedNote) < len(note) {
transposedNote += " "
}
transposedNotesArray = append(transposedNotesArray, transposedNote)
} else {
transposedNotesArray = append(transposedNotesArray, note)
}
}
notesNormalized := strings.Join(notesArray, " ")
newNotes := strings.Join(transposedNotesArray, " ")
fmt.Println()
fmt.Println("1: ", notesNormalized)
fmt.Println("2: ", newNotes)
}