ArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArray BrainModular BrainModular Users Forum 2007-11-30T21:07:22+02:00 https://brainmodular.org/forums/app.php/feed/topic/644 2007-11-30T21:07:22+02:00 2007-11-30T21:07:22+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3373#p3373 <![CDATA[Scripting: Newbie at work...]]>
thanks guys, worked like a charm.

antwan

Statistics: Posted by antwan — 30 Nov 2007, 20:07


]]>
2007-11-29T10:08:02+02:00 2007-11-29T10:08:02+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3335#p3335 <![CDATA[Scripting: Newbie at work...]]> We ca use a flag 'Need_Reset : boolean'

CODE:

//////////////////////////////// main proc////////////////////////////////--------------------var Need_Reset &#58; boolean;//--------------------begin  if Need_Reset   then begin     need_reset &#58;= false;     for i &#58;= 0 to 11 do SetValue&#40;trigs&#91;i&#93;, 0&#41;;  end; nbOfMidi &#58;= GetLength&#40;input&#41;;  // get the number of incoming midi codes   if nbOfMidi > 0  then begin    for i &#58;= 0 to nbOfMidi - 1 do begin       GetMidiArrayValue&#40;input, i, Miditmp&#41;;         setValue&#40;msg,MidiTmp.msg&#41;;       setValue&#40;data1,MidiTmp.data1&#41;;       setValue&#40;data2,MidiTmp.data2&#41;;         if &#40;&#40;MidiTmp.msg = 144&#41; or &#40;MidiTmp.msg = 128&#41;&#41;        and &#40;MidiTmp.data1 >= 60&#41; and &#40;MidiTmp.data1 <= 71&#41;        then begin          index &#58;= MidiTmp.data1 - 60;          if &#40;MidiTmp.msg = 128&#41;           or&#40;&#40;MidiTmp.data2 = 0&#41; and &#40;MidiTmp.msg = 144&#41;&#41;          then // NoteOff             SetValue&#40;trigs&#91;index&#93;, 0&#41;          else begin             SetValue&#40;trigs&#91;index&#93;, 1&#41;;             need_reset &#58;= true;          end;       end;    end;  end;end.
not tested but should work!

Statistics: Posted by senso — 29 Nov 2007, 09:08


]]>
2007-11-29T09:49:16+02:00 2007-11-29T09:49:16+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3332#p3332 <![CDATA[Scripting: Newbie at work...]]> Statistics: Posted by bsork — 29 Nov 2007, 08:49


]]>
2007-11-28T22:41:29+02:00 2007-11-28T22:41:29+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3327#p3327 <![CDATA[Scripting: Newbie at work...]]>
what's the proper way to script a trigger to come out of one of the ouputs?
i.e. lets say we have an output in the script module called "trigger" and under some condition I want a rapid 1 and then 0 to come out from "trigger".

thanks,

antwan

Statistics: Posted by antwan — 28 Nov 2007, 21:41


]]>
2007-11-22T15:54:32+02:00 2007-11-22T15:54:32+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3242#p3242 <![CDATA[Scripting: Newbie at work...]]>
You could try to use modules though; filter Note messages, check note number values and use a PassEventFlow module when in the right interval. If you do, please tell whether you fixed it.

Statistics: Posted by bsork — 22 Nov 2007, 14:54


]]>
2007-11-22T12:07:23+02:00 2007-11-22T12:07:23+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3236#p3236 <![CDATA[Scripting: Newbie at work...]]>
@Moody33: Are you looking for a script that filters all MIDI messages except NoteOns and NoteOffs between Note no X and Note no Y?
Yes, absolutely. I want to filter each notes of an octave. But i 'm bad in script...

Statistics: Posted by moody33 — 22 Nov 2007, 11:07


]]>
2007-11-21T22:27:34+02:00 2007-11-21T22:27:34+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3227#p3227 <![CDATA[Scripting: Newbie at work...]]>
@antwan: if you write

if MidiTmp.msg = 144 or MidiTmp.msg = 128

for most compiler it is ambiguous because it can interpreted as

if MidiTmp.msg = ((144 or MidiTmp.msg) = 128)

and generates a compilation error because 144 is not a boolean...
It's tricky, but for the first time, not my fault!

Statistics: Posted by senso — 21 Nov 2007, 21:27


]]>
2007-11-21T22:02:28+02:00 2007-11-21T22:02:28+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3226#p3226 <![CDATA[Scripting: Newbie at work...]]>
@Moody33: Are you looking for a script that filters all MIDI messages except NoteOns and NoteOffs between Note no X and Note no Y?

Statistics: Posted by bsork — 21 Nov 2007, 21:02


]]>
2007-11-21T21:21:34+02:00 2007-11-21T21:21:34+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3222#p3222 <![CDATA[Scripting: Newbie at work...]]>
I need the same script but with Midi Notes Output rather than On/Off switches...because I need the velocity output.

Anyone for scripting this? Thanks.

Statistics: Posted by moody33 — 21 Nov 2007, 20:21


]]>
2007-11-21T20:43:15+02:00 2007-11-21T20:43:15+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3215#p3215 <![CDATA[Scripting: Newbie at work...]]>
Also, dont forget that 128 = NOTE OFF
and 144 with velocity = 0 gives also a NOTE OFF

CODE:

