Missing modernisations

I feel the library is not being fully ported over c++11. There are plenty of places where we still use interfaces for single callbacks and functions pointers with void* contexts as remnants of C99 development… Any reason why this is not prioritised ?

To take some examples, juce::ModalComponentManager::Callback should be a std::function instead of being an interface (very very annoying to work with). And juce::URL::openInputStream progress callback with void* context should be a lambda too. And there are more, you’ll find plenty in the library.

1 Like

Also, all of this verbosity nonsense can be removed imho. Useless with lambda captures, or are there any use case for those ? Can’t figure out what they will be useful for, especially considering we support only 2 parameters maximum.

    /** This is a utility function to create a ModalComponentManager::Callback that will
        call a static function with two custom parameters.

        The function that you supply must take three parameters - the first being an int, which is
        the result code that was used when the modal component was dismissed, and the next two are
        your custom types. Note that these custom values will be copied and stored, so they must
        be primitive types or classes that provide copy-by-value semantics.

        E.g. @code
        static void myCallbackFunction (int modalResult, double customValue1, String customValue2)
        {
            if (modalResult == 1)
                doSomethingWith (customValue1, customValue2);
        }

        Component* someKindOfComp;
        ...
        someKindOfComp->enterModalState (true, ModalCallbackFunction::create (myCallbackFunction, 3.0, String ("xyz")));
        @endcode
        @see ModalComponentManager::Callback
    */
    template <typename ParamType1, typename ParamType2>
    static ModalComponentManager::Callback* withParam (void (*functionToCall) (int, ParamType1, ParamType2),
                                                       ParamType1 parameterValue1,
                                                       ParamType2 parameterValue2)
    {
        return create ([=] (int r) { functionToCall (r, parameterValue1, parameterValue2); });
    }

What if i want to pass 3 parameters :smiley:

1 Like

There is an std::function there no ?

Yes but iiuc @kunitoki suggests that the only interface should be just setting an std::function. and removing ModalCallback, ModalCallbackFunction, and other helpers all together to make for a more coherent and consistent API.

sure, but do we need the other ones ?

That class should be removed as it is not providing anything useful. Less code, less classes, less complexity. Less unit tests to write and maintain (i always assume JUCE has unit tests for those right ?).

1 Like

Yep sure.
I suppose the goal was not to break compatibility but honestly I don’t mind.

1 Like

if we want to move forward we should get away with supporting these legacy constructs.

2 Likes