Exemple #1
0
/////////////////////////////////////////////////////////////////////////////
// Local exit function
/////////////////////////////////////////////////////////////////////////////
static s32 EXIT_Handler(void)
{
  s32 status = 0;

  if( store_file_required ) {
    // write config file
    MUTEX_SDCARD_TAKE;
    if( (status=SEQ_FILE_GC_Write()) < 0 )
      SEQ_UI_SDCardErrMsg(2000, status);
    MUTEX_SDCARD_GIVE;
  }

  return status;
}
/////////////////////////////////////////////////////////////////////////////
// Local button callback function
// Should return:
//   1 if value has been changed
//   0 if value hasn't been changed
//  -1 if invalid or unsupported button
/////////////////////////////////////////////////////////////////////////////
static s32 Button_Handler(seq_ui_button_t button, s32 depressed)
{
  if( depressed ) return 0; // ignore when button depressed

#if 0
  // leads to: comparison is always true due to limited range of data type
  if( button >= SEQ_UI_BUTTON_GP1 && button <= SEQ_UI_BUTTON_GP16 ) {
#else
  if( button <= SEQ_UI_BUTTON_GP16 ) {
#endif
    // re-use encoder handler - only select UI item, don't increment, flags will be toggled
    return Encoder_Handler((int)button, 0);
  }

  // remaining buttons:
  switch( button ) {
    case SEQ_UI_BUTTON_Select:
    case SEQ_UI_BUTTON_Right:
      if( ++ui_selected_item >= NUM_OF_ITEMS )
	ui_selected_item = 0;
      SetSubpageBasedOnItem(ui_selected_item);
      return 1; // value always changed

    case SEQ_UI_BUTTON_Left:
      if( ui_selected_item == 0 )
	ui_selected_item = NUM_OF_ITEMS-1;
      else
	--ui_selected_item;
      SetSubpageBasedOnItem(ui_selected_item);
      return 1; // value always changed

    case SEQ_UI_BUTTON_Up:
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);

    case SEQ_UI_BUTTON_Down:
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
  }

  return -1; // invalid or unsupported button
}