//////////////////////////////// main proc//////////////////////////////begin nbOfMidi &#58;= GetLength&#40;input&#41;;  // get the number of incoming midi codes   if nbOfMidi > 0  then begin    for i &#58;= 0 to nbOfMidi - 1 do begin       GetMidiArrayValue&#40;input, i, Miditmp&#41;;         setValue&#40;msg,MidiTmp.msg&#41;;       setValue&#40;data1,MidiTmp.data1&#41;;       setValue&#40;data2,MidiTmp.data2&#41;;         if &#40;&#40;MidiTmp.msg = 144&#41; or &#40;MidiTmp.msg = 128&#41;&#41;        and &#40;MidiTmp.data1 >= 60&#41; and &#40;MidiTmp.data1 <= 71&#41;        then begin          index &#58;= MidiTmp.data1 - 60;          if &#40;MidiTmp.msg = 128&#41;           or&#40;&#40;MidiTmp.data2 = 0&#41; and &#40;MidiTmp.msg = 144&#41;&#41;          then // NoteOff             SetValue&#40;trigs&#91;index&#93;, 0&#41;          else             SetValue&#40;trigs&#91;index&#93;, 1&#41;;       end;    end;  end;end.

Statistics: Posted by senso — 21 Nov 2007, 19:43


]]>
2007-11-21T19:59:10+02:00 2007-11-21T19:59:10+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3212#p3212 <![CDATA[Scripting: Newbie at work...]]>
okay so I tried to follow both of your advice, but apparently did something wrong > it's giving a type mismatch. here's what i ended up with:

CODE:

//////////////////////////// Remaps each midi note from range 60-71 to triggers/////////////////////////// parameters declarationvar input   &#58; Tparameter;var msg     &#58; Tparameter;var data1   &#58; Tparameter;var data2   &#58; Tparameter;var trigs  &#58; array of Tparameter;// initialisation &#58; create parametersprocedure init;var i &#58; integer;begin   Input &#58;= CreateParam&#40;'In',ptMidi&#41;; msg &#58;= CreateParam&#40;'msg', ptdataField&#41;; data1 &#58;= CreateParam&#40;'data1', ptdataField&#41;; data2 &#58;= CreateParam&#40;'msg', ptdataField&#41;;   SetIsOutPut&#40;Input,false&#41;; SetIsInput&#40;msg, false&#41;; SetIsInput&#40;data1, false&#41;; SetIsInput&#40;data2, false&#41;; setarraylength&#40;trigs,12&#41;;  for i &#58;= 0 to 11   do begin     trigs&#91;i&#93; &#58;= CreateParam&#40;'trig'+inttostr&#40;i+1&#41;, ptSwitch&#41;;     setisInput&#40;trigs&#91;i&#93;, false&#41;;  end;end;// Global variablesvar nbOfMidi     &#58; integer;var Miditmp      &#58; TMidi;var i            &#58; integer;var index        &#58; integer;//////////////////////////////// main proc//////////////////////////////begin nbOfMidi &#58;= GetLength&#40;input&#41;;  // get the number of incoming midi codes   if nbOfMidi > 0  then begin    for i &#58;= 0 to nbOfMidi - 1 do begin       GetMidiArrayValue&#40;input, i, Miditmp&#41;;         setValue&#40;msg,MidiTmp.msg&#41;;       setValue&#40;data1,MidiTmp.data1&#41;;       setValue&#40;data2,MidiTmp.data2&#41;;       if &#40;&#40;MidiTmp.msg = 144 or MidiTmp.msg = 128&#41; and MidiTmp.data1 >= 60 and MidiTmp.data1 <= 71&#41; then begin          index &#58;= MidiTmp.data1 - 60;          if &#40;&#40;MidiTmp.msg = 144 and MidiTmp.data2 = 0&#41; or MidiTmp.msg = 128&#41; then // NoteOff             SetDataArrayValue&#40;trigs, index, 0&#41;;          else             SetDataArrayValue&#40;trigs, index, 1&#41;;       end;    end;  end;end.
where did i go wrong?
thanks

antwan

Statistics: Posted by antwan — 21 Nov 2007, 18:59


]]>
2007-11-21T09:22:05+02:00 2007-11-21T09:22:05+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3205#p3205 <![CDATA[Scripting: Newbie at work...]]>
thanks for your replies, i'm right now solving another patch but after I get it done, I'll get back to learning scripting and have a good look at your tips. When I do, I will probably have more questions about your codes. Till then! Thanks,

antwan

Statistics: Posted by antwan — 21 Nov 2007, 08:22


]]>
2007-11-20T22:18:04+02:00 2007-11-20T22:18:04+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3202#p3202 <![CDATA[Scripting: Newbie at work...]]>
I also forgot to initialize the values, which Senso remembered.

Statistics: Posted by bsork — 20 Nov 2007, 21:18


]]>
2007-11-20T20:06:15+02:00 2007-11-20T20:06:15+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3196#p3196 <![CDATA[Scripting: Newbie at work...]]> If you prefer standard switches as outputs, easier for patching, you can use an array of parameters:

CODE:

var trigs  &#58; array of Tparameter;procedure init;var i &#58; integer;begin  ... // create other params here  setarraylength&#40;trigs,12&#41;;  for i &#58;= 0 to 11   do begin     trigs&#91;i&#93; &#58;= CreateParam&#40;'trig'+inttostr&#40;i+1&#41;, ptSwitch&#41;;     setisInput&#40;trigs&#91;i&#93;, false&#41;;  end;....

