K1Guitar/UI/UI_SongMode.c

499 lines
18 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "includes.h"
extern uint8_t CurrentMode;
static uint8_t transpose[5] = {0xF0, 0x51, 0x05, 0x0A, 0xF7};
static uint8_t Speed[6] = {0xF0, 0x51, 0x03, 0x00, 0x00, 0xF7};
void Draw_Tab_Mode_Menu(const LEBEL_UI *UI, GUI_SWITCH *Group)
{
/* 四字 TAB用 12 号(字库齐全)+ 加宽,避免缺字/裁切 */
const uint16_t tab_w = 68;
const uint16_t tab_h = 22;
const uint8_t tab_r = 6;
const uint8_t tab_font = 12;
const uint16_t start_x = 12;
const uint16_t start_y = UI->y + 1;
const uint16_t text_y = start_y + (tab_h - tab_font) / 2;
const uint16_t inset = 6;
uint16_t color_sel_bg = COLOR_GRAD_MID;
uint16_t color_unsel_bg = COLOR_NORMAL_BG;
uint16_t color_text = UI->Text_fc;
if(Group->Current == 1)
{
LCD_FillRoundRect(start_x, start_y, tab_w, tab_h, tab_r, color_unsel_bg);
LCD_FillRoundRect(start_x+tab_w +4, start_y, tab_w, tab_h, tab_r, color_sel_bg);
LCD_ShowChinese_AutoAlign(
start_x + inset, start_x + tab_w - inset, text_y,
(const uint8_t*)"\xBD\xDA\xD7\xE0\xC0\xE0\xD0\xCD",
LCD_ALIGN_CENTER, color_text, color_unsel_bg, 0, tab_font);
LCD_ShowChinese_AutoAlign(
start_x + tab_w + 4 + inset, start_x + tab_w + 4 + tab_w - inset, text_y,
(const uint8_t *)"\xB1\xBE\xB5\xD8\xC7\xFA\xC4\xBF",
LCD_ALIGN_CENTER, color_text, color_sel_bg, 0, tab_font);
}
else
{
LCD_FillRoundRect(start_x, start_y, tab_w, tab_h, tab_r, color_sel_bg);
LCD_FillRoundRect(start_x+tab_w +4, start_y, tab_w, tab_h, tab_r, color_unsel_bg);
LCD_ShowChinese_AutoAlign(
start_x + inset, start_x + tab_w - inset, text_y,
(const uint8_t*)"\xBD\xDA\xD7\xE0\xC0\xE0\xD0\xCD",
LCD_ALIGN_CENTER, color_text, color_sel_bg, 0, tab_font);
LCD_ShowChinese_AutoAlign(
start_x + tab_w + 4 + inset, start_x + tab_w + 4 + tab_w - inset, text_y,
(const uint8_t *)"\xB1\xBE\xB5\xD8\xC7\xFA\xC4\xBF",
LCD_ALIGN_CENTER, color_text, color_unsel_bg, 0, tab_font);
}
}
void Show_home_UI(void)
{
UI_ClearFocus();
LCD_FillByColor(0,0,240,320,UI0902_BG_COLOR);
label_top();
label_Tranzpose_ui(&UI_Label[GUI_TRANSPOSE], &mGuiData[GUI_TRANSPOSE]);
label_Speed_ui(&UI_Label[GUI_SPEED], &mGuiData[GUI_SPEED]);
label_ModeSelece_ui(&UI_Label[GUI_MODE_PARAM],&mGuiData[GUI_MODE_PARAM]);
label_TimbreSelece_ui(&UI_Label[GUI_TIMBRE_SELECT], &mGuiData[GUI_TIMBRE_SELECT]);
label_PlaySection_ui(&UI_Label[GUI_PLAY_SECTION], &mGuiData[GUI_PLAY_SECTION]);
label_Tab_Select_ui(&UI_Label[GUI_PLAY_SECTION], &mGuiData[GUI_TAB_INDEX]);
//LCD_WR_REG(0x29); // Display ON恢复扫描整页<E695B4>?间呈<E997B4>?
//LCD_BLK_Set();
}
int8_t delta = 0;
void Touch_Action(int8_t FLAG, uint8_t ID, uint8_t areaIndex,uint8_t value)
{
uint8_t last_value;
uint8_t midi_note_buff[4] = {0,};
NvmParam_Type * nvm = drv_nvm_param_ptr();
if(FLAG == 1 || FLAG == -1)
{
switch(ID)
{
case GUI_TRANSPOSE:
{
last_value = mGuiData[ID].Current;
GUI_Item_AjustLoopValue(&mGuiData[ID], FLAG);
if (!UI_SetFocus(GUI_TRANSPOSE))
Refresh_Transpose(&UI_Label[ID], &mGuiData[ID]);
// label_Tranzpose_ui(&UI_Label[GUI_TRANSPOSE], &mGuiData[GUI_TRANSPOSE]);
if(nvm->param.Transpose != mGuiData[ID].Current)
{
nvm->param.Transpose = mGuiData[ID].Current;
}
transpose[3] = mGuiData[ID].Current;
USART4_SendData(transpose,sizeof(transpose));
int8_t new_trans = mGuiData[GUI_TRANSPOSE].Current;
delta = new_trans - last_value;
USE_MIDI.Midi_1 += delta;
USE_MIDI.Midi_2 += delta;
USE_MIDI.Midi_3 += delta;
USE_MIDI.Midi_4 += delta;
USE_MIDI.Midi_5 += delta;
USE_MIDI.Midi_6 += delta;
if(StartFlag)
{
switch(mGuiData[GUI_TAB_INDEX].Current)
{
case 2:
{
uint8_t midi = 0x3c;
midi += mGuiData[GUI_TRANSPOSE].Current;
AutoBandTop1_Note_On(midi,0x3c); // AutoBand 模块未加入工程
}
break;
case 1:
{
AutoBandTop1_SetPiecePlayMode(1,0,480); // AutoBand 模块未加入工程
AutoBandTop1_StartWithNotes(midi_note_buff,GetChordNotesByType(KEY_ID_1629,chord_type_index_map[KEY_ID_1629].type,midi_note_buff));
AutoBandTop1_SetLoopMode(0,1);
}
break;
case 0:
{
AutoBandTop1_SetPiecePlayMode(1,0,480); // AutoBand 模块未加入工程
AutoBandTop1_StartWithNotes(midi_note_buff,GetChordNotesByType(KEY_ID_1629,chord_type_index_map[KEY_ID_1629].type,midi_note_buff));
}
break;
}
}
}
break;
case GUI_SPEED:
{
last_value = mGuiData[ID].Current;
GUI_Item_AjustValue(&mGuiData[ID], FLAG);
if (!UI_SetFocus(GUI_SPEED))
Refresh_Transpose(&UI_Label[ID], &mGuiData[ID]);
Speed[3] = mGuiData[ID].Current / 128;
Speed[4] = mGuiData[ID].Current % 128;
USART4_SendData(Speed,sizeof(Speed));
if(nvm->param.BPM != mGuiData[ID].Current)
{
nvm->param.BPM = mGuiData[ID].Current;
}
AutoBandTop1_ChangeBPM(mGuiData[ID].Current); // AutoBand 模块未加入工程
}
break;
case GUI_MODE_PARAM:
{
GUI_SWITCH *pCurData =NULL;
switch(mGuiData[GUI_TAB_INDEX].Current)
{
case 0: case 1:
if(mGuiData[GUI_AUTOBAND_SW].Current)
{
pCurData = &ParamGuiData[EXPRESS_MODE_PARAM];
}
else
{
pCurData = &ParamGuiData[SONG_MODE_PARAM];
}
break;
case 2: pCurData = &ParamGuiData[ALL_MODE_PARAM]; break;
}
last_value = pCurData->Current;
GUI_Item_AjustLoopValue(pCurData, FLAG);
if (!UI_SetFocus(GUI_MODE_PARAM))
show_Param(&UI_Label[GUI_MODE_PARAM], pCurData);
switch(mGuiData[GUI_TAB_INDEX].Current)
{
case 0: case 1:
if(mGuiData[GUI_AUTOBAND_SW].Current)
{
AutoBandTop1_LoadPresetItemFromFlash(0);
}
else
{
AutoBandTop1_LoadPresetItemFromFlash(ParamGuiData[SONG_MODE_PARAM].Current);
}
break;
case 2: AutoBandTop1_LoadPresetItemFromFlash(ParamGuiData[ALL_MODE_PARAM].Current); break;
}
switch(mGuiData[GUI_TAB_INDEX].Current)
{
case 0: nvm->param.Param1 = ParamGuiData[SONG_MODE_PARAM].Current; break; // 姝屾<E5A79D>????
case 1: nvm->param.Param2 = ParamGuiData[EXPRESS_MODE_PARAM].Current;
break; // 涓撳<E6B693>????
case 2: nvm->param.Param3 = ParamGuiData[ALL_MODE_PARAM].Current; break; // 涓囪<E6B693>????
}
}
break;
case GUI_TIMBRE_SELECT:
last_value = mGuiData[ID].Current;
GUI_Item_AjustLoopValue(&mGuiData[ID], FLAG);
UI_SetFocus(GUI_TIMBRE_SELECT);
Refresh_StringTimbre(last_value, &UI_Label[ID], &mGuiData[ID]);
uint8_t ReturnTimbre[8] = {0xF0,0x60,0x03,0x05,0x00,0x00,0x00,0xF7};
ReturnTimbre[6] = mGuiData[GUI_TIMBRE_SELECT].Current;
USART4_SendData(ReturnTimbre,sizeof(ReturnTimbre));
if(nvm->param.Timbre != mGuiData[ID].Current)
{
nvm->param.Timbre = mGuiData[ID].Current;
}
break;
}
}
if(ID == GUI_AUTOBAND_SW)
{
mGuiData[ID].Current = value;
if(mGuiData[GUI_AUTOBAND_SW].Current)
{
ADDRESS = 0x0009EB5B;
}else
{
ADDRESS = 0x00000000;
}
if (!UI_SetFocus(GUI_MODE_PARAM))
label_ModeSelece_ui(&UI_Label[GUI_MODE_PARAM],&mGuiData[GUI_MODE_PARAM]);
return;
}
else if(ID==GUI_PLAY_SECTION)
{
if(mGuiData[ID].Current != value)
{
mGuiData[ID].Current = value;
AutoBandTop1_SetRunVar(mGuiData[ID].Current);
}else
{
AutoBandTop1_FillinWithIndex(value);
AutoBandTop1_Start();
}
if (!UI_SetFocus(GUI_PLAY_SECTION))
Refresh_SectionSelect(last_value, &UI_Label[ID], &mGuiData[ID]);
return;
}
else if(ID == GUI_NAV_BAR)
{
switch(value)
{
case UI0902_NAV_SETTING: MenuPage_Setting_Proc(); break;
case UI0902_NAV_MIXER: MenuPage_Mixer_Proc(); break;
case UI0902_NAV_MODE: UI_ReturnToModeSelect(); break;
default: break;
}
return;
}
else if(ID==GUI_TAB_INDEX)
{
if(mGuiData[ID].Current != value)
{
mGuiData[ID].Current = value;
app_tm1629_all_on(LED_COLOR_G);
switch(mGuiData[ID].Current)
{
case 0:
if(mGuiData[GUI_TAB_LAST_INDEX].Current == mGuiData[ID].Current)
break;
StartFlag = 0;
AutoBandTop1_Stop();
if(mGuiData[GUI_AUTOBAND_SW].Current)
{
ADDRESS = 0x0009EB5F;
}
else
{
ADDRESS = 0x00000000;
}
break;
case 1:
if(mGuiData[GUI_TAB_LAST_INDEX].Current == mGuiData[ID].Current)
break;
StartFlag = 0;
AutoBandTop1_Stop();
if(mGuiData[GUI_AUTOBAND_SW].Current)
{
ADDRESS = 0x0009EB5F;
}
else
{
ADDRESS = 0x00000000;
}
break;
case 2:
if(mGuiData[GUI_TAB_LAST_INDEX].Current == mGuiData[ID].Current)
break;
StartFlag = 0;
AutoBandTop1_Stop();
ADDRESS = 0x0009598F;
break;
}
Refresh_TabSelect_ui(&UI_Label[ID], &mGuiData[ID]);
}
return;
}
else if(ID==GUI_BL_SW)
{
mGuiData[ID].Current = !mGuiData[ID].Current;
Show_BL_Icon(mGuiData[GUI_BL_SW].Current);
return;
}
}
void UI_SongMode_Init(void)
{
CurrentMode = 0;
//mGuiData[GUI_AUTOBAND_SW].Current = 0;
mGuiData[GUI_TAB_INDEX].Current = 0;
mGuiData[GUI_TAB_LAST_INDEX].Current = mGuiData[GUI_TAB_INDEX].Current;
Show_home_UI();
pCurrentTouch_Area = Touch_Areas;
}
void UI_SongMode_Process(DisplayTaskMessage_Type msg)
{
uint8_t midi_note_buff[4] = {0,};
NvmParam_Type * nvm = drv_nvm_param_ptr();
switch(msg.MessageType)
{
case MSG_ID_TOUCH:
{
uint8_t hit = 0U;
for(uint8_t k=0; k<TOUCH_AREA_NUM; k++)
{
if( msg.HiByte >= pCurrentTouch_Area[k].x_min && msg.HiByte <= pCurrentTouch_Area[k].x_max &&
msg.LoByte >= pCurrentTouch_Area[k].y_min && msg.LoByte <= pCurrentTouch_Area[k].y_max )
{
hit = 1U;
LOG_I("UI", "song hit area=%u id=%u val=%u x=%u y=%u",
(unsigned)k, (unsigned)pCurrentTouch_Area[k].ID,
(unsigned)pCurrentTouch_Area[k].Value,
(unsigned)msg.HiByte, (unsigned)msg.LoByte);
Touch_Action(pCurrentTouch_Area[k].Flag,pCurrentTouch_Area[k].ID,k,pCurrentTouch_Area[k].Value);
ResetAutoPowerCount();
break;
}
}
if (!hit) {
LOG_I("UI", "song miss x=%u y=%u",
(unsigned)msg.HiByte, (unsigned)msg.LoByte);
}
}
break;
case MSG_ID_BATTERY_VALUE:
Draw_Status_Battery_Icon(percentage);
break;
case MSG_ID_EC_VOL:
Send_volume(msg.ID);
Draw_Volume_Bar(UI0902_VOL_X, UI0902_VOL_Y, msg.HiByte, 1, WHITE, GRAY);
break;
case MSG_ID_TAP_SPEED:
//last_value = mGuiData[GUI_SPEED].Current;
mGuiData[GUI_SPEED].Current = msg.ID;
if (!UI_SetFocus(GUI_SPEED))
Refresh_Transpose(&UI_Label[GUI_SPEED], &mGuiData[GUI_SPEED]);
AutoBandTop1_ChangeBPM(mGuiData[GUI_SPEED].Current);
if(nvm->param.BPM != mGuiData[GUI_SPEED].Current)
{
nvm->param.BPM = mGuiData[GUI_SPEED].Current;
}
Speed[3] = mGuiData[GUI_SPEED].Current / 128;
Speed[4] = mGuiData[GUI_SPEED].Current % 128;
USART4_SendData(Speed,sizeof(Speed));
//
// ResetAutoPowerCount();
break;
case MSG_ID_TOUCH_LONG_REPEAT:
{
/* 长按顶栏y<28返回三键模式选择页 */
if (msg.LoByte < 28)
{
UI_ReturnToModeSelect();
break;
}
for(uint8_t k=0; k<TOUCH_AREA_NUM; k++)
{
if( msg.HiByte >= pCurrentTouch_Area[k].x_min && msg.HiByte <= pCurrentTouch_Area[k].x_max &&
msg.LoByte >= pCurrentTouch_Area[k].y_min && msg.LoByte <= pCurrentTouch_Area[k].y_max )
{
if(pCurrentTouch_Area[k].ID == GUI_SPEED)
{
int flag = pCurrentTouch_Area[k].Flag;
uint8_t last = mGuiData[GUI_SPEED].Current;
if(flag == 1)
{
if(mGuiData[GUI_SPEED].Current < 260)
{
mGuiData[GUI_SPEED].Current += 10;
if(mGuiData[GUI_SPEED].Current > 260)
mGuiData[GUI_SPEED].Current = 260;
}
else
{
break;
}
}
else if(flag == -1)
{
if(mGuiData[GUI_SPEED].Current > 40)
{
mGuiData[GUI_SPEED].Current -= 10;
if(mGuiData[GUI_SPEED].Current < 40)
mGuiData[GUI_SPEED].Current = 40;
}else
{
break;
}
}
// <20>?有数值真正改变才执行全套刷新、串口、伴奏更<E5A58F>?
if(last != mGuiData[GUI_SPEED].Current)
{
Refresh_Transpose(&UI_Label[GUI_SPEED], &mGuiData[GUI_SPEED]);
if(nvm->param.BPM != mGuiData[GUI_SPEED].Current)
{
nvm->param.BPM = mGuiData[GUI_SPEED].Current;
}
uint8_t Speed[6] = {0xF0, 0x51, 0x03, 0x00, 0x00, 0xF7};
Speed[3] = mGuiData[GUI_SPEED].Current / 128;
Speed[4] = mGuiData[GUI_SPEED].Current % 128;
USART4_SendData(Speed,sizeof(Speed));
AutoBandTop1_ChangeBPM(mGuiData[GUI_SPEED].Current);
}
// 超时计数无<E695B0>?<3F>变不变都可以重<E4BBA5>?看你需<E4BDA0>?
//ResetAutoPowerCount();
}
break;
}
}
}
break;
case MSG_ID_BP_TRANSPOSE:
{
uint8_t lastvalue = mGuiData[GUI_TRANSPOSE].Current;
if(mGuiData[GUI_TRANSPOSE].Current != msg.ID)
{
mGuiData[GUI_TRANSPOSE].Current = msg.ID;
if (!UI_SetFocus(GUI_TRANSPOSE))
Refresh_Transpose(&UI_Label[GUI_TRANSPOSE], &mGuiData[GUI_TRANSPOSE]);
}
if(nvm->param.Transpose != mGuiData[GUI_TRANSPOSE].Current)
{
nvm->param.Transpose = mGuiData[GUI_TRANSPOSE].Current;
}
transpose[3] = mGuiData[GUI_TRANSPOSE].Current;
USART4_SendData(transpose,5);
int8_t new_trans = mGuiData[GUI_TRANSPOSE].Current;
delta = new_trans - lastvalue; /* 使用正确<E6ADA3>???? lastvalue */
USE_MIDI.Midi_1 += delta;
USE_MIDI.Midi_2 += delta;
USE_MIDI.Midi_3 += delta;
USE_MIDI.Midi_4 += delta;
USE_MIDI.Midi_5 += delta;
USE_MIDI.Midi_6 += delta;
if(/*KEY_ID_1629 != 0 && */StartFlag && KEY_ID_1629 != 22 && KEY_ID_1629 != 23)
{
AutoBandTop1_SetPiecePlayMode(1,0,480);
AutoBandTop1_StartWithNotes(midi_note_buff,GetChordNotesByType(KEY_ID_1629,chord_type_index_map[KEY_ID_1629].type,midi_note_buff));
AutoBandTop1_SetLoopMode(0,1);
AutoBandTop1_StartWithNotes(midi_note_buff,GetChordNotesByType(KEY_ID_1629,chord_type_index_map[KEY_ID_1629].type,midi_note_buff));
}
ResetAutoPowerCount();
}
break;
case MSG_ID_CHARG:
Show_Battery_Icon(msg.ID);
break;
}
//drv_nvm_save_to_flash();
}