Jump to content

Recommended Posts

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 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...