forked from AudioKit/Flow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContents.swift
62 lines (54 loc) · 2.29 KB
/
Contents.swift
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
import Flow
import PlaygroundSupport
import SwiftUI
func simplePatch() -> Patch {
let midiSource = Node(name: "MIDI source",
outputs: [
Port(name: "out ch. 1", type: .midi),
Port(name: "out ch. 2", type: .midi),
])
let generator = Node(name: "generator",
inputs: [
Port(name: "midi in", type: .midi),
Port(name: "CV in", type: .control),
],
outputs: [Port(name: "out")])
let processor = Node(name: "processor", inputs: ["in"], outputs: ["out"])
let mixer = Node(name: "mixer", inputs: ["in1", "in2"], outputs: ["out"])
let output = Node(name: "output", inputs: ["in"])
let nodes = [midiSource, generator, processor, generator, processor, mixer, output]
let wires = Set([
Wire(from: OutputID(0, 0), to: InputID(1, 0)),
Wire(from: OutputID(0, 1), to: InputID(3, 0)),
Wire(from: OutputID(1, 0), to: InputID(2, 0)),
Wire(from: OutputID(2, 0), to: InputID(5, 0)),
Wire(from: OutputID(3, 0), to: InputID(4, 0)),
Wire(from: OutputID(4, 0), to: InputID(5, 1)),
Wire(from: OutputID(5, 0), to: InputID(6, 0)),
])
var patch = Patch(nodes: nodes, wires: wires)
patch.recursiveLayout(nodeIndex: 6, at: CGPoint(x: 1000, y: 50))
return patch
}
struct FlowDemoView: View {
@State var patch = simplePatch()
@State var selection = Set<NodeIndex>()
public var body: some View {
NodeEditor(patch: $patch, selection: $selection)
.nodeColor(.secondary)
.portColor(for: .control, .gray)
.portColor(for: .signal, Gradient(colors: [.yellow, .blue]))
.portColor(for: .midi, .red)
.onNodeMoved { index, location in
print("Node at index \(index) moved to \(location)")
}
.onWireAdded { wire in
print("Added wire: \(wire)")
}
.onWireRemoved { wire in
print("Removed wire: \(wire)")
}
}
}
PlaygroundPage.current.setLiveView(FlowDemoView().frame(width: 1200, height: 500))
PlaygroundPage.current.needsIndefiniteExecution = true