ref: 1cc67b0d9400bcc0e751f2a631b2a1744859a5e4
dir: /piper/kick.c/
#include <u.h> #include <libc.h> #include "piper.h" typedef struct Kick Kick; struct Kick { struct { int freq; int attack; int release; }a; struct { int freq; int attack; int release; int enable; }b; int gate; int volume; char path[1]; }; static int cmd(void *aux, Cmd *c) { Kick *k; k = aux; switch (c->type) { case CmdNote: fprint(k->gate, "0"); fprint(k->volume, "%g", c->note[0].vel); fprint(k->a.freq, "%g", c->note[0].freq); fprint(k->a.release, "%g", c->note[0].dur); if (c->numnotes > 1) { fprint(k->b.freq, "%g", c->note[1].freq); fprint(k->b.release, "%g", c->note[1].dur); fprint(k->b.enable, "%g", c->note[1].vel); } else { fprint(k->b.enable, "0"); } fprint(k->gate, "1"); break; case CmdVol: fprint(k->volume, "%g", c->vol); break; case CmdRaw: break; } return 0; } static void * alloc(char *path) { Kick *k; if ((k = calloc(1, sizeof(*k) + strlen(path) + 1)) != nil) { k->a.freq = pathopen(path, "A/Frequency/ctl"); k->a.attack = pathopen(path, "A/Attack/ctl"); k->a.release = pathopen(path, "A/Release/ctl"); k->b.freq = pathopen(path, "B/Frequency/ctl"); k->b.attack = pathopen(path, "B/Attack/ctl"); k->b.release = pathopen(path, "B/Release/ctl"); k->b.enable = pathopen(path, "B/Enable/ctl"); k->gate = pathopen(path, "Control/Gate/ctl"); k->volume = pathopen(path, "Control/Gain/ctl"); strcpy(k->path, path); } return k; } Synth kick_drum = { .name = "Kick Drum", .cmd = cmd, .alloc = alloc, };