/* 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/AudioSamplerParameters_multitrack.h" #include "utilities/IOUtilities.h" #include "utilities/lookup3.h" #include #define stemobject_implementation AudioSamplerParameters_multitrack stemobject_vtable_begin(); stemobject_vtable_entry(dispose); stemobject_vtable_entry(copy); stemobject_vtable_entry(isEqual); stemobject_vtable_entry(hash); stemobject_vtable_end(); AudioSamplerParameters_multitrack * AudioSamplerParameters_multitrack_create(unsigned int trackCount, struct AudioSamplerParameters_multitrack_track * tracks) { stemobject_create_implementation(init, trackCount, tracks) } bool AudioSamplerParameters_multitrack_init(AudioSamplerParameters_multitrack * self, unsigned int trackCount, struct AudioSamplerParameters_multitrack_track * tracks) { call_super(init, self); self->trackCount = trackCount; self->tracks = memdup(tracks, trackCount * sizeof(*tracks)); return true; } void AudioSamplerParameters_multitrack_dispose(AudioSamplerParameters_multitrack * self) { for (unsigned int trackIndex = 0; trackIndex < self->trackCount; trackIndex++) { call_virtual(dispose, self->tracks[trackIndex].parameters); } free(self->tracks); call_super_virtual(dispose, self); } AudioSamplerParameters_multitrack * AudioSamplerParameters_multitrack_copy(AudioSamplerParameters_multitrack * self) { stemobject_copy_implementation(initCopy) } void AudioSamplerParameters_multitrack_initCopy(AudioSamplerParameters_multitrack * self, AudioSamplerParameters_multitrack * original) { call_super(initCopy, self, (AudioSamplerParameters *) original); self->trackCount = original->trackCount; self->tracks = memdup(original->tracks, original->trackCount * sizeof(*original->tracks)); for (unsigned int trackIndex = 0; trackIndex < self->trackCount; trackIndex++) { self->tracks[trackIndex].name = strdup(original->tracks[trackIndex].name); self->tracks[trackIndex].parameters = call_virtual(copy, original->tracks[trackIndex].parameters); } } bool AudioSamplerParameters_multitrack_isEqual(AudioSamplerParameters_multitrack * self, compat_type(AudioSamplerParameters_multitrack *) compareUntyped) { AudioSamplerParameters_multitrack * compare = compareUntyped; if (!StemObject_isExactClass(compare, self->vtable)) { return false; } if (self->trackCount != compare->trackCount) { return false; } for (unsigned int trackIndex = 0; trackIndex < self->trackCount; trackIndex++) { if (self->tracks[trackIndex].offset != compare->tracks[trackIndex].offset || self->tracks[trackIndex].blend != compare->tracks[trackIndex].blend || !call_virtual(isEqual, self->tracks[trackIndex].parameters, compare->tracks[trackIndex].parameters)) { return false; } } return true; } uint32_t AudioSamplerParameters_multitrack_hash(AudioSamplerParameters_multitrack * self, uint32_t initval) { uint32_t result = initval; for (unsigned int trackIndex = 0; trackIndex < self->trackCount; trackIndex++) { result = hashlittle(&self->tracks[trackIndex].offset, sizeof(self->tracks[trackIndex].offset), result); result = hashlittle(&self->tracks[trackIndex].blend, sizeof(self->tracks[trackIndex].blend), result); result = call_virtual(hash, self->tracks[trackIndex].parameters, result); } return result; } void AudioSamplerParameters_multitrack_addTrack(AudioSamplerParameters_multitrack * self, struct AudioSamplerParameters_multitrack_track track) { self->trackCount++; self->tracks = realloc(self->tracks, self->trackCount * sizeof(*self->tracks)); self->tracks[self->trackCount - 1] = track; } void AudioSamplerParameters_multitrack_removeTrack(AudioSamplerParameters_multitrack * self, unsigned int trackIndex) { if (trackIndex < self->trackCount) { call_virtual(dispose, self->tracks[trackIndex].parameters); self->trackCount--; for (; trackIndex < self->trackCount; trackIndex++) { self->tracks[trackIndex] = self->tracks[trackIndex + 1]; } } }