1

I'm using pygame.midi library to send MIDI Messages (Control Change messages, not notes). The idea is to send from the output (from this python program) to the input of another program.

>>> import time
>>> import pygame.midi as midi
>>> midiout = midi.Output(3)
>>> midi.init()
>>> midiout = midi.Output(3)
>>> midiout.write_short(0x74,124,0)
PortMidi call failed...
  PortMidi: `Invalid MIDI message Data'
type ENTER...

As you can see, i'm sending 0x74,124,0. I'm taking those numbers from rakarrack (the application that i want to control) implementation chart: http://rakarrack.sourceforge.net/midiic.html

What am I doing wrong?

Mr_LinDowsMac
  • 2,644
  • 9
  • 56
  • 75

1 Answers1

1

MIDI status bytes (the first byte of the message) must have the high (0x80) bit set. the linked chart is a bit confusing, but I'm guessing 0x74 is a data byte and must be preceded by the proper status byte.

>>> import pygame.midi as midi
>>> midi.init()
>>> midiout = midi.Output(0)
>>> midiout.write_short(0xb0, 0x74, 124)

some basic MIDI documentation: http://www.midi.org/techspecs/midimessages.php

control change is 0xbn, where n is the channel number, so 0xb0 is a control change message for channel 0.

jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107
  • Where the '0x80' comes from? I don't see in the chart. – Mr_LinDowsMac Aug 23 '13 at 18:00
  • I just updated with a link to status codes. 0x80 is "note off" on channel 0, probably not what you want; I just used it as an example. – jcomeau_ictx Aug 23 '13 at 18:02
  • Comparing both MIDI charts I figured out that the 0x74 should be the second byte, and 124 is the value of on/off (which replaces velocity). The question is, what is the first byte value? – Mr_LinDowsMac Aug 23 '13 at 18:26
  • since I have no knowledge of rakarrack, my guess would be a "note on" event, 0x9n, where n is the channel. 0x90 for channel 0 for example. – jcomeau_ictx Aug 23 '13 at 18:33
  • mmmm... python accepted like a valid instruction, however rakarrack doesn't do anything. I don't think it should be a note on event, because this is not a playing device (like a syntetizer or sampler). – Mr_LinDowsMac Aug 23 '13 at 18:38
  • I already change the output device, but it doesn't do anything when i send that instruction. Maybe I'm still using the wrong first byte. – Mr_LinDowsMac Aug 23 '13 at 18:39
  • you'll need to find and study some documentation on rakarrack. – jcomeau_ictx Aug 23 '13 at 18:40
  • control change is 0xb0 [sorry, it took me a while to put two and two together -- it's been years since I studied MIDI] – jcomeau_ictx Aug 23 '13 at 18:43
  • I read more carefully the MIDI Implementation of the chart that you provided. The first byte that I should send is "0xb0" which corresponds to "Chan 1 Control/Mode Change". And it works! – Mr_LinDowsMac Aug 23 '13 at 18:52
  • Thanks! i figured out myself anyway :P – Mr_LinDowsMac Aug 23 '13 at 18:53