/////////////////////////////////////////////////////////////////////////////
// Local Display Handler function
// IN: <high_prio>: if set, a high-priority LCD update is requested
/////////////////////////////////////////////////////////////////////////////
static s32 LCD_Handler(u8 high_prio)
{
  if( high_prio )
    return 0; // there are no high-priority updates

  // layout:
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
  // <--------------------------------------><-------------------------------------->
  // Transposer  Section    MIDI   Ext.       Bus Port Chn. Lower/Upper Mode   Reset 
  //  and Arp.   Control   Router  Ctrl Misc.  1  IN1  #16   ---   ---  T&A    Stacks

  // Transposer  Section    MIDI   Ext.      Port Chn.  G1   G2   G3   G4  Fwd  Reset
  //  and Arp.   Control   Router  Ctrl Misc. All #16  C-1  C-2  C-3  C-4  USB1 Stcks

  // Transposer  Section    MIDI   Ext.      Node IN P/Chn  OUT P/Chn   | DefaultPort
  //  and Arp.   Control   Router  Ctrl Misc. #1  Def. All  Def. # 1    |    USB1    

  // Transposer  Section    MIDI   Ext.      Port Chn.      Function        CC#      
  // Transposer  Section    MIDI   Ext.       IN  OUT Chn.| Function        CC#      
  //  and Arp.   Control   Router  Ctrl Misc. All off --- | Morph Value       1      

  // Transposer  Section    MIDI   Ext.      BLM_SCALAR                       MIDI   
  //  and Arp.   Control   Router  Ctrl Misc.Port: OUT2                     Monitor 


  seq_midi_router_node_t *n = &seq_midi_router_node[selected_router_node];

  ///////////////////////////////////////////////////////////////////////////
//<<<<<<< .mine
 /*
  const char leftpage[2][41] = {
    "Transposer  Section    MIDI             ",
    " and Arp.   Control   Router    Misc.   "
  };
=======
*/
  SEQ_LCD_CursorSet(0, 0);
  SEQ_LCD_PrintString("Transposer  Section    MIDI   Ext.      ");
  SEQ_LCD_CursorSet(0, 1);
  SEQ_LCD_PrintString(" and Arp.   Control   Router  Ctrl Misc.");
//>>>>>>> .r1826

  if( ui_cursor_flash && selected_subpage <= 5 ) {
    const u8 select_pos1[5]  = {  0, 10, 20, 30, 35 };
    const u8 select_width[5] = { 10, 10, 10,  5,  5 };

    int line;
    for(line=0; line<2; ++line) {
      SEQ_LCD_CursorSet(select_pos1[selected_subpage], line);
      SEQ_LCD_PrintSpaces(select_width[selected_subpage]);
    }
  }
/*
	SEQ_LCD_CursorSet(0, 0);
	if (selected_subpage == SUBPAGE_TRANSPOSE && ui_cursor_flash) {
		SEQ_LCD_PrintSpaces(21);
	} else {
		SEQ_LCD_PrintString(" Transposer and Arp ");
    }
	SEQ_LCD_CursorSet(0, 1);
	if (selected_subpage == SUBPAGE_SECTIONS && ui_cursor_flash) {
		SEQ_LCD_PrintSpaces(21);
	} else {
		SEQ_LCD_PrintString("   Section control   ");
    }
	SEQ_LCD_CursorSet(0, 2);
	if (selected_subpage == SUBPAGE_ROUTER && ui_cursor_flash) {
		SEQ_LCD_PrintSpaces(21);
	} else {
		SEQ_LCD_PrintString("     MIDI router     ");
    }
	SEQ_LCD_CursorSet(0, 3);
	if (selected_subpage == SUBPAGE_MISC && ui_cursor_flash) {
		SEQ_LCD_PrintSpaces(21);
	} else {
		SEQ_LCD_PrintString("     Miscilenious     ");
    }
	*/
	SEQ_LCD_CursorSet(0, 4);
	
  switch( selected_subpage ) {
  ///////////////////////////////////////////////////////////////////////////
    case SUBPAGE_TRANSPOSE: {

	  //SEQ_LCD_CursorSet(40, 0);
      SEQ_LCD_PrintString(" Bus Port Chn. Mode  ");
	  SEQ_LCD_CursorSet(0, 6);
	  SEQ_LCD_PrintString(" Lower/Upper   Reset ");
      SEQ_LCD_CursorSet(0, 5);

      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_IN_BUS && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(5);
      } else {
	SEQ_LCD_PrintFormattedString("  %d  ", selected_bus+1);
      }

      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_IN_PORT && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(4);
      } else {
	if( seq_midi_in_port[selected_bus] )
	  SEQ_LCD_PrintString(SEQ_MIDI_PORT_InNameGet(SEQ_MIDI_PORT_InIxGet(seq_midi_in_port[selected_bus])));
	else
	  SEQ_LCD_PrintString(" All");
      }
      SEQ_LCD_PrintSpaces(1);


      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_IN_CHN && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(3);
      } else {
	if( seq_midi_in_channel[selected_bus] )
	  SEQ_LCD_PrintFormattedString("#%2d", seq_midi_in_channel[selected_bus]);
	else
	  SEQ_LCD_PrintString("---");
      }
      SEQ_LCD_PrintSpaces(3);