Statistics: Posted by senso — 20 Nov 2007, 19:06


]]>
2007-11-20T10:31:18+02:00 2007-11-20T10:31:18+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3188#p3188 <![CDATA[Scripting: Newbie at work...]]>
I haven't tried your script (sorry, at work), but it could easily be simplified a bit to at least make it more CPU-friendly. Before I get into details, I'd like to add that the simplest way of creating a note-message-to-switch functionality in Usine would be to use MIDI learn on switches, but I guess you already knew that.

Since you're creating a lot of switches, using an output array would be the most effective and the program could have been quite a bit shorter. Without changing the structure of your program, you could for instance drop the triggerX variables (unless you're planning to expand the script of course) - you might as well just enter 0 and 1 directly into the trigX outputs. Then you could also skip the BEGIN/END pairs of the IF-THEN since you're only having one statement executed.

One thing you haven't done, is to loop through the incomming MIDI messages. If you've used the unpack feature on the MidiIn module, I guess that would work ok, but if not you could get into trouble when hitting several keys simultaniously. There are numerous examples of looping through MIDI messages in the scripts you've already have had a look at.

It might not be relevant to you, but you should also have in mind that a NoteOn with velocity = 0 (msg=144, data2=0) should also be treated as a NoteOff.

---


Here's an (untested!) example that should accomplish the same as your script using an output array, which can be accessed using various Usine modules.

CODE:

// initialisation &#58; create parametersprocedure init;begin   Input &#58;= CreateParam&#40;'In',ptMidi&#41;; msg &#58;= CreateParam&#40;'msg', ptdataField&#41;; data1 &#58;= CreateParam&#40;'data1', ptdataField&#41;; data2 &#58;= CreateParam&#40;'msg', ptdataField&#41;; trigArr &#58;= CreateParam&#40;'triggers', ptDataArray&#41;; SetLength&#40;trigArr, 12&#41;;   SetIsOutPut&#40;Input,false&#41;; SetIsInput&#40;msg, false&#41;; SetIsInput&#40;data1, false&#41;; SetIsInput&#40;data2, false&#41;; SetIsInput&#40;trigArr, false&#41;;end;// Global variablesvar nbOfMidi     &#58; integer;var Miditmp      &#58; TMidi;var i            &#58; integer;var index        &#58; integer;//////////////////////////////// main proc//////////////////////////////beginnbOfMidi &#58;= GetLength&#40;input&#41;;  // get the number of incoming midi codes   if nbOfMidi > 0  then begin    for i &#58;= 0 to nbOfMidi - 1 do begin       GetMidiArrayValue&#40;input, i, Miditmp&#41;;         setValue&#40;msg,MidiTmp.msg&#41;;       setValue&#40;data1,MidiTmp.data1&#41;;       setValue&#40;data2,MidiTmp.data2&#41;;       if &#40;&#40;MidiTmp.msg = 144 or MidiTmp.msg = 128&#41; and MidiTmp.data1 >= 60 and MidiTmp.data1 <= 71&#41; then begin          index &#58;= MidiTmp.data1 - 60;          if &#40;&#40;MidiTmp.msg = 144 and MidiTmp.data2 = 0&#41; or MidiTmp.msg = 128&#41; then // NoteOff             SetDataArrayValue&#40;trigArr, index, 0&#41;;          else             SetDataArrayValue&#40;trigArr, index, 1&#41;;       end;    end;  end;end.

Statistics: Posted by bsork — 20 Nov 2007, 09:31


]]>
2007-11-19T22:49:35+02:00 2007-11-19T22:49:35+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3186#p3186 <![CDATA[Scripting: Newbie at work...]]>
I'm taking a journey into the realms of scripting in Usine. Hands up anyone who cares to help a complete amateur!

I've spent an evening intensively looking through the forum, at script examples and the manual and I'd say I've gotten somewhere from square one but still have mileage to cover :)

I'm doing a small exercise for myself and I have a couple of questions...

First of all:
What am I trying to accomplish?
A script that takes in Midi, looks for midi notes from the range 60-71, and maps note ons and offs for each note in that range to their own little on/off switch output.

Secondly, a few questions:
1) Is this the sort of idea that is smart to carry out by scripting?
2) Could someone have a look at my code and tell me what they see... I can see it works as I intended but the script looks very long and complex to me... maybe there's something I could learn in simplifying it - and making it better coding?

Feel free to smile, as I said, I'm a first-timer!

ps. the msg, data1 & data2 outputs are there just to... you know.... monitor what's going on...

CODE:

