--- cui_midi.c- Tue Apr 22 01:00:00 2014 +++ cui_midi.c Wed Apr 23 23:00:00 2014 @@ -11,6 +11,7 @@ #include "cui/num.h" #include "cui/tab.h" #include "cui/kbd.h" +#include "cui/timer.h" FILE *fp = NULL; #define BUFN 4096 @@ -71,15 +72,37 @@ int prog, vol, velo; cui kbd; int pmode, msec; + int arpe_note; }; struct test4{ cui mn_ch, prog, vol, velo; int midi_ch, bak_ch; struct test4_ch ch[16]; - cui pmode, on, msec, play; + cui pmode, on, msec, play, repeat; }; +static int +repeat_hdr(cui obj, int evt, int val, void *prm) +{ + struct test4 *p = (struct test4 *)prm; + struct test4_ch *ch = &p->ch[ p->midi_ch ]; + int i, note, prev = ch->arpe_note; + + + if(prev >= 0) set_char3_wrt((8<<4) | p->midi_ch, prev, ch->velo); + for(note=0; note<128; note++) if(cui_kbd_get(ch->kbd, note)) break; + if(note < 128){ + for(i=0; i<128; i++){ + note = (prev + 1 + i) % 128; + if(cui_kbd_get(ch->kbd, note)) break; + } + set_char3_wrt((9<<4) | p->midi_ch, note, ch->velo); + ch->arpe_note = note; + } + return TRUE; +} + int t4_btn_hdr(cui obj, int evt, int val, void *prm) { @@ -112,6 +135,7 @@ 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); + cui_show_hide(p->repeat, strcmp(s, "Arpeggio") == 0); }else if(obj == p->on){ int note; int hi = val ? (9<<4) : (8<<4); @@ -130,6 +154,8 @@ prev = note; } set_char3_wrt((8<<4) | p->midi_ch, prev, ch->velo); + }else if(obj == p->repeat){ + cui_timer_set(obj, val ? ch->msec : -1, FALSE); }else return FALSE; return TRUE; } @@ -157,6 +183,7 @@ cui_bind(t4.ch[i].kbd, CUI_EVT_BUTTON, t4_btn_hdr, &t4); t4.ch[i].pmode = 0; t4.ch[i].msec = 200; + t4.ch[i].arpe_note = -1; } 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); @@ -173,7 +200,7 @@ 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); + t4.on = cui_ckbox_new(bs4, cui_x2(t4.pmode)+2, t4.pmode->y, "ON", FALSE); cui_hide(t4.on); t4.msec = cui_num_new(bs4, cui_x2(t4.pmode)+2, t4.pmode->y, 4+3, 200, 0, 1000, 0); @@ -182,6 +209,9 @@ t4.play = cui_button_new(bs4, cui_x2(t4.msec)+2, t4.msec->y, "play"); cui_hide(t4.play); + t4.repeat = cui_ckbox_new(bs4, cui_x2(t4.play)+2, t4.play->y, "repeat", FALSE); + cui_hide(t4.repeat); + cui_wh_fit(bs4); cui_show(bs4); @@ -191,6 +221,8 @@ 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_bind(t4.repeat, CUI_EVT_BUTTON, t4_btn_hdr, &t4); + cui_bind(t4.repeat, CUI_EVT_TIMER, repeat_hdr, &t4); cui_handler_call(t4.mn_ch, CUI_EVT_BUTTON, cui_menu_int_get(t4.mn_ch));