Welcome to %s forums

BrainModular Users Forum

Login Register

Sending Midi Via script

I need help on a Patch
Post Reply
styro
Member
Posts: 11
Contact:

Sending Midi Via script

Unread post by styro » 23 Nov 2023, 14:01

Hello
Somehow i don't get how to send MIDI...

how does the MIDIOut TParameters works, whats the meaning of the first parameter (index)?

procedure TParameter.asMidi(index : integer; val : TMIDI); // set the value of a MIDI parameter at the index

i made a simple script, it works somehow, what is really puzzleing is that there is permanently sending the MIDI of the state,
not only one time when the state is changing? The wire from the MIDIOut-Port to the MIDI-device has permanent traffic...


many thanks for any help!

styro


//GLOBAL VARIABLES AND TPARAMETER DECLARATIONS
var StateInput : TParameter;

var LastInput : TParameter;

var MIDIOut : TParameter;

var MIDINotex : TMidi;

var countdown : Integer;

var testmode : Integer;

//PROCESS
PROCEDURE PROCESS();
BEGIN
testmode := testmode +1;
if LastInput <> StateInput.asInteger
then
BEGIN
LastInput:=StateInput.asInteger;
Trace('MIDITest input has changed State:' + inttostr(LastInput) );
Trace(testmode);
CASE LastInput OF
0: Begin
MIDINotex.msg := 128;
MIDINotex.data1 := 0;
MIDINotex.data2 := 0;
MIDIOut.asMidi(0,MIDINotex);
MIDINotex.msg := 128;
MIDINotex.data1 := 1;
MIDINotex.data2 := 0;
MIDIOut.asMidi(1,MIDINotex);

End;
1: Begin
MIDINotex.msg := 144;
MIDINotex.data1 := 0;
MIDINotex.data2 := 127;
MIDIOut.asMidi(0,MIDINotex);
MIDINotex.msg := 144;
MIDINotex.data1 := 1;
MIDINotex.data2 := 127;
MIDIOut.asMidi(1,MIDINotex);
End;
2: Begin
MIDINotex.msg := 144;
MIDINotex.data1 := 4;
MIDINotex.data2 := 127;
MIDIOut.asMidi(0,MIDINotex);
MIDINotex.msg := 144;
MIDINotex.data1 := 5;
MIDINotex.data2 := 127;
MIDIOut.asMidi(1,MIDINotex);
End;
3: Begin
MIDINotex.msg := 128;
MIDINotex.data1 := 0;
MIDINotex.data2 := 0;
MIDIOut.asMidi(0,MIDINotex);
MIDINotex.msg := 128;
MIDINotex.data1 := 1;
MIDINotex.data2 := 0;
MIDIOut.asMidi(1,MIDINotex);
End;
4: Begin
MIDINotex.msg := 128;
MIDINotex.data1 := 4;
MIDINotex.data2 := 0;
MIDIOut.asMidi(0,MIDINotex);
MIDINotex.msg := 128;
MIDINotex.data1 := 5;
MIDINotex.data2 := 0;
MIDIOut.asMidi(1,MIDINotex);
End;
5: Begin
End;
6: Begin
End;
7: Begin
End;
8: Begin
End;
9: Begin
End;
10: Begin
End;
11: Begin
End;
End;//END MAIN CASE
END
END;

//INIT PROCEDURE
PROCEDURE INIT();
BEGIN

StateInput:=CreateParam('State',ptDataFader,pioInput);
StateInput.Min(0);
StateInput.Max(100);


MIDIOut := CreateParam('MIDIOut',ptMidi,pioOutput);
testmode := 0;

END;

procedure ProcessThread;
var inval : single;
begin

end;

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 26 Nov 2023, 15:41

I reckon you should put your code into a callback, then it will run only when a new event is received.
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

styro
Member
Posts: 11
Contact:

Unread post by styro » 27 Nov 2023, 14:13

Many thanks for Your Answer,
Unfortunately putting the things in the callback procedure doesn't help, the MIDI-Out commands just keep on sending,
my midi-interface transmit-led keeps on blinking like wild while all the MIDI-Note from a state are sent repeatedly.
Thats really wired, its like that a buffer holding the MIDI-Notes is not cleared after sending.
The states-input changes not fast, it's connected to a increment button and a counter.
When i put a pass-change module on the midi-out-port of the script is works, so that the notes are only sent one time,
but this would be a really ugly kludge, and i would like to know how to solve this error in the script.

many thanks for some help and all the best
styro

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 29 Nov 2023, 01:21

I did some tests and lodge a bug report to Senso

Cheers
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

styro
Member
Posts: 11
Contact:

Unread post by styro » 30 Nov 2023, 01:10

Many thanks for Your help!
cheers styro

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 30 Nov 2023, 14:03

this works, although the .channel does not yet,


//GLOBAL VARIABLES AND TPARAMETER DECLARATIONS
var StateInput : TParameter;

var LastInput : TParameter;

var MIDIOut : TParameter;

var MIDINotex1,MIDINotex2 : TMidi;

var countdown : Integer;

var testmode : Integer;

var flag : Integer;


//INIT PROCEDURE
PROCEDURE INIT();
BEGIN

StateInput:=CreateParam('State',ptDataFader,pioInput);
StateInput.Min(0);
StateInput.Max(100);


MIDIOut := CreateParam('MIDIOut',ptMidi,pioOutput);
testmode := 0;

END;

procedure ProcessThread;
//var inval : single;
begin

end;

PROCEDURE CALLBACK(N:INTEGER);
BEGIN
CASE N OF
lastInput: Begin

