ref: ea5ba1c288fd5aa77c5362699e0229b1e07e35ec
parent: 0c08554afecf7dacc2cda3fdb70c5d7f4fc0e28f
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sun Feb 23 16:57:53 EST 2020
plan9: add midi CC and PB; default to CN=0 (need midifs)
--- a/plan9.c
+++ b/plan9.c
@@ -53,6 +53,8 @@
/* this might become a bad idea in the future */
Mark_flag_group_highlight = 1<<6,
Mark_flag_selected = 1<<7,
+
+ Midicn = 0<<4, /* cable number. FIXME: write midifs */
};
typedef struct Snap Snap;
@@ -517,35 +519,62 @@
static void
process(Oevent_list *events)
{
- int i, off;
+ int i, off, t;
Oevent *e;
u8int u[4];
char tmp[64];
for (e = events->buffer, i = 0; i < events->count; i++, e++) {
- if (e->any.oevent_type == Oevent_type_midi_note) {
- Oevent_midi_note *n = &e->midi_note;
- u[0] = 1;
- u[1] = 0x90 | n->channel;
- u[2] = (n->octave + 1)*12 + n->note;
- u[3] = n->velocity;
- if (midi >= 0)
+ t = e->any.oevent_type;
+
+ if (midi >= 0) {
+ if (t == Oevent_type_midi_note) {
+ Oevent_midi_note *n = &e->midi_note;
+ u[0] = Midicn | 0x9;
+ u[1] = 0x90 | n->channel;
+ u[2] = (n->octave + 1)*12 + n->note;
+ u[3] = n->velocity;
write(midi, u, 4);
- off = n->channel*128 + u[2];
- noteoff[off].u[1] = 0x80 | n->channel;
- noteoff[off].u[2] = u[2];
- noteoff[off].u[3] = 0;
- noteoff[off].at = tick + n->duration;
- } else if (e->any.oevent_type == Oevent_type_cmd_string) {
+ off = n->channel*128 + u[2];
+ noteoff[off].u[0] = Midicn | 0x8;
+ noteoff[off].u[1] = 0x80 | n->channel;
+ noteoff[off].u[2] = u[2];
+ noteoff[off].u[3] = 0;
+ noteoff[off].at = tick + n->duration;
+ continue;
+ } else if (t == Oevent_type_midi_cc) {
+ Oevent_midi_cc *c = &e->midi_cc;
+ u[0] = Midicn | 0xb;
+ u[1] = 0xb0 | c->channel;
+ u[2] = c->control;
+ u[3] = c->value;
+ write(midi, u, 4);
+ continue;
+ } else if (t == Oevent_type_midi_pb) {
+ Oevent_midi_pb *p = &e->midi_pb;
+ u[0] = Midicn | 0xe;
+ u[1] = 0xe0 | p->channel;
+ u[2] = p->lsb;
+ u[3] = p->msb;
+ write(midi, u, 4);
+ continue;
+ }
+ }
+
+ if (udp >= 0) {
+ if (t == Oevent_type_udp_string) {
+ Oevent_udp_string *u = &e->udp_string;
+ write(udp, u->chars, u->count); /* FIXME show errors */
+ continue;
+ }
+ }
+
+ if (t == Oevent_type_cmd_string) {
Oevent_cmd_string *c = &e->cmd_string;
memmove(tmp, c->chars, c->count);
tmp[c->count] = 0;
command(tmp, nosnapshot);
- } else if (e->any.oevent_type = Oevent_type_udp_string) {
- Oevent_udp_string *u = &e->udp_string;
- if (udp >= 0)
- write(udp, u->chars, u->count); /* FIXME show errors */
}
}