# Is a carry bit generated when doing bit-wise shift left in MT?

I would like to use one global variable only, to represent the state of 8 LEDs, since I am running out of global variables. The easiest way to interpret the state of this global variable would be to shift left once. If the carry bit is set, I know that the first LED is turned on. If i shift left again, I can determine the state of the second LED. So.... is there a carry bit in MT? I could do the interpretation also by using the "OR" function, but I think it would be easier with bitwise shifts. Thanks, Gabriel

There is no carry function, however bitwise manipulation is fairly straight forward. I do this using a single variable to control 16 channel routing of midi output. I’ll send you an example or some baick ideas either later tonight or tomorrow,

Steve

Hopefully the below will give you the idea.

I use on translator for initializing global variables

Another for bit manipulation

And one for each light that I want to control (only bit 1 light shown here)

// Translator Init – I would run this on project open

//bit map variable
gk=0
// channel use for incoming bit manipulation messages
gc=0
// controller to use
ga=44

Bit manipulation logic

Input on Controller ga with Control change set value to pp

//Bitmap of channel select gk
// qq = 0 then even set on otherwise set off
qq=pp%2
// determine which bit to manipulate
rr=pp/2
// after the below, tt is now the amount to shift
// and rr is the channel/bit number
if qq==0 then tt=rr-1
if qq==1 then tt=rr
ss=1<<tt
// If even set the bit
if qq==0 then gk=gk|ss
// If odd clear the bit
if qq==1 then gk=gk^ss
// Then run a timer to update the channel/light status

// The below example set specific launchpad lights to specified color
// I will only show channel 1 in the exampe instead of 16 channels

//On timer status

//Outgoing Action Note on channel 1 with note qq and velocity pp

// gk is the midi channel bitmap
// Will use bottom two rows to display
// 60-67H = 1-8
// 70-77H = 9-16
// gq = channel with dirty status
//if gq!=1 then exit rules, skip Outgoing Action
// test bit 1
rr=gk&1
// For the above you would use 2 for bit 2, 4 for bit 3, 8 for bit 4, 16 for bit 5 ,32 for bit 6, 64 for bit 7 ,128 for bit 8
// note number for this LED
qq=96
// pp 15=red 127=yellow 60=green 12=off
ww=127
if rr==1 then pp=ww
if rr==0 then pp=12

If you want carry bit emulation with BMT I would do as follows
Say gk is your global variable
You want an 8 bit variable
If you set the value to FF 255
Since bome are 32 bit unsigned intergers you can do this on shift left
Say you want to take bit 8 as the carry

This is from top of my head. Not tested but should be close

gk=gk<<1

in the above gk would now be 510

and it with 256 to test for carry

pp=gk&256
if pp!=0 then pp=1

So now if there is carry pp would be one and if not it would be zero

Now for right shift

First test bit one
pp=gk&1

pp will now be one if carry zero otherwise

Now shift it right
gk=gk>>1

gk should now be 127

In both cases pp should be set if carry and clear if not

If you want it to wrap around the carry bit you would then have to add logic to do that

for left ship just take do this

gk=gk|pp

for right shift you would do this

pp<<7
gk=gk|pp

Hi Steve,
Thanks very much for your reply. Super! Really. Once I absorbed it my approach to my problem changed, and I’ve made a lot of progress.

However, there’s a roadblock in my project:
I need to be able to change a 30 bit word which is organized as ten contiguous 3 bit blocks from one value to another. I’ve inserted a space between each 3 bit block to make it more readable, and given an example of an initial word below:

010 010 000 100 100 000 000 000 000 000

I’m showing this in binary form, though in the algorithm I’m working on, the number is represented in hexadecimal form since Midi Translator doesn’t allow numbers in binary form.

For the block I want to change, the rules for the change are:
— Only one of the 3 bits in any block can be 1 and the other bits must be 0.
— Only one block at a time will change.

-- This can be any arbitrary block.
— All other blocks must retain their original values

A typical change, might be:
010 010 000 100 100 000 000 000 000 000 = original word
010 001 000 100 100 000 000 000 000 000 = changed word
Note that only the second 3 bit block than changes. The others remain the same.

I’ve tried many combinations of ANDs, ORs, and XORs, along with LEFT BIT-WISE shifts and RIGHT BIT-WISE shifts, but can’t quite get the needed result.
Can you help me figure out how it can be done? My method is awfully convoluted. There must be a simpler way.
Thanks,
Gabriel

