class library: Reset has been renamed to OnError
[supercollider.git] / SCClassLibrary / JITLib / ProxySpace / NodeMapSetting.sc
blobb8bb43786af67627964458ffae7b4088960b4745
1 NodeMapSetting {
3         var <>key, <>value, <>busNumChannels, <>isMultiChannel=false, <>isMapped=false, <>mappedRate;
5         *new { arg key, value, busNumChannels;
6                 ^super.newCopyArgs(key, value, busNumChannels)
7         }
9         map { arg index;
10                 value = index;
11                 isMultiChannel = false;
12                 isMapped = true;
13                 busNumChannels = 1;
14         }
15         mapn { arg index, numChannels;
16                 value = index;
17                 busNumChannels = numChannels;
18                 isMultiChannel = true;
19                 isMapped = true;
20         }
21         mapa { arg index;
22                 this.map(index);
23                 mappedRate = \audio;
24         }
25         mapan { arg index, numChannels;
26                 this.map(index, numChannels);
27                 mappedRate = \audio;
28         }
29         set { arg val;
30                 value = val;
31                 isMapped = false;
32                 isMultiChannel = val.isSequenceableCollection;
33         }
34         getValue { // unmapped, single channel only
35                 ^if(this.isMapped.not and: { this.isMultiChannel.not }) { value } { nil }
36         }
38         addToEvent { arg event;
39                 var mapPrefix;
40                 if(isMapped) {
41                         mapPrefix = if(mappedRate === \audio) { "a" } { "c" };
42                         event.put(key, { |i| mapPrefix ++ (i + this.index) }.dup(busNumChannels))
43                 } {
44                         event.put(key, value)
45                 }
47         }
49         updateNodeMap { arg nodeMap;
50                 if(isMapped) {
51                         if(this.isNeutral) { nodeMap.upToDate = false; ^this }; // ignore setting
52                         this.updateBusNumChannels;
53                         if(isMultiChannel) {
54                                 if(mappedRate === \audio) {
55                                         nodeMap.mapanArgs = nodeMap.mapanArgs.addAll([key,this.index,busNumChannels])
56                                 } {
57                                         nodeMap.mapnArgs = nodeMap.mapnArgs.addAll([key, this.index, busNumChannels])
58                                 }
59                         }{
60                                 if(mappedRate === \audio) {
61                                         nodeMap.mapaArgs = nodeMap.mapaArgs.addAll([key, this.index]);
62                                 } {
63                                         nodeMap.mapArgs = nodeMap.mapArgs.addAll([key, this.index]);
64                                 }
65                         }
66                 } {
67                         if(value.notNil) {
68                                 if(isMultiChannel) {
69                                         nodeMap.setnArgs = nodeMap.setnArgs.addAll([key, value.size]++value)
70                                 } {
71                                         nodeMap.setArgs = nodeMap.setArgs.addAll([key, value])
72                                 }
73                         };
74                 }
75         }
77         copy {
78                 ^this.class.prNew(key, value, busNumChannels, isMultiChannel, isMapped, mappedRate)
79         }
81         isEmpty { ^value.isNil }
82         index { ^value }
83         isNeutral { ^false }
84         updateBusNumChannels {}
86         storeArgs { ^[key, value, busNumChannels] }
88         printOn { arg stream;
89                 stream << this.storeArgs
90         }
92         *prNew { arg key, value, busNumChannels, isMultiChannel=false, isMapped=false, mappedRate;
93                 ^super.newCopyArgs(key, value, busNumChannels, isMultiChannel, isMapped, mappedRate)
94         }
98 ProxyNodeMapSetting : NodeMapSetting {
99         var <>rate; // rate is the synthDef "rate" arg, value is a proxy !
101         index { ^value.index }
102         isEmpty {
103                 ^value.isNil and: { rate.isNil }
104         }
106         map { arg proxy;
107                 value = proxy;
108                 isMapped = true;
109                 // stays neutral if both mappedRate, busNumChannels are nil
110                 if(proxy.isNeutral) { proxy.initBus(mappedRate, busNumChannels) }; // could add a test
111                 busNumChannels = proxy.numChannels;
112                 busNumChannels !? { isMultiChannel = busNumChannels > 1 };
113                 mappedRate = proxy.rate; // here we determine the rate simply from the input proxy
114         }
116         isNeutral { ^value.isNeutral }
117         storeArgs { ^[value, busNumChannels, rate] }
118         updateBusNumChannels {
119                 if(isMultiChannel and: { busNumChannels.isNil }) {
120                         busNumChannels = value.numChannels;
121                 };
122         }