@@ -14,7 +14,8 @@ | |||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | ||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||||
*/ | |||||
*/ | |||||
#include <stdio.h> | |||||
#include "LogicPlugin.h" | #include "LogicPlugin.h" | ||||
#include "LogicPluginGUI.h" | #include "LogicPluginGUI.h" | ||||
#include <FL/Fl_Button.h> | #include <FL/Fl_Button.h> | ||||
@@ -46,20 +47,26 @@ string GetGroupName() | |||||
/////////////////////////////////////////////////////// | /////////////////////////////////////////////////////// | ||||
LogicPlugin::LogicPlugin() : | 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.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("Operator",(int*)&m_Operator); | ||||
m_AudioCH->Register("Constant",&m_Constant); | |||||
// Andy Preston - Multiple Inputs | |||||
m_AudioCH->Register ("Inputs", &m_Inputs); | |||||
} | } | ||||
LogicPlugin::~LogicPlugin() | LogicPlugin::~LogicPlugin() | ||||
@@ -67,7 +74,7 @@ LogicPlugin::~LogicPlugin() | |||||
} | } | ||||
PluginInfo &LogicPlugin::Initialise(const HostInfo *Host) | PluginInfo &LogicPlugin::Initialise(const HostInfo *Host) | ||||
{ | |||||
{ | |||||
return SpiralPlugin::Initialise(Host); | return SpiralPlugin::Initialise(Host); | ||||
} | } | ||||
@@ -78,79 +85,112 @@ SpiralGUIType *LogicPlugin::CreateGUI() | |||||
this,m_AudioCH,m_HostInfo); | this,m_AudioCH,m_HostInfo); | ||||
} | } | ||||
void LogicPlugin::Execute() | |||||
{ | |||||
float Freq=0, OldFreq=0; | |||||
switch (m_Operator) | |||||
{ | |||||
case AND : | |||||
for (int n=0; n<m_HostInfo->BUFSIZE; 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; n<m_HostInfo->BUFSIZE; 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; n<m_HostInfo->BUFSIZE; n++) | |||||
{ | |||||
if (GetInput(0,n)>0) SetOutput(0,n,-1.0f); | |||||
else SetOutput(0,n,1.0f); | |||||
} | |||||
break; | |||||
case NAND : | |||||
for (int n=0; n<m_HostInfo->BUFSIZE; 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; n<m_HostInfo->BUFSIZE; 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; n<m_HostInfo->BUFSIZE; 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; n<m_HostInfo->BUFSIZE; 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; n<m_HostInfo->BUFSIZE; 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<m_PluginInfo.NumInputs; i++) { | |||||
if (GetInput (i, n) > 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<<m_Version<<endl; | |||||
s<<m_Constant<<" "; | |||||
// Andy Preston - Multiple Inputs | |||||
void LogicPlugin::SetInputs (int n) { | |||||
// once to clear the connections with the current info | |||||
// do we need this???? | |||||
UpdatePluginInfoWithHost(); | |||||
// Things can get a bit confused deleting and adding inputs | |||||
// so we just chuck away all the ports... | |||||
RemoveAllInputs (); | |||||
RemoveAllOutputs (); | |||||
m_PluginInfo.NumInputs = 0; | |||||
m_PluginInfo.NumOutputs = 0; | |||||
m_PluginInfo.PortTips.clear (); | |||||
// ... and then create some new ones | |||||
CreatePorts (n, true); | |||||
// do the actual update | |||||
UpdatePluginInfoWithHost (); | |||||
} | |||||
// Andy Preston - Multiple Inputs | |||||
void LogicPlugin::CreatePorts (int n, bool AddPorts) { | |||||
int c; | |||||
m_PluginInfo.NumInputs = n; | |||||
m_Inputs = n; | |||||
char t[256]; | |||||
for (c=1; c<=n; c++) { | |||||
sprintf (t, "Input %d", c); | |||||
m_PluginInfo.PortTips.push_back (t); | |||||
} | |||||
m_PluginInfo.NumOutputs = 1; | |||||
m_PluginInfo.PortTips.push_back ("Output"); | |||||
if (AddPorts) { | |||||
for (c=0; c<m_PluginInfo.NumInputs; c++) AddInput(); | |||||
for (c=0; c<m_PluginInfo.NumOutputs; c++) AddOutput(); | |||||
} | |||||
} | } | ||||
void LogicPlugin::StreamIn(istream &s) | |||||
void LogicPlugin::StreamOut(ostream &s) | |||||
{ | { | ||||
int version; | |||||
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; | |||||
} | |||||
} | } |
@@ -14,7 +14,7 @@ | |||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | ||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||||
*/ | |||||
*/ | |||||
#include "../SpiralPlugin.h" | #include "../SpiralPlugin.h" | ||||
#include <FL/Fl_Pixmap.H> | #include <FL/Fl_Pixmap.H> | ||||
@@ -27,7 +27,7 @@ class LogicPlugin : public SpiralPlugin | |||||
public: | public: | ||||
LogicPlugin(); | LogicPlugin(); | ||||
virtual ~LogicPlugin(); | virtual ~LogicPlugin(); | ||||
virtual PluginInfo& Initialise(const HostInfo *Host); | virtual PluginInfo& Initialise(const HostInfo *Host); | ||||
virtual SpiralGUIType* CreateGUI(); | virtual SpiralGUIType* CreateGUI(); | ||||
virtual void Execute(); | virtual void Execute(); | ||||
@@ -38,11 +38,18 @@ public: | |||||
enum OperatorType{NONE,AND,OR,NOT,NAND,NOR,XOR,XNOR}; | enum OperatorType{NONE,AND,OR,NOT,NAND,NOR,XOR,XNOR}; | ||||
OperatorType GetOperator() { return m_Operator; } | 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: | private: | ||||
OperatorType m_Operator; | 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 | #endif |
@@ -74,7 +74,15 @@ SpiralPluginGUI(w,h,o,ch) | |||||
m_XNOR->labelsize(10); | m_XNOR->labelsize(10); | ||||
m_XNOR->selection_color(GUI_COLOUR); | m_XNOR->selection_color(GUI_COLOUR); | ||||
m_XNOR->callback((Fl_Callback*)cb_XNOR); | 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(); | end(); | ||||
} | } | ||||
@@ -103,9 +111,25 @@ void LogicPluginGUI::UpdateValues(SpiralPlugin *o) | |||||
case LogicPlugin::XOR : m_XOR->value(true); break; | case LogicPlugin::XOR : m_XOR->value(true); break; | ||||
case LogicPlugin::XNOR : m_XNOR->value(true); break; | case LogicPlugin::XNOR : m_XNOR->value(true); break; | ||||
} | } | ||||
// Andy Preston - multiple inputs | |||||
m_Inputs->value (Plugin->GetInputs()); | |||||
} | } | ||||
//// Callbacks //// | //// 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) | inline void LogicPluginGUI::cb_AND_i(Fl_Button* o, void* v) | ||||
{ | { | ||||
if (o->value()) | if (o->value()) | ||||
@@ -220,8 +244,9 @@ void LogicPluginGUI::cb_XNOR(Fl_Button* o, void* v) | |||||
const string LogicPluginGUI::GetHelpText(const string &loc){ | const string LogicPluginGUI::GetHelpText(const string &loc){ | ||||
return string("") | return string("") | ||||
+ "Note that NOT only uses input 1,\nand XOR/XNOR only use inputs 1 and 2\n\n" | |||||
+ "1001010111010101101111101010100101010101010100010100100101\n" | + "1001010111010101101111101010100101010101010100010100100101\n" | ||||
+ "0010101010111010010010101010001010011110001010101000101010\n" | + "0010101010111010010010101010001010011110001010101000101010\n" | ||||
+ "1110111101101001000010101010111110101010101010101111010101\n" | |||||
+ "0011011111010101101000001010101010001010100001100111010111"; | |||||
+ "1110111101101001000010101010111110101010101010101111010101\n" | |||||
+ "0011011111010101101000001010101010001010100001100111010111"; | |||||
} | } |
@@ -14,16 +14,13 @@ | |||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | ||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||||
*/ | |||||
*/ | |||||
#include <FL/Fl.H> | #include <FL/Fl.H> | ||||
#include <FL/Fl_Window.H> | #include <FL/Fl_Window.H> | ||||
#include <FL/Fl_Group.H> | #include <FL/Fl_Group.H> | ||||
#include <FL/Fl_Button.H> | #include <FL/Fl_Button.H> | ||||
#include <FL/Fl_Button.H> | |||||
#include <FL/Fl_Input.H> | |||||
#include "../Widgets/Fl_Knob.H" | |||||
#include <FL/Fl_Counter.H> | |||||
#include "../Widgets/Fl_DragBar.H" | #include "../Widgets/Fl_DragBar.H" | ||||
#include "LogicPlugin.h" | #include "LogicPlugin.h" | ||||
#include "../SpiralPluginGUI.h" | #include "../SpiralPluginGUI.h" | ||||
@@ -32,36 +29,35 @@ | |||||
#define PluginGUI | #define PluginGUI | ||||
static const int NUM_KEYS = 12; | static const int NUM_KEYS = 12; | ||||
class LogicPluginGUI : public SpiralPluginGUI | class LogicPluginGUI : public SpiralPluginGUI | ||||
{ | { | ||||
public: | public: | ||||
LogicPluginGUI(int w, int h, LogicPlugin *o,ChannelHandler *ch,const HostInfo *Info); | LogicPluginGUI(int w, int h, LogicPlugin *o,ChannelHandler *ch,const HostInfo *Info); | ||||
virtual void UpdateValues(SpiralPlugin *o); | virtual void UpdateValues(SpiralPlugin *o); | ||||
protected: | protected: | ||||
const string GetHelpText(const string &loc); | |||||
const string GetHelpText(const string &loc); | |||||
private: | private: | ||||
Fl_Counter *m_Inputs; | |||||
Fl_Button *m_AND,*m_OR,*m_NOT,*m_NAND,*m_NOR,*m_XOR,*m_XNOR; | 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); | 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); | 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); | 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); | inline void cb_NAND_i(Fl_Button* o, void* v); | ||||
static void cb_NAND(Fl_Button* o, void* v); | static void cb_NAND(Fl_Button* o, void* v); | ||||
inline void cb_NOR_i(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); | 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); | inline void cb_XNOR_i(Fl_Button* o, void* v); | ||||
static void cb_XNOR(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 | #endif |