home *** CD-ROM | disk | FTP | other *** search
Wrap
/* Copyright 2007, Philip S. Considine All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. The name of Philip S. Considine may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ //////////////////////////////////////////////////////////////////////////////////////////// desc: MIDI Modification Gizmo. //////////////////////////////////////////////////////////////////////////////////////////// //Input Channel slider1:0<0,15,1{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}>Input Channel /*----------- NOTE MIN/MAX You can change these if you want! --------------*/ //Sliders slider2:0<0,127,1>Note Min slider3:127<0,127,1>Note Max //Drop-downs with note names (disabled) //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 //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 /*-------------------------------------------------------------------------*/ //Input Velocity Min slider4:0<0,127,1>Input Velocity Min //Input Velocity Max slider5:127<0,127,1>Input Velocity Max //Input Mode slider6:0<0,1,1{Clamp To Range,Ignore Outside Range}>Input Velocity Mode //Velocity Scaling slider7:100<0,1000,1>Velocity Scaling(%) //Random Velocity slider8:0<0,100,1>Random Velocity (%) //Output Velocity Min slider9:0<0,127,1>Output Velocity Min //Output Velocity Max slider10:127<0,127,1>Output Velocity Max //Transpose slider11:0<-60,60,1>Transpose (semitones) //Random Pitch Bend slider12:0<0,100,1>Random Pitch (%) //Pitch Reset slider13:1<0,1,1{No,Yes}>Pitch Reset //Output Channel 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 //////////////////////////////////////////////////////////////////////////////////////////// @init statNoteOff = 8 * 16; statNoteOn = 9 * 16; statPitch = 14 * 16; pitchCentre = 16384; status = channel = velocity = note = transpose = pitch = 0; //////////////////////////////////////////////////////////////////////////////////////////// @slider //No fractions! slider2 = floor(slider2); slider3 = floor(slider3); slider4 = floor(slider4); slider5 = floor(slider5); slider8 = floor(slider8); slider9 = floor(slider9); slider10 = floor(slider10); slider11 = floor(slider11); slider12 = floor(slider12); //Clamp to respectable values slider2 > slider3 ? slider2 = slider3; slider3 < slider2 ? slider3 = slider2; slider4 > slider5 ? slider4 = slider5; slider5 < slider4 ? slider5 = slider4; slider7 < 0 ? slider7 = 0; slider8 < 0 ? slider8 = 0; slider8 > 100 ? slider8 = 100; slider9 > slider10 ? slider9 = slider10; slider10 < slider9 ? slider10 = slider9; slider11 < -60 ? slider11 = -60; slider11 > 660 ? slider11 = 60; slider12 < 0 ? slider12 = 0; slider12 > 100 ? slider12 = 100; //Set variables inChannel = slider1; noteMin = slider2; noteMax = slider3; inVelMin = slider4; inVelMax = slider5; velMode = slider6; velScale = slider7 / 100; velocityRand = slider8 / 100; outVelMin = slider9; outVelMax = slider10; transpose = slider11; pitchRand = slider12 / 100; pitchReset = slider13; outChannel = slider14; //////////////////////////////////////////////////////////////////////////////////////////// @block while ( midirecv(offset,msg1,msg23) ? ( t += 1; //Counter for random stuff //Check status byte status = msg1 & 240; //High four bits is message type (240 == 11110000) channel = msg1 & 15; //Low four bits is channel number (15 == 00001111) //Is it on our channel? channel == inChannel ? ( //Is it a note event? (status == statNoteOn || status == statNoteOff) ? ( //Get note number and velocity note = msg23 & 127; velocity = ((msg23/256) & 127); //Check input velocity mode velMode == 1 ? ( velocity > 0 ? ( inVelRange = (velocity < inVelMin || velocity > inVelMax) ? 0 : 1; ); ); //Is it within our note range? note >= noteMin && note <= noteMax && inVelRange == 1 ? ( process = 1; osc = sin(t); //used to make random values positive or negative //Process the message process > 0 ? ( //Do velocity velocity > 0 ? ( //Clamp input velocity to range velocity < inVelMin ? velocity = inVelMin; velocity > inVelMax ? velocity = inVelMax; //Scale velocity by percentage velocity = floor(velocity * velScale); //Randomise clamped velocity by percentage velocityRand > 0 ? velocity = floor(velocity + (rand(velocity * velocityRand)*osc)); //Clamp output velocity velocity < outVelMin ? velocity = outVelMin; velocity > outVelMax ? velocity = outVelMax; ); //Do transpose and clamp result if needed note += transpose; note < 0 ? note = 0; note > 127 ? note = 127; //Generate and send pitch bend message if needed pitchRand > 0 ? ( pitch = pitchCentre + floor(rand(pitchCentre * pitchRand)* osc); midisend(offset, statPitch + outChannel, pitch); ); //Send data midisend(offset,status + outChannel,note |(velocity * 256)); ); ) : //Outside note/velocity range, pass thru ( //Send pitch reset if needed pitchRand > 0 && pitchReset == 1 ? midisend(offset, statPitch + outChannel, pitchCentre); //Pass data midisend(offset,msg1,msg23); ); ):midisend(offset,msg1,msg23); //Not a note, pass thru ):midisend(offset,msg1,msg23); //Not on our channel, pass thru ); );