-Overhauled GenericMIDI binding system to map event strings to the Event enumeration, faster compares

This commit is contained in:
Harry van Haaren 2013-10-03 00:39:00 +01:00
parent 437a06fa86
commit f1e1c855c4
3 changed files with 44 additions and 14 deletions

View file

@ -334,8 +334,14 @@ void GenericMIDI::midi(unsigned char* midi)
midiToAction.at(i).data == data )
{
Binding& b = midiToAction.at(i);
LUPPP_NOTE("Executing action %s", b.action.c_str() );
LUPPP_NOTE("Executing action %i", b.action );
switch( b.action )
{
case Event::TRACK_VOLUME: jack->getLogic()->trackVolume( b.track, value ); break;
}
/*
if( b.action.compare("track:volume") == 0 ) {
jack->getLogic()->trackVolume( b.track, value );
}
@ -346,9 +352,7 @@ void GenericMIDI::midi(unsigned char* midi)
LUPPP_NOTE("Executing action %s v = %f", b.action.c_str(), value );
//jack->getLogic()->trackVolume( b.track, value );
}
*/
}
}
@ -428,17 +432,43 @@ int GenericMIDI::loadController( std::string file )
// collect essential data
cJSON* status = cJSON_GetObjectItem( binding, "status" );
cJSON* data = cJSON_GetObjectItem( binding, "data" );
cJSON* action = cJSON_GetObjectItem( binding, "action" );
int action = -1;
cJSON* actionJson = cJSON_GetObjectItem( binding, "action" );
// collect event metadata
cJSON* track = cJSON_GetObjectItem( binding, "track" );
LUPPP_NOTE("Binding from %i %i %s", status->valueint, data->valueint, action->valuestring);
midiToAction.push_back( Binding(status->valueint, data->valueint, action->valuestring ) );
// get Event::type from string, and store the int representation of it:
// this is faster for comparison in the RT callback
if ( strcmp( actionJson->valuestring, "track:volume" ) == 0 )
{
action = Event::TRACK_VOLUME;
}
if ( track )
midiToAction.back().track = track->valueint;
/*
if( b.action.compare("track:volume") == 0 ) {
jack->getLogic()->trackVolume( b.track, value );
}
else if( b.action.compare("track:sendAmount") == 0 ) {
jack->getLogic()->trackSend( b.track, SEND_REV, value );
}
else if( b.action.compare("footpedal") == 0 ) {
LUPPP_NOTE("Executing action %s v = %f", b.action.c_str(), value );
//jack->getLogic()->trackVolume( b.track, value );
}
*/
if ( action != -1 )
{
LUPPP_NOTE("Binding from %i %i %s", status->valueint, data->valueint, actionJson->valuestring);
midiToAction.push_back( Binding(status->valueint, data->valueint, action ) );
if ( track )
midiToAction.back().track = track->valueint;
}
}
}
@ -465,7 +495,7 @@ int GenericMIDI::loadController( std::string file )
LUPPP_NOTE("Binding from %s to %i %i", action->valuestring, status->valueint, data->valueint );
actionToMidi.push_back( Binding(status->valueint, data->valueint, action->valuestring ) );
//actionToMidi.push_back( Binding(status->valueint, data->valueint, action->valuestring ) );
}
}
else

View file

@ -10,7 +10,7 @@
#include "../observer/midi.hxx"
/// for future compatibility, LupppAction might be a string mapped to a unique number
typedef std::string LupppAction;
typedef int LupppAction;
class Binding
{
@ -20,7 +20,8 @@ class Binding
unsigned char status;
unsigned char data;
/// the action this binding relates to
/// the action this binding relates to: this is an integer based on the
/// event.hxx enumeration of event types
LupppAction action;
/// arguments to the event: track number, scene number etc

View file

@ -9,7 +9,6 @@
event.hxx
This file provides declarations for each type of event that the engine uses.
*/
#include "looper.hxx"
@ -38,7 +37,7 @@ namespace Event
};
enum {
MASTER_VOL,
MASTER_VOL = 0,
MASTER_INPUT_VOL,
MASTER_INPUT_TO,
MASTER_INPUT_TO_ACTIVE,