home *** CD-ROM | disk | FTP | other *** search
- -- 2000.02.26
- -- Clive Green <clivegreen@atlas.co.uk>
-
- ------------------------------------------------------------------------------------------------------
-
- -- very rudimentary fxMembers manager:
-
- ------------------------------------------------------------------------------------------------------
-
- -- declare properties:
- property fxBindings -- a #propList of fx labels, each with a sound effect
-
- property fxLibName -- the name of the sound effects castlibrary
- property fxChannels -- a linear list of fx sound channel numbers to be used
-
- property fxMembers -- a #propList of fx member #names with castnumbers
- property fxChannelRegistry -- a #propList of sound channels with soundbusy flags
-
- ------------------------------------------------------------------------------------------------------
-
- on new me,L
-
- -- (1) extract and check arguments:
-
- -- check for a parameter list:
- if ilk(L) <> #propList then return ¬
- [#error:#noParamListSupplied, #msg:"soundFXservice:new"]
-
- -- a reference to the parent codebase is REQUIRED:
- main = L[#main]
-
- if (ilk(main) <> #instance) then return ¬
- [#error:#noMainObjectSupplied, #msg:"soundFXservice:new"]
-
- --------------------
-
- -- (2) obtain fx mapping data:
- dm = main.getDataManager()
- fxBindings = dm.getData([#set:#soundFX])
-
- --------------------
-
- -- (3) store literals:
-
- -- we're using sounds from which FX library?
- fxLibName = "soundFX"
-
- -- which sound channels are to be used for facilitating sound effects?
- fxChannels = [3,4,5,6,7,8]
-
- --------------------
-
- -- (4) compile a list of available fxMembers:
-
- -- locate required library:
- c = castlib(fxLibName).number
-
- if voidP(c) then return ¬
- [#error:#castlibMissing, #msg:fxLibName]
-
- -- compile a list of fx names with member numbers:
- fxMembers = [:]
- repeat with i = 1 to the number of members of castlib c
-
- n = member(i,c).number
-
- -- sound members only:
- if member(n).type <> #sound then next repeat
-
- -- store audio cast member number as a symbol:
- fxMembers[symbol(member(n).name)] = n
-
- end repeat
-
- --------------------
-
- -- (5) compile a registry of audio channel states:
- fxChannelRegistry = []
-
- repeat with i in fxChannels
-
- -- obtain the current state of each fx sound channel:
- add fxChannelRegistry,[#channel:i, #state:soundBusy(i)]
-
- end repeat
-
- --------------------
-
- -- pass back my address:
- return me
-
- ----------------------------------------------------------------------------------------------------
-
- on playGlueFX me,g
-
- -- play the sound effect (if any) associated with the glue symbol g:
- id = 0
- case g of
-
- #handPoint:
-
- -- specify glueID as fx bindingID!
- id = g
-
- otherwise
-
- -- successful button glue calls produce a click:
- if string(g) contains "button" then id = #buttonClick
-
- end case
-
- -- play fx:
- if symbolP(id) then me.playSoundFX(id)
-
- ----------------------------------------------------------------------------------------------------
-
- on playSoundFX me,bindingID
-
- -- check for bindingID argument:
- if not symbolP(bindingID) then return ¬
- [#error:#noBindingIDsupplied, #msg:"soundFXservice:playSoundFX"]
-
- -- does the binding supplied resolve to a listed entry in the bindings table?
- x = fxBindings[bindingID]
- if not symbolP(x) then return ¬
- [#error:#unlistedBindingID, #msg:"soundFXservice:playSoundFX" && "(fxBinding =" && bindingID & ")"]
-
- -- attempt to resolve the name n obtained to a known fx:
- n = fxMembers[x]
- if not integerP(n) then return ¬
- [#error:#noFXmemberFound, #msg:"soundFXservice:playSoundFX" && "(fxName =" && x & ")"]
-
- --------------------
-
- -- first look for a currently free fxChannel:
- x = 0
- repeat with i in fxChannels
-
- if not soundBusy(i) then
-
- -- the ith sound channel is free:
- x = i
- exit repeat
-
- end if
-
- end repeat
-
- -- if all channels are busy, then re-use the first fx channel:
- if not x then
-
- x = fxChannels[1]
- sound stop x
-
- end if
-
- --------------------
-
- -- play the sound effect!
- puppetSound(x,n)
-
- ----------------------------------------------------------------------------------------------------