-Initial controller MIDI binding hacked in

This commit is contained in:
Harry van Haaren 2013-10-18 01:06:34 +01:00
parent 49b95653bc
commit 62dd928d9b
8 changed files with 61 additions and 3 deletions

View file

@ -22,7 +22,7 @@ GenericMIDI::GenericMIDI(std::string file) :
name = "generic";
// load the JSON config file
int result = loadController( file );
int result = LUPPP_RETURN_OK; //loadController( file );
if ( result == LUPPP_RETURN_OK )
{
@ -371,6 +371,13 @@ void GenericMIDI::midi(unsigned char* midi)
//LUPPP_NOTE("GenericMIDI::midi() %i %i %f", status, data, value );
// create new MIDI binding?
if ( jack->bindingEventRecordEnable )
{
setupBinding( jack->bindingEventType, status, data, 0 );
jack->bindingEventRecordEnable = false;
}
// iterate over bindings, execute binding action if matches
for(unsigned int i = 0; i < midiToAction.size(); i++)
{
@ -597,6 +604,20 @@ int GenericMIDI::loadController( std::string file )
return LUPPP_RETURN_OK;
}
void GenericMIDI::setupBinding( LupppAction eventType, int midiStatus, int midiData, int track )
{
LUPPP_NOTE("MIDI binding, track %d, from eventType %d to %d, %d", track, eventType, midiStatus, midiData );
Binding* tmp = new Binding();
tmp->action = eventType;
tmp->status = midiStatus;
tmp->data = midiData;
tmp->track = track;
midiToAction.push_back( tmp );
}
Binding* GenericMIDI::setupBinding( cJSON* binding )
{

View file

@ -12,7 +12,7 @@
#include "../cjson/cJSON.h"
#include "../observer/midi.hxx"
/// for future compatibility, LupppAction might be a string mapped to a unique number
/// a LupppAction represents the Event type, as from Event.hxx
typedef int LupppAction;
class Binding
@ -83,6 +83,9 @@ class GenericMIDI : public Controller, public MidiIO
void process(int nframes);
// for adding bindings from MIDI / GUI event pair
void setupBinding( LupppAction eventType, int midiStatus, int midiData, int track );
private:
STATUS stat;

View file

@ -16,6 +16,16 @@ void ControllerUpdater::registerController( Controller* controller )
controller->registerComponents();
}
Controller* ControllerUpdater::getController(std::string name)
{
// FIXME: find controller based on name / ID?
LUPPP_WARN("FIXME, returning 0th element!!");
if ( c.size() >= 1 )
return c.at(0);
return 0;
}
void ControllerUpdater::reset()
{
for(unsigned int i = 0; i < c.size(); i++)

View file

@ -31,6 +31,9 @@ class ControllerUpdater
void registerController( Controller* controller );
// returns a Controller* by its name
Controller* getController(std::string name);
void reset();
void mute(int t, bool b);

View file

@ -36,7 +36,7 @@ namespace Event
INPUT_TO_SIDE_KEY,
};
enum {
enum EVENT_TYPE {
// default event type
EVENT_NULL = 0,

View file

@ -36,6 +36,14 @@ void handleDspEvents()
// recheck the size against the actual event size
if ( availableRead >= e->size() )
{
// MIDI binding creation: sample the Event.
if( jack->bindingEventRecordEnable )
{
printf("event %i\n", e->type() );
jack->bindingEventType = e->type();
}
switch ( e->type() )
{
case Event::QUIT: {

View file

@ -52,6 +52,13 @@ Jack::Jack() :
// CAREFUL: setup the size by default: otherwise malloc() is called on push_back
midiIO.reserve( CONTROLLERS_PREALLOC );
// MIDI binding stuff
bindingEventRecordEnable = true;
bindingTrack = 0;
bindingEventType = EVENT_NULL;
//GenericMIDI* tmp = new GenericMIDI("akai_apc.ctlr");
//tmp->registerComponents();
//controllerUpdater->registerController( static_cast<Controller*>(tmp) );

View file

@ -74,6 +74,11 @@ class Jack
{
return client;
};
// MIDI binding creation
bool bindingEventRecordEnable;
int bindingTrack;
int bindingEventType;
private:
jack_client_t* client;
@ -142,6 +147,7 @@ class Jack
// UI update variables
int uiUpdateCounter;
int uiUpdateConstant;
};
#endif // LUPPP_JACK_H