From f3028d465e26d3536a7360777a1b0905f5e9aa46 Mon Sep 17 00:00:00 2001 From: edgeeffect Date: Sat, 18 Jan 2003 19:29:14 +0000 Subject: [PATCH] Ported Wave Shaper to new archetecture --- .../Plugins/WaveShaperPlugin/Makefile.in | 33 +- .../WaveShaperPlugin/WaveShaperIcon.xpm | 289 ---------------- .../WaveShaperPlugin/WaveShaperPlugin.C | 314 +++++++++--------- .../WaveShaperPlugin/WaveShaperPlugin.h | 61 ++-- .../WaveShaperPlugin/WaveShaperPlugin.pro | 17 - .../WaveShaperPlugin/WaveShaperPluginGUI.C | 204 ++++++------ .../WaveShaperPlugin/WaveShaperPluginGUI.h | 62 ++-- 7 files changed, 328 insertions(+), 652 deletions(-) delete mode 100644 SpiralSound/Plugins/WaveShaperPlugin/WaveShaperIcon.xpm delete mode 100644 SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPlugin.pro diff --git a/SpiralSound/Plugins/WaveShaperPlugin/Makefile.in b/SpiralSound/Plugins/WaveShaperPlugin/Makefile.in index 311dab1..92825d7 100644 --- a/SpiralSound/Plugins/WaveShaperPlugin/Makefile.in +++ b/SpiralSound/Plugins/WaveShaperPlugin/Makefile.in @@ -1,22 +1,19 @@ ############################################################################# # Makefile for building WaveShaperPlugin.so -# Generated by tmake at 08:01, 2001/10/05 -# Project: WaveShaperPlugin -# Template: app ############################################################################# ####### Compiler, tools and options CC = gcc CXX = g++ -CFLAGS = @CFLAGS@ -CXXFLAGS= @CXXFLAGS@ +CFLAGS = @CFLAGS@ +CXXFLAGS= @CXXFLAGS@ INCPATH = -I/usr/X11R6/include LINK = g++ -shared -LFLAGS = +LFLAGS = LIBS = -L/usr/X11R6/lib @FLTK_LIBS@ -lGL -lXext -lX11 -ldl MOC = moc -UIC = +UIC = TAR = tar -cf GZIP = gzip -9f @@ -65,12 +62,12 @@ OBJECTS = ../SpiralPlugin.o \ ../../Sample.o \ WaveShaperPlugin.o \ WaveShaperPluginGUI.o -INTERFACES = -UICDECLS = -UICIMPLS = -SRCMOC = -OBJMOC = -DIST = +INTERFACES = +UICDECLS = +UICIMPLS = +SRCMOC = +OBJMOC = +DIST = TARGET = WaveShaperPlugin.so ####### Implicit rules @@ -102,10 +99,8 @@ $(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) moc: $(SRCMOC) -tmake: Makefile - -Makefile: WaveShaperPlugin.pro - tmake WaveShaperPlugin.pro -o Makefile +tmake: + tmake WaveShaperPlugin.pro dist: $(TAR) WaveShaperPlugin.tar WaveShaperPlugin.pro $(SOURCES) $(HEADERS) $(INTERFACES) $(DIST) @@ -114,7 +109,7 @@ dist: clean: -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) $(TARGET) -rm -f *~ core - + install: $(INSTALL) $(TARGET) $(libdir)/SpiralPlugins @@ -157,7 +152,7 @@ WaveShaperPlugin.o: WaveShaperPlugin.C \ ../Widgets/Fl_DragBar.H \ ../SpiralPluginGUI.h \ ../Widgets/Fl_DragBar.H \ - WaveShaperIcon.xpm + SpiralIcon.xpm WaveShaperPluginGUI.o: WaveShaperPluginGUI.C \ WaveShaperPluginGUI.h \ diff --git a/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperIcon.xpm b/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperIcon.xpm deleted file mode 100644 index 86fbcbd..0000000 --- a/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperIcon.xpm +++ /dev/null @@ -1,289 +0,0 @@ -/* XPM */ -static char * WaveShaperIcon_xpm[] = { -"36 36 250 2", -" c None", -". c #8B889B", -"+ c #9C99AA", -"@ c #ADAAB9", -"# c #837F94", -"$ c #7D7990", -"% c #9995A7", -"& c #67627C", -"* c #CDCBD4", -"= c #FCFCFC", -"- c #D1D0D8", -"; c #FFFFFF", -"> c #F1F1F3", -", c #848095", -"' c #2A2248", -") c #CFCED6", -"! c #68637D", -"~ c #ABA8B6", -"{ c #D5D3DB", -"] c #9490A2", -"^ c #C4C4C4", -"/ c #1D1C1D", -"( c #313134", -"_ c #EEEFEE", -": c #FBFBFB", -"< c #EFEFEF", -"[ c #7B768D", -"} c #464060", -"| c #DEDEE1", -"1 c #CBCACC", -"2 c #EEEEF1", -"3 c #79758C", -"4 c #FBFBFC", -"5 c #A2A2A2", -"6 c #171800", -"7 c #F5F6F5", -"8 c #747474", -"9 c #2A2A2B", -"0 c #403958", -"a c #7D788F", -"b c #C0BEC8", -"c c #BCBAC6", -"d c #BCBAC5", -"e c #625C79", -"f c #2B2932", -"g c #191919", -"h c #CCCCCC", -"i c #807B91", -"j c #3B3556", -"k c #F2F2F4", -"l c #929292", -"m c #BFBFBF", -"n c #111111", -"o c #000000", -"p c #100E15", -"q c #868689", -"r c #FEFDFE", -"s c #D9D7DE", -"t c #9C98AA", -"u c #FDFCFD", -"v c #DDDDDD", -"w c #575755", -"x c #5E5E5E", -"y c #C4C2CD", -"z c #423C5C", -"A c #F0F0F2", -"B c #939393", -"C c #555555", -"D c #4A4A4A", -"E c #010101", -"F c #282828", -"G c #C2C2C2", -"H c #DBDAE0", -"I c #615C78", -"J c #F6F6F7", -"K c #DADADA", -"L c #545454", -"M c #B8B8B8", -"N c #48445C", -"O c #2B2B2C", -"P c #686417", -"Q c #D3D3D3", -"R c #C1BEC9", -"S c #474060", -"T c #31294D", -"U c #716C85", -"V c #65607A", -"W c #625D78", -"X c #D5D4DB", -"Y c #F7F7F7", -"Z c #8B8B8B", -"` c #393643", -" . c #47415F", -".. c #9692A4", -"+. c #D9D8DE", -"@. c #F7F7F8", -"#. c #918DA0", -"$. c #B8B5C1", -"%. c #D1D1D1", -"&. c #252525", -"*. c #727175", -"=. c #FEFEFF", -"-. c #9D99AA", -";. c #DBD9E0", -">. c #E9E9E9", -",. c #CBCBCB", -"'. c #E0E0E0", -"). c #6C6C6C", -"!. c #515151", -"~. c #A6A6A7", -"{. c #827E93", -"]. c #615C77", -"^. c #EAEAED", -"/. c #DFDFE1", -"(. c #FFFF00", -"_. c #1E1D24", -":. c #9894A7", -"<. c #B1AEBB", -"[. c #69686F", -"}. c #969422", -"|. c #615C76", -"1. c #5F5A75", -"2. c #413E4D", -"3. c #1A1A1C", -"4. c #C3C1CB", -"5. c #9D9D9D", -"6. c #202020", -"7. c #383838", -"8. c #4C4C4C", -"9. c #C9C7D0", -"0. c #F1F1F1", -"a. c #F8F8F8", -"b. c #AEACB9", -"c. c #FEFEFE", -"d. c #1D1D1D", -"e. c #B7B5C1", -"f. c #9390A2", -"g. c #BBBBBB", -"h. c #414141", -"i. c #28272A", -"j. c #F4F4F6", -"k. c #605B76", -"l. c #736E86", -"m. c #D8D8D8", -"n. c #727272", -"o. c #848486", -"p. c #CCCBD3", -"q. c #747087", -"r. c #6D6881", -"s. c #1C1C1C", -"t. c #242424", -"u. c #656566", -"v. c #F6F6F6", -"w. c #E8E6EA", -"x. c #706B84", -"y. c #E3E1E6", -"z. c #474746", -"A. c #C8C8C8", -"B. c #373639", -"C. c #FDFCFE", -"D. c #ABA8B7", -"E. c #F1F0F3", -"F. c #6D6980", -"G. c #AEAEAE", -"H. c #95929E", -"I. c #5B5A5C", -"J. c #F7F6F7", -"K. c #F4F3F5", -"L. c #908C9F", -"M. c #C8C6D0", -"N. c #837E96", -"O. c #86868A", -"P. c #ECEBEE", -"Q. c #5B5571", -"R. c #646078", -"S. c #AFAFB0", -"T. c #454545", -"U. c #363636", -"V. c #7A7A7A", -"W. c #C8C8C9", -"X. c #212025", -"Y. c #969699", -"Z. c #FAFAFA", -"`. c #F8F8F9", -" + c #A29EAF", -".+ c #F7F6F8", -"++ c #F0F0F1", -"@+ c #B8B7B9", -"#+ c #E4E4E4", -"$+ c #FDFDFD", -"%+ c #A5A2B2", -"&+ c #3B3456", -"*+ c #A8A5B4", -"=+ c #525252", -"-+ c #848387", -";+ c #CDCDCD", -">+ c #8D899C", -",+ c #494262", -"'+ c #68627C", -")+ c #40395A", -"!+ c #ECECEC", -"~+ c #B4B5B5", -"{+ c #313232", -"]+ c #E3E3E3", -"^+ c #B1AEBC", -"/+ c #BDBBC6", -"(+ c #3C3556", -"_+ c #898599", -":+ c #EDEDED", -"<+ c #39393A", -"[+ c #333333", -"}+ c #F5F5F5", -"|+ c #2B2B2B", -"1+ c #2D2A3D", -"2+ c #B6B4C1", -"3+ c #F5F5F6", -"4+ c #605A76", -"5+ c #DAD8DF", -"6+ c #F5F4F6", -"7+ c #615B76", -"8+ c #524D6A", -"9+ c #E4E3E8", -"0+ c #D5D5D5", -"a+ c #1B1B1B", -"b+ c #303030", -"c+ c #AAABAB", -"d+ c #585464", -"e+ c #B0AEBB", -"f+ c #A29FAF", -"g+ c #E9E8E9", -"h+ c #787779", -"i+ c #2D2D2E", -"j+ c #595959", -"k+ c #FAFAFB", -"l+ c #807B92", -"m+ c #B0ADBB", -"n+ c #E8E7EB", -"o+ c #3A3258", -"p+ c #E6E5EA", -"q+ c #DFDEE3", -"r+ c #443E5E", -"s+ c #BAB8C4", -"t+ c #C1BFCA", -"u+ c #E0E0E5", -"v+ c #D0CED6", -"w+ c #362F52", -"x+ c #CECCD5", -"y+ c #413A5B", -"z+ c #6A657F", -"A+ c #9793A6", -" ", -" ", -" ", -" . + @ # $ % ", -" & * = * - ; > , ' ; ; ; ) ! ", -" ~ ; ; { ] ; ^ / ( _ ; : < [ ", -" } | 1 2 3 4 5 6 6 7 : 8 9 0 a b ", -" c : d e f g h i j k l 6 6 ; m n o p q r s ", -" t u ; v w 6 6 x y z A B 6 C ; D E o F G ; H ", -" I J ; ; K L 6 6 6 M N O 6 6 P 6 6 6 6 Q R S T U V ", -" W X ; ; ; ; Y Z 6 6 6 6 6 6 6 P 6 6 6 6 ` ...+.@.#. ", -" $.; ; ; ; ; ; = %.&.6 6 6 6 6 P 6 6 6 6 6 *.=.; ; -. ", -" ;.; ; >.Q h ,.'.).6 6 6 6 6 6 P 6 6 6 6 6 6 !.~.4 {. ", -" ].^.; /.6 6 6 6 6 6 6 6 6 6 6 6 (.(.6 6 6 6 6 6 _.:. ", -" U @ <.[.6 6 6 6 6 6 6 6 6 6 }.(.}.6 (.6 6 6 6 6 ", -" |.1.2.6 6 6 6 6 6 6 6 6 6 (.6 P 6 6 (.6 6 6 6 3. ", -" 4.; ; 5.6.6.7.8.6.6 6 6 6 6 (.6 P 6 6 (.6 6 6 6 6 ", -" 9.; ; 0.a.; ; ; P P P P P P (.P P P P (.P P P 6 6 ", -" b.; ; ; ; c.; ; d.6 6 6 6 6 (.6 P 6 6 6 (.6 6 (.6 e., ", -" f.; ; c.; : g.h.6 6 6 6 6 (.6 6 P 6 6 6 (.6 (.6 i.c.j.k. ", -" l.; ; ; m.n.6 6 6 6 6 6 6 (.6 6 P 6 6 6 6 (.}.6 o.; ; p.q. ", -" r.J ; : s.6 6 6 6 t.6 6 (.}.6 6 P 6 6 6 6 6 6 6 u.v.; ; w.x. ", -" y.; ; z.6 6 6 6 A.(.(.6 6 6 6 P 6 6 6 6 6 6 6 6 B.C.; ; > x. ", -" D.; E.F.6 6 6 G.c.; H.6 6 6 6 6 6 6 6 6 6 6 6 6 6 I.J.; ; K.L. ", -" x.M.! N.O.6 x ; ; P.Q.R.S.l T.6 6 6 U.V.W.X.6 6 6 6 Y.Z.; ; `.@ ", -" +.+++@+#+$+; %+&+*+; v.T.6 6 6 =+; ; -+6 6 6 6 6 ;+; ; = >+ ", -" ,+> ; ; ; ; ; ; '+)+; ; !+7.6 6 6 D ; ; ~+6 6 6 6 {+]+; ; ^+ ", -" > ; ; ; ; /+(+_+; ; :+<+6 6 6 [+; ; }+|+6 6 1+2+; 3+3 ", -" 4+5+= ; 6+7+8+9+; ; 0+a+6 6 6 b+; ; ; c+=+d+ ", -" e+4 f+ W ; ; ; g+h+b+6 i+j+; ; ; c.k+l+ ", -" m+; ; ; ; ; n+o+p+; ; ; ; = q+r+ ", -" s+t+u+4 ; ; v+w+x+; ; ; s _+S ", -" y+ z+A+_+ ", -" ", -" ", -" "}; diff --git a/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPlugin.C b/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPlugin.C index 2797fc3..63d3e4f 100644 --- a/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPlugin.C +++ b/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPlugin.C @@ -1,4 +1,4 @@ -/* WaveShaper Plugin Copyleft (C) 2001 Yves Usson +/* WaveShaper Plugin Copyleft (C) 2001 Yves Usson * for SpiralSynthModular * Copyleft (C) 2001 David Griffiths * @@ -15,190 +15,176 @@ * 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 "WaveShaperPlugin.h" #include "WaveShaperPluginGUI.h" -#include -#include "WaveShaperIcon.xpm" +#include "SpiralIcon.xpm" extern "C" { -SpiralPlugin* CreateInstance() -{ - return new WaveShaperPlugin; -} -char** GetIcon() -{ - return WaveShaperIcon_xpm; +SpiralPlugin* CreateInstance() { + return new WaveShaperPlugin; } -int GetID() -{ - return 0x0032; -} +char** GetIcon() { + return SpiralIcon_xpm; } -/////////////////////////////////////////////////////// - -WaveShaperPlugin::WaveShaperPlugin() -{ - m_PluginInfo.Name="WaveShaper"; - m_PluginInfo.Width=278; - m_PluginInfo.Height=260; - m_PluginInfo.NumInputs=1; - m_PluginInfo.NumOutputs=1; - m_PluginInfo.PortTips.push_back("Input"); - m_PluginInfo.PortTips.push_back("Out"); - wt = new float[512]; - for (int i=0;i<512;i++) wt[i] = (i / 256.0 - 1.0); - m_Wave = 1; - for (int i=0;i<6;i++) m_Coefs[i] = 0.0; - m_Coefs[0] = 1.0; -} - -WaveShaperPlugin::~WaveShaperPlugin() -{ - delete [] wt; -} - -PluginInfo &WaveShaperPlugin::Initialise(const HostInfo *Host) -{ - PluginInfo& Info = SpiralPlugin::Initialise(Host); - Calc(); - return Info; -} - -SpiralGUIType *WaveShaperPlugin::CreateGUI() -{ - m_GUI = new WaveShaperPluginGUI(m_PluginInfo.Width, - m_PluginInfo.Height, - this,m_HostInfo); - m_GUI->hide(); - return m_GUI; -} - -void WaveShaperPlugin::Execute() -{ - float k1,k2; - if (!InputExists(0)) return; - for (int i=0;iBUFSIZE;i++) - { - float v = GetInput(0,i); - int index = (short)(256.0*v)+256; - // short rm = v - ((index-256)*(long)SpiralInfo::MAXSAMPLE)/256; - if (index<0) index=0; - if (index>511) index=511; - // k1 = rm / (SpiralInfo::MAXSAMPLE/256.0); - // v = (short)(k1*(wt[index]-wt[index+1])+wt[index+1]); - SetOutput(0,i,wt[index]); - } -} - -void WaveShaperPlugin::Calc(void) - -{ -int i; -float xx,x,y,max; - - if (m_Wave) - { - max = 1.0; - for (i=0;i<512;i++) - { - x = i / 256.0 - 1.0; - y = 0; - xx = x; - for (int j=1; j<7; j++) - { - y += m_Coefs[j-1] * xx; - xx *= x; - } - y = fabs(y); - max = max > y? max:y; - } - for (i=0;i<512;i++) - { - x = i / 256.0 - 1.0; - y = 0; - xx = x; - for (int j=1; j<7; j++) - { - y += m_Coefs[j-1] * xx; - xx *= x; - } - y /= max; - set(i,y); - } - } - else - { - max = 1.0; - for (i=0;i<512;i++) - { - x = (i / 256.0 - 1.0)*M_PI; - y = 0; - for (int j=1; j<7; j++) - y += m_Coefs[j-1] * sin(x*(1+(j-1)*3)); - y = fabs(y); - max = max > y? max:y; - } - for (i=0;i<512;i++) - { - x = (i / 256.0 - 1.0)*M_PI; - y = 0; - for (int j=1; j<7; j++) - y += m_Coefs[j-1] * sin(x*(1+(j-1)*3)); - y /= max; - set(i,y); - } - } -} - -float WaveShaperPlugin::Get(int index) - -{ - if ((index < 0) || (index > 511)) return 0; - return wt[index]; -} - -void WaveShaperPlugin::set(int index,float v) - -{ - if ((index < 0) || (index > 511)) return; - if (v > 1.0f) v = 1.0f; - if (v < -1.0f) v = -1.0f; - wt[index] = v; +int GetID() { + return 0x0032; } -void WaveShaperPlugin::SetCoef(int index,float v){ - if ((index < 0) || (index > 5)) return; - m_Coefs[index] = v; } -void WaveShaperPlugin::SetWaveType(int t){ - m_Wave = t; -} +/////////////////////////////////////////////////////// -float WaveShaperPlugin::GetCoef(int index){ +WaveShaperPlugin::WaveShaperPlugin () { + int i; + m_PluginInfo.Name = "WaveShaper"; + m_PluginInfo.Width = 278; + m_PluginInfo.Height = 260; + m_PluginInfo.NumInputs = 1; + m_PluginInfo.NumOutputs = 1; + m_PluginInfo.PortTips.push_back ("Input"); + m_PluginInfo.PortTips.push_back ("Out"); + m_wt = new float[512]; + for (i=0; i<512; i++) m_wt[i] = (i / 256.0 - 1.0); + m_GUIArgs.FuncPlot = new float[256]; + for (i=0; i<256; i++) m_GUIArgs.FuncPlot[i] = m_wt[i*2]; + m_Wave = 1; + for (i=0; i<6; i++) m_Coefs[i] = 0.0; + m_Coefs[0] = 1.0; + m_AudioCH->Register ("WaveType", &m_GUIArgs.WaveType); + m_AudioCH->Register ("CoefNum", &m_GUIArgs.CoefNum); + m_AudioCH->Register ("CoefVal", &m_GUIArgs.CoefVal); + m_AudioCH->RegisterData ("WT", ChannelHandler::OUTPUT, m_GUIArgs.FuncPlot, 256 * sizeof (float)); +} + +WaveShaperPlugin::~WaveShaperPlugin() { + delete [] m_GUIArgs.FuncPlot; + delete [] m_wt; +} + +PluginInfo &WaveShaperPlugin::Initialise (const HostInfo *Host) { + PluginInfo& Info = SpiralPlugin::Initialise (Host); + calc(); + return Info; +} + +SpiralGUIType *WaveShaperPlugin::CreateGUI () { + return new WaveShaperPluginGUI (m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo); +} + +void WaveShaperPlugin::ExecuteCommands () { + if (m_AudioCH->IsCommandWaiting ()) { + switch (m_AudioCH->GetCommand ()) { + case (SETWAVETYPE) : + m_Wave = m_GUIArgs.WaveType; + calc (); + break; + case (SETCOEF) : + if ((m_GUIArgs.CoefNum < 0) || (m_GUIArgs.CoefNum > 5)) break; + m_Coefs[m_GUIArgs.CoefNum] = m_GUIArgs.CoefVal; + calc (); + break; + } + } +} + +void WaveShaperPlugin::Execute () { + float k1, k2; + if (!InputExists (0)) return; + for (int i=0; iBUFSIZE; i++) { + float v = GetInput (0, i); + int index = (short)(256.0*v) + 256; + // short rm = v - ((index-256)*(long)SpiralInfo::MAXSAMPLE)/256; + if (index < 0) index = 0; + if (index > 511) index = 511; + // k1 = rm / (SpiralInfo::MAXSAMPLE/256.0); + // v = (short)(k1*(wt[index]-wt[index+1])+wt[index+1]); + SetOutput (0, i, m_wt[index]); + } +} + +// Functions used by GUI.UpdateValues + +float WaveShaperPlugin::GetCoef (int index) { if ((index < 0) || (index > 5)) return 0; - return m_Coefs[index]; + return m_Coefs[index]; } int WaveShaperPlugin::GetWaveType(){ return m_Wave; } -void WaveShaperPlugin::StreamOut(ostream &s) -{ - s<>version>>m_Wave; - for (int i=0;i<6;i++) s>>m_Coefs[i]; - Calc(); +void WaveShaperPlugin::set (int index, float v) { + if ((index < 0) || (index > 511)) return; + if (v > 1.0f) v = 1.0f; + if (v < -1.0f) v = -1.0f; + m_wt[index] = v; +} + +void WaveShaperPlugin::calc (void) { + int i; + float xx,x,y,max; + if (m_Wave) { + max = 1.0; + for (i=0; i<512; i++) { + x = i / 256.0 - 1.0; + y = 0; + xx = x; + for (int j=1; j<7; j++) { + y += m_Coefs[j-1] * xx; + xx *= x; + } + y = fabs(y); + max = max > y? max:y; + } + for (i=0; i<512; i++) { + x = i / 256.0 - 1.0; + y = 0; + xx = x; + for (int j=1; j<7; j++) { + y += m_Coefs[j-1] * xx; + xx *= x; + } + y /= max; + set (i, y); + } + } + else { + max = 1.0; + for (i=0; i<512; i++) { + x = (i / 256.0 - 1.0)*M_PI; + y = 0; + for (int j=1; j<7; j++) y += m_Coefs[j-1] * sin(x*(1+(j-1)*3)); + y = fabs(y); + max = max > y? max:y; + } + for (i=0; i<512; i++) { + x = (i / 256.0 - 1.0)*M_PI; + y = 0; + for (int j=1; j<7; j++) y += m_Coefs[j-1] * sin(x*(1+(j-1)*3)); + y /= max; + set(i, y); + } + } + for (i=0; i<256; i++) m_GUIArgs.FuncPlot[i] = m_wt[i*2]; +} + +// Streaming + +void WaveShaperPlugin::StreamOut (ostream &s) { + s << m_Version << " " << m_Wave; + for (int i=0; i<6; i++) s << " " << m_Coefs[i]; +} + +void WaveShaperPlugin::StreamIn (istream &s) { + int version; + s >> version >> m_Wave; + for (int i=0; i<6; i++) s >> m_Coefs[i]; + calc (); } diff --git a/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPlugin.h b/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPlugin.h index c082d2e..c393648 100644 --- a/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPlugin.h +++ b/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPlugin.h @@ -1,4 +1,4 @@ -/* WaveShaper Plugin Copyleft (C) 2001 Yves Usson +/* WaveShaper Plugin Copyleft (C) 2001 Yves Usson * for SpiralSynthModular * Copyleft (C) 2001 David Griffiths * @@ -15,7 +15,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 @@ -23,37 +23,34 @@ #ifndef WaveShaperPLUGIN #define WaveShaperPLUGIN -class WaveShaperPlugin : public SpiralPlugin -{ -public: - WaveShaperPlugin(); - virtual ~WaveShaperPlugin(); - - virtual PluginInfo& Initialise(const HostInfo *Host); - virtual SpiralGUIType* CreateGUI(); - virtual void Execute(); - virtual void StreamOut(ostream &s); - virtual void StreamIn(istream &s); - - // has to be defined in the plugin - virtual void UpdateGUI() { Fl::check(); } - - void Calc(void); - float Get(int); - void SetCoef(int,float); - void SetWaveType(int); - float GetCoef(int); - int GetWaveType(void); -private: - float *wt; - float m_Coefs[6]; - int m_Wave; - void set(int,float); - friend istream &operator>>(istream &s, WaveShaperPlugin &o); - friend ostream &operator<<(ostream &s, WaveShaperPlugin &o); +class WaveShaperPlugin : public SpiralPlugin { + public: + WaveShaperPlugin(); + virtual ~WaveShaperPlugin (); + virtual PluginInfo& Initialise (const HostInfo *Host); + virtual SpiralGUIType* CreateGUI(); + virtual void Execute(); + virtual void ExecuteCommands(); + virtual void StreamOut(ostream &s); + virtual void StreamIn(istream &s); + float GetCoef(int); + int GetWaveType(void); + enum GUICommands { NONE, SETWAVETYPE, SETCOEF }; + struct GUIArgs { + int WaveType, CoefNum; + float CoefVal, *FuncPlot; + }; + private: + GUIArgs m_GUIArgs; + float *m_wt, m_Coefs[6]; + int m_Wave; + void calc (void); + void set (int index, float v); + friend istream &operator>> (istream &s, WaveShaperPlugin &o); + friend ostream &operator<< (ostream &s, WaveShaperPlugin &o); }; -istream &operator>>(istream &s, WaveShaperPlugin &o); -ostream &operator<<(ostream &s, WaveShaperPlugin &o); +istream &operator>> (istream &s, WaveShaperPlugin &o); +ostream &operator<< (ostream &s, WaveShaperPlugin &o); #endif diff --git a/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPlugin.pro b/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPlugin.pro deleted file mode 100644 index e1e7a88..0000000 --- a/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPlugin.pro +++ /dev/null @@ -1,17 +0,0 @@ -HEADERS = ../SpiralPlugin.h \ - ../SpiralPluginGUI.h \ - ../Widgets/Fl_Knob.H \ - ../Widgets/Fl_DragBar.H \ - ../../Sample.h \ - WaveShaperPlugin.h \ - WaveShaperPluginGUI.h - -SOURCES = ../SpiralPlugin.C \ - ../SpiralPluginGUI.C \ - ../Widgets/Fl_Knob.cxx \ - ../Widgets/Fl_DragBar.cxx \ - ../../Sample.C \ - WaveShaperPlugin.C \ - WaveShaperPluginGUI.C - -TARGET = WaveShaperPlugin.so diff --git a/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPluginGUI.C b/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPluginGUI.C index 8e7938b..4572807 100644 --- a/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPluginGUI.C +++ b/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPluginGUI.C @@ -1,4 +1,4 @@ -/* WaveShaper Plugin Copyleft (C) 2001 Yves Usson +/* WaveShaper Plugin Copyleft (C) 2001 Yves Usson * for SpiralSynthModular / * Copyleft (C) 2000 David Griffiths * @@ -15,7 +15,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 "WaveShaperPluginGUI.h" #include @@ -24,7 +24,8 @@ static const int GUI_COLOUR = 179; static const int GUIBG_COLOUR = 144; static const int GUIBG2_COLOUR = 145; -FunctionPlot::FunctionPlot(int ox,int oy,int ww,int hh): Fl_Widget(ox,oy,ww,hh) { + +FunctionPlot::FunctionPlot(int ox, int oy, int ww, int hh) : Fl_Widget (ox, oy, ww, hh) { fval = new float[256]; for (int i=0;i<256;i++) fval[i] = i / 128.0 - 1.0; } @@ -34,14 +35,14 @@ FunctionPlot::~FunctionPlot() { } void FunctionPlot::draw() { - int ox = x() + 3; -int oy = y() +3; -int ww = w() - 6; -int hh = h() - 6; -float coefx,coefy; - - draw_box(); - fl_clip(ox,oy,ww,hh); + int ox = x() + 3; + int oy = y() +3; + int ww = w() - 6; + int hh = h() - 6; + float coefx,coefy; + + draw_box(); + fl_clip(ox,oy,ww,hh); coefx = ww / 256.0; coefy = hh / 2.0; for (int i = -5; i < 5; i++) @@ -70,13 +71,13 @@ int FunctionPlot::handle(int event) { return 0; } -void FunctionPlot::set(const int index,const float v) { +void FunctionPlot::set(const int index, const float v) { if ((index < 0) || (index > 255)) return; fval[index] = v; if (fval[index] > 1.0f) fval[index] = 1.0f; if (fval[index] < -1.0f) fval[index] = -1.0f; } - + float FunctionPlot::get(const int index) const { if ((index < 0) || (index > 255)) return (-10.0f); return fval[index]; @@ -85,100 +86,107 @@ float FunctionPlot::get(const int index) const { //////////////////////////////////////////// -WaveShaperPluginGUI::WaveShaperPluginGUI(int w, int h,WaveShaperPlugin *o,const HostInfo *Info) : -SpiralPluginGUI(w,h,o) -{ - m_Plugin=o; - fplot = new FunctionPlot(3, 20, 268, 195); - fplot->box(FL_ENGRAVED_BOX); - fplot->color(7); - - radio_polynomial = new Fl_Round_Button(3, 218, 30, 20, "S"); - radio_polynomial->down_box(FL_ROUND_DOWN_BOX); - radio_polynomial->value(1); - radio_polynomial->type(102); - radio_polynomial->labelfont(12); - radio_polynomial->labelsize(12); - radio_polynomial->callback((Fl_Callback*)cb_radio); - - radio_sines = new Fl_Round_Button(3, 238, 30, 20, "S"); - radio_sines->down_box(FL_ROUND_DOWN_BOX); - radio_sines->value(0); - radio_sines->type(102); - radio_sines->labelfont(12); - radio_sines->labelsize(12); - radio_sines->callback((Fl_Callback*)cb_radio); - - { Fl_Box* o = new Fl_Box(26, 218, 25, 20, "a .x"); - o->labelfont(2); - o->labelsize(10); - } - { Fl_Box* o = new Fl_Box(33, 227, 10, 15, "i"); - o->labelfont(2); - o->labelsize(10); - } - { Fl_Box* o = new Fl_Box(47, 217, 10, 15, "i"); - o->labelfont(2); - o->labelsize(10); - } - { Fl_Box* o = new Fl_Box(31, 246, 10, 15, "i"); - o->labelfont(2); - o->labelsize(10); - } - { Fl_Box* o = new Fl_Box(36, 237, 25, 20, "a .sin i x"); - o->labelfont(2); - o->labelsize(10); - } - - for (int i=0;i<6;i++) - { - knob[i] = new Fl_Knob(70+i*35, 220, 30, 30); - knob[i]->labelsize(10); - knob[i]->minimum(-1); - knob[i]->step(0.01); - knob[i]->value(0); - knob[i]->color(GUI_COLOUR); - knob[i]->callback((Fl_Callback*)cb_knob); - knob[i]->type(Fl_Knob::DOTLIN); - } - knob[0]->value(1.0); - end(); +WaveShaperPluginGUI::WaveShaperPluginGUI (int w, int h, WaveShaperPlugin *o, ChannelHandler *ch, const HostInfo *Info) : +SpiralPluginGUI(w, h, o, ch) +{ + fplot = new FunctionPlot(3, 20, 268, 195); + fplot->box(FL_ENGRAVED_BOX); + fplot->color(7); + + radio_polynomial = new Fl_Round_Button(3, 218, 30, 20, "S"); + radio_polynomial->down_box(FL_ROUND_DOWN_BOX); + radio_polynomial->value(1); + radio_polynomial->type(102); + radio_polynomial->labelfont(12); + radio_polynomial->labelsize(12); + radio_polynomial->callback((Fl_Callback*)cb_radio); + + radio_sines = new Fl_Round_Button(3, 238, 30, 20, "S"); + radio_sines->down_box(FL_ROUND_DOWN_BOX); + radio_sines->value(0); + radio_sines->type(102); + radio_sines->labelfont(12); + radio_sines->labelsize(12); + radio_sines->callback((Fl_Callback*)cb_radio); + + { Fl_Box* o = new Fl_Box(26, 218, 25, 20, "a .x"); + o->labelfont(2); + o->labelsize(10); + } + { Fl_Box* o = new Fl_Box(33, 227, 10, 15, "i"); + o->labelfont(2); + o->labelsize(10); + } + { Fl_Box* o = new Fl_Box(47, 217, 10, 15, "i"); + o->labelfont(2); + o->labelsize(10); + } + { Fl_Box* o = new Fl_Box(31, 246, 10, 15, "i"); + o->labelfont(2); + o->labelsize(10); + } + { Fl_Box* o = new Fl_Box(36, 237, 25, 20, "a .sin i x"); + o->labelfont(2); + o->labelsize(10); + } + + for (int i=0; i<6; i++) { + knob[i] = new Fl_Knob (70+i*35, 220, 30, 30, ""); + knob[i]->color (GUI_COLOUR); + knob[i]->type (Fl_Knob::DOTLIN); + knob[i]->labelsize (10); + knob[i]->maximum (1); + knob[i]->minimum (-1); + knob[i]->step (0.01); + knob[i]->value (0); + knob[i]->callback ((Fl_Callback*)cb_knob); + } + knob[0]->value(1.0); + end(); } +void WaveShaperPluginGUI::UpdateValues (SpiralPlugin *o) { + WaveShaperPlugin* Plugin = (WaveShaperPlugin*) o; + int wt = Plugin->GetWaveType (); + radio_polynomial->value (wt); + radio_sines->value (!wt); + for (int j=0; j<6; j++) knob[j]->value (Plugin->GetCoef (j)); + Update (); +} - -void WaveShaperPluginGUI::UpdateValues() -{ - int wt = m_Plugin->GetWaveType(); - radio_polynomial->value(wt); - radio_sines->value(!wt); - for (int j=0; j<6; j++) knob[j]->value(m_Plugin->GetCoef(j)); - knobCB(); +void WaveShaperPluginGUI::Update () { + // Formerly KnobCB + float WTData[256]; + m_GUICH->GetData ("WT", (void*)WTData); + for (int i=0; i<256; i++) fplot->set (i, WTData[i]); + fplot->redraw (); } -inline void WaveShaperPluginGUI::cb_radio_i(Fl_Round_Button*, void*) { - m_Plugin->SetWaveType(radio_polynomial->value()); - knobCB(); +inline void WaveShaperPluginGUI::cb_radio_i (Fl_Round_Button*, void*) { + m_GUICH->Set ("WaveType", (int)radio_polynomial->value ()); + m_GUICH->SetCommand (WaveShaperPlugin::SETWAVETYPE); } -void WaveShaperPluginGUI::cb_radio(Fl_Round_Button* o, void* v) { - ((WaveShaperPluginGUI*)(o->parent()))->cb_radio_i(o,v); + +void WaveShaperPluginGUI::cb_radio (Fl_Round_Button* o, void* v) { + ((WaveShaperPluginGUI*)(o->parent()))->cb_radio_i (o, v); } -inline void WaveShaperPluginGUI::cb_knob_i(Fl_Knob*, void*) { - for (int j=0; j<6; j++) m_Plugin->SetCoef(j,knob[j]->value()); - knobCB(); +inline void WaveShaperPluginGUI::cb_knob_i (Fl_Knob* o, void* v) { + for (int j=0; j<6; j++) { + if (o==knob[j]) { + m_GUICH->Set ("CoefNum", j); + m_GUICH->Set ("CoefVal", (float)knob[j]->value ()); + m_GUICH->SetCommand (WaveShaperPlugin::SETCOEF); + break; + } + } } -void WaveShaperPluginGUI::cb_knob(Fl_Knob* o, void* v) { - ((WaveShaperPluginGUI*)(o->parent()))->cb_knob_i(o,v); +void WaveShaperPluginGUI::cb_knob (Fl_Knob* o, void* v) { + ((WaveShaperPluginGUI*)(o->parent()))->cb_knob_i (o, v); } -void WaveShaperPluginGUI::knobCB() { -int i; - - m_Plugin->Calc(); - for (i=0;i<256;i++) - { - fplot->set(i,m_Plugin->Get(i*2)); - } - fplot->redraw(); +const string WaveShaperPluginGUI::GetHelpText(const string &loc){ + return string("") + + "This plugin simulates wave shaping as found on analogue\n" + + "synths, usable in two modes, linear or sine based.\n"; } diff --git a/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPluginGUI.h b/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPluginGUI.h index 269cd18..d8cb572 100644 --- a/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPluginGUI.h +++ b/SpiralSound/Plugins/WaveShaperPlugin/WaveShaperPluginGUI.h @@ -1,4 +1,4 @@ -/* WaveShaper Plugin Copyleft (C) 2001 Yves Usson +/* WaveShaper Plugin Copyleft (C) 2001 Yves Usson * for SpiralSynthModular * Copyleft (C) 2000 David Griffiths * @@ -15,7 +15,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 #include @@ -33,39 +33,35 @@ #define WaveShaperGUI class FunctionPlot : public Fl_Widget { -public: - FunctionPlot(int ox,int oy,int ww,int hh); - ~FunctionPlot(); -private: - float *fval; - void draw(); - int handle(int event); -public: - void set(const int index,const float v); - float get(const int index) const; + public: + FunctionPlot (int ox, int oy, int ww, int hh); + ~FunctionPlot (); + private: + float *fval; + void draw (); + int handle (int event); + public: + void set (const int index, const float v); + float get (const int index) const; }; -class WaveShaperPluginGUI : public SpiralPluginGUI -{ -public: - WaveShaperPluginGUI(int w, int h, WaveShaperPlugin *o,const HostInfo *Info); - - virtual void UpdateValues(); - virtual SpiralPlugin* GetPlugin() { return m_Plugin; } - - WaveShaperPlugin *m_Plugin; -private: - FunctionPlot *fplot; - Fl_Round_Button *radio_polynomial; - Fl_Round_Button *radio_sines; - Fl_Knob *knob[6]; - - //// Callbacks //// - inline void cb_radio_i(Fl_Round_Button*, void*); - static void cb_radio(Fl_Round_Button* o, void* v); - inline void cb_knob_i(Fl_Knob*, void*); - static void cb_knob(Fl_Knob* o, void* v); - void knobCB(); +class WaveShaperPluginGUI : public SpiralPluginGUI { + public: + WaveShaperPluginGUI (int w, int h, WaveShaperPlugin *o, ChannelHandler *ch, const HostInfo *Info); + virtual void UpdateValues (SpiralPlugin *o); + virtual void Update (); + protected: + const string GetHelpText (const string &loc); + private: + FunctionPlot *fplot; + Fl_Round_Button *radio_polynomial; + Fl_Round_Button *radio_sines; + Fl_Knob *knob[6]; + //// Callbacks //// + inline void cb_radio_i (Fl_Round_Button*, void*); + static void cb_radio (Fl_Round_Button* o, void* v); + inline void cb_knob_i (Fl_Knob*, void*); + static void cb_knob (Fl_Knob* o, void* v); }; #endif