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
target_link_libraries( luppp "-ltcc -ldl" )
target_link_libraries( luppp ${JACK_LIBRARIES} )
target_link_libraries( luppp ${LIBLO_LIBRARIES} )
target_link_libraries( luppp ${NTK_LIBRARIES} )

View file

@ -1,17 +1,17 @@
/*
* Author: Harry van Haaren 2016
* harryhaaren@gmail.com
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -26,14 +26,75 @@
#include "../eventhandler.hxx"
#include "libtcc.h"
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) :
Controller()
Controller()
{
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)

View file

@ -1,17 +1,17 @@
/*
* Author: Harry van Haaren 2013
* harryhaaren@gmail.com
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -39,14 +39,30 @@
* however this would also require significant effort, which does not
* 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
{
public:
CtlrScript(std::string filename);
std::string getName(){return "CtlrScript";}
void bpm(int bpm);
public:
CtlrScript(std::string filename);
std::string getName()
{
return "CtlrScript";
}
void bpm(int bpm);
private:
void *program;
ctlr_poll poll;
ctlr_handle handle;
};
#endif // LUPPP_CONTROLLER_SCRIPT_H

View file

@ -39,6 +39,7 @@
#include "audiobuffer.hxx"
#include "eventhandler.hxx"
#include "controller/ctlrscript.hxx"
#include "controller/genericmidi.hxx"
#include "controller/guicontroller.hxx"
@ -268,6 +269,11 @@ Jack::Jack( std::string name ) :
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
gui->setupMidiControllers();