home *** CD-ROM | disk | FTP | other *** search
/ LineOne ISP Sign-Up 5 / LineOne.iso / assets / cxt / scripts / parentScripts.cst / 00080_soundFXservice parent.ls < prev    next >
Encoding:
Text File  |  2001-01-27  |  4.2 KB  |  162 lines

  1. -- 2000.02.26
  2. -- Clive Green <clivegreen@atlas.co.uk>
  3.  
  4. ------------------------------------------------------------------------------------------------------
  5.  
  6. -- very rudimentary fxMembers manager:
  7.  
  8. ------------------------------------------------------------------------------------------------------
  9.  
  10. -- declare properties:
  11. property fxBindings        -- a #propList of fx labels, each with a sound effect
  12.  
  13. property fxLibName         -- the name of the sound effects castlibrary
  14. property fxChannels        -- a linear list of fx sound channel numbers to be used
  15.  
  16. property fxMembers         -- a #propList of fx member #names with castnumbers
  17. property fxChannelRegistry -- a #propList of sound channels with soundbusy flags 
  18.  
  19. ------------------------------------------------------------------------------------------------------
  20.  
  21. on new me,L
  22.   
  23.   -- (1) extract and check arguments:
  24.   
  25.   -- check for a parameter list:
  26.   if ilk(L) <> #propList then return ┬¼
  27.   [#error:#noParamListSupplied, #msg:"soundFXservice:new"]
  28.   
  29.   -- a reference to the parent codebase is REQUIRED:
  30.   main = L[#main]
  31.   
  32.   if (ilk(main) <> #instance) then return ┬¼
  33.   [#error:#noMainObjectSupplied, #msg:"soundFXservice:new"]
  34.   
  35.   --------------------
  36.   
  37.   -- (2) obtain fx mapping data:
  38.   dm = main.getDataManager()
  39.   fxBindings = dm.getData([#set:#soundFX])
  40.   
  41.   --------------------
  42.   
  43.   -- (3) store literals:
  44.   
  45.   -- we're using sounds from which FX library?
  46.   fxLibName = "soundFX"
  47.   
  48.   -- which sound channels are to be used for facilitating sound effects?
  49.   fxChannels = [3,4,5,6,7,8]
  50.   
  51.   --------------------
  52.   
  53.   -- (4) compile a list of available fxMembers:
  54.   
  55.   -- locate required library:
  56.   c = castlib(fxLibName).number
  57.   
  58.   if voidP(c) then return ┬¼
  59.   [#error:#castlibMissing, #msg:fxLibName]
  60.   
  61.   -- compile a list of fx names with member numbers:
  62.   fxMembers = [:]
  63.   repeat with i = 1 to the number of members of castlib c
  64.     
  65.     n = member(i,c).number
  66.     
  67.     -- sound members only:
  68.     if member(n).type <> #sound then next repeat
  69.     
  70.     -- store audio cast member number as a symbol:
  71.     fxMembers[symbol(member(n).name)] = n
  72.     
  73.   end repeat
  74.   
  75.   --------------------
  76.   
  77.   -- (5) compile a registry of audio channel states:
  78.   fxChannelRegistry = []
  79.   
  80.   repeat with i in fxChannels
  81.     
  82.     -- obtain the current state of each fx sound channel:
  83.     add fxChannelRegistry,[#channel:i, #state:soundBusy(i)]
  84.     
  85.   end repeat
  86.   
  87.   --------------------
  88.   
  89.   -- pass back my address:
  90.   return me
  91.   
  92.   ----------------------------------------------------------------------------------------------------
  93.   
  94. on playGlueFX me,g
  95.   
  96.   -- play the sound effect (if any) associated with the glue symbol g:
  97.   id = 0
  98.   case g of
  99.       
  100.     #handPoint:
  101.       
  102.       -- specify glueID as fx bindingID!
  103.       id = g
  104.       
  105.     otherwise
  106.       
  107.       -- successful button glue calls produce a click:
  108.       if string(g) contains "button" then id = #buttonClick
  109.       
  110.   end case
  111.   
  112.   -- play fx:
  113.   if symbolP(id) then me.playSoundFX(id)
  114.   
  115.   ----------------------------------------------------------------------------------------------------
  116.   
  117. on playSoundFX me,bindingID
  118.   
  119.   -- check for bindingID argument:
  120.   if not symbolP(bindingID) then return ┬¼
  121.   [#error:#noBindingIDsupplied, #msg:"soundFXservice:playSoundFX"]
  122.   
  123.   -- does the binding supplied resolve to a listed entry in the bindings table?
  124.   x = fxBindings[bindingID]
  125.   if not symbolP(x) then return ┬¼
  126.   [#error:#unlistedBindingID, #msg:"soundFXservice:playSoundFX" && "(fxBinding =" && bindingID & ")"]
  127.   
  128.   -- attempt to resolve the name n obtained to a known fx:
  129.   n = fxMembers[x]
  130.   if not integerP(n) then return ┬¼
  131.   [#error:#noFXmemberFound, #msg:"soundFXservice:playSoundFX" && "(fxName =" && x & ")"]
  132.   
  133.   --------------------
  134.   
  135.   -- first look for a currently free fxChannel:
  136.   x = 0
  137.   repeat with i in fxChannels
  138.     
  139.     if not soundBusy(i) then
  140.       
  141.       -- the ith sound channel is free:
  142.       x = i
  143.       exit repeat
  144.       
  145.     end if
  146.     
  147.   end repeat
  148.   
  149.   -- if all channels are busy, then re-use the first fx channel:
  150.   if not x then
  151.     
  152.     x = fxChannels[1]
  153.     sound stop x
  154.     
  155.   end if
  156.   
  157.   --------------------
  158.   
  159.   -- play the sound effect!
  160.   puppetSound(x,n)
  161.   
  162.   ----------------------------------------------------------------------------------------------------