-Fixing bindings window, adding Author / Email details

main
Harry van Haaren 2013-11-16 17:19:36 +00:00
parent 50b34ebaa7
commit f9e1950777
6 changed files with 117 additions and 24 deletions

View File

@ -78,12 +78,20 @@ std::string GenericMIDI::getName()
return name;
}
std::string GenericMIDI::getAuthor()
{
return author;
}
std::string GenericMIDI::getEmail()
{
return email;
}
void GenericMIDI::volume(int t, float f)
{
}
void GenericMIDI::recordArm(int t, bool enabled)
{
for(unsigned int i = 0; i < actionToMidi.size(); i++)
@ -389,11 +397,13 @@ void GenericMIDI::midi(unsigned char* midi)
int data = midi[1];
float value = midi[2] / 127.f;
//LUPPP_NOTE("GenericMIDI::midi() %i %i %f", status, data, value );
// create new MIDI binding?
if ( jack->bindingEventRecordEnable )
{
LUPPP_NOTE("making binding from: %i %i %f", status, data, value );
setupBinding( jack->bindingEventType, status, data,
jack->bindingTrack,
jack->bindingScene,
@ -402,11 +412,11 @@ void GenericMIDI::midi(unsigned char* midi)
// binding is now created, so disable GUI binding enable button
jack->bindingEventRecordEnable = false;
EventControllerBindingEnable e( false );
EventControllerBindingEnable e( getID(), false );
writeToGuiRingbuffer( &e );
// update GUI of new binding
EventControllerBindingMade e2( (void*)midiToAction.back() );
EventControllerBindingMade e2( getID(), (void*)midiToAction.back() );
writeToGuiRingbuffer( &e2 );
}
@ -588,6 +598,28 @@ int GenericMIDI::loadController( std::string file )
LUPPP_NOTE("Has no name field");
}
cJSON* authorJson = cJSON_GetObjectItem( controllerJson, "author" );
if ( authorJson )
{
author = authorJson->valuestring;
LUPPP_NOTE("Author %s", author.c_str() );
}
else
{
LUPPP_NOTE("Has no author field");
}
cJSON* linkJson = cJSON_GetObjectItem( controllerJson, "email" );
if ( linkJson )
{
email = linkJson->valuestring;
LUPPP_NOTE("Email %s", email.c_str() );
}
else
{
LUPPP_NOTE("Has no email field");
}
int nInputBindings = 0;
cJSON* inputBindings = cJSON_GetObjectItem( controllerJson, "inputBindings");
@ -634,7 +666,7 @@ int GenericMIDI::loadController( std::string file )
}
else
{
LUPPP_WARN("No output bindings array in .ctlr map." );
LUPPP_NOTE("No output bindings array in .ctlr map." );
nOutputBindings++; // hack to avoid 2 prints
}
if ( nOutputBindings == 0 )

View File

@ -32,6 +32,8 @@ class GenericMIDI : public Controller, public MidiIO
void setName(std::string );
std::string getName();
std::string getAuthor();
std::string getEmail();
/// track actions
//void mute(int t, bool b);
@ -73,6 +75,8 @@ class GenericMIDI : public Controller, public MidiIO
STATUS stat;
std::string name;
std::string author;
std::string email;
/// contains midi binding instances
std::vector<Binding*> midiToAction;

View File

@ -128,8 +128,9 @@ class EventControllerBindingMade : public EventBase
public:
int type() { return int(CONTROLLER_BINDING_MADE); }
uint32_t size() { return sizeof(EventControllerBindingMade); }
int controllerID;
void* binding;
EventControllerBindingMade(void* b=0): binding(b){}
EventControllerBindingMade(int id = 0, void* b=0): controllerID(id), binding(b){}
};
class EventControllerBindingEnable : public EventBase
@ -137,8 +138,9 @@ class EventControllerBindingEnable : public EventBase
public:
int type() { return int(CONTROLLER_BINDING_ENABLE); }
uint32_t size() { return sizeof(EventControllerBindingEnable); }
int controllerID;
bool enable;
EventControllerBindingEnable(bool e=false):enable(e){}
EventControllerBindingEnable(int id = 0, bool e=false):controllerID(id),enable(e){}
};
class EventGridSelectClipEvent : public EventBase

View File

