@@ -60,9 +60,11 @@ JSI_PROPERTY_SETTER_IMPL(AudioParamHostObject, value) {
6060}
6161
6262JSI_HOST_FUNCTION_IMPL (AudioParamHostObject, setValueAtTime) {
63- auto event = [param = param_,
64- value = static_cast <float >(args[0 ].getNumber ()),
65- startTime = args[1 ].getNumber ()](BaseAudioContext &) {
63+ auto startTime = args[1 ].getNumber ();
64+ controlQueue_.push (AutomationEvent (AutomationEventType::SET_VALUE, startTime));
65+
66+ auto event = [param = param_, value = static_cast <float >(args[0 ].getNumber ()), startTime](
67+ BaseAudioContext &) {
6668 param->setValueAtTime (value, startTime);
6769 };
6870
@@ -71,9 +73,11 @@ JSI_HOST_FUNCTION_IMPL(AudioParamHostObject, setValueAtTime) {
7173}
7274
7375JSI_HOST_FUNCTION_IMPL (AudioParamHostObject, linearRampToValueAtTime) {
74- auto event = [param = param_,
75- value = static_cast <float >(args[0 ].getNumber ()),
76- endTime = args[1 ].getNumber ()](BaseAudioContext &) {
76+ auto endTime = args[1 ].getNumber ();
77+ controlQueue_.push (AutomationEvent (AutomationEventType::LINEAR_RAMP, endTime));
78+
79+ auto event = [param = param_, value = static_cast <float >(args[0 ].getNumber ()), endTime](
80+ BaseAudioContext &) {
7781 param->linearRampToValueAtTime (value, endTime);
7882 };
7983
@@ -82,9 +86,11 @@ JSI_HOST_FUNCTION_IMPL(AudioParamHostObject, linearRampToValueAtTime) {
8286}
8387
8488JSI_HOST_FUNCTION_IMPL (AudioParamHostObject, exponentialRampToValueAtTime) {
85- auto event = [param = param_,
86- value = static_cast <float >(args[0 ].getNumber ()),
87- endTime = args[1 ].getNumber ()](BaseAudioContext &) {
89+ auto endTime = args[1 ].getNumber ();
90+ controlQueue_.push (AutomationEvent (AutomationEventType::EXPONENTIAL_RAMP, endTime));
91+
92+ auto event = [param = param_, value = static_cast <float >(args[0 ].getNumber ()), endTime](
93+ BaseAudioContext &) {
8894 param->exponentialRampToValueAtTime (value, endTime);
8995 };
9096
@@ -93,9 +99,12 @@ JSI_HOST_FUNCTION_IMPL(AudioParamHostObject, exponentialRampToValueAtTime) {
9399}
94100
95101JSI_HOST_FUNCTION_IMPL (AudioParamHostObject, setTargetAtTime) {
102+ auto startTime = args[1 ].getNumber ();
103+ controlQueue_.push (AutomationEvent (AutomationEventType::SET_TARGET, startTime));
104+
96105 auto event = [param = param_,
97106 target = static_cast <float >(args[0 ].getNumber ()),
98- startTime = args[ 1 ]. getNumber () ,
107+ startTime,
99108 timeConstant = args[2 ].getNumber ()](BaseAudioContext &) {
100109 param->setTargetAtTime (target, startTime, timeConstant);
101110 };
@@ -105,17 +114,18 @@ JSI_HOST_FUNCTION_IMPL(AudioParamHostObject, setTargetAtTime) {
105114}
106115
107116JSI_HOST_FUNCTION_IMPL (AudioParamHostObject, setValueCurveAtTime) {
117+ auto startTime = args[1 ].getNumber ();
118+ auto duration = args[2 ].getNumber ();
119+ controlQueue_.push (
120+ AutomationEvent (AutomationEventType::SET_VALUE_CURVE, startTime, startTime + duration));
121+
108122 auto arrayBuffer =
109123 args[0 ].getObject (runtime).getPropertyAsObject (runtime, " buffer" ).getArrayBuffer (runtime);
110124 auto *rawValues = reinterpret_cast <float *>(arrayBuffer.data (runtime));
111125 auto length = static_cast <int >(arrayBuffer.size (runtime) / sizeof (float ));
112126 auto values = std::make_shared<AudioArray>(rawValues, length);
113127
114- auto event = [param = param_,
115- values,
116- length,
117- startTime = args[1 ].getNumber (),
118- duration = args[2 ].getNumber ()](BaseAudioContext &) {
128+ auto event = [param = param_, values, length, startTime, duration](BaseAudioContext &) {
119129 param->setValueCurveAtTime (values, length, startTime, duration);
120130 };
121131
@@ -124,7 +134,10 @@ JSI_HOST_FUNCTION_IMPL(AudioParamHostObject, setValueCurveAtTime) {
124134}
125135
126136JSI_HOST_FUNCTION_IMPL (AudioParamHostObject, cancelScheduledValues) {
127- auto event = [param = param_, cancelTime = args[0 ].getNumber ()](BaseAudioContext &) {
137+ auto cancelTime = args[0 ].getNumber ();
138+ controlQueue_.cancelScheduledValues (cancelTime);
139+
140+ auto event = [param = param_, cancelTime](BaseAudioContext &) {
128141 param->cancelScheduledValues (cancelTime);
129142 };
130143
@@ -133,7 +146,10 @@ JSI_HOST_FUNCTION_IMPL(AudioParamHostObject, cancelScheduledValues) {
133146}
134147
135148JSI_HOST_FUNCTION_IMPL (AudioParamHostObject, cancelAndHoldAtTime) {
136- auto event = [param = param_, cancelTime = args[0 ].getNumber ()](BaseAudioContext &) {
149+ auto cancelTime = args[0 ].getNumber ();
150+ controlQueue_.cancelScheduledValues (cancelTime);
151+
152+ auto event = [param = param_, cancelTime](BaseAudioContext &) {
137153 param->cancelAndHoldAtTime (cancelTime);
138154 };
139155
@@ -164,24 +180,17 @@ Result<NoneType, std::string> AudioParamHostObject::checkCurveExclusionFromJSI(
164180 const jsi::Value *args) {
165181 auto arg = args[0 ].getObject (runtime);
166182 auto type = static_cast <AutomationEventType>(arg.getProperty (runtime, " type" ).getNumber ());
167-
168- switch (type) {
169- case AutomationEventType::SET_VALUE:
170- case AutomationEventType::LINEAR_RAMP:
171- case AutomationEventType::EXPONENTIAL_RAMP:
172- case AutomationEventType::SET_TARGET: {
173- auto startTime = arg.getProperty (runtime, " startTime" ).getNumber ();
174- return controlQueue_.checkCurveExclusion (AutomationEvent (type, startTime));
175- }
176- case AutomationEventType::SET_VALUE_CURVE: {
177- auto startTime = arg.getProperty (runtime, " startTime" ).getNumber ();
178- auto duration = arg.getProperty (runtime, " duration" ).getNumber ();
179- return controlQueue_.checkCurveExclusion (
180- AutomationEvent (type, startTime, startTime + duration));
181- }
182- default :
183- return Ok (None);
183+ auto automationTime = arg.getProperty (runtime, " automationTime" ).getNumber ();
184+
185+ AutomationEvent event;
186+ if (type == AutomationEventType::SET_VALUE_CURVE) {
187+ auto duration = arg.getProperty (runtime, " duration" ).getNumber ();
188+ event = AutomationEvent (type, automationTime, automationTime + duration);
189+ } else {
190+ event = AutomationEvent (type, automationTime);
184191 }
192+
193+ return controlQueue_.checkCurveExclusion (event);
185194}
186195
187196} // namespace audioapi
0 commit comments