What is the criteria you pick a block on input? For instance, are you going to take an input controller value of 1 to 10 to pick the block that you want to manipulate? If not, how do you pick the block? I think I need to understand better what your input values are and how you want to use them to get to your output? Where to you get your other variable(s) to determine the ultimate output value?

At a high level I think you need to do something like

Grab a block based on some input value
manipulate that block based on some other input value(s)
replace the manipulated block (after validating it is legal)
What do you ultimately do with the output? Do you just set the block in this translator and then use some
other translator for desired output or do you expect an output here?

Here is something that would show the basic logic (but obviously not tested and syntax in some places is not right:
Inputs
//pp=input block number
//qq= desired value
//ga= global variable
rr=pp-1
rr=rr*3 Shift amount
ss=ga>>rr
ss=ss&7 strip other bits
Manipulation happens here
ss=qq desired value
if ss=1 then goto finish
if ss==2 then goto finish
if ss==4 then goto finish
exit rules skip outgoing action – Invalid
finish: ss=ss<\

(Oh boo, the system here is not allowing some special characters and is munging them. Maybe I can paste this into answer instead of comment)

Here is something that would show the basic logic (but obviously not tested and syntax in some places is not right:

Inputs
//pp=input block number
//qq= desired value
//ga= global variable

rr=pp-1
rr=rr*3 Shift amount
ss=ga>>rr
ss=ss&7 strip other bits
Manipulation happens here
ss=qq desired value
if ss=1 then goto finish
if ss==2 then goto finish
if ss==4 then goto finish
exit rules skip outgoing action – Invalid

finish ss=ss<<rr
ga=ss|ga

Hi Steve,

Thanks again.
I didn’t want to get into much detail, because I thought it would muddy the waters, but I see that you need more information.
Here goes… some of this is obvious, I’m sure, but some is not, so I’ll go ahead with a plodding description of my system and my needs.

Inputs come from six APC Mini’s. We need only to deal with one Mini to explain the system.
— The Mini has 64 oblong buttons arranged in an 8×8 matrix. These send
the Midi “Note On” messages to MT (Note numbers 0 through 63).
— Each of these messages launch a clip (sample) in Ableton Live.
— Each button can light up
— Additionally, there is a row of 8 round buttons below the 8th row and
a column of round buttons to the right of the 8th column.
— These can also light up.
— There are also 9 faders arranged in a horizontal row below the buttons.

I’ll leave it at that, though there are some irrelevant details about the button functionality as well as some faders.

Now for the functionality I’m after in Ableton Live.
— Live is also arranged in rows and columns, where each “cell” in the
matrix represents a clip (sample) that can be played.
— In Live, only 1 clip in a column can be playing at the same time.
— In essence, this means that if a clip is playing and another button is
pressed in the same column , The first clip stops and the second clip
starts.
—This functionality is part of Live, not something I do in MT.
— If a clip is launched by pressing a button in the controller, Live sends a
midi message back to the Mini, which is used to light the button that
launched the clip.

So much for how the APC and Live interact.
— MT lies between the APC and Live, so:
— MT receives messages from the Mini, manipulates them, and
sends the results to Live.
— MT also receives messages from Live, does manipulations and sends
the results to Live.

Since the buttons light up to convey whether a clip is playing or not, one might think I would have no problem in knowing which clip is playing, but I use the lights to convey other information, so I throw away this data from Live, and light the buttons to display whether any effects have been applied to any sample in a column.
I still want to know which clips are playing, so I use the round buttons by lighting up the one below the column in which a clip is playing, as well as the round button to the right of the row of that clip.

Note that there are 24 clips in each of Live’s columns. Each column is called a Track.
Since I only have 8 buttons in a column in the Mini, I use 3 columns of 8 buttons to represent the 24 clips in an Live track.

Now for my problem:
— When I press a button to launch a clip in Live, I want to light one of the
round buttons.
— Since a Track contains 24 clips, the clip that’s playing could be in any one
if the three columns representing the Track (in the Mini).
— Since only one clip can be playing in a track, if a clip is playing in one of
the three columns, and a clip is then launched in one of the other two
columns, the first round button should no longer be lit up, and the round
button under the new clip should be lit.

That can be achieved easily in MT, but there’s another functionality.
—One of the three faders under a track controls the amplitude of the clip
that’s playing.
— When this fader value is zero, the clip that’s playing in the column is
turned off (no longer playing).
— When the fader value is greater than 0, the clip starts playing again.
— This means that the LED in the round button for this clip will be turned off
when the fader goes to 0, and the same round button will light up again when the fader goes above 0.
— Keeping track of the vertical round buttons corresponding to the row in
which a clip is playing is no problem, so I don’t need help with that.

I could keep track of the identity of the round buttons which need to be lit or
not lit pretty easily if I had enough global variables to remember which of the three round buttons in a track are lit up, but I’ve used almost all the globals (ga, through z9), and simply don’t have enough to keep track of the lights in all 6 of my Mini’s. This would require 16 globals. I will need some of these for other purposes, so I decided to utilize a two 30 bit words (each word handles 3 Mini’s. So, to keep things simple:
— Each grouping of 3 bits represents the three columns in a track.
— Binary 1 is used to represent a button that’s lit. Binary 0 means it’s not lit.
— Only one of the three buttons can be lit at any one time since only one of
the 24 samples in a track can be playing at one time.
— If I change one of the bits representing a track (three columns) this action cannot affect any of the other 27 bits in the 30 bit word. This is because
the state of the other buttons (lit or not lit) remains the same. One track
has no interaction with any other track.

I think that explains my predicament pretty well. Maybe this accounting is overweening and confused. I hope not.
Thanks,
Gabriel

Wow that is a lot to swallow but I think I get the idea. Let me break it down into requirement from a BMT
standpoint before we explore further.

1. You want to control lights of 6 APCs from Abelton
2. Abelton will send note on/note off messages to BMT
3. The note messages will be the same note for each device but each on different controller (channel)
4. You want BMT to translate from Channel and Note input into a set of bitmap variables
5. There will be ultimately 2 variables each containing 32 bits of which only 30 will be using. (10 bits/led\’s per device)
6. Each variable will represent LED on/of state (by bit)
So input message from Ableton to BMT will be
Note On – Turn bit on
Note Off – Turn bit off
Channel – Which device (block)
Each bit will be deterimed by the note value
As an example if groupings are as follows for the first of the two variables:
Bit0 – Block 0 note 0 – First APC -Channel 1
Bit1 – Block 0 note 0 – Second APC – Channel 2
Bit2 – Block 0 note 0 – Third APC – Channel 3
Bit3 – Block 1 note 1 – First APC
Bit4 – Block 1 note 1 – Second APC
Bit5 – Block 1 note 1 – Third APC
Bit6 – Block 2 note 2 – First APC
Bit7 – Block 2 note 2 – Second APC
Bit8 – Block 2 note 2 – Third AP
Bit9 – Block 3 note 3 – First APC
Bit10 – Block 3 note 3 – Second APC
Bit11 – Block 3 note 3 – Third AP

Bit27 – Block 9 note 9 – First APC
Bit28 – Block 9 note 9 – Second APC
Bit29 – Block 9 note 9 – Third AP
And you want to turn show light on status of Second APC note 2 you would want a value as follow
-9- -8- -7- -6- -5- -4- -3- -2- -1- -0-
000 000 000 000 000 000 000 010 000 000
Message in from Ableton would be
Note on channel 2 value none zero
Rule might look something like this
Note on Any channel any value set pp to note set qq to channel
Rules – TBD if my thinking of this is right (using bit map logic) us local variables to determine channel and note
Output value 90 02 7F – 9x where x= channel 02=local note variable
So in a nutshell note and channel determines which bit to set and value determine whether to set or clear the bit.
If this is correct let me know. If not, please clarify
Steve

My turn to swallow 😉 I’ll answer inline:

1) You want to control lights of 6 APCs from Abelton CORRECT
2) Abelton will send note on/note off messages to BMT CORRECT, BUT I DON’T USE THEM TO LIGHT THE BUTTONS THAT HAVE LAUNCHED A CLIP BECAUSE THEY ARE LIT UP TO DISPLAY INFORMATION ABOUT EFFECTS IN THE TRACK.
3) The note messages will be the same note for each device but each on different controller (channel) CORRECT
4) You want BMT to translate from Channel and Note input into a set of bitmap variables CORRECT
5) There will be ultimately 2 variables each containing 32 bits of which only 30 will be using. (10 bits/led’s per device) I’M NOT SURE I UNDERSTAND THIS – JUST TO BE CLEAR, THERE ARE 8 BITS PER DEVICE, AND ALSO 8 LEDS. EACH LED SHOWS WHETHER OR NOT THERE IS A CLIP PLAYING IN ITS COLUMN OF 8 BUTTONS. MORE DETAIL:
–THERE IS ONE BIT PER LED, (ON OR OFF).
–THERE ARE 3 LEDS GROUPED TOGETHER, REPRESENTING THE 3 COLUMNS IN A TRACK (SO 3 BITS ARE GROUPED TOGETHER ALSO)
–ONLY ONE OF THE THREE CAN BE ON AT A TIME.
–I THOUGHT THERE WAS A COMPLICATION THAT FORCED ME TO USE 30 BIT WORDS , BUT I SEE NOW THAT 24 BITS WILL SUFFICE TO REPRESENT THE 24 LEDS THAT ARE TO BE CONTROLLED.
6) Each variable will represent LED on/of state (by bit) CORRECT
So input message from Ableton to BMT will be
Note On – Turn bit on
Note Off – Turn bit off
Channel – Which device (block)
Each bit will be deterimed by the note value ALL OF 6) IS CORRECT BUT I IGNORE THE MESSAGES FROM LIVE FOR TWO REASONS:
— LIVE TELLS ME TO TURN ON THE LED UNDER THE BUTTON THAT LAUNCHED A CLIP. SINCE I USE THESE LEDS TO REPRESENT THE STATUS OF THE MANY EFFECTS IN A TRACK, I CAN’T SIMULTANEOUSLY USE THEM TO REPRESENT CLIP PLAYING – OR NOT PLAYING FOR THAT BUTTON.
—I’VE TRIED TO UNDERSTAND THE MESSAGES COMING BACK TO MT FROM ABLETON, BUT IT’S CONFUSING. THERE IS MORE THAN ONE MESSAGE COMING BACK PER BUTTON PRESS, AND I UNDERSTAND SOME OF IT BUT NOT ALL. IT’S ALSO NOT THE SAME, DEPENDING ON WHICH CLIPS ARE PLAYING ALREADY.
—YOUR REPLY MADE ME RETHINK WHETHER I COULD SIMPLY DECODE THIS INFORMATION TO DERIVE WHICH “COLUMN PLAYING” LED IS TO BE LIT. BUT BECAUSE I DON’T FULLY UNDERSTAND THE FEEDBACK TO MT, I DECIDED I NEED TO KEEP TRACK OF THE LEDS STATUSES IN MT CODE, AND NOT TO RELY ON FEEDBACK FROM ABLETON TO DO IT.
—- BUT —–
—I’LL GIVE THIS SOME SERIOUS THOUGHT AGAIN. IF I CAN BREAK UNDERSTAND THE FEEDBACK, I COULD USE THE FACT THAT ABLETON ITSELF IS KEEPING TRACK OF LED STATUSES AND FORGET ABOUT DOING IT MYSELF. FOR NOW, THOUGH, I’LL CONTINUE WITH THE METHOD I’VE BEEN WORKING ON.
As an example if groupings are as follows for the first of the two variables: YOUR MAPPING ISN’T WHAT I THINK IT SHOULD BE…. I’LL INSERT MY IDEA OF THE MAPPING BELOW YOURS.
Bit0 – Block 0 note 0 – First APC -Channel 1
Bit1 – Block 0 note 0 – Second APC – Channel 2
Bit2 – Block 0 note 0 – Third APC – Channel 3
Bit3 – Block 1 note 1 – First APC
Bit4 – Block 1 note 1 – Second APC
Bit5 – Block 1 note 1 – Third APC
Bit6 – Block 2 note 2 – First APC
Bit7 – Block 2 note 2 – Second APC
Bit8 – Block 2 note 2 – Third AP
Bit9 – Block 3 note 3 – First APC
Bit10 – Block 3 note 3 – Second APC
Bit11 – Block 3 note 3 – Third AP

