Creating user modules tutorial?


#1

Is there anything besides this thread (which is not really a guide)?

Projucer doesn’t seem to have a new module template, unless I’m supposed to use a static or dynamic library, which I don’t think is correct.

Basically, I’m at the point where I’d like to organize my own code into a few modules (dsp, UI, etc) for my multiple plugin projects.

Any help would be appreciated. Thanks.


#2

I can pitch in on this one. Some general rules I’ve learned about how JUCE needs these things to be formatted:


Each top-level module’s header file must have the comment block mentioned in the post you shared.

Example:

/** BEGIN_JUCE_MODULE_DECLARATION

    ID:            my_module
    vendor:         
    version:        0.0.1
    name:           
    description:    
    website:        
    license:        Proprietary

    dependencies:   

    END_JUCE_MODULE_DECLARATION
*/

The module’s folder and its top-level .h/.cpp/.cmm module files must have the same name as the ID from that comment block.

  • eg: my_module, my_module.h/.cpp/.mm

Projucer controllable flags/macros can be created using this form, and must exist in your module’s top-level header.

/** Config: MYMODULE_IMPORTANT_MACRO_NAME

    Enables my really fancy macro that affects my entire module.

    By default, this is enabled.
*/
#ifndef MYMODULE_IMPORTANT_MACRO_NAME
    #define MYMODULE_IMPORTANT_MACRO_NAME 1
#endif

#3

Thanks.

So, I made my main module folder and created module inside that as described. I set the Global Search Path for User Modules but when I try to add my module to a project, it does not show up under Add a Module/Global User Modules Path. ???


#4

You can use the “Use module form specific folder”. The last used will appear as “Exporter Path”. And you can add the “Global user search path”, but it seems, that this folder needs to be named “modules”…
HTH


#5

Thanks. Yeah, I guess “MyModules” doesn’t work…lol


#6

This was a bug and should be fixed on develop shortly!


#7

How do I set up using user modules?

My understanding of ‘user modules’ is that I can share, use, edit .h/.cpp files between projects, is this even correct?

I’ve copied some files into a ‘modules’ folder and pointed to it in the Projucers global search paths. I also added the following to the top of the header file, making sure the ID matches the filename.h/.cpp

/** BEGIN_JUCE_MODULE_DECLARATION

ID:            my_module
vendor:         
version:        0.0.1
name:           
description:    
website:        
license:        Proprietary

dependencies:   

END_JUCE_MODULE_DECLARATION
*/

#8

That is correct. You will find your files in the project in the folder “JUCE Modules”.
The main cpp file will be linked with your code, just like normal source files, so you can include all other cpp files in this modulename.cpp file. You can have a look into the juce modules, they work the same way.
The only thing to note is, that at this point the juce namespace is not imported, so best practice is to add juce:: to every juce class you use in your module.

HTH


#9

Sorry I don’t understand the process from what you’ve said. So I need to create a main header file which will include every other file i want to use. Then I include it in PluginProcessor.h etc like we do with: #include "../JuceLibraryCode/JuceHeader.h"? Then I get the projucer to set the user module path to wherever the mymodules.h header file and the other files are? I must be missing something because this doesn’t work.

Thanks for the juce:: tip, that would surely cause me headaches later :slight_smile:


#10

The nice thing using the Projucer here is, you don’t have to include anything.
The JuceHeader.h is auto generated, and contains all necessary module headers, that you selected in Projucer’s modules tab.

Your header in the module includes the headers of the modules it depends on, like seen here:

HTH


#11

Thanks for your help! That seems like a great method, I assumed there was gunna be a lot more steps.

I had a look through some of the JUCE modules and JUCE Module Format.txt to work out how to format them. I think I’ve got it all right but I’m not able to use the classes in PluginProcessor.h etc.
I have the projucer point to a ‘modules’ folder. Inside there is a gui folder which contains gui.h. Which looks like:

/*******************************************************************************
BEGIN_JUCE_MODULE_DECLARATION

ID:               gui
vendor:           nameGoesHere
version:          0.1
name:             GUI element files
description:      GUI for parameters, layouts, elements etc.
website:          http://www.website.com/
license:          Copyright. All Rights Reserved.

END_JUCE_MODULE_DECLARATION

*******************************************************************************/

#pragma once
#define GUI_H_INCLUDED

//==============================================================================

#include "CustomLookAndFeel.h"

In a sub folder of gui, I have a folder called look_and_feel which contains the CustomLookAndFeel.h and .cpp.

I haven’t added any new code to PluginProcessor etc since you say #include "../JuceLibraryCode/JuceHeader.h" will include all the user modules too.


#12

Any help? Still don’t know how to set up user modules


#13

Well what’s not working? Any error messages?


#14

I have it set up as described in my last last message but aren’t able to use any classes in a project. I have the Projucer link to the appropriate user modules folder.


#15

Which is the case, if you added your module to your project and re-saved it in Projucer.
You can double check by looking into the …/JuceLibraryCode/JuceHeader.h (on XCode just CMD+click in the filename).

If your module depends on other (juce-) modules, your module header has to include them, that way you can define the order of the dependencies.
A minimal would be:

#include <juce_core/juce_core.h>

HTH


#16

If it can be of any help, I have written some notes to myself on how to structure a JUCE module, based on some guesswork in addition to what’s written in the official JUCE Module Format.txt:

https://www.dropbox.com/s/uc115mcuomyl09y/Module%20Guidelines.html?dl=1


#17

Thanks for posting this. I don’t agree with this part:

Conventions:

juce_module (all lowercase) is used as the generic name of a JUCE-style module
juce_Source (name is Uppercase) is used as the generic name of one of the source files that compose a module.

That is the convention for JUCE modules, yes, but user-created modules IMO should have the form

vendor_module (all lowercase) is used as the generic name of a JUCE-style module
vendor_Source (name is Uppercase) is used as the generic name of one of the source files that compose a module.

Where “vendor” is e.g. your GitHub username or whatever you want to use.

I would argue that the second point is not even necessary; the files will be hidden in your module folder.

I also think that JUCE and Projucer are long overdue proper support for including user modules from e.g. Git repositories, even better would be a central repository that lists all available user modules and their Git address.

Currently user modules are not very “discoverable”.


#18

Yes, all your points are very valid, let me explain:

What I have meant by putting those statements under the “Conventions” title was that in the rest of the document I used those strings to refer to a generic module in JUCE format and to a generic source file inside said module, respectively.

That was not intended as a suggested convention for naming third party modules and source files, in particular regarding the “juce_” prefix. I used it only intending to give the reader the familiar name that he is used to see when looking through the JUCE code.

In fact, for that part I agree with you that third party modules should replace the “juce_” prefix with something else in order not to confuse them with “official” modules.

Also, in addition to your proposed improvements to Projucer, maybe the “Juce Modules” and “Juce Library Code” folders that appear e.g. in Xcode projects should be given more generic names that don’t mention “Juce”, now that several modules in JUCE format may be provided by third parties as well?


#19

I’ve regretted those names for years now!


#20

I’m still not getting my modules to work…
A start to finish tutorial for getting a user module working would be immensely helpful.

Am I wrong for thinking a folders going to appear here containing my user modules?:
juce%20modules