Macros
Wednesday 29 July 2020
If we dig through the generated files in a JUCE application, we won’t find our familiar
main() function. There is, however, a macro START_JUCE_APPLICATION() at the end of
Main.cpp.
That’s what we refer to as a macro. A macro is a piece of functionality that’s hidden
away by what we call the Preprocessor. The preprocessor runs before the compiler proper,
and for the sake of brevity, sometimes we use macros to generate code for us.
Macros are simple text-substitution routines. For example if we have
#define THE_ANSWER 42
int main()
std::cout << "the answer to the ultimate question of "
<< "life, the universe, and everything is "
<< THE_ANSWER
<< std::endl;
}
What will is that the preprocessor will take this file as input and output something
akin to the version below:
int main()
{
std::cout << "the answer to the ultimate question of "
<< "life, the universe, and everything is "
<< 42
<< std::endl;
}
Notice how the macro THE_ANSWER got removed and all of its occurrences (granted,
there was only one) got replaced with its value.
Some simple expressions can also be evaluated during preprocessor time.
More posts in cpp
- Add a component ID and converting between ints and strings
- Implement a play button and add a listener
- Implement paintRowBackground and paintCell
- Add a vector to store a list of files
- Add a TableListBox
- Create a PlaylistComponent in the Projucer project
- Threads
- Implement a timer
- Add getPosition and setPosition functions
- Refactor DJAudioPlayer to use app-scope formatManager
- Draw the thumbnail
- Hook up the load button to trigger the AudioThumbnail load
- The AudioThumbnail class in the API
- Creating a new component - WaveformDisplay
- Implementing drag and drop triggers
- Use a MixerAudioSource to play more than one file at a time
- Implement the listener interfaces to DeckGUI
- Creating a DeckGUI class
- setPosition control
- Implementing setGain and setSpeed
- Add audio playback functionality
- Writing the DJAudioPlayer class
- Creating a new JUCE class with Projucer
- Refactoring our code
- Using ResamplingAudioPlayer to implement variable speed playback
- Add stop, start and volume functionality
- Add a file chooser
- Audio file playback in JUCE
- Realtime sound synthesis in JUCE
- Adding a slider listener
- Introduction to event listeners
- Macros
- Inheritance
- Adding a GUI widget to the JUCE app
- Introduction to JUCE