/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser 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, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct PlugSignal = [ SIG_fWaveform : I, SIG_fAmplitude : F, SIG_iPeriod : I, SIG_iOutputRate : I, SIG_fOffset : F, SIG_iTickUpdate : I ]mkPlugSignal;; fun deleteOb(inst)= 0;; fun cbControlPreRender(inst, sessionstr, etime, obstr)= let _tickcount -> curtick in if (obstr.SIG_iTickUpdate == nil || (curtick - obstr.SIG_iTickUpdate) >= (1000 / obstr.SIG_iOutputRate)) then ( let (itof (mod curtick obstr.SIG_iPeriod)) /. (itof obstr.SIG_iPeriod) -> periodratio in if (obstr.SIG_fWaveform == 0) then // Sine ( let sin ((2.0 *. PIf) *. periodratio) -> value in SendPluginEvent inst "Value" (ftoa ((value *. obstr.SIG_fAmplitude) +. obstr.SIG_fOffset)) nil; 0; ) else if (obstr.SIG_fWaveform == 1) then // Square ( let if (periodratio <. 0.5) then 1.0 else -.1.0 -> value in SendPluginEvent inst "Value" (ftoa ((value *. obstr.SIG_fAmplitude) +. obstr.SIG_fOffset)) nil; 0; ) else if (obstr.SIG_fWaveform == 2) then // Triangle ( let if (periodratio <. 0.5) then (-.periodratio) *. 4.0 +. 1.0 else periodratio *. 4.0 -. 3.0 -> value in SendPluginEvent inst "Value" (ftoa ((value *. obstr.SIG_fAmplitude) +. obstr.SIG_fOffset)) nil; 0; ) else if (obstr.SIG_fWaveform == 3) then // Sawtooth ( let periodratio *. 2.0 -. 1.0 -> value in SendPluginEvent inst "Value" (ftoa ((value *. obstr.SIG_fAmplitude) +. obstr.SIG_fOffset)) nil; 0; ) else nil; set obstr.SIG_iTickUpdate = curtick; ); 0;; fun cbStart(inst, from, action, param, rep, obstr)= setPluginInstanceCbScenePreRender inst mkfun4 @cbControlPreRender obstr; 0;; fun cbStop(inst, from, action, param, rep, obstr)= setPluginInstanceCbScenePreRender inst nil; 0;; fun cbSetAmplitude(inst, from, action, param, rep, obstr)= if (param == nil) || (!strcmp "" (strtrim param)) then nil else set obstr.SIG_fAmplitude = atof param; 0;; fun cbSetPeriod(inst, from, action, param, rep, obstr)= if (param == nil) || (!strcmp "" (strtrim param)) then nil else set obstr.SIG_iPeriod = atoi param; 0;; fun newOb(inst)= let atoi (getPluginInstanceParam inst "waveform") -> waveform in let if (waveform == nil) then 0 else waveform -> waveform in let atof (getPluginInstanceParam inst "amplitude") -> amplitude in let if amplitude == nil then 1.0 else amplitude -> amplitude in let atoi (getPluginInstanceParam inst "period") -> period in let if period == nil then 2000 else period -> period in let atoi (getPluginInstanceParam inst "outputrate") -> outputrate in let if outputrate == nil then 60 else outputrate -> outputrate in let atof (getPluginInstanceParam inst "offset") -> offset in let if offset == nil then 0.0 else offset -> offset in let atoi (getPluginInstanceParam inst "init") -> init in let if (init == nil) then 1 else init -> init in let mkPlugSignal [waveform amplitude period outputrate offset nil] -> obstr in ( if (!init) then nil else cbStart inst nil nil nil nil obstr; PluginRegisterAction inst "Start" mkfun6 @cbStart obstr; PluginRegisterAction inst "Stop" mkfun6 @cbStop obstr; PluginRegisterAction inst "Set amplitude" mkfun6 @cbSetAmplitude obstr; PluginRegisterAction inst "Set period" mkfun6 @cbSetPeriod obstr; setPluginInstanceCbDel inst @deleteOb; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;