d2k Posted July 17, 2004 Report Share Posted July 17, 2004 Hey...In my LC i have 2 cores, the 2nd core just handles the master fader (regular pot) and a additonal 16x2 lcd...Is it possible to makes use of another 2 ain inputs (so A1 and A2) on the 2nd core (for a joystick) and have it just send regular CC events over the midi chain?Cheers. Quote Link to comment Share on other sites More sharing options...
TK. Posted July 18, 2004 Report Share Posted July 18, 2004 Hi Dan,sure, the USER_AIN_NotifyChange hook can be found in lc_mf.incAlthough "_mf.inc" implies that this file is intented for motorfaders only, this does not mean that you wouldn't be able to react on any other analog control element from there.Best Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
d2k Posted July 18, 2004 Author Report Share Posted July 18, 2004 yes, i imagined it would be possible and u make it sound so easy...but...where to start? ???Here is the tag:USER_AIN_NotifyChange LC_MF_FaderEvent ;; save the fader number in LC_FADER_NUMBER movwf LC_FADER_NUMBER #if TOUCH_SENSOR_MODE >= 2 ;; in this mode, no value will be sent if touch sensor not active movf LC_FADER_NUMBER, W call MIOS_MF_SuspendGet bz LC_MF_FaderEvent_End #endif ;; store 10-bit LSB value in LC_FADER_POS_L movff MIOS_PARAMETER2, LC_FADER_POS_L ;; store 10-bit MSB value in LC_FADER_POS_H movff MIOS_PARAMETER3, LC_FADER_POS_H ;; shift the values to the right position like descriped in ;; the Logic Control MIDI implementation, chapter 12 ;; 10 bit -> 14 bit (LC_FADER_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: E<fader> LSB MSB movf LC_FADER_NUMBER, W andlw 0x0f #if MOTORFADER0_IS_MASTERFADER != 0 skpnz iorlw 0x08 #endif iorlw 0xe0 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 LC_MF_FaderEvent_End ;; thats all return ;; -------------------------------------------------------------------------- ;; 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 ;; derive 10-bit value from received 14-bit value. Store 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 ;; LSB = MSB[0] | MIDI LSB btfsc LC_FADER_POS_H, 0 bsf LC_FADER_POS_L, 7 ;; MSB = MIDI MSB >> 1 clrc rrf LC_FADER_POS_H, F ;; 10-bit value = 14-bit value >> 4 clrc rrf LC_FADER_POS_H, F ; 1 rrf LC_FADER_POS_L, F clrc rrf LC_FADER_POS_H, F ; 2 rrf LC_FADER_POS_L, F clrc rrf LC_FADER_POS_H, F ; 3 rrf LC_FADER_POS_L, F clrc rrf LC_FADER_POS_H, F ; 4 rrf LC_FADER_POS_L, F ;; 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 from ain eg 2 I see: USER_AIN_NotifyChange ;; a pot has been moved. ;; Send a MIDI event ;; save pot number in AIN_POT_NUMBER movff MIOS_PARAMETER1, AIN_POT_NUMBER ;; save low-byte of conversion result in AIN_VALUE_L movff MIOS_PARAMETER2, AIN_VALUE_L ;; save high-byte of conversion result in AIN_VALUE_H movff MIOS_PARAMETER3, AIN_VALUE_H ;; prepare pointer 0 for last value entry lfsr FSR0, AIN_VALUE_7BIT_BEGIN movf AIN_POT_NUMBER, W addwf FSR0L, F ;; now we can access the last pot value indirectly via INDF0 ;; prepare pointer 1 for active value entry lfsr FSR1, AIN_ACTIVE_VALUES_BEGIN movf AIN_POT_NUMBER, W addwf FSR1L, F ;; now we can access the active value indirectly via INDF1 ;; important for soft-overtake: save last pot value in AIN_LAST_VALUE ;; so that we can determine the direction (clockwise or counter-clockwise turn?) movff INDF0, AIN_LAST_VALUE ;; the AIN driver delivers a 10-bit result ;; convert it to a 7-bit value and save new result in AIN_VALUE_7BIT ;; the calculation is simple: the 10-bit value has to be divided by 8 ;; the common way for this simple division is to shift the value ;; three times to the right. Every right-shift divides the value by 2 clrc ; value / 2 rrf MIOS_PARAMETER3, F rrf MIOS_PARAMETER2, F clrc ; value / 2 rrf MIOS_PARAMETER3, F rrf MIOS_PARAMETER2, F clrc ; value / 2 rrf MIOS_PARAMETER3, F rrf MIOS_PARAMETER2, W ; copy result to working register (WREG) ;; makes: value / (2*2*2) == value / 8 ;; result is now in WREG, write result to AIN_VALUE_7BIT (INDF0) movwf INDF0 ;; if soft takeover has not been activated, continue behind the ;; handler IFCLR INDF1, 7, rgoto AIN_Cont ; (INDF1 == AIN_VALUE_7BIT[pot_number]) ;; continue of active value == new value movf INDF1, W andlw 0x7f ; (mask out snap bit) xorwf INDF0, W bz AIN_Cont ; values equal? continue! ;; else branch depending on clockwise or counter clockwise turn ;; means: last value <= new value movf AIN_LAST_VALUE, W IFLEQ INDF0, ACCESS, rgoto AIN_CounterClockwise AIN_Clockwise ;; pot has been moved clockwise ;; exit if if new value <= active value movf INDF1, W andlw 0x7f ; (mask out snap bit) IFLEQ INDF0, ACCESS, return ;; exit if active value >= last value IFGEQ AIN_LAST_VALUE, ACCESS, return ;; else continue rgoto AIN_Cont AIN_CounterClockwise ;; pot has been counter clockwise ;; exit if if new value >= active value movf INDF1, W andlw 0x7f ; (mask out snap bit) IFGEQ INDF0, ACCESS, return ;; exit if active value <= last value IFLEQ AIN_LAST_VALUE, ACCESS, return ;; else continue AIN_Cont ;; save 7-bit result in AIN_ACTIVE_VALUE movff INDF0, INDF1 ;; and clear snap bit bcf INDF1, 7 ;; ;; !!!IMPORTANT!!! ;; MIOS functions normaly overwrite the FSR1 pointer, where currently ;; the active value has been saved ;; so don't use INDF1 anymore below (or calculate the correct pointer to the ;; pot entry once more) ;; !!!IMPORTANT!!! ;; ;; now send a MIDI event which contains the new value ;; we read the entry from MIOS_MPROC_EVENT_TABLE ;; this has a big advantage: you can setup the "input" and "output" ;; events at one place! TABLE_ADDR MIOS_MPROC_EVENT_TABLE ; this macro sets the base address movf AIN_POT_NUMBER, W ; add pot offset (number *2) to TABLPTR mullw 2 ; multiplicate with 2, result in PROD[LH] movf PRODL, W addwf TBLPTRL, F ; low-byte movf PRODH, W addwfc TBLPTRH, F ; high-byte (+carry bit on overrun) ;; for MIDIbox Link: notify begin of stream call MIOS_MIDI_BeginStream ;; send first MIDI byte tblrd*+ ; read first byte from table movf TABLAT, W call MIOS_MIDI_TxBufferPut ; and send ;; send the second MIDI byte tblrd*+ ; read second byte from table movf TABLAT, W call MIOS_MIDI_TxBufferPut ; and send ;; send the third MIDI byte movf INDF0, W ; value from 0x00 to 0x7f call MIOS_MIDI_TxBufferPut ;; for MIDIbox Link: notify end of stream call MIOS_MIDI_EndStream ;; request a display update by setting DISPLAY_UPDATE_REQ,0 ;; USER_DISPLAY_Tick polls this flag! bsf DISPLAY_UPDATE_REQ, 0 ;; thats all return ENDSo i have to take some of ain eg 2 and combine with the code in lc_mc.inc right...no other files need touching? Quote Link to comment Share on other sites More sharing options...
d2k Posted July 18, 2004 Author Report Share Posted July 18, 2004 okay, I have no idea about this MIOS shiz...whoever can get this workin gets a one of these joysticks for free... Quote Link to comment Share on other sites More sharing options...
TK. Posted July 18, 2004 Report Share Posted July 18, 2004 ///////////////////////////////////////////////////////////////////////////// // This function is called by MIOS when a pot has been moved ///////////////////////////////////////////////////////////////////////////// void AIN_NotifyChange(unsigned char pin, unsigned int pin_value) { if( pin == 1 ) // J5.A1 { // send CC event for Joystick X axis MIOS_MIDI_TxBufferPut(0xb0); MIOS_MIDI_TxBufferPut(0x10); MIOS_MIDI_TxBufferPut(MIOS_AIN_Pin7bitGet(pin)); return; } if( pin == 2 ) // J5.A2 { // send CC event for Joystick Y axis MIOS_MIDI_TxBufferPut(0xb0); MIOS_MIDI_TxBufferPut(0x11); MIOS_MIDI_TxBufferPut(MIOS_AIN_Pin7bitGet(pin)); return; } // else continue with motorfader handling ... // ... // ... // ... } does it look less complicated or not?If yes: then it makes sense to wait for the MIOS C wrapper release... ;-)Best Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
d2k Posted July 18, 2004 Author Report Share Posted July 18, 2004 yes, I can safely say I dont understand any of that - as for any C bidness, again the same ball ache...::)and btw, that snippet of code u posted has thrown me even more - it looks like javascript or summin now (does not tie in with the way the code is written in ur .inc etc...needless to say the build failed ;D Quote Link to comment Share on other sites More sharing options...
TK. Posted July 18, 2004 Report Share Posted July 18, 2004 And I hoped that you are learning from all the tips and code snippets that I gave you in the past...However, here the assembler variant... if it doesn't work immediately, please first try to find out the problem by yourself to avoid a massive attack of ping-pong mails here in the forum (e.g. check the main.err file)In distance to the C example this code sends the events via MIDI channel 16, because channel 1 should be reserved for the LC protocol ;; -------------------------------------------------------------------------- ;; This function is called by MIOS when a pot has been moved ;; Input: ;; o Pot number in WREG and MIOS_PARAMETER1 ;; o LSB value in MIOS_PARAMETER2 ;; o MSB value in MIOS_PARAMETER3 ;; -------------------------------------------------------------------------- USER_AIN_NotifyChange LC_MF_FaderEvent ;; save the fader number in LC_FADER_NUMBER movwf LC_FADER_NUMBER movlw 0x01 IFNEQ LC_FADER_NUMBER, ACCESS, rgoto LC_MF_FaderEvent_Not1 LC_MF_FaderEvent_1 movlw 0xbf call MIOS_MIDI_TxBufferPut movlw 0x10 call MIOS_MIDI_TxBufferPut movf LC_FADER_NUMBER, W call MIOS_AIN_Pin7bitGet call MIOS_MIDI_TxBufferPut return LC_MF_FaderEvent_Not1 movlw 0x02 IFNEQ LC_FADER_NUMBER, ACCESS, rgoto LC_MF_FaderEvent_Not2 LC_MF_FaderEvent_2 movlw 0xbf call MIOS_MIDI_TxBufferPut movlw 0x11 call MIOS_MIDI_TxBufferPut movf LC_FADER_NUMBER, W call MIOS_AIN_Pin7bitGet call MIOS_MIDI_TxBufferPut return LC_MF_FaderEvent_Not2 ;; the rest of the LC MF handler ;; ... ;; ... ;; ... LC_MF_FaderEvent_End ;; thats all return Best Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
d2k Posted July 19, 2004 Author Report Share Posted July 19, 2004 And I hoped that you are learning from all the tips and code snippets that I gave you in the past...T, I try to but I'm afraid when it comes to any code it's a case of in 1 ear and out the other with me...always has been and MIOS/assembler is no exception...but hey, least u get one of these joysticks outta it  ;)if it doesn't work immediately...It worked!Cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.