Post by mo13 on Jun 17, 2024 17:00:56 GMT
I'm having a little trouble with converting and scaling Pitch Bend to 3 CC's to set a BPM on the other end which is 1-999
So I need the 3 outgoing CCs to correctly increment/decrement their values from 0 0 1 to 9 9 9 according tot the incoming PB.
EF 00 01 triggering to send out BF $125 00, BF $126 00, BF 127$ 01 , EF 7E 7F triggering BF $125 09, BF $126 09, BF 127$ 09
This is as close as I got but it's not incrementing/decrementing the values accordingly on the output, if anyone knows how else to possibly approach this?
# Converting Pitch Bend on Ch.16 to 3 CCs (125, 126, 127)
# representing BPM values (1-999)
IF LOAD
# Define constants for CC numbers
ASS J0 = $125 # CC1 (125) - Hundreds digit
ASS J1 = $126 # CC2 (126) - Tens digit
ASS J2 = $127 # CC3 (127) - Ones digit
# Initialize counters for digits
ASS K0 = 0 0 0 0
ASS L0 = 0
ALIAS K0 HUNDREDS_DIGIT
ALIAS K1 TENS_DIGIT
ALIAS K2 ONES_DIGIT
ALIAS K3 LAST_VALUE
ALIAS L0 CURRENT_VALUE
# Define loop boundaries
ALIAS 0 MIN_LOOP
ALIAS 9 MAX_LOOP
END
# Detect Pitch Bend message on Channel 16
IF M0 == EF
# Calculate current pitch bend value (LSB + MSB * 128)
MAT CURRENT_VALUE = M1 + M2 * 128
# Determine direction of change
IF CURRENT_VALUE > LAST_VALUE
# Forward counting
MAT ONES_DIGIT = ONES_DIGIT + 1
# Check if ONES_DIGIT exceeds its range
IF ONES_DIGIT > MAX_LOOP
# Reset ONES_DIGIT to MIN_LOOP and increment TENS_DIGIT
ASS ONES_DIGIT = MIN_LOOP
MAT TENS_DIGIT = TENS_DIGIT + 1
END
# Check if TENS_DIGIT exceeds its range
IF TENS_DIGIT > MAX_LOOP
# Reset TENS_DIGIT to MIN_LOOP and increment HUNDREDS_DIGIT
ASS TENS_DIGIT = MIN_LOOP
MAT HUNDREDS_DIGIT = HUNDREDS_DIGIT + 1
END
# Check if HUNDREDS_DIGIT exceeds its range
IF HUNDREDS_DIGIT > MAX_LOOP
ASS HUNDREDS_DIGIT = MIN_LOOP
END
END
IF CURRENT_VALUE < LAST_VALUE
# Backward counting
MAT ONES_DIGIT = ONES_DIGIT - 1
# Check if ONES_DIGIT goes below its range
IF ONES_DIGIT < MIN_LOOP
# Set ONES_DIGIT to MAX_LOOP and decrement TENS_DIGIT
ASS ONES_DIGIT = MAX_LOOP
MAT TENS_DIGIT = TENS_DIGIT - 1
END
# Check if TENS_DIGIT goes below its range
IF TENS_DIGIT < MIN_LOOP
# Set TENS_DIGIT to MAX_LOOP and decrement HUNDREDS_DIGIT
ASS TENS_DIGIT = MAX_LOOP
MAT HUNDREDS_DIGIT = HUNDREDS_DIGIT - 1
END
# Check if HUNDREDS_DIGIT goes below its range
IF HUNDREDS_DIGIT < MIN_LOOP
ASS HUNDREDS_DIGIT = MAX_LOOP
END
END
# Update LAST_VALUE with the current pitch bend value
ASS LAST_VALUE = CURRENT_VALUE
# Send CC messages with the BPM digits
SND BF J0 HUNDREDS_DIGIT
SND BF J1 TENS_DIGIT
SND BF J2 ONES_DIGIT
END
# Specific handling for reset and preset values
IF M0 == EF 00 00
# Reset all counters
ASS HUNDREDS_DIGIT = 0
ASS TENS_DIGIT = 0
ASS ONES_DIGIT = 0
ASS LAST_VALUE = 0
END
IF M0 == EF 01 00
# Set counters to 0 0 1
ASS HUNDREDS_DIGIT = 0
ASS TENS_DIGIT = 0
ASS ONES_DIGIT = 1
ASS LAST_VALUE = 128 # Equivalent to EF 01 00 in pitch bend value
# Send CC messages
SND BF J0 0
SND BF J1 0
SND BF J2 1
END
IF M0 == EF 7E 7F
# Set counters to 9 9 9
ASS HUNDREDS_DIGIT = 9
ASS TENS_DIGIT = 9
ASS ONES_DIGIT = 9
ASS LAST_VALUE = 16383 # Equivalent to EF 7E 7F in pitch bend value
END
Block
So I need the 3 outgoing CCs to correctly increment/decrement their values from 0 0 1 to 9 9 9 according tot the incoming PB.
EF 00 01 triggering to send out BF $125 00, BF $126 00, BF 127$ 01 , EF 7E 7F triggering BF $125 09, BF $126 09, BF 127$ 09
This is as close as I got but it's not incrementing/decrementing the values accordingly on the output, if anyone knows how else to possibly approach this?