2013-10-18 14:49:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
#include "goptions.hxx"
|
|
|
|
|
|
|
|
#include "eventhandler.hxx"
|
|
|
|
|
2013-10-18 16:56:20 +02:00
|
|
|
#include "controller/binding.hxx"
|
2013-10-19 14:16:16 +02:00
|
|
|
#include "controller/controller.hxx"
|
|
|
|
#include "controller/genericmidi.hxx"
|
2013-10-18 14:49:46 +02:00
|
|
|
|
2013-10-19 13:54:26 +02:00
|
|
|
#include "gui.hxx"
|
|
|
|
extern Gui* gui;
|
2013-10-18 14:49:46 +02:00
|
|
|
|
|
|
|
static void writeBindEnable(Fl_Widget* w, void* data)
|
|
|
|
{
|
|
|
|
OptionsWindow* o = (OptionsWindow*) data;
|
|
|
|
//LUPPP_NOTE("MIDI bind mode");
|
|
|
|
|
|
|
|
Avtk::LightButton* l = (Avtk::LightButton*)w;
|
|
|
|
l->value( !l->value() );
|
|
|
|
|
2013-10-18 17:52:04 +02:00
|
|
|
EventControllerBindingEnable e( l->value() );
|
2013-10-18 14:49:46 +02:00
|
|
|
writeToDspRingbuffer( &e );
|
2013-10-18 17:56:13 +02:00
|
|
|
|
|
|
|
if ( l->value() < 0.5 )
|
|
|
|
{
|
|
|
|
o->setTarget("");
|
|
|
|
}
|
2013-10-18 14:49:46 +02:00
|
|
|
}
|
|
|
|
|
2013-11-02 18:54:42 +01:00
|
|
|
static void addNewController(Fl_Widget* w, void*)
|
|
|
|
{
|
|
|
|
LUPPP_NOTE("%s","ADD Controller cb");
|
|
|
|
|
2013-11-03 14:41:30 +01:00
|
|
|
GenericMIDI* c = 0;
|
|
|
|
|
2013-11-02 18:54:42 +01:00
|
|
|
const char* name = fl_input( "Controller name: ", "" );
|
|
|
|
if ( name )
|
|
|
|
{
|
2013-11-03 14:41:30 +01:00
|
|
|
c = new GenericMIDI( 0, name);
|
2013-11-02 18:54:42 +01:00
|
|
|
}
|
2013-11-03 14:41:30 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
c = new GenericMIDI();
|
|
|
|
}
|
|
|
|
|
2013-11-02 18:54:42 +01:00
|
|
|
|
|
|
|
if ( c->status() == Controller::CONTROLLER_OK )
|
|
|
|
{
|
|
|
|
EventControllerInstance e(c);
|
|
|
|
writeToDspRingbuffer( &e );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LUPPP_ERROR("Controller initialization failed!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-19 14:16:16 +02:00
|
|
|
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");
|
2013-10-19 14:31:14 +02:00
|
|
|
|
|
|
|
stringstream s;
|
|
|
|
s << getenv("HOME") << "/.config/openAV/luppp/";
|
|
|
|
fnfc.directory( s.str().c_str() ); // default directory to use
|
2013-10-19 14:16:16 +02:00
|
|
|
// 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!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-02 18:54:42 +01:00
|
|
|
|
|
|
|
|
2013-10-19 13:54:26 +02:00
|
|
|
static void writeControllerFile(Fl_Widget* w, void* data)
|
|
|
|
{
|
|
|
|
OptionsWindow* o = (OptionsWindow*) data;
|
|
|
|
|
|
|
|
// FIXME: Controller ID hardcoded
|
|
|
|
EventControllerInstanceGetToWrite e( 1 );
|
|
|
|
writeToDspRingbuffer( &e );
|
|
|
|
}
|
|
|
|
|
2013-10-18 14:49:46 +02:00
|
|
|
|
|
|
|
OptionsWindow::OptionsWindow()
|
|
|
|
{
|
2013-10-19 13:54:26 +02:00
|
|
|
window = new Fl_Double_Window(400,400,"Options");
|
2013-10-18 14:49:46 +02:00
|
|
|
|
2013-10-19 13:54:26 +02:00
|
|
|
tabs = new Fl_Tabs(0, 0, 400, 400);
|
2013-10-18 15:12:34 +02:00
|
|
|
|
|
|
|
int x, y, w, h;
|
|
|
|
tabs->client_area( x, y, w, h, 25 );
|
|
|
|
|
2013-10-18 16:56:20 +02:00
|
|
|
Fl_Group* bindingGroup = new Fl_Group( x, y, w, h, "Binding");
|
2013-10-18 15:12:34 +02:00
|
|
|
{
|
2013-10-18 16:56:20 +02:00
|
|
|
targetLabelStat = new Fl_Box(x + 100,y + 5, 75, 25,"Target: ");
|
|
|
|
targetLabel = new Fl_Box(x + 140,y + 5, 200, 25,"");
|
2013-10-18 15:12:34 +02:00
|
|
|
bindEnable = new Avtk::LightButton(x + 5, y + 5, 100, 25, "Bind Enable");
|
2013-10-18 16:56:20 +02:00
|
|
|
|
2013-10-19 13:54:26 +02:00
|
|
|
writeControllerBtn = new Avtk::Button( x + 5, y + 275, 100, 25, "Save" );
|
2013-10-19 14:38:49 +02:00
|
|
|
ctlrButton = new Avtk::Button(x + 110, y + 275, 100, 25, "Load");
|
2013-11-02 18:54:42 +01:00
|
|
|
newButton = new Avtk::Button(x + 215, y + 275, 100, 25, "New");
|
2013-10-19 13:54:26 +02:00
|
|
|
|
|
|
|
Fl_Scroll* s = new Fl_Scroll( x + 5, y + 35, 400, 180 );
|
2013-10-19 15:22:49 +02:00
|
|
|
bindings = new Avtk::Bindings( x + 5, y + 35, 398, 10 );
|
2013-10-18 16:56:20 +02:00
|
|
|
s->end();
|
2013-10-18 15:12:34 +02:00
|
|
|
}
|
2013-10-18 16:56:20 +02:00
|
|
|
bindingGroup->end();
|
2013-10-18 15:12:34 +02:00
|
|
|
|
|
|
|
Fl_Group* controllers = new Fl_Group( x, y, w, h, "Controllers");
|
|
|
|
controllers->hide();
|
|
|
|
{
|
2013-10-19 14:38:49 +02:00
|
|
|
//ctlrButton = new Avtk::Button(x + 5, y + 5, 100, 25, "Add Controller");
|
2013-10-18 15:12:34 +02:00
|
|
|
}
|
|
|
|
controllers->end();
|
|
|
|
|
|
|
|
tabs->end();
|
2013-10-18 14:49:46 +02:00
|
|
|
|
2013-11-08 17:55:05 +01:00
|
|
|
target = 0;
|
|
|
|
|
2013-11-02 18:54:42 +01:00
|
|
|
newButton->callback( addNewController );
|
2013-10-19 14:16:16 +02:00
|
|
|
ctlrButton->callback( selectLoadController );
|
2013-10-18 14:49:46 +02:00
|
|
|
bindEnable->callback( writeBindEnable, this );
|
2013-10-19 13:54:26 +02:00
|
|
|
writeControllerBtn->callback( writeControllerFile, this );
|
2013-10-18 14:49:46 +02:00
|
|
|
|
|
|
|
window->end();
|
|
|
|
}
|
|
|
|
|
2013-10-18 15:33:00 +02:00
|
|
|
void OptionsWindow::setTarget(const char* t)
|
|
|
|
{
|
2013-10-18 16:06:27 +02:00
|
|
|
if ( target )
|
|
|
|
free (target);
|
|
|
|
target = strdup(t);
|
|
|
|
|
|
|
|
targetLabel->label( target );
|
|
|
|
targetLabel->redraw();
|
|
|
|
|
|
|
|
//LUPPP_NOTE("New Target %s\n", target );
|
2013-10-18 15:33:00 +02:00
|
|
|
}
|
|
|
|
|
2013-10-18 14:49:46 +02:00
|
|
|
void OptionsWindow::show()
|
|
|
|
{
|
|
|
|
window->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionsWindow::setBindEnable(bool e)
|
|
|
|
{
|
2013-11-03 14:41:30 +01:00
|
|
|
LUPPP_NOTE("setBindEnable() %i", int(e) );
|
2013-10-18 14:49:46 +02:00
|
|
|
bindEnable->value( e );
|
2013-10-18 16:06:27 +02:00
|
|
|
setTarget("");
|
2013-10-18 14:49:46 +02:00
|
|
|
}
|
|
|
|
|
2013-10-18 17:52:04 +02:00
|
|
|
void OptionsWindow::addBinding( Binding* b )
|
2013-10-18 16:56:20 +02:00
|
|
|
{
|
2013-11-03 14:41:30 +01:00
|
|
|
// FIXME: adding a binding causes the window to stop drawing properly!
|
|
|
|
//bindings->add( b );
|
2013-10-18 16:56:20 +02:00
|
|
|
}
|
2013-10-18 14:49:46 +02:00
|
|
|
|