-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.go
77 lines (62 loc) · 1.62 KB
/
init.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
package audacity
import (
"fmt"
"io"
"os"
"runtime"
"time"
winio "github.com/Microsoft/go-winio"
)
var (
toPipe io.WriteCloser
fromPipe io.ReadCloser
eol string
)
func initPipes() (err error) {
errFormat := "dialing %s pipe failed: %s\nPossible solution: Ensure Audacity is running with mod-script-pipe, see: https://manual.audacityteam.org/man/scripting.html#Enable_mod-script-pipe."
for tries := 0; tries < 2; tries++ {
if tries == 1 {
// TODO start audacity via command
// "C:\Program Files (x86)\Audacity\audacity.exe"
}
if runtime.GOOS == "windows" {
eol = "\r\n"
t := time.Minute
// TODO winio still necessary?
if fromPipe, err = winio.DialPipe("\\\\.\\pipe\\FromSrvPipe", &t); err != nil {
if tries == 0 {
continue
}
return fmt.Errorf(errFormat, err, "sending")
}
if toPipe, err = winio.DialPipe("\\\\.\\pipe\\ToSrvPipe", &t); err != nil {
return fmt.Errorf(errFormat, err, "receiving")
}
} else {
toName := "/tmp/audacity_script_pipe.to." + string(os.Getuid())
fromName := "/tmp/audacity_script_pipe.from." + string(os.Getuid())
eol = "\n"
if toPipe, err = os.Open(toName); err != nil {
if tries == 0 {
continue
}
return fmt.Errorf(errFormat, err, "sending")
}
if fromPipe, err = os.Open(fromName); err != nil {
return fmt.Errorf(errFormat, err, "receiving")
}
}
}
return nil
}
// ClosePipes closes the pipes to Audacity. Make sure you call this function when you are done.
func ClosePipes() {
if toPipe != nil {
toPipe.Close()
toPipe = nil
}
if fromPipe != nil {
fromPipe.Close()
fromPipe = nil
}
}