3. Top-level
3.1. Header File
#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.
#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;
}
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.
#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
.
{"monolith:version", pp_version, 0, 0, {CHR,___,___}},
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.
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
.
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.
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.
if (!strncmp(argv[1], "runt", 4)) {
return irunt_begin(argc - 1, argv + 1, runt_monolith_loader);
}
3.5.3. Check for 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.
#include "s9.scm.h"
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.
#ifdef MONOLITH_STRETCHER
int stretcher_main(int argc, char *argv[]);
#endif
#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.
#ifdef MONOLITH_STRETCHER
int monolith_jpm(int argc, char *argv[]);
#endif
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.
#ifdef MONOLITH_CFLOOP
int run_cfloop(int argc, char *argv[]);
#endif
#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.
#ifdef MONOLITH_SCRAMBLER
int scrambler_main(int argc, char *argv[]);
#endif
#ifdef MONOLITH_SCRAMBLER
if (!strcmp(argv[1], "scrambler")) {
return scrambler_main(argc - 1, argv + 1);
}
#endif
3.5.9. wavdraw
#ifdef MONOLITH_SCRAMBLER
int wavdraw_main(int argc, char *argv[]);
#endif
#ifdef MONOLITH_SCRAMBLER
if (!strcmp(argv[1], "wavdraw")) {
return wavdraw_main(argc - 1, argv + 1);
}
#endif
3.5.10. sndkit
int monolith_lil_main(int argc, char *argv[]);
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.
int minimp4_main(int argc, char *argv[]);
if (!strcmp(argv[1], "minimp4")) {
return minimp4_main(argc - 1, argv + 1);
}
prev | home | next