diff --git a/resources/controllers/test.c b/resources/controllers/test.c new file mode 100644 index 0000000..36cdfa5 --- /dev/null +++ b/resources/controllers/test.c @@ -0,0 +1,77 @@ +#include "luppp_script_api.h" + +int test_poll(unsigned char* midi) +{ + if(midi[1] == 0x42) { + printf("play pressed\n"); + } + if(midi[1] == 0x3c) { + printf("cue pressed\n"); + } + if(midi[1] == 0x3b) { + printf("demo pressed\n"); + } + if(midi[1] == 0x33) { + printf("33 pressed\n"); + } + if(midi[1] == 0x47) { + printf("47 pressed\n"); + } + if(midi[1] == 0x66) { + printf("66 pressed - sending track active\n"); + struct event_track_send_active e = { + .track = 3, + .send = 0, + .active = midi[0] == 0x90, + }; + luppp_do(EVENT_TRACK_SEND_ACTIVE, &e); + } + + static int lookup[0x17]; + lookup[0x8 ] = 0; + lookup[0x17] = 1; + lookup[0xb ] = 2; + lookup[0x9 ] = 3; + + if(midi[0] == 0xb0) { + if(midi[1] == 0x17 || + midi[1] == 0x8 || + midi[1] == 0xb || + midi[1] == 0x9) { + struct event_track_send e = { + .track = lookup[midi[1]], + .send = 0, + .value = midi[2] / 127.f, + }; + luppp_do(EVENT_TRACK_SEND, &e); + } + + if(midi[1] == 0xd || midi[1] == 0xe) { + struct event_track_volume e = { + .track = (midi[1] == 0xe), + .value = midi[2] / 127.f, + }; + luppp_do(EVENT_TRACK_VOLUME, &e); + } + } + + return 0; +} + +void test_handle(void *ctlr, enum EVENT_ID id, void *event) +{ + printf("test_handle event id %d\n", id); + switch(id) { + case EVENT_TRACK_SEND_ACTIVE: { + struct event_track_send_active *e = + (struct event_track_send_active *)event; + printf("Script t %d, s %d, active %d\n", e->track, e->send, e->active); + unsigned char led_on [3] = {0x90, 0x42, 0x7F}; + unsigned char led_off[3] = {0x80, 0x42, 0}; + if(e->active) + luppp_write_midi(ctlr, led_on); + else + luppp_write_midi(ctlr, led_off); + } break; + }; +} diff --git a/src/controller/ctlrscript.cxx b/src/controller/ctlrscript.cxx index 324fd9b..f11e3de 100644 --- a/src/controller/ctlrscript.cxx +++ b/src/controller/ctlrscript.cxx @@ -192,22 +192,23 @@ int CtlrScript::compile() return -EINVAL; } - poll = (ctlr_handle_midi)tcc_get_symbol(s, "d2_poll"); + poll = (ctlr_handle_midi)tcc_get_symbol(s, "test_poll"); if(!poll) { error("failed to get de poll\n"); return -EINVAL; } /* handles events from Luppp */ - handle = (ctlr_handle_event)tcc_get_symbol(s, "d2_handle"); + handle = (ctlr_handle_event)tcc_get_symbol(s, "test_handle"); if(!handle) - error("failed to get d2 handle\n"); + error("failed to get test handle\n"); tcc_delete(s); /* Store the time of compiling */ file_modify_time(filename.c_str(), &script_load_time); program_ok = 1; + printf("compiled ok\n"); }