forked from synthia-synth/synthia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
86 lines (77 loc) · 3.5 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
78
79
80
81
82
83
84
85
86
package main
import (
"fmt"
"flag"
"io/ioutil"
)
//go:generate -command yacc go tool yacc
//go:generate yacc -o lang.go -p "lang" lang.y
const DefaultSampleRate = 44100
var glsampleRate float64 = DefaultSampleRate
func usage(){
fmt.Println("synthia: The synth which goes...")
fmt.Println("Usage: synthia FILE")
}
func main() {
flag.Parse()
args := flag.Args()
if len(args) < 1{
usage()
return
}
path := args[0]
data, err := ioutil.ReadFile(path)
if err != nil {
println(err)
return
}
langParse(&langLex{line: data})
ast.Exec()
tune := ast.Tune()
fmt.Println("Tune Generated. Playing...")
playTune(tune, glsampleRate)
}
func genTwinkle() []*Note {
var song []*Note
song = append(song, NewNote(C, 5, AccidentalNatural, Crotchet, NormalLength))
song = append(song, NewNote(C, 5, AccidentalNatural, Crotchet, NormalLength))
song = append(song, NewNote(G, 5, AccidentalNatural, Crotchet, NormalLength))
song = append(song, NewNote(G, 5, AccidentalNatural, Crotchet, NormalLength))
song = append(song, NewNote(A, 5, AccidentalNatural, Crotchet, NormalLength))
song = append(song, NewNote(A, 5, AccidentalNatural, Crotchet, NormalLength))
song = append(song, NewNote(G, 5, AccidentalNatural, Minim, NormalLength))
song = append(song, NewNote(C, 5, AccidentalNatural, Crotchet, NormalLength))
song = append(song, NewNote(A, 5, AccidentalNatural, Crotchet, NormalLength))
song = append(song, NewNote(G, 5, AccidentalNatural, Crotchet, NormalLength))
song = append(song, NewNote(B, 5, 0.1, Crotchet, NormalLength))
song = append(song, NewNote(B, 5, 0.2, Crotchet, NormalLength))
song = append(song, NewNote(B, 5, 0.3, Crotchet, NormalLength))
song = append(song, NewNote(B, 5, 0.4, Crotchet, NormalLength))
song = append(song, NewNote(B, 5, 0.5, Crotchet, NormalLength))
song = append(song, NewNote(B, 5, 0.6, Crotchet, NormalLength))
song = append(song, NewNote(B, 5, 0.7, Crotchet, NormalLength))
song = append(song, NewNote(B, 5, 0.8, Crotchet, NormalLength))
song = append(song, NewNote(B, 5, 0.9, Crotchet, NormalLength))
song = append(song, NewNote(B, 5, 1.0, Crotchet, NormalLength))
song = append(song, NewNote(B, 5, 1.1, Crotchet, NormalLength))
song = append(song, NewNote(B, 5, 1.2, Crotchet, NormalLength))
return song
}
func genFast() []*Note {
var song []*Note
song = append(song, NewNote(C, 5, AccidentalNatural, HemiDemiSemiQuaver, NormalLength))
song = append(song, NewNote(A, 5, AccidentalNatural, HemiDemiSemiQuaver, NormalLength))
song = append(song, NewNote(G, 5, AccidentalNatural, HemiDemiSemiQuaver, NormalLength))
song = append(song, NewNote(B, 5, AccidentalNatural, HemiDemiSemiQuaver, NormalLength))
song = append(song, NewNote(A, 5, AccidentalNatural, HemiDemiSemiQuaver, NormalLength))
song = append(song, NewNote(C, 5, AccidentalNatural, HemiDemiSemiQuaver, NormalLength))
song = append(song, NewNote(G, 5, AccidentalNatural, HemiDemiSemiQuaver, NormalLength))
song = append(song, NewNote(C, 5, AccidentalNatural, HemiDemiSemiQuaver, NormalLength))
song = append(song, NewNote(A, 5, AccidentalNatural, HemiDemiSemiQuaver, NormalLength))
song = append(song, NewNote(G, 5, AccidentalNatural, HemiDemiSemiQuaver, NormalLength))
song = append(song, NewNote(B, 5, AccidentalNatural, HemiDemiSemiQuaver, NormalLength))
song = append(song, NewNote(A, 5, AccidentalNatural, HemiDemiSemiQuaver, NormalLength))
song = append(song, NewNote(C, 5, AccidentalNatural, HemiDemiSemiQuaver, NormalLength))
song = append(song, NewNote(G, 5, AccidentalNatural, HemiDemiSemiQuaver, NormalLength))
return song
}