Probably a Noob-ish C++ Question about the "Build a Midi Synthesizer" Tutorial

Howdy! I’m walking myself through the “Build A Midi Synthesizer” tutorial here:

https://docs.juce.com/master/tutorial_synth_using_midi_input.html

And I’ve run into two bits of syntax I don’t understand in the startNote function. (I am new to C++ in addition to JUCE, so my apologies if this is really basic stuff. I’m coming from only a basic understanding of Java.) The function starts as follows:

void startNote (int midiNoteNumber, float velocity,

SynthesiserSound*, int /*currentPitchWheelPosition*/) override

  1. What is happening with the “SynthesizerSound*” argument being passed into the function? I’ve not seen a declaration (of a pointer or otherwise) without a variable name like that, and it doesn’t seem like it’s used at all in the function itself.

  2. What is happening with the “int /*currentPitchWheelPosition*/” argument? Is “currentPitchWheelPosition” actually commented out (making it like the above example, a type but no variable name), or is this another piece of syntax I don’t understand?

If it’s easier to link me to some basic C++ tutorials covering these topics that would also be greatly appreciated. I just didn’t have much luck searching for “pointer without name variable argument function C++” =P

Thanks and cheers,
John

In the tutorial code, apparently the SynthesiserSound object is not used in the method, so the pointer variable is omitted entirely from the arguments. The pitch wheel position variable is also omitted but the potential variable name you might want to use is put in the comments. (Maybe a later tutorial is going to actually use it…?) I think they did the code that way to avoid compiler warnings about unused variables.

You could change the code to something like :

void startNote (int midiNoteNumber, float velocity, SynthesiserSound* sound, int currentPitchWheelPosition)

But you would then get (harmless) compiler warnings…

Thanks very much for the quick reply! Just out of curiosity, do they need to be there because it’s overriding another function that usually takes those arguments? Or are they just there because the creator of the tutorial thought it was worth highlighting the fact that one would usually be using those variables in a “startNote” function?

They need to be there because the virtual function signature is like that.

Thanks again!

JUCE also contains a template function ignoreUnused() that accomplishes the same thing – squelches compiler warnings about unused parameters and also documents that you’re not using the argument intentionally.

2 Likes