-Luppp loads default controllers from file

main
Harry van Haaren 2013-11-02 00:56:02 +00:00
parent 5395e59ef2
commit e8caaa961a
3 changed files with 68 additions and 1 deletions

View File

@ -15,6 +15,8 @@
#include "eventhandler.hxx"
#include "gmastertrack.hxx"
#include "controller/genericmidi.hxx"
#include <sndfile.hh>
#include <samplerate.h>
@ -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

View File

@ -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 );

View File

@ -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<Binding*> b = c->getMidiToAction();
for(unsigned int i =0; i < b.size(); i++ )
optionWindow->addBinding( b.at(i) );
/*
if ( c->status() == Controller::CONTROLLER_OK )
{