Jump to content

midi router beat indicator


fabricio

Recommended Posts

Hi,

MIDI Router is a C based application. I guess that you want to indicate the beat based on the received MIDI Clock, right?

So, just do the modifications in router.c: hook the code into the ROUTER_Rx_xxx function of the MIDI In Port which receives the MIDI Clock.

Add a counter which is incremented on each incoming MIDI clock event (evnt0 == 0xf8)

Reset this counter on each incoming MIDI clock start event (evnt0 == 0xfa) or once the counter is >= 24 (-> 24 MIDI clocks = 1 beat)

Assumed, that you connect the LED to PIC Pin RC0, you can turn the LED on with PORTCbits.RC0 = 1, and turn it off with PORTCbits.RC0=0

So, turn it on whenever the counter is 0, and turn it off whenever the counter is != 0

Best Regards, Thorsten

Link to comment
Share on other sites

thank you for your answer.(waou tk himself).

after a lot of try i have succeed.

i show you the code in router.c :

void ROUTER_Rx_INT0(unsigned char ptype, unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam

{

  // Core MIDI IN, connected to my PC

  // lock/release this routing path on SysEx streams

  ROUTER_LockPathOnSysEx(PORT_INT0, ptype);

  // forward data to the MIDI OUTs of all IIC slaves

  if (evnt0 == 0xf8 && router_flags.EXT_CLOCK_MODE){

        ++ clock_counter;

        }

  else if (evnt0 == 0xfa){

            clock_counter = 0;

            MIOS_DOUT_PinSet1(3);

              router_flags.EXT_CLOCK_MODE = 1;

            }

  else if(evnt0 == 0xfc){

      clock_counter = 0;

      beat_counter = 0;

        router_flags.EXT_CLOCK_MODE = 0;

        ROUTER_Tx_IIC0(ptype, evnt0, evnt1, evnt2);

        ROUTER_Tx_IIC1(ptype, evnt0, evnt1, evnt2);

      }

 

  if (clock_counter >= 24){

                 

                    clock_counter = 0;

                    ++ beat_counter;

                    if(beat_counter == 4){

                                    MIOS_DOUT_PinSet1(3);

                                    beat_counter = 0;

                                    }

                    else{

                        MIOS_DOUT_PinSet1(4);

                          }

                        }

if( router_flags.EXT_CLOCK_MODE )  {               

ROUTER_Tx_IIC0(ptype, evnt0, evnt1, evnt2);

ROUTER_Tx_IIC1(ptype, evnt0, evnt1, evnt2);

}

}

and i have to modify midi_rxtx.asm :

#define MIDI_RXTX_LED_DELAY 3

; pin number of Rx LED

#define MIDI_RXTX_RX_LED 0x03

; pin number of Tx LED

#define MIDI_RXTX_RX_LED1 0x04

;

; ==========================================================================

;; export lables

global _MIDI_RXTX_NotifyRx

global _MIDI_RXTX_NotifyTx

global _MIDI_RXTX_Handler

; ==========================================================================

midi_rxtx_data udata

MIDI_RXTX_RX_CTR res 1

; ==========================================================================

MIDI_RXTX code

; ==========================================================================

;; --------------------------------------------------------------------------

;;  FUNCTION: MIDI_RXTX_NotifyRx

;;  DESCRIPTION: this function has to be called from the USER_MIDI_NotifyRx

;;  hook when a MIDI event has been received to reload the RX counter

;; --------------------------------------------------------------------------

_MIDI_RXTX_NotifyRx

;; called from mios_wrapper/mios_wrapper.asm

movlw MIDI_RXTX_LED_DELAY

SET_BSR MIDI_RXTX_RX_CTR

movwf MIDI_RXTX_RX_CTR, BANKED

return

;; --------------------------------------------------------------------------

;;  FUNCTION: MIDI_RXTX_NotifyTx

;;  DESCRIPTION: this function has to be called from the USER_MIDI_NotifyTx

;;  hook when a MIDI event will be transmitted to reload the TX counter

;; --------------------------------------------------------------------------

_MIDI_RXTX_NotifyTx

return

;; --------------------------------------------------------------------------

;;  FUNCTION: MIDI_RXTX_Handler

;;  DESCRIPTION: this function has to be called from the USER_SR_ServicePrpeare

;;  hook, it decrements the Rx/Tx counters and sets the LEDs depending on the

;;  counter values

;; --------------------------------------------------------------------------

_MIDI_RXTX_Handler

;; Decrement Rx counter if != 0

SET_BSR MIDI_RXTX_RX_CTR

movf MIDI_RXTX_RX_CTR, W, BANKED

skpz

decf MIDI_RXTX_RX_CTR, F, BANKED

;;

;; remove the code below if you don't want to use LEDs to

;; indicate the counter state

;;

;; set the Rx LED depending on counter state

        SET_BSR MIDI_RXTX_RX_CTR

movf MIDI_RXTX_RX_CTR, W, BANKED

bz _MIDI_RXTX_Handler_RxOff

        rgoto _MIDI_RXTX_Handler_Rx_Cont

_MIDI_RXTX_Handler_RxOff

movlw 0x00

movwf MIOS_PARAMETER1

movlw MIDI_RXTX_RX_LED

call MIOS_DOUT_PinSet

movlw 0x00

movwf MIOS_PARAMETER1

movlw MIDI_RXTX_RX_LED1

call MIOS_DOUT_PinSet0

_MIDI_RXTX_Handler_Rx_Cont

return

END

i don't know if it's elegant but the led (green and red)flash with the tempo

and i'm happy

fab

Link to comment
Share on other sites

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...