//////////////////////////// Remaps each midi note from range 60-71 to triggers/////////////////////////// parameters declarationvar input   &#58; Tparameter;var msg     &#58; Tparameter;var data1   &#58; Tparameter;var data2   &#58; Tparameter;var trig1   &#58; Tparameter;var trig2   &#58; Tparameter;var trig3   &#58; Tparameter;var trig4   &#58; Tparameter;var trig5   &#58; Tparameter;var trig6   &#58; Tparameter;var trig7   &#58; Tparameter;var trig8   &#58; Tparameter;var trig9   &#58; Tparameter;var trig10  &#58; Tparameter;var trig11  &#58; Tparameter;var trig12  &#58; Tparameter;// initialisation &#58; create parametersprocedure init;begin   Input &#58;= CreateParam&#40;'In',ptMidi&#41;; msg &#58;= CreateParam&#40;'msg', ptdataField&#41;; data1 &#58;= CreateParam&#40;'data1', ptdataField&#41;; data2 &#58;= CreateParam&#40;'msg', ptdataField&#41;; trig1 &#58;= CreateParam&#40;'trig1', ptSwitch&#41;; trig2 &#58;= CreateParam&#40;'trig2', ptSwitch&#41;; trig3 &#58;= CreateParam&#40;'trig3', ptSwitch&#41;; trig4 &#58;= CreateParam&#40;'trig4', ptSwitch&#41;; trig5 &#58;= CreateParam&#40;'trig5', ptSwitch&#41;; trig6 &#58;= CreateParam&#40;'trig6', ptSwitch&#41;; trig7 &#58;= CreateParam&#40;'trig7', ptSwitch&#41;; trig8 &#58;= CreateParam&#40;'trig8', ptSwitch&#41;; trig9 &#58;= CreateParam&#40;'trig9', ptSwitch&#41;; trig10 &#58;= CreateParam&#40;'trig10', ptSwitch&#41;; trig11 &#58;= CreateParam&#40;'trig11', ptSwitch&#41;; trig12 &#58;= CreateParam&#40;'trig12', ptSwitch&#41;;   SetIsOutPut&#40;Input,false&#41;; SetIsInput&#40;msg, false&#41;; SetIsInput&#40;data1, false&#41;; SetIsInput&#40;data2, false&#41;; SetIsInput&#40;trig1, false&#41;; SetIsInput&#40;trig2, false&#41;; SetIsInput&#40;trig3, false&#41;; SetIsInput&#40;trig4, false&#41;; SetIsInput&#40;trig5, false&#41;; SetIsInput&#40;trig6, false&#41;; SetIsInput&#40;trig7, false&#41;; SetIsInput&#40;trig8, false&#41;; SetIsInput&#40;trig9, false&#41;; SetIsInput&#40;trig10, false&#41;; SetIsInput&#40;trig11, false&#41;; SetIsInput&#40;trig12, false&#41;; end;// Global variablesvar nbOfMidi     &#58; integer;var Miditmp      &#58; TMidi;var trigger1     &#58; integer;var trigger2     &#58; integer;var trigger3     &#58; integer;var trigger4     &#58; integer;var trigger5     &#58; integer;var trigger6     &#58; integer;var trigger7     &#58; integer;var trigger8     &#58; integer;var trigger9     &#58; integer;var trigger10    &#58; integer;var trigger11    &#58; integer;var trigger12    &#58; integer;//////////////////////////////// main proc//////////////////////////////beginnbOfMidi &#58;= GetLength&#40;input&#41;;  // get the number of incoming midi codes   if nbOfMidi > 0  then begin    GetMidiArrayValue&#40;input,0,Miditmp&#41;;      setValue&#40;msg,MidiTmp.msg&#41;;    setValue&#40;data1,MidiTmp.data1&#41;;    setValue&#40;data2,MidiTmp.data2&#41;;if &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 60&#41; then begin    trigger1 &#58;= 1;    SetValue&#40;trig1, trigger1&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 60&#41; then begintrigger1 &#58;= 0;SetValue&#40;trig1, trigger1&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 61&#41; then begin    trigger2 &#58;= 1;    SetValue&#40;trig2, trigger2&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 61&#41; then begintrigger2 &#58;= 0;SetValue&#40;trig2, trigger2&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 62&#41; then begin    trigger3 &#58;= 1;    SetValue&#40;trig3, trigger3&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 62&#41; then begintrigger3 &#58;= 0;SetValue&#40;trig3, trigger3&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 63&#41; then begin    trigger4 &#58;= 1;    SetValue&#40;trig4, trigger4&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 63&#41; then begintrigger4 &#58;= 0;SetValue&#40;trig4, trigger4&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 64&#41; then begin    trigger5 &#58;= 1;    SetValue&#40;trig5, trigger5&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 64&#41; then begintrigger5 &#58;= 0;SetValue&#40;trig5, trigger5&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 65&#41; then begin    trigger6 &#58;= 1;    SetValue&#40;trig6, trigger6&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 65&#41; then begintrigger6 &#58;= 0;SetValue&#40;trig6, trigger6&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 66&#41; then begin    trigger7 &#58;= 1;    SetValue&#40;trig7, trigger7&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 66&#41; then begintrigger7 &#58;= 0;SetValue&#40;trig7, trigger7&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 67&#41; then begin    trigger8 &#58;= 1;    SetValue&#40;trig8, trigger8&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 67&#41; then begintrigger8 &#58;= 0;SetValue&#40;trig8, trigger8&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 68&#41; then begin    trigger9 &#58;= 1;    SetValue&#40;trig9, trigger9&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 68&#41; then begintrigger9 &#58;= 0;SetValue&#40;trig9, trigger9&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 69&#41; then begin    trigger10 &#58;= 1;    SetValue&#40;trig10, trigger10&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 69&#41; then begintrigger10 &#58;= 0;SetValue&#40;trig10, trigger10&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 70&#41; then begin    trigger11 &#58;= 1;    SetValue&#40;trig11, trigger11&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 70&#41; then begintrigger11 &#58;= 0;SetValue&#40;trig11, trigger11&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 71&#41; then begin    trigger12 &#58;= 1;    SetValue&#40;trig12, trigger12&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 71&#41; then begintrigger12 &#58;= 0;SetValue&#40;trig12, trigger12&#41;;endendend.
thanks a million for your help!

/antwan

Statistics: Posted by antwan — 19 Nov 2007, 21:49


]]>
BrainModular BrainModular Users Forum 2007-11-30T21:07:22+02:00 https://brainmodular.org/forums/app.php/feed/topic/644 2007-11-30T21:07:22+02:00 2007-11-30T21:07:22+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3373#p3373 <![CDATA[Scripting: Newbie at work...]]>
thanks guys, worked like a charm.

