--- cui_midi.c- 2014-04-22 00:00:00.000000000 +0900 +++ cui_midi.c 2014-04-22 01:00:00.000000000 +0900 @@ -70,12 +70,14 @@ struct test4_ch{ int prog, vol, velo; cui kbd; + int pmode, msec; }; struct test4{ cui mn_ch, prog, vol, velo; int midi_ch, bak_ch; struct test4_ch ch[16]; + cui pmode, on, msec, play; }; int @@ -90,17 +92,44 @@ cui_num_vp_set(p->prog, &ch->prog); cui_num_vp_set(p->vol, &ch->vol); cui_num_vp_set(p->velo, &ch->velo); - cui_hide(p->ch[ p->bak_ch ].kbd); cui_show(ch->kbd); + cui_menu_popup_vp_set(p->pmode, &ch->pmode); + cui_num_vp_set(p->msec, &ch->msec); p->bak_ch = p->midi_ch; }else if(obj == p->prog){ set_char2_wrt((0xc<<4) | p->midi_ch, ch->prog); }else if(obj == p->vol){ set_char3_wrt((0xb<<4) | p->midi_ch, 7 /* vol msb */, ch->vol); }else if(obj == ch->kbd){ - if(val & 0x100) set_char3_wrt((9<<4) | p->midi_ch, val & ~0x100, ch->velo); - else set_char3_wrt((8<<4) | p->midi_ch, val & ~0x100, ch->velo); + char *s = cui_menu_popup_str_get(p->pmode); + if(strcmp(s, "Immediate") == 0){ + if(val & 0x100) set_char3_wrt((9<<4) | p->midi_ch, val & ~0x100, ch->velo); + else set_char3_wrt((8<<4) | p->midi_ch, val & ~0x100, ch->velo); + } + }else if(obj == p->pmode){ + char *s = cui_menu_popup_str_get(p->pmode); + cui_show_hide(p->on, strcmp(s, "Chord") == 0); + cui_show_hide(p->msec, strcmp(s, "Arpeggio") == 0); + cui_show_hide(p->play, strcmp(s, "Arpeggio") == 0); + }else if(obj == p->on){ + int note; + int hi = val ? (9<<4) : (8<<4); + for(note=0; note<128; note++){ + if(!cui_kbd_get(ch->kbd, note)) continue; + set_char3_wrt(hi | p->midi_ch, note, ch->velo); + } + }else if(obj == p->play){ + int note, prev; + prev = -1; + for(note=0; note<128; note++){ + if(!cui_kbd_get(ch->kbd, note)) continue; + if(prev >= 0) set_char3_wrt((8<<4) | p->midi_ch, prev, ch->velo); + set_char3_wrt((9<<4) | p->midi_ch, note, ch->velo); + usleep(ch->msec * 1000); + prev = note; + } + set_char3_wrt((8<<4) | p->midi_ch, prev, ch->velo); }else return FALSE; return TRUE; } @@ -126,6 +155,8 @@ t4.ch[i].kbd = cui_kbd_new(bs4, 0, 8, 50); cui_hide(t4.ch[i].kbd); cui_bind(t4.ch[i].kbd, CUI_EVT_BUTTON, t4_btn_hdr, &t4); + t4.ch[i].pmode = 0; + t4.ch[i].msec = 200; } obj = cui_label_new(bs4, 0, 0, "midi ch : "); t4.mn_ch = cui_menu_int_new(bs4, cui_x2(obj), obj->y, 2+1, 0, 0, 15); @@ -140,12 +171,26 @@ obj = cui_label_new(bs4, 2, cui_y2(t4.vol)+1, "velo : "); t4.velo = cui_num_new(bs4, cui_x2(obj), obj->y, 3+3, 0, 0, 127, 0); + t4.pmode = cui_menu_popup_new(bs4, 2, cui_y2(t4.ch[0].kbd)+1, 9+1, + (char *[]){ "Immediate", "Chord", "Arpeggio", NULL}, 0); + t4.on = cui_ckbox_new(bs4, cui_x2(t4.pmode)+2, t4.pmode->y, "ON", 0); + cui_hide(t4.on); + + t4.msec = cui_num_new(bs4, cui_x2(t4.pmode)+2, t4.pmode->y, 4+3, 200, 0, 1000, 0); + cui_hide(t4.msec); + + t4.play = cui_button_new(bs4, cui_x2(t4.msec)+2, t4.msec->y, "play"); + cui_hide(t4.play); + cui_wh_fit(bs4); cui_show(bs4); cui_bind(t4.mn_ch, CUI_EVT_BUTTON, t4_btn_hdr, &t4); cui_bind(t4.prog, CUI_EVT_BUTTON, t4_btn_hdr, &t4); cui_bind(t4.vol, CUI_EVT_BUTTON, t4_btn_hdr, &t4); + cui_bind(t4.pmode, CUI_EVT_BUTTON, t4_btn_hdr, &t4); + cui_bind(t4.on, CUI_EVT_BUTTON, t4_btn_hdr, &t4); + cui_bind(t4.play, CUI_EVT_BUTTON, t4_btn_hdr, &t4); cui_handler_call(t4.mn_ch, CUI_EVT_BUTTON, cui_menu_int_get(t4.mn_ch));