I don't know if I'm supposed to post a scripting topic here or in "Patch development".
You know, my mapping obsession?
Well. My script is successfully compiled but as soon as I send a midi note, the tracer says: "[Script Error] : Type Mismatch in 0"
Here is the code:
Code: Select all
/////////////////////////////
// NoteMGR
/////////////////////////////
// This script remaps notes XOR transposes them and/or applies a ratio
// to their velocity
// It needs a 128 (0 to 127) array where each entry is the incoming note#
// and each value is the mapped note#
// Plug an Array Editor Module on the 'Map' input to edit mapped notes.
// By default, the values of
// - entry 0 should be 0
// - entry 1 should be 1
// - entry 2 should be 2
// - [...]
// - entry 127 should be 127
// That must be done or the script won't work.
// If you want note 60 to play one octave below when the whole range is
// transposed one octave up, try this:
// LeftLimt = lower note of your keyboard or you want to hear
// RightLimt = upper note " " " " " " " "
// Transpo = 0 (half steps)
// Octave = 1 (actual octave plus one)
// Velo = 100% (of your playing velocity)
// Velocity ratio will NOT be applied to the remapped note (just a
// choice that can change)
// Note that on some VSTis, a velocity greater than 127 will be
// set to 0 or 1!
// go to the entry#60 of yout Array Editor and change it's value to 48 (60-12)
// ...and play unplayable patterns!
// or, for stochastic purposes...
// don't plug an Array Editor Module on the 'Map' input but an Array (Display or Set)
// with 'num' set to 128 and try 'Randomize'.
// Remember your global remote for 'Panic'?
/////////////////////////////
// parameters declaration
var Input : Tparameter;
var nMap : Tparameter;
var LL : TParameter;
var RL : TParameter;
var Oct : TParameter;
var Trans : TParameter;
var Vel : TParameter;
var Output : Tparameter;
// initialisation : create parameters
procedure init;
begin
Input := CreateParam('MidiIn',ptMidi);
nMap := CreateParam('Map',ptArray);
LL := CreateParam('LeftLimit',ptDataFader);
RL := CreateParam('RightLimit',ptDataFader);
Trans := CreateParam('Transpo',ptDataFader);
Oct := CreateParam('Octave',ptDataFader);
Vel := CreateParam('Velo',ptDataFader);
Output := CreateParam('MidiOut',ptMidi);
SetIsOutPut(Input,false);
SetIsOutPut(nMap,false); SetMin(nMap,0); SetMax(nMap,127)
SetIsOutPut(LL,false); SetFormat(LL,'%.0f'); SetMin(LL,0); SetMax(LL,127); SetDefaultValue(LL,36);
SetIsOutPut(RL,false); SetFormat(RL,'%.0f'); SetMin(RL,0); SetMax(RL,127); SetDefaultValue(RL,72);
SetIsOutPut(Oct,false); SetFormat(Oct,'%.0f'); SetMin(Oct,-4); SetMax(Oct,4); SetDefaultValue(Oct,0);
SetIsOutPut(Trans,false); SetFormat(Trans,'%.0f'); SetMin(Trans,-11); SetMax(Trans,11); SetDefaultValue(Trans,0);
SetIsOutPut(Vel,false); SetFormat(Vel,'%.0f'); SetSymbol(Vel,'%'); SetMin(Vel,0); SetMax(Vel,400); SetDefaultValue(Vel,100);
SetIsInput(Output,false);
end;
// Global variables
var i : integer;
var nbMidiIn : integer;
var nbMidiOut : integer;
var ActualNote : integer;
var MappedNote : integer;
var ReceivedMidi : TMidi;
var TranspoVal : single;
var VeloVal : double;
// main proc
begin
nbMidiIn := GetLength(input); // get the number of incoming midi codes
if nbMidiIn > 0 // if notes are recieved
then begin
TranspoVal := trunc(getValue(Trans)+(getValue(Oct) * 12)); // calculates the total tranpo value
VeloVal := getValue(Vel) / 100; // calculates the velocity ratio
for i := 0 to nbMidiIn-1 // loops each note of polyphonic data
do begin
GetMidiArrayValue(Input,i,ReceivedMidi); // get individual midi data
ActualNote := ReceivedMidi.data1; // get individual note #
if (ActualNote >= getValue(LL)) and (ActualNote < getValue(RL)) // if the individual note is in the range
then begin
SetLength(outPut,nbMidiOut); // set the new number of output codes
MappedNote := trunc(GetDataArrayValue(nMap,ReceivedMidi.data1)); // get mapped note #
if ActualNote = MappedNote // if the note is NOT mapped
then
if (TranspoVal - VeloVal) <> -1 // if transpo or velo are changed
then begin
ReceivedMidi.data1 := ActualNote + TranspoVal; // changes transpo
ReceivedMidi.data2 := trunc(ReceivedMidi.data2 * VeloVal); // changes velocity
end
else ReceivedMidi.data1 := MappedNote; // else only remap the note
SetMidiArrayValue(Output,NbMidiOut,ReceivedMidi); // sets output value
NbMidiOut := NbMidiOut + 1; // reset next number of outgoing midi codes
end
end;
end
else SetLength(outPut,0); // nothing received, nothing sent
end.
/////////////////////////////
// 27-02-2007
// Vincent MICHEL
/////////////////////////////My favotite line is this one:
Code: Select all
// That must be done or the script won't work.There are 3 points where I'm not sure of what I'm doing (3, well...):
1. when I get the note value in the array
Code: Select all
MappedNote := trunc(GetDataArrayValue(nMap,ReceivedMidi.data1));Code: Select all
if (ActualNote >= getValue(LL)) and (ActualNote < getValue(RL))
then beginCode: Select all
SetLength(outPut,nbMidiOut);Anyway, this proc is some kind of test. It's easier to write (and lighter to run) if I just never check if the note# is remapped and always use the array values. Too many imbrications of "If ... then ... else ..."
Well, Bj?rn, I think it's for you...
Sorry!
But I hope you'll use it! It's very useful! I like it! Play huge grooves all across the keyboard with just a few finger impulse!
