Jump to content

bugfight

Frequent Writer
  • Posts

    812
  • Joined

  • Last visited

Posts posted by bugfight

  1. ok "soon" actually was soon in this case.

    i haven't checked this into svn, (tk let me know if you want me to...)

    but it is tested and working on my hardware.

    i'm not sure "descramble" is the best choice for naming it, though...

    here are the changes.

    in main.h i added:

    #define BLM_DESCRAMBLE_ROWS 1 //set this to 0 for 4x16 (like MB_Seq) and 1 for 8x8
    
    the rest of the changes are in main.c in Global variables, i added:
    #if BLM_DESCRAMBLE_ROWS
    unsigned char blm_button_row_dscrmbl;
    #endif
    
    in DISPLAY_Tick(), i replaced   
    MIOS_LCD_PrintBCD3(blm_button_row);:
    
    with
    
    #if BLM_DESCRAMBLE_ROWS
      MIOS_LCD_PrintBCD3(blm_button_row_dscrmbl);
    #else
      MIOS_LCD_PrintBCD3(blm_button_row);
    #endif
    
    here is the entire MPROC_NotifyReceivedEvnt() which contains the scramble code: i also corrected an error in local vars where led_column and led_row were reversed...
    void MPROC_NotifyReceivedEvnt(unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam
    {
      unsigned char led_column;
      unsigned char led_row;
      unsigned char evnt1Adj;
      unsigned char btnVal;
    
      // control the Duo-LEDs via Note On/Off Events
      // The colour is controlled with velocity value:
      // 0x00:       both LEDs off
      // 0x01..0x3f: green LED on
      // 0x40..0x5f: red LED on
      // 0x60..0x7f: both LEDs on
    
      // only MIDI note numbers from 0x00..0x3f are valid (-> 64 LEDs)
    
      evnt1Adj = (evnt1 - BLM_MIDI_STARTNOTE) & 0x7f;
      if( (evnt0 == 0x80 || evnt0 == 0x90) && (evnt1Adj < 0x40 ) ) {
    
        // derive LED column and row from note number
        
        led_column = evnt1Adj & 0x07;
    #if BLM_DESCRAMBLE_ROWS
        //scramble the rows, NOTE: this method is not scalable
        blm_button_row_dscrmbl = evnt1Adj >> 3;
        led_row = blm_button_row_dscrmbl;
    
        led_row <<= 1;
        if(led_row & 0x08) {
          led_row &= 0x07;
          led_row++;
        }
    #else
        led_row = evnt1Adj >> 3;
    #endif
    
        // 90 xx 00 is the same like a note off event!
        // (-> http://www.borg.com/~jglatt/tech/midispec.htm)
        if( evnt0 == 0x80 || evnt2 == 0x00 ) 
        {
          // Note Off or velocity == 0x00: clear both LEDs
          blm_row_green[led_row] &= MIOS_HLP_GetBitANDMask(led_column);
          blm_row_red[led_row]   &= MIOS_HLP_GetBitANDMask(led_column);
    
          btnVal = 1;
        } 
        else 
        {
          btnVal = 0;
    
          if( evnt2 < 0x40 ) {
            // Velocity < 0x40: set green LED, clear red LED
            blm_row_green[led_row] |= MIOS_HLP_GetBitORMask(led_column);
            blm_row_red[led_row]   &= MIOS_HLP_GetBitANDMask(led_column);
    
          } else if( evnt2 < 0x60 ) {
            // Velocity < 0x60: clear green LED, set red LED
            blm_row_green[led_row] &= MIOS_HLP_GetBitANDMask(led_column);
            blm_row_red[led_row]   |= MIOS_HLP_GetBitORMask(led_column);
          } else {
    
            // Velocity >= 0x60: set both LEDs
            blm_row_green[led_row] |= MIOS_HLP_GetBitORMask(led_column);
            blm_row_red[led_row]   |= MIOS_HLP_GetBitORMask(led_column);
          }
        }
    
        // enable this code (turn #if 0 into #if 1) if midi notes should change the LCD display
        // disable it when LCD should only be affected via buttons
    #if 1
        blm_button_row = led_row;
        blm_button_column = led_column;
        blm_button_value = btnVal;
        // request display update
        app_flags.DISPLAY_UPDATE_REQ = 1; 
    #endif
      }
    }
    
    
    here is the entire BLM_NotifyToggle() which contains the descramble code:
    void BLM_NotifyToggle(unsigned char pin, unsigned char value) __wparam
    {
      unsigned char mask;
      unsigned char noteNumber;
      
    #if BLM_DESCRAMBLE_ROWS
      //convert blm_button_row to blm_button_row_dscrmbl.  NOTE: this method is not scalable
      blm_button_row_dscrmbl = blm_button_row >> 1;
      if( 0x01 & blm_button_row ) //if row is odd number
        blm_button_row_dscrmbl |= 0x04; //
      noteNumber = ((blm_button_row_dscrmbl << 3) + blm_button_column + BLM_MIDI_STARTNOTE) & 0x7f;
    #else
      noteNumber = (pin + BLM_MIDI_STARTNOTE) & 0x7f;
    #endif
      
      // send pin number and value as Note On Event
      MIOS_MIDI_TxBufferPut(0x90);
      MIOS_MIDI_TxBufferPut(noteNumber);
      MIOS_MIDI_TxBufferPut(value ? 0x00 : 0x7f);
    
      // enable this code (turn #if 0 into #if 1) if buttons should change the LED colour directly
      // disable it when LEDs should only be controlled via MIDI
    #if 1
      // cycle colour whenever button has been pressed (value == 0)
      if( !value ) {
        mask = MIOS_HLP_GetBitORMask(blm_button_column);
        if ( blm_row_green[blm_button_row] & mask )
           blm_row_red[blm_button_row] ^= mask;
        blm_row_green[blm_button_row] ^= mask;
      }
    #endif
      // request display update
      app_flags.DISPLAY_UPDATE_REQ = 1;
    }
    
    

×
×
  • Create New...