CtlrScript: added TCC code, added link flags

This commit attempts to compile and run the d2 script as prototyped
outside of Luppp.
This commit is contained in:
Harry van Haaren 2016-12-01 16:00:07 +00:00
parent 4657b4b135
commit bdacf93e83
4 changed files with 98 additions and 14 deletions

View file

@ -65,6 +65,7 @@ add_executable (luppp version.hxx ${sources} )
# Linking # Linking
target_link_libraries( luppp "-ltcc -ldl" )
target_link_libraries( luppp ${JACK_LIBRARIES} ) target_link_libraries( luppp ${JACK_LIBRARIES} )
target_link_libraries( luppp ${LIBLO_LIBRARIES} ) target_link_libraries( luppp ${LIBLO_LIBRARIES} )
target_link_libraries( luppp ${NTK_LIBRARIES} ) target_link_libraries( luppp ${NTK_LIBRARIES} )

View file

@ -26,14 +26,75 @@
#include "../eventhandler.hxx" #include "../eventhandler.hxx"
#include "libtcc.h"
extern Jack* jack; extern Jack* jack;
static void error_func(void *opaque, const char *msg)
{
printf("TCC ERROR: %s\n", msg);
}
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;
uint32_t size;
};
CtlrScript::CtlrScript(std::string filename) : CtlrScript::CtlrScript(std::string filename) :
Controller() Controller()
{ {
printf("%s, attempting to compile %s\n", __func__, filename.c_str()); printf("%s, attempting to compile %s\n", __func__, filename.c_str());
TCCState *s;
#warning WIP HERE, add TCC libs, and attempt to load/compile filename s = tcc_new();
if(!s)
error("failed to create tcc context\n");
tcc_set_error_func(s, 0x0, error_func);
tcc_set_options(s, "-g");
tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
int ret = tcc_add_file(s, filename.c_str());
if(ret < 0) {
printf("gracefully handling error now... \n");
return;
}
program = malloc(tcc_relocate(s, NULL));
if(!program)
error("failed to alloc mem for program\n");
ret = tcc_relocate(s, program);
if(ret < 0)
error("failed to relocate code to program memory\n");
poll = (ctlr_poll)tcc_get_symbol(s, "d2_poll");
if(!poll)
error("failed to get de poll\n");
handle = (void (*)(void*))tcc_get_symbol(s, "d2_handle");
if(!handle)
error("failed to get d2 handle\n");
tcc_delete(s);
uint32_t iter = 0;
iter = poll(iter);
struct event_t ev = { 0, 1 };
if(iter == 1)
ev.type = 1;
handle(&ev);
#warning FIXME: Free program when needed
//free(program);
} }
void CtlrScript::bpm(int bpm) void CtlrScript::bpm(int bpm)

View file

@ -39,14 +39,30 @@
* however this would also require significant effort, which does not * however this would also require significant effort, which does not
* seem worth the time at the moment. * seem worth the time at the moment.
*/ */
/* These typedefs are for the poll and handle events of the scripted
* controller, to receieve and send events as needed */
typedef int (*ctlr_poll)(int);
typedef void (*ctlr_handle)(void *);
class CtlrScript : public Controller class CtlrScript : public Controller
{ {
public: public:
CtlrScript(std::string filename); CtlrScript(std::string filename);
std::string getName(){return "CtlrScript";} std::string getName()
{
return "CtlrScript";
}
void bpm(int bpm); void bpm(int bpm);
private:
void *program;
ctlr_poll poll;
ctlr_handle handle;
}; };
#endif // LUPPP_CONTROLLER_SCRIPT_H #endif // LUPPP_CONTROLLER_SCRIPT_H

View file

@ -39,6 +39,7 @@
#include "audiobuffer.hxx" #include "audiobuffer.hxx"
#include "eventhandler.hxx" #include "eventhandler.hxx"
#include "controller/ctlrscript.hxx"
#include "controller/genericmidi.hxx" #include "controller/genericmidi.hxx"
#include "controller/guicontroller.hxx" #include "controller/guicontroller.hxx"
@ -268,6 +269,11 @@ Jack::Jack( std::string name ) :
LUPPP_ERROR("%s","Error creating LupppGUI Controller instance"); LUPPP_ERROR("%s","Error creating LupppGUI Controller instance");
} }
Controller* cs = new CtlrScript("test.c");
if(!cs) {
LUPPP_ERROR("Error creating CtlrScript instance\n");
}
// call into the GUI, telling it to register default controllers // call into the GUI, telling it to register default controllers
gui->setupMidiControllers(); gui->setupMidiControllers();