antwan

Statistics: Posted by antwan — 30 Nov 2007, 20:07


]]>
2007-11-29T10:08:02+02:00 2007-11-29T10:08:02+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3335#p3335 <![CDATA[Scripting: Newbie at work...]]> We ca use a flag 'Need_Reset : boolean'

CODE:

//////////////////////////////// main proc////////////////////////////////--------------------var Need_Reset &#58; boolean;//--------------------begin  if Need_Reset   then begin     need_reset &#58;= false;     for i &#58;= 0 to 11 do SetValue&#40;trigs&#91;i&#93;, 0&#41;;  end; nbOfMidi &#58;= GetLength&#40;input&#41;;  // get the number of incoming midi codes   if nbOfMidi > 0  then begin    for i &#58;= 0 to nbOfMidi - 1 do begin       GetMidiArrayValue&#40;input, i, Miditmp&#41;;         setValue&#40;msg,MidiTmp.msg&#41;;       setValue&#40;data1,MidiTmp.data1&#41;;       setValue&#40;data2,MidiTmp.data2&#41;;         if &#40;&#40;MidiTmp.msg = 144&#41; or &#40;MidiTmp.msg = 128&#41;&#41;        and &#40;MidiTmp.data1 >= 60&#41; and &#40;MidiTmp.data1 <= 71&#41;        then begin          index &#58;= MidiTmp.data1 - 60;          if &#40;MidiTmp.msg = 128&#41;           or&#40;&#40;MidiTmp.data2 = 0&#41; and &#40;MidiTmp.msg = 144&#41;&#41;          then // NoteOff             SetValue&#40;trigs&#91;index&#93;, 0&#41;          else begin             SetValue&#40;trigs&#91;index&#93;, 1&#41;;             need_reset &#58;= true;          end;       end;    end;  end;end.
not tested but should work!

Statistics: Posted by senso — 29 Nov 2007, 09:08


]]>
2007-11-29T09:49:16+02:00 2007-11-29T09:49:16+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3332#p3332 <![CDATA[Scripting: Newbie at work...]]> Statistics: Posted by bsork — 29 Nov 2007, 08:49


]]>
2007-11-28T22:41:29+02:00 2007-11-28T22:41:29+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3327#p3327 <![CDATA[Scripting: Newbie at work...]]>
what's the proper way to script a trigger to come out of one of the ouputs?
i.e. lets say we have an output in the script module called "trigger" and under some condition I want a rapid 1 and then 0 to come out from "trigger".

thanks,

antwan

Statistics: Posted by antwan — 28 Nov 2007, 21:41


]]>
2007-11-22T15:54:32+02:00 2007-11-22T15:54:32+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3242#p3242 <![CDATA[Scripting: Newbie at work...]]>
You could try to use modules though; filter Note messages, check note number values and use a PassEventFlow module when in the right interval. If you do, please tell whether you fixed it.

Statistics: Posted by bsork — 22 Nov 2007, 14:54


]]>
2007-11-22T12:07:23+02:00 2007-11-22T12:07:23+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3236#p3236 <![CDATA[Scripting: Newbie at work...]]>
@Moody33: Are you looking for a script that filters all MIDI messages except NoteOns and NoteOffs between Note no X and Note no Y?
Yes, absolutely. I want to filter each notes of an octave. But i 'm bad in script...

Statistics: Posted by moody33 — 22 Nov 2007, 11:07


]]>
2007-11-21T22:27:34+02:00 2007-11-21T22:27:34+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3227#p3227 <![CDATA[Scripting: Newbie at work...]]>
@antwan: if you write

if MidiTmp.msg = 144 or MidiTmp.msg = 128

for most compiler it is ambiguous because it can interpreted as

if MidiTmp.msg = ((144 or MidiTmp.msg) = 128)

and generates a compilation error because 144 is not a boolean...
It's tricky, but for the first time, not my fault!

Statistics: Posted by senso — 21 Nov 2007, 21:27


]]>
2007-11-21T22:02:28+02:00 2007-11-21T22:02:28+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3226#p3226 <![CDATA[Scripting: Newbie at work...]]>
@Moody33: Are you looking for a script that filters all MIDI messages except NoteOns and NoteOffs between Note no X and Note no Y?

Statistics: Posted by bsork — 21 Nov 2007, 21:02


]]>
2007-11-21T21:21:34+02:00 2007-11-21T21:21:34+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3222#p3222 <![CDATA[Scripting: Newbie at work...]]>
I need the same script but with Midi Notes Output rather than On/Off switches...because I need the velocity output.

Anyone for scripting this? Thanks.

Statistics: Posted by moody33 — 21 Nov 2007, 20:21


]]>
2007-11-21T20:43:15+02:00 2007-11-21T20:43:15+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3215#p3215 <![CDATA[Scripting: Newbie at work...]]>
Also, dont forget that 128 = NOTE OFF
and 144 with velocity = 0 gives also a NOTE OFF

CODE:

