1 /* SpiralSound
2 * Copyleft (C) 2001 David Griffiths <dave@pawfal.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 #include "OperatorPlugin.h"
19 #include "OperatorPluginGUI.h"
20 #include <FL/Fl_Button.H>
21 #include "SpiralIcon.xpm"
22 #include "../../NoteTable.h"
23
24 using namespace std;
25
26 extern "C" {
SpiralPlugin_CreateInstance()27 SpiralPlugin* SpiralPlugin_CreateInstance()
28 {
29 return new OperatorPlugin;
30 }
31
SpiralPlugin_GetIcon()32 char** SpiralPlugin_GetIcon()
33 {
34 return SpiralIcon_xpm;
35 }
36
SpiralPlugin_GetID()37 int SpiralPlugin_GetID()
38 {
39 return 44;
40 }
41
SpiralPlugin_GetGroupName()42 string SpiralPlugin_GetGroupName()
43 {
44 return "Maths/Logic";
45 }
46 }
47
48 ///////////////////////////////////////////////////////
49
OperatorPlugin()50 OperatorPlugin::OperatorPlugin() :
51 m_Operator(ADD),
52 m_Constant(0)
53 {
54 m_Version=2;
55
56 m_PluginInfo.Name="Operator";
57 m_PluginInfo.Width=120;
58 m_PluginInfo.Height=80;
59 m_PluginInfo.NumInputs=2;
60 m_PluginInfo.NumOutputs=1;
61 m_PluginInfo.PortTips.push_back("Input 1");
62 m_PluginInfo.PortTips.push_back("Input 2");
63 m_PluginInfo.PortTips.push_back("Output");
64
65 m_AudioCH->Register("Operator",(int*)&m_Operator);
66 m_AudioCH->Register("Constant",&m_Constant);
67 }
68
~OperatorPlugin()69 OperatorPlugin::~OperatorPlugin()
70 {
71 }
72
Initialise(const HostInfo * Host)73 PluginInfo &OperatorPlugin::Initialise(const HostInfo *Host)
74 {
75 return SpiralPlugin::Initialise(Host);
76 }
77
CreateGUI()78 SpiralGUIType *OperatorPlugin::CreateGUI()
79 {
80 return new OperatorPluginGUI(m_PluginInfo.Width,
81 m_PluginInfo.Height,
82 this,m_AudioCH,m_HostInfo);
83 }
84
Execute()85 void OperatorPlugin::Execute()
86 {
87 float Freq=0, OldFreq=0;
88 switch (m_Operator)
89 {
90 case ADD :
91 if (InputExists(1))
92 {
93 for (int n=0; n<m_HostInfo->BUFSIZE; n++)
94 {
95 SetOutput(0,n,GetInput(0,n)+GetInput(1,n));
96 }
97 }
98 else
99 {
100 for (int n=0; n<m_HostInfo->BUFSIZE; n++)
101 {
102 SetOutput(0,n,GetInput(0,n)+m_Constant);
103 }
104 }
105 break;
106 case SUB :
107 if (InputExists(1))
108 {
109 for (int n=0; n<m_HostInfo->BUFSIZE; n++)
110 {
111 SetOutput(0,n,GetInput(0,n)-GetInput(1,n));
112 }
113 }
114 else
115 {
116 for (int n=0; n<m_HostInfo->BUFSIZE; n++)
117 {
118 SetOutput(0,n,GetInput(0,n)-m_Constant);
119 }
120 }
121 break;
122 case DIV :
123 if (InputExists(1))
124 {
125 for (int n=0; n<m_HostInfo->BUFSIZE; n++)
126 {
127 if (GetInput(1,n)==0) SetOutput(0,n,0);
128 else SetOutput(0,n,GetInput(0,n)/GetInput(1,n));
129 }
130 }
131 else
132 {
133 for (int n=0; n<m_HostInfo->BUFSIZE; n++)
134 {
135 if (m_Constant==0) SetOutput(0,n,0);
136 else SetOutput(0,n,GetInput(0,n)/m_Constant);
137 }
138 }
139 break;
140 case MUL :
141 if (InputExists(1))
142 {
143 for (int n=0; n<m_HostInfo->BUFSIZE; n++)
144 {
145 SetOutput(0,n,GetInput(0,n)*GetInput(1,n));
146 }
147 }
148 else
149 {
150 for (int n=0; n<m_HostInfo->BUFSIZE; n++)
151 {
152 SetOutput(0,n,GetInput(0,n)*m_Constant);
153 }
154 }
155 break;
156 default:
157 break;
158 }
159 }
160
ExecuteCommands()161 void OperatorPlugin::ExecuteCommands()
162 {
163 }
164
StreamOut(ostream & s)165 void OperatorPlugin::StreamOut(ostream &s)
166 {
167 s<<m_Version<<endl;
168 s<<m_Constant<<" ";
169 s<<(int)m_Operator<<" ";
170 }
171
StreamIn(istream & s)172 void OperatorPlugin::StreamIn(istream &s)
173 {
174 int version;
175 s>>version;
176 s>>m_Constant;
177 if (version>1)
178 {
179 int t;
180 s>>t;
181 m_Operator=(OperatorType)t;
182 }
183 }
184