/*
      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_IN_MODE && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(4);
      } else {
	SEQ_LCD_PrintString(seq_midi_in_options[selected_bus].MODE_PLAY ? "Play" : "T&A ");
      }
      SEQ_LCD_PrintSpaces(3);	  
	  
	  SEQ_LCD_CursorSet(0, 7);
*/	  
      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_IN_LOWER && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(3);
      } else {
	SEQ_LCD_PrintNote(seq_midi_in_lower[selected_bus]);
      }
      SEQ_LCD_PrintSpaces(3);


      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_IN_UPPER && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(3);
      } else {
	SEQ_LCD_PrintNote(seq_midi_in_upper[selected_bus]);
      }
      SEQ_LCD_PrintSpaces(2);


      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_IN_MODE && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(4);
      } else {
	SEQ_LCD_PrintString(seq_midi_in_options[selected_bus].MODE_PLAY ? "Play" : "T&A ");
      }
      SEQ_LCD_PrintSpaces(3);

	  
      SEQ_LCD_PrintString("Stacks");
    } break;


  ///////////////////////////////////////////////////////////////////////////
    case SUBPAGE_SECTIONS: {
      //SEQ_LCD_CursorSet(40, 0);
      SEQ_LCD_PrintString(" Port Chn.  G1   G2  "); 
      SEQ_LCD_CursorSet(0, 6);
	  SEQ_LCD_PrintString(" G3   G4  Fwd  Reset ");

	  SEQ_LCD_CursorSet(0, 5);
	  
      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_S_PORT && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(4);
      } else {
	if( seq_midi_in_sect_port )
	  SEQ_LCD_PrintString(SEQ_MIDI_PORT_InNameGet(SEQ_MIDI_PORT_InIxGet(seq_midi_in_sect_port)));
	else
	  SEQ_LCD_PrintString(" All");
      }
      SEQ_LCD_PrintSpaces(1);

      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_S_CHN && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(3);
      } else {
	if( seq_midi_in_sect_channel )
	  SEQ_LCD_PrintFormattedString("#%2d", seq_midi_in_sect_channel);
	else
	  SEQ_LCD_PrintString("---");
      }
      SEQ_LCD_PrintSpaces(2);

      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_S_OCT_G1 && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(3);
      } else {
	SEQ_LCD_PrintNote(seq_midi_in_sect_note[0]);
      }
      SEQ_LCD_PrintSpaces(2);

      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_S_OCT_G2 && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(3);
      } else {
	SEQ_LCD_PrintNote(seq_midi_in_sect_note[1]);
      }
      SEQ_LCD_PrintSpaces(2);

	  
	  SEQ_LCD_CursorSet(0, 5);
	  
      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_S_OCT_G3 && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(3);
      } else {
	SEQ_LCD_PrintNote(seq_midi_in_sect_note[2]);
      }
      SEQ_LCD_PrintSpaces(2);

      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_S_OCT_G4 && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(3);
      } else {
	SEQ_LCD_PrintNote(seq_midi_in_sect_note[3]);
      }

      SEQ_LCD_PrintSpaces(2);

      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_S_FWD_PORT && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(4);
      } else {
	if( seq_midi_in_sect_fwd_port == 0 )
	  SEQ_LCD_PrintString("----");
	else
	  SEQ_LCD_PrintString(SEQ_MIDI_PORT_OutNameGet(SEQ_MIDI_PORT_OutIxGet(seq_midi_in_sect_fwd_port)));
      }

      SEQ_LCD_PrintSpaces(1);
      SEQ_LCD_PrintString("Stcks");
    } break;


  ///////////////////////////////////////////////////////////////////////////
    case SUBPAGE_ROUTER: {
//<<<<<<< .mine
      //SEQ_LCD_CursorSet(40, 0);
      SEQ_LCD_PrintString(" Node  IN Port/Chn   "); 
	  SEQ_LCD_CursorSet(0, 6);
	  SEQ_LCD_PrintString("OUT Port/Chn Def.Port");
      SEQ_LCD_CursorSet(0, 5);
/*
	  =======
      SEQ_LCD_CursorSet(40, 0);
      SEQ_LCD_PrintString("Node IN P/Chn  OUT P/Chn   | DefaultPort");
      SEQ_LCD_CursorSet(40, 1);
>>>>>>> .r1826
*/
      ///////////////////////////////////////////////////////////////////////
      SEQ_LCD_PrintSpaces(1);
      if( ui_selected_item == ITEM_R_NODE && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(3);
      } else {
	SEQ_LCD_PrintFormattedString("#%2d", selected_router_node+1);
      }
      SEQ_LCD_PrintSpaces(1);

      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_R_SRC_PORT && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(4);
      } else {
	SEQ_LCD_PrintString(SEQ_MIDI_PORT_InNameGet(SEQ_MIDI_PORT_InIxGet(n->src_port)));
      }
      SEQ_LCD_PrintSpaces(1);

      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_R_SRC_CHN && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(3);
      } else {
	if( !n->src_chn ) {
	  SEQ_LCD_PrintString("---");
	} else if( n->src_chn > 16 ) {
	  SEQ_LCD_PrintString("All");
	} else {
	  SEQ_LCD_PrintFormattedString("#%2d", n->src_chn);
	}
      }
      SEQ_LCD_PrintSpaces(2);

	  SEQ_LCD_CursorSet(0, 7);
	  
      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_R_DST_PORT && ui_cursor_flash ) {
	if( n->dst_chn >= 18 ) {
	  SEQ_LCD_PrintSpaces(2);
	} else {
	  SEQ_LCD_PrintSpaces(4);
	}
      } else {
	if( n->dst_chn >= 18 ) {
	  SEQ_LCD_PrintSpaces(2);
	} else {
	  SEQ_LCD_PrintString(SEQ_MIDI_PORT_OutNameGet(SEQ_MIDI_PORT_OutIxGet(n->dst_port)));
	}
      }

      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_R_DST_CHN && ui_cursor_flash ) {
	if( n->dst_chn >= 18 ) {
	  SEQ_LCD_PrintSpaces(7);
	} else {
	  SEQ_LCD_PrintSpaces(5);
	}
      } else {
	if( !n->dst_chn ) {
	  SEQ_LCD_PrintString(" --- ");
	} else if( n->dst_chn == 17 ) {
	  SEQ_LCD_PrintString(" All ");
	} else if( n->dst_chn == 18 ) {
	  SEQ_LCD_PrintString("  Track");
	} else if( n->dst_chn >= 19 ) {
	  SEQ_LCD_PrintString("Sel.Trk");
	} else {
	  SEQ_LCD_PrintFormattedString(" #%2d ", n->dst_chn);
	}
      }
      SEQ_LCD_PrintSpaces(3);

      ///////////////////////////////////////////////////////////////////////
      SEQ_LCD_PrintChar('|');
      SEQ_LCD_PrintSpaces(4);

      if( ui_selected_item == ITEM_DEF_PORT && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(4);
      } else {
	SEQ_LCD_PrintString(SEQ_MIDI_PORT_OutNameGet(SEQ_MIDI_PORT_OutIxGet(MIOS32_MIDI_DefaultPortGet())));
      }
      SEQ_LCD_PrintSpaces(4);
    } break;


  ///////////////////////////////////////////////////////////////////////////
    case SUBPAGE_EXT_CTRL: {
      SEQ_LCD_CursorSet(40, 0);
      SEQ_LCD_PrintString(" IN  OUT  Chn.|Function        ");
      if( selected_ext_ctrl < SEQ_MIDI_IN_EXT_CTRL_NUM_IX_CC ) {
	SEQ_LCD_PrintString("CC#      ");
      } else {
	SEQ_LCD_PrintSpaces(10);
      }
      SEQ_LCD_CursorSet(40, 1);

      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_EXT_PORT && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(4);
      } else {
	if( seq_midi_in_ext_ctrl_port == 0xff )
	  SEQ_LCD_PrintString(" All");
	else if( !seq_midi_in_ext_ctrl_port )
	  SEQ_LCD_PrintString(" off");
	else
	  SEQ_LCD_PrintString(SEQ_MIDI_PORT_InNameGet(SEQ_MIDI_PORT_InIxGet(seq_midi_in_ext_ctrl_port)));
      }
      SEQ_LCD_PrintSpaces(1);

      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_EXT_PORT_OUT && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(4);
      } else {
	if( seq_midi_in_ext_ctrl_out_port )
	  SEQ_LCD_PrintString(SEQ_MIDI_PORT_OutNameGet(SEQ_MIDI_PORT_OutIxGet(seq_midi_in_ext_ctrl_out_port)));
	else
	  SEQ_LCD_PrintString("off ");
      }
      SEQ_LCD_PrintSpaces(1);

      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_EXT_CHN && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(3);
      } else {
	if( seq_midi_in_ext_ctrl_channel )
	  SEQ_LCD_PrintFormattedString("#%2d", seq_midi_in_ext_ctrl_channel);
	else
	  SEQ_LCD_PrintString("---");
      }
      SEQ_LCD_PrintString(" |");

      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_EXT_CTRL && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(15);
      } else {
	SEQ_LCD_PrintStringPadded((char *)SEQ_MIDI_IN_ExtCtrlStr(selected_ext_ctrl), 15);
      }


      ///////////////////////////////////////////////////////////////////////
      if( ui_selected_item == ITEM_EXT_VALUE && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(10);
      } else {
	SEQ_LCD_PrintSpaces(1);
	if( selected_ext_ctrl == SEQ_MIDI_IN_EXT_CTRL_NRPN_ENABLED ) {
	  SEQ_LCD_PrintStringPadded(seq_midi_in_ext_ctrl_asg[selected_ext_ctrl] ? "enabled" : "disabled", 9);
	} else if( selected_ext_ctrl == SEQ_MIDI_IN_EXT_CTRL_PC_MODE ) {
	  SEQ_LCD_PrintStringPadded((char *)SEQ_MIDI_IN_ExtCtrlPcModeStr(seq_midi_in_ext_ctrl_asg[selected_ext_ctrl]), 9);
	} else {
	  u8 cc = seq_midi_in_ext_ctrl_asg[selected_ext_ctrl];
	  if( cc >= 0x80 )
	    SEQ_LCD_PrintString("off");
	  else
	    SEQ_LCD_PrintFormattedString("%3d", cc);
	  SEQ_LCD_PrintSpaces(7);
	}
      }

    } break;


  ///////////////////////////////////////////////////////////////////////////
    case SUBPAGE_MISC: {
      //SEQ_LCD_CursorSet(40, 0);
//<<<<<<< .mine
      SEQ_LCD_PrintString("BLM_SCALAR ");
      SEQ_LCD_PrintString(blm_timeout_ctr ? "connected  " : "not found ");
      SEQ_LCD_CursorSet(0, 6);
	  SEQ_LCD_PrintString("         MIDI   ");
      SEQ_LCD_CursorSet(0, 5);
/*
	  =======
      SEQ_LCD_PrintString("BLM_SCALAR                       MIDI   ");
      SEQ_LCD_CursorSet(40, 1);
>>>>>>> .r1826
*/
      ///////////////////////////////////////////////////////////////////////
      SEQ_LCD_PrintString("Port: ");
      if( ui_selected_item == ITEM_BLM_SCALAR_PORT && ui_cursor_flash ) {
	SEQ_LCD_PrintSpaces(4);
      } else {
	if( !seq_blm_port )
	  SEQ_LCD_PrintString(" off");
	else
	  SEQ_LCD_PrintString(SEQ_MIDI_PORT_InNameGet(SEQ_MIDI_PORT_InIxGet(seq_blm_port)));
      }

//<<<<<<< .mine
	  SEQ_LCD_CursorSet(0, 7);
	  
//=======
      SEQ_LCD_PrintString(blm_timeout_ctr ? " (found)  " : "          ");

      // free for new parameters
      SEQ_LCD_PrintSpaces(12);

//>>>>>>> .r1826
      ///////////////////////////////////////////////////////////////////////
      SEQ_LCD_PrintString("Monitor ");

    } break;
  }

  return 0; // no error
}


