mirror of
https://github.com/vale981/openAV-Luppp
synced 2025-03-05 09:01:39 -05:00
ctlrscript: refactored API and events working
This commit is contained in:
parent
d664bb010a
commit
60d990e4ea
3 changed files with 58 additions and 32 deletions
|
@ -18,15 +18,17 @@
|
|||
|
||||
#include "ctlrscript.hxx"
|
||||
|
||||
#include <iostream>
|
||||
#include <errno.h>
|
||||
#include <iostream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "../jack.hxx"
|
||||
#include "../event.hxx"
|
||||
#include "../logic.hxx"
|
||||
#include "../gridlogic.hxx"
|
||||
|
||||
#include "../eventhandler.hxx"
|
||||
#include <sys/stat.h>
|
||||
#include "luppp_script_api.h"
|
||||
|
||||
#include "libtcc.h"
|
||||
|
||||
|
@ -42,11 +44,27 @@ static void error(const char *msg)
|
|||
printf("%s\n", msg);
|
||||
}
|
||||
|
||||
#warning TODO: Externalize this to a header which the controllers should\
|
||||
include to understand the event types, and functions for sending
|
||||
struct event_t {
|
||||
uint32_t type;
|
||||
};
|
||||
void luppp_do(enum EVENT_ID id, void* e)
|
||||
{
|
||||
printf("%s : event: %d, %p\n", __func__, id, e);
|
||||
switch(id) {
|
||||
case EVENT_TRACK_SEND_ACTIVE: {
|
||||
struct event_track_send_active *ev =
|
||||
(struct event_track_send_active *)e;
|
||||
jack->getLogic()->trackSendActive(ev->track, ev->send,
|
||||
ev->active);
|
||||
break;
|
||||
}
|
||||
case EVENT_TRACK_SEND: {
|
||||
struct event_track_send *ev =
|
||||
(struct event_track_send *)e;
|
||||
jack->getLogic()->trackSend(ev->track, ev->send,
|
||||
ev->value);
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
static int file_modify_time(const char *path, time_t *new_time)
|
||||
{
|
||||
|
@ -67,6 +85,7 @@ int CtlrScript::compile()
|
|||
if(program) {
|
||||
free(program);
|
||||
}
|
||||
program_ok = 0;
|
||||
|
||||
TCCState *s;
|
||||
s = tcc_new();
|
||||
|
@ -83,6 +102,12 @@ int CtlrScript::compile()
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
tcc_add_symbol(s, "luppp_do", (void *)luppp_do);
|
||||
if(ret < 0) {
|
||||
error("failed to insert luppp_do() symbol\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
program = malloc(tcc_relocate(s, NULL));
|
||||
if(!program)
|
||||
error("failed to alloc mem for program\n");
|
||||
|
@ -107,6 +132,7 @@ int CtlrScript::compile()
|
|||
|
||||
/* Store the time of compiling */
|
||||
file_modify_time(filename.c_str(), &script_load_time);
|
||||
program_ok = 1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -163,6 +189,9 @@ void CtlrScript::midi(unsigned char* midi)
|
|||
{
|
||||
script_reload();
|
||||
|
||||
if(!program_ok)
|
||||
return;
|
||||
|
||||
int status = midi[0];
|
||||
int data = midi[1];
|
||||
float value = midi[2] / 127.f;
|
||||
|
@ -171,26 +200,8 @@ void CtlrScript::midi(unsigned char* midi)
|
|||
int ret = poll(midi);
|
||||
}
|
||||
|
||||
struct event_bpm_t {
|
||||
struct event_t event;
|
||||
int bpm;
|
||||
};
|
||||
|
||||
void CtlrScript::bpm(int bpm)
|
||||
{
|
||||
printf("%s : %d\n", __func__, bpm);
|
||||
//struct event_t ev = { 2, 1 };
|
||||
|
||||
struct event_bpm_t ev = {
|
||||
.event = { .type = 2 },
|
||||
.bpm = bpm,
|
||||
};
|
||||
|
||||
handle(&ev);
|
||||
}
|
||||
|
||||
struct event_trac_send_active_t {
|
||||
struct event_t event;
|
||||
int type;
|
||||
int track;
|
||||
int send;
|
||||
int active;
|
||||
|
@ -198,9 +209,12 @@ struct event_trac_send_active_t {
|
|||
|
||||
void CtlrScript::trackSendActive(int t, int send, bool a)
|
||||
{
|
||||
if(!program_ok)
|
||||
return;
|
||||
|
||||
printf("%s : %d : %d\n", __func__, send, a);
|
||||
struct event_trac_send_active_t ev = {
|
||||
.event = { .type = 3 },
|
||||
.type = 3,
|
||||
.track = t,
|
||||
.send = send,
|
||||
.active = 0,
|
||||
|
|
|
@ -58,7 +58,6 @@ public:
|
|||
return "CtlrScript";
|
||||
}
|
||||
|
||||
void bpm(int bpm);
|
||||
void trackSendActive(int t, int send, bool a);
|
||||
|
||||
void midi(unsigned char* midi);
|
||||
|
@ -66,6 +65,11 @@ public:
|
|||
Controller::STATUS status();
|
||||
|
||||
private:
|
||||
/* a flag stating if the program linked OK. If not, we do not act
|
||||
* on the script, and do not call *any* function pointers related
|
||||
* to the script, as they *will* cause a segfault */
|
||||
int program_ok;
|
||||
|
||||
void *program;
|
||||
ctlr_handle_midi poll;
|
||||
ctlr_handle_event handle;
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
*/
|
||||
|
||||
|
||||
#ifndef LUPPP_CONTROLLER_SCRIPT_H
|
||||
#define LUPPP_CONTROLLER_SCRIPT_H
|
||||
#ifndef LUPPP_SCRIPT_API_H
|
||||
#define LUPPP_SCRIPT_API_H
|
||||
|
||||
/**
|
||||
* This file is the API for the Controller Scripts, allowing them to
|
||||
|
@ -29,6 +29,7 @@
|
|||
|
||||
enum EVENT_ID {
|
||||
EVENT_NOP = 0,
|
||||
EVENT_TRACK_SEND,
|
||||
EVENT_TRACK_SEND_ACTIVE,
|
||||
};
|
||||
|
||||
|
@ -38,7 +39,14 @@ struct event_track_send_active {
|
|||
int active;
|
||||
};
|
||||
|
||||
static void luppp_do(enum EVENT_ID id, void* event_struct);
|
||||
struct event_track_send {
|
||||
int track;
|
||||
int send;
|
||||
float value;
|
||||
};
|
||||
|
||||
#endif /* LUPPP_CONTROLLER_SCRIPT_H */
|
||||
|
||||
void luppp_do(enum EVENT_ID id, void* event_struct);
|
||||
|
||||
#endif /* LUPPP_SCRIPT_API_H */
|
||||
|
Loading…
Add table
Reference in a new issue