/* Copyright (c) 2021 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #include "audiosynth/FrequencyCurve.h" #include "utilities/lookup3.h" #define stemobject_implementation FrequencyCurve stemobject_vtable_begin(); stemobject_vtable_entry(dispose); stemobject_vtable_entry(copy); stemobject_vtable_entry(isEqual); stemobject_vtable_entry(hash); stemobject_vtable_entry(initState); stemobject_vtable_entry(disposeState); stemobject_vtable_entry(getPropertyCount); stemobject_vtable_entry(getPropertyAtIndex); stemobject_vtable_entry(getPropertyValueStateless); stemobject_vtable_entry(setPropertyValue); stemobject_vtable_entry(sample); stemobject_vtable_end(); FrequencyCurve * FrequencyCurve_create(float baseValue) { stemobject_create_implementation(init, baseValue) } bool FrequencyCurve_init(FrequencyCurve * self, float baseValue) { call_super(init, self); self->baseValue = baseValue; return true; } void FrequencyCurve_dispose(FrequencyCurve * self) { call_super_virtual(dispose, self); } FrequencyCurve * FrequencyCurve_copy(FrequencyCurve * self) { stemobject_copy_implementation(initCopy) } bool FrequencyCurve_isEqual(FrequencyCurve * self, compat_type(FrequencyCurve *) compareUntyped) { FrequencyCurve * compare = compareUntyped; return StemObject_isExactClass(compare, self->vtable) && compare->baseValue == self->baseValue; } uint32_t FrequencyCurve_hash(FrequencyCurve * self, uint32_t initval) { initval = hashlittle(&self->baseValue, sizeof(self->baseValue), initval); return initval; } void FrequencyCurve_initCopy(FrequencyCurve * self, FrequencyCurve * original) { call_super(init, self); self->baseValue = original->baseValue; } struct FrequencyCurve_state { float baseValue; }; SamplerObject_state * FrequencyCurve_initState(FrequencyCurve * self) { struct FrequencyCurve_state * stateStruct = malloc(sizeof(*stateStruct)); stateStruct->baseValue = self->baseValue; return stateStruct; } void FrequencyCurve_disposeState(FrequencyCurve * self, SamplerObject_state * state) { free(state); } static SynthProperty synthProperties[1]; static void initSynthProperties(void) { SYNTH_PROPERTY(0, baseValue, "Base value", 0.0f, 9.0f, 4.0f, 1.0f / 12.0f) } SYNTH_PROPERTY_FUNCTION_IMPLEMENTATIONS() float FrequencyCurve_getPropertyValueStateless(FrequencyCurve * self, SynthPropertyIdentifier propertyIdentifier) { return self->baseValue; } void FrequencyCurve_setPropertyValue(FrequencyCurve * self, SamplerObject_state * state, SynthPropertyIdentifier propertyIdentifier, float value) { struct FrequencyCurve_state * stateStruct = state; stateStruct->baseValue = value; } float FrequencyCurve_sample(FrequencyCurve * self, SamplerObject_state * state, float phase, float phaseDelta, float time, float timeDelta) { struct FrequencyCurve_state * stateStruct = state; return stateStruct->baseValue; }