3. Top-level

3.1. Header File

<<header>>=
#ifndef MONOLITH_H
#define MONOLITH_H
<<enums>>
<<exported_macros>>
<<typedefs>>
<<callback_prototypes>>
<<function_declarations>>
#endif

3.2. C file

To start things off, we create an s9 interpreter with a single function added.

<<top>>=
#include <stdio.h>

#ifndef MONOLITH_SIMPLE
#include <jack/jack.h>
#endif

#include <math.h>
<<system_includes>>
#include "runt.h"
#include "graforge.h"
#include "soundpipe.h"
#include "runt_graforge.h"
#include "runt_ftbl.h"
#include "s9core.h"
#include "s9import.h"
#include "s9ext.h"
#include "scheme.h"

#ifdef MONOLITH_NORNS
#include <linux/input.h>
#include "norns.h"
#endif

#include "monolith.h"
#include "jan.h"

<<aux_includes>>

#ifndef MONOLITH_BLKSIZE
#define MONOLITH_BLKSIZE 64 /* blocksize for graforge */
#endif

#ifndef CROSSFADE_SIZE
#define CROSSFADE_SIZE 512
#endif

<<macros>>

int s9_main_with_loader(int argc, char *argv[], void (*loader)(void));
int janet_main(int argc, char *argv[]);
<<structs>>
<<global_struct>>
<<static_function_declarations>>
<<scheme_functions>>
<<primitive_table>>
<<loader>>
<<functions>>
int monolith_main(int argc, char *argv[])
{
    int rc;
<<check_for_keywords>>
    monolith_init(&g_monolith);
    rc = s9_main_with_loader(argc, argv, loader);
    monolith_cleanup(&g_monolith);
    return rc;
}
<<function_declarations>>=
int monolith_main(int argc, char *argv[]);

3.3. main.c

This is generated separately from the rest of the gang, in order for a libmonolith to exist.

<<main.c>>=
#include <stdio.h>
#include "runt.h"
#include "graforge.h"
#include "monolith.h"

int main(int argc, char *argv[])
{
    return monolith_main(argc, argv);
}

3.4. Version Number

The version number is determined with the macro MONOLITH_VERSION. It is sourced from the current fossil checkout hash, and the macro is using CFLAGS inside the Makefile. The version string can be retrieved using the function monolith:version.

<<primitive_entries>>=
{"monolith:version", pp_version, 0, 0, {CHR,___,___}},
<<scheme_functions>>=
static cell pp_version(cell x) {
    return s9_make_string(MONOLITH_VERSION, strlen(MONOLITH_VERSION));
}

3.5. Subprograms

Monolith has a few sub programs that can be run from the commandline, using a style similar to that of git.

The codeblock below checks for keywords, and if it finds a match, runs the program associated with it.

<<check_for_keywords>>=
if(argc > 1) {
<<start_sqlar>>
<<start_runt>>
#ifdef USE_JANET
<<start_janet>>
#endif
<<start_mkimg>>
<<start_stretcher>>
#ifdef USE_JANET
<<start_jpm>>
#endif
<<start_cfloop>>
<<start_scrambler>>
<<start_wavdraw>>
<<start_sndkit>>
}

3.5.1. Check for SQLar

Embedded in Monolith is SQLar, the SQLite archiver. This is a special third party utility that can utilize SQLite as an archive file. The SQLar program can be instantiated with the function sqlar_main.

<<static_function_declarations>>=
int sqlar_main(int argc, char **argv);

The sqlar program can be run using the command monolith sqlar. When this happens, the sqlar CLI will run instead of the default monolith REPL. Arguments passed after that will be treated as command line arguments to SQLar.

<<start_sqlar>>=
if (!strncmp(argv[1], "sqlar", 5)) {
    return sqlar_main(argc - 1, argv + 1);
}

3.5.2. Check for Runt

The runt interpretor for Monolith can be loaded explicitely using the word "runt". This will start an irunt interpretor via irunt_begin. This can be used to run runt code directly, rather than through the scheme interface.

