-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.go
57 lines (45 loc) · 1.12 KB
/
connection.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
package muse
type Connection struct {
Module Module
Index int
}
// IConn for quick connecting multiple module/control outputs to inputs of module/control
type IConn struct {
Object any
OutIndex int
InIndex int
}
// IConns parse args to []*ICon, args need to be in the following order:
// - required module whose output is routed to input index
// - optional outIndex of module (default 0)
// - if outIndex is given follows an optional inIndex (otherwise index of count of IConn's parsed so far)
// - repeat...
func IConns(args ...any) []*IConn {
n := len(args)
argIndex := 0
inIndexCnt := 0
iConns := []*IConn{}
var inIndex int
var outIndex int
for argIndex < len(args) {
obj := args[argIndex]
argIndex++
outIndex = 0
inIndex = inIndexCnt
if argIndex < n {
if givenOutIndex, ok := args[argIndex].(int); ok {
outIndex = givenOutIndex
argIndex++
}
}
if argIndex < n {
if givenInIndex, ok := args[argIndex].(int); ok {
inIndex = givenInIndex
argIndex++
}
}
iConns = append(iConns, &IConn{Object: obj, OutIndex: outIndex, InIndex: inIndex})
inIndexCnt++
}
return iConns
}