-
Notifications
You must be signed in to change notification settings - Fork 1
/
play.go
99 lines (96 loc) · 2.17 KB
/
play.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
87
88
89
90
91
92
93
94
95
96
97
98
99
package subcmd
import (
"os"
"github.com/but80/smaf825/sequencer"
"github.com/but80/smaf825/serial"
"github.com/but80/smaf825/smaf/chunk"
"github.com/but80/smaf825/smaf/log"
"github.com/urfave/cli"
)
var Play = cli.Command{
Name: "play",
Aliases: []string{"p"},
Usage: "Plays SMAF format files (.mmf|.spf)",
ArgsUsage: "<device> <filename>",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "state, s",
Usage: `Show state`,
},
cli.IntFlag{
Name: "volume, v",
Usage: `Master volume (0..63)`,
Value: 48,
},
cli.IntFlag{
Name: "gain, g",
Usage: `Analog gain (0..3)`,
Value: 1,
},
cli.IntFlag{
Name: "seqvol, V",
Usage: `SeqVol (0..31)`,
Value: 16,
},
cli.IntFlag{
Name: "loop, l",
Usage: `Loop count (0: infinite)`,
Value: 1,
},
cli.IntFlag{
Name: "baudrate, r",
Usage: `Baud rate ` + serial.BaudRateList(),
Value: 57600,
},
cli.BoolFlag{
Name: "debug, d",
Usage: `Show debug messages`,
},
cli.BoolFlag{
Name: "quiet, q",
Usage: `Suppress information messages`,
},
cli.BoolFlag{
Name: "silent, Q",
Usage: `Do not output any messages`,
},
},
Action: func(ctx *cli.Context) error {
if ctx.NArg() < 2 || ctx.Int("loop") < 0 ||
ctx.Int("volume") < 0 || 63 < ctx.Int("volume") ||
ctx.Int("gain") < 0 || 3 < ctx.Int("gain") ||
ctx.Int("seqvol") < 0 || 31 < ctx.Int("seqvol") ||
!serial.IsValidBaudRate(ctx.Int("baudrate")) {
cli.ShowCommandHelp(ctx, "play")
os.Exit(1)
}
if ctx.Bool("debug") {
log.Level = log.LogLevel_Debug
} else if ctx.Bool("silent") {
log.Level = log.LogLevel_None
} else if ctx.Bool("quiet") {
log.Level = log.LogLevel_Warn
}
args := ctx.Args()
mmf, err := chunk.NewFileChunk(args[1])
if err != nil {
return cli.NewExitError(err, 1)
}
q := sequencer.Sequencer{
DeviceName: args[0],
ShowState: ctx.Bool("state"),
}
opts := &sequencer.SequencerOptions{
Loop: ctx.Int("loop"),
Volume: ctx.Int("volume"),
Gain: ctx.Int("gain"),
SeqVol: ctx.Int("seqvol"),
BaudRate: ctx.Int("baudrate"),
}
err = q.Play(mmf, opts)
if err != nil {
return cli.NewExitError(err, 1)
}
return nil
},
}