From e8caaa961a9fc3b5cbf8aedc6269c0ffdc7e6c36 Mon Sep 17 00:00:00 2001 From: Harry van Haaren Date: Sat, 2 Nov 2013 00:56:02 +0000 Subject: [PATCH] -Luppp loads default controllers from file --- src/diskreader.cxx | 52 ++++++++++++++++++++++++++++++++++++++++++++++ src/diskreader.hxx | 3 +++ src/gui.cxx | 14 ++++++++++++- 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/diskreader.cxx b/src/diskreader.cxx index 56d8796..e086455 100644 --- a/src/diskreader.cxx +++ b/src/diskreader.cxx @@ -15,6 +15,8 @@ #include "eventhandler.hxx" #include "gmastertrack.hxx" +#include "controller/genericmidi.hxx" + #include #include @@ -26,6 +28,56 @@ DiskReader::DiskReader() { } +int DiskReader::loadPreferences() +{ + stringstream s; + s << getenv("HOME") << "/.config/openAV/luppp/luppp.prfs"; + std::ifstream sampleFile( s.str().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* preferencesJson = cJSON_Parse( sampleString ); + if (!preferencesJson) + { + return LUPPP_RETURN_ERROR; + } + + cJSON* ctlrs = cJSON_GetObjectItem( preferencesJson, "defaultControllers" ); + if ( ctlrs ) + { + //cout << ".nanba HAS items." << endl; + int nCtlrs = cJSON_GetArraySize( ctlrs ); + for(int i = 0; i < nCtlrs; i++ ) + { + cJSON* ctlr = cJSON_GetArrayItem( ctlrs, i ); + if( ctlr ) + { + LUPPP_NOTE("Loading controller %s", ctlr->valuestring); + stringstream s; + s << getenv("HOME") << "/.config/openAV/luppp/controllers/" << ctlr->valuestring; + GenericMIDI* c = new GenericMIDI( s.str().c_str() ); + EventControllerInstance e(c); + writeToDspRingbuffer( &e ); + } + } + } + else + { + cout << "Warning: .nanba has no items." << endl; + } + + cJSON_Delete( preferencesJson ); + free ( sampleString ); + } + + return LUPPP_RETURN_OK; +} + int DiskReader::loadSample( int track, int scene, string path ) { /// load the sample diff --git a/src/diskreader.hxx b/src/diskreader.hxx index b89ea96..5e1614e 100644 --- a/src/diskreader.hxx +++ b/src/diskreader.hxx @@ -25,6 +25,9 @@ class DiskReader public: DiskReader(); + /// loads default settings for Luppp: controller instances etc + int loadPreferences(); + /// loads a sample into a new AudioBuffer, returning the buffer int loadSample( int track, int scene, std::string path ); diff --git a/src/gui.cxx b/src/gui.cxx index 50b89f2..e82ed68 100644 --- a/src/gui.cxx +++ b/src/gui.cxx @@ -299,6 +299,18 @@ Gui::Gui() : // Create AudioEditor after window.end() has been called audioEditor = new AudioEditor(); + // read settings file using diskreader, and setup controllers etc + int prefs = diskReader->loadPreferences(); + if ( prefs != LUPPP_RETURN_OK ) + { + LUPPP_ERROR("Error loading preferences"); + } + else + { + LUPPP_NOTE("Loaded preferences"); + } + + /* // default controller for testing stringstream s; s << getenv("HOME") << "/.config/openAV/luppp/controllers/akai_apc.ctlr"; @@ -308,7 +320,7 @@ Gui::Gui() : std::vector b = c->getMidiToAction(); for(unsigned int i =0; i < b.size(); i++ ) optionWindow->addBinding( b.at(i) ); - + /* if ( c->status() == Controller::CONTROLLER_OK ) {