/////////////////////////////////////////////////////////////////////////////
// Local exit function
/////////////////////////////////////////////////////////////////////////////
static s32 EXIT_Handler(void)
{
  s32 status = 0;

  if( store_file_required ) {
    // write config files
    MUTEX_SDCARD_TAKE;
    if( (status=SEQ_FILE_C_Write(seq_file_session_name)) < 0 )
      SEQ_UI_SDCardErrMsg(2000, status);
    MUTEX_SDCARD_GIVE;

    MUTEX_SDCARD_TAKE;
    if( (status=SEQ_FILE_GC_Write()) < 0 )
      SEQ_UI_SDCardErrMsg(2000, status);
    MUTEX_SDCARD_GIVE;
  }

  return status;
}
Exemple #3
0
/////////////////////////////////////////////////////////////////////////////
// Local button callback function
// Should return:
//   1 if value has been changed
//   0 if value hasn't been changed
//  -1 if invalid or unsupported button
/////////////////////////////////////////////////////////////////////////////
static s32 Button_Handler(seq_ui_button_t button, s32 depressed)
{
  if( depressed ) return 0; // ignore when button depressed

#if 0
  // leads to: comparison is always true due to limited range of data type
  if( button >= SEQ_UI_BUTTON_GP1 && button <= SEQ_UI_BUTTON_GP16 ) {
#else
  if( button <= SEQ_UI_BUTTON_GP16 ) {
#endif
    // re-use encoder handler - only select UI item, don't increment, flags will be toggled
    return Encoder_Handler((int)button, 0);
  }

  // remaining buttons:
  switch( button ) {
    case SEQ_UI_BUTTON_Select:
    case SEQ_UI_BUTTON_Right:
      if( depressed ) return -1;
      if( ++ui_selected_item >= NUM_OF_ITEMS )
	ui_selected_item = 0;
      return 1; // value always changed

    case SEQ_UI_BUTTON_Left:
      if( depressed ) return -1;
      if( ui_selected_item == 0 )
	ui_selected_item = NUM_OF_ITEMS-1;
      else
	--ui_selected_item;
      return 1; // value always changed

    case SEQ_UI_BUTTON_Up:
      if( depressed ) return -1;
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, 1);

    case SEQ_UI_BUTTON_Down:
      if( depressed ) return -1;
      return Encoder_Handler(SEQ_UI_ENCODER_Datawheel, -1);
  }

  return -1; // invalid or unsupported button
}