<<start_runt>>=
if (!strncmp(argv[1], "runt", 4)) {
    return irunt_begin(argc - 1, argv + 1, runt_monolith_loader);
}

3.5.3. Check for Janet

Runs the janet interpreter.

<<start_janet>>=
if (!strncmp(argv[1], "janet", 5)) {
    return janet_main(argc - 1, argv + 1);
}

3.5.4. mkimg

Used to generated a monolith image monolith.image.

This will also need to write a version of s9.scm, which is embedded in this program.

<<aux_includes>>=
#include "s9.scm.h"
<<start_mkimg>>=
if (!strncmp(argv[1], "mkimg", 5)) {
    int img_argc;
    FILE *fp;
    char *img_argv[] = {
        "monolith",
        "-i", "-",
        "-d", "monolith.image"
    };
    img_argc = 5;
    fp = fopen("s9.scm", "w");
    fwrite(s9_scm, 1, s9_scm_len, fp);
    fclose(fp);
    printf("Attempting to generate monolith.image\n");
    return s9_main_with_loader(img_argc, img_argv, loader);
}

3.5.5. Stretcher

Stretcher is a small command line utility used to apply the paulstretch algorithm to audio files. This is only enabled if MONOLITH_STRETCHER is defined.

<<static_function_declarations>>=
#ifdef MONOLITH_STRETCHER
int stretcher_main(int argc, char *argv[]);
#endif
<<start_stretcher>>=
#ifdef MONOLITH_STRETCHER
if (!strcmp(argv[1], "stretcher")) {
    return stretcher_main(argc - 1, argv + 1);
}
#endif

3.5.6. JPM (Janet Plugin Manager)

The Janet Plugin Manager is used to build janet plugins. This version of JPM is built to run internally inside of monolith.

<<static_function_declarations>>=
#ifdef MONOLITH_STRETCHER
int monolith_jpm(int argc, char *argv[]);
#endif
<<start_jpm>>=
if (!strcmp(argv[1], "jpm")) {
    return monolith_jpm(argc - 1, argv + 1);
}

3.5.7. cfloop

cfloop is a tiny crossfade looper generator for wav files.

<<static_function_declarations>>=
#ifdef MONOLITH_CFLOOP
int run_cfloop(int argc, char *argv[]);
#endif
<<start_cfloop>>=
#ifdef MONOLITH_CFLOOP
if (!strcmp(argv[1], "cfloop")) {
    return run_cfloop(argc - 1, argv + 1);
}
#endif

3.5.8. scrambler

scrambler is an offline FFT scrambler.

<<static_function_declarations>>=
#ifdef MONOLITH_SCRAMBLER
int scrambler_main(int argc, char *argv[]);
#endif
<<start_scrambler>>=
#ifdef MONOLITH_SCRAMBLER
if (!strcmp(argv[1], "scrambler")) {
    return scrambler_main(argc - 1, argv + 1);
}
#endif

3.5.9. wavdraw

wavdraw draws a waveform.

<<static_function_declarations>>=
#ifdef MONOLITH_SCRAMBLER
int wavdraw_main(int argc, char *argv[]);
#endif
<<start_wavdraw>>=
#ifdef MONOLITH_SCRAMBLER
if (!strcmp(argv[1], "wavdraw")) {
    return wavdraw_main(argc - 1, argv + 1);
}
#endif

3.5.10. sndkit

<<static_function_declarations>>=
int monolith_lil_main(int argc, char *argv[]);
<<start_sndkit>>=
if (!strcmp(argv[1], "sndkit")) {
    return monolith_lil_main(argc - 1, argv + 1);
}

3.5.11. minimp4

A modified version of the test program that comes with minimp4.

<<static_function_declarations>>=
int minimp4_main(int argc, char *argv[]);
<<start_sndkit>>=
if (!strcmp(argv[1], "minimp4")) {
    return minimp4_main(argc - 1, argv + 1);
}



prev | home | next