Skip to content

Commit

Permalink
Addressed issue #43 where a multiple reads from the ALSA buffer cause…
Browse files Browse the repository at this point in the history
…s the internal origin prefix to be included more than once
  • Loading branch information
Dave Kelly committed Nov 21, 2019
1 parent 9bc5a18 commit 5aa346d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion raveloxmidi/configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([raveloxmidi],[0.7.8])
AC_INIT([raveloxmidi],[0.7.99])
AC_CANONICAL_HOST
AC_CANONICAL_BUILD
AC_CANONICAL_TARGET
Expand Down
2 changes: 1 addition & 1 deletion raveloxmidi/include/net_distribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
#ifndef _NET_DISTRIBUTE_H
#define _NET_DISTRIBUTE_H

void net_distribute_midi( unsigned char *packet, size_t recv_len );
void net_distribute_midi( unsigned char *packet, size_t recv_len, char first_byte_ignore );

#endif
8 changes: 5 additions & 3 deletions raveloxmidi/src/net_distribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ extern int errno;
#include "raveloxmidi_alsa.h"

/* Send MIDI commands to all connections */
void net_distribute_midi( unsigned char *packet, size_t recv_len )
void net_distribute_midi( unsigned char *packet, size_t recv_len, char first_byte_ignore )
{
rtp_packet_t *rtp_packet = NULL;
unsigned char *packed_rtp_buffer = NULL;
size_t packed_rtp_buffer_len = 0;
char offset = 0;

midi_note_t *midi_note = NULL;
midi_control_t *midi_control = NULL;
Expand All @@ -87,11 +88,12 @@ void net_distribute_midi( unsigned char *packet, size_t recv_len )
enum midi_message_type_t message_type = 0;
size_t midi_payload_len = 0;

offset = ( first_byte_ignore ? 1 : 0 );

// Convert the buffer into a set of commands
midi_payload_len = recv_len - 1;
midi_payload_len = recv_len - offset;
initial_midi_payload = midi_payload_create();
midi_payload_set_buffer( initial_midi_payload, packet + 1 , &midi_payload_len );
midi_payload_set_buffer( initial_midi_payload, packet + offset , &midi_payload_len );
midi_payload_to_commands( initial_midi_payload, MIDI_PAYLOAD_STREAM, &midi_commands, &num_midi_commands );
midi_payload_destroy( &initial_midi_payload );

Expand Down
2 changes: 1 addition & 1 deletion raveloxmidi/src/net_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ int net_socket_read( int fd )
#endif
// MIDI data on internal socket or ALSA rawmidi device
{
net_distribute_midi( read_buffer, read_buffer_size );
net_distribute_midi( read_buffer, read_buffer_size , (fd==RAVELOXMIDI_ALSA_INPUT) );
} else {
// RTP MIDI inbound from remote socket
rtp_packet_t *rtp_packet = NULL;
Expand Down
9 changes: 1 addition & 8 deletions raveloxmidi/src/raveloxmidi_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,7 @@ int raveloxmidi_alsa_read( unsigned char *buffer, size_t buffer_size )

if( input_handle )
{
bytes_read = snd_rawmidi_read( input_handle, buffer + 1, buffer_size - 1 );

if( bytes_read > 0 )
{
// Add fake 0xaa identifier for origin identifier
buffer[0] = 0xaa;
bytes_read++;
}
bytes_read = snd_rawmidi_read( input_handle, buffer, buffer_size );
}

return bytes_read;
Expand Down

0 comments on commit 5aa346d

Please sign in to comment.