/* Sound Environment Client - DMS - dec 97 - by Sébastien Metrot */ /* Rev. 1.0 - Mar. '98 - by Marc Barilley */ /* Rev. 1.1 - Sep. '98 - by Marc Barilley */ /* Rev. 1.2 - Jan. '99 - by Patrice FAVRE */ defcom cStarted = started;; var ONCE = 0;; var LOOP_ON_ALL = 1;; var LOOP = 2;; var RANDOM = 3;; var enable=1;; var mode=0;; typeof nbloop = I;; typeof soundlist = [[S Multi] r1];; /* [name file] */ typeof playinglist = [[S Multi] r1];; /* [name file] */ typeof todo = S;; proto activate = fun [DMI S S S] I;; fun listcat (l1, l2)= if l1==nil then l2 else let l1 -> [val nxt] in val::(listcat nxt l2);; fun soundByName (sound, name)= let sound -> [n _] in !strcmp n name;; fun _downloaded (file, name)= if file==nil then nil else let _CRmulti _channel DMSwin 0 0 0 0 _checkpack file nil -> multi in let _GETmultiXYsource multi -> [xmsource ymsource wmsource hmsource] in if (xmsource==0) && (ymsource==0) && (wmsource==0) && (hmsource==0) then { set soundlist = listcat soundlist [name multi]::nil; if todo==nil then nil else activate nil todo nil nil; } else nil; 0;; fun __newSound (name, file)= _RSCdownload this file file mknode @_downloaded name 1;; fun random ()= if (sizelist soundlist) < 2 then nil else let mod rand sizelist soundlist -> pos in if (hd endlist soundlist pos) != hd playinglist then pos else random;; proto reflex = fun [Multi I I] Multi;; fun reflex (multi, mode, newstate)= if enable then if newstate == MEDIA_MODE_STOP then { let hd playinglist -> [name multi] in { _DMSevent this name nil nil; _DMSevent this "stopped" name nil }; if mode == ONCE then nil else if mode == LOOP_ON_ALL then { set playinglist = tl playinglist; if playinglist==nil then { if nbloop!=nil && nbloop>0 then set nbloop=nbloop-1 else nil; if nbloop==nil || nbloop>0 then set playinglist=soundlist else nil } else nil; if playinglist!=nil then let hd playinglist -> [name multi] in { _SETmultiReflexMode multi @reflex LOOP_ON_ALL; _PLAYmulti multi } else nil } else if mode == LOOP then { if nbloop!=nil && nbloop>0 then set nbloop=nbloop-1 else nil; if nbloop==nil || nbloop>0 then let hd playinglist -> [name multi] in _PLAYmulti multi else nil } else if mode == RANDOM then let random -> pos in if pos==nil then nil else { set playinglist = endlist soundlist pos; let hd playinglist -> [name multi] in { _SETmultiReflexMode multi @reflex RANDOM; _PLAYmulti multi } } else nil } else nil else nil;; fun activate (from, action, param, reply)= if !strcmp action "destroy" then { _DMSdelete this; nil } else if !strcmp action "stopSound" then let hd playinglist -> [name multi] in { _SETmultiReflexMode multi nil 0; _PAUSEmulti multi; _DMSevent this "stopped" name nil; _SETmultiHome multi; } else if !strcmp action "playSound" then if enable then if playinglist==nil then if soundlist==nil then { set todo = action; nil } else { set playinglist = soundlist; let hd playinglist -> [name multi] in { _SETmultiReflexMode multi @reflex mode; _PLAYmulti multi; } } else let hd playinglist -> [name multi] in { _SETmultiReflexMode multi @reflex mode; _PLAYmulti multi; } else nil else if !strcmp action "once" then let hd playinglist -> [name multi] in _SETmultiReflexMode multi @reflex set mode = ONCE else if !strcmp action "loopOnAll" then { set nbloop=atoi param; let hd playinglist -> [name multi] in _SETmultiReflexMode multi @reflex set mode = LOOP_ON_ALL } else if !strcmp action "loop" then { set nbloop=atoi param; let hd playinglist -> [name multi] in _SETmultiReflexMode multi @reflex set mode = LOOP } else if !strcmp action "random" then let hd playinglist -> [name multi] in _SETmultiReflexMode multi @reflex set mode = RANDOM else if !strcmp action "disable" then { set enable = 0; nil } else if !strcmp action "enable" then { set enable = 1; nil } else if enable then let search_in_list soundlist @soundByName action -> sound in if sound==nil then { set todo = action; nil } else { set todo = nil; set playinglist = endlist soundlist (pos_in_list soundlist sound 0); if playinglist==nil then set playinglist=soundlist else nil; let sound -> [name multi] in { _SETmultiReflexMode multi @reflex mode; _PLAYmulti multi; } } else nil; 0;; fun IniDMI (param)= srand time; _DMSregisterDMI this @activate nil; _DMSevent this "in" nil nil; _DMSsend this cStarted [];; /* comm - provided for backward compatibility */ fun __enbale (i)= set enable=i;; fun __stopMidi()= activate nil "stopSound" nil nil;; fun __startMidi()= activate nil "playSound" nil nil;; fun __stopAll ()= activate nil "stopSound" nil nil;; fun __play (name)= activate nil name nil nil;; /* end comm */