home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Sound / Misc / MUSICX21.DMS / in.adf / rexx / InterpolateSlope.mxe < prev    next >
Encoding:
Text File  |  1993-10-01  |  4.5 KB  |  177 lines

  1. /* linear interpolation between selected events                        */
  2. /* written by Henry Lowengard, after much prodding by Ken Bookstein */
  3. /* modified by Joe Pearce (2-15-91)                                    */
  4.  
  5. /* The FIRST selected event of the indicated type (CTL, PBEN, etc.) */
  6. /* determines the channel (and control number if CTL or note number */
  7. /* if polyphonic AT) of events that will be "sloped". Here is what    */
  8. /* is affected in each case:                                        */
  9. /*        Control Change (CTL): Controller Value                        */
  10. /*        Pitch Bend (PBEN): Bend Value                                */
  11. /*        Channel Aftertouch (CAT): Pressure                            */
  12. /*        Polyphonic Aftertouch (PAT): Pressure                        */
  13.  
  14. Options results
  15.  
  16. /* hokey box creator */
  17.  
  18. MXLABEL "Event Type:"
  19. MXRADIO "Control Change,Pitch Bend,Channel AT,Polyphonic AT"
  20. MXSLIDER "  Step Width:,1,10,1"
  21. MXREQUEST "Interpolate Event Slope,SLOPE"
  22. if result == 0 then exit
  23.  
  24. /* get the data */
  25.  
  26. MXVALUE 2
  27. i = Result
  28. if i = 0 then Etype = 'CTL'
  29. if i = 1 then Etype = 'PBEN'
  30. if i = 2 then Etype = 'CAT'
  31. if i = 3 then Etype = 'PAT'
  32.  
  33. MXVALUE 3
  34. Stepsize = Result
  35. if Etype = "PBEN" then StepSize = StepSize * 128
  36.  
  37. GETBARDATA
  38.  
  39. /* use brain, do work ! */
  40. evtIota = 1    /* array of selected goodies */
  41. MXPOINTER  "sleepy"
  42.  
  43. BEGINSCAN 'selected'
  44. /* trace r */
  45. if result ~=0 then do forever
  46.     NEXTEVENT
  47.     if result == 0 then break   /* skoot when out of events */
  48.  
  49.     if EVENT.TYPE == ETYPE then do
  50.         if ETYPE = "CTL" then do
  51. /* looking for first or last */
  52.             if evtIota = 1 then do
  53.                 echannel = EVENT.CHANNEL
  54.                 enum = EVENT.NUM
  55.                 end
  56.             else if echannel ~= EVENT.CHANNEL | enum ~= EVENT.NUM then break
  57.             EvtV.EVTIOTA = EVENT.VALUE 
  58.             EvtT.evtIota = EVENT.START.ticks
  59.             EvtB.evtIota = EVENT.START.bars
  60.             EvtC.evtIota = EVENT.START.clocks
  61.             EvtIota = EvtIota +1
  62.             end /* control change stuff */ 
  63.         if Etype = "PBEN" then do
  64.             if evtIota = 1 then echannel = EVENT.CHANNEL
  65.             else if echannel ~= EVENT.CHANNEL then break
  66.  
  67.             EVTV.EVTIOTA = EVENT.NUM
  68.             EVTT.EVTIOTA = EVENT.START.ticks
  69.             EvtB.evtIota = EVENT.START.bars
  70.             EvtC.evtIota = EVENT.START.clocks
  71.             EvtIota = EvtIota +1
  72.             end /* pbend stuff */
  73.         if Etype = "CAT" then do
  74.             if evtIota = 1 then echannel = EVENT.CHANNEL
  75.             else if echannel ~= EVENT.CHANNEL then break
  76.  
  77.             EVTV.EVTIOTA = EVENT.PRESSURE
  78.             EVTT.EVTIOTA = EVENT.START.ticks
  79.             EvtB.evtIota = EVENT.START.bars
  80.             EvtC.evtIota = EVENT.START.clocks
  81.             EvtIota = EvtIota +1
  82.             end /* channel AT stuff */
  83.         if ETYPE = "PAT" then do
  84. /* looking for first or last */
  85.             if evtIota = 1 then do
  86.                 echannel = EVENT.CHANNEL
  87.                 enum = EVENT.NUM
  88.                 end
  89.             else if echannel ~= EVENT.CHANNEL | enum ~= EVENT.NUM then break
  90.             EvtV.EVTIOTA = EVENT.PRESSURE
  91.             EvtT.evtIota = EVENT.START.ticks
  92.             EvtB.evtIota = EVENT.START.bars
  93.             EvtC.evtIota = EVENT.START.clocks
  94.             EvtIota = EvtIota +1
  95.             end /* polyphonic AT stuff */ 
  96.         end /* types matched on first one... */
  97. /* re scan etc etc. */
  98.     end /* forever 8^) if beg scan's result ~=0 */
  99.  
  100. evtiota = evtiota -1
  101. say EVTiota "is number of matching selected events!"
  102.  
  103. if evtiota <= 1 then  do
  104.     MXREPORT "Not enough "||Etype||"'s selected!"
  105.     exit
  106.     end
  107.  
  108.     /* debugging code */
  109. /*
  110. do i= 1 to evtiota
  111. say i EvtT.i ":" EvtV.i
  112. end
  113. */
  114.  
  115. /* loop around like a dope stuffing in ye events */
  116. do Evti = 2 to EvtIota
  117.     EvtF=Evti-1 /* from value */
  118.     T0 = EvtT.EvtF /* first time in clox */
  119.     T1 = EvtT.EvtI /* ditto for end time */
  120.     C0 = EvtV.EvtF /* low end control */
  121.     C1 = EvtV.EvtI /* end for values */
  122.  
  123.         /* debugging code */
  124.     /* MXREPORT "FROM/TO:"||t0||":"||T1||" "||c0||":"||C1||", range "||C1-C0 */
  125.  
  126.     DT = T1-T0
  127.     DC = C1-C0
  128.     ByAmt = SIGN(DC)*StepSize
  129.  
  130.     if dC ~= 0 then do
  131.         OldC=-1
  132.         do InI = c0+Byamt to c1-Byamt by ByAMT
  133.  
  134.             delticks = (((ini-C0)/DC)*DT)%1 + EvtC.EvtF
  135.             EVENT.START.CLOCKS = delticks // BARDATA.MEASURE
  136.             EVENT.START.BARS = EvtB.EvtF + delticks % BARDATA.MEASURE
  137.             EVENT.TYPE=ETYPE
  138.             EVENT.CHANNEL=echannel
  139.  
  140.             IF ETYPE = "CTL" then do 
  141.                 EVENT.NUM = ENUM
  142.                 EVENT.VALUE =INI
  143.                 if Event.Value ~= OldC then do
  144.                     oldc=Event.Value
  145.                      ADDEVENT
  146.                     end
  147.                 end
  148.             if ETYPE = "PBEN" then do
  149.                 EVENT.NUM = INI
  150.                 if Event.NUM ~= OldC then do
  151.                     oldc=Event.Num
  152.                      ADDEVENT
  153.                     end
  154.                 end
  155.             if ETYPE = "CAT" then do
  156.                 EVENT.PRESSURE = INI
  157.                 if Event.PRESSURE ~= OldC then do
  158.                     oldc=Event.Pressure
  159.                      ADDEVENT
  160.                     end
  161.                 end
  162.             IF ETYPE = "PAT" then do 
  163.                 EVENT.NUM = ENUM
  164.                 EVENT.PRESSURE =INI
  165.                 if Event.PRESSURE ~= OldC then do
  166.                     oldc=Event.PRESSURE
  167.                      ADDEVENT
  168.                     end
  169.                 end
  170.             end
  171.         end /* DT is valid */
  172.     end
  173.  
  174. /* MXREPORT "All Done!" */        /* it should be obvious... */
  175. MXPOINTER "normal"
  176. exit
  177.