uuid.h
A unique identifier.
#include <sonore/uuid.h>- 1type
- 3other declarations
On this page
Design notes
What it is for
A preset needs a name a user can change and an id that never does, or renaming a preset breaks every project that referenced it. A sample library needs to know that two files with the same name in different folders are different samples. Anything that has to say "this one, not that one" across a save and a reload needs one.
Why not the SDK's own random
random.h is xoshiro128+ seeded through splitmix64, and it is deliberately DETERMINISTIC: a plugin whose noise differed between runs could not be nulled against a reference render, and that is the whole reason it is written that way.
Which makes it exactly wrong here. Two instances of a plugin, seeded identically because they were constructed identically, would mint identical "unique" ids -- and the failure is invisible until somebody has two of the plugin in one project and their presets start overwriting each other.
Where the entropy comes from
std::random_device is the standard answer, and on every platform this SDK targets it is a real entropy source. It is NOT guaranteed to be: the standard permits a deterministic implementation, and some older MinGW builds shipped one that returns the same sequence every run.
So it is mixed with two things that cannot both be constant across runs: the high-resolution clock, and the address of a stack object, which moves with ASLR. If random_device is real this changes nothing; if it is not, the ids are still distinct. Belt and braces, on the one function where a collision is silent and permanent.
Types 1
128 bits, as sixteen bytes.
Functions 3
- fn
inline Uuid makeUuid()A fresh identifier.uuid.h:90 - fn
inline std::string uuidToString(const Uuid& id)The canonical 8-4-4-4-12, lowercase. What goes in a state file.uuid.h:125 - fn
inline bool uuidFromString(const std::string& text, Uuid* out)Back from text. False for anything that is not one.uuid.h:143