Link Search Menu Expand Document

The example files in Allolib Playground have a typical structure; understanding this big picture structure can be helpful when getting started.

  1. #include and using namespace ... statements, plus global variables and utility functions
  2. definition of an instrument, e.g. class SineEnv : public SynthVoice {
  3. definition of an app, e.g. class MyApp : public App {
  4. a main program, e.g. int main() {

For example, here’s tutorials/synthesis/01_SineEnv_Piano.cpp, with the last three of these sections “collapsed” in VSCode. The first part doesn’t completely appear on the screen.

image

Here are some more explanations of each of these sections.

1. #include and using namespace ...

2. Define instrument (SynthVoice)

3. Define App (user interface)

We typically define a subclass of App, e.g. called MyApp which provides a user interface to interact with our instrument.

The first line looks like this, and indicates that MyApp inherits from App which is the App class of Allolib. For documentation of this, you can see:

class MyApp : public App {

4. a main program

The main program is typically not modified unless you want to:

  • change the size of the initial window that appears on the screen
  • change the default audio parameters: bit rate, block size, number of channels, number of audio inputs.
int main() {
  // Create app instance
  MyApp app;
  
  // Set window size
  app.dimensions(1200, 600);
  
  // Set up audio
  app.configureAudio(48000., 512, 2, 0);
  app.start();
  return 0;
}