aboutsummaryrefslogtreecommitdiffhomepage
path: root/backends
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2019-12-05 19:31:14 +0100
committercbdev <cb@cbcdn.com>2019-12-05 19:31:14 +0100
commit9c37eddad24eb7e9bbc9aae723b3a992ec5b4c97 (patch)
tree0488f962a93cc4ba6406828042c74d0931b962b4 /backends
parent8979c52e767791f97f462835a9e4c5e66d1112cc (diff)
downloadmidimonster-9c37eddad24eb7e9bbc9aae723b3a992ec5b4c97.tar.gz
midimonster-9c37eddad24eb7e9bbc9aae723b3a992ec5b4c97.tar.bz2
midimonster-9c37eddad24eb7e9bbc9aae723b3a992ec5b4c97.zip
Unify midi parsing/deparsing code
Diffstat (limited to 'backends')
-rw-r--r--backends/jack.c8
-rw-r--r--backends/winmidi.c89
-rw-r--r--backends/winmidi.h10
3 files changed, 35 insertions, 72 deletions
diff --git a/backends/jack.c b/backends/jack.c
index 192aab2..926f800 100644
--- a/backends/jack.c
+++ b/backends/jack.c
@@ -98,20 +98,20 @@ static int mmjack_process_midi(instance* inst, mmjack_port* port, size_t nframes
//ident.fields.port set on output in mmjack_handle_midi
ident.fields.sub_channel = event.buffer[0] & 0x0F;
ident.fields.sub_type = event.buffer[0] & 0xF0;
+ ident.fields.sub_control = event.buffer[1];
+ value = event.buffer[2];
if(ident.fields.sub_type == 0x80){
ident.fields.sub_type = midi_note;
value = 0;
}
else if(ident.fields.sub_type == midi_pitchbend){
+ ident.fields.sub_control = 0;
value = event.buffer[1] | (event.buffer[2] << 7);
}
else if(ident.fields.sub_type == midi_aftertouch){
+ ident.fields.sub_control = 0;
value = event.buffer[1];
}
- else{
- ident.fields.sub_control = event.buffer[1];
- value = event.buffer[2];
- }
//append midi data
mmjack_midiqueue_append(port, ident, value);
}
diff --git a/backends/winmidi.c b/backends/winmidi.c
index bda5401..b274c06 100644
--- a/backends/winmidi.c
+++ b/backends/winmidi.c
@@ -203,35 +203,17 @@ static int winmidi_set(instance* inst, size_t num, channel** c, channel_value* v
for(u = 0; u < num; u++){
ident.label = c[u]->ident;
- switch(ident.fields.type){
- case note:
- output.components.status = 0x90 | ident.fields.channel;
- output.components.data1 = ident.fields.control;
- output.components.data2 = v[u].normalised * 127.0;
- break;
- case cc:
- output.components.status = 0xB0 | ident.fields.channel;
- output.components.data1 = ident.fields.control;
- output.components.data2 = v[u].normalised * 127.0;
- break;
- case pressure:
- output.components.status = 0xA0 | ident.fields.channel;
- output.components.data1 = ident.fields.control;
- output.components.data2 = v[u].normalised * 127.0;
- break;
- case aftertouch:
- output.components.status = 0xD0 | ident.fields.channel;
- output.components.data1 = v[u].normalised * 127.0;
- output.components.data2 = 0;
- break;
- case pitchbend:
- output.components.status = 0xE0 | ident.fields.channel;
- output.components.data1 = ((int)(v[u].normalised * 16384.0)) & 0x7F;
- output.components.data2 = (((int)(v[u].normalised * 16384.0)) >> 7) & 0x7F;
- break;
- default:
- fprintf(stderr, "Unknown winmidi channel type %d\n", ident.fields.type);
- continue;
+ //build output message
+ output.components.status = ident.fields.type | ident.fields.channel;
+ output.components.data1 = ident.fields.control;
+ output.components.data2 = v[u].normalised * 127.0;
+ if(ident.fields.type == pitchbend){
+ output.components.data1 = ((int)(v[u].normalised * 16384.0)) & 0x7F;
+ output.components.data2 = (((int)(v[u].normalised * 16384.0)) >> 7) & 0x7F;
+ }
+ else if(ident.fields.type == aftertouch){
+ output.components.data1 = v[u].normalised * 127.0;
+ output.components.data2 = 0;
}
midiOutShortMsg(data->device_out, output.dword);
@@ -330,40 +312,21 @@ static void CALLBACK winmidi_input_callback(HMIDIIN device, unsigned message, DW
//param1 has the message
input.dword = param1;
ident.fields.channel = input.components.status & 0x0F;
- switch(input.components.status & 0xF0){
- case 0x80:
- ident.fields.type = note;
- ident.fields.control = input.components.data1;
- val.normalised = 0.0;
- break;
- case 0x90:
- ident.fields.type = note;
- ident.fields.control = input.components.data1;
- val.normalised = (double) input.components.data2 / 127.0;
- break;
- case 0xA0:
- ident.fields.type = pressure;
- ident.fields.control = input.components.data1;
- val.normalised = (double) input.components.data2 / 127.0;
- break;
- case 0xB0:
- ident.fields.type = cc;
- ident.fields.control = input.components.data1;
- val.normalised = (double) input.components.data2 / 127.0;
- break;
- case 0xD0:
- ident.fields.type = aftertouch;
- ident.fields.control = 0;
- val.normalised = (double) input.components.data1 / 127.0;
- break;
- case 0xE0:
- ident.fields.type = pitchbend;
- ident.fields.control = 0;
- val.normalised = (double)((input.components.data2 << 7) | input.components.data1) / 16384.0;
- break;
- default:
- fprintf(stderr, "winmidi unhandled status byte %02X\n", input.components.status);
- return;
+ ident.fields.type = input.components.status & 0xF0;
+ ident.fields.control = input.components.data1;
+ val.normalised = (double) input.components.data2 / 127.0;
+
+ if(ident.fields.type == 0x80){
+ ident.fields.type = note;
+ val.normalised = 0;
+ }
+ else if(ident.fields.type == pitchbend){
+ ident.fields.control = 0;
+ val.normalised = (double)((input.components.data2 << 7) | input.components.data1) / 16384.0;
+ }
+ else if(ident.fields.type == aftertouch){
+ ident.fields.control = 0;
+ val.normalised = (double) input.components.data1 / 127.0;
}
break;
case MIM_LONGDATA:
diff --git a/backends/winmidi.h b/backends/winmidi.h
index ffa6a26..8c2d76b 100644
--- a/backends/winmidi.h
+++ b/backends/winmidi.h
@@ -19,11 +19,11 @@ typedef struct /*_winmidi_instance_data*/ {
enum /*_winmidi_channel_type*/ {
none = 0,
- note,
- cc,
- pressure,
- aftertouch,
- pitchbend
+ note = 0x90,
+ cc = 0xB0,
+ pressure = 0xA0,
+ aftertouch = 0xD0,
+ pitchbend = 0xE0
};
typedef union {