//////////////////////////////// main proc//////////////////////////////begin nbOfMidi &#58;= GetLength&#40;input&#41;;  // get the number of incoming midi codes   if nbOfMidi > 0  then begin    for i &#58;= 0 to nbOfMidi - 1 do begin       GetMidiArrayValue&#40;input, i, Miditmp&#41;;         setValue&#40;msg,MidiTmp.msg&#41;;       setValue&#40;data1,MidiTmp.data1&#41;;       setValue&#40;data2,MidiTmp.data2&#41;;         if &#40;&#40;MidiTmp.msg = 144&#41; or &#40;MidiTmp.msg = 128&#41;&#41;        and &#40;MidiTmp.data1 >= 60&#41; and &#40;MidiTmp.data1 <= 71&#41;        then begin          index &#58;= MidiTmp.data1 - 60;          if &#40;MidiTmp.msg = 128&#41;           or&#40;&#40;MidiTmp.data2 = 0&#41; and &#40;MidiTmp.msg = 144&#41;&#41;          then // NoteOff             SetValue&#40;trigs&#91;index&#93;, 0&#41;          else             SetValue&#40;trigs&#91;index&#93;, 1&#41;;       end;    end;  end;end.

Statistics: Posted by senso — 21 Nov 2007, 19:43


]]>
2007-11-21T19:59:10+02:00 2007-11-21T19:59:10+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3212#p3212 <![CDATA[Scripting: Newbie at work...]]>
okay so I tried to follow both of your advice, but apparently did something wrong > it's giving a type mismatch. here's what i ended up with:

CODE:

//////////////////////////// Remaps each midi note from range 60-71 to triggers/////////////////////////// parameters declarationvar input   &#58; Tparameter;var msg     &#58; Tparameter;var data1   &#58; Tparameter;var data2   &#58; Tparameter;var trigs  &#58; array of Tparameter;// initialisation &#58; create parametersprocedure init;var i &#58; integer;begin   Input &#58;= CreateParam&#40;'In',ptMidi&#41;; msg &#58;= CreateParam&#40;'msg', ptdataField&#41;; data1 &#58;= CreateParam&#40;'data1', ptdataField&#41;; data2 &#58;= CreateParam&#40;'msg', ptdataField&#41;;   SetIsOutPut&#40;Input,false&#41;; SetIsInput&#40;msg, false&#41;; SetIsInput&#40;data1, false&#41;; SetIsInput&#40;data2, false&#41;; setarraylength&#40;trigs,12&#41;;  for i &#58;= 0 to 11   do begin     trigs&#91;i&#93; &#58;= CreateParam&#40;'trig'+inttostr&#40;i+1&#41;, ptSwitch&#41;;     setisInput&#40;trigs&#91;i&#93;, false&#41;;  end;end;// Global variablesvar nbOfMidi     &#58; integer;var Miditmp      &#58; TMidi;var i            &#58; integer;var index        &#58; integer;//////////////////////////////// main proc//////////////////////////////begin nbOfMidi &#58;= GetLength&#40;input&#41;;  // get the number of incoming midi codes   if nbOfMidi > 0  then begin    for i &#58;= 0 to nbOfMidi - 1 do begin       GetMidiArrayValue&#40;input, i, Miditmp&#41;;         setValue&#40;msg,MidiTmp.msg&#41;;       setValue&#40;data1,MidiTmp.data1&#41;;       setValue&#40;data2,MidiTmp.data2&#41;;       if &#40;&#40;MidiTmp.msg = 144 or MidiTmp.msg = 128&#41; and MidiTmp.data1 >= 60 and MidiTmp.data1 <= 71&#41; then begin          index &#58;= MidiTmp.data1 - 60;          if &#40;&#40;MidiTmp.msg = 144 and MidiTmp.data2 = 0&#41; or MidiTmp.msg = 128&#41; then // NoteOff             SetDataArrayValue&#40;trigs, index, 0&#41;;          else             SetDataArrayValue&#40;trigs, index, 1&#41;;       end;    end;  end;end.
where did i go wrong?
thanks

antwan

Statistics: Posted by antwan — 21 Nov 2007, 18:59


]]>
2007-11-21T09:22:05+02:00 2007-11-21T09:22:05+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3205#p3205 <![CDATA[Scripting: Newbie at work...]]>
thanks for your replies, i'm right now solving another patch but after I get it done, I'll get back to learning scripting and have a good look at your tips. When I do, I will probably have more questions about your codes. Till then! Thanks,

antwan

Statistics: Posted by antwan — 21 Nov 2007, 08:22


]]>
2007-11-20T22:18:04+02:00 2007-11-20T22:18:04+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3202#p3202 <![CDATA[Scripting: Newbie at work...]]>
I also forgot to initialize the values, which Senso remembered.

Statistics: Posted by bsork — 20 Nov 2007, 21:18


]]>
2007-11-20T20:06:15+02:00 2007-11-20T20:06:15+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3196#p3196 <![CDATA[Scripting: Newbie at work...]]> If you prefer standard switches as outputs, easier for patching, you can use an array of parameters:

CODE:

var trigs  &#58; array of Tparameter;procedure init;var i &#58; integer;begin  ... // create other params here  setarraylength&#40;trigs,12&#41;;  for i &#58;= 0 to 11   do begin     trigs&#91;i&#93; &#58;= CreateParam&#40;'trig'+inttostr&#40;i+1&#41;, ptSwitch&#41;;     setisInput&#40;trigs&#91;i&#93;, false&#41;;  end;....

Statistics: Posted by senso — 20 Nov 2007, 19:06


]]>
2007-11-20T10:31:18+02:00 2007-11-20T10:31:18+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3188#p3188 <![CDATA[Scripting: Newbie at work...]]>
I haven't tried your script (sorry, at work), but it could easily be simplified a bit to at least make it more CPU-friendly. Before I get into details, I'd like to add that the simplest way of creating a note-message-to-switch functionality in Usine would be to use MIDI learn on switches, but I guess you already knew that.

