Introducing JIVE - the ultimate JUCE extension for building GUIs

Yeah, nice!

JIVE v1.1 - Views and Hooks

A small but powerful addition - jive::View provides a convenient way to attach additional behaviour to a view through the use of it’s various Hooks.

Previously, it was difficult to access the corresponding Component from the unit that created the juce::ValueTree that represents it, making things like attaching widgets to juce::AudioProcessorValueTreeState rather messy. Now, we can easily access the jive::GuiItem and the juce::Component it wraps without the View needing to know about the rest of the app, and without the rest of the app needing to pass anything to the View!

Below is a short example - for a more in-depth example please see the Views and Hooks docs.

class MyView : public jive::View
{
protected:
    juce::ValueTree initialise() final
    {
        // Here we construct the initial state of the view
        return juce::ValueTree {
            "MyWidget",
            {
                { "value", 123 },
            },
        };
    }

    std::unique_ptr<juce::Component> createComponent(const juce::ValueTree& tree) final
    {
        // Here we construct an instance of our custom component that will
        // later be wrapped and managed by a jive::GuiItem
        if (tree.getType().toString() == "MyWidget")
            return std::make_unique<MyWidget>();

        return nullptr;
    }

    void setup(jive::GuiItem& item) final
    {
        // Here we have access to the jive::GuiItem that has been created to
        // wrap and manage our custom component.
        // We can access that component using item.getComponent()
    }
};

// Here we use jive::makeView() to construct an instance of our custom
// View and wrap it in a juce::ValueTree to be interpreted by a
// jive::Interpreter (or added as a child to a tree to be interpreted).
const auto view = jive::makeView<MyView>();
4 Likes

JIVE v1.2 - Animations

JIVE 1.2 introduces a powerful new animations API for Layouts and Style Sheets.

As shown in the updated Demo Runner, JIVE supports animating all expected layout and style properties as well as offering a flexible and intuitive API for animating any custom properties.

See docs/Animations.md for more info.

Animations example from the Demo Runner

15 Likes

Is there a way to add JIVE views to an existing JUCE UI?

This sort of works - I get an active button area, but the button title doesn’t show, the styling is all black, etc. Just seems like I’m missing something minor.

std::unique_ptr<jive::GuiItem> addJive()
{
    static constexpr auto button = R"(
    <Button width="100" height="30" name="buttonName">
        <Text>buttonText</Text>
    </Button>
    )";
    static constexpr auto style = R"(
        {
            "background": "red",
        }
    )";

    jive::Interpreter interpreter;
    auto item = interpreter.interpret(jive::parseXML(button).setProperty("style", style, nullptr));
    return item;
}

(in MainWindow.cpp)
topLevelComponent = addJive()->getComponent();
mainUI->addChildComponent( *topLevelComponent );

You need to make sure the jive::GuiItem stays alive along with the component.

In this line you’re accessing the shared JUCE Component from the item but then throwing the item away so all the mechanics that manage that component are gone.

Keep the std::unique_ptr<jive::GuiItem> as a member and it should work fine!

Currently running this in Visual Studio 2022 with the latest Projucer. I’ve tried running the demo .jucer projects but I always get a compilation error for the modules it seems. For example, in the jive_Transitions.h…

namespace juce
{
    template <>
    struct VariantConverter<jive::Transitions::ReferenceCountedPointer>
    {
        static jive::Transitions::ReferenceCountedPointer fromVar(const var& v)
        {
            if (auto* transitions = dynamic_cast<jive::Transitions*>(v.getObject()))
                return transitions;

            if (v.isString())
                return jive::Transitions::fromString(v.toString());

            return nullptr;
        }

        static var toVar(jive::Transitions::ReferenceCountedPointer transitions)
        {
            return var{ transitions }; // Compilation error here.
        }
    };
} // namespace juce

The error says, "no instance of constructor “juce::var::var” matches the argument list, argument types are: (jive::Transitions::ReferenceCountedPointer). This also happens wherever the VariantConverters pop up (e.g jive_MiscVariantConverters.h, and jive_Transitions.h)

Any help? Sorry, I’m not the most experienced coder so pardon my ignorance :sweat_smile:

This should be fixed now if you try the latest main.
I haven’t been able to check the Projucer projects on Windows specifically though so let me know if there’s further issues!

Yeah that fixed it! I think this next issue might be unique to the demo-plugin, but in Icons.h, I get an error that the binary_data::motionblurlarge_svg (and it’s size) is not a member of the binary_data namespace.

Ahh, tried to just bypass this temporarily by adding some values, but I do get another error. Not sure if this is related.
image

Ahh yes sorry I missed that… added that icon to the demo app but not the plugin. You should just be able to add the motion blur svg to the demo plugin’s Projucer project yourself in the meantime

Yes thank you! Another issue I’ve been having is getting the styles to work. I followed the tutorial up through the style sheets, but noticed that the style-sheets were not reflecting any changes. I tried testing out my current plugin and some other examples to little avail. For example, the gain-plugin renders as such:


It seems to function fine, although whenever I change, say, the font-size, for the gain-label to 100, it remains virtually the same. (This is also after saving changes and debugging again in VS).

Then in my own plugin, I have within the createEditor():

    jassert(JIVE_IS_PLUGIN_PROJECT);
    auto view = jiveUI::getView();
    if (auto editor = viewInterpreter.interpret(view, this))
    {
        if (dynamic_cast<juce::AudioProcessorEditor*>(editor.get()))
        {
            viewInterpreter.listenTo(*editor);
            //TODO: FIND THE PARAMETERS HERE
            return dynamic_cast<juce::AudioProcessorEditor*>(editor.release());
        }
    }

