/
TextSendOSC.go
54 lines (46 loc) · 1016 Bytes
/
TextSendOSC.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
package main
import (
"os"
"flag"
"strings"
"encoding/json"
"io/ioutil"
"golang.org/x/text/transform"
"golang.org/x/text/encoding/japanese"
"github.com/hypebeast/go-osc/osc"
)
type Config struct {
Host string `json:"host"`
Port int `json:"port"`
Address string `json:"address"`
IsYukariNet bool `json:"isYukariNet"`
}
func main() {
_conf, err := ioutil.ReadFile("config.json")
if err != nil {
panic(err)
}
var config Config
json.Unmarshal(_conf, &config)
flag.Parse()
str := strings.Join(flag.Args(), " ")
SendOSC(config, str)
if(config.IsYukariNet){
os.Stdout.WriteString(ConvertShiftJIS(str))
} else {
os.Stdout.WriteString(str)
}
}
func SendOSC(config Config, str string) {
client := osc.NewClient(config.Host, config.Port)
msg := osc.NewMessage(config.Address)
msg.Append(str)
client.Send(msg)
}
func ConvertShiftJIS(str string) (string) {
result, _, err := transform.String(japanese.ShiftJIS.NewEncoder(), str)
if err != nil {
panic(err)
}
return result
}