mirror of https://github.com/nealey/hdjd.git
Now relays controller events to a virtual midi device
This commit is contained in:
parent
dcaa85e4bb
commit
d118941b59
3
Makefile
3
Makefile
|
@ -2,7 +2,8 @@ all: hdjd aac123
|
||||||
|
|
||||||
hdjd: CFLAGS += $(shell pkg-config --cflags libusb-1.0)
|
hdjd: CFLAGS += $(shell pkg-config --cflags libusb-1.0)
|
||||||
hdjd: LDFLAGS += $(shell pkg-config --libs libusb-1.0)
|
hdjd: LDFLAGS += $(shell pkg-config --libs libusb-1.0)
|
||||||
|
hdjd: CFLAGS += $(shell pkg-config --cflags alsa)
|
||||||
|
hdjd: LDFLAGS += $(shell pkg-config --libs alsa)
|
||||||
|
|
||||||
aac123: CFLAGS += $(shell pkg-config --cflags alsa)
|
aac123: CFLAGS += $(shell pkg-config --cflags alsa)
|
||||||
aac123: LDLIBS += $(shell pkg-config --libs alsa)
|
aac123: LDLIBS += $(shell pkg-config --libs alsa)
|
||||||
|
|
82
hdjd.c
82
hdjd.c
|
@ -1,6 +1,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <libusb.h>
|
#include <libusb.h>
|
||||||
|
#include <alsa/asoundlib.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Some things I use for debugging
|
* Some things I use for debugging
|
||||||
|
@ -17,46 +18,101 @@
|
||||||
#define DUMP_c(v) DUMPf("%s = '%c' (0x%02x)", #v, v, v)
|
#define DUMP_c(v) DUMPf("%s = '%c' (0x%02x)", #v, v, v)
|
||||||
#define DUMP_p(v) DUMPf("%s = %p", #v, v)
|
#define DUMP_p(v) DUMPf("%s = %p", #v, v)
|
||||||
|
|
||||||
// Steel: 0xb102, 0x83, 0x03
|
struct device {
|
||||||
// MP3e2: 0x0b105, 0x82,
|
uint16_t product_id;
|
||||||
// 4set: 0xb10c, 0x84, 0x02
|
uint8_t ep_in;
|
||||||
|
uint8_t ep_out;
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct device devices[] = {
|
||||||
|
{ 0xb102, 0x83, 0x04 },
|
||||||
|
{ 0xb105, 0x82, 0x03 },
|
||||||
|
{ 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct libusb_device_handle *handle;
|
static snd_seq_t *handle;
|
||||||
|
struct libusb_device_handle *dev;
|
||||||
|
struct libusb_device_descriptor ddesc;
|
||||||
|
char name[100];
|
||||||
|
const struct device *d;
|
||||||
|
snd_midi_event_t *midi_event_parser;
|
||||||
|
int seq_port;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (libusb_init(NULL) < 0) {
|
if (libusb_init(NULL) < 0) {
|
||||||
return 69;
|
return 69;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle = libusb_open_device_with_vid_pid(NULL, 0x06f8, 0xb102);
|
for (d = devices; d->product_id; d += 1) {
|
||||||
if (!handle) {
|
dev = libusb_open_device_with_vid_pid(NULL, 0x6f8, d->product_id);
|
||||||
|
if (dev) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!dev) {
|
||||||
printf("Couldn't find a controller\n");
|
printf("Couldn't find a controller\n");
|
||||||
return 69;
|
return 69;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Figure out what this thing is called
|
||||||
|
libusb_get_device_descriptor(libusb_get_device(dev), &ddesc);
|
||||||
|
{
|
||||||
|
char *p = name;
|
||||||
|
|
||||||
|
ret = libusb_get_string_descriptor_ascii(dev, ddesc.iManufacturer, name, sizeof(name));
|
||||||
|
if (ret > 0) {
|
||||||
|
p = name + ret;
|
||||||
|
*p = ' ';
|
||||||
|
p += 1;
|
||||||
|
ret = libusb_get_string_descriptor_ascii(dev, ddesc.iProduct, p, sizeof(name) - ret - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
printf("Can't figure out what to call this thing.\n");
|
||||||
|
return 69;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("Opened a %s\n", name);
|
||||||
|
|
||||||
|
if (snd_seq_open(&handle, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0) {
|
||||||
|
perror("snd_seq_open");
|
||||||
|
return(69);
|
||||||
|
}
|
||||||
|
snd_seq_nonblock(handle, 1);
|
||||||
|
snd_seq_set_client_name(handle, name);
|
||||||
|
seq_port = snd_seq_create_simple_port(handle, name,
|
||||||
|
SND_SEQ_PORT_CAP_READ |
|
||||||
|
SND_SEQ_PORT_CAP_WRITE |
|
||||||
|
SND_SEQ_PORT_CAP_SUBS_READ |
|
||||||
|
SND_SEQ_PORT_CAP_SUBS_WRITE,
|
||||||
|
SND_SEQ_PORT_TYPE_MIDI_GENERIC);
|
||||||
|
snd_midi_event_new(256, &midi_event_parser);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
uint8_t data[80];
|
uint8_t data[80];
|
||||||
int transferred;
|
int transferred;
|
||||||
int i;
|
int i;
|
||||||
|
snd_seq_event_t ev;
|
||||||
|
|
||||||
if ((ret = libusb_bulk_transfer(handle, 0x83, data, sizeof data, &transferred, 0))) {
|
if ((ret = libusb_bulk_transfer(dev, 0x83, data, sizeof data, &transferred, 0))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < transferred; i += 1) {
|
for (i = 0; i < transferred; i += 1) {
|
||||||
printf("%02x ", data[i]);
|
printf("%02x ", data[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
snd_midi_event_encode(midi_event_parser, data, transferred, &ev);
|
||||||
|
snd_seq_ev_set_direct(&ev);
|
||||||
|
snd_seq_ev_set_source(&ev, seq_port);
|
||||||
|
snd_seq_ev_set_subs(&ev);
|
||||||
|
snd_seq_event_output(handle, &ev);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
snd_seq_drain_output(handle);
|
||||||
// Cram it back out, to turn that light on
|
|
||||||
if ((ret = libusb_bulk_transfer(handle, 0x04, data, transferred, &transferred, 0))) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|
Loading…
Reference in New Issue