Since you're creating a lot of switches, using an output array would be the most effective and the program could have been quite a bit shorter. Without changing the structure of your program, you could for instance drop the triggerX variables (unless you're planning to expand the script of course) - you might as well just enter 0 and 1 directly into the trigX outputs. Then you could also skip the BEGIN/END pairs of the IF-THEN since you're only having one statement executed.

One thing you haven't done, is to loop through the incomming MIDI messages. If you've used the unpack feature on the MidiIn module, I guess that would work ok, but if not you could get into trouble when hitting several keys simultaniously. There are numerous examples of looping through MIDI messages in the scripts you've already have had a look at.

It might not be relevant to you, but you should also have in mind that a NoteOn with velocity = 0 (msg=144, data2=0) should also be treated as a NoteOff.

---


Here's an (untested!) example that should accomplish the same as your script using an output array, which can be accessed using various Usine modules.

CODE:

// initialisation &#58; create parametersprocedure init;begin   Input &#58;= CreateParam&#40;'In',ptMidi&#41;; msg &#58;= CreateParam&#40;'msg', ptdataField&#41;; data1 &#58;= CreateParam&#40;'data1', ptdataField&#41;; data2 &#58;= CreateParam&#40;'msg', ptdataField&#41;; trigArr &#58;= CreateParam&#40;'triggers', ptDataArray&#41;; SetLength&#40;trigArr, 12&#41;;   SetIsOutPut&#40;Input,false&#41;; SetIsInput&#40;msg, false&#41;; SetIsInput&#40;data1, false&#41;; SetIsInput&#40;data2, false&#41;; SetIsInput&#40;trigArr, false&#41;;end;// Global variablesvar nbOfMidi     &#58; integer;var Miditmp      &#58; TMidi;var i            &#58; integer;var index        &#58; integer;//////////////////////////////// main proc//////////////////////////////beginnbOfMidi &#58;= GetLength&#40;input&#41;;  // get the number of incoming midi codes   if nbOfMidi > 0  then begin    for i &#58;= 0 to nbOfMidi - 1 do begin       GetMidiArrayValue&#40;input, i, Miditmp&#41;;         setValue&#40;msg,MidiTmp.msg&#41;;       setValue&#40;data1,MidiTmp.data1&#41;;       setValue&#40;data2,MidiTmp.data2&#41;;       if &#40;&#40;MidiTmp.msg = 144 or MidiTmp.msg = 128&#41; and MidiTmp.data1 >= 60 and MidiTmp.data1 <= 71&#41; then begin          index &#58;= MidiTmp.data1 - 60;          if &#40;&#40;MidiTmp.msg = 144 and MidiTmp.data2 = 0&#41; or MidiTmp.msg = 128&#41; then // NoteOff             SetDataArrayValue&#40;trigArr, index, 0&#41;;          else             SetDataArrayValue&#40;trigArr, index, 1&#41;;       end;    end;  end;end.

Statistics: Posted by bsork — 20 Nov 2007, 09:31


]]>
2007-11-19T22:49:35+02:00 2007-11-19T22:49:35+02:00 https://brainmodular.org/forums/viewtopic.php?t=644&p=3186#p3186 <![CDATA[Scripting: Newbie at work...]]>
I'm taking a journey into the realms of scripting in Usine. Hands up anyone who cares to help a complete amateur!

I've spent an evening intensively looking through the forum, at script examples and the manual and I'd say I've gotten somewhere from square one but still have mileage to cover :)

I'm doing a small exercise for myself and I have a couple of questions...

First of all:
What am I trying to accomplish?
A script that takes in Midi, looks for midi notes from the range 60-71, and maps note ons and offs for each note in that range to their own little on/off switch output.

Secondly, a few questions:
1) Is this the sort of idea that is smart to carry out by scripting?
2) Could someone have a look at my code and tell me what they see... I can see it works as I intended but the script looks very long and complex to me... maybe there's something I could learn in simplifying it - and making it better coding?

Feel free to smile, as I said, I'm a first-timer!

ps. the msg, data1 & data2 outputs are there just to... you know.... monitor what's going on...

CODE:

//////////////////////////// Remaps each midi note from range 60-71 to triggers/////////////////////////// parameters declarationvar input   &#58; Tparameter;var msg     &#58; Tparameter;var data1   &#58; Tparameter;var data2   &#58; Tparameter;var trig1   &#58; Tparameter;var trig2   &#58; Tparameter;var trig3   &#58; Tparameter;var trig4   &#58; Tparameter;var trig5   &#58; Tparameter;var trig6   &#58; Tparameter;var trig7   &#58; Tparameter;var trig8   &#58; Tparameter;var trig9   &#58; Tparameter;var trig10  &#58; Tparameter;var trig11  &#58; Tparameter;var trig12  &#58; Tparameter;// initialisation &#58; create parametersprocedure init;begin   Input &#58;= CreateParam&#40;'In',ptMidi&#41;; msg &#58;= CreateParam&#40;'msg', ptdataField&#41;; data1 &#58;= CreateParam&#40;'data1', ptdataField&#41;; data2 &#58;= CreateParam&#40;'msg', ptdataField&#41;; trig1 &#58;= CreateParam&#40;'trig1', ptSwitch&#41;; trig2 &#58;= CreateParam&#40;'trig2', ptSwitch&#41;; trig3 &#58;= CreateParam&#40;'trig3', ptSwitch&#41;; trig4 &#58;= CreateParam&#40;'trig4', ptSwitch&#41;; trig5 &#58;= CreateParam&#40;'trig5', ptSwitch&#41;; trig6 &#58;= CreateParam&#40;'trig6', ptSwitch&#41;; trig7 &#58;= CreateParam&#40;'trig7', ptSwitch&#41;; trig8 &#58;= CreateParam&#40;'trig8', ptSwitch&#41;; trig9 &#58;= CreateParam&#40;'trig9', ptSwitch&#41;; trig10 &#58;= CreateParam&#40;'trig10', ptSwitch&#41;; trig11 &#58;= CreateParam&#40;'trig11', ptSwitch&#41;; trig12 &#58;= CreateParam&#40;'trig12', ptSwitch&#41;;   SetIsOutPut&#40;Input,false&#41;; SetIsInput&#40;msg, false&#41;; SetIsInput&#40;data1, false&#41;; SetIsInput&#40;data2, false&#41;; SetIsInput&#40;trig1, false&#41;; SetIsInput&#40;trig2, false&#41;; SetIsInput&#40;trig3, false&#41;; SetIsInput&#40;trig4, false&#41;; SetIsInput&#40;trig5, false&#41;; SetIsInput&#40;trig6, false&#41;; SetIsInput&#40;trig7, false&#41;; SetIsInput&#40;trig8, false&#41;; SetIsInput&#40;trig9, false&#41;; SetIsInput&#40;trig10, false&#41;; SetIsInput&#40;trig11, false&#41;; SetIsInput&#40;trig12, false&#41;; end;// Global variablesvar nbOfMidi     &#58; integer;var Miditmp      &#58; TMidi;var trigger1     &#58; integer;var trigger2     &#58; integer;var trigger3     &#58; integer;var trigger4     &#58; integer;var trigger5     &#58; integer;var trigger6     &#58; integer;var trigger7     &#58; integer;var trigger8     &#58; integer;var trigger9     &#58; integer;var trigger10    &#58; integer;var trigger11    &#58; integer;var trigger12    &#58; integer;//////////////////////////////// main proc//////////////////////////////beginnbOfMidi &#58;= GetLength&#40;input&#41;;  // get the number of incoming midi codes   if nbOfMidi > 0  then begin    GetMidiArrayValue&#40;input,0,Miditmp&#41;;      setValue&#40;msg,MidiTmp.msg&#41;;    setValue&#40;data1,MidiTmp.data1&#41;;    setValue&#40;data2,MidiTmp.data2&#41;;if &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 60&#41; then begin    trigger1 &#58;= 1;    SetValue&#40;trig1, trigger1&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 60&#41; then begintrigger1 &#58;= 0;SetValue&#40;trig1, trigger1&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 61&#41; then begin    trigger2 &#58;= 1;    SetValue&#40;trig2, trigger2&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 61&#41; then begintrigger2 &#58;= 0;SetValue&#40;trig2, trigger2&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 62&#41; then begin    trigger3 &#58;= 1;    SetValue&#40;trig3, trigger3&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 62&#41; then begintrigger3 &#58;= 0;SetValue&#40;trig3, trigger3&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 63&#41; then begin    trigger4 &#58;= 1;    SetValue&#40;trig4, trigger4&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 63&#41; then begintrigger4 &#58;= 0;SetValue&#40;trig4, trigger4&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 64&#41; then begin    trigger5 &#58;= 1;    SetValue&#40;trig5, trigger5&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 64&#41; then begintrigger5 &#58;= 0;SetValue&#40;trig5, trigger5&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 65&#41; then begin    trigger6 &#58;= 1;    SetValue&#40;trig6, trigger6&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 65&#41; then begintrigger6 &#58;= 0;SetValue&#40;trig6, trigger6&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 66&#41; then begin    trigger7 &#58;= 1;    SetValue&#40;trig7, trigger7&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 66&#41; then begintrigger7 &#58;= 0;SetValue&#40;trig7, trigger7&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 67&#41; then begin    trigger8 &#58;= 1;    SetValue&#40;trig8, trigger8&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 67&#41; then begintrigger8 &#58;= 0;SetValue&#40;trig8, trigger8&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 68&#41; then begin    trigger9 &#58;= 1;    SetValue&#40;trig9, trigger9&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 68&#41; then begintrigger9 &#58;= 0;SetValue&#40;trig9, trigger9&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 69&#41; then begin    trigger10 &#58;= 1;    SetValue&#40;trig10, trigger10&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 69&#41; then begintrigger10 &#58;= 0;SetValue&#40;trig10, trigger10&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 70&#41; then begin    trigger11 &#58;= 1;    SetValue&#40;trig11, trigger11&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 70&#41; then begintrigger11 &#58;= 0;SetValue&#40;trig11, trigger11&#41;;endif &#40;MidiTmp.msg = 144&#41; and &#40;MidiTmp.data1 = 71&#41; then begin    trigger12 &#58;= 1;    SetValue&#40;trig12, trigger12&#41;;endif &#40;MidiTmp.msg = 128&#41; and &#40;MidiTmp.data1 = 71&#41; then begintrigger12 &#58;= 0;SetValue&#40;trig12, trigger12&#41;;endendend.
thanks a million for your help!

/antwan

Statistics: Posted by antwan — 19 Nov 2007, 21:49


]]>