shithub: neindaw

ref: 11bee08c7da60c752092e5ada1ede8a9dc916a68
dir: /piper/kick.c/

View raw version
#include <u.h>
#include <libc.h>
#include "piper.h"
#include "util.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 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,
};