@@ -25,6 +25,7 @@ const soundsDir string = "sounds"
25
25
26
26
var hkey = hotkey .New ()
27
27
var ctrl = & beep.Ctrl {}
28
+ var quit = make (chan bool )
28
29
29
30
func main () {
30
31
rand .Seed (time .Now ().Unix ())
@@ -38,10 +39,14 @@ func main() {
38
39
}
39
40
}()
40
41
41
- err := configureShortcuts ()
42
- if err != nil {
43
- log .Fatal ("Could not configure shortcuts:" , err .Error ())
44
- }
42
+ go func () {
43
+ err := configureShortcuts ()
44
+ if err != nil {
45
+ log .Fatal ("Could not configure shortcuts:" , err .Error ())
46
+ }
47
+ }()
48
+
49
+ <- quit // Keep the program alive until we kill it with a keyboard shortcut
45
50
}
46
51
47
52
func readConfigFile () {
@@ -102,7 +107,8 @@ func generateTwitchHelp(user string, allSoundDirectories []string) string {
102
107
}
103
108
104
109
func notify () {
105
- playSfx (soundsDir + "/chat-notification.ogg" )
110
+ // TODO: Make this play over top other sound effects
111
+ // playSfx(soundsDir + "/chat-notification.ogg")
106
112
}
107
113
108
114
func executeTwitchMessage (message twitch.PrivateMessage , allSoundDirectories []string ) bool {
@@ -122,8 +128,6 @@ func executeTwitchMessage(message twitch.PrivateMessage, allSoundDirectories []s
122
128
}
123
129
124
130
func configureShortcuts () error {
125
- quit := make (chan bool )
126
-
127
131
fmt .Println ("Push Shift+Alt+Q to quit" )
128
132
hkey .Register (hotkey .Shift + hotkey .Alt , 'Q' , func () {
129
133
fmt .Println ("Quit" )
@@ -139,8 +143,6 @@ func configureShortcuts() error {
139
143
return err
140
144
}
141
145
142
- <- quit // Keep the program alive until we kill it with a keyboard shortcut
143
-
144
146
return nil
145
147
}
146
148
@@ -174,24 +176,28 @@ func randomSfx(directory string) func() {
174
176
}
175
177
176
178
func playSfx (path string ) error {
177
- streamer , format , err := decodeFile (path )
178
- if err != nil {
179
- return err
180
- }
181
- defer streamer .Close ()
179
+ // TODO: Figure out a cleaner way to stop a sound effect and play another (this Goroutine is dirty)
180
+ go func () error {
181
+ streamer , format , err := decodeFile (path )
182
+ if err != nil {
183
+ return err
184
+ }
185
+ defer streamer .Close ()
182
186
183
- sr := format .SampleRate * 2
184
- speaker .Init (sr , sr .N (time .Second / 10 ))
187
+ sr := format .SampleRate * 2
188
+ speaker .Init (sr , sr .N (time .Second / 10 ))
185
189
186
- resampled := beep .Resample (4 , format .SampleRate , sr , streamer )
190
+ resampled := beep .Resample (4 , format .SampleRate , sr , streamer )
187
191
188
- log .Println ("Playing " + path )
192
+ log .Println ("Playing " + path )
189
193
190
- done := make (chan bool )
191
- ctrl = & beep.Ctrl {Streamer : beep .Seq (resampled , beep .Callback (func () { done <- true })), Paused : false }
192
- speaker .Play (ctrl )
194
+ done := make (chan bool )
195
+ speaker .Play (beep .Seq (resampled , beep .Callback (func () { done <- true })))
193
196
194
- <- done // Block until the sound file is done playing
197
+ <- done // Block until the sound file is done playing
198
+
199
+ return nil
200
+ }()
195
201
196
202
return nil
197
203
}
0 commit comments