# New way to use PGM in plugins

**URL:** https://forum.foleysfinest.com/t/new-way-to-use-pgm-in-plugins/39
**Category:** PluginGuiMagic
**Created:** [23 March 2021 23:07 UTC](https://forum.foleysfinest.com/t/new-way-to-use-pgm-in-plugins/39 "2021-03-23T23:07:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![daniel](https://forum.foleysfinest.com/user_avatar/forum.foleysfinest.com/daniel/32/5_2.png) [@daniel](https://forum.foleysfinest.com/u/daniel)
#### Post date: [23 March 2021 23:07 UTC](https://forum.foleysfinest.com/t/new-way-to-use-pgm-in-plugins/39/1 "2021-03-23T23:07:17Z")

</div>

Since Version 1.3.0 there is an easier way to use PluginGuiMagic in a JUCE based plugin.

What stays the same is to add the foleys\_gui\_magic to the project.

- Instead of inheriting juce::AudioProcessor inherit foleys::MagicProcessor
- You don’t need to add a magicState. It is alreadt added in the new base class
- You don’t need to use AudioProcessorValueTree, but you can.
- You need to remove the hasEditor and createEditor from your processor class, so the editor is created from the base class
- You should remove setStateInformation/getStateInformation to enable a preconfigured loading and saving of your plugins state
- to add your own components override the `void initialiseBuilder (foleys::MagicBuilder& builder)`:

```auto
void MyProcessor::initialiseBuilder (MagicGUIBuilder& builder)
{
    builder.registerJUCEFactories();
    builder.registerJUCELookAndFeels();
    // add your own factories here:
    builder.registerFactory ("MyComponent", &MyComponenttem::factory);
    // the factory was created by adding the FOLEYS_DECLARE_GUI_FACTORY (MyComponentItem) to your wrapping GuiItem
}

```

This is how you set up the GUI in your processors constructor:

- set the ValueTree in the constructor from BinaryData:

```auto
magicState.setGuiValueTree (BinaryData::magic_xml, BinaryData::magic_xmlSize);

```

- Alternatively you can load from a file. On Mac it is particularily useful, since you can change it without recompiling. This uses the file and falls back to a version in BinaryData:

```auto
auto file = juce::File::getSpecialLocation (juce::File::currentApplicationFile)
        .getChildFile ("Contents")
        .getChildFile ("Resources")
        .getChildFile ("magic.xml");

if (file.existsAsFile())
    magicState.setGuiValueTree (file);
else
    magicState.setGuiValueTree (BinaryData::magic_xml, BinaryData::magic_xmlSize);

```

- Last but not least you can use an auto generated ValueTree, which adds as many controls as it knows about:

```auto
auto defaultGUI = magicState.createDefaultGUITree();
magicState.setGuiValueTree (defaultGUI);

```

Hope that helps, please let me know if there are problems

---

<div class="post-metadata">

### Author: ![daniel](https://forum.foleysfinest.com/user_avatar/forum.foleysfinest.com/daniel/32/5_2.png) [@daniel](https://forum.foleysfinest.com/u/daniel)
#### Post date: [25 October 2021 20:21 UTC](https://forum.foleysfinest.com/t/new-way-to-use-pgm-in-plugins/39/2 "2021-10-25T20:21:02Z")

</div>


