# GPT-chat and JUCE

**URL:** <https://forum.juce.com/t/gpt-chat-and-juce/53975>\
**Category:** General JUCE discussion\
**Created:** [December 2, 2022, 1:32pm UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975 "2022-12-02T13:32:17Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 2, 2022, 1:32pm UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975/1 "2022-12-02T13:32:17Z")

</div>

Just an FYI for people who were thinking of posting a JUCE question here: you might get a quicker (and maybe even better) answer by asking [https://chat.openai.com/chat](https://chat.openai.com/chat) instead.

For example, I asked it:

> How do I create an animated level meter in JUCE?

and got:

> To create an animated level meter in JUCE, you can use the `juce::MeterComponent` class, which provides a customizable level meter that can be animated. To use it, you’ll need to include the appropriate headers and create an instance of the `MeterComponent` class. Then, you can use the `setMeterLevel` method to set the level of the meter and the `setPeakHoldEnabled` method to enable peak hold, which will show the highest level reached by the meter.
> 
> Here’s an example of how you might use the `MeterComponent` class to create an animated level meter:
> 
> ```auto
> #include <JuceHeader.h>
> 
> class MyLevelMeter : public juce::MeterComponent
> {
> public:
> MyLevelMeter()
> {
> // Enable peak hold and set the meter level to 0.5.
> setPeakHoldEnabled (true);
> setMeterLevel (0.5);
> 
> // Set the number of LED lights to 10 and the width of the meter to 300 pixels.
> setNumLights (10);
> setSize (300, 20);
> }
> };
> 
> ```
> 
> You can then add your `MyLevelMeter` component to your JUCE application and use it like any other component. To animate the level meter, you can update the meter level in regular intervals, for example by using a `juce::Timer` object to call the `setMeterLevel` method at regular intervals.
> 
> I hope this helps! Let me know if you have any other questions.

Not bad.

Then I asked:

> Explain how a juce::Component works, in the style of a 1940s mobster

and it replied:

> Sure, here’s how I might explain a juce::Component in the style of a 1940s mobster:
> 
> "See, kid, a juce::Component is like the boss of a user interface. It’s got all the power and control over what’s displayed on the screen.
> 
> You wanna create a button or a text box or some other fancy widget? You gotta go through the juce::Component to make it happen. It’s the one in charge of positioning and sizing those widgets, and it’s the one that tells 'em what to do when a mouse clicks on 'em or a keyboard key gets pressed.
> 
> Now, you might be thinking, “Hey, this juce::Component sounds like a real tough guy.” And you’re right, kid, it is. But it’s also a fair boss. It lets other juce::Component objects join its crew and work together to create a user interface that’s smooth and stylish.
> 
> So, bottom line, if you wanna make a user interface that’s the bees knees, you gotta pay your respects to the juce::Component. It’s the boss, kid, and you don’t want to mess with the boss."

---

<div class="post-metadata">

**Author:** ![Fandusss](https://avatars.discourse-cdn.com/v4/letter/f/a4c791/32.png) [@Fandusss](https://forum.juce.com/u/Fandusss)\
**Post date:** [December 2, 2022, 1:37pm UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975/2 "2022-12-02T13:37:43Z")

</div>

Guess the juce team has to make that MeterComponent now

---

<div class="post-metadata">

**Author:** ![alatar](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@alatar](https://forum.juce.com/u/alatar)\
**Post date:** [December 2, 2022, 8:51pm UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975/3 "2022-12-02T20:51:46Z")

</div>

And don’t forget:

“You gotta pay your respects to the juce::Component. It’s the boss!” 😆

---

<div class="post-metadata">

**Author:** ![ans](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ans/32/617_2.png) [@ans](https://forum.juce.com/u/ans)\
**Post date:** [December 3, 2022, 11:08am UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975/4 "2022-12-03T11:08:21Z")

</div>

We’re far beyond the uncanny valley already. At some point in the future all content written in English will be discredited as basically untrustworthy, as more than 50% of it will have been fabricated by A.I. Professional copywriters already use it en masse to generate first drafts.

I guess around 2050 or so, humans will have to invent new forms of communication that A.I. is unable to deal with, or else …

---

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [December 3, 2022, 12:04pm UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975/5 "2022-12-03T12:04:51Z")

</div>

I asked ChatGPT to write that juce::MeterComponent class, thats what I got:

_Please write the juce::MeterComponent class for the JUCE C++ framework, which is an animated level meter._

```auto
#include <JuceHeader.h>

class MeterComponent : public juce::Component
{
public:
    MeterComponent()
    {
        setBufferedToImage(true);
    }

    void paint(juce::Graphics& g) override
    {
        const auto width = getWidth();
        const auto height = getHeight();

        g.fillAll(juce::Colours::black);

        const auto level = getLevel();

        const auto barWidth = width / 10.0f;
        const auto barHeight = height * level;

        for (int i = 0; i < 10; ++i)
        {
            const auto x = i * barWidth;
            const auto y = height - barHeight;

            g.setColour(juce::Colour::fromHSV(i / 10.0f, 1.0f, 1.0f, 1.0f));
            g.fillRect(x, y, barWidth, barHeight);
        }
    }

    void setLevel(float newLevel)
    {
        if (newLevel != level)
        {
            level = newLevel;
            repaint();
        }
    }

    float getLevel() const noexcept
    {
        return level;
    }

private:
    float level = 0.0f;

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MeterComponent)
};

```

**This `MeterComponent` class displays a horizontal level meter with 10 bars. The level is set with the `setLevel()` method and the current level is returned by the `getLevel()` method. The meter is animated by calling `repaint()` whenever the level changes.**

I compiled the code and set the level to 0.5, this is the result

![Screenshot 2022-12-03 at 12.59.46](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/9/9fd4576237a6f5ce195f82ecfed2b65f7c5e1ee1.png)

---

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [December 3, 2022, 12:28pm UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975/6 "2022-12-03T12:28:44Z")

</div>

Really wondering what the consequences of this technology will be in the future.

---

<div class="post-metadata">

**Author:** ![asimilon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/asimilon/32/4235_2.png) [@asimilon](https://forum.juce.com/u/asimilon)\
**Post date:** [December 3, 2022, 1:12pm UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975/7 "2022-12-03T13:12:35Z")

</div>

Somewhat relevant to this, considering that ChatGPT invented a somewhat plausible `juce::MeterComponent` class.

> **[ChatGPT produces made-up nonexistent references](https://news.ycombinator.com/item?id=33841672)**
>
> I was trying to find references to mathematical treatment of lists, and queried ChatGPT the following:\<p\>Please provide references that deal with the mathematical properties of lists\<p\>To which ChatGPT responded as follows:\<p\>\<pre\>\<code\> "Introduction to the Mathematics of Lists" by Peter J. Cameron...

---

<div class="post-metadata">

**Author:** ![Mrugalla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mrugalla/32/13092_2.png) [@Mrugalla](https://forum.juce.com/u/Mrugalla)\
**Post date:** [December 3, 2022, 2:45pm UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975/8 "2022-12-03T14:45:48Z")

</div>

yesterday i asked GPT-chat what kinda plugin it would make if it was a VST developer and it told me it would create an analyzer for the sentiment of a vocal input. That would be incredible :o just wanna pass this info on to everyone here, because i’m not into machine learning myself, so i can’t do it

---

<div class="post-metadata">

**Author:** ![caustik](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/caustik/32/22449_2.png) [@caustik](https://forum.juce.com/u/caustik)\
**Post date:** [December 4, 2022, 4:03pm UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975/9 "2022-12-04T16:03:39Z")

</div>

Forget about Grid and FlexBox just give ChatGPT the set of Component pointers and a link to your social media account and let it select the optimal layout for you as a person. lol

---

<div class="post-metadata">

**Author:** ![rebbur](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@rebbur](https://forum.juce.com/u/rebbur)\
**Post date:** [December 8, 2022, 8:35am UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975/10 "2022-12-08T08:35:37Z")

</div>

ChatGPT is very impressive, but i’m wondering how it knows about the existence of JUCE. Did it get fed some extra data for this or did it just pick it up from the interwebs?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [December 8, 2022, 9:40am UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975/11 "2022-12-08T09:40:58Z")

</div>

The JUCE team recruited 5 support engineers to train the AI, in order to lower the entry barrier 😉

I guess it’s simply web crawlers, like any search engine…

IMHO the same concerns like with Copilot and OpenSource licenses apply…

> **[Analyzing the Legal Implications of GitHub Copilot - FOSSA](https://fossa.com/blog/analyzing-legal-implications-github-copilot/)**
>
> The release of GitHub Copilot raises questions about potential copyright infringement and license compliance issues.

---

<div class="post-metadata">

**Author:** ![asimilon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/asimilon/32/4235_2.png) [@asimilon](https://forum.juce.com/u/asimilon)\
**Post date:** [December 8, 2022, 10:16am UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975/12 "2022-12-08T10:16:54Z")

</div>

The Github Copilot product page more or less leads with “GitHub Copilot uses the OpenAI Codex”, so I presume given ChatGPT’s ability to suggest all manner of code that essentially what Copilot is “as a product” is some “prompt engineering” so that you get useful results.

It would be interesting to try “prompting” Copilot to do some more “creative” writing that GPT-3 is able to do, perhaps:

```auto
std::string getBackStory() {
// return a string that gives the back story for the main character in our game

```

and let the robot do its magic.

---

<div class="post-metadata">

**Author:** ![cpr2323](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/cpr2323/32/18682_2.png) [@cpr2323](https://forum.juce.com/u/cpr2323)\
**Post date:** [December 8, 2022, 1:15pm UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975/13 "2022-12-08T13:15:51Z")

</div>

Speaking of stories, my son runs D&D games, and after I pointed him to GPT-Chat he msged me,

`"Ok this is out of control. I just got it to create a dnd adventure, a 4 person party, and roleplay the party accepting the quest"`

---

<div class="post-metadata">

**Author:** ![matt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/matt/32/18340_2.png) [@matt](https://forum.juce.com/u/matt)\
**Post date:** [January 2, 2023, 8:00pm UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975/14 "2023-01-02T20:00:22Z")

</div>

Just…wow…

[https://youtu.be/Ra7WUfaQNrM](https://youtu.be/Ra7WUfaQNrM)

---

<div class="post-metadata">

**Author:** ![pauloesteban](https://avatars.discourse-cdn.com/v4/letter/p/a5b964/32.png) [@pauloesteban](https://forum.juce.com/u/pauloesteban)\
**Post date:** [May 24, 2023, 4:25am UTC](https://forum.juce.com/t/gpt-chat-and-juce/53975/16 "2023-05-24T04:25:04Z")

</div>

The _ **trick** _ is to type the prompt in the [syntax](https://pbs.twimg.com/media/FGJ84rXX0AEGTBL?format=jpg&name=large) that the Large Language Model (LLM) expects.

My first prompts were like:

> May you indicate me a working example of juce::FileListComponent

The output was a non-working code. But then I improved the prompt:

> As a C++ JUCE programmer, may you indicate me how to use juce::DirectoryContentsList as a broadcaster and a derived class from juce::FileListComponent as a listener? juce::DirectoryContentsList instance is passed as an argument of the juce::FileListComponent instance, for example

```auto
fileListComponent.reset (new DerivedFileListComponent (*directoryContentsList, *this));

```

Leading to a very useful code sample.

On the other hand, GPT-3.5 and GPT-4 are on a Sep 2021 snapshot, hence, the answers are not up-to-date with JUCE 7.

I tried Bard and Bing, but it felt their results were less usable even when they are connected to the Internet.
