• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: basic MIDI packet construction question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: basic MIDI packet construction question


  • Subject: Re: basic MIDI packet construction question
  • From: Kurt Revis <email@hidden>
  • Date: Fri, 3 Jan 2003 22:43:01 -0800

On Friday, January 3, 2003, at 09:09 PM, David Cake wrote:

Not a Core MIDI specific question - I'm having trouble constructing pitch bend MIDI packets from scratch. My other MIDI stuff appears to work fine - but I can't seem to get the two byte values in pitchbend working correctly. Currently, Kurts MIDI Monitor app keeps reporting stange values like -4011 when I am expecting a small int value. Anyone got pointers to sample code?

Here's my code which goes from 2 MIDI bytes to the value that is displayed.

+ (NSString *)formatSignedDataByte1:(Byte)dataByte1 byte2:(Byte)dataByte2 usingOption:(SMDataFormattingOption)option;
{
// Combine two 7-bit values into one 14-bit value. Treat the result as signed, if displaying as decimal; 0x2000 is the center.
int value;

value = (int)dataByte1 + (((int)dataByte2) << 7);

switch (option) {
case SMDataFormatDecimal:
default:
return [NSString stringWithFormat:@"%d", value - 0x2000];

case SMDataFormatHexadecimal:
return [NSString stringWithFormat:@"$X", value];
}
}

The opposite would be something like this:

int originalValue; // given; must be >= -8192 and <= 8191
int value;
Byte byte1, byte2;

value = originalValue + 0x2000;
byte1 = value & 0x7F;
byte2 = value >> 7;

I think this is right, but let me know if it doesn't work for you.

--
Kurt Revis
email@hidden
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.

References: 
 >basic MIDI packet construction question (From: David Cake <email@hidden>)

  • Prev by Date: basic MIDI packet construction question
  • Next by Date: Sound Output Components for OS X???
  • Previous by thread: basic MIDI packet construction question
  • Next by thread: Sound Output Components for OS X???
  • Index(es):
    • Date
    • Thread