Bit27 – Block 9 note 9 – First APC
Bit28 – Block 9 note 9 – Second APC
Bit29 – Block 9 note 9 – Third AP

MY MAPPING:
— USES NOTE NUMBERS ONLY TO DETERMINE THE COLUMN NUMBER FOR THE CLIP TO BE LAUNCHED. SO:
IN COLUMN 0
BUTTON 7 – SENDS NOTE 7 WHICH LAUNCHES CLIP 7
BUTTON 6 – SENDS NOTE 6 WHICH LAUNCHES CLIP 6
BUTTON 5 – SENDS NOTE 5 WHICH LAUNCHES CLIP 5
BUTTON 4 – SENDS NOTE 4 WHICH LAUNCHES CLIP 4
BUTTON 3 – SENDS NOTE 3 WHICH LAUNCHES CLIP 3
BUTTON 2 – SENDS NOTE 2 WHICH LAUNCHES CLIP 2
BUTTON 1 – SENDS NOTE 1 WHICH LAUNCHES CLIP 1
BUTTON 0 – SENDS NOTE 0 WHICH LAUNCHES CLIP 0
IN COLUMN 1
BUTTON 7 – SENDS NOTE 15 WHICH LAUNCHES CLIP 7
BUTTON 6 – SENDS NOTE 14 WHICH LAUNCHES CLIP 6
BUTTON 5 – SENDS NOTE 13 WHICH LAUNCHES CLIP 5
BUTTON 4 – SENDS NOTE 12 WHICH LAUNCHES CLIP 4
BUTTON 3 – SENDS NOTE 11 WHICH LAUNCHES CLIP 3
BUTTON 2 – SENDS NOTE 10 WHICH LAUNCHES CLIP 2
BUTTON 1 – SENDS NOTE 9 WHICH LAUNCHES CLIP 1
BUTTON 0 – SENDS NOTE 8 WHICH LAUNCHES CLIP 0
AND SO ON, FOR COLUMNS 3-7
—NOTE 0-7 ARE IN COLUMN 0, NOTE 8-15 ARE IN 1 ETC
—I USE THE NOTE NUMBERS, TO IDENTIFY THE COLUMN (ONE OF THE THREE THAT COMPRISE A TRACK) IN WHICH A BUTTON HAS BEEN PRESSED AND STORE THAT INFORMATION IN THE 24 BIT WORD. THEN I USE THE INFO AS FOLLOWS:
———I SOMETIMES USE A FADER TO ATTENUATE THE AMPLITUDE OF A CLIP, AND ULTIMATELY STOP THE CLIP FROM PLAYING WHEN THE FADER REACHES VALUE 0.
——–THEN WHEN I USE THE FADER TO RESUME PLAYING OF THE SAMPLE, I NEED TO KNOW WHICH LED TO LIGHT UP, SHOWING WHICH COLUMN A CLIP IS PLAYING IN.
——-I “UNPACK” THE 24 BIT WORD WHICH CONTROL LED STATUSES.
——-IF I WANT TO TURN ON THE LED FOR ONE COLUMN, BUT THERE IS ALREADY A LED LIT IN ANOTHER COLUMN, I NEED TO TURN OFF THAT ORIGINALLY LIT LED.
SO THOUGH NOTES ARE USED IN MY CODE, BY THE TIME A 24 BIT WORD HAS BEEN STORED, THE NOTE INFORMATION IS NO LONGER RELEVANT.
THIS IS THE MAPPING I THINK IS RELEVANT.
TRACK 0
Bit0 – Block 0 ON/0FF CONTROLS THE LED FOR THE 1ST COLUMN IN APC 1
Bit1 – Block 0 ON/OFF CONTROLS THE LED FOR THE 2ND COLUMN IN APC 1
Bit2 – Block 0 ON/OFF CONTROLS THE LED FOR THE 3RD COLUMN IN APC 1
TRACK 1
Bit3 – Block 1 ON/OFF CONTROLS THE LED FOR THE 4TH COLUMN IN APC 1
Bit4 – Block 1 ON/OFF CONTROLS THE LED FOR THE 5TH COLUMN IN APC 1
Bit5 – Block 1 ON/OFF CONTROLS THE LED FOR THE 6TH COLUMN IN APC 1
TRACK 2
Bit6 – Block 2 ON/OFF CONTROLS THE LED FOR THE 7TH COLUMN IN APC 1
Bit7 – Block 2 ON/OFF CONTROLS THE LED FOR THE 8TH COLUMN IN APC 1

