mirror of
https://github.com/vale981/openAV-Luppp
synced 2025-03-05 09:01:39 -05:00
ctlrscript: refactor and rework, now handles MIDI
This commit is contained in:
parent
bdacf93e83
commit
4b3153574f
4 changed files with 60 additions and 10 deletions
|
@ -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<MidiIO*>(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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue