mirror of https://github.com/nealey/hdjd.git
Handles a single message, then segfaults
This commit is contained in:
parent
fbc59832be
commit
98c870b09b
18
alsa.c
18
alsa.c
|
@ -2,11 +2,13 @@
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <alsa/asoundlib.h>
|
#include <alsa/asoundlib.h>
|
||||||
|
#include "alsa.h"
|
||||||
#include "dump.h"
|
#include "dump.h"
|
||||||
|
|
||||||
static snd_seq_t *snd_handle;
|
static snd_seq_t *snd_handle;
|
||||||
static int seq_port;
|
static int seq_port;
|
||||||
static snd_midi_event_t *midi_event_parser;
|
static snd_midi_event_t *midi_event_parser;
|
||||||
|
static snd_seq_event_t *ev;
|
||||||
|
|
||||||
int
|
int
|
||||||
alsa_setup(const char *name)
|
alsa_setup(const char *name)
|
||||||
|
@ -22,11 +24,8 @@ alsa_setup(const char *name)
|
||||||
SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_READ |
|
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_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_MIDI_GENERIC);
|
||||||
|
|
||||||
if (snd_seq_event_input(handle, &ev) < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (snd_midi_event_new(256, &midi_event_parser) < 0) {
|
if (snd_midi_event_new(256, &midi_event_parser) < 0) {
|
||||||
|
perror("snd_midi_event_new");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,15 +62,12 @@ alsa_fd_setup(int *nfds, fd_set *rfds, fd_set *wfds)
|
||||||
void
|
void
|
||||||
alsa_read_ready()
|
alsa_read_ready()
|
||||||
{
|
{
|
||||||
snd_seq_event_t *ev;
|
|
||||||
int ret = 1;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char buf[256];
|
unsigned char buf[256];
|
||||||
long converted;
|
long converted;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (snd_seq_event_input(handle, &ev) < 0) {
|
if (snd_seq_event_input(snd_handle, &ev) < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!midi_event_parser) {
|
if (!midi_event_parser) {
|
||||||
|
@ -94,9 +90,9 @@ alsa_check_fds(fd_set *rfds, fd_set *wfds)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < npfd; i += 1) {
|
for (i = 0; i < npfd; i += 1) {
|
||||||
int fd = pfds[i]->fd;
|
int fd = pfd[i].fd;
|
||||||
|
|
||||||
if (FD_ISSET(fd, &rfds) || FD_ISSET(fd, &wfds)) {
|
if (FD_ISSET(fd, rfds) || FD_ISSET(fd, wfds)) {
|
||||||
alsa_read_ready();
|
alsa_read_ready();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
2
alsa.h
2
alsa.h
|
@ -6,5 +6,5 @@
|
||||||
int alsa_setup(const char *name);
|
int alsa_setup(const char *name);
|
||||||
void alsa_fd_setup(int *nfds, fd_set *rfds, fd_set *wfds);
|
void alsa_fd_setup(int *nfds, fd_set *rfds, fd_set *wfds);
|
||||||
void alsa_read_ready();
|
void alsa_read_ready();
|
||||||
|
void alsa_check_fds(fd_set *rfds, fd_set *wfds);
|
||||||
#endif
|
#endif
|
||||||
|
|
5
hdjd.c
5
hdjd.c
|
@ -45,7 +45,10 @@ main(int argc, char *argv[])
|
||||||
DUMP();
|
DUMP();
|
||||||
}
|
}
|
||||||
|
|
||||||
DUMP();
|
alsa_check_fds(&rfds, &wfds);
|
||||||
|
usb_check_fds(&rfds, &wfds);
|
||||||
|
|
||||||
|
//DUMP();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
32
usb.c
32
usb.c
|
@ -2,7 +2,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
#include "usb.h"
|
||||||
#include "dump.h"
|
#include "dump.h"
|
||||||
|
|
||||||
static struct libusb_device_handle *usb_dev;
|
static struct libusb_device_handle *usb_dev;
|
||||||
|
@ -48,12 +50,17 @@ usb_xfer_done(struct libusb_transfer *transfer)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
usb_setup(char *name, size_t namelen)
|
usb_setup(const char *name, size_t namelen)
|
||||||
{
|
{
|
||||||
if (libusb_init(NULL) < 0) {
|
if (libusb_init(NULL) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (libusb_pollfds_handle_timeouts(NULL) == 0) {
|
||||||
|
printf("I'm too dumb to handle events on such an old system.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
for (d = devices; d->product_id; d += 1) {
|
for (d = devices; d->product_id; d += 1) {
|
||||||
usb_dev = libusb_open_device_with_vid_pid(NULL, 0x6f8, d->product_id);
|
usb_dev = libusb_open_device_with_vid_pid(NULL, 0x6f8, d->product_id);
|
||||||
if (usb_dev) {
|
if (usb_dev) {
|
||||||
|
@ -69,12 +76,16 @@ usb_setup(char *name, size_t namelen)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct libusb_device_descriptor ddesc;
|
struct libusb_device_descriptor ddesc;
|
||||||
char *p = name;
|
char name_[200];
|
||||||
|
char *p = name_;
|
||||||
|
|
||||||
|
strncpy(name_, name, sizeof(name_) - 1);
|
||||||
|
name_[sizeof(name_) - 1] = 0;
|
||||||
|
|
||||||
libusb_get_device_descriptor(libusb_get_device(usb_dev), &ddesc);
|
libusb_get_device_descriptor(libusb_get_device(usb_dev), &ddesc);
|
||||||
ret = libusb_get_string_descriptor_ascii(usb_dev, ddesc.iManufacturer, (unsigned char *)name, namelen);
|
ret = libusb_get_string_descriptor_ascii(usb_dev, ddesc.iManufacturer, (unsigned char *)name, namelen);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
p = name + ret;
|
p = name_ + ret;
|
||||||
*p = ' ';
|
*p = ' ';
|
||||||
p += 1;
|
p += 1;
|
||||||
ret = libusb_get_string_descriptor_ascii(usb_dev, ddesc.iProduct, (unsigned char *)p, namelen - ret - 1);
|
ret = libusb_get_string_descriptor_ascii(usb_dev, ddesc.iProduct, (unsigned char *)p, namelen - ret - 1);
|
||||||
|
@ -110,12 +121,21 @@ usb_fd_setup(int *nfds, fd_set *rfds, fd_set *wfds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
usb_initiate_transfer();
|
usb_initiate_transfer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
usb_read_ready()
|
usb_check_fds(fd_set *rfds, fd_set *wfds)
|
||||||
{
|
{
|
||||||
libusb_handle_events(NULL);
|
const struct libusb_pollfd **usb_fds = libusb_get_pollfds(NULL);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; usb_fds[i]; i += 1) {
|
||||||
|
int fd = usb_fds[i]->fd;
|
||||||
|
|
||||||
|
if (FD_ISSET(fd, rfds) || FD_ISSET(fd, wfds)) {
|
||||||
|
libusb_handle_events(NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue