A few usefull classes for JUCE

I collected up some code I’ve written / ported to juce over the years and put them into a module named Gin. Some I’ve posted before as individual files, but I thought it would be better to have them all in a juce module. All code ported to juce was originally BSD license or similar, credits are in the files. This adds a few useful classes such as:

  • BMPImageFormat - Load and Save Windows Bitmaps. 8, 24, 32 bit, uncompressed reading supported. Write 32 bit.
  • ColourPropertyComponent - Colour picker for PropertyComponent
  • Ellipse - Determine if point is on ellipse. Find point at angle on ellipse.
  • FilePropertyComponent - File chooser for PropertyComponent
  • FileSystemWathcer - Get notified when files in directory change
  • ImageEffects - Sepia, Vignette, Soften, Sharpen, Invert, Contrast, Hue, Saturation, etc. Works on ARGB formatted images only.
  • Integrator - Calculate integrals
  • LeastSquaresRegression - Fits a curve to data points
  • LinearRegression - Fits a line to data points
  • MapViewer - Displays a map. Shows map tiles noly, you will need to extend it to draw paths, markers, etc.
  • OpenStreetMaps - Fetch tiles from various OSM servers
  • SharedMemory - Share a memory block between processes
  • Spline - A smooth curve from a set of discrete points
  • PerlinNoise - Natural looking noise
29 Likes

Some screenshots from the demo app:

image

image

image

6 Likes

great stuff, thanks!

What’s new in Gin since I last posted about it:

  • DownloadManager - a class for downloading multiple files in the background simultaneously with retries, gzip support, progress, etc.

  • ElevatedFileCopy - Requests admin permission to copy files, create directories, delete files. (macOS / Windows only)

  • EquationParser - solve math equations in strings i.e. x + y / sin (t)

  • AudioEquationParser - solve audio equations in strings i.e. lp24(saw(60), 4000, _q) / 2

  • MessagePack - converts to / from MessagePack and juce::var

  • parsePlist - converts from xml plist to juce::var

  • valueTreeToJSON / valueTreeFromJSON - convert between ValueTrees and json

  • LambdaValueTreeListener / AsyncLambdaValueTreeListener - listen to ValueTrees without having to subclass

  • applyBlend - 25 blending modes for Image

  • ResamplingFifo - a fifo that you push and pop at different sample rates

  • AsyncWebsocket - websocket class, supports https

  • SecureStreamingSocket - like StreamingSocket, but https. Client only.

30 Likes

I’ve started adding some comments and documentation, so it isn’t just a big dump of unreadable code.

https://figbug.github.io/Gin/annotated.html

8 Likes

Did the json to valueTree stuff get pulled? I recently had to write one of these and it felt pretty clunky by the end. I’d be interested to see how did it. Maybe this is even possible now with the latest versions of JUCE? I’m still rocking out 5.4.7!

juce::String valueTreeToJSON ( **const** juce::ValueTree& v);

juce::ValueTree valueTreeFromJSON ( **const** juce::String& jsonText);

There are a few special named properties. Couldn’t think another way to do it.

1 Like

@RolandMR -
Hi, I’m not sure if this is the appropriate place to post about it, but gin does not build against JUCE 7 - there are warnings and errors. I just tried the latest version from the git.

I was using the one downloaded back in April, and that gave a different set of errrors from the ones encountered with the one downloaded today.

I commented out a few things I wasn’t using to get it to work, so it’s not stopping me from moving forward with JUCE 7…

Can you post the warnings and what platform? Do you have extra warning enabled? It’s building clean for me.

I’m building DEBUG on Mac OS Mojave 10.14.6, Xcode 10.3. I wish it were more modern, but it is what it is.

These are the errors encountered with the previous version from April:

These are the errors encountered with the latest version:

(I don’t quite get that “‘if’ initialization statements are a C++17 extension” warning - I do that all over the place…)

I have the “Add recommended compiler warning flags” option turned on in Projucer Projects, for DEBUG.

std::optional was added in C++17, that’s why you don’t have it. I’d comment it out for now, C++17 is really useful and I’d rather not hold back.

I’ve always had C++14 (default) set in my JUCE projects. So I changed it to C++17. Does not seem to have introduced any issues, and it fixes the gin problems. Thanks!

Ok, I’ve updated the module headers to require C++17, in future you should get an error if it’s not enabled.

3 Likes

Just for the records because it seems to pertain to this discussion, JUCE has the Optional class as a replacement for std::optional until the requirement for JUCE is raised to C++17 (stated in their docs)

2 Likes

I’d rather not use it because of this comment:

This isn’t really intended to be used by JUCE clients. Instead, it’s to be used internally in JUCE code, with an API close-enough to std::optional that the types can be swapped with fairly minor disruption at some point in the future, but without breaking any public APIs .

But then again, it has already been used in public APIs. C++17 is well supported by now, I don’t see any reason to hold back.

1 Like

Sure, the intention of my post was to add information for someone that might end up here searching “std::optional” and “C++14” on the forum.
By no means I’m suggesting that you should use the class provided by JUCE if you decide that C++17 is the minimum requirement for your lib (which I personally think it’s quite reasonable)

2 Likes

Has anyone had any success using this module in a project built using CMake?

Yes I did a few weeks ago. I think it was pretty straight forward just doing something like this:

juce_add_modules(
        Gin/modules/gin ALIAS_NAMESPACE gin
        Gin/modules/gin_dsp ALIAS_NAMESPACE gin
        Gin/modules/gin_metadata ALIAS_NAMESPACE gin
        Gin/modules/gin_network ALIAS_NAMESPACE gin
        Gin/modules/gin_plugin ALIAS_NAMESPACE gin
)

Thanks @chrhaase, and where is Gin in relation to the ${CMAKE_CURRENT_SOURCE_DIR}? And I assume you then do something like:

set(JUCE_MODULES
    juce::juce_core
    juce::juce_events
    ...
    gin::gin_dsp

etc., etc.? I’ll give it a whirl. I’m particulrly interesting in websocket class, but I see no example code. I wonder if anyone has a basic example they can share?

[edit] seems to work, thanks for this :slight_smile: Unfortunately, the one project I want to use it on is still using JUCE6. I might be able to roll gin back to a compatible version…

Yes, I just do target_link_libraries directly, but should be the same :slight_smile:
I put Gin in libs directory where all my other dependencies are.

Have only used the dsp module so far!

1 Like