OK – OUT OF COLUMNS IN APC 1,
STILL TRACK 2 BUT THE COLUMN IS PHYSICALLY IN APC2
Bit8 – Block 2 ON/OFF CONTROLS THE LED FOR THE 1ST COLUMN IN APC 2
TRACK 3
Bit9 – Block 3 ON/OFF CONTROLS THE LED FOR THE 2ND COLUMN IN APC 2
Bit10 –Block 3 ON/OFF CONTROLS THE LED FOR THE 3RD COLUMN IN APC 2
Bit11 – Block 3 ON/OFF CONTROLS THE LED FOR THE 4TH COLUMN IN APC 2
TRACK 4
Bit12 – Block 4 ON/OFF CONTROLS THE LED FOR THE 5TH COLUMN IN APC 2
Bit13 – Block 4 ON/OFF CONTROLS THE LED FOR THE 6TH COLUMN IN APC 2
Bit14 – Block 4 ON/OFF CONTROLS THE LED FOR THE 7TH COLUMN IN APC 2
TRACK 5
Bit15 – Block 5 ON/OFF CONTROLS THE LED FOR THE 8TH COLUMN IN APC 2
OK – OUT OF COLUMNS IN APC 1,
STILL TRACK 5 BUT THE ITS NEXT TWO COLUMNS OF TRACK 5 ARE PHYSICALLY IN APC3
Bit16 – Block 5 ON/OFF CONTROLS THE LED FOR THE 1ST COLUMN IN APC 3
Bit17 – Block 5 ON/OFF CONTROLS THE LED FOR THE 2ND COLUMN IN APC 3
Bit18 – Block 6 ON/OFF CONTROLS THE LED FOR THE 3RD COLUMN IN APC 3
Bit19 – Block 6 ON/OFF CONTROLS THE LED FOR THE 4TH COLUMN IN APC 3
Bit20 – Block 6 ON/OFF CONTROLS THE LED FOR THE 5TH COLUMN IN APC 3
Bit21 – Block 7 ON/OFF CONTROLS THE LED FOR THE 6TH COLUMN IN APC 3
Bit22 – Block 7 ON/OFF CONTROLS THE LED FOR THE 7TH COLUMN IN APC 3
Bit23 – Block 7 ON/OFF CONTROLS THE LED FOR THE 8TH COLUMN IN APC 3

