program change always selects gunshot sound

Bug #1153531 reported by Paddy Strebel
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ttyMIDI
Invalid
Undecided
Unassigned

Bug Description

I have an external midi sound module at /dev/ttyACM0 and use ttymidi
to play midi files. Currently this does not work well: a program change
is always doubled with a second program change with parameter 127.
As a result all midi files sound like a shooting game.

ttymidi -v -s /dev/ttyACM0 &
aplaymidi -p 128:1 rhapsody.mid

Debug output: (Looped MIDI_OUT to MIDI_IN)

Alsa 0xc0 Program change 001 001 4294967295
Serial 0xc0 Program change 000 001
Serial 0xc0 Program change 000 127

While searching for the bug I stumbled over two bugs in
write_midi_action_to_serial_port()
but could not find the reason for the problem above.

case SND_SEQ_EVENT_KEYPRESS:
bytes[0] = 0x90 + ev->data.control.channel;

// should be 0xA0 not 0x90

bytes[0] = bytes[1] = 0; bytes[2] = 0xFF;

// initialisation should be inside do-loop

I've also tried hairless-midiserial which works,
but I would prefer a command line tool.

Revision history for this message
kecajtop (kecajtop) wrote :

Hi!
It worked for me, so you have to change code in this way:

case SND_SEQ_EVENT_PGMCHANGE:
                                bytes[0] = 0xC0 + ev->data.control.channel;
                                bytes[1] = ev->data.control.param;
                                bytes[2] = ev->data.control.value;
                                if (!arguments.silent && arguments.verbose)
                                printf("Alsa 0x%x Program change >> %03u %03u %03u\n", bytes[0]&0xF0, bytes[0]&0xF, bytes[1],bytes[2]);
                                break;

Regards
Kecajtop

Revision history for this message
Jari Suominen (jari-tasankokaiku) wrote :

In case someone still after so many years :) is wondering:

According MIDI specs, Program Change does not have two data bytes, only one. Only situation where Program Change status byte would be followed by two (or more) data bytes, is when running status is enabled. Then correct way to parse this data (again MIDI specs) is to treat each extra data byte as new Program Change message (as no new status byte has been provided). Result would be the same behavior as reported here.

To me it seems that this behavior is already implemented in ALSA sequencer, not ttyMIDI, therefore details of the implementation are not visible in ttyMIDI code. Not sure how to generate accidentally three byte Program Change message in the first place, but the problem seems to be in the software sending these messages.

Changed in ttymidi:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.