/* ----------------------------------------------------------------------------- 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 PlugInputMixerStr = [ PIMS_inst : PInstance, PIMS_sFormat : S, PIMS_iNbInputs : I, PIMS_lInputList : [[S I] r1], PIMS_iOutputMode : I, PIMS_iTimeInterval : I, PIMS_bAllInitialized : I, PIMS_iLastUpdate : I, PIMS_bEnabled : I ]mkPlugInputMixerStr;; fun deleteOb(inst, obstr)= 0;; fun cbGetFormatedOutput(inst, from, action, param, reply, obstr)= let obstr.PIMS_sFormat -> format in let 0 -> i in ( while (i < obstr.PIMS_iNbInputs) do ( let nth_list obstr.PIMS_lInputList i -> inputdata in ( let strcat "$" (ctoa (65 + i)) -> key in let inputdata -> [iparam _] in if (strfindi key format 0) == nil then nil else set format = replaceByKeyIndex2 format key iparam; mutate inputdata <- [_ 0]; ); set i = i + 1; ); set format = _DMSapplyLinkCode _DMSapplyByGlobalVar format; SendPluginEvent inst "Formated output" format nil; ); 0;; fun cbPreRender(inst, viewstr, obstr)= let _tickcount -> curtime in if (curtime - obstr.PIMS_iLastUpdate < obstr.PIMS_iTimeInterval) then nil else ( cbGetFormatedOutput inst nil nil nil nil obstr; set obstr.PIMS_iLastUpdate = curtime; ); 0;; fun cbEnable(inst, from, action, param, reply, obstr)= set obstr.PIMS_bEnabled = 1; if (obstr.PIMS_iOutputMode != 2) then nil else setPluginInstanceCbPreRender inst mkfun3 @cbPreRender obstr; 0;; fun cbDisable(inst, from, action, param, reply, obstr)= set obstr.PIMS_bEnabled = 0; setPluginInstanceCbPreRender inst nil; 0;; fun cbReset(inst, from, action, param, reply, obstr)= let sizelist obstr.PIMS_lInputList -> size in let 0 -> i in while (i < size) do ( let nth_list obstr.PIMS_lInputList i -> inputdata in mutate inputdata <- ["" 0]; set i = i + 1; ); set obstr.PIMS_bAllInitialized = 0; 0;; fun cbInput(inst, from, action, param, reply, obstr)= let if (param == nil) then "" else param -> param in ( let (nth_char action (strlen action) - 1) - 65 -> i in let nth_list obstr.PIMS_lInputList i -> inputdata in mutate inputdata <- [param 1]; if (!obstr.PIMS_bEnabled) || (obstr.PIMS_iOutputMode == 2) then nil else let 1 -> allupdated in ( let sizelist obstr.PIMS_lInputList -> size in let 0 -> i in while (i < size) do ( let nth_list obstr.PIMS_lInputList i -> [param updated] in if (updated != 0) then nil else set allupdated = 0; set i = i + 1; ); if (!allupdated) then nil else set obstr.PIMS_bAllInitialized = 1; if (!obstr.PIMS_bAllInitialized) || (obstr.PIMS_iOutputMode == 1 && !allupdated) then nil else cbGetFormatedOutput inst nil nil nil nil obstr; ); ); 0;; fun newOb(inst)= let atoi (getPluginInstanceParam inst "nbinputs") -> nbinputs in let if (nbinputs == nil) then 2 else nbinputs -> nbinputs in let getPluginInstanceParam inst "format" -> format in let if (format == nil) then "" else format -> format in let atoi (getPluginInstanceParam inst "outputmode") -> outputmode in let if (outputmode == nil) then 1 else outputmode -> outputmode in let atof (getPluginInstanceParam inst "timeinterval") -> timeinterval in let if (timeinterval == nil) then 1.0 else timeinterval -> timeinterval in let atoi (getPluginInstanceParam inst "init") -> init in let if (init == nil) then 1 else init -> init in let mkPlugInputMixerStr [inst format nbinputs nil outputmode (ftoi (timeinterval *. 1000.0)) 0 0 init] -> obstr in ( if (!init) then nil else cbEnable inst nil nil nil nil obstr; PluginRegisterAction inst "Enable" mkfun6 @cbEnable obstr; PluginRegisterAction inst "Disable" mkfun6 @cbDisable obstr; PluginRegisterAction inst "Reset" mkfun6 @cbReset obstr; PluginRegisterAction inst "Get formated output" mkfun6 @cbGetFormatedOutput obstr; while (nbinputs > 0) do ( set nbinputs = nbinputs - 1; PluginRegisterAction inst (strcat "Input " (ctoa (65 + nbinputs))) mkfun6 @cbInput obstr; set obstr.PIMS_lInputList = ["" 0]::obstr.PIMS_lInputList; ); setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;