You are on page 1of 7
Fiiblace Lowy MeLiacer eecures(1on3 do=ID, tong fizetileacure, lox munberDftearurer) Pe btasience doe dee = (Chusistoe #) tabdoe get (deID) AO ASSoasa ERCDOR_OXYALID_COC 10, A AGGERIE THVSLCD PARAMETER VALOR, At (GiontesoNnecine aie eeE get total aes(}) © doc-osc{t]ooiat ime > 22000) 34 (gsetienmuce ) doe-see[1]doet_ total nest) (COPED asStees St the! eta SF the seat i (ldge-sse[1J-oajouten ct ncer_nenuren(dac-rac(2J-sgot_total_asa[}.1,False,Golae, 2 nunberoftansares, 1.0.0.2, 03) Cr tesort nenaunen Refsnes Hieatlianaure 86 ((doe-se0[t]-sasouten_eféacer nenuren(firatearure, 1, falas, false, 7,munbesCéllensures,,0,0,,0)) MIDI Tutorial ‘This MIDI tutorial wil help you to understand how you can use the MIDI language to control any device that uses the MIDI protocel MIDI Tutorial Part 1 - MIDI Messages ‘The MIDI language is used to transmit real me information forthe playback of 2 piece of music. “Real time" means that each message is sent exactly atthe moment it must be Interpreted by the target syatheszer (which can be 2 hardware synthesizer or software synthesize”). Various messages are defined to transmit the information needed to perform the playback of muse, ‘The important points that the MEDI language does not cefine tne sound Itself but only the sequence of instructions to create the sound in te target synthesizer ‘The MIDI messages are sent as a time sequence of one or more bytes (8 bits). ‘The Fst byte isa STATUS byte, cftzn followed by DATA byteswrth addtional parameters, A STATUS byte has bit 7 set to 1 and aDATA Byte has bit 7 set to ‘The STATUS byte determines the type ofthe message, The number of DATA bytes that fellow depend an the type of the message, Except for some system MIDI messages, the STATUS byte contains theMIOT ‘channel number. There are 16 possible MIDI channels, numbered from 0 to 15 14 hexadecimal In practice, musicians and software refer to te MIDI cnannels By ‘counting them from 1 to 16, 20 that there Isa ciference of 1 when you program them in hexadecimal (channel "I" coded “0, channel "10" is coded "9" anc channel 16 le coded"), In the same MIDI cable, up to 16 MIDI channels may be used to control up to 16 diferent instruments playing independent (MIDI RUNNING STATUS While reading bytes coming from 2 MIDI ‘message, you must know that the STATUS byte can in fat be omitted (except the frst message of that type). In'such 3 case, you can receive a message that only has DATA bytes. Me STATUS byte Is then supposed t9 be the same as the last STATUS byte receive. This called MIDI RUNNING STATUS. It ls useful for instance to optimize transmission when along seres of the samme messages are sent. An ‘example would be & pitch bend or crescendo volume curve. You can also use this MIDI RUNNING STATUS when you generate MIDI ‘messages, bt you shouid care about how the target synthesizer oF Software wil receive to be sure i 5 well aterpreted. MIDI Tutorial Part 2 - NOTE Messages The main messages are the NOTE ON ané NOTE OFF messages ‘The NOTE ON message is sent when the performer hits 2 key ofthe music keyooard. (tcontains parameters to spect the pith ofthe nate as wel as the velocity (intensity of the note when It's hit) ‘When a synthesizer receives this message, i starts playing that nate with the correct pitch and force level ‘when the NOTE OFF message s received, the corresponding nate is switened af by the synthesizer. every NOTE ON message requires its corresponding NOTE OFF message, otherwise the note wil pay forever. The only exception is er percussion struments, where it ean happen that only the NOTE ON is sont, asthe percussion note stops by self automaticaly. But is better practice to send the NOTE OFF in every case, because you are not sure how Ie could be Interpreted by the synthesize receiving i. ‘The NOTE ON message Is structured 2s follows: + Status byte: 1002 cece + Data byte 2 09 pePP + Data byte 2 : ov www where! "CCCC" is the MIDI channel (rom 0 to 15) PP PPP" Is the pitch value (From 0 to 127) “YW VWWV" Is the velocty value (rom 0 227) The pitch value determines the frequency ofthe note to be played from 0 127, withthe middle C note being represented by the value ef 60: The value is represented in half steps, so that C# willbe 61, D willbe 62, To transpose a note one octave higher, add 12 to its ph value. By using MIDI, transposition Is very simple as itis done simply by adding or subtracting & fed value Be cautious however about the range of MIDI nates that goes from 0 to 127. By {adding for instance 4 octaves (+48) to a note of value 96, the totals 144, which is outside the range and may be truncated to 16 (144~ 128) so that a very low note wil result. ‘The velocity value normally goes fom 1 to 127, covering the range from 2 practically inaudible nate up to the maximum note level. tbasically corresponds to the scale of nuances found in music notation, as fellows (it is more indleatve than exact values) PPR =8 pep =20 PP = Pp =2 mp =53 LS 2 In baste synthesizers, the veloc value 's used only to determine the force with which the nate s played, the only eect being a note thet Is louder or sfter In volume. In more sophisticated synthesizer, this value will also affect the sound qualty. Indeed, on 2 real pian, hitting a note harder will not only affect its loudness but ‘also the qualty ofthe sound set, the timber. This practealy the case with any feal instrument ‘There isa special case Ifthe velocty is sotto zero, The NOTE ONmessage then has the same meaning az a NOTE OFF message, switering the note of ‘The NOTE OFF message is structured 2s follows: sta Js byte: 1000 cece + Data byte 1 0° EPP + ata byte 2 : ov Www where CCCC and PPPPPOP have the same meaning as above, The VWWWWW is the Felease velocity, which Is very rarely used. By default, set It o zero, MIDI Tutorial Part 3 - Playing notes and chords \wnen you send @ NOTE ON message to a synthesizer, this note starts playing Meanwfile, ou can send other NOTE ON messages, with ciferent note ptches, 50 a5 to hear a chord. However, you need to Keep track af the nates that are playing, so that you can send a corresponcingNOTE OFF for each note, otherwise {here wil be stuck notes playing forever, Let's take an example. What are the MIDI messages needed to play the fllowing da60 7 {As the time dimension must be present to hear the musi, here isthe time ‘sequence of the MIDI messages that you need to send to synthesizer to have it Dlay the above music on channel 1 (remember, coded as 0), mith a veloy of 64 (mezze forte), n hexadecimal (0x means hexadecimal notation) (0x90 - 0x40 - 0x40 (Start of E3 note, pitch = 64) (0x90 - 0x43 - 0x40 (Start of G3 note, pitch= 67) (0x80 - 0x43 - 0x00 (End of G3 note, pitch=67) + tL: 0x90 - 0x45 - 0x40 (Start of AZ note, pteh=69) + [2 : ©xBO - 0x45 - 0x00 (End of A3 nate, pitch=69) (0x80 - 0x40 - 0x00 (End of E3 note, pitch 64) (0x90 - 0x3C - 0x40 (Start of C3 note, pltcn = 60) (0x90 - 0x47 - 0x40 (start of 85 note, ptch= 71) + &3 : OxB0 - 0x47 - 0x00 (End of 83 nate, pitch 71) + 23 : Ox90 - 0x48 - 0x40 (Start of C4 note pitch 72) + 124 : 0x0 - 0x48 - 0x00 (End of C4 nate, pltch= 72) + 14 : @x80 - Ox3C - 0x40 (End af C3 note, piteh = 60) “t"ceprasents the tie In seconds. The score plays at 60 beats per minute, 0 ‘each quarter note is 1 second. MIDI Tutorial Part 4 - Selecting Instruments Up to.now, there is no information to tel the synthesizer what sound must be uses to play tne notes. The synthesizer woule probably use the piano oF ts ‘defaul Instrument ‘There is a MIDI message to specify an instrument from a predefined list of 128, Sounds, tn theory, each synthesizer may have its own custom lst of instruments, but the "General Midl (GM) standard defines a Ist of 128 Instruments that simplifies compatiblity. Most synthesizer have atleast a compatibilty mode with {the GM standard, You can find the lst of General MIDI instruments here (General MIDI standard ‘The MIDI message used to spacify the instrument is called a “program change message, It has one STATUS byte and one DATA byte + Status byte: 1100 cece + Data byte 2 0X0 X00 where CCC i the MIDI channe! (0 to 15) and XXXXXN i the instrument number from 0 {0 127. Similarly ta MIDI channels, you wil ften see thet the Instrument numbers in synthesizers and in GM lists, are numbered from 1 to 128 50 you also need to ade or subtract I for the conversion For instance, the trumpet instrament has number 57 Inthe GM list, soln the [above MIDI marsage you must sat XXXXXXX = 56 to get te corectIetrument in the targot synthesizer ‘The notes sent tothe synthesizer after that message willbe played with 2 trumpet soune ‘Sound Quality of Instruments You will notice that the ‘Sound quality as produced by the target synthesizer hes nothing to do with MIDI mescages. After receiving 2 program change specifying the trumpet instrument, 2 ‘heap, fon duality sound card synthesizer may play @ pretty bad trumpet sound, while a high quality sampler ‘may render a beautial and realise rumpet sound. This is the main problem with MIDI sequences, is that you have no control ofthe final quality of reproduction, {5 you do not know what i the synthesizer that wil play Ie when you publish a MIDI sequence. MIDI Tutorial Part 5 - Drum instruments. Drum instruments form a special case, as they do not have a specific pitch lke on {piano or trumpet. & specie MIDI channel is used to transmit the playback of {rum instruments. In General Mi itis Channel 10, but you wl find synthesizers ‘that can be programmed to reclve drums on any channel In the case of a channel assigned to drum instruments (and also for special sound effects often included in synthesizers), the NOTE ON and NOTE OFF message Information forthe pitch In Yack used to select which drum or sound effect will ioe For General MIDI, you can find the standard list of drum instruments here (atthe ‘end ofthat page) ‘General IDI drum instruments list For instance, to play a bass rum instrument on channel 10, send the NOTE ON message as follows + 0x99 0123 0x40 (0x99 is the STATUS byte forthe NOTE ON message, using channel 10 (coded 9), ‘0x23 is decimal 25 which 's the note suber used for the acoustic bass drum in ‘the GW list above, OxA0 is decimal 64 fora veloty around the mezzo {forte nuance, You should then send the NOTE OFF message as fllows + 0x39 0x23 0x00 MIDI Tutorial Part 6 - Using MIDI Channels The MIDI protocol handles up to 16 different MIDI channels. Each channel has its ‘own status, for instance the current instrument cefined, the notes tat are ‘currently playing, 2: well a other values hke the volume, the panerami, By using cierent MIDI channels, you can define 2 specific instrument for each, By sending nates onthe corresponding MIDI channels, these notes will sound with the given instruments Here is a score example with tree instruments Bass Drum ‘The sax, piano and bass drum wil use respectively channels 2, 2 and 10. The MIDI message sequence is te fllowing, First send the program changes to specify the instruments to use on each channel + 10 : OxCO - 0x43 (Alte Sax > coded 65 = Ox41) + {0 : OxC4 - 0x00 (Piano = 1 + 20 : OxC9 - 0x00 (Standard Drums Kit = 1 = > coded 0) > coded 0) For drums on General MIDI itis the program change 1 (coded 0) which Is the Standard crums kt, Some synthesizers also propose Jaz2 Kits, Orchestral kits, ‘lecrronic kts... with efferent drum sounds) ‘Then we can send the notes as already explained, Notice that here, we have used the NOTE ON message with 8 velocty of zero, as the equivalent ofthe NOTE [OFF message. This is on used in practice, + 20: 0x90 - Oxa8 - 0x40 (Start sax Cé, pitch = 72 » Ox48) (0x91 - 0x3¢ - Ox40 (Start plano C3, pitch = 60 = 0%3C) (0x91 - 0x43 - 0x40 (Start piano G3, pitch = 67 = 0x43) (x91 - Ox4C - Ox40 (Start piano E4, pitch = 76 = OxéC) (0x99 - 0x23 - 0x40 (Start Bass Drum = 35 = 0x23) (0x90 - 0x48 - 0x00 (stop sax C4, pitch = 72 = oxt8) (0x99 - 0x23 - 0x00 (Stop 8ass Drum = 35 = 0123) (0x90 - Ox4A - 0x40 (Start sax D4, pitch = 74 = Ox4a) (0x90 - OxaA - 0x00 (Stop sax D4, pitch = 74 » Ox) (0x90 - Oxac - 0x40 (Start sax £4 ptch = 78 = Ox4C) (0x90 - 0x46 - 0x00 (Stop sax 4, pitch (0x99 - 0x23 - 0x00 (Stop Bass Drum = 35, (0x90 - Ox4F - 0x40 (Start 50x Gé, pitch = 79 (0x90 - Ox4F - 0x00 (Stop sex GA, pitch = 79 (0x91 - 0x3 - 0x00 (Stop piano C3, (x91 - 0x43 - 0x00 (Stop piano G2, pitch = 67 = Ox43) (x91 - x46 - 0x00 (Stop plano Et, pitch = 76 = Ox4C) MIDI Tutorial Part 7 - MIDI Controllers ‘There are 126 MIDI controllers defined, but only a few of them are used in practice, The purpose ofa MIDI controle isto set a value of 3 parameter in the Synthesizer playing the notes, lke the volume, the paneramie (postion in space from left to rant in stereo}, the level of reverderation, ‘The message Is constructed as follows: + Status byte: 1011 cece + ata byte 1 : ONNN NNN where CCCC Is the MIDI channel, NNNNNNN is the controler number (rom 0 to 127) and VWWWWW is the value assigned tothe controll (also from Oto 127). ‘The most commen controller numbers are the fllowing: + 0» Sound bank selection (MSB) +1 = Modulation wheel, often assigned to a vibrato or tremolo effect. + 7-= Volume level of te instrument + 10 = Panoramic (0 = let; 64 center; 127 = eight) + 11 = Expression (sometimes used also for volume conteal or similar, depending on the syethesizer) + 32 = Soune bank selection (LSB) + a = Sustain pedal (0 = no pedal; >= 6 pedal on) + 121 = All controllers off (this message clears all the controler values for this Channel, back to their default values) +123 = All notes off (tis message stops all the nates that playing) re currently Volume and velocity, For instance if you want to set the volume toa value of £00 (in the 0 to 127 range of values, 100 = 0x64) for the instrument playing on channel 1 (coded 0), {you can send the folowing message + 0xB0 - 0x07 - 0x64 ‘The volume change has an impact on all notes currently playing 2s well asthe notes that wll start playing later. The synthesizer keeps that volume level unt {nother volume level's sont Rememiber thatthe velocity ofa note is sent with the NOTE ON message itself ‘The velocity cannot be changed once the note has been started, so you can use the volume controler to change the level of the note after I has been started To create a crescendo, you need to sand a sequence of increasing volume valves, You must always balance out the velocity and volume values to use, so that bot are in a correct range of value. Tf one of them Is to lo, the nates may not be heard correctly even if the other value is at Rs maximal value, The effect of Both Values are multiplicative to determine the real loucness ofthe note, Instrument selection [As we have seen before, you can select a sound on a synthesizer with the 128 ‘Values ofthe program change message. The sound bank selection messages (88 Least Significant Byte ard MSS Most Significant Byte) are used In adition to the program change message, -Asynthesizer may contain one oF mare sound banks, each containing 128 Sounds. If you want to use a specie sound bank ofthe synthesizer, ou must fst ‘activate the new Bank ang then send the program change message [As an example, if you want to use sound number 3 (encoded 2) an channel (coded 0) n the bank with specication LSB1; MSB~S, you must send the {allowing sequence of MIDI messages: + 0xB0 - 0x00 - 0x05 (MSS sound bank selection) + 0xB0 - 0x20 - 0x01 (L58 sound bank selection) + 0xC0 + 002 (sound selection in the currant sound bank) [After receiving these messages, the synthesizer will play the folowing nates with ‘that specific soune. [As the SB and LSB can range from 0 to 127, there Is total of 128 x 128 = 46284 possible sound Dank tobe selected, In practice, only a few are implemented, ‘The Information about the program change numbers and the sound banks ‘vallable Isto be found inthe MIDI implementation chart and MIDI specications of the synthesizer you are using MIDI Tutorial Part 8 - Pitch Bend ‘The Pich Bend message is used to vary the pitch ofthe not the current MIDI channel, The message s the fllowing 2s that are playing on + status byte: 1110 ccc + ata byte 2 : LLL LULL + Data byte 2 : OMEN MAM Where CCCC Is the MIDI channel, LLLLLL Is the LSB of the pitch bend value and MMMMIMMs the MSB. The 14 bit value ofthe pitch bend Is dated so that a Value of 12000 isthe center corresponding fo the normal pitch ofthe note (no pitch change). Using numbers above Ox2000 (up ta Ox3FFF) will crease the Pitch and using numbers below (down so 0x0000) will decrease the pitch. The Fange of pth change i symmetric (up and down) and ean often be adjusted In the synthesizer tse The most common range value is +/- 2 semitones around the standard note pte Pitch bend is often used to create glissando and guitar bend effects. To achieve this, you must sand a continucus sequence of pitch bend messages, to vary the pitch in real time, often enough so thatthe ear does not hear too much steps in the curve For instance, to “bene” a nate of 2 semitone higher, you must send 2 value of (3000, which wil be sent as: Indeee, the value 0x3000 must be split into two 7-bit values, giving Ox60 and ‘0x00 for the MSB ang LSB parts MIDI Tutorial Part 9 - Resetting notes [As we have seen, all NOTE ON message should have its correspondingNOTE ‘OFF message, otherwise the note will continue te sound forever ‘There are cases where you want to reset whatever notes are playing. There are basically 4 ways to do this, Some synthesizer do net accept them all, soi Is Interesting to ater the diferent possbites. 1 Using MIDI controller 123, 1f you send @ MIDI controller 122 on one MIDI channel, the synthesizer wil stop allnotes playing on that channel. To reset all MIDI channels, send that message for eacn channel. Please nate that some syntheszer do not respond to ths message 2-MIDI Reset message This sa one status byte message OXF, without data bytes. It should reset the synthesizer to its power-on defaul, 59 it also stops al notes playing. Use ths message sparingly, as & reset the full synthesizer, not only the nates playing You can also send, for each channel (0 to 15) and each note pitch (0 to 127) one MIDI NOTE OFF message. Tiss the total solution, but requires alt of MIDI ‘messages to be sent, which may have some reaction time according to the MIDI haraware system you use 4 MIDI NOTE OFF - optimized In this case, use a table to keep track ofthe NOTE ON and OFF messages you sen for each channel. & buffer of 128 bytes for each channel, representing the umber of NOTE ON messages sent to that note should be Incrementea by a NOTE ON and decremented by a NOTE OFF. Then, when you want to reset every note, simply go through that table and send @ NOTE OFF to each note that i sll playing, MIDI Tutorial - Going further The above information covers the basic use of MIDI for many playback tuations ‘ofind al information about the more advanced MIDI messages and conventions, you can goon the site of the MIDI Manufacturers Association, that you can easily tind with Google. Ifyou have any question, fel free to contact me at Info@arpegemusicicom musically yours, Dominique Vandenneucker Music Sofware Designer since 1992 at Arpege Music Back from “MIDI Tutorial” page to “Music Software Develooment” 9302, Copyright 2012 - Arpege Music - Dominique Vandenneucker

You might also like