-Updated controller loading file

main
Harry van Haaren 2013-10-19 13:16:16 +01:00
parent e7cec02609
commit 88b04ecd6e
2 changed files with 80 additions and 1 deletions

View File

@ -84,6 +84,48 @@ int DiskWriter::writeControllerFile(std::string name ,
if ( g )
{
LUPPP_NOTE("Writing .ctlr file...");
cJSON* controllerJson = cJSON_CreateObject();
cJSON_AddItemToObject ( controllerJson, "name", cJSON_CreateString( name.c_str() ));
cJSON_AddItemToObject ( controllerJson, "author", cJSON_CreateString( author.c_str() ));
cJSON_AddItemToObject ( controllerJson, "link", cJSON_CreateString( link.c_str() ));
// input bindings
std::vector<Binding*> b = g->getMidiToAction();
cJSON* inputBindings = cJSON_CreateArray();
cJSON_AddItemToObject(controllerJson, "inputBindings", inputBindings );
for(unsigned int i = 0; i < b.size(); i++ )
{
// create binding
cJSON* binding = cJSON_CreateObject();
cJSON_AddItemToArray( inputBindings, binding );
// add metadata to binding
// FIXME: get action string from Event class: need to move function from GenericMIDI to there
//cJSON_AddNumberToObject( binding, "action", cJSON_CreateString( "actionStringHere" ) );
cJSON_AddNumberToObject( binding, "status", b.at(i)->status );
cJSON_AddNumberToObject( binding, "data" , b.at(i)->data );
cJSON_AddNumberToObject( binding, "track" , b.at(i)->track );
cJSON_AddNumberToObject( binding, "scene" , b.at(i)->scene );
cJSON_AddNumberToObject( binding, "send" , b.at(i)->send );
cJSON_AddNumberToObject( binding, "active", b.at(i)->active );
}
// write the sample JSON node to <samplePath>/sample.cfg
stringstream controllerCfgPath;
controllerCfgPath << getenv("HOME") << "/.config/openAV/luppp/controller.cfg";
ofstream controllerCfgFile;
controllerCfgFile.open ( controllerCfgPath.str().c_str() );
controllerCfgFile << cJSON_Print( controllerJson );
controllerCfgFile.close();
}
else
{

View File

@ -5,6 +5,8 @@
#include "eventhandler.hxx"
#include "controller/binding.hxx"
#include "controller/controller.hxx"
#include "controller/genericmidi.hxx"
#include "gui.hxx"
extern Gui* gui;
@ -26,6 +28,41 @@ static void writeBindEnable(Fl_Widget* w, void* data)
}
}
static void selectLoadController(Fl_Widget* w, void*)
{
// FIXME: refactor
string path;
Fl_Native_File_Chooser fnfc;
fnfc.title("Pick a controller definition");
fnfc.type(Fl_Native_File_Chooser::BROWSE_FILE);
fnfc.filter("Controllers\t*.ctlr");
fnfc.directory( getenv("HOME") ); // default directory to use
// Show native chooser
switch ( fnfc.show() ) {
case -1: printf("ERROR: %s\n", fnfc.errmsg()); break; // ERROR
case 1: printf("CANCEL\n"); break; // CANCEL
default: printf("Loading controller at %s\n", fnfc.filename());
path = fnfc.filename();
break;
}
if ( strcmp( path.c_str(), "" ) == 0 )
return;
LUPPP_NOTE("%s","ADD Controller cb");
Controller* c = new GenericMIDI( path );
if ( c->status() == Controller::CONTROLLER_OK )
{
EventControllerInstance e(c);
writeToDspRingbuffer( &e );
}
else
{
LUPPP_ERROR("Controller initialization failed!");
}
}
static void writeControllerFile(Fl_Widget* w, void* data)
{
OptionsWindow* o = (OptionsWindow*) data;
@ -68,7 +105,7 @@ OptionsWindow::OptionsWindow()
tabs->end();
//ctlrButton->callback( selectLoadController );
ctlrButton->callback( selectLoadController );
bindEnable->callback( writeBindEnable, this );
writeControllerBtn->callback( writeControllerFile, this );