[PD] midiout broken

federico xaero at inwind.it
Mon Nov 14 23:22:38 CET 2005


günter geiger ha scritto:

>On Sun, 13 Nov 2005, federico wrote:
>  
>
>>I don't see any changes from my local version.
>>last time I checked midiout functionality with alsa_midi, note and
>>controllers worked ok, but system exclusive were not transmitted.
>>in fact I discovered that sys_alsa_putmidibyte never gets called (!).
>>in addition I am not sure if a message can be sent to alsa byte-per-byte
>>instead of passing the entire buffer, i should look at the docs...
>>    
>>
>
>I fear that in order to make midiout work with ALSA one has to implement
>a midi parser and send the single events. Thats why Miller says its
>"wrong-headed".
>
>Somone should really try to figure out how raw midi streams can be
>sent via the ALSA sequencer interface, maybe there's a way.
>  
>
this patch was submitted time ago.
what does tries to fix?
it simply parses for system exclusive messages (they begin with 0xf0 and 
end with 0xf7) so we put everithing that comes between 0xf0...0xf7 in a 
buffer, and when receiving the 0xf7 byte (end-of-sysex) we send the 
entire buffer to alsa.
this should be the right way of doing it.
since note&controllers worked, i think it is okay sending them like we 
actually do.

however when I tried this didn't work because sys_alsa_putmidibyte 
doesn't gets called.
how do I re-enable it?


--- pd-0.39-1.orig/src/s_midi_alsa.c    2005-08-20 01:25:19.000000000 +0200
+++ pd-0.39-1/src/s_midi_alsa.c    2005-10-24 21:17:27.000000000 +0200
@@ -163,20 +163,39 @@ void sys_alsa_putmidimess(int portno, in

void sys_alsa_putmidibyte(int portno, int byte)
{
+#define dataptr_sz 1024
+    static unsigned int dataptr_pos = 0;
+    static unsigned char dataptr[dataptr_sz];
+
+    fprintf(stderr, "midi byte: 0x%2,2X\n");
+       snd_seq_event_t ev;
    snd_seq_ev_clear(&ev);
    if (portno >= 0 && portno < alsa_nmidiout)
    {
-        // repack into 1 byte char and put somewhere to point at
-        unsigned char data = (unsigned char)byte;
-        unsigned char *dataptr = malloc(1);
-        memcpy(dataptr,&byte,1);
-
-        snd_seq_ev_set_sysex(&ev,1,dataptr); //...set_variable *should* 
have worked but didn't
-        snd_seq_ev_set_direct(&ev);
-        snd_seq_ev_set_subs(&ev);
-        snd_seq_ev_set_source(&ev,alsa_midioutfd[portno]);
-        snd_seq_event_output_direct(midi_handle,&ev);
+    if(dataptr_pos < dataptr_sz) {
+        // store sysex (from xf0 to xf7) in a buffer...
+        if(dataptr_pos == 0 && byte != 0xf0) return; // drop unexpeted 
result
+        dataptr[dataptr_pos++] = (unsigned char)byte;
+        if(byte != 0xf7) return; // wait til xf7
+    } else {
+        // overflow: drop the msg
+        dataptr_pos = 0;
+        return;
+    }
+
+    int i;
+    fprintf(stderr, "sending sysex (len=%d)", dataptr_pos);
+    for(i=0; i<dataptr_pos; i++) fprintf(stderr, " 0x%.2X", dataptr[i]);
+    fprintf(stderr, "\n");
+   +    if(dataptr_pos > 0) {
+            snd_seq_ev_set_sysex(&ev,dataptr_pos,dataptr);
+        snd_seq_ev_set_direct(&ev);
+            snd_seq_ev_set_subs(&ev);
+            snd_seq_ev_set_source(&ev,alsa_midioutfd[portno]);
+            snd_seq_event_output_direct(midi_handle,&ev);
+    }
    }
}






More information about the Pd-list mailing list