Skip to content

Commit

Permalink
Add basic device abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelforney committed Feb 26, 2024
1 parent 3f9617a commit 9cd349c
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 48 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ OSCMIX_OBJ=\
oscmix.o\
socket.o\
sysex.o\
util.o
util.o\
\
device_ffucxii.o

WSDGRAM_OBJ=\
wsdgram.o\
Expand Down
42 changes: 42 additions & 0 deletions device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef DEVICE_H
#define DEVICE_H

enum inputflags {
INPUT_GAIN = 1 << 0,
INPUT_REFLEVEL = 1 << 1,
INPUT_48V = 1 << 2,
INPUT_HIZ = 1 << 3,
};

struct inputinfo {
char name[12];
int flags;
};

enum outputflags {
OUTPUT_REFLEVEL = 1 << 0,
};

struct outputinfo {
const char *name;
int flags;
};

enum deviceflags {
DEVICE_DUREC = 1 << 0,
DEVICE_ROOMEQ = 1 << 1,
};

struct device {
const char *id;
const char *name;
int version;
int flags;

const struct inputinfo *inputs;
int inputslen;
const struct outputinfo *outputs;
int outputslen;
};

#endif
62 changes: 62 additions & 0 deletions device_ffucxii.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "device.h"

#define LEN(a) (sizeof (a) / sizeof *(a))

static const struct inputinfo inputs[] = {
{"Mic/Line 1", INPUT_GAIN | INPUT_48V},
{"Mic/Line 2", INPUT_GAIN | INPUT_48V},
{"Inst/Line 3", INPUT_GAIN | INPUT_REFLEVEL},
{"Inst/Line 4", INPUT_GAIN | INPUT_REFLEVEL},
{"Analog 5", INPUT_GAIN | INPUT_REFLEVEL},
{"Analog 6", INPUT_GAIN | INPUT_REFLEVEL},
{"Analog 7", INPUT_GAIN | INPUT_REFLEVEL},
{"Analog 8", INPUT_GAIN | INPUT_REFLEVEL},
{"SPDIF L"},
{"SPDIF R"},
{"AES L"},
{"AES R"},
{"ADAT 1"},
{"ADAT 2"},
{"ADAT 3"},
{"ADAT 4"},
{"ADAT 5"},
{"ADAT 6"},
{"ADAT 7"},
{"ADAT 8"},
};
_Static_assert(LEN(inputs) == 20, "bad inputs");

static const struct outputinfo outputs[] = {
{"Analog 1", OUTPUT_REFLEVEL},
{"Analog 2", OUTPUT_REFLEVEL},
{"Analog 3", OUTPUT_REFLEVEL},
{"Analog 4", OUTPUT_REFLEVEL},
{"Analog 5", OUTPUT_REFLEVEL},
{"Analog 6", OUTPUT_REFLEVEL},
{"Phones 7", OUTPUT_REFLEVEL},
{"Phones 8", OUTPUT_REFLEVEL},
{"SPDIF L"},
{"SPDIF R"},
{"AES L"},
{"AES R"},
{"ADAT 1"},
{"ADAT 2"},
{"ADAT 3"},
{"ADAT 4"},
{"ADAT 5"},
{"ADAT 6"},
{"ADAT 7"},
{"ADAT 8"},
};
_Static_assert(LEN(outputs) == 20, "bad outputs");

const struct device ffucxii = {
.id = "ffucxii",
.name = "Fireface UCX II",
.version = 30,
.flags = DEVICE_DUREC | DEVICE_ROOMEQ,
.inputs = inputs,
.inputslen = LEN(inputs),
.outputs = outputs,
.outputslen = LEN(outputs),
};
13 changes: 12 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ main(int argc, char *argv[])
pthread_t midireader, oscreader;
struct itimerval it;
sigset_t set;
const char *port;

if (fcntl(6, F_GETFD) < 0)
fatal("fcntl 6:");
Expand All @@ -135,6 +136,7 @@ main(int argc, char *argv[])

recvaddr = defrecvaddr;
sendaddr = defsendaddr;
port = NULL;

ARGBEGIN {
case 'd':
Expand All @@ -152,6 +154,9 @@ main(int argc, char *argv[])
case 'm':
sendaddr = mcastaddr;
break;
case 'p':
port = EARGF(usage());
break;
default:
usage();
break;
Expand All @@ -160,7 +165,13 @@ main(int argc, char *argv[])
rfd = sockopen(recvaddr, 1);
wfd = sockopen(sendaddr, 0);

init();
if (!port) {
port = getenv("MIDIPORT");
if (!port)
fatal("device is not specified; pass -p or set MIDIPORT");
}
if (init(port) != 0)
return 1;

sigfillset(&set);
pthread_sigmask(SIG_SETMASK, &set, NULL);
Expand Down
Loading

0 comments on commit 9cd349c

Please sign in to comment.