home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Sound / Misc / MUSICX21.DMS / in.adf / rexx / V-Scaler.mxe < prev   
Encoding:
Text File  |  1980-01-23  |  3.3 KB  |  110 lines

  1. /*    RexxEdit example ARexx macro program                    */
  2.  
  3. /*    Velocity scaler written entirely in ARexx                */
  4.  
  5. options results                            /* always include this command    */
  6.  
  7. MXSLIDER "Initial Level:,0,300"            /* percentage level change        */
  8.  
  9. MXSLIDER "Final Level:,0,300"            /* percentage level change        */
  10.  
  11. MXSLIDER "Random Factor:,0,100"            /* random fluctuations            */
  12.  
  13. MXNOTESIZE "Duration:"                    /* duration selector            */
  14.  
  15. MXRADIO "Attack velocity,Release velocity"    /* mutually exclusive        */
  16.  
  17. MXRADIO "Selected events,All events"    /* mutually exclusive            */
  18.  
  19. MXREQUEST "AREXX VELOCITY SCALER,SCALE"    /* bring up requester & wait    */
  20. if result == 0 then exit                    /* 0 if user canceled        */
  21.  
  22. MXPOINTER "sleepy"                        /* tell user we're busy            */
  23.  
  24. MXVALUE 1                                /* get initial level            */
  25. initval = result
  26.  
  27. MXVALUE 2                                /* get final level                */
  28. finalval = result
  29.  
  30. MXVALUE 3                                /* get random level                */
  31. rndfactor = result
  32.  
  33. MXVALUE 5                                /* attack or release velocity    */
  34. veltype = result
  35.  
  36. notecount = 0                /* do scan to just find start and end times */
  37.  
  38. MXVALUE 6                                /* selected or all events        */
  39. if result == 0 then BEGINSCAN 'selected'
  40. else BEGINSCAN 'all'
  41.  
  42. if result ~= 0 then do forever            /* if BEGINSCAN ok, scan events    */
  43.  
  44.   NEXTEVENT                                /* get next event                */
  45.   if result == 0 then break                    /* 0 if no more events        */
  46.  
  47.   if EVENT.TYPE == 'NOTE' then do        /* if a note...                    */
  48.     if notecount == 0 then do                /* if no notes found yet...    */
  49.       if EVENT.CLOCKTYPE == 'ABS' then starttime = EVENT.START.QFRAMES
  50.       else starttime = EVENT.START.TICKS
  51.       end
  52.     else do                                    /* if have start value...    */
  53.       if EVENT.CLOCKTYPE == 'ABS' then stoptime = EVENT.START.QFRAMES
  54.       else stoptime = EVENT.START.TICKS
  55.       end
  56.     notecount = notecount + 1                /* add one to note count    */
  57.     end
  58.   end
  59. ENDSCAN                                    /* terminate the first scan        */
  60.  
  61.     /* if only one note or start & stop times the same, no scaling needed */
  62.  
  63. if notecount < 2 | starttime == stoptime then do
  64.   MXPOINTER "normal"
  65.   exit
  66.   end
  67.  
  68. offtime = stoptime - starttime            /* time diference                */
  69. offval = finalval - initval                /* velocity change over time    */
  70. if rndfactor > 0 then random(1,1,time('S'))    /* initialize random command */
  71.  
  72. MXVALUE 4                                /* begin the second scan        */
  73. if result == 0 then BEGINSCAN 'selected'
  74. else BEGINSCAN 'all'
  75.  
  76. if result ~= 0 then do forever
  77.  
  78.   NEXTEVENT                                /* get next event                */
  79.   if result == 0 then break                    /* 0 if no more events        */
  80.  
  81.   if EVENT.TYPE == 'NOTE' then do        /* if a note...                    */
  82.                                             /* get the event's time        */
  83.     if EVENT.CLOCKTYPE == 'ABS' then thistime = EVENT.START.QFRAMES
  84.     else thistime = EVENT.START.TICKS
  85.  
  86.                                             /* scale & randomize        */
  87.     percent = (offval * (thistime - starttime)) % offtime + initval
  88.     if rndfactor > 0 then 
  89.       percent = percent + random(0,2 * rndfactor) - rndfactor
  90.  
  91.                                             /* adjust correct velocity    */
  92.     if veltype == 0 then do
  93.       EVENT.ATTACK = (EVENT.ATTACK * percent) % 100
  94.       if (EVENT.ATTACK < 0) then EVENT.ATTACK = 0
  95.       if (EVENT.ATTACK > 127) then EVENT.ATTACK = 127
  96.       end
  97.     else do
  98.       EVENT.RELEASE = (EVENT.RELEASE * percent) % 100
  99.       if (EVENT.RELEASE < 0) then EVENT.RELEASE = 0
  100.       if (EVENT.RELEASE > 127) then EVENT.RELEASE = 127
  101.       end
  102.  
  103.     REPLEVENT                                /* replace the event        */
  104.  
  105.     end
  106.   end
  107. ENDSCAN                                    /* end second scan                */
  108.  
  109. MXPOINTER "normal"                        /* done!                        */
  110.