-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
72 lines (56 loc) · 1.31 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
package main
import (
"flag"
"fmt"
drum "github.com/kellydunn/go-challenge-1"
sequencer "github.com/kellydunn/go-step-sequencer/sequencer"
"time"
)
// Entry point for go-step-sequencer
// Parses command line flags, which can be either:
// - --pattern A filepath for the splice pattern on the filesystem.
// - --kit A directory that contains all the samples for the tracks contained in the pattern.
func main() {
var patternPath string
var kitPath string
flag.StringVar(
&patternPath,
"pattern",
"patterns/pattern_1.splice",
"-pattern=path/to/pattern.splice",
)
flag.StringVar(
&kitPath,
"kit",
"kits",
"-kit=path/to/kits",
)
flag.Parse()
pattern, err := drum.DecodeFile(patternPath)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
for _, track := range pattern.Tracks {
filepath := kitPath + "/" + pattern.Version + "/" + track.Name + ".wav"
track.Buffer, err = sequencer.LoadSample(filepath)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
track.Playhead = len(track.Buffer)
fmt.Printf("loaded sample: %s\n", filepath)
}
fmt.Printf("%s\n", pattern)
s, err := sequencer.NewSequencer()
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
s.Pattern = pattern
s.Timer.SetTempo(s.Pattern.Tempo)
s.Start()
for {
time.Sleep(time.Second)
}
}