home *** CD-ROM | disk | FTP | other *** search
/ Dream 49 / Amiga_Dream_49.iso / amiga / applications / musique / resonance.lha / resonance-gui.rexx < prev    next >
OS/2 REXX Batch file  |  1998-01-26  |  5KB  |  193 lines

  1. /*************************************************************************/
  2. /* $VER: resonance 1.0                                                   */
  3. /*                                                                       */
  4. /* Resonance  (c) 1998 D. Krupicz                                        */
  5. /* Octamed Sound Studio analog resonance plug-in                         */
  6. /* Slow Slow Slow :(                                                     */
  7. /*************************************************************************/
  8. /*
  9. gui_file = arg(1)
  10. */
  11. gui_file = 'ram:rexx/gui/resonance.gui'
  12.  
  13. IF EXISTS("libs:rexxsupport.library") THEN DO
  14.     IF ~SHOW("L","rexxsupport.library") THEN
  15.         IF ~ADDLIB("rexxsupport.library",0,-30,0) THEN EXIT
  16. END
  17. ELSE EXIT
  18.  
  19. IF EXISTS("libs:rexxreqtools.library") THEN DO
  20.     IF ~SHOW("L","rexxreqtools.library") THEN
  21.         IF ~ADDLIB("rexxreqtools.library",0,-30) THEN EXIT
  22. END
  23. ELSE EXIT
  24.  
  25. if ~ 'SHOW'('L',"rexxmathlib.library") then DO
  26.    'ADDLIB'('rexxmathlib.library',0,-30,0)
  27.    END
  28.  
  29.  
  30. OPTIONS RESULTS
  31. OPTIONS FAILAT 10
  32.  
  33. SIGNAL ON SYNTAX
  34. SIGNAL ON FAILURE 
  35.  
  36. ADDRESS OCTAMED_REXX
  37. ed_setblocklines 16       /* 16 lines per block, pal */
  38. ADDRESS REXX
  39.  
  40. /* Get the GUI file from the user */
  41. IF gui_file = '' THEN
  42.   DO
  43.     gui_file=rtfilerequest('REXX:gui',,'Varexx Request','_Load','rt_reqpos=reqpos_centerscr rtfi_matchpat=#?.gui rtfi_flags=freqf_patgad')
  44.     IF gui_file = '' THEN EXIT
  45.   END
  46.  
  47. /* Check Varexx is loaded if not load it */
  48.  
  49. IF SHOW( 'p', 'VAREXX' ) ~= 1 THEN DO
  50.     ADDRESS COMMAND "run >NIL: varexx"
  51.     ADDRESS COMMAND "WaitForPort VAREXX"
  52. END
  53. ADDRESS VAREXX
  54.  
  55. IF OPENPORT("HOLLY") = 0 THEN DO
  56.     CALL rtezrequest "Could not open a port.",, "Varexx Error"
  57.     EXIT
  58. END
  59.  
  60. /*  'load ' gui_file 'HOLLY'  */ /*normal screen */
  61.   'load ' gui_file 'HOLLY PS=OCTAMED'  /*go to octamed screen */
  62.  
  63. vhost = RESULT
  64. /* say rc externerror */
  65. ADDRESS VALUE vhost
  66.  
  67. show
  68.  
  69. /**************************************************************************/
  70. /* MAIN LOOP -- Check for GUI events                                      */
  71. /**************************************************************************/
  72.  
  73. /* set defaults */
  74.  
  75. amp = 31000            /* initial amplitude */
  76. decay = 1.075              /* decay rate   long = 1.015  short = 2 */
  77. fmult = 1             /* frequency */
  78. fmod = 1  /*  1.0005  */             /* frequency mod over time */
  79.  
  80. threshold = 256        /* effect threshold */
  81. look_offs = 5         /* difference offset */
  82.  
  83.  
  84. DO FOREVER
  85.    CALL WAITPKT("HOLLY")
  86.    packet = GETPKT("HOLLY")
  87.    IF packet ~= '00000000'x THEN DO
  88.       drop pos vol
  89.       class = GETARG(packet)
  90. /*      say class  */
  91.       IF class = "CLOSEWINDOW" THEN LEAVE
  92.  
  93.       IF left( class , 4 ) = '_MIX' THEN DO
  94.          mix = right( class , 3 ) / 100
  95.          'settext textmix' mix
  96.          'settext info mix_set'
  97.          END
  98.  
  99.       IF left( class , 6 ) = '_FMULT' THEN DO
  100.          fmult = right( class , 3 ) / 50
  101.          'settext textfmult' 'sin * 'fmult
  102.          'settext info freq_set'
  103.          END
  104.  
  105.       IF left( class , 5 ) = '_FMOD' THEN DO
  106.          fmod = ( right( class , 3 ) - 10 ) / 100000 + 1
  107.          'settext textfmod' fmod
  108.          'settext info freq.mod_set'
  109.          END
  110.  
  111.       IF left( class , 6 ) = '_DECAY' THEN DO
  112. /*         decay = ( right( class , 3 ) / 100 ) + 1  */
  113.          decay =   ((( right( class , 3 ) - 10 ) * 10 ) / 800 ) + 1
  114.          'settext textdecay' decay
  115.          'settext info decay_set'
  116.          END
  117.  
  118.      IF left( class , 10 ) = '_THRESHOLD' THEN DO
  119.          threshold = right( class , 3 )
  120.          'settext textthreshold' threshold
  121.          'settext info threshold_set'
  122.          END
  123.  
  124.      IF left( class , 10 ) = '_LOOK_OFFS' THEN DO
  125.          look_offs = right( class , 3 )
  126.          'settext textlook_offs' look_offs 
  127.          'settext info look_set'
  128.          END
  129.  
  130.       IF class = "GO" THEN DO      /* actually do resonance */
  131.          'settext info working...'
  132.          address 'OCTAMED_REXX'
  133.          drop s_type begin end
  134.          'in_gettype' var s_type
  135.          IF s_type ~= 'EMPTY' THEN DO
  136.             'sa_getrangestart' var begin
  137.             'sa_getrangeend' var end
  138.  
  139.             DO i= begin TO end BY 1
  140.                drop smpl_a smpl_b amp_b
  141.                sa_getsample i var smpl_a
  142.                sa_getsample i + look_offs var smpl_b
  143.  
  144.                amp_b = abs( smpl_b - smpl_a )
  145.  
  146.                IF amp_b > threshold THEN amp = amp_b / 2
  147. /*
  148.                say 'mix' mix 'amp' amp 'fmult' fmult 'fmod' fmod 'decay' decay
  149. */
  150.                y = smpl_a / 2 + trunc( mix * ( sin( i * fmult ) * amp ))   /* calculate resonance */
  151.                amp = amp / decay
  152.                IF amp < 1 THEN amp = 1
  153.                fmult = fmult / fmod
  154.                IF fmult < 0.00001 THEN fmult = 0.00001
  155.                sa_setsample i y
  156.                END
  157.             END
  158.  
  159.          sa_refresh
  160.  
  161.          ADDRESS VALUE vhost
  162.          'settext info done.'
  163.          IF s_type = 'EMPTY' THEN DO
  164.             'settext info no_sample'
  165.             END
  166.          END
  167.       END
  168.    END
  169.  
  170.     'hide unload'    
  171.  
  172.     CALL CLOSEPORT( "HOLLY" )
  173. EXIT
  174.  
  175. /* Error messages */
  176. failure:
  177.     SAY "Error code" rc "-- Line" SIGL
  178.     SAY EXTERNERROR
  179.     'hide unload'
  180.     CALL CLOSEPORT ("HOLLY")
  181.  
  182. EXIT
  183.  
  184. syntax:
  185.     SAY "Error" rc  "-- Line" SIGL
  186.     SAY ERRORTEXT( rc )
  187.     'hide unload'
  188.     CALL CLOSEPORT ("HOLLY")
  189. EXIT
  190.  
  191.  
  192.  
  193.