Jump to content

Recommended Posts

Posted

Hello,

i've got the following question:

What is the best solution to scale the controller resolution from 0-127 to 0-100?

I think this should be no problem. ??

Greetings,

Stefan

Posted

Hi Stefan,

here an excerpt from the midibox64 application:


;; --------------------------------------------------------------------------
;;  This function scales a 7bit value depending on a min and max value
;;  If the min value is greater than the max value, they will be
;;  automatically converted to realise a reversed scaling
;;  Input:
;;    o 7bit value in WREG
;;    o min value in MB64_POT_MIN_VALUE
;;    o max value in MB64_POT_MAX_VALUE
;;  Output:
;;    o scaled value in WREG and MIOS_PARAMETER1
;;  USES: MIOS_PARAMETER1 and MIOS_PARAMETER2
;; --------------------------------------------------------------------------
MB64_POT_ScaleValue
;; save pot value in MIOS_PARAMETER1
movwf MIOS_PARAMETER1

SET_BSR MB64_BASE

;; send min value if min == max
movf MB64_POT_MIN_VALUE, W, BANKED
IFNEQ MB64_POT_MAX_VALUE, BANKED, rgoto MB64_POT_ScaleValueDo
movwf MIOS_PARAMETER1
rgoto MB64_POT_ScaleValue_End

MB64_POT_ScaleValueDo
;; set MIOS_PARAMETER2[0] if min > max
bcf MIOS_PARAMETER2, 0
movf MB64_POT_MAX_VALUE, W, BANKED
IFLEQ MB64_POT_MIN_VALUE, BANKED, rgoto MB64_POT_ScaleValue_NoConv
bsf MIOS_PARAMETER2, 0
MB64_POT_ScaleValue_NoConv

;; scaled value-1 = ((current value+1) * (max-min+1)) / 128
;; swap max/min if MIOS_PARAMETER2[0] set

;; multiply current value * (max-min+1)
IFSET MIOS_PARAMETER2, 0, rgoto MB64_POT_ScaleValue_Inv
MB64_POT_ScaleValue_NoInv
movf MB64_POT_MIN_VALUE, W, BANKED
subwf MB64_POT_MAX_VALUE, W, BANKED
rgoto MB64_POT_ScaleValue_Cont1
MB64_POT_ScaleValue_Inv
movf MB64_POT_MAX_VALUE, W, BANKED
subwf MB64_POT_MIN_VALUE, W, BANKED
;; rgoto MB64_POT_ScaleValue_Cont1
MB64_POT_ScaleValue_Cont1
addlw 1
mulwf MIOS_PARAMETER1, ACCESS ; multiply with current value
;; divide result by 128 (result >> 7)
;; good trick: just shift the upper bit of the low byte into the high byte
rlf PRODL, W
rlf PRODH, W
andlw 0x7f
;; add min or max value depending on MIOS_PARAMETER2[0]
btfss MIOS_PARAMETER2, 0
addwf MB64_POT_MIN_VALUE, W, BANKED
btfsc MIOS_PARAMETER2, 0
addwf MB64_POT_MAX_VALUE, W, BANKED
;; store result in MIOS_PARAMETER1
movwf MIOS_PARAMETER1
MB64_POT_ScaleValue_End
movf MIOS_PARAMETER1, W

;; return immediately if inversion bit not set
IFCLR MIOS_PARAMETER2, 0, return

;; else inverse the result
subwf MB64_POT_MIN_VALUE, W, BANKED
addwf MB64_POT_MAX_VALUE, W, BANKED
movwf MIOS_PARAMETER1
return
[/code]

Note: MB64_BASE is the base pointer to the page where MB64_POT_MIN_VALUE and MB64_POT_MAX_VALUE are located.

Best Regards, Thorsten.

Posted

Hello again,

i've tested it with my motorfaders. If i move a fader it works as expected.

But when i send a controller-message the fader jumps to the non scaled

position (values 0..127). I use the Midibox64e application.

I think, i have to modify "MB64E_FADER_Move" from "mb64e_fader.inc" ?

The values, which are send to the midibox, range from 0..100.

Regards,

Stefan 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...