/////////////////////////////////////////////////////////////////////////////
// Local Display Handler function
// IN: <high_prio>: if set, a high-priority LCD update is requested
/////////////////////////////////////////////////////////////////////////////
static s32 LCD_Handler(u8 high_prio)
{
  if( high_prio )
    return 0; // there are no high-priority updates

  // layout:
  // 00000000001111111111222222222233333333330000000000111111111122222222223333333333
  // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
  // <--------------------------------------><-------------------------------------->
  //  CV  Curve SlewRate PRng  Gate  Calibr.  Clk   Rate    Width             Module 
  //   1  V/Oct    0 mS    2   Pos.    off     1   24 PPQN   1 mS             AOUT_NG


  ///////////////////////////////////////////////////////////////////////////
  SEQ_LCD_CursorSet(0, 0);
  SEQ_LCD_PrintString(" CV  Curve SlewRate PRng  Gate  Calibr.  Clk   Rate    Width             Module ");

  ///////////////////////////////////////////////////////////////////////////
  SEQ_LCD_CursorSet(0, 1);

  ///////////////////////////////////////////////////////////////////////////
  if( ui_selected_item == ITEM_CV && ui_cursor_flash ) {
    SEQ_LCD_PrintSpaces(5);
  } else {
    SEQ_LCD_PrintFormattedString(" %2d  ", selected_cv+1);
  }

  ///////////////////////////////////////////////////////////////////////////
  if( ui_selected_item == ITEM_CURVE && ui_cursor_flash ) {
    SEQ_LCD_PrintSpaces(6);
  } else {
    SEQ_LCD_PrintString((char *)SEQ_CV_CurveNameGet(selected_cv));
  }

  ///////////////////////////////////////////////////////////////////////////
  if( ui_selected_item == ITEM_SLEWRATE && ui_cursor_flash ) {
    SEQ_LCD_PrintSpaces(9);
  } else {
    SEQ_LCD_PrintFormattedString(" %3d mS  ", SEQ_CV_SlewRateGet(selected_cv));
  }

  ///////////////////////////////////////////////////////////////////////////
  if( ui_selected_item == ITEM_PITCHRANGE && ui_cursor_flash ) {
    SEQ_LCD_PrintSpaces(6);
  } else {
    SEQ_LCD_PrintFormattedString("%3d   ", SEQ_CV_PitchRangeGet(selected_cv));
  }

  ///////////////////////////////////////////////////////////////////////////
  if( ui_selected_item == ITEM_GATE && ui_cursor_flash ) {
    SEQ_LCD_PrintSpaces(6);
  } else {
    SEQ_LCD_PrintFormattedString(SEQ_CV_GateInversionGet(selected_cv) ? "Neg.  " : "Pos.  ");
  }

  ///////////////////////////////////////////////////////////////////////////
  if( ui_selected_item == ITEM_CALIBRATION && ui_cursor_flash ) {
    SEQ_LCD_PrintSpaces(8);
  } else {
    SEQ_LCD_PrintFormattedString(" %s ", SEQ_CV_CaliNameGet());
  }

  ///////////////////////////////////////////////////////////////////////////
  if( ui_selected_item == ITEM_CLK_SEL && ui_cursor_flash ) {
    SEQ_LCD_PrintSpaces(4);
  } else {
    SEQ_LCD_PrintFormattedString("%3d ", selected_clkout + 1);
  }
  SEQ_LCD_PrintSpaces(2);

  ///////////////////////////////////////////////////////////////////////////
  if( ui_selected_item == ITEM_CLK_PPQN && ui_cursor_flash ) {
    SEQ_LCD_PrintSpaces(9);
  } else {
    u16 divider = SEQ_CV_ClkDividerGet(selected_clkout);
    if( !divider ) {
      SEQ_LCD_PrintFormattedString("StartStop", 384 / divider);
    } else {
      SEQ_LCD_PrintFormattedString("%3d PPQN ", 384 / divider);
    }
  }

  ///////////////////////////////////////////////////////////////////////////
  if( ui_selected_item == ITEM_CLK_WIDTH && ui_cursor_flash ) {
    SEQ_LCD_PrintSpaces(6);
  } else {
    SEQ_LCD_PrintFormattedString("%3d mS", SEQ_CV_ClkPulseWidthGet(selected_clkout));
  }

  SEQ_LCD_PrintSpaces(12);

  ///////////////////////////////////////////////////////////////////////////
  if( ui_selected_item == ITEM_MODULE && ui_cursor_flash ) {
    SEQ_LCD_PrintSpaces(8);
  } else {
    SEQ_LCD_PrintString((char *)SEQ_CV_IfNameGet(SEQ_CV_IfGet()));
  }


  return 0; // no error
}