and in a seperate .h file…

#pragma once
#include <jive_core/jive_core.h>

namespace jiveUI
{
	// Used in plugin editor for the view.
	[[nodiscard]] inline auto getView()
	{
		return juce::ValueTree{
			"Editor",
			{
				{"width", 800},
				{"height", 250},
				{"align-items", "centre"},
				{"justify-content", "centre"},
				{
					"style",
					new jive::Object{
						{ "background", "#FFFFFF" },
					},
				},
			},
			{
				// TODO: Create other objects/param stuff here
			}
		};
	}
}

Sadly, the background is not all white. The width/height seem to change appropriately though in both cases.
Finally, the demo-runner seems to run fine and it’s styles do change how I expect them to, although wrapping my head around that one has been a bit slower for me.
Sorry for so many questions! Thank you for your time and patience!

Have you enabled JIVE_GUI_ITEMS_HAVE_STYLE_SHEETS=1?

Ahh I’m so silly. I thought I had enabled this earlier. Things have progressed quite swiftly since then. Little hiccups from me aside, overall this has been quite an intuitive and simple experience, even for a noobie like me to use! :grin:

1 Like

What do you think would be the best approach towards handling filmstrips for knobs within JIVE? I know that JUCE has a weird way of working with filmstrips (most often I see people overriding the paint() function within the component), but I had read how we should stick to using the styles as much as possible as opposed to overriding LookAndFeel/paint()/etc. Is there some way to do this currently? Or should I just supply my own custom component?

You could add an <Image/> element as a child of the slider, and then listen to the slider’s "on-change" event to determine which slice of the filmstrip to set as the "src" of the <Image/>. A jive::View might be the easiest way to do that

class FilmstripSlider : public jive::View
{
public:
    juce::ValueTree initialise() final
    {
        return juce::ValueTree{
            "Slider",
            {
            },
            {
                juce::ValueTree{ "Image" },
            },
        };
    }

    void setup(jive::GuiItem& item) final
    {
        onValueChange = std::make_unique<jive::Event>(item.state, "on-change");
        imageSource = std::make_unique<jive::Event>(item.state.getChild(0), "src");

        onValueChange->onTrigger = [this]() {
            imageSource->set(...);
        };
    }
private:
    std::unique_ptr<jive::Event> onValueChange;
    std::unique_ptr<jive::Property<juce::Image>> imageSource;
};

I’m having some trouble having a default comboBox display properly. For example, with this basic code:

juce::ValueTree
{
	"ComboBox",
	{
		{"id", comboBoxId},
		{"width", width},
		{"height", height},
		{
		"style",
			new jive::Object{
				{"background", jive::toVar(colors::skyPrimary)},
			}
		}
	},
},

A combo box is most definitely there, as I can correctly access a comboBox component later in the code (Using the style in this example, I can also get a color block of it’s dimensions and where it should be). After adding items to it (outside of the jive code), I can click where it should be at runtime and I see the item list pop up like normal, although not once do I ever see the base combo box.

Any idea why this might be happening?

I couldn’t say for sure without looking at the code and/or seeing a screenshot of the build.

Combo boxes do need a bit of TLC, but they do work as I would expect. E.g. adding this snippet to the Gain plugin demo:

juce::ValueTree{
    "ComboBox",
    {
        { "id", "my-box" },
        { "width", 200 },
        { "height", 25 },
        {
            "style",
            new jive::Object{
                { "background", "#FF88AA" },
            },
        },
    },
    {
        juce::ValueTree{ "Option", { { "text", "One" }, { "enabled", true } } },
        juce::ValueTree{ "Option", { { "text", "Two" }, { "enabled", true } } },
        juce::ValueTree{ "Option", { { "text", "Three" }, { "enabled", true } } },
    },
},

Gives this:

jive::LookAndFeel makes all the basic widgets invisible so the JIVE elements and styling render as expected. So if you want the combobox to show the currently selected item for example you’ll need to add a "Text" element to it. You can use the "on-change" even to update the text as needed.

Ahh ok yeah. I was suspecting I would need to do that. Thank you for the clarification!

I’ve been working with the jive layouts and was curious about whether it’s possible to essentially add a background image to a basic component without needing to make it a custom component. For example my initial approach…

// Some Component...
juce::ValueTree
{
	"Component",
	{
		// Alignment/justification....
	},
	{
		juce::ValueTree{"Image", {{"source","..."}}},
		// Other component.
		// Other component.
	}
}

…might’ve worked well if I didn’t have child components that also needed their own justification/alignment, as the drawable is treated as it’s own component rather than a “background” image. I also tried to make the main component an Image and adding children to that, but that didn’t work either. So is it possible to do this just using Jive layouts? Or would I have to define my own custom component to implement this?

Something like this might work:

// Some Component...
juce::ValueTree
{
	"Component",
	{
        { "display", "block" }
	},
	{
		juce::ValueTree{"Image", {{"source","..."}, {"width", "100%"}, {"height", "100%"}}},
        juce::ValueTree{
            "Component",
            {
                {"width", "100%"},
                {"height", "100%"},
         		// Alignment/justification....
            },
            {
		        // Other component.
        		// Other component.
            },
        },
	}
}