-
Notifications
You must be signed in to change notification settings - Fork 23
MIDI
MIDI is a system for musical instruments to communicate with each other and with computers.
If you want to control MIDI software with GlovePIE, you will need to download and install MidiYoke from http://www.midiox.com/myoke.htm. MIDI Yoke will also allow you to read MIDI output from other programs.
Otherwise you can only control the soundcard or external MIDI devices. You can also read input from MIDI devices.
MIDI devices can be plugged into your joystick port, if you have the right cable. Then you can use them for input.
Each computer may have multiple MIDI output ports, and multiple MIDI input ports. The output ports will include your sound card, software synthesisers, the external ports on the back of your computer, and MIDI Yoke ports. Input ports will include the input ports on the back of your soundcard, and the MIDI Yoke ports. There is no guarantee that input and output ports match up. There is also an output port called the “MIDI Mapper” which in Windows 3.1 was a complicated system for forwarding MIDI messages to different devices, but now it is just a setting in control panel which forwards everything to a chosen device.
Each MIDI port has 16 channels. It is possible to have multiple MIDI devices connected to the same port, but for each one to be listening to a separate channel. It is also possible for one MIDI device to use all the channels, with each channel representing a separate virtual instrument.
You can set which MIDI output port you want GlovePIE to use, like this:
midi.DeviceOut = 2
Where 1 is the first output port, and 0 is the MIDI mapper.
Future writes to midi values will then go to port 2.
You can set the input port like this:
midi.DeviceIn = 2
But there is no guarantee that input port 2 is connected to the same device as output port 2. In fact, most of the time it won’t be.
If you want to know what the name of that device is, use:
debug = midi.OutDevName
or
debug = midi.InDevName
You can also look at OutVersion
, OutTech
, InVersion
and InTech
.
Instead of using the default ports that you set with DeviceOut
and DeviceIn
, you can also use several ports at once, by explicitly putting them after the “midi” part of the value. For example to set the volume on (the default channel) of MIDI output port 2:
midi2.Volume = 50%
Or you could do the same thing like this:
midi.DeviceOut = 2
midi.Volume = 50%
A better way to control output ports, is to use the different port categories:
midi.mapper.volume = 50%
midi.soundcard.volume = 50%
midi.software.volume = 50%
midi.wavetable.volume = 50%
midi.playback.volume = 50%
midi.yoke2.volume = 50%
midi.external2.volume = 50%
You can optionally put a number after the category to use the nth device in that category.
If you want to set the default output device to one of those, then you can read from the DeviceOut or DeviceIn on one of those devices and use it to set the default device. Observe:
midi.DeviceOut = midi.yoke3.DeviceOut
That will set the default output port to the 3rd MIDI Yoke port.
Each MIDI port has 16 channels, numbered 1 to 16. You can set the default channel like this:
midi.DefaultChannel = 4
Each channel has its own instrument number, volume and other parameters, and each channel can play multiple notes at once.
Or you can specify the channel explicitly, like this:
midi.Channel4.Volume = 50%
You can specify both the port and the channel like this:
midi.Yoke3.Channel4.Volume = 50%
All the channels behave the same, except for Channel 10 on General MIDI devices (which most devices are these days). Channel 10 is always in percussion mode, and will play a different percussion instrument for each note of the scale. You can turn General Midi on or off by setting:
midi.GeneralMidi = True
or
midi.GeneralMidi = False
If you tell GlovePIE to play a percussion instrument, it will automatically do it on channel 10, regardless of which channel you specify.
You can turn notes on and off by setting the note to either true or false. For example to play middle C when the press the space bar:
midi.MiddleC = space
Middle C is octave 5, so you can also write it like this:
midi.C5 = space
You can also play other notes like this:
midi.FSharp8 = Enter
The lowest note is C0. The highest note is G10.
If you want more control over how fast the note is struck, you can set the velocity instead. If you turn notes on and off like above they will always be struck with a velocity of 50%. But you can also turn notes on by setting their velocity:
if pressed(Space) then midi.C5Velocity = 80%
if released(Space) then midi.C5Velocity = 0
Note that velocities are between 0 and 1 (80% is the same as 0.8). Setting the velocity to 0 turns the note off. Notes are always released with a release-velocity of 50%.
Some instruments will sound the same whatever velocity you use.
You can also apply extra pressure to a note when it is down. By default 0 extra pressure is applied. Applying extra pressure to a note may not have any effect on most instruments. The extra pressure is called “aftertouch”.
if pressed(space) then
midi.C5 = true
midi.C5Aftertouch = 20%
else
midi.C5 = false
end if
You can also apply extra pressure to every note that is played on that channel by setting the ChannelPressure
:
midi.ChannelPressure = 20%
You can also play a note by setting midi.FirstNote
to the number of the note you want to play. There are 12 notes per octave, including sharps and flats (anyone who tells you 8 is an idiot, even without sharps and flats there are only 7). C0 is note number 0. C1 is note number 12. MiddleC
is note number 60. G10 is note number 127. You need to set it to -1 to turn the note off.
if pressed(Space) then midi.FirstNote = 60
if released(Space) then midi.FirstNote = -1
There is also a SecondNote
, ThirdNote
, and FourthNote
, so you can play 4 notes by number at once.
These notes are all struck (and released) with a velocity of 50%.
You can’t read the note you are playing, so if you want to remember it, store it in a variable. Reading from midi.FirstNote
will read from the MIDI input device instead!
You can play percussion instruments by setting one of the percussion instruments:
midi.AcousticBassDrum = space
AcousticBassDrum, BassDrum2, SideStick, AcousticSnare, HandClap, ElectricSnare, LowFloorTom, ClosedHiHat, HighFloorTom, PedalHiHat, LowTom, OpenHiHat, LowMidTom, HighMidTom, CrashCymbal1, HighTom, RideCymbal1, ChineseCymbal, RideBell, Tambourine, SplashCymbal, Cowbell, CrashCymbal2, Vibraslap, RideCymbal2, HiBongo, LowBongo, MuteHiConga, OpenHiConga, LowConga, HighTimbale, LowTimbale, HighAgogo, LowAgogo, Cabasa, Maracas, ShortWhistle, LongWhistle, ShortGuiro, LongGuiro, Claves, HiWoodBlock, LowWoodBlock, MuteCuica, OpenCuica, MuteTriangle, OpenTriangle
You can also set other percussion instruments by setting Percussion0
to Percussion127
.
You can read whether notes are being played on a MIDI input device like this:
debug = midi.MiddleC
or you can read by number by using midi.FirstNote
(SecondNote
, ThirdNote
and FourthNote
don’t work for MIDI input yet).
if midi.FirstNote = 60 then say(“hello”)
You can use these methods to control games by using a MIDI keyboard:
Space = midi.MiddleC
Up = midi.MiddleDSharp
Down = midi.MiddleE
Left = midi.MiddleD
Right = midi.MiddleE
You can also read the velocities and aftertouches.
You can set the instrument to a number between 1 and 128 by setting midi.Instrument. See a midi instrument chart on the internet if you want to know what each instrument is.
If you normally use instrument numbers between 0 and 127, you can set midi.Instrument0 instead.
Note that each channel has its own instrument (except channel 10 on GeneralMidi)
By default instrument 1 is used, which is normally a piano.
If your instrument contains multiple banks of instruments, you can also set BankSelectLevel
. But you need to divide by 16383… for example, to set it to bank 2:
midi.BankSelectLevel = 2 / 16383
The first bank is bank 0. Instrument banks may have no effect on some devices.
You can also set the pitch bend using the pitch wheel.
The pitch wheel can be set to a value between 0 and 1. Setting it to 0.5 means no effect.
midi.PitchWheel = 50%
Each channel has its own Pitch Wheel.
You can also try setting the PitchBendRange
to change the range that the maximum pitch bend represents, in semitones.
Each channel of each device has a set of 32 different 14-bit controls, numbered 0 to 31, and a set of 7-bit controls numbered 64 onwards. You can also access the two 7-bit components of the 14-bit controls separately, as Coarse and Fine controls or as byte controls numbered 0 to 63.
Some of them have standard names, and some of them just have numbers. But you can use any control by number if you prefer. Sometimes the controls aren’t used for their defined function.
For example, setting Midi.Volume is the same as setting Midi.Control7.
So you can either write this:
midi.Volume = 52.38%
or
midi.Control7 = 52.38%
It is a 14-bit control, so it is a value between 0 and 1, but with about 4 or 5 decimal places. In this case we are setting it to 0.5238
You can also access the coarse and fine parts separately, like this:
midi.Control7Coarse = 0.5
midi.Control7Fine = 0
The controls numbered 32 to 63 are the same as the fine parts of the controls numbered 0 to 31. So Control7Fine and Control38 are the same thing.
You can also use ByteControl7 to refer to the coarse part of Control7, or ByteControl38 to refer to the fine part of Control7.
Controls numbered 64 onwards are only 7-bit controls, and have no coarse or fine components. They are also set to a value between 0 and 1, but they will be accurate to less decimal places (about 2). They also often have names.
MIDI also has RPN messages. These include:
MasterTuning, MasterTuningCoarse, MasterTuningFine, PitchBendRange, TuningProgramSelect and TuningBankSelect.
You can set them in GlovePIE like this:
Midi.PitchBendRange = 2 octaves
Midi.MasterTuning = -0.5 semitones // all notes will be off by half a note
I can’t guarantee these will work.
You can also set other RPN values manually, Eg. to set RPN 0,1 like this:
Midi.Control101 = 0 / 127
Midi.Control100 = 1 / 127
Midi.DataEntry = 0.75 // whatever value you want to set it to
Midi.Control101 = 127 / 127
Midi.Control100 = 127 / 127
There are no standard NRPN values (that’s the point of NRPN). But you can set them manually like this (for NRPN 0,1):
Midi.Control99 = 0 / 127
Midi.Control98 = 1 / 127
Midi.DataEntry = 0.75 // or whatever value
Midi.Control99 = 127 / 127
Midi.Control98 = 127 / 127
You can set standard System Exclusive midi values like this:
Midi.GeneralMidi = true
Midi.MasterVolume = 76%
Midi.IdentityRequest = pressed(space)
If you want to set other System Exclusive midi values, you need to save them in a .SYX file. You can then tell GlovePIE to send that file like this:
Midi.SetupFile = “c:\coolsounds.syx”