home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 July & August / PCWorld_2007-07-08_cd.bin / audio-video / reaper / reaper1861-install.exe / Effects / IX / MIDI_Tool II < prev    next >
Encoding:
Text File  |  2007-05-02  |  7.6 KB  |  217 lines

  1. /*
  2. Copyright 2007, Philip S. Considine
  3. All rights reserved.
  4.  
  5. Redistribution and use in source and binary forms, with or without modification, are permitted 
  6. provided that the following conditions are met:
  7.  
  8. Redistributions of source code must retain the above copyright notice, this list of conditions 
  9. and the following disclaimer. 
  10.  
  11. Redistributions in binary form must reproduce the above copyright notice, this list of conditions 
  12. and the following disclaimer in the documentation and/or other materials provided with the distribution. 
  13.  
  14. The name of Philip S. Considine may not be used to endorse or promote products derived from this
  15. software without specific prior written permission.
  16.  
  17. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 
  18. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
  19. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
  20. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  21. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
  22. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  23. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
  24. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26.  
  27. ////////////////////////////////////////////////////////////////////////////////////////////
  28. desc: MIDI Modification Gizmo.
  29.  
  30. ////////////////////////////////////////////////////////////////////////////////////////////
  31.  
  32. //Input Channel
  33. slider1:0<0,15,1{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}>Input Channel
  34.  
  35. /*----------- NOTE MIN/MAX You can change these if you want! --------------*/
  36. //Sliders
  37. slider2:0<0,127,1>Note Min
  38. slider3:127<0,127,1>Note Max
  39.  
  40. //Drop-downs with note names (disabled)
  41. //slider2:0<0,127,1{C0,C#0,D0,D#0,E0,F0,F#0,G0,G#0,A0,A#0,B0,C1,C#1,D1,D#1,E1,F1,F#1,G1,G#1,A1,A#1,B1,C2,C#2,D2,D#2,E2,F2,F#2,G2,G#2,A2,A#2,B2,C3,C#3,D3,D#3,E3,F3,F#3,G3,G#3,A3,A#3,B3,C4,C#4,D4,D#4,E4,F4,F#4,G4,G#4,A4,A#4,B4,C5,C#5,D5,D#5,E5,F5,F#5,G5,G#5,A5,A#5,B5,C6,C#6,D6,D#6,E6,F6,F#6,G6,G#6,A6,A#6,B6,C7,C#7,D7,D#7,E7,F7,F#7,G7,G#7,A7,A#7,B7,C8,C#8,D8,D#8,E8,F8,F#8,G8,G#8,A8,A#8,B8,C9,C#9,D9,D#9,E9,F9,F#9,G9,G#9,A9,A#9,B9,C10,C#10,D10,D#10,E10,F10,F#10,G10}>Note Min
  42. //slider3:127<0,127,1{C0,C#0,D0,D#0,E0,F0,F#0,G0,G#0,A0,A#0,B0,C1,C#1,D1,D#1,E1,F1,F#1,G1,G#1,A1,A#1,B1,C2,C#2,D2,D#2,E2,F2,F#2,G2,G#2,A2,A#2,B2,C3,C#3,D3,D#3,E3,F3,F#3,G3,G#3,A3,A#3,B3,C4,C#4,D4,D#4,E4,F4,F#4,G4,G#4,A4,A#4,B4,C5,C#5,D5,D#5,E5,F5,F#5,G5,G#5,A5,A#5,B5,C6,C#6,D6,D#6,E6,F6,F#6,G6,G#6,A6,A#6,B6,C7,C#7,D7,D#7,E7,F7,F#7,G7,G#7,A7,A#7,B7,C8,C#8,D8,D#8,E8,F8,F#8,G8,G#8,A8,A#8,B8,C9,C#9,D9,D#9,E9,F9,F#9,G9,G#9,A9,A#9,B9,C10,C#10,D10,D#10,E10,F10,F#10,G10}>Note Max
  43. /*-------------------------------------------------------------------------*/
  44.  
  45. //Input Velocity Min
  46. slider4:0<0,127,1>Input Velocity Min
  47.  
  48. //Input Velocity Max
  49. slider5:127<0,127,1>Input Velocity Max
  50.  
  51. //Input Mode
  52. slider6:0<0,1,1{Clamp To Range,Ignore Outside Range}>Input Velocity Mode
  53.  
  54. //Velocity Scaling
  55. slider7:100<0,1000,1>Velocity Scaling(%)
  56.  
  57. //Random Velocity
  58. slider8:0<0,100,1>Random Velocity (%)
  59.  
  60. //Output Velocity Min
  61. slider9:0<0,127,1>Output Velocity Min
  62.  
  63. //Output Velocity Max
  64. slider10:127<0,127,1>Output Velocity Max
  65.  
  66. //Transpose
  67. slider11:0<-60,60,1>Transpose (semitones)
  68.  
  69. //Random Pitch Bend
  70. slider12:0<0,100,1>Random Pitch (%)
  71.  
  72. //Pitch Reset
  73. slider13:1<0,1,1{No,Yes}>Pitch Reset
  74.  
  75. //Output Channel
  76. slider14:0<0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,1{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}>Output Channel
  77.  
  78. ////////////////////////////////////////////////////////////////////////////////////////////
  79. @init
  80.  
  81. statNoteOff = 8 * 16;
  82. statNoteOn     = 9 * 16;
  83. statPitch = 14 * 16;
  84.  
  85. pitchCentre = 16384;
  86.  
  87. status = channel = velocity = note = transpose = pitch = 0;
  88.  
  89. ////////////////////////////////////////////////////////////////////////////////////////////
  90. @slider
  91.  
  92. //No fractions!
  93. slider2 = floor(slider2);
  94. slider3 = floor(slider3);
  95. slider4 = floor(slider4);
  96. slider5 = floor(slider5);
  97. slider8 = floor(slider8);
  98. slider9 = floor(slider9);
  99. slider10 = floor(slider10);
  100. slider11 = floor(slider11);
  101. slider12 = floor(slider12);
  102.  
  103. //Clamp to respectable values
  104. slider2 > slider3 ? slider2 = slider3;
  105. slider3 < slider2 ? slider3 = slider2;
  106. slider4 > slider5 ? slider4 = slider5;
  107. slider5 < slider4 ? slider5 = slider4;
  108. slider7 < 0 ? slider7 = 0;
  109. slider8 < 0 ? slider8 = 0; slider8 > 100 ? slider8 = 100;
  110. slider9 > slider10 ? slider9 = slider10;
  111. slider10 < slider9 ? slider10 = slider9;
  112. slider11 < -60 ? slider11 = -60; slider11 > 660 ? slider11 = 60;
  113. slider12 < 0 ? slider12 = 0; slider12 > 100 ? slider12 = 100;
  114.  
  115. //Set variables
  116. inChannel = slider1;
  117. noteMin = slider2;
  118. noteMax = slider3;
  119. inVelMin = slider4;
  120. inVelMax = slider5;
  121. velMode = slider6;
  122. velScale = slider7 / 100;
  123. velocityRand = slider8 / 100;
  124. outVelMin = slider9;
  125. outVelMax = slider10;
  126. transpose = slider11;
  127. pitchRand = slider12 / 100;
  128. pitchReset = slider13;
  129. outChannel = slider14;
  130.  
  131. ////////////////////////////////////////////////////////////////////////////////////////////
  132. @block
  133. while
  134. (
  135.     midirecv(offset,msg1,msg23) ?
  136.     (
  137.         t += 1;    //Counter for random stuff
  138.         
  139.         //Check status byte
  140.         status = msg1 & 240;    //High four bits is message type (240 == 11110000)
  141.         channel = msg1 & 15;    //Low four bits is channel number (15 == 00001111)
  142.         
  143.         //Is it on our channel?
  144.         channel == inChannel ?
  145.         (
  146.             //Is it a note event?
  147.             (status == statNoteOn || status == statNoteOff) ?
  148.             (
  149.                 //Get note number and velocity
  150.                 note = msg23 & 127;
  151.                 velocity = ((msg23/256) & 127);
  152.                 
  153.                 //Check input velocity mode
  154.                 velMode == 1 ?
  155.                 (
  156.                     velocity > 0 ?
  157.                     (
  158.                         inVelRange = (velocity < inVelMin || velocity > inVelMax) ? 0 : 1;
  159.                     );
  160.                 );
  161.                 
  162.                 //Is it within our note range?
  163.                 note >= noteMin && note <= noteMax && inVelRange == 1 ?
  164.                 (
  165.                     process = 1;
  166.                     osc = sin(t);    //used to make random values positive or negative 
  167.                                 
  168.                     //Process the message
  169.                     process > 0 ?
  170.                     (
  171.                         //Do velocity
  172.                         velocity > 0 ?
  173.                         (        
  174.                             //Clamp input velocity to range
  175.                             velocity < inVelMin ? velocity = inVelMin;
  176.                             velocity > inVelMax ? velocity = inVelMax;
  177.                                 
  178.                             //Scale velocity by percentage
  179.                             velocity = floor(velocity * velScale);
  180.                             
  181.                             //Randomise clamped velocity by percentage
  182.                             velocityRand > 0 ? velocity = floor(velocity + (rand(velocity * velocityRand)*osc));
  183.                         
  184.                             //Clamp output velocity
  185.                             velocity < outVelMin ? velocity = outVelMin;
  186.                             velocity > outVelMax ? velocity = outVelMax;
  187.                         );
  188.                         
  189.                         //Do transpose and clamp result if needed
  190.                         note += transpose;
  191.                         note < 0 ? note = 0; note > 127 ? note = 127;
  192.                         
  193.                         //Generate and send pitch bend message if needed
  194.                         pitchRand > 0 ?
  195.                         (
  196.                             pitch = pitchCentre + floor(rand(pitchCentre * pitchRand)* osc);
  197.                             midisend(offset, statPitch + outChannel, pitch);
  198.                         );
  199.  
  200.                         //Send data
  201.                         midisend(offset,status + outChannel,note |(velocity * 256));    
  202.                     );
  203.                 )
  204.                 :    //Outside note/velocity range, pass thru
  205.                 (
  206.                     //Send pitch reset if needed
  207.                     pitchRand > 0 && pitchReset == 1 ? midisend(offset, statPitch + outChannel, pitchCentre);
  208.                             
  209.                     //Pass data
  210.                     midisend(offset,msg1,msg23);
  211.                 );
  212.             ):midisend(offset,msg1,msg23); //Not a note, pass thru
  213.         ):midisend(offset,msg1,msg23); //Not on our channel, pass thru
  214.     );
  215. );
  216.  
  217.