-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
procmessage.go
107 lines (83 loc) · 2.36 KB
/
procmessage.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
100
101
102
103
104
105
106
107
package main
import (
"fmt"
"strings"
"time"
"github.com/chabad360/go-osc/osc"
)
var (
clipName = ""
directionForward = true
timeLeft string
clipLength float32
posPrev float32
)
func procMsg(data *osc.Message) {
if strings.HasPrefix(data.Address, clipPath) {
switch {
case strings.HasSuffix(data.Address, "/position"):
procPos(data)
case strings.HasSuffix(data.Address, "direction"):
procDirection(data)
case strings.HasSuffix(data.Address, "/name"):
procName(data)
case strings.HasSuffix(data.Address, "/duration"):
procDuration(data)
case strings.HasSuffix(data.Address, "/connect"):
reset()
case strings.Contains(data.Address, "/select"):
reset()
}
}
}
func procDirection(data *osc.Message) {
directionForward = data.Arguments[0].(int32) != 0
if !directionForward {
posPrev = 1 - posPrev
}
}
func procName(data *osc.Message) {
clipName = data.Arguments[0].(string)
clipNameBinding.Set("Clip Name: " + clipName)
broadcast.Publish(osc.NewMessage("/name", clipName))
}
func procDuration(data *osc.Message) {
clipLength = (data.Arguments[0].(float32) * 604800) + 0.001
clipLengthBinding.Set(fmt.Sprintf("Clip Length: %.3fs", clipLength))
broadcast.Publish(osc.NewMessage("/duration", clipLength))
}
func reset() {
lightReset()
posPrev = 0
}
func lightReset() {
message.Address = clipPath + "/name"
message2.Address = clipPath + "/transport/position/behaviour/duration"
if _, err := oscServer.WriteTo(osc.NewBundle(message, message2), OSCAddr+":"+OSCPort); err != nil {
fmt.Println(err)
}
}
func procPos(data *osc.Message) {
pos := data.Arguments[0].(float32)
if !directionForward {
pos = 1 - pos
}
if posPrev == 0 || posPrev == pos || pos < 0.002 {
posPrev = pos
return
}
currentPosInterval := pos - posPrev
if currentPosInterval < 0 && posPrev > 0 {
return
}
posPrev = pos
if clipInvert {
pos = 1 - pos
}
t := (clipLength * 1000) * (1 - pos)
timeActual := time.UnixMilli(int64(t)).UTC()
timeLeft = fmt.Sprintf("-%02d:%02d:%02d.%03d", timeActual.Hour(), timeActual.Minute(), timeActual.Second(), timeActual.Nanosecond()/1000000)
broadcast.Publish(osc.NewMessage("/time", timeLeft, fmt.Sprintf("%.3fs", clipLength)))
broadcast.Send()
//fmt.Println(message, clipLength, samples, pos, currentPosInterval, currentTimeInterval, currentEstSize, posInterval, timeInterval, average(estSizeBuffer))
}