C++ project template?

I often go through the same tedious steps to set up midi, osc, audio, etc. in a project. It’s a little different every time, depending on the needs of the project, but having the base methods needed for such setup already declared and defined in a source code that can then be tweaked would be nice.

I guess I could just make a project that has all that stuff and then copy it and delete what I need whatever I don’t need whenever I make a new project. Wondering if there are any other ideas for this though.

I’ve made a tool for internal use that ties with ofxMicroUI lots of functionality, and binds to update, draw, interface events where needed, so I can use and reuse easily some components as bpm, fft, camera, lights, shader, multi windows output, syphon out, 3d preview, autopilot to work with presets.

with this I can import some functionality sometimes using just one line of code and one include, and sometimes copying a txt file to a project too.
This is helping working in different parallel projects at the same time. I’m packing all of this code as it was one ofxAddon, but they are just a lot of reusable .h and .cpp files

This is the “skeleton” class where others derive, kinda ugly but it works

struct microFeature {
	ofxMicroUISoftware * soft = NULL;
	string name = "";
	ofxMicroUI * ui = NULL;
	ofxMicroUI * ui2 = NULL;
	bool * use = NULL;
	bool isSetup = false;

	microFeature(ofxMicroUISoftware * _soft);
	// criei 28 de outubro de 2021 somente pra acomodar o featurecolor
	microFeature(ofxMicroUI * _ui);
	// fiz agora para Cairo.
	microFeature(ofxMicroUISoftware * _soft, ofxMicroUI * _ui, bool * u = NULL);
	microFeature(string n, ofxMicroUI * _ui, bool * u = NULL);
	microFeature(ofxMicroUISoftware * _soft, string n, bool * u = NULL);
	microFeature(ofxMicroUISoftware * _soft, ofxMicroUI * _ui, ofxMicroUI * _ui2);
	microFeature(ofxMicroUISoftware * _soft, string n, ofxMicroUI * _ui, ofxMicroUI * _ui2 = NULL);
	virtual void begin();
	virtual void end();
	virtual void internalSetup();

	virtual void setup();
	virtual void update();
	virtual void draw();
	virtual void draw(int x, int y);
	virtual void uiEvents(ofxMicroUI::element & e);

	virtual void uiEventMaster(string & s);

	virtual bool isOk();
	virtual void checkSetup();
	virtual void onUpdate(ofEventArgs &data);


Hey I’ve recently written a few of such templates for OF projects that use shaders. It saves some time, but it also helps to keep my code consistent from project to project.

I love dimitri’s example above and the idea of a virtual class that has essential elements and that can also be customized.

And custom classes in an addon can be a huge help. A custom class can inherit from an OF class, and/or combine various objects from OF or other addons. It can be used even if not all members are required for a given project.

So for instance I have a child class called ofxImage that inherits from ofImage and adds an ofDirectory, an ofParameter for an index into that directory, various methods, and etc. I am constantly using those objects together, so having them in a custom class as an addon is awesome as it saves some time but also really helps to keep things consistent and in a single place where it can be maintained.

1 Like

I’m happy to find recently that a simple class can use OF events and don’t need to start from ofBaseApp which have lots of dependencies, so I could add trackpad and middle mouse button in my 3d preview, now it works like Blender. Improvement in one place and instant results in multiple projects


Thanks for your suggestions. I put this aside to work on some more pressing issues but am once again starting a new project.

One thing I’m thinking about is that I often use similar code in the audioIn method, which overrides a virtual method in ofSoundBaseTypes.h, which is included in ofBaseApp. Is there a way to override it from a custom class? Or should I just do the override as usual in ofApp but make a method in my custom class that gets called from the ofApp’s override, eg:

void ofApp::audioIn(ofSoundBuffer& input) 

if I understand want you want to do, you can achieve it by using ofSoundStreamSettings:: setInListener() or ::setOutListener() and pointing to your class (which should probably hold an explicit ofSoundStream instance).

and/or maybe it’s logical to make your class a subclass of ofBaseSoundInput/ofBaseSoundOutput to inherit the interface, like ofBaseApp:

your class is expected to implement audioIn and/or audioOut.


Hey, thanks. I’ll try this at some point. I got distracted by another issue with my new project that I need to resolve first.

actually it’s quite related! in the other answer I made the processing explicit in the main setup() but it could also be integrated in a class (ex: a NoiseGenerator).

1 Like

Alright, I just replied in that thread with my new code. As you said, you can’t make a general solution without adding a ton of parameters to every method. Also, the way I have it set up currently, maybe it makes more sense to have ofxCustom be a static class instead of making an object (since I shouldn’t need more than one instance)…