From c5bcf5f625caa4a580dbd5a88c14ef5087791ffa Mon Sep 17 00:00:00 2001 From: Harry van Haaren Date: Tue, 24 Sep 2013 18:38:53 +0100 Subject: [PATCH] -Updated controller to attempt read the JSON controller definition. --- src/controller/genericmidi.cxx | 45 +++++++++++++++++++++++++++++++++- src/diskreader.cxx | 2 +- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/controller/genericmidi.cxx b/src/controller/genericmidi.cxx index ec1c160..418a6aa 100644 --- a/src/controller/genericmidi.cxx +++ b/src/controller/genericmidi.cxx @@ -3,11 +3,16 @@ #include "genericmidi.hxx" #include +#include +#include #include #include "../jack.hxx" #include "../gridlogic.hxx" +#include "../cjson/cJSON.h" + + extern Jack* jack; GenericMIDI::GenericMIDI(std::string file, std::string name) : @@ -330,8 +335,46 @@ void GenericMIDI::reset() int GenericMIDI::loadController( std::string file ) { - LUPPP_NOTE("%s%s","Loading controller : ", file.c_str() ); + /// open and read whole file +#ifdef DEBUG_CONTROLLER + cout << "loading controller file " << file.c_str() << endl; +#endif + std::ifstream sampleFile( file.c_str(), std::ios_base::in|std::ios_base::ate); + long file_length = sampleFile.tellg(); + if ( file_length > 0 ) + { + sampleFile.seekg(0, std::ios_base::beg); + sampleFile.clear(); + char *sampleString = new char[file_length]; + sampleFile.read(sampleString, file_length); + + cJSON* controllerJson = cJSON_Parse( sampleString ); + if (!controllerJson) { + LUPPP_ERROR("%s %s","Error in Sample JSON before: ", cJSON_GetErrorPtr() ); + return LUPPP_RETURN_ERROR; + } + + cJSON* control = cJSON_GetObjectItem( controllerJson, "midiIn" ); + if ( control ) + { + LUPPP_NOTE("%s,%i","num MIDI inputs: ", control->valueint ); + } + else + { + cout << "Warning: audio.cfg has no entry for beats." << endl; + } + + cJSON_Delete( controllerJson ); + free ( sampleString ); + } + else + { + LUPPP_WARN("%s %s","No controller definition found in ", file.c_str() ); + return LUPPP_RETURN_WARNING; + } + + return LUPPP_RETURN_OK; } diff --git a/src/diskreader.cxx b/src/diskreader.cxx index ffc35f8..69b73dd 100644 --- a/src/diskreader.cxx +++ b/src/diskreader.cxx @@ -120,7 +120,7 @@ int DiskReader::loadSample( int track, int scene, string path ) } else { - LUPPP_WARN("%s %s","DiskReader::loadSample() empty or no sample.cfg found at ",base.str().c_str() ); + LUPPP_WARN("%s %s","Empty or no sample.cfg found at ",base.str().c_str() ); return LUPPP_RETURN_WARNING; }