Welcome to %s forums

BrainModular Users Forum

Login Register

infinte note off

I need help on a Patch
Post Reply
pansoul
Member
Posts: 39
Contact:

Unread post by pansoul » 03 Mar 2009, 22:53

hello

i try to do a sequencer script and i have a problem with generating midi event.
here a small part of my script that i wrote to find where my problem come from.

beat = GetValue(beat-synchro-externe);

if (beat = 2)
then begin
setvalue(Out-data,88);
end
else begin
setvalue(Out-data,89);
end
this script works well it means that when the
beat value is 2 it generates 88 else it generates 89 (when the beat value is 1,3 or 4)

but when i try to create a midi note in place of value 89 it generates infinite note on, on every beat value.
beat = GetValue(beat-synchro-externe);

if (beat = 2)
then begin
setvalue(Out-data,88);
end
else begin
Midi-note.Msg := 144;
Midi-note.Data1 := 37;
Midi-note.Data2 := 100;
Midi-note.Channel := 4;
SetMidiArrayValue(out-mid,0,Midi-note);
SetLength(out-mid,1);
end
is there a problem in my way of generating midi ?

thanks
Vincent

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 04 Mar 2009, 00:01

Not a problem per se, just missing NoteOffs. I don't quite understand how you want this to behave, but the simplest way to generate NoteOffs is using the Midi Transformer with length > 0, which will give a gate length in milliseconds.

You may do this somewhere in your script, but I'd like to add this anyway: Remember to set the length of the Midi array to 0 when it's not supposed to send any messages, else you will be sending the same message for every block execution. You should take a look at some of the included Midi scripts in the distro and/or download some of add-ons.
Bjørn S

pansoul
Member
Posts: 39
Contact:

Unread post by pansoul » 04 Mar 2009, 00:19

oops sorry but i didn't explain myself correctly. when i say "infinte noteon" i mean that hundred of note on are produced in a few seconds (it is the same if replace noteon - 144 by noteoff -128 ).

what i explain in this example is not what i want to do. Actually i don't need 'if else end' statement but only 'if end' and i don't need to produce 88 or 89 anymore but it is a test to see that when i produce a value like 88 , it is generated only one time and when i produce noteon or off , hundred times.

the behaviour i want is :
-beat 1 read array 1
-beat 2 read array 2
-beat 3 read array 3
and so on but i can't solve this inopportune "infinite noteon"

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 04 Mar 2009, 09:18

Your problem is what I described at the end of my post: You have to empty the array between each NoteOn with SetLength(<midi_out_parameter_name>, 0) since the array is read once for each execution block.

You can see an example in for instance the ScriptsMidiTranspose.script in the distro. Here's the main loop:

Code: Select all

begin
 nbOfMidi &#58;= GetLength&#40;input&#41;;  // get the number of incoming midi codes  
 if nbOfMidi > 0 
 then begin
    SetLength&#40;outPut,nbOfMidi&#41;;      // set the number of output codes
    transpoVal &#58;= getValue&#40;transpo&#41;; // get the transpo value
    for i &#58;= 0 to nbOfMidi-1         // loop for all input codes, for polyphonic data &#40;chords&#41;
    do begin
      GetMidiArrayValue&#40;input,i,ReceivedMidi&#41;; // get each code
      ReceivedMidi.data1 &#58;= ReceivedMidi.data1+trunc&#40;transpoVal&#41;; // calculate transpo
      SetMidiArrayValue&#40;output,i,ReceivedMidi&#41;; // set output value     
    end;
 end 
 else SetLength&#40;outPut,0&#41;; // nothing received, set out length to 0

end.
One thing that isn't obvious, is that you don't have to to set the length before filling in the output data, so the above example could also be done like this:

Code: Select all

begin
 nbOfMidi &#58;= GetLength&#40;input&#41;;  // get the number of incoming midi codes  
 if nbOfMidi > 0 
 then begin
    transpoVal &#58;= getValue&#40;transpo&#41;; // get the transpo value
    for i &#58;= 0 to nbOfMidi-1         // loop for all input codes, for polyphonic data &#40;chords&#41;
    do begin
      GetMidiArrayValue&#40;input,i,ReceivedMidi&#41;; // get each code
      ReceivedMidi.data1 &#58;= ReceivedMidi.data1+trunc&#40;transpoVal&#41;; // calculate transpo
      SetMidiArrayValue&#40;output,i,ReceivedMidi&#41;; // set output value     
    end;
 end; 
 SetLength&#40;outPut, nbOfMidi&#41;;
end.
Bjørn S

pansoul
Member
Posts: 39
Contact:

Unread post by pansoul » 04 Mar 2009, 19:58

ok it works well now
thanks
Vincent

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests