Hi!
I am developing a tool to extract features from songs, and I can't seem to find a proper way to store / expose them to the user. I have a Song struct that stores all kind of information about a song: its title, album, path, etc. I am however unsure how to handle numeric features.
Basically, I extract a bunch of features in the form of a Vec here https://github.com/Polochon-street/bliss-rs/blob/master/src/song.rs#L204-L210, which is stored in the Song.analysis Vec.
It has the advantage of being straightforward, because the thing most of the users will want to do with this Vec is to make it an ndarray's arr1, and compute distance between two analysis to check how different songs are, see https://github.com/Polochon-street/bliss-rs/blob/master/src/library.rs#L49-L52.
Though, in some cases, it would be nice to see which feature is which, without having to read the comment that says "vec[0] is the tempo, vec[1] is the zero-crossing rate", etc.
I've toyed with the idea of having an Analysis struct that has every field, like so:
struct Analysis {
tempo: f32,
zcr: f32,
...,
chroma_10: f32
}
with a to_vec that would just return vec![self.tempo, self.zcr, ...].
However, it has the disadvantage of having to set each field individually in the analysis step, which can make it quite verbose (especially since I have 10 unnamed chroma features on top of the rest, and there will probably be a lot more features in the future).
I could also keep the Vec and have a NamedAnalysis struct that I can just build from a Vec by implementing From<Vec<f32>> which would just return NamedAnalysis { tempo: vec[0], zcr: vec[1], ...}, so that only people actually needing to see which field is which will use that; the rest will stick to a Vec.
I don't really know which solution is the best (and to be honest, there are probably better solutions), so any kind help will be greatly appreciated ![]()