MIDIProtocol craig@ccrma.stanford.edu 21January2016 Bytes MIDIprotocolandMIDIfilesarebasedonbytes Bytes • Bytesare8-digitbinarydigits(states) • 00000000—11111111 TotalnumberofconfiguraGonsofthe8digits: bit=BinarydigIT 28=256 • RepresenGngasanunsignedinteger: 0—255 • RepresenGngasa2’scomplimentsignedinteger(sGll256states): 0—127,-128—-1 PosiGonalnotaGonofnumbers hSps://en.wikipedia.org/wiki/PosiGonal_notaGon • Whatdoes“365”mean? PosiGonalnotaGonofnumbers hSps://en.wikipedia.org/wiki/PosiGonal_notaGon • Whatdoes“365”mean? 365=300+60+5 365=3x100+6x10+5x1 365=3x102+6x101+5x100 3 6 5 DigitposiGon: 2 1 0 BinaryNumbers Whatisthebinarynumber10110indecimalposiGonalnotaGon(base-10)? 101102 1x24+0x23+1x22+1x21+0x20 16+0+4+2+0 2210 HexadecimalNumbers • Hexadecimaluses16astheposiGonalbase. • DigitsrepresenGng“10”through“15”aretheleSers“A”through“F” A16=1010 B16=1110 C16=1210 D16=1310 E16=1410 F16=1510` HexvsBinaryvsDecimal • Computersoperateinternallywithbinary(on/offstates) • ConverGng011010102todecimalisnon-trivial(addlotsofpowersoftwo) • ConverGng011010102tohexadecimalistrivial(memorize16conversions)because everyfourbinarydigitsrepresentonehexdigit(“nibble”). 011010102: 011010102 01101010 4+28+2 6A 6A16 011010102 64+32+8+2 10610 UsefulConversiontoKnow 111111112=FF16=25510 2’scomplimentinterpretaGon: =-110 011111112=7F16=12710 100000002=8016=12810 Note:FFhand0xFFarealternatewaysofindicaGnghex. OtherPosiGonalBases hSp://wiki.ccarh.org/images/9/92/Hexadecimal_numbers.pdf Tallymarks(base-1): 24 Sexagesimal(Base-60) hSps://en.wikipedia.org/wiki/Sexagesimal Developed~5000yearsagobySumerians (c.1800–1600BCE) Minutes/Seconds: 1;24,51,10=1+24/601+51/602+10/603 =1.41421296≈√2 12’3’’+16’42”=20’12” MIDIBytes MIDIData/CommandBytes 0—127 Databytes 128—255 Commandbytes 10000000 2—011111112 80h—FFh 000000002—01111111 2 7-BITS 00h—7Fh MIDICommands Command nibble 8_ 9_ A_ B_ Note-off Note-on Apertouch XY C_ D_ E_ F_ ConGnuouscontroller Channel nibble Patchchange ChannelPressure Pitchbend Systemmessages MIDICommandParameters =databyte(numberbetween0and127) Note-off Note-on Apertouch ConGnuous controller 8_ 9_ A_ B_ C_ D_ E_ F_ velocity Patch change key velocity Channel pressure key pressure Pitchbend controller value System messages key instrument pressure LSB MSB (usually0exceptsysex) RunningStatus REGULARMESSAGING: 903C48913E52913E00903C 00 RUNNINGSTATUS(removerepeatedcommandbytes): 903C48913E523E00903C00 ReconstrucGngregularmessages 903C48913E52 (91) 3E00903C00 AlternateNote-OffCommands 8_commandsarefornote-offmessages: 803C64 =turnoffnote60(0x3C,middleC) Withareleasevelocityof100(64h) Butalsoacommonnote-offshorthand: 903C00 =turnoffnote60(0x3C,middleC) Withundefinedreleasevelocity • Sosopestsoundingnotehasdatabyteof01,not00. Cinmidi hSp://wiki.ccarh.org/wiki/Cinmidi “Console-InMIDI”:DisplayincomingMIDImessagesinterminalwithGmestamps. ;; ;; ;; ;; ;; ;; ;; ;; ;; 0 30 128 7 23 109 25 98 4 102 28 109 Style: Timing: Message format: Format: Command-line: Input Port: Cpu Speed: 0x90 0x80 0x90 0x80 0x90 0x90 0x80 0x90 0x80 0x80 0x90 0x80 default delta milliseconds delta-time, MIDI command-byte, MIDI parameter-byte(s) asciimidi 1.0 cinmidi -o invention13-28.txt -p 1 1: 1000 MHz 64 88 45 64 69 88 64 64 57 87 72 91 69 64 71 91 72 64 71 64 64 104 57 64 ; ; ; ; ; ; ; ; ; ; ; ; NOTE chan:1 key:E4 vel:88 NOTEOFF chan: 1 key:A2 vel: NOTE chan:1 key:A4 vel:88 NOTEOFF chan: 1 key:E4 vel: NOTE chan:1 key:A3 vel:87 NOTE chan:1 key:C5 vel:91 NOTEOFF chan: 1 key:A4 vel: NOTE chan:1 key:B4 vel:91 NOTEOFF chan: 1 key:C5 vel: NOTEOFF chan: 1 key:B4 vel: NOTE chan:1 key:E4 vel:104 NOTEOFF chan: 1 key:A3 vel: 64 64 64 64 64 64