Skip to content

Commit 4d77bed

Browse files
committed
channel 12 for musicstar. fix up volume code
1 parent b95b4c7 commit 4d77bed

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

internal/client/client.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,17 @@ func sendNotesClient(wg *sync.WaitGroup, closedChan chan struct{}, conn net.Conn
164164
var t *timer.Timer
165165
if !dontControlVolume {
166166
t = &timer.Timer{}
167-
timeout := t.New(10) // 10 seconds
167+
timeout := t.New(5)
168168
t.Start()
169169

170170
go func() {
171-
// reset the volume on the timeout
172-
for range timeout {
171+
for {
172+
<-timeout
173173
go volume.SetVolume(common.HIGH_VOLUME)
174174
// make a new timer and overwrite the channel
175175
t = &timer.Timer{}
176-
timeout = t.New(10) // 10 seconds
176+
timeout = t.New(5)
177+
t.Start()
177178
}
178179
}()
179180
}
@@ -189,11 +190,6 @@ func sendNotesClient(wg *sync.WaitGroup, closedChan chan struct{}, conn net.Conn
189190
continue
190191
}
191192

192-
if !dontControlVolume {
193-
go volume.SetVolume(common.LOW_VOLUME)
194-
t.Reset()
195-
}
196-
197193
go func() {
198194
if delay > 0 {
199195
time.Sleep(time.Duration(delay) * time.Millisecond)
@@ -217,6 +213,11 @@ func sendNotesClient(wg *sync.WaitGroup, closedChan chan struct{}, conn net.Conn
217213
notesChan <- msg
218214
reconnect = true
219215
}
216+
if !dontControlVolume {
217+
go volume.SetVolume(common.LOW_VOLUME)
218+
t.Reset()
219+
}
220+
220221
}
221222
case channel.NoteOff:
222223
channel := channels.CheckChannel(v.Channel(), csvRecords)

pkg/timer/timer.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,45 @@ type Timer struct {
1010
secondsLeft int64
1111
resetChan chan struct{}
1212
doneChan chan struct{}
13+
internalDoneChan chan struct{}
1314
}
1415

1516
func (t *Timer) New(seconds int64) chan struct{} {
1617
t.requestedSeconds = seconds
1718
t.secondsLeft = seconds
18-
t.resetChan = make(chan struct{}, 10) // don't block on a reset message if we're sleeping
19+
t.resetChan = make(chan struct{})
1920
t.doneChan = make(chan struct{})
2021
return t.doneChan
2122
}
2223

2324
func (t *Timer) Start() {
2425
go func() {
2526
for {
26-
select {
27-
// see if a reset is requested
28-
case <-t.resetChan:
29-
// reset the timer
30-
t.secondsLeft = t.requestedSeconds
31-
default:
32-
}
3327

3428
if t.secondsLeft <= 0 {
3529
t.doneChan <- struct{}{}
30+
t.internalDoneChan <- struct{}{}
3631
return
3732
}
38-
3933
// Sleep and subtract a second
4034
time.Sleep(1 * time.Second)
4135
t.secondsLeft -= 1
4236
}
4337
}()
38+
39+
go func() {
40+
for {
41+
// see if a reset is requested
42+
select {
43+
case <-t.resetChan:
44+
// reset the timer
45+
t.secondsLeft = t.requestedSeconds
46+
case <-t.internalDoneChan:
47+
return
48+
}
49+
}
50+
}()
51+
4452
}
4553

4654
func (t *Timer) Reset() {

profiles/wosp/channels.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
9,0,0
1111
10,0,0
1212
11,0,0
13-
12,0,0
13+
12,12,0
1414
13,0,0
1515
14,0,0
1616
15,3,-12

0 commit comments

Comments
 (0)