/////////////////////////////////////////////////////////////////////////////
// Local exit function
/////////////////////////////////////////////////////////////////////////////
static s32 EXIT_Handler(void)
{
  s32 status = 0;

  // ensure that calibration mode disabled
  SEQ_CV_CaliModeSet(selected_cv, AOUT_CALI_MODE_OFF);

  if( store_file_required ) {
    // write config file
    MUTEX_SDCARD_TAKE;
    if( (status=SEQ_FILE_GC_Write()) < 0 )
      SEQ_UI_SDCardErrMsg(2000, status);
    MUTEX_SDCARD_GIVE;

    store_file_required = 0;
  }

  return status;
}
Exemple #4
0
/////////////////////////////////////////////////////////////////////////////
// This task is called periodically each second
/////////////////////////////////////////////////////////////////////////////
void SEQ_TASK_Period1S(void)
{
  static s8 wait_boot_ctr = 3; // wait 3 seconds before loading from SD Card - this is to increase the time where the boot screen is print!
  u8 load_sd_content = 0;

  // poll for IIC modules as long as HW config hasn't been locked (read from SD card)
  // TODO: use proper mutex handling here
#ifndef MIOS32_FAMILY_EMULATION
  if( !SEQ_FILE_HW_ConfigLocked() ) {
    MIOS32_IIC_MIDI_ScanInterfaces();
  }
#endif  

  // boot phase of 2 seconds finished?
  if( wait_boot_ctr > 0 ) {
    --wait_boot_ctr;
    if( wait_boot_ctr )
      return;
  }

  // BLM timeout counter
  MIOS32_IRQ_Disable();
  if( seq_blm_timeout_ctr )
    --seq_blm_timeout_ctr;
  MIOS32_IRQ_Enable();

  // check if SD Card connected
  MUTEX_SDCARD_TAKE;

  s32 status = FILE_CheckSDCard();

  if( status == 1 ) {
    if( wait_boot_ctr != 0 ) { // don't print message if we just booted
      char str[21];
      sprintf(str, "Label: %s", FILE_VolumeLabel());
#ifndef MBSEQV4L
      SEQ_UI_Msg(SEQ_UI_MSG_SDCARD, 2000, " SD Card connected", "        :-D");
#endif
      DEBUG_MSG("SD Card connected: %s\n", FILE_VolumeLabel());
    }
    SEQ_FILE_LoadSessionName();
    DEBUG_MSG("Loading session %s\n", seq_file_session_name);
    SEQ_FILE_LoadAllFiles(1);
  } else if( status == 2 ) {
#ifndef MBSEQV4L
    SEQ_UI_Msg(SEQ_UI_MSG_SDCARD, 2000, "SD Card disconnected", "        :-/");
#endif
    DEBUG_MSG("SD Card disconnected\n");
    SEQ_FILE_UnloadAllFiles();
    wait_boot_ctr = -1;
  } else if( status == 3 ) {
    if( !FILE_SDCardAvailable() ) {
#ifndef MBSEQV4L
      SEQ_UI_Msg(SEQ_UI_MSG_SDCARD, 2000, "  No SD Card found  ", "        :-(");
#endif
      DEBUG_MSG("SD Card not found\n");
      SEQ_FILE_HW_LockConfig(); // lock configuration
      wait_boot_ctr = -1;
    } else if( !FILE_VolumeAvailable() ) {
#ifndef MBSEQV4L
      SEQ_UI_Msg(SEQ_UI_MSG_SDCARD, 2000, "!! SD Card Error !!!", "!! Invalid FAT !!!!!");
#endif
      DEBUG_MSG("ERROR: SD Card contains invalid FAT!\n");
      SEQ_FILE_HW_LockConfig(); // lock configuration
      wait_boot_ctr = -1;
    } else {
#ifndef MBSEQV4L
      if( wait_boot_ctr != 0 ) { // don't print message if we just booted
	char str1[30];
	sprintf(str1, "Banks: ....");
	u8 bank;
	for(bank=0; bank<4; ++bank)
	  str1[7+bank] = SEQ_FILE_B_NumPatterns(bank) ? ('1'+bank) : '-';
	char str2[30];
	sprintf(str2, 
		"M:%c S:%c G:%c C:%c%c HW:%c", 
		SEQ_FILE_M_NumMaps() ? '*':'-',
		SEQ_FILE_S_NumSongs() ? '*':'-',
		SEQ_FILE_G_Valid() ? '*':'-',
		SEQ_FILE_C_Valid() ? 'S':'-',
		SEQ_FILE_GC_Valid() ? 'G':'-',
		SEQ_FILE_HW_Valid() ? '*':'-');
	SEQ_UI_Msg(SEQ_UI_MSG_SDCARD, 2000, str1, str2);
      }
#endif

#if MBSEQV4L
      // auto-format
      // check if formatting is required
      if( SEQ_FILE_FormattingRequired() ) {
	strcpy(seq_file_new_session_name, "DEF_V4L");
	DEBUG_MSG("Creating initial session '%s'... this can take some seconds!\n", seq_file_new_session_name);

	if( (status=SEQ_FILE_Format()) < 0 ) {
	  DEBUG_MSG("Failed to create session! (status: %d)\n", status);
	} else {
	  SEQ_FILE_StoreSessionName();
	  DEBUG_MSG("Done!\n");
	}
      }
#endif

      // request to load content of SD card
      load_sd_content = 1;

      // notify that boot finished
      wait_boot_ctr = -1;
    }
  } else if( status < 0 ) {
    wait_boot_ctr = -1;
#ifndef MBSEQV4L
    SEQ_UI_SDCardErrMsg(2000, status);
#endif
    DEBUG_MSG("ERROR: SD Card Error %d (FatFs: D%3d)\n", status, file_dfs_errno);
  }

  // check for format request
  // this is running with low priority, so that LCD is updated in parallel!
  if( seq_ui_format_req ) {
    // note: request should be cleared at the end of this process to avoid double-triggers!
    if( (status = SEQ_FILE_Format()) < 0 ) {
#ifndef MBSEQV4L
      SEQ_UI_SDCardErrMsg(2000, status);
#endif
      DEBUG_MSG("ERROR: SD Card Error %d (FatFs: D%3d)\n", status, file_dfs_errno);
    } else {
#ifndef MBSEQV4L
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Files created", "successfully!");
#endif
      DEBUG_MSG("Files created successfully!\n");

      // store session name
      status |= SEQ_FILE_StoreSessionName();
    }

    // request to load content of SD card
    load_sd_content = 1;

    // finally clear request
    seq_ui_format_req = 0;
  }

  // check for backup request
  // this is running with low priority, so that LCD is updated in parallel!
  if( seq_ui_backup_req ) {
    // note: request should be cleared at the end of this process to avoid double-triggers!
    status = SEQ_FILE_CreateBackup();
      
    if( status < 0 ) {
      if( status == FILE_ERR_COPY ) {
#ifndef MBSEQV4L
	SEQ_UI_Msg(SEQ_UI_MSG_USER, 2000, "COPY FAILED!", "ERROR :-(");
#endif
	DEBUG_MSG("ERROR: copy failed!\n");
      } else {
#ifndef MBSEQV4L
	SEQ_UI_SDCardErrMsg(2000, status);
#endif
	DEBUG_MSG("ERROR: SD Card Error %d (FatFs: D%3d)\n", status, file_dfs_errno);
      }
    }
    else {
#ifndef MBSEQV4L
      SEQ_UI_Msg(SEQ_UI_MSG_USER, 1000, "Files copied", "successfully!");
#endif
      DEBUG_MSG("Files copied successfully!\n");

      // store session name
      status |= SEQ_FILE_StoreSessionName();
    }

    // finally clear request
    seq_ui_backup_req = 0;
  }

  // check for save all request
  // this is running with low priority, so that LCD is updated in parallel!
  if( seq_ui_saveall_req ) {
    s32 status = 0;

    // store all patterns
    int group;
    for(group=0; group<SEQ_CORE_NUM_GROUPS; ++group)
      status |= SEQ_FILE_B_PatternWrite(seq_file_session_name, seq_pattern[group].bank, seq_pattern[group].pattern, group, 1);

    // store config (e.g. to store current song/mixermap/pattern numbers
    SEQ_FILE_C_Write(seq_file_session_name);

    // store global config
    SEQ_FILE_GC_Write();

    // store mixer map
    SEQ_MIXER_Save(SEQ_MIXER_NumGet());

    // store session name
    if( status >= 0 )
      status |= SEQ_FILE_StoreSessionName();

    if( status < 0 ) {
#ifndef MBSEQV4L
      SEQ_UI_SDCardErrMsg(2000, status);
#endif
      DEBUG_MSG("ERROR: SD Card Error %d (FatFs: D%3d)\n", status, file_dfs_errno);
    }

    // finally clear request
    seq_ui_saveall_req = 0;
  }

  MUTEX_SDCARD_GIVE;

  // load content of SD card if requested ((re-)connection detected)
  if( load_sd_content && !SEQ_FILE_FormattingRequired() ) {
    // send layout request to MBHP_BLM_SCALAR
    MUTEX_MIDIOUT_TAKE;
    SEQ_BLM_SYSEX_SendRequest(0x00);
    MUTEX_MIDIOUT_GIVE;

    // TODO: should we load the patterns when SD Card has been detected?
    // disadvantage: current edit patterns are destroyed - this could be fatal during a live session if there is a bad contact!

    SEQ_MIXER_Load(SEQ_MIXER_NumGet());
    SEQ_SONG_Load(SEQ_SONG_NumGet());
  }

#ifndef MBSEQV4L
  SEQ_LCD_LOGO_ScreenSaver_Period1S();
#endif
}