Hi everybody …
Here is my solution for handling masterfader-event with an encoder. I hope that I got all the changes ;) .
Change in lc_mproc.inc:
...
;; --------------------------------------------------------------------------
;; Ex has been received: move motorfader
;; --------------------------------------------------------------------------
LC_MPROC_Received_Ex
;; mask out MIDI channel (== fader number)
movlw 0x0f
andwf MIOS_PARAMETER1, F
#if MOTORFADER0_IS_MASTERFADER == 0
;; do nothing if fader number >= 8
movlw 0x09 ;including "MasterfaderEvent" this has to be 0x09 !!!
IFGEQ MIOS_PARAMETER1, ACCESS, return
#else
;; exit if fader number == 0
; movf MIOS_PARAMETER1, W
; skpnz
; return
;; do nothing if fader number >= 9
movlw 0x09
IFGEQ MIOS_PARAMETER1, ACCESS, return
;; master fader 8 -> 0
movlw 0x07
andwf MIOS_PARAMETER1, F
#endif
;; move fader
movf MIOS_PARAMETER1, W
goto LC_MF_FaderMove ; (located in lc_mf.inc)
...
Change in lc_mf.inc:
...
;; --------------------------------------------------------------------------
;; This function is called by LC_MPROC_Received_Ex when a fader should
;; be moved
;; Input:
;; o fader number in WREG and MIOS_PARAMETER1
;; o LSB value in MIOS_PARAMETER2
;; o MSB value in MIOS_PARAMETER3
;; --------------------------------------------------------------------------
LC_MF_FaderMove
;; save fader number in LC_FADER_NUMBER
andlw 0x07
movwf LC_FADER_NUMBER
;; LSB = MSB[0] | MIDI LSB
btfsc MIOS_PARAMETER3, 0
bsf MIOS_PARAMETER2, 7
;; MSB = MIDI MSB >> 1
clrc
rrf MIOS_PARAMETER3, F
;; 10-bit value = 14-bit value >> 4
clrc
rrf MIOS_PARAMETER3, F ; 1
rrf MIOS_PARAMETER2, F
clrc
rrf MIOS_PARAMETER3, F ; 2
rrf MIOS_PARAMETER2, F
clrc
rrf MIOS_PARAMETER3, F ; 3
rrf MIOS_PARAMETER2, F
clrc
rrf MIOS_PARAMETER3, F ; 4
rrf MIOS_PARAMETER2, F
;; check if fader is masterfader
movlw 0x07
IFLEQ MIOS_PARAMETER1, ACCESS, goto LC_FADER_MOVE ; branch if fader is not masterfader
;; store 10-bit result in LC_MFADER_POS_[LH] if fader is masterfader and return
movff MIOS_PARAMETER2, LC_MFADER_POS_L ; MIDI LSB -> LC_MFADER_POS_L
movff MIOS_PARAMETER3, LC_MFADER_POS_H ; MIDI MSB -> LC_MFADER_POS_H
return
LC_FADER_MOVE
;; store 10-bit result in LC_FADER_POS_[LH]
movff MIOS_PARAMETER2, LC_FADER_POS_L ; MIDI LSB -> LC_FADER_POS_L
movff MIOS_PARAMETER3, LC_FADER_POS_H ; MIDI MSB -> LC_FADER_POS_H
;; finally move fader
movff LC_FADER_POS_L, MIOS_PARAMETER1
movff LC_FADER_POS_H, MIOS_PARAMETER2
movf LC_FADER_NUMBER, W
goto MIOS_MF_FaderMove
Change in lc_enc.inc: (in my setup last encoder No.28 is for masterfader-event)
...
;; --------------------------------------------------------------------------
;; This function is called by MIOS when an encoder has been moved
;; Input:
;; o Encoder number in WREG and MIOS_PARAMETER1
;; o signed incrementer value in MIOS_PARAMETER2:
;; - is positive when encoder has been turned clockwise
;; - is negative when encoder has been turned counter clockwise
;; --------------------------------------------------------------------------
USER_ENC_NotifyChange
;; if encoder number within 0 and 7, send a V-pot event
movlw 0x07
IFLEQ MIOS_PARAMETER1, ACCESS, goto LC_ENC_SendVPot
;; send generic cubase "MasterVolumen" event
movlw 0x08
IFGEQ MIOS_PARAMETER1, ACCESS, goto LC_ENC_SendMasterVolumen
;; send generic cubase"relative" event
movlw 0x1c
IFNEQ MIOS_PARAMETER1, ACCESS, goto LC_ENC_SendCubaseRemote ;in my setup some encoders control cubase-generic-remote
;; else do nothing
return
...
!! You have to modify the branches to your design !! …and add following lines:
...
;; --------------------------------------------------------------------------
;; This function is called by MIOS when encoder sends "mastervolume"
;; Input:
;; o signed incrementer value in MIOS_PARAMETER2:
;; - is positive when encoder has been turned clockwise
;; - is negative when encoder has been turned counter clockwise
;; --------------------------------------------------------------------------
LC_ENC_SendMasterVolumen
; -----------------------------------------------------
;; save incrementer in LC_MFADER_LAST_INC
movff MIOS_PARAMETER2, LC_MFADER_LAST_INC
;; now we have to add (or subtract) the incrementer from the absolute value,
;; which has been stored in LC_MFADER_POS_L
;; the simplest solution is the use of MIOS_HLP_16bitAddSaturate, which
;; can handle with values up to 16 bit!!! :-)
;; please refer to the function documentation for the input/output parameters!
;; set pointer to LC_MFADER_POS_L
;; (it is located to an even address, thats important when this function is used!)
;; (and since we are modifying a 16-bit value, the next address to the low-byte
;; is used as high-byte -> see app_defines.h)
lfsr FSR1, LC_MFADER_POS_L
;; set max value
movlw 0xff ; low-byte of max value
movwf MIOS_PARAMETER1
movlw 0x03 ; high-byte of max value
movwf MIOS_PARAMETER2
;; get incrementer (which has been stored in LC_MFADER_LAST_INC)
movf LC_MFADER_LAST_INC, W
;; call routine
call MIOS_HLP_16bitAddSaturate
;; now [FSR1] = INDF1 = LC_MFADER_POS_L contains the result
;; MIOS_PARAMETER1[0] is set when value has been changed
;; exit routine if value has not been changed
IFCLR MIOS_PARAMETER1, 0, return
;-----------------------------------------------------------
movf LC_MFADER_POS_L, W
movwf LC_FADER_POS_L
movf LC_MFADER_POS_H, W
movwf LC_FADER_POS_H
;; 10 bit -> 14 bit (LC_MFADER_POS_[LH] << 4)
clrc
rlf LC_FADER_POS_L, F ; 1
rlf LC_FADER_POS_H, F
rlf LC_FADER_POS_L, F ; 2
rlf LC_FADER_POS_H, F
rlf LC_FADER_POS_L, F ; 3
rlf LC_FADER_POS_H, F
rlf LC_FADER_POS_L, F ; 4
rlf LC_FADER_POS_H, F
;; MIDI MSB: (LC_FADER_POS_H << 1) | LC_FADER_POS_L[7]
clrc
rlf LC_FADER_POS_H, W
IFSET LC_FADER_POS_L, 7, iorlw 0x01
movwf LC_FADER_POS_H
;; MIDI LSB: LC_FADER_POS_L & 0x7f
movlw 0x7f
andwf LC_FADER_POS_L, F
;; for MIDIbox Link: notify begin of stream
call MIOS_MIDI_BeginStream
;; finally send value: E8 LSB MSB for masterfader
movlw 0xe8
call MIOS_MIDI_TxBufferPut
movf LC_FADER_POS_L, W
call MIOS_MIDI_TxBufferPut
movf LC_FADER_POS_H, W
call MIOS_MIDI_TxBufferPut
;; for MIDIbox Link: notify end of stream
call MIOS_MIDI_EndStream
return
Add in app_defines.h :
...
;; masterfader value for encoder
LC_MFADER_POS_L EQU 0x030 ; received and transmitted low byte of fader position; low byte of 16-bit absolute value, address must be even!!!
LC_MFADER_POS_H EQU 0x031 ; received and transmitted high byte of fader position; high byte of 16-bit absolute value, address must be odd!!!
LC_MFADER_SPEED EQU 0x032 ; the speed setting, selected by Inc/Dec button
LC_MFADER_LAST_INC EQU 0x033 ; last incrementer
...
Add at the end of lc_init.inc :
...
;; set speed for encoder "masterfader" to "fast", speed exponent value is 3
movlw 0x03 ; speed exponent
movwf MIOS_PARAMETER2
movlw MIOS_ENC_SPEED_FAST ; fast speed mode
movwf MIOS_PARAMETER1
movlw 0x1c ; in my setup encoder number 28 is masterfader
call MIOS_ENC_SpeedSet
return
;; <------------------------------------------------------>
...
Have fun ;D
Pearl