diff --git a/src/controller/ctlrscript.cxx b/src/controller/ctlrscript.cxx index 13fc9c7..36792e4 100644 --- a/src/controller/ctlrscript.cxx +++ b/src/controller/ctlrscript.cxx @@ -41,7 +41,7 @@ static void error(const char *msg) } #warning TODO: Externalize this to a header which the controllers should\ - include to understand the event types, and functions for sending +include to understand the event types, and functions for sending struct event_t { uint32_t type; uint32_t size; @@ -49,7 +49,8 @@ struct event_t { CtlrScript::CtlrScript(std::string filename) : - Controller() + Controller(), + MidiIO() { printf("%s, attempting to compile %s\n", __func__, filename.c_str()); TCCState *s; @@ -95,9 +96,47 @@ CtlrScript::CtlrScript(std::string filename) : #warning FIXME: Free program when needed //free(program); + + // If the controller requests it, register MIDI ports for doing + // I/O. How to request this is curently unknown, but we could add + // a specific function, a generic function for querying what it + // would like, or some other sane extensible method :) + + stat = CONTROLLER_OK; +} + +int CtlrScript::registerComponents() +{ + // makes JACK add this controller to the midiObservers list: + // note the static_cast<>() is *needed* here for multiple-inheritance + MidiIO* m = static_cast(this); + + registerMidiPorts( "testScripted" ); + + jack->registerMidiIO( m ); + + return LUPPP_RETURN_OK; +} + + +Controller::STATUS CtlrScript::status() +{ + return stat; +} + +void CtlrScript::midi(unsigned char* midi) +{ + int status = midi[0]; + int data = midi[1]; + float value = midi[2] / 127.f; + + printf("%s : got %2x %2x %0.2f\n", __func__, status, data, value); } void CtlrScript::bpm(int bpm) { printf("%s : %d\n", __func__, bpm); + + struct event_t ev = { 2, 1 }; + handle(&ev); } diff --git a/src/controller/ctlrscript.hxx b/src/controller/ctlrscript.hxx index 4a96629..1f43abd 100644 --- a/src/controller/ctlrscript.hxx +++ b/src/controller/ctlrscript.hxx @@ -45,11 +45,14 @@ typedef int (*ctlr_poll)(int); typedef void (*ctlr_handle)(void *); -class CtlrScript : public Controller +class CtlrScript : public Controller, public MidiIO { public: CtlrScript(std::string filename); + /* called to register this instance with JACK */ + int registerComponents(); + std::string getName() { return "CtlrScript"; @@ -57,11 +60,17 @@ public: void bpm(int bpm); + void midi(unsigned char* midi); + + Controller::STATUS status(); + private: void *program; ctlr_poll poll; ctlr_handle handle; + Controller::STATUS stat; + }; diff --git a/src/gui.cxx b/src/gui.cxx index b652880..b6a7752 100644 --- a/src/gui.cxx +++ b/src/gui.cxx @@ -52,6 +52,8 @@ extern Jack* jack; #include "../planning/luppp.c" #include "../planning/bg.c" +#include "controller/ctlrscript.hxx" + using namespace std; extern Gui* gui; @@ -532,6 +534,13 @@ void Gui::setupMidiControllers() writeToDspRingbuffer( &e ); } } + + Controller* cs = new CtlrScript("test.c"); + if(!cs) { + LUPPP_ERROR("Error creating CtlrScript instance\n"); + } + EventControllerInstance e(cs); + writeToDspRingbuffer( &e ); } void Gui::reset() diff --git a/src/jack.cxx b/src/jack.cxx index 547280f..a221de4 100644 --- a/src/jack.cxx +++ b/src/jack.cxx @@ -39,7 +39,6 @@ #include "audiobuffer.hxx" #include "eventhandler.hxx" -#include "controller/ctlrscript.hxx" #include "controller/genericmidi.hxx" #include "controller/guicontroller.hxx" @@ -269,14 +268,8 @@ 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(); - } Jack::~Jack()