From f1e1c855c474b6b2843a306e9015f8138bb1e4ac Mon Sep 17 00:00:00 2001 From: Harry van Haaren Date: Thu, 3 Oct 2013 00:39:00 +0100 Subject: [PATCH] -Overhauled GenericMIDI binding system to map event strings to the Event enumeration, faster compares --- src/controller/genericmidi.cxx | 50 +++++++++++++++++++++++++++------- src/controller/genericmidi.hxx | 5 ++-- src/event.hxx | 3 +- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/controller/genericmidi.cxx b/src/controller/genericmidi.cxx index 49bc53c..7520d22 100644 --- a/src/controller/genericmidi.cxx +++ b/src/controller/genericmidi.cxx @@ -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 diff --git a/src/controller/genericmidi.hxx b/src/controller/genericmidi.hxx index e448582..f04d70f 100644 --- a/src/controller/genericmidi.hxx +++ b/src/controller/genericmidi.hxx @@ -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 diff --git a/src/event.hxx b/src/event.hxx index b8f7200..6c9ae59 100644 --- a/src/event.hxx +++ b/src/event.hxx @@ -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,