Page 1 of 1

Posted: 15 Jan 2009, 12:06
by moody33
Hi all.

As I don't understand scripts , I ask you for help !

I need a simple script like this:

One Midi input. Range 0-127
One Array output. Range 0-127 (or user defined?)

Each time a note number is triggered, array output is set to 1 until received a note off ( 0 )
For example, if Note number 64 is pressed, then array position "64" is set to 1 .
Of course, I need a polyphonic script, so if I pressed note number 64 and note number 72, array position 64 and 72 would be set to 1, and the other to 0.

Thansk in advance for those who can help me.

And why not, another script that make the inverse? array trigger midi notes?

Posted: 15 Jan 2009, 12:33
by amiga909
Gold Members

Re: Need a script

for what do u need this?


what kind of midi data do you put in there?

what kind of array data do you need (eg. format, precision)?

Posted: 15 Jan 2009, 12:49
by nay-seven
not sure but maybe possible with patching...
as amiga909 ask , can you be more precise about your needs.....?

Posted: 15 Jan 2009, 12:59
by bsork
I might volunteer, it shouldn't be very hard - in fact it would be a simplified version of the ClearMidiNotes script (or whatever I called the AllNotesOff thingie I made some time ago).

This could however be done with patching of not too many modules, using SetArrayElement with index=NoteNumber and a bit checking for values (remember that a NoteOn with velocity = 0 is a NoteOff...).

Can't help anything more right now, so if you haven't found out how to patch it and noone else has done it in the meantime, I can create something for you before the weekend.

Posted: 15 Jan 2009, 13:05
by moody33
Precision :

Midi data input flow: Midi note On and Note Off only .
Array ouput format? Don't sure to understand. I need a 127 size array ( corresponding to the 127 note range in midi flow. )
When a Note On ( number 32 for example) is detect, the number off the note activate the corresponding array position (32 here) and set it to 1.
when a Note Off is detect, (32 again), the corresponding array position is set to 0 . 0 is the defaut value for the array.

do you understand what I mean?

Posted: 15 Jan 2009, 13:10
by moody33
Bsork: Thanks you for your advice. But I can't do it with patching probably because of my polyphonic needed.
I remember a patch ( 12notes switch) but it send integer values, and I don't want 127 wire !

Here is the script ( I dont remember who is the author) . I want quite the same thing but with a single array output in place of integer values. Hope it help.

//////////////////////////
// Remaps each midi note from range 60-71 to triggers
/////////////////////////
// parameters declaration

var input : Tparameter;

var msg : Tparameter;
var data1 : Tparameter;
var data2 : Tparameter;

var trigs : array of Tparameter;

// initialisation : create parameters
procedure init;
var i : integer;
begin
Input := CreateParam('In',ptMidi);
msg := CreateParam('msg', ptdataField);
data1 := CreateParam('data1', ptdataField);
data2 := CreateParam('msg', ptdataField);

SetIsOutPut(Input,false);
SetIsInput(msg, false);
SetIsInput(data1, false);
SetIsInput(data2, false);

setarraylength(trigs,12);
for i := 0 to 11
do begin
trigs := CreateParam('trig'+inttostr(i+1), ptSwitch);
setisInput(trigs, false);
end;
end;

// Global variables

var nbOfMidi : integer;
var Miditmp : TMidi;
var i : integer;
var index : integer;

//////////////////////////////
// main proc
//////////////////////////////
begin

nbOfMidi := GetLength(input); // get the number of incoming midi codes
if nbOfMidi > 0
then begin
for i := 0 to nbOfMidi - 1 do begin
GetMidiArrayValue(input, i, Miditmp);
setValue(msg,MidiTmp.msg);
setValue(data1,MidiTmp.data1);
setValue(data2,MidiTmp.data2);

if ((MidiTmp.msg = 144) or (MidiTmp.msg = 128))
and (MidiTmp.data1 >= 60) and (MidiTmp.data1 <= 71)
then begin
index := MidiTmp.data1 - 60;
if (MidiTmp.msg = 128)
or((MidiTmp.data2 = 0) and (MidiTmp.msg = 144))
then // NoteOff
SetValue(trigs[index], 0)
else
SetValue(trigs[index], 1);
end;
end;
end;
end.

--------------------------------------------------------------------------------

Posted: 15 Jan 2009, 22:01
by bsork
You could do it with patching using either the unpack feature of the Midi In module (if that's where the data is coming from), and there's also a Midi/Midi Tools/Midi Unpack.script that you can use to split up Midi data to one message per execution block. Anyhow, it's a small script (and mostly copy and paste from older stuff):

Code: Select all

VAR pIn, pOut, pReset &#58; tParameter;

VAR tmp &#58; tMidi;
VAR len, i &#58; integer;

PROCEDURE Init;
BEGIN
   pIn &#58;= CreateParam&#40;'midi in', ptMidi&#41;; SetIsOutput&#40;pIn, FALSE&#41;;
   pOut &#58;= CreateParam&#40;'array out', ptArray&#41;; SetIsInput&#40;pOut, FALSE&#41;;
   pReset &#58;= CreateParam&#40;'reset to 0', ptButton&#41;; SetIsOutput&#40;pReset, FALSE&#41;;

   SetLength&#40;pOut, 128&#41;;
END; // Init

// main
BEGIN
   len &#58;= GetLength&#40;pIn&#41;;
   FOR i &#58;= 0 TO &#40;len - 1&#41; DO BEGIN
      GetMidiArrayValue&#40;pIn, i, tmp&#41;;
      IF &#40;&#40;tmp.msg = 144&#41; AND &#40;tmp.data2 > 0&#41;&#41; THEN BEGIN // NoteOn
         SetDataArrayValue&#40;pOut, tmp.data1, 1&#41;;
         //writeln&#40;'NoteOn&#58;'+IntToStr&#40;tmp.data1&#41;&#41;;
      END
      ELSE IF &#40;   &#40;tmp.msg = 128&#41;
               OR &#40;&#40;tmp.msg = 144&#41; AND &#40;tmp.data2 = 0&#41;&#41;&#41; THEN BEGIN // NoteOff
         SetDataArrayValue&#40;pOut, tmp.data1, 0&#41;;
         //writeln&#40;'NoteOff&#58;'+IntToStr&#40;tmp.data1&#41;&#41;;
      END;
   END;
   IF &#40;GetValue&#40;pReset&#41; = 1&#41; THEN BEGIN
      FOR i &#58;= 0 TO 127 DO BEGIN
         SetDataArrayValue&#40;pOut, i, 0&#41;;
      END;
      SetValue&#40;pReset, 0&#41;;
   END;
END.

Posted: 17 Jan 2009, 00:13
by moody33
Thanks you Bsork!
It work like a charm and it's exactly what I need.
Thanks you again for your help.
Regards