/* 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/AmplitudeEnvelope.h" #include "utilities/lookup3.h" #define stemobject_implementation AmplitudeEnvelope 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(getLength); stemobject_vtable_entry(getPropertyCount); stemobject_vtable_entry(getPropertyAtIndex); stemobject_vtable_entry(getPropertyValueStateless); stemobject_vtable_entry(setPropertyValue); stemobject_vtable_entry(sample); stemobject_vtable_end(); AmplitudeEnvelope * AmplitudeEnvelope_create(float baseAmplitude, float length) { stemobject_create_implementation(init, baseAmplitude, length) } bool AmplitudeEnvelope_init(AmplitudeEnvelope * self, float baseAmplitude, float length) { call_super(init, self); self->baseAmplitude = baseAmplitude; self->length = length; return true; } void AmplitudeEnvelope_dispose(AmplitudeEnvelope * self) { call_super_virtual(dispose, self); } AmplitudeEnvelope * AmplitudeEnvelope_copy(AmplitudeEnvelope * self) { stemobject_copy_implementation(initCopy) } bool AmplitudeEnvelope_isEqual(AmplitudeEnvelope * self, compat_type(AmplitudeEnvelope *) compareUntyped) { AmplitudeEnvelope * compare = compareUntyped; if (!StemObject_isExactClass(compare, self->vtable)) { return false; } if (StemObject_isExactClass(self, &AmplitudeEnvelope_class) && compare->length != self->length) { return false; } return compare->baseAmplitude == self->baseAmplitude && compare->length == self->length; } uint32_t AmplitudeEnvelope_hash(AmplitudeEnvelope * self, uint32_t initval) { initval = hashlittle(&self->baseAmplitude, sizeof(self->baseAmplitude), initval); initval = hashlittle(&self->length, sizeof(self->length), initval); return initval; } void AmplitudeEnvelope_initCopy(AmplitudeEnvelope * self, AmplitudeEnvelope * original) { call_super(initCopy, self, (SamplerObject *) original); self->baseAmplitude = original->baseAmplitude; self->length = original->length; } struct AmplitudeEnvelope_state { float baseAmplitude; }; SamplerObject_state * AmplitudeEnvelope_initState(AmplitudeEnvelope * self) { struct AmplitudeEnvelope_state * stateStruct = malloc(sizeof(*stateStruct)); stateStruct->baseAmplitude = self->baseAmplitude; return stateStruct; } void AmplitudeEnvelope_disposeState(AmplitudeEnvelope * self, SamplerObject_state * state) { free(state); } float AmplitudeEnvelope_getLength(AmplitudeEnvelope * self) { return self->length; } static SynthProperty synthProperties[1]; static void initSynthProperties(void) { SYNTH_PROPERTY(0, baseAmplitude, "Amplitude", 0.0f, 1.0f, 0.5f, 0.05f) } SYNTH_PROPERTY_FUNCTION_IMPLEMENTATIONS() float AmplitudeEnvelope_getPropertyValueStateless(AmplitudeEnvelope * self, SynthPropertyIdentifier propertyIdentifier) { return self->baseAmplitude; } void AmplitudeEnvelope_setPropertyValue(AmplitudeEnvelope * self, SamplerObject_state * state, SynthPropertyIdentifier propertyIdentifier, float value) { struct AmplitudeEnvelope_state * stateStruct = state; stateStruct->baseAmplitude = value; } float AmplitudeEnvelope_sample(AmplitudeEnvelope * self, SamplerObject_state * state, float phase, float phaseDelta, float time, float timeDelta) { struct AmplitudeEnvelope_state * stateStruct = state; return stateStruct->baseAmplitude; }