aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2017-06-07 23:42:51 +0200
committercbdev <cb@cbcdn.com>2017-06-07 23:42:51 +0200
commit804b5c3b3abbac7b95d79bf84fabbb78d94e2c39 (patch)
tree5a8a54ea90351720f2b0a0853f61d1c85f9a9de6
parent00c273f6ce28fe267c483b20d1edf4630f5b741f (diff)
downloadmidimonster-804b5c3b3abbac7b95d79bf84fabbb78d94e2c39.tar.gz
midimonster-804b5c3b3abbac7b95d79bf84fabbb78d94e2c39.tar.bz2
midimonster-804b5c3b3abbac7b95d79bf84fabbb78d94e2c39.zip
ArtNet input
-rw-r--r--artnet.c40
-rw-r--r--artnet.h16
-rw-r--r--monster.cfg9
3 files changed, 44 insertions, 21 deletions
diff --git a/artnet.c b/artnet.c
index 80db7f3..599a6c4 100644
--- a/artnet.c
+++ b/artnet.c
@@ -199,7 +199,7 @@ static channel* artnet_channel(instance* instance, char* spec){
fprintf(stderr, "Invalid ArtNet channel %s\n", spec);
return NULL;
}
- return mm_channel(instance, channel, 1);
+ return mm_channel(instance, channel - 1, 1);
}
static int artnet_set(instance* inst, size_t num, channel** c, channel_value* v){
@@ -222,7 +222,7 @@ static int artnet_set(instance* inst, size_t num, channel** c, channel_value* v)
if(mark){
//output frame
- artnet_output_pkt frame = {
+ artnet_pkt frame = {
.magic = {'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
.opcode = htobe16(OpDmx),
.version = htobe16(ARTNET_VERSION),
@@ -244,9 +244,17 @@ static int artnet_set(instance* inst, size_t num, channel** c, channel_value* v)
}
static int artnet_handle(size_t num, managed_fd* fds){
- size_t u;
+ size_t u, p;
ssize_t bytes_read;
char recv_buf[ARTNET_RECV_BUF];
+ artnet_instance_id inst_id = {
+ .label = 0
+ };
+ instance* inst = NULL;
+ channel* chan = NULL;
+ channel_value val;
+ artnet_instance_data* data;
+ artnet_pkt* frame = (artnet_pkt*) recv_buf;
if(!num){
//early exit
return 0;
@@ -255,8 +263,30 @@ static int artnet_handle(size_t num, managed_fd* fds){
for(u = 0; u < num; u++){
do{
bytes_read = recv(fds[u].fd, recv_buf, sizeof(recv_buf), 0);
- if(bytes_read > sizeof(artnet_header)){
- fprintf(stderr, "Possible artnet data\n");
+ if(bytes_read > sizeof(artnet_hdr)){
+ if(!memcmp(frame->magic, "Art-Net\0", 8) && be16toh(frame->opcode) == OpDmx){
+ //find matching instance
+ inst_id.fields.net = frame->net;
+ inst_id.fields.uni = frame->universe;
+ inst = mm_instance_find(BACKEND_NAME, inst_id.label);
+ if(inst){
+ data = (artnet_instance_data*) inst->impl;
+
+ //read data, notify of changes
+ for(p = 0; p < be16toh(frame->length); p++){
+ if(frame->data[p] != data->data.in[p]){
+ data->data.in[p] = frame->data[p];
+ chan = mm_channel(inst, p, 0);
+ val.raw.u64 = frame->data[p];
+ val.normalised = (double)frame->data[p] / 255.0;
+ if(chan && mm_channel_event(chan, val)){
+ fprintf(stderr, "Failed to push ArtNet channel event to core\n");
+ return 1;
+ }
+ }
+ }
+ }
+ }
}
} while(bytes_read > 0);
diff --git a/artnet.h b/artnet.h
index fa8d16e..dc90e19 100644
--- a/artnet.h
+++ b/artnet.h
@@ -51,21 +51,13 @@ enum {
mark = 2
};
-typedef struct /*_artnet_pkt_header*/ {
+typedef struct /*_artnet_hdr*/ {
uint8_t magic[8];
uint16_t opcode;
uint16_t version;
-} artnet_header;
+} artnet_hdr;
-typedef struct /*_artnet_input_pkt*/ {
- uint8_t sequence;
- uint8_t port;
- uint8_t universe;
- uint8_t net;
- uint16_t length;
-} artnet_input_pkt;
-
-typedef struct /*_artnet_output_pkt*/ {
+typedef struct /*_artnet_pkt*/ {
uint8_t magic[8];
uint16_t opcode;
uint16_t version;
@@ -75,7 +67,7 @@ typedef struct /*_artnet_output_pkt*/ {
uint8_t net;
uint16_t length;
uint8_t data[512];
-} artnet_output_pkt;
+} artnet_pkt;
enum artnet_pkt_opcode {
OpDmx = 0x0050
diff --git a/monster.cfg b/monster.cfg
index 561649a..128efcd 100644
--- a/monster.cfg
+++ b/monster.cfg
@@ -2,7 +2,7 @@
name = MIDIMonster
[backend artnet]
-bind = 127.0.0.1 6454
+bind = * 6454
net = 0
;[backend osc]
@@ -18,8 +18,8 @@ write = BCF
[midi xlate]
[artnet net1]
-net = 1
-uni = 1
+net = 0
+uni = 0
output = true
[map]
@@ -27,7 +27,8 @@ bcf.cc0.81 = lc1.cc0.1
lc1.cc0.1 = bcf.cc0.81
bcf.cc0.82 = lc1.note0.9
net1.15 = bcf.cc0.82
-;net1.256 = lc1.note0.9
+bcf.cc0.1 = net1.1
+bcf.cc0.2 = net1.3
;net1.257 = bcf.cc0.81
;net1.231 = foo.1
;net1.255 = lc1.cc0.1