When I was working on a code on scanning matrix piano keyboard, I had the need to find an element number based on the row, column and column size.
For example:
Find the order (left to right) of the element at (2,4) in a 5 columns table.
//(row, column)
[1, 5, 3, 7, 9]
[2, 4, 5, 6, 7]
[1, 3, 5, 3, 2]
We know that the value at (2, 4) is "6" but how do we know its order (if it's the 1st element, 2nd, 3rd... etc...) in the table?
I painstakingly tried to "find" the formula for this (cause I can't find it on the internet and I don't know what the keyword is) but here you go.
// Finding the element number (or order) by row and column
// ---------------------------------------------------------
// E(number) = C(total) * R - ( C(total) - C )
// -----
// E(number) - element number of the given row and column (from left to right)
// C(total) - total column of the table
// R - row number of the element
// C - column number of the element
And another useful formula that I "created" (or formulated)...
I cant explain it though. English is not my native language. But I will call it...
"Delay to MIDI Velocity Value For Velocity Sensitive Keyboard That Uses Two Switches And Determine The Time Difference Of Those Switches To Know How Fast/Hard The Key Was Struck"
// Finding the equivalent velocity using the given maximum delay and determined delay of a key
// -------------------------------------------------------------------------------------------------
// E(velocity) = ( ( D(maximum) - D(key) ) / D(maximum) ) * 127
// -----
// E(velocity) - resulting velocity from the given delay
// D(maximum) - maximum delay to be considered as 0 velocity
// D(key) - given delay of the key
// 127 - maximum midi note on velocity
//
Grammar and mathematical corrections are very very welcome.