testmode := testmode +1;
Trace('MIDITest input has changed State:' + inttostr(LastInput) );
Trace(testmode);
flag := 1;

CASE LastInput.asInteger OF
0: Begin
trace('case 0');
MIDINotex1.msg := 144;
MIDINotex1.data1 := 64;
MIDINotex1.data2 := 127;
//MIDINotex.Channel(2):
MIDIOut.Length(2);
MIDIOut.asMidi(0,MIDINotex1);
MIDINotex2.msg := 128;
MIDINotex2.data1 := 64;
MIDINotex2.data2 := 0;
//MIDINotex.Channel(3):
MIDIOut.asMidi(1,MIDINotex2);

End;
1: Begin
trace('case 1');
MIDINotex1.msg := 144;
MIDINotex1.data1 := 0;
MIDINotex1.data2 := 127;

MIDINotex2.msg := 144;
MIDINotex2.data1 := 1;
MIDINotex2.data2 := 127;
End;
2: Begin
MIDINotex1.msg := 144;
MIDINotex1.data1 := 4;
MIDINotex1.data2 := 127;

MIDINotex2.msg := 144;
MIDINotex2.data1 := 5;
MIDINotex2.data2 := 127;

End;
3: Begin
MIDINotex1.msg := 128;
MIDINotex1.data1 := 0;
MIDINotex1.data2 := 0;

MIDINotex2.msg := 128;
MIDINotex2.data1 := 1;
MIDINotex2.data2 := 0;

End;
4: Begin
MIDINotex1.msg := 128;
MIDINotex1.data1 := 4;
MIDINotex1.data2 := 0;

MIDINotex2.msg := 128;
MIDINotex2.data1 := 5;
MIDINotex2.data2 := 0;

End;
5: Begin
End;
6: Begin
End;
7: Begin
End;
8: Begin
End;
9: Begin
End;
10: Begin
End;
11: Begin
End;
End;//END CASE
END
END;
END;

//PROCESS
PROCEDURE PROCESS();
BEGIN

if flag = 1
then
BEGIN
flag:=0;
MIDIOut.Length(2);
MIDIOut.asMidi(0,MIDINotex1);
MIDIOut.asMidi(1,MIDINotex2);
END
else
MIDIOut.Length(0);

END;
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

styro
Member
Posts: 11
Contact:

Unread post by styro » 05 Dec 2023, 16:58

Thanks very much!!
i could change the script accordingly and it seems to work, but it looks a little hacky....

many thanks for Your help and all the best!

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 08 Dec 2023, 01:49

my bad, the channel selection is OC :

//GLOBAL VARIABLES AND TPARAMETER DECLARATIONS
var StateInput : TParameter;

var LastInput : TParameter;

var MIDIOut : TParameter;

var MIDINotex1,MIDINotex2 : TMidi;

var countdown : Integer;

var testmode : Integer;

var flag : Integer;


//INIT PROCEDURE
PROCEDURE INIT();
BEGIN

StateInput:=CreateParam('State',ptDataFader,pioInput);
StateInput.Min(0);
StateInput.Max(100);


MIDIOut := CreateParam('MIDIOut',ptMidi,pioOutput);
testmode := 0;

END;

procedure ProcessThread;
//var inval : single;
begin

end;

PROCEDURE CALLBACK(N:INTEGER);
BEGIN
CASE N OF
lastInput: Begin

testmode := testmode +1;
Trace('MIDITest input has changed State:' + inttostr(LastInput) );
Trace(testmode);
flag := 1;

CASE LastInput.asInteger OF
0: Begin
trace('case 0');
MIDINotex1.msg := 144;
MIDINotex1.data1 := 64;
MIDINotex1.data2 := 127;
MIDINotex1.Channel:= 2;
MIDIOut.Length(2);
MIDIOut.asMidi(0,MIDINotex1);
MIDINotex2.msg := 128;
MIDINotex2.data1 := 64;
MIDINotex2.data2 := 0;
MIDINotex2.Channel:= 10;
MIDIOut.asMidi(1,MIDINotex2);

End;
1: Begin
trace('case 1');
MIDINotex1.msg := 144;
MIDINotex1.data1 := 0;
MIDINotex1.data2 := 127;

MIDINotex2.msg := 144;
MIDINotex2.data1 := 1;
MIDINotex2.data2 := 127;
End;
2: Begin
MIDINotex1.msg := 144;
MIDINotex1.data1 := 4;
MIDINotex1.data2 := 127;

MIDINotex2.msg := 144;
MIDINotex2.data1 := 5;
MIDINotex2.data2 := 127;

End;
3: Begin
MIDINotex1.msg := 128;
MIDINotex1.data1 := 0;
MIDINotex1.data2 := 0;

MIDINotex2.msg := 128;
MIDINotex2.data1 := 1;
MIDINotex2.data2 := 0;

End;
4: Begin
MIDINotex1.msg := 128;
MIDINotex1.data1 := 4;
MIDINotex1.data2 := 0;

MIDINotex2.msg := 128;
MIDINotex2.data1 := 5;
MIDINotex2.data2 := 0;

End;
5: Begin
End;
6: Begin
End;
7: Begin
End;
8: Begin
End;
9: Begin
End;
10: Begin
End;
11: Begin
End;
End;//END CASE
END
END;
END;

//PROCESS
PROCEDURE PROCESS();
BEGIN

if flag = 1
then
BEGIN
flag:=0;
MIDIOut.Length(2);
MIDIOut.asMidi(0,MIDINotex1);
MIDIOut.asMidi(1,MIDINotex2);
END
else
MIDIOut.Length(0);

END;
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests