psiphi75/sonogram

Generate a legend from gradient

Closed this issue · 5 comments

juho commented

A legend generated from the gradient would be nice to have- Simon's comment suggests two options:

  1. Render it in the spectrogram, but this will cover part of the spectrogram and it will be very difficult to add text.
  2. Render another PNG without any labels. Then allow the UI to add labels

I like the second option- overlaying two images is quite easy and then the program doesn't have to have an opinion on where to place the legend. Width and height options for the output image would be nice.

juho commented

Tried to label this as a feature request but I suppose it's for repo officials only- I don't get the menu.

juho commented

@psiphi75 I was wondering if the gradient could be done the other way around, mapping dB threshold values to colours?

So something like..

let mut gradient = ColourGradient::new();
gradient.add_colour(RGBAColour::new(-100.0, 0, 0, 0, 255));     // Black - I was originally thinking -f32::INFINITY but it might be better to define a lower bound
gradient.add_colour(RGBAColour::new(-60.0, 55, 0, 110, 255));  // Purple
gradient.add_colour(RGBAColour::new(-40.0, 0, 0, 180, 255));   // Blue
gradient.add_colour(RGBAColour::new(-20.0, 0, 255, 255, 255)); // Cyan
gradient.add_colour(RGBAColour::new(-10.0, 255, 255, 0, 255)); // Green
gradient.add_colour(RGBAColour::new(-0.0, 255, 0, 0, 255));   // Red

This way you could define a minimum and maximum amplitude range, and generating the gradient would be much easier outside the package as the same colour stops can be calculated based on that range. What do you think?

Yes, that's possible and I've thought about that myself. Something like:

gradient.add_colour_at_db(-100.0, RGBAColour::new(0, 0, 0, 255)); 
gradient.add_colour_at_db(-60.0, RGBAColour::new(55, 0, 110, 255)); 

The RGBAColour struct is just a colour, the gradient should know about the mapping.

juho commented

Yes! That would make it trivial to overlay a gradient as you see fit elsewhere and this package wouldn't have to have an opinion on how it looks. Thinking about it, it's not just the gradient- it'd also need to have some markers for the stops and the dB numbers to go along with it, and people have different needs on how those appear in terms of font and colour.

This issue is resolved with commit 5e906e4. Note the changes are significant with this release. There are many breaking API changes. However, it's on it's way to becoming a real spectrogram tool. Also, the dB values are calculated more accurately, so the appearance of the gradients will be different.