@ -297,27 +297,29 @@ void handleGuiEvents()
if ( availableRead >= sizeof(EventControllerBindingEnable) ) {
EventControllerBindingEnable ev;
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventControllerBindingEnable) );
// FIXME: needs to include controllerID!
//gui->getOptionsWindow()->setBindEnable( ev.enable );
ControllerUI* c = gui->getOptionsWindow()->getControllerUI( ev.controllerID );
if ( c )
c->setBindEnable( ev.enable );
else
LUPPP_WARN("ControllerUI %i doesn't exist in the UI", ev.controllerID );
} break; }
case Event::CONTROLLER_BINDING_TARGET: {
if ( availableRead >= sizeof(EventControllerBindingTarget) ) {
EventControllerBindingTarget ev;
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventControllerBindingTarget) );
// FIXME: needs to include controllerID!
//gui->getOptionsWindow()->setTarget( ev.target );
gui->getOptionsWindow()->setTarget( ev.target );
} break; }
case Event::CONTROLLER_BINDING_MADE: {
if ( availableRead >= sizeof(EventControllerBindingMade) ) {
EventControllerBindingMade ev;
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventControllerBindingMade) );
// FIXME: needs to include controllerID!
//gui->getOptionsWindow()->addBinding( (Binding*)ev.binding );
ControllerUI* c = gui->getOptionsWindow()->getControllerUI( ev.controllerID );
if ( c )
c->addBinding( (Binding*)ev.binding );
else
LUPPP_WARN("ControllerUI %i doesn't exist in the UI", ev.controllerID );
} break; }
case Event::CONTROLLER_INSTANCE_GET_TO_WRITE: {

View File

@ -27,6 +27,8 @@ static void addControllerUiDsp(OptionsWindow* self, GenericMIDI* c)
self->tabs->insert( *self->controllers.back()->widget, self->addGroup );
// tell the ControllerUI to add the bindings from this Controller*
self->controllers.back()->setAuthor( c->getAuthor() );
self->controllers.back()->setEmail( c->getEmail() );
self->controllers.back()->addBindings( c );
self->tabs->redraw();
@ -44,7 +46,8 @@ static void writeBindEnable(Fl_Widget* w, void* data)
Avtk::LightButton* l = (Avtk::LightButton*)w;
l->value( !l->value() );
EventControllerBindingEnable e( l->value() );
int controllerID = -1; // waste?
EventControllerBindingEnable e( controllerID, l->value() );
writeToDspRingbuffer( &e );
}
@ -157,15 +160,20 @@ ControllerUI::ControllerUI(int x, int y, int w, int h, std::string n, int ID)
widget = new Fl_Group( x, y, w, h, name);
{
targetLabelStat = new Fl_Box(x + 100,y + 5, 75, 25,"Target: ");
targetLabel = new Fl_Box(x + 140,y + 5, 200, 25,"");
bindEnable = new Avtk::LightButton(x + 5, y + 5, 100, 25, "Bind Enable");
// author / link
authorLabel = new Fl_Box( x, y + 0, 200, 30, "Author: -" );
emailLabel = new Fl_Box( x + w/2, y + 0, 200, 30, "Email: -" );
// binding / target
targetLabelStat = new Fl_Box(x + 100,y + 25, 75, 25,"Target: ");
targetLabel = new Fl_Box(x + 140,y + 25, 200, 25,"");
bindEnable = new Avtk::LightButton(x + 5, y + 25, 100, 25, "Bind Enable");
writeControllerBtn = new Avtk::Button( x + 5, y + h - 27, 100, 25, "Save" );
//ctlrButton = new Avtk::Button(x + 110, y + 275, 100, 25, "Load");
removeController = new Avtk::Button(x + 110, y + h - 27, 100, 25, "Remove");
Fl_Scroll* s = new Fl_Scroll( x + 5, y + 35, 400, 180 );
Fl_Scroll* s = new Fl_Scroll( x + 5, y + 75, 400, 180 );
s->box( FL_UP_BOX );
bindings = new Avtk::Bindings( x + 5, y + 35, 398, 10 );
s->end();
@ -182,7 +190,15 @@ ControllerUI::ControllerUI(int x, int y, int w, int h, std::string n, int ID)
writeControllerBtn->callback( writeControllerFile, this );
}
void ControllerUI::setTarget(const char* n)
void OptionsWindow::setTarget(const char* n)
{
for(unsigned int i = 0; i < controllers.size(); i++ )
{
controllers.at(i)->setTarget( n );
}
}
void ControllerUI::setTarget( const char* n )
{
if ( target )
free (target);
@ -192,19 +208,45 @@ void ControllerUI::setTarget(const char* n)
targetLabel->redraw();
}
void ControllerUI::setAuthor(std::string a)
{
stringstream s;
s << "Author: " << a;
author = s.str();
authorLabel->label( author.c_str() );
authorLabel->redraw();
}
void ControllerUI::setEmail(std::string e)
{
stringstream s;
s << "Email: " << e;
email = s.str();
emailLabel->label( email.c_str() );
emailLabel->redraw();
}
void ControllerUI::setBindEnable( bool b )
{
bindEnable->value( b );
}
void ControllerUI::addBinding( Binding* b )
{
// add individual bindings as they're made
}
void ControllerUI::addBindings( GenericMIDI* c )
{
/*
// FIXME: add binding to Avtk::Binding here
std::vector<Binding*> bindingVector= c->getMidiToAction();
for( int i = 0; i < bindingVector.size() && i < 5; i++ )
for(unsigned int i = 0; i < bindingVector.size() && i < 5; i++ )
{
bindings->add( bindingVector.at(i) );
}
*/
}
ControllerUI::~ControllerUI()

View File

@ -27,9 +27,13 @@ class ControllerUI
ControllerUI( int x, int y, int w, int h, std::string name,int id);
~ControllerUI();
void setTarget(const char* n);
void setAuthor(std::string author);
void setEmail (std::string email );
void setTarget(const char* n);
void setBindEnable( bool b );
void addBinding( Binding* b );
void addBindings( GenericMIDI* c );
// the ControllerID this UI class represents
@ -45,6 +49,12 @@ class ControllerUI
private:
// bindings
char* target;
std::string author;
std::string email;
Fl_Box* authorLabel;
Fl_Box* emailLabel;
Fl_Box* targetLabel;
Fl_Box* targetLabelStat;
Avtk::Bindings* bindings;
@ -66,6 +76,7 @@ class OptionsWindow
void show();
void hide();
void setTarget(const char* n);
ControllerUI* getControllerUI(int id);
// public for static methods only