Contributor: ALTON PRILLAMAN { ALTON PRILLAMAN HOWEVER,now would be a good time to learn about "Bitwise Operators" to accomplish your goal With minimal memory requirements. I'll start With the basics (no offense intended). You may have heard, or remember from a Programming class that a Byte is made up of 8 bits. When looking at a Byte in binary, each bit holds a value of 0 or 1 that when put together in their respective places will add up to make the number. Here's an example of a Byte: B I N A R Y T A B L E ========================================================================= Power | 7 6 5 4 3 2 1 0 | of 2 ------+---------------------------------+----- Bit # | 8 7 6 5 4 3 2 1 | ------+---------------------------------+----- Value | 128 64 32 16 8 4 2 1 | HEX ------+---------------------------------+----- 0 | 0 0 0 0 0 0 0 0 | 00ドル 1 | 0 0 0 0 0 0 0 1 | 01ドル * 2 | 0 0 0 0 0 0 1 0 | 02ドル 3 | 0 0 0 0 0 0 1 1 | 03ドル * 4 | 0 0 0 0 0 1 0 0 | 04ドル 5 | 0 0 0 0 0 1 0 1 | 05ドル 6 | 0 0 0 0 0 1 1 0 | 06ドル 7 | 0 0 0 0 0 1 1 1 | 07ドル * 8 | 0 0 0 0 1 0 0 0 | 08ドル 9 | 0 0 0 0 1 0 0 1 | 09ドル 10 | 0 0 0 0 1 0 1 0 | 0ドルA 11 | 0 0 0 0 1 0 1 1 | 0ドルB 12 | 0 0 0 0 1 1 0 0 | 0ドルC 13 | 0 0 0 0 1 1 0 1 | 0ドルD 14 | 0 0 0 0 1 1 1 0 | 0ドルE 15 | 0 0 0 0 1 1 1 1 | 0ドルF * 16 | 0 0 0 1 0 0 0 0 | 10ドル | | * 32 | 0 0 1 0 0 0 0 0 | 20ドル * 64 | 0 1 0 0 0 0 0 0 | 40ドル * 128 | 1 0 0 0 0 0 0 0 | 80ドル | | 255 | 1 1 1 1 1 1 1 1 | $FF ------+---------------------------------+----- * = All columns to the right had filled up With 1s, so we carried to the next column to the left. Notice that when all of the "bit places" have a "1" in them, that the total adds up to be 255 which is the maximum number that a Byte can hold. In binary (the inner part of the Chart), "1" is the maximum value a bit can hold Until it carries to the next column to the left. This brings us to the next Chart, HEXIDECIMAL: H E X I D E C I M A L T A B L E ========================================================================= Power| 1 0 |of 16 Power| 1 0 |of 16 -------+---------+----- -------+---------+----- Decimal| | Decimal| | Value| 16 0 | HEX Value| 16 0 | HEX -------+---------+----- -------+---------+----- 0| 0 0 | 00ドル 31| 1 1 | 1ドルF 1| 0 1 | 01ドル * 32| 2 0 | 20ドル 2| 0 2 | 02ドル 33| 2 1 | 21ドル 3| 0 3 | 03ドル | | 4| 0 4 | 04ドル 47| 2 F | 2ドルF 5| 0 5 | 05ドル * 48| 3 0 | 30ドル 6| 0 6 | 06ドル 63| 3 F | 3ドルF 7| 0 7 | 07ドル * 64| 4 0 | 40ドル 8| 0 8 | 08ドル 79| 4 F | 4ドルF 9| 0 9 | 09ドル 80| 5 0 | 50ドル 10| 0 A | 0ドルA 95| 5 F | 5ドルF 11| 0 B | 0ドルB * 96| 6 0 | 60ドル 12| 0 C | 0ドルC 111| 6 F | 6ドルF 13| 0 D | 0ドルD * 112| 7 0 | 70ドル 14| 0 E | 0ドルE 127| 7 F | 7ドルF 15| 0 F | 0ドルF * 128| 8 0 | 80ドル * 16| 1 0 | 10ドル 255| F F | $FF 17| 1 1 | 11ドル * 256| |0100ドル -------+---------+----- -------+---------+----- * = All columns to the right had filled up With 15 (F) so we carried to the next column to the left. The hexidecimal table is derived from BASE 16. The value that each column may hold a value of 15 (F) before we carry to the next column. Also notice that when both columns fill up With a value of "F" ($FF) that the result is 255, which is the maximum For a Byte. Okay, With that behind us, let's take a look at your application. As you may have noticed in the binary table in the previous message, a Byte will give us the ability to track up to 8 bits. Our goal here is to turn on or off each of the 8 bits as each channel is turned on or off. I assume that you've got 16 channels to work With, so we'll use a Word instead of a Byte. When looked at in binary, a Word is like placing two Bytes side-by-side. Notice that the HEXIDECIMAL works the same way. 256-------------------------+ +---------------------------- 128 512----------------------+ | | +------------------------- 64 1024-------------------+ | | | | +---------------------- 32 2048----------------+ | | | | | | +------------------- 16 4096-------------+ | | | | | | | | +---------------- 8 8192----------+ | | | | | | | | | | +------------- 4 16384-------+ | | | | | | | | | | | | +---------- 2 32768----+ | | | | | | | | | | | | | | +------- 1 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Power | 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0|of 2 -------+------------------------------------------------+------- Bit # | 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1| -------+------------------------------------------------+------- Decimal| | Value| BINARY | HEX -------+------------------------------------------------+------- 1| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1| 0001ドル 2| 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0| 0002ドル 4| 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0| 0004ドル 8| 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0| 0008ドル 16| 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0| 0010ドル 32| 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0| 0020ドル 64| 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0| 0040ドル 128| 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0| 0080ドル 256| 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0| 0100ドル 512| 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0| 0200ドル 1024| 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0| 0400ドル 2048| 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0| 0800ドル 4096| 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0| 1000ドル 8192| 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0| 2000ドル 16384| 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0| 4000ドル 32768| 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0| 8000ドル -------+------------------------------------------------+------- Though it has taken us a While to get here, you now have a "value" for each of your midi channels. if you need to use more than 16 channels, you can use the same methods applied above using a LongInt to give you a total of 32 channels (or bits). You can now declare these as Constants in your Program like so: } Program MidiStuff; Const {Midi Channels} Ch1 = 0001ドル; Ch2 = 0002ドル; Ch3 = 0004ドル; Ch4 = 0008ドル; Ch5 = 0010ドル; Ch6 = 0020ドル; Ch7 = 0040ドル; Ch8 = 0080ドル; Ch9 = 0100ドル; Ch10 = 0200ドル; Ch11 = 0400ドル; Ch12 = 0800ドル; Ch13 = 1000ドル; Ch14 = 2000ドル; Ch15 = 4000ドル; Ch16 = 8000ドル; Var MidiChannels : Word; { Now you can turn on or off each channel and check to see if one is set by using the following Procedures and Functions. You can accomplish this by using the or and and operators. } Function ChannelIsOn(Ch : Word) : Boolean; begin ChannelIsOn := (MidiChannels and Ch = Ch); end; Procedure TurnOnChannel(Ch : Word); begin MidiChannels := MidiChannels or Ch; end; Procedure TurnOffChannel(Ch : Word); begin MidiChannels := MidiChannels and not Ch; end; begin MidiChannels := 0000ドル; {Initialize MidiChannels - No channels on!} TurnOnChannel(Ch2); if ChannelIsOn(Ch2) then Writeln('Channel 2 is on!') else Writeln('Channel 2 is off!'); if ChannelIsOn(Ch3) then Writeln('Channel 3 is on!') else Writeln('Channel 3 is off!'); TurnOnChannel(Ch16); TurnOnChannel(Ch10); TurnOffChannel(Ch2); if ChannelIsOn(Ch2) then Writeln('Channel 2 is on!') else Writeln('Channel 2 is off!'); end.