diff --git a/SpiralSound/Plugins/LogicPlugin/LogicPlugin.C b/SpiralSound/Plugins/LogicPlugin/LogicPlugin.C index f52155b..f1612d0 100644 --- a/SpiralSound/Plugins/LogicPlugin/LogicPlugin.C +++ b/SpiralSound/Plugins/LogicPlugin/LogicPlugin.C @@ -14,7 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ +*/ +#include #include "LogicPlugin.h" #include "LogicPluginGUI.h" #include @@ -46,20 +47,26 @@ string GetGroupName() /////////////////////////////////////////////////////// LogicPlugin::LogicPlugin() : -m_Operator(AND), -m_Constant(0) +m_Operator(AND) { - m_PluginInfo.Name="Logic"; + m_Version = 2; + m_PluginInfo.Name="Logic"; m_PluginInfo.Width=75; - m_PluginInfo.Height=100; - m_PluginInfo.NumInputs=2; - m_PluginInfo.NumOutputs=1; - m_PluginInfo.PortTips.push_back("Input 1"); - m_PluginInfo.PortTips.push_back("Input 2"); - m_PluginInfo.PortTips.push_back("Output"); - + // Andy Preston - multiple inputs - was 100 + m_PluginInfo.Height=130; + + // Andy Preston - Multiple Inputs + CreatePorts (); + // m_PluginInfo.NumInputs=2; + // m_PluginInfo.NumOutputs=1; + // m_PluginInfo.PortTips.push_back("Input 1"); + // m_PluginInfo.PortTips.push_back("Input 2"); + // m_PluginInfo.PortTips.push_back("Output"); + m_AudioCH->Register("Operator",(int*)&m_Operator); - m_AudioCH->Register("Constant",&m_Constant); + // Andy Preston - Multiple Inputs + m_AudioCH->Register ("Inputs", &m_Inputs); + } LogicPlugin::~LogicPlugin() @@ -67,7 +74,7 @@ LogicPlugin::~LogicPlugin() } PluginInfo &LogicPlugin::Initialise(const HostInfo *Host) -{ +{ return SpiralPlugin::Initialise(Host); } @@ -78,79 +85,112 @@ SpiralGUIType *LogicPlugin::CreateGUI() this,m_AudioCH,m_HostInfo); } -void LogicPlugin::Execute() -{ - float Freq=0, OldFreq=0; - - switch (m_Operator) - { - case AND : - for (int n=0; nBUFSIZE; n++) - { - if (GetInput(0,n)>0 && GetInput(1,n)>0) SetOutput(0,n,1.0f); - else SetOutput(0,n,-1.0f); - } - break; - case OR : - for (int n=0; nBUFSIZE; n++) - { - if (GetInput(0,n)>0 || GetInput(1,n)>0) SetOutput(0,n,1.0f); - else SetOutput(0,n,-1.0f); - } - break; - case NOT : - for (int n=0; nBUFSIZE; n++) - { - if (GetInput(0,n)>0) SetOutput(0,n,-1.0f); - else SetOutput(0,n,1.0f); - } - break; - case NAND : - for (int n=0; nBUFSIZE; n++) - { - if (!(GetInput(0,n)>0 && GetInput(1,n)>0)) SetOutput(0,n,1.0f); - else SetOutput(0,n,-1.0f); - } - break; - case NOR : - for (int n=0; nBUFSIZE; n++) - { - if (!(GetInput(0,n)>0) && !(GetInput(1,n)>0)) SetOutput(0,n,1.0f); - else SetOutput(0,n,-1.0f); - } - break; - case XOR : - for (int n=0; nBUFSIZE; n++) - { - if ((GetInput(0,n)>0 || GetInput(1,n)>0) && - !(GetInput(0,n)>0 && GetInput(1,n)>0)) SetOutput(0,n,1.0f); - else SetOutput(0,n,-1.0f); - } - break; - case XNOR : - for (int n=0; nBUFSIZE; n++) - { - if ((GetInput(0,n)>0 && GetInput(1,n)>0) || - (!(GetInput(0,n)>0) && !(GetInput(1,n)>0))) SetOutput(0,n,1.0f); - else SetOutput(0,n,-1.0f); - } - break; - } +// Andy Preston - Multiple Inputs +void LogicPlugin::Execute (void) { + float Freq=0, OldFreq=0; + for (int n=0; nBUFSIZE; n++) { + switch (m_Operator) { + case NOT: // Only Uses Input 1 + if (GetInput(0,n)>0) SetOutput(0,n,-1.0f); + else SetOutput(0,n,1.0f); + break; + case XOR: // Only uses inputs 1 and 2 + if ((GetInput(0,n)>0 || GetInput(1,n)>0) && !(GetInput(0,n)>0 && GetInput(1,n)>0)) + SetOutput(0,n,1.0f); + else SetOutput(0,n,-1.0f); + break; + case XNOR: // Only uses inputs 1 and 2 + if ((GetInput(0,n)>0 && GetInput(1,n)>0) || (!(GetInput(0,n)>0) && !(GetInput(1,n)>0))) + SetOutput(0,n,1.0f); + else SetOutput(0,n,-1.0f); + break; + default: // Uses all available inputs + int true_val, give_up; + switch (m_Operator) { + case AND: true_val = 1; give_up = -1; break; + case OR: true_val = 1; give_up = 1; break; + case NAND: true_val = -1; give_up = 1; break; + case NOR : true_val = -1; give_up = -1; break; + default: true_val = 0; give_up = 0; break; + } + int result = 0; + for (int i=0; i 0) result = true_val; else result = -true_val; + if (result == give_up) break; + } + SetOutput (0, n, (float)result); + break; + } + } } -void LogicPlugin::ExecuteCommands() -{ + +void LogicPlugin::ExecuteCommands() { + // Andy Preston - Multiple Inputs + if (m_AudioCH->IsCommandWaiting ()) { + switch (m_AudioCH->GetCommand()) { + case SETINPUTS: + SetInputs (m_Inputs); + break; + } + } } - -void LogicPlugin::StreamOut(ostream &s) -{ - s<>version; - s>>m_Constant; + s << 1 /*m_Version*/ << endl; + s << m_PluginInfo.NumInputs << " " << m_Operator; +} + +void LogicPlugin::StreamIn(istream &s) { + int version, datum; + s >> version; + switch (version) { + case 1: // Original Version + s >> datum; // Version 1 saved a constant that is not used now + SetInputs (2); + break; + case 2: // Andy Preston + s >> datum; + SetInputs (datum); + s >> datum; + m_Operator = (OperatorType)datum; + break; + } } diff --git a/SpiralSound/Plugins/LogicPlugin/LogicPlugin.h b/SpiralSound/Plugins/LogicPlugin/LogicPlugin.h index 5ab380e..149946d 100644 --- a/SpiralSound/Plugins/LogicPlugin/LogicPlugin.h +++ b/SpiralSound/Plugins/LogicPlugin/LogicPlugin.h @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ +*/ #include "../SpiralPlugin.h" #include @@ -27,7 +27,7 @@ class LogicPlugin : public SpiralPlugin public: LogicPlugin(); virtual ~LogicPlugin(); - + virtual PluginInfo& Initialise(const HostInfo *Host); virtual SpiralGUIType* CreateGUI(); virtual void Execute(); @@ -38,11 +38,18 @@ public: enum OperatorType{NONE,AND,OR,NOT,NAND,NOR,XOR,XNOR}; OperatorType GetOperator() { return m_Operator; } - float GetConstant() { return m_Constant; } - + // float GetConstant() { return m_Constant; } Andy Preston - this value is not used + // Andy Preston - Multiple Inputs + enum GUICommands {NOCMD, SETINPUTS}; + int GetInputs (void) { return m_Inputs; } + private: OperatorType m_Operator; - float m_Constant; + // float m_Constant; Andy Preston - this value is not used + // Andy Preston - Multiple Inputs + int m_Inputs; + void SetInputs (int n); + void CreatePorts (int n = 2, bool AddPorts = false); }; #endif diff --git a/SpiralSound/Plugins/LogicPlugin/LogicPluginGUI.C b/SpiralSound/Plugins/LogicPlugin/LogicPluginGUI.C index e826a93..0eb90b7 100644 --- a/SpiralSound/Plugins/LogicPlugin/LogicPluginGUI.C +++ b/SpiralSound/Plugins/LogicPlugin/LogicPluginGUI.C @@ -74,7 +74,15 @@ SpiralPluginGUI(w,h,o,ch) m_XNOR->labelsize(10); m_XNOR->selection_color(GUI_COLOUR); m_XNOR->callback((Fl_Callback*)cb_XNOR); - + + // Andy Preston - multiple inputs + m_Inputs = new Fl_Counter (17, 97, 40, 20, "Inputs"); + m_Inputs->labelsize (10); + m_Inputs->type (FL_SIMPLE_COUNTER); + m_Inputs->step (1); + m_Inputs->value (2); + m_Inputs->callback ((Fl_Callback*) cb_Inputs); + end(); } @@ -103,9 +111,25 @@ void LogicPluginGUI::UpdateValues(SpiralPlugin *o) case LogicPlugin::XOR : m_XOR->value(true); break; case LogicPlugin::XNOR : m_XNOR->value(true); break; } + // Andy Preston - multiple inputs + m_Inputs->value (Plugin->GetInputs()); } //// Callbacks //// + +// Andy Preston - multiple inputs +inline void LogicPluginGUI::cb_Inputs_i (Fl_Counter* o, void* v) { + if (o->value() < 2) o->value(2); + else { + m_GUICH->Set ("Inputs", int (o->value ())); + m_GUICH->SetCommand (LogicPlugin::SETINPUTS); + } +} + +void LogicPluginGUI::cb_Inputs (Fl_Counter* o, void* v) { + ((LogicPluginGUI*) (o->parent ())) -> cb_Inputs_i (o, v); +} + inline void LogicPluginGUI::cb_AND_i(Fl_Button* o, void* v) { if (o->value()) @@ -220,8 +244,9 @@ void LogicPluginGUI::cb_XNOR(Fl_Button* o, void* v) const string LogicPluginGUI::GetHelpText(const string &loc){ return string("") + + "Note that NOT only uses input 1,\nand XOR/XNOR only use inputs 1 and 2\n\n" + "1001010111010101101111101010100101010101010100010100100101\n" + "0010101010111010010010101010001010011110001010101000101010\n" - + "1110111101101001000010101010111110101010101010101111010101\n" - + "0011011111010101101000001010101010001010100001100111010111"; + + "1110111101101001000010101010111110101010101010101111010101\n" + + "0011011111010101101000001010101010001010100001100111010111"; } diff --git a/SpiralSound/Plugins/LogicPlugin/LogicPluginGUI.h b/SpiralSound/Plugins/LogicPlugin/LogicPluginGUI.h index de9879e..30bac9c 100644 --- a/SpiralSound/Plugins/LogicPlugin/LogicPluginGUI.h +++ b/SpiralSound/Plugins/LogicPlugin/LogicPluginGUI.h @@ -14,16 +14,13 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ +*/ #include #include #include #include -#include -#include - -#include "../Widgets/Fl_Knob.H" +#include #include "../Widgets/Fl_DragBar.H" #include "LogicPlugin.h" #include "../SpiralPluginGUI.h" @@ -32,36 +29,35 @@ #define PluginGUI static const int NUM_KEYS = 12; + class LogicPluginGUI : public SpiralPluginGUI { public: LogicPluginGUI(int w, int h, LogicPlugin *o,ChannelHandler *ch,const HostInfo *Info); - virtual void UpdateValues(SpiralPlugin *o); - protected: - const string GetHelpText(const string &loc); - + const string GetHelpText(const string &loc); private: + Fl_Counter *m_Inputs; Fl_Button *m_AND,*m_OR,*m_NOT,*m_NAND,*m_NOR,*m_XOR,*m_XNOR; - - void ClearButtons(); - - //// Callbacks //// + void ClearButtons(); + //// Callbacks //// inline void cb_AND_i(Fl_Button* o, void* v); - static void cb_AND(Fl_Button* o, void* v); + static void cb_AND(Fl_Button* o, void* v); inline void cb_OR_i(Fl_Button* o, void* v); - static void cb_OR(Fl_Button* o, void* v); + static void cb_OR(Fl_Button* o, void* v); inline void cb_NOT_i(Fl_Button* o, void* v); - static void cb_NOT(Fl_Button* o, void* v); + static void cb_NOT(Fl_Button* o, void* v); inline void cb_NAND_i(Fl_Button* o, void* v); static void cb_NAND(Fl_Button* o, void* v); inline void cb_NOR_i(Fl_Button* o, void* v); - static void cb_NOR(Fl_Button* o, void* v); + static void cb_NOR(Fl_Button* o, void* v); inline void cb_XOR_i(Fl_Button* o, void* v); - static void cb_XOR(Fl_Button* o, void* v); + static void cb_XOR(Fl_Button* o, void* v); inline void cb_XNOR_i(Fl_Button* o, void* v); static void cb_XNOR(Fl_Button* o, void* v); + inline void cb_Inputs_i (Fl_Counter* o, void* v); + static void cb_Inputs (Fl_Counter* o, void* v); }; #endif