And you want to turn show light on status of Second APC note 2 you would want a value as follow
-9- -8- -7- -6- -5- -4- -3- -2- -1- -0-
000 000 000 000 000 000 000 010 000 000 I THINK NOT…I THINK IT WOULD GO LIKE THIS:
—FIRST OF ALL, I KNOW IT’S STUPID, BUT I’VE BEEN REFERRING TO THE BITS IN THE 24 BIT WORD IN BACKWARDS ORDER BECAUSE THAT CORRESPONDS TO THE POSITION OF THE ACTUAL LEDS, HORIZONTALLY. SO:
-0- -1- -2- -3- -4- -5- -6- -7- -8- -9-
I WANT TO SHOW THE STATUS OF THE LED THAT MEANS A CLIP IS PLAYING, SAY, IN TRACK 2 – COLUMN 2 (AND IN NO OTHER COLUMN IN ANY APC). THAT IS DONE LIKE THIS:
000 010 000 000 000 000 000 010 000 000
I DON’T THINK THE REST OF YOUR LISTING APPLIES, BECAUSE I’M NOT RESPONDING TO MESSAGES SENT FROM ABLETON IN ORDER TO TURN LEDS ON OR OFF, BUT INSTEAD, LOOKING AT THE 24 BIT WORD AND DETERMINING FROM THAT, WHAT LEDS SHOULD BE LIT. IT’S EASY TO FIGURE OUT WHICH LEDS TO LIGHT WHEN I PRESS A BUTTON, BUT I HAVE TO REMEMBER WHAT’S LIT AND WHAT ISN’T IN ORDER TO TURN OFF THE LED FOR A COLUMN IN WHICH A CLIP IS PLAYING, SO THAT I CAN TURN IT OFF, AND TURN ON THE LED FOR ANOTHER COLUMN IN THAT SAME TRACK. (THAT’S BECAUSE ONLY ONE CLIP IN A TRACK CAN BE PLAYING AT ONE
SO… I’LL CONTINUE TO WORK ON THIS METHOD, BUT WILL ALSO SEE IF I CAN ANALYZE FEEDBACK FROM ABLETON AND PARSE IT IN A WAY THAT ALLOWS ME TO DETERMINE HOW TO TREAT THE LEDS
Thanks again,
Gabriel

This is where I lose you. Could you explain what each bit means here?
-0- -1- -2- -3- -4- -5- -6- -7- -8- -9-
I WANT TO SHOW THE STATUS OF THE LED THAT MEANS A CLIP IS PLAYING, SAY, IN TRACK 2 – COLUMN 2 (AND IN NO OTHER COLUMN IN ANY APC). THAT IS DONE LIKE THIS:
000 010 000 000 000 000 000 010 000 000
What does each bit of the above mean?
Which light(s) on which APC should be lit?
Do the 3 bits represent binary of 0-7 for the light lit in that column? I’m trying to determine if you just want a single light indicating something is happening on that track or whether you also want to know which clip is playing on that track? If the latter, I think we don’t have enough bits to determine
Total Lights per APC = 24
Total lights lit at ones = 8
Which row do you want to light = 3 bit binary value for each of 8 channels per APC means you need 1 global variable per APC. If all we want is one light on that channel/column – which one would you light?

Sorry if I sound dense. Spent two hours looking at this this morning and for some reason still can\’t get it. (pulling my hair). Maybe you are only using 3 columns out of the 8 on each APC?
Maybe some examples of bit maps and which lights on which APC\’s you want to show based on each example?
Essentially you are asking how to decode the bit maps into notes you want to sent to each APC (on or off). Seems to me you have already figured out how to construct the bit map an now just need help using it to unpack into the correct output midi messages.

Maybe you can look at the attached illustration and see what I’m missing

Attachments:

I didn’t give you information for the row because it’s much simpler to deal with, and I already have a strategy for controlling those LEDs. I thought it would be simpler to leave the LED indicators for row out of the discussion, but see, now, that it really would be confusing to you, not to know how I’m dealing with them.
I’ll explain the row indicators next, but before that,I want to say that you absolutely understand the column indicator situation. Really, my question boils down to this:

— I have a 24 bit word in which the bits should be thought of in groups of three as shown below:

23 22 21 – 20 19 18 – 17 16 15 – 14 13 12 – 11 10 9 – 8 7 6 – 5 4 3 – 2 1 0

— It’s not important to know what the individual bits stand for.
–It’s not important to know how I determine which bit should be 0 and which should be 1.
–I do believe you, in fact, do understand these two facts.

Basically, it comes down to the following.

— Initially all bits will be zero.
000 000 000 000 000 000 000 000

— If I set an arbitrary bit to 1 the result should be:
000 000 001 000 000 000 000 000

— Trying to set this bit to 1 again should leave the everything unchanged:
000 000 001 000 000 000 000 000

— If I set a bit in a different group of 3 it shouldn’t affect the bit that’s already set. The result
should be:
000 000 001 000 000 000 001 000

— If i set a bit in a group that already has a bit set, the ”old” bit should changes to 0 and the new one should be set to 1. Nothing else should change. This follows the rule that only one bit in a group can be 1. The result should be:
000 000 100 000 000 000 001 000

— If any bits have changed, I’ll store the altered 24 bit word. I know how to retrieve the state
of any bit if I need to know it… so that’s not part of my problem.

That’s all there is to it. I just don’t know how to do this easily using the available operators in MT…. OR XOR AND SHIFT-LEFT SHIFT RIGHT.

Maybe the details I provided got in the way.

As for the row indicators, it’s simpler. They are represented by an 8 bit word (for the 8 rows in an APC.) Only one of these bits can be on at a time, so it’s simple to achieve that by replacing the old 8 bit word with the new one.

I feel a little guilty for not presenting this all in it’s simple form, though maybe it was interesting to know what I was trying to do with these manipulations. If you do want to know more, I can answer any questions, but in any case, maybe you now have enough information to give me the steps to dealing with the 24 bit word changes.
Thanks,
Gabriel

Well now that I have no more hair, I think I am at the crux of what you are asking. My original logic was a bit flawed as when I OR’d the new value in, I didn’t ensure I cleared the original bits in that block first. Here is my best shot at that.

I have the block number, original value (ga) and new desired value (qq) and block number (pp) as input for testing

The result should modify only the 3 bits in that block clearing out the old bits there but not touching any other block.

Hopefully this time I got it right

//Inputs
//pp=input block number
//qq= desired valu
ga=10
pp=5
qq=4
//Value to update
//ga= global variable

rr=pp-1
// Shift amount to get the block into the bits 0-2
rr=rr*3
// Now the it is in the right area for manipulation
ss=ga>>rr
// Now you have just the 3 bits you want to manipulate
//strip other bits
ss=ss&7
// Manipulation happens here
// Set it to the desired value into temporary variable
ss=qq
// The below are the only legal values
if ss==1 then goto “finish”
if ss==2 then goto “finish”
if ss==4 then goto “finish”
// Abort, you must have an illigal value
exit rules, skip Outgoing Action
label “finish”
//OK legal value shift the value back into the right bits
//Complement all ones zeros all zeros now ones
tt=ga^-1
uu=7
uu=uu<<rr
// Set all marked values to 1
tt=tt|uu
// And set back to normal
tt=tt^-1
// Now or with new values
ss=ss<<rr
tt=tt|ss
ga=tt

Steve,
If I try the code with an initial ga=8396800 = 100 000 000 010 000 000 000 000
the final state becomes 8404992 100 000 000 100 000 000 000 000
Perfect!
Clearly I end up with a valid final state. But I don’t understand your example as a whole (or the steps in it) because of my confusion about the starting state.

Does ga=10
pp=5
qq=4
imply that:
– the leftmost bit of the 5th block (starting at the right) of a 24 bit word
– would be changed from either 000 or 010 or 001 to 100.
It must, because that’s what happens! I picked 010 as the initial state of that block.

But what does your initial value of 10 stand for?
Presumably this is hex, so: 10000 binary. Where would that fit into the 24 bit initial state?
If I run your code with that initial value The final state becomes:
0100000000001010 so I think I should parse it this way –
0 100 000 000 001 010 throwing away the left-most bit.

But that implies that there were at least two, and maybe three bits set in the initial word. But that’s not the case.
How did these extra bits come into being? What do they mean?

But, HOLY COW. I’m awed at your solution. Luckily I didn’t have other problems of this type in my code or it would have been years to finish, and then – only with help from people like you.
Thanks,
Gabriel

10 is decimal which would be 001 010 in binary or 0A in hex or 12 octal. I just used it as a starting point for my testing. I could have as easily put in 0x0A but Bome SW would have converted it to decimal 10 anyway for display purposes.
If you set an illegal initial value than my logic will not fix it.
Steve
P.S. If you turn on logging you should be able to figure this out. If not I can explain each step for you.
Another note is since this is block number 4 the entire input value is shifted right. I should have sent example as block 1 (right most block) Blocks in my example are as left to right. by my code.
So since the initial value is really not 001 010 ( my bad ) it is really 001 010 000 000 000 000 . We are only operating on block 5 (010). The other block was added in testing just to make sure I did not change it.

Just in case I didn’t make sense (early here) Here are xamples

Block 1 value 2 = 2 octal
Block 2 value 2 = 20 octal 010 000 binary
block 2 value 10 = 120 octal 001 010 000 binary
block 5 value 10 = 120000 octal 001 010 000 000 000 binary

Here is a cleaned up and better documented copy of the final solution. Please mark as resolved if this is what you were looking for.

//Inputs
//pp=target block number
// block numbers go from lsb to msb
// xxx means unchanged from original value nothing to the left is
// ever changed
// block 1 valud 2 = 010
// block 2 value 2 = 010 xxx
// block 5 value 4 = 100 xxx xxx xxx xxx
// Since BMT uses 32 bit signed integer
// You can get 10 blocks (30 bits)
// You don’t have to use them all
//qq= desired new value
//ga = the global variable you are manipulating
// Modify these values for testing
//—- Start of testing values
ga=10
pp=6
qq=4
//—- end of testing values
// Since BMT handles 32 bit only cannot hav block
// greater than 10
if pp>10 then exit rules, skip Outgoing Action
//Value to update
//ga= global variable

rr=pp-1
// Shift amount to get the block into the bits 0-2
rr=rr*3
// Now the it is in the right area for manipulation
ss=ga>>rr
// Now you have just the 3 bits you want to manipulate
//strip other bits
ss=ss&7
// Manipulation happens here
// Set it to the desired value into temporary variable
ss=qq
// The below are the only legal values
// This may vary depending on client requirements

if ss==1 then Goto “finish”
if ss==2 then Goto “finish”
if ss==4 then Goto “finish”
// Abort, you must have an illigal value
exit rules, skip Outgoing Action

Label “finish”
//OK legal value shift the value back into the right bits
//Complement – Turn all 0 to 1 and all 1 to 0
// Note -1 in Bome is signed 32 bit int so FFFF FFFF hex
tt=ga^-1
uu=7
// Shift it into the right position 3 bits * (block number -1)
uu=uu<<rr
// Set all marked values to 1
tt=tt|uu
// Complement back to original value
tt=tt^-1
// The desired block is now all 0
// Now OR it with new values
// First shift the value into position
ss=ss<<rr
// Now OR it with initial value to get result
ga=tt|ss