ArrayArrayArrayArrayArrayArray BrainModular BrainModular Users Forum 2010-03-07T12:54:56+02:00 https://brainmodular.com/forums/app.php/feed/topic/1992 2010-03-07T12:54:56+02:00 2010-03-07T12:54:56+02:00 https://brainmodular.com/forums/viewtopic.php?t=1992&p=12380#p12380 <![CDATA[script efficiencies....]]> Statistics: Posted by bsork — 07 Mar 2010, 11:54


]]>
2010-03-07T04:03:00+02:00 2010-03-07T04:03:00+02:00 https://brainmodular.com/forums/viewtopic.php?t=1992&p=12369#p12369 <![CDATA[script efficiencies....]]>
-e

Statistics: Posted by woodslanding — 07 Mar 2010, 03:03


]]>
2010-03-06T13:23:11+02:00 2010-03-06T13:23:11+02:00 https://brainmodular.com/forums/viewtopic.php?t=1992&p=12338#p12338 <![CDATA[script efficiencies....]]> Statistics: Posted by senso — 06 Mar 2010, 12:23


]]>
2010-03-06T09:54:38+02:00 2010-03-06T09:54:38+02:00 https://brainmodular.com/forums/viewtopic.php?t=1992&p=12305#p12305 <![CDATA[script efficiencies....]]> Statistics: Posted by gurulogic — 06 Mar 2010, 08:54


]]>
2010-03-06T09:09:25+02:00 2010-03-06T09:09:25+02:00 https://brainmodular.com/forums/viewtopic.php?t=1992&p=12300#p12300 <![CDATA[script efficiencies....]]> Statistics: Posted by 23fx23 — 06 Mar 2010, 08:09


]]>
2010-03-06T05:19:13+02:00 2010-03-06T05:19:13+02:00 https://brainmodular.com/forums/viewtopic.php?t=1992&p=12298#p12298 <![CDATA[script efficiencies....]]>
I'm wondering, though (and this is mostly directed at Bsork) whether there are any obvious inefficiencies in it, as I'm trying to save processing power wherever I can....

Any tips appreciated as always!

CODE:

&#40;*/////////////////////////////////////////////////////// CHANNEL  // Version 2009-11-21; author&#58; eric moon//// based on work by Bsork and amiga909//////////////////////////////////////////////////////*&#41;//  MIDI Channel Strip&#58;//  it is designed to function as part of a mixer channel strip, running between several keyboards and a vsti.//   takes a number of midi inputs &#40;on separate cables, for visual clarity&#41;//  and performs the following operations on each.//  enable, disable--per input//  strip CCs and send them out a separate output//  read CC64 values &#40;or a CC of your choice&#41; to withhold noteoffs until the sus pedal is released.//  limit to minimum and maximum notes--one range affects all inputs//  transpose--again, one range for all inputs.//  output rechannelizing--all outs are a single channel.  Use multiple strips to control multi-timbral modules.//  bypass output for turning off unused instruments.  waits for all notes to be released....//  Drone switch that keeps current notes sounding, but discards all note input as long as it is held//  Midi learn for note range&#58;//  When learn is turned on, midi note output is suspended//   the first noteNumber sets the low end of the range, the second noteNumber sets the upper limit.//   once both notes are sent, notes go to main output  as usual.//   support for inverse range, if low note is above high noteCONST SUS_PED= 64;    //change if you use an unorthodox CC for sustaining.CONST INPUT_COUNT = 2;  // could handle any number, I think!CONST NOTEON        = Byte&#40;144&#41;;CONST NOTEOFF       = Byte&#40;128&#41;;CONST CONTROL       = Byte&#40;176&#41;;CONST PITCHBEND     = Byte&#40;224&#41;;CONST AFTERTOUCH    = Byte&#40;208&#41;;VAR   heldNotes                    &#58; ARRAY OF boolean;VAR   transList                    &#58; ARRAY OF integer; VAR   isEnabled                    &#58; Array of boolean;VAR   pMidiINS,pEnableINS          &#58; ARRAY OF TParameter;VAR   midiInCounts                 &#58; ARRAY OF integer;VAR   pTranspIN, pDroneIN,pOutChanIN, pLearnIN, pLowNoteIn, pHiNoteIn  &#58; TParameter;       VAR   pPassOut,pRejectOut,pBypassOut, pLowNoteOut, pHiNoteOut                   &#58; Tparameter;       VAR   transpose, hiVal, lowVal                                 &#58; integer; VAR   passCount, rejectCount, learnCount, minKey, maxKey, outChan               &#58; integer;VAR   isSustaining, isLearning, isDroning, doRelease, bypassReady               &#58; boolean;///////////////////////////      INITIALIZE        /////////////////////////////////////PROCEDURE init; VAR i &#58; integer;   BEGIN      transpose &#58;= 0; transpose &#58;= 0; hiVal&#58;= 120; lowVal &#58;= 12;    passCount &#58;= 0; rejectCount &#58;= 0; learnCount &#58;= 0; minKey &#58;= 128; maxKey &#58;= 0; outChan &#58;= 1;    isSustaining &#58;= FALSE; isLearning &#58;= FALSE; isDroning &#58;= FALSE; doRelease &#58;= FALSE; bypassReady &#58;= FALSE;        setArrayLength&#40;pMidiINS, INPUT_COUNT&#41;;    setArrayLength&#40;pEnableINS, INPUT_COUNT&#41;;    setArrayLength&#40;isEnabled, INPUT_COUNT&#41;;    setArrayLength&#40;midiInCounts, INPUT_COUNT&#41;;   FOR i&#58;=0 TO INPUT_COUNT   DO midiInCounts&#91;i&#93;&#58;=0;    setArrayLength&#40;heldNotes, 128&#41;;               FOR i&#58;=0 TO 127           DO heldNotes&#91;i&#93;&#58;=FALSE;    SetArrayLength&#40;transList, 128&#41;;              FOR i&#58;=0 TO 127           DO transList&#91;i&#93;&#58;=0;        FOR i &#58;= 0 TO INPUT_COUNT - 1 DO  BEGIN        pEnableINS&#91;i&#93;  &#58;= CreateParam&#40;'enable ' + intToStr&#40;i + 1&#41;,ptSwitch&#41;;                SetIsOutPut&#40;pEnableINS&#91;i&#93;,false&#41;;            END;        pBypassOut       &#58;= CreateParam&#40;'inst bypass', ptSwitch&#41;;       SetIsInput&#40;pBypassOut,false&#41;;        pTranspIN        &#58;= CreateParam&#40;'trans',ptDataFader&#41;;          SetIsOutPut&#40;pTranspIN,false&#41;;      pOutChanIN       &#58;= CreateParam&#40;'out ch',ptMidiNoteFader&#41;;      SetIsOutPut&#40;pOutChanIN,false&#41;;    pLearnIN         &#58;= CreateParam&#40;'learn',ptButton&#41;;              SetIsOutPut&#40;pLearnIN,false&#41;;    pHiNoteIN        &#58;= CreateParam&#40;'high note',ptMidiNoteFader&#41;;   SetIsOutPut&#40;pHiNoteIN,false&#41;;    pHiNoteOUT        &#58;= CreateParam&#40;'hi note', ptDataField&#41;;         SetIsInPut&#40;pHiNoteOut,false&#41;;     pLowNoteIN       &#58;= CreateParam&#40;'low note',ptMidiNoteFader&#41;;    SetIsOutPut&#40;pLowNoteIN,false&#41;;    pLowNoteOUT       &#58;= CreateParam&#40;'low note',ptDataField&#41;;         SetIsInPut&#40;pLowNoteOut,false&#41;;    pDroneIN         &#58;= CreateParam&#40;'drone', ptSwitch&#41;;             SetIsOutput&#40;pDroneIN,false&#41;;           SetFormat&#40;pTranspIN,'%.0f'&#41;;    SetMin&#40;pTranspIN,-48&#41;;  SetMax&#40;pTranspIN,48&#41;;        SetFormat&#40;pOutChanIN,'%.0f'&#41;;   SetMin&#40;pOutChanIN,1&#41;;  SetMax&#40;pOutChanIN,16&#41;;           FOR i &#58;= 0 TO INPUT_COUNT - 1 DO  BEGIN        pMidiINS&#91;i&#93;  &#58;= CreateParam&#40;'MIDIin ' + intToStr&#40;i + 1&#41; ,ptMidi&#41;;               SetIsOutPut&#40;pMidiINS&#91;i&#93;,false&#41;;    END;        pPassOut          &#58;= CreateParam&#40;'passed MIDI',ptMidi&#41;;           SetIsInput&#40;pPassOut,false&#41;;      pRejectOut        &#58;= CreateParam&#40;'rejected MIDI',ptMidi&#41;;         SetIsInput&#40;pRejectOut,false&#41;;END;   ///////////////////////////  MIDI OUTPUT METHODS   ////////////////////////////////////PROCEDURE PassOut&#40;midi &#58; tMidi&#41;;BEGIN   midi.channel &#58;= BYTE&#40;outChan&#41;;   SetMidiArrayValue&#40;pPassOut, passCount, midi&#41;;   passCount &#58;= passCount + 1;END;PROCEDURE RejectOut&#40;midi &#58; tMidi&#41;;BEGIN   midi.channel &#58;= BYTE&#40;outChan&#41;;   SetMidiArrayValue&#40;pRejectOut, rejectCount, midi&#41;;   rejectCount &#58;= rejectCount + 1;END;/////////////////////////   MIDI MESSAGE TESTS  ///////////////////////////////////////FUNCTION IsNote &#40;midi &#58; tMidi&#41; &#58; Boolean;BEGIN   IsNote &#58;= &#40;&#40;midi.msg = NOTEON&#41; OR &#40;midi.msg = NOTEOFF&#41;&#41;;END;FUNCTION IsNoteOn &#40;midi &#58; tMidi&#41; &#58; Boolean;BEGIN   IsNoteOn &#58;= &#40;&#40;midi.msg = NOTEON&#41; AND &#40;midi.data2 > 0&#41;&#41;;END;FUNCTION IsNoteOff &#40;midi &#58; tMidi&#41; &#58; Boolean;BEGIN   IsNoteOff &#58;= &#40;midi.msg = NOTEOFF&#41; OR &#40;&#40;midi.msg = NOTEON&#41; AND &#40;midi.data2 = 0&#41;&#41;;END;FUNCTION IsSustain &#40;midi &#58; tMidi&#41; &#58; Boolean;BEGIN    IsSustain &#58;= &#40;midi.msg = CONTROL&#41;  AND &#40;midi.data1 = SUS_PED&#41;;END;//////////////////////////      OTHER TESTS     ////////////////////////////////////////FUNCTION UpdateBypass&#40;&#41;  &#58;  INTEGER;VAR i  &#58; integer;BEGIN     bypassReady &#58;= TRUE;      FOR i &#58;= 0 to &#40;INPUT_COUNT - 1&#41; DO BEGIN        if isEnabled&#91;i&#93; THEN BEGIN            bypassReady &#58;= FALSE;            setValue&#40;pBypassOut, 0&#41;;        END;    END;    IF bypassReady AND isClear&#40;&#41; THEN setValue&#40;pBypassOUT, 1&#41;;       END; FUNCTION isInRange&#40;noteNumber &#58; integer &#41; &#58; Boolean;VAR inRange &#58; Boolean;VAR reversed &#58; Boolean;BEGIN    reversed &#58;= &#40;lowVal >= hiVal&#41;;    IF reversed THEN isInRange &#58;= &#40;noteNumber < hiVal&#41;  OR  &#40;noteNumber > lowVal&#41;                ELSE isInRange &#58;= &#40;noteNumber <= hiVal&#41; AND &#40;noteNumber >= lowVal&#41;; END;////////////////////////       SETTERS       ////////////////////////////////////////////PROCEDURE SetLowVal&#40;n &#58; integer&#41;;BEGIN    setValue&#40;pLowNoteOut, n&#41;;    lowVal &#58;= n;END;PROCEDURE SetHiVal&#40;n &#58; integer&#41;;BEGIN    setValue&#40;pHiNoteOut, n&#41;;    hiVal &#58;= n;END;////////////////////////     PROCESS MIDI    ////////////////////////////////////////////FUNCTION bstr&#40;b &#58; boolean&#41; &#58; string;BEGIN if b THEN bstr &#58;= 'TRUE' else bstr &#58;= 'FALSE'; END;PROCEDURE ProcessMidi&#40;midi &#58; tMidi; enabled &#58; boolean&#41;;BEGIN    IF isLearning THEN processLearn&#40;midi&#41;     ELSE IF not&#40;isDroning&#41; THEN BEGIN        IF isSustain&#40;midi&#41; THEN BEGIN            isSustaining &#58;= midi.data2 > 64;            if NOT&#40;isSustaining&#41; THEN doRelease &#58;= TRUE;                END                   // pass PB and AT with notes        ELSE IF &#40;midi.msg = PITCHBEND&#41; OR &#40;midi.msg = AFTERTOUCH&#41; THEN passOut&#40;midi&#41;        ELSE IF NOT&#40;IsNote&#40;midi&#41;&#41; THEN rejectOut&#40;midi&#41;        // everything else deals with note data....        ELSE IF IsInRange&#40;midi.data1&#41;and enabled THEN BEGIN            IF isNoteOn&#40;midi&#41; THEN BEGIN                ProcessNoteOn&#40;midi, enabled&#41;;            END ELSE BEGIN                       ProcessNoteOff&#40;midi&#41;            END;        END ELSE rejectOut&#40;midi&#41;; //notes that are out of range        IF doRelease THEN sendNoteOffs&#40;false&#41;;    END;  END;PROCEDURE ProcessLearn&#40;midi &#58; tMidi&#41;;BEGIN    IF &#40;isNoteOn&#40;midi&#41;&#41; and &#40;learnCount = 0&#41; THEN BEGIN        lowVal &#58;= midi.data1;        setValue&#40;pLowNoteOUT, lowVal&#41;;        learnCount &#58;= 1;                       END     ELSE IF &#40;isNoteOn&#40;midi&#41;&#41; and &#40;learnCount = 1&#41;  THEN BEGIN        hiVal &#58;= midi.data1;        setValue&#40;pHiNoteOUT, hiVal&#41;;        learnCount &#58;= 0;        isLearning &#58;= FALSE;  // we've set our outs....    END;END;PROCEDURE ProcessNoteOn&#40;midi &#58; tMidi; enabled &#58; boolean&#41;;BEGIN    IF enabled THEN BEGIN        transList&#91;midi.data1&#93; &#58;= transpose;         midi.data1 &#58;= midi.data1 + transpose;        PassOut&#40;midi&#41;;        heldNotes&#91;midi.data1&#93; &#58;= TRUE;    END;END;PROCEDURE ProcessNoteOff&#40;midi &#58; Tmidi&#41;;BEGIN    midi.data1 &#58;= midi.data1 + transList&#91;midi.data1&#93;;    heldNotes&#91;midi.data1&#93; &#58;= FALSE;    IF isSustaining THEN  storeNoteOff&#40;midi&#41; ELSE  PassOut&#40;midi&#41;;    IF bypassReady AND isClear&#40;&#41; THEN  BEGIN        setValue&#40;pBypassOut, 1&#41;;        isSustaining &#58;= FALSE;        isDroning &#58;= FALSE;        bypassReady &#58;= FALSE;    END;END;PROCEDURE storeNoteOff&#40;midi &#58; tMidi&#41;;BEGIN         // is this all we're doing here?  should this be in the method above??    IF &#40;midi.data1 > maxKey&#41; THEN maxKey &#58;= midi.data1;    IF &#40;midi.data1 < minKey&#41; THEN minKey &#58;= midi.data1;  END;PROCEDURE ProcessDrone&#40;n &#58; integer&#41;;BEGIN    IF n = 0 THEN SendNoteOffs&#40;TRUE&#41;;    isSustaining &#58;= FALSE;    isDroning &#58;= n > 0;   END;FUNCTION isClear&#40;&#41; &#58; boolean;VAR key &#58; integer; VAR clear &#58; boolean;BEGIN    clear &#58;= TRUE;    FOR key&#58;= minKey TO maxKey DO IF heldNotes&#91;key&#93; = TRUE THEN clear &#58;= FALSE;    isClear &#58;= clear;END;PROCEDURE SendNoteOffs&#40;closeAll &#58; boolean&#41;;VAR key &#58; integer;VAR midi &#58; tMidi;BEGIN    FOR key&#58;= minKey TO maxKey DO BEGIN            IF &#40;heldNotes&#91;key&#93; = FALSE&#41; OR closeAll THEN BEGIN             midi.msg &#58;= NOTEOFF;            midi.channel &#58;= Byte&#40;outChan&#41;;            midi.data1 &#58;= key;            midi.data2 &#58;= 0;            passOut&#40;midi&#41;;            heldNotes&#91;key&#93; &#58;= FALSE;        END;                                                              END;     doRelease &#58;= FALSE;END;////////////////////////       CALLBACK      /////////////////////////////////////////////PROCEDURE Callback&#40;n&#58; integer&#41;;VAR i &#58; integer;BEGIN    FOR i &#58;= 0 to INPUT_COUNT - 1 DO BEGIN        CASE n OF             pEnableINS&#91;i&#93; &#58;  BEGIN                                 isEnabled&#91;i&#93; &#58;= getValue&#40;n&#41; > 0;                                 UpdateBypass&#40;&#41;;                             END;               pMidiINS&#91;i&#93;   &#58;  midiInCounts&#91;i&#93; &#58;= GetLength&#40;n&#41;;        END;    END;        CASE n OF        pLearnIN      &#58;     isLearning     &#58;= TRUE;                pOutChanIN    &#58;     outChan        &#58;= Byte&#40;trunc&#40;getValue&#40;n&#41;&#41;&#41;;        pTranspIN     &#58;     transpose      &#58;=&#40;trunc&#40;getValue&#40;n&#41;&#41;&#41;;        pHiNoteIN     &#58;     setHiVal&#40;trunc&#40;getValue&#40;n&#41;&#41;&#41;;        pLowNoteIN    &#58;     setLowVal&#40;trunc&#40;getValue&#40;n&#41;&#41;&#41;;                pDroneIN      &#58;     ProcessDrone&#40;trunc&#40;getValue&#40;n&#41;&#41;&#41;;         END;END;/////////////////////////      PROCESS        //////////////////////////////////////////PROCEDURE Process;VAR i, inputNum &#58; Integer;VAR currMsg     &#58; tMidi;BEGIN    FOR inputNum &#58;= 0 TO &#40;INPUT_COUNT - 1&#41; DO BEGIN            FOR i &#58;= 0 TO &#40;midiInCounts&#91;inputNum&#93; - 1&#41; DO BEGIN                GetMidiArrayValue&#40;pMidiINS&#91;inputNum&#93;, i, currMsg&#41;;                ProcessMidi&#40;currMsg, isEnabled&#91;inputNum&#93;&#41;;            END;    END;    SetLength&#40;pPassOut, passCount&#41;;    SetLength&#40;pRejectOut, rejectCount&#41;;    passCount   &#58;= 0;    rejectCount &#58;= 0;END;

Statistics: Posted by woodslanding — 06 Mar 2010, 04:19


]]>
BrainModular BrainModular Users Forum 2010-03-07T12:54:56+02:00 https://brainmodular.com/forums/app.php/feed/topic/1992 2010-03-07T12:54:56+02:00 2010-03-07T12:54:56+02:00 https://brainmodular.com/forums/viewtopic.php?t=1992&p=12380#p12380 <![CDATA[script efficiencies....]]> Statistics: Posted by bsork — 07 Mar 2010, 11:54


]]>
2010-03-07T04:03:00+02:00 2010-03-07T04:03:00+02:00 https://brainmodular.com/forums/viewtopic.php?t=1992&p=12369#p12369 <![CDATA[script efficiencies....]]>
-e

Statistics: Posted by woodslanding — 07 Mar 2010, 03:03


]]>
2010-03-06T13:23:11+02:00 2010-03-06T13:23:11+02:00 https://brainmodular.com/forums/viewtopic.php?t=1992&p=12338#p12338 <![CDATA[script efficiencies....]]> Statistics: Posted by senso — 06 Mar 2010, 12:23


]]>
2010-03-06T09:54:38+02:00 2010-03-06T09:54:38+02:00 https://brainmodular.com/forums/viewtopic.php?t=1992&p=12305#p12305 <![CDATA[script efficiencies....]]> Statistics: Posted by gurulogic — 06 Mar 2010, 08:54


]]>
2010-03-06T09:09:25+02:00 2010-03-06T09:09:25+02:00 https://brainmodular.com/forums/viewtopic.php?t=1992&p=12300#p12300 <![CDATA[script efficiencies....]]> Statistics: Posted by 23fx23 — 06 Mar 2010, 08:09


]]>
2010-03-06T05:19:13+02:00 2010-03-06T05:19:13+02:00 https://brainmodular.com/forums/viewtopic.php?t=1992&p=12298#p12298 <![CDATA[script efficiencies....]]>
I'm wondering, though (and this is mostly directed at Bsork) whether there are any obvious inefficiencies in it, as I'm trying to save processing power wherever I can....

Any tips appreciated as always!

CODE:

&#40;*/////////////////////////////////////////////////////// CHANNEL  // Version 2009-11-21; author&#58; eric moon//// based on work by Bsork and amiga909//////////////////////////////////////////////////////*&#41;//  MIDI Channel Strip&#58;//  it is designed to function as part of a mixer channel strip, running between several keyboards and a vsti.//   takes a number of midi inputs &#40;on separate cables, for visual clarity&#41;//  and performs the following operations on each.//  enable, disable--per input//  strip CCs and send them out a separate output//  read CC64 values &#40;or a CC of your choice&#41; to withhold noteoffs until the sus pedal is released.//  limit to minimum and maximum notes--one range affects all inputs//  transpose--again, one range for all inputs.//  output rechannelizing--all outs are a single channel.  Use multiple strips to control multi-timbral modules.//  bypass output for turning off unused instruments.  waits for all notes to be released....//  Drone switch that keeps current notes sounding, but discards all note input as long as it is held//  Midi learn for note range&#58;//  When learn is turned on, midi note output is suspended//   the first noteNumber sets the low end of the range, the second noteNumber sets the upper limit.//   once both notes are sent, notes go to main output  as usual.//   support for inverse range, if low note is above high noteCONST SUS_PED= 64;    //change if you use an unorthodox CC for sustaining.CONST INPUT_COUNT = 2;  // could handle any number, I think!CONST NOTEON        = Byte&#40;144&#41;;CONST NOTEOFF       = Byte&#40;128&#41;;CONST CONTROL       = Byte&#40;176&#41;;CONST PITCHBEND     = Byte&#40;224&#41;;CONST AFTERTOUCH    = Byte&#40;208&#41;;VAR   heldNotes                    &#58; ARRAY OF boolean;VAR   transList                    &#58; ARRAY OF integer; VAR   isEnabled                    &#58; Array of boolean;VAR   pMidiINS,pEnableINS          &#58; ARRAY OF TParameter;VAR   midiInCounts                 &#58; ARRAY OF integer;VAR   pTranspIN, pDroneIN,pOutChanIN, pLearnIN, pLowNoteIn, pHiNoteIn  &#58; TParameter;       VAR   pPassOut,pRejectOut,pBypassOut, pLowNoteOut, pHiNoteOut                   &#58; Tparameter;       VAR   transpose, hiVal, lowVal                                 &#58; integer; VAR   passCount, rejectCount, learnCount, minKey, maxKey, outChan               &#58; integer;VAR   isSustaining, isLearning, isDroning, doRelease, bypassReady               &#58; boolean;///////////////////////////      INITIALIZE        /////////////////////////////////////PROCEDURE init; VAR i &#58; integer;   BEGIN      transpose &#58;= 0; transpose &#58;= 0; hiVal&#58;= 120; lowVal &#58;= 12;    passCount &#58;= 0; rejectCount &#58;= 0; learnCount &#58;= 0; minKey &#58;= 128; maxKey &#58;= 0; outChan &#58;= 1;    isSustaining &#58;= FALSE; isLearning &#58;= FALSE; isDroning &#58;= FALSE; doRelease &#58;= FALSE; bypassReady &#58;= FALSE;        setArrayLength&#40;pMidiINS, INPUT_COUNT&#41;;    setArrayLength&#40;pEnableINS, INPUT_COUNT&#41;;    setArrayLength&#40;isEnabled, INPUT_COUNT&#41;;    setArrayLength&#40;midiInCounts, INPUT_COUNT&#41;;   FOR i&#58;=0 TO INPUT_COUNT   DO midiInCounts&#91;i&#93;&#58;=0;    setArrayLength&#40;heldNotes, 128&#41;;               FOR i&#58;=0 TO 127           DO heldNotes&#91;i&#93;&#58;=FALSE;    SetArrayLength&#40;transList, 128&#41;;              FOR i&#58;=0 TO 127           DO transList&#91;i&#93;&#58;=0;        FOR i &#58;= 0 TO INPUT_COUNT - 1 DO  BEGIN        pEnableINS&#91;i&#93;  &#58;= CreateParam&#40;'enable ' + intToStr&#40;i + 1&#41;,ptSwitch&#41;;                SetIsOutPut&#40;pEnableINS&#91;i&#93;,false&#41;;            END;        pBypassOut       &#58;= CreateParam&#40;'inst bypass', ptSwitch&#41;;       SetIsInput&#40;pBypassOut,false&#41;;        pTranspIN        &#58;= CreateParam&#40;'trans',ptDataFader&#41;;          SetIsOutPut&#40;pTranspIN,false&#41;;      pOutChanIN       &#58;= CreateParam&#40;'out ch',ptMidiNoteFader&#41;;      SetIsOutPut&#40;pOutChanIN,false&#41;;    pLearnIN         &#58;= CreateParam&#40;'learn',ptButton&#41;;              SetIsOutPut&#40;pLearnIN,false&#41;;    pHiNoteIN        &#58;= CreateParam&#40;'high note',ptMidiNoteFader&#41;;   SetIsOutPut&#40;pHiNoteIN,false&#41;;    pHiNoteOUT        &#58;= CreateParam&#40;'hi note', ptDataField&#41;;         SetIsInPut&#40;pHiNoteOut,false&#41;;     pLowNoteIN       &#58;= CreateParam&#40;'low note',ptMidiNoteFader&#41;;    SetIsOutPut&#40;pLowNoteIN,false&#41;;    pLowNoteOUT       &#58;= CreateParam&#40;'low note',ptDataField&#41;;         SetIsInPut&#40;pLowNoteOut,false&#41;;    pDroneIN         &#58;= CreateParam&#40;'drone', ptSwitch&#41;;             SetIsOutput&#40;pDroneIN,false&#41;;           SetFormat&#40;pTranspIN,'%.0f'&#41;;    SetMin&#40;pTranspIN,-48&#41;;  SetMax&#40;pTranspIN,48&#41;;        SetFormat&#40;pOutChanIN,'%.0f'&#41;;   SetMin&#40;pOutChanIN,1&#41;;  SetMax&#40;pOutChanIN,16&#41;;           FOR i &#58;= 0 TO INPUT_COUNT - 1 DO  BEGIN        pMidiINS&#91;i&#93;  &#58;= CreateParam&#40;'MIDIin ' + intToStr&#40;i + 1&#41; ,ptMidi&#41;;               SetIsOutPut&#40;pMidiINS&#91;i&#93;,false&#41;;    END;        pPassOut          &#58;= CreateParam&#40;'passed MIDI',ptMidi&#41;;           SetIsInput&#40;pPassOut,false&#41;;      pRejectOut        &#58;= CreateParam&#40;'rejected MIDI',ptMidi&#41;;         SetIsInput&#40;pRejectOut,false&#41;;END;   ///////////////////////////  MIDI OUTPUT METHODS   ////////////////////////////////////PROCEDURE PassOut&#40;midi &#58; tMidi&#41;;BEGIN   midi.channel &#58;= BYTE&#40;outChan&#41;;   SetMidiArrayValue&#40;pPassOut, passCount, midi&#41;;   passCount &#58;= passCount + 1;END;PROCEDURE RejectOut&#40;midi &#58; tMidi&#41;;BEGIN   midi.channel &#58;= BYTE&#40;outChan&#41;;   SetMidiArrayValue&#40;pRejectOut, rejectCount, midi&#41;;   rejectCount &#58;= rejectCount + 1;END;/////////////////////////   MIDI MESSAGE TESTS  ///////////////////////////////////////FUNCTION IsNote &#40;midi &#58; tMidi&#41; &#58; Boolean;BEGIN   IsNote &#58;= &#40;&#40;midi.msg = NOTEON&#41; OR &#40;midi.msg = NOTEOFF&#41;&#41;;END;FUNCTION IsNoteOn &#40;midi &#58; tMidi&#41; &#58; Boolean;BEGIN   IsNoteOn &#58;= &#40;&#40;midi.msg = NOTEON&#41; AND &#40;midi.data2 > 0&#41;&#41;;END;FUNCTION IsNoteOff &#40;midi &#58; tMidi&#41; &#58; Boolean;BEGIN   IsNoteOff &#58;= &#40;midi.msg = NOTEOFF&#41; OR &#40;&#40;midi.msg = NOTEON&#41; AND &#40;midi.data2 = 0&#41;&#41;;END;FUNCTION IsSustain &#40;midi &#58; tMidi&#41; &#58; Boolean;BEGIN    IsSustain &#58;= &#40;midi.msg = CONTROL&#41;  AND &#40;midi.data1 = SUS_PED&#41;;END;//////////////////////////      OTHER TESTS     ////////////////////////////////////////FUNCTION UpdateBypass&#40;&#41;  &#58;  INTEGER;VAR i  &#58; integer;BEGIN     bypassReady &#58;= TRUE;      FOR i &#58;= 0 to &#40;INPUT_COUNT - 1&#41; DO BEGIN        if isEnabled&#91;i&#93; THEN BEGIN            bypassReady &#58;= FALSE;            setValue&#40;pBypassOut, 0&#41;;        END;    END;    IF bypassReady AND isClear&#40;&#41; THEN setValue&#40;pBypassOUT, 1&#41;;       END; FUNCTION isInRange&#40;noteNumber &#58; integer &#41; &#58; Boolean;VAR inRange &#58; Boolean;VAR reversed &#58; Boolean;BEGIN    reversed &#58;= &#40;lowVal >= hiVal&#41;;    IF reversed THEN isInRange &#58;= &#40;noteNumber < hiVal&#41;  OR  &#40;noteNumber > lowVal&#41;                ELSE isInRange &#58;= &#40;noteNumber <= hiVal&#41; AND &#40;noteNumber >= lowVal&#41;; END;////////////////////////       SETTERS       ////////////////////////////////////////////PROCEDURE SetLowVal&#40;n &#58; integer&#41;;BEGIN    setValue&#40;pLowNoteOut, n&#41;;    lowVal &#58;= n;END;PROCEDURE SetHiVal&#40;n &#58; integer&#41;;BEGIN    setValue&#40;pHiNoteOut, n&#41;;    hiVal &#58;= n;END;////////////////////////     PROCESS MIDI    ////////////////////////////////////////////FUNCTION bstr&#40;b &#58; boolean&#41; &#58; string;BEGIN if b THEN bstr &#58;= 'TRUE' else bstr &#58;= 'FALSE'; END;PROCEDURE ProcessMidi&#40;midi &#58; tMidi; enabled &#58; boolean&#41;;BEGIN    IF isLearning THEN processLearn&#40;midi&#41;     ELSE IF not&#40;isDroning&#41; THEN BEGIN        IF isSustain&#40;midi&#41; THEN BEGIN            isSustaining &#58;= midi.data2 > 64;            if NOT&#40;isSustaining&#41; THEN doRelease &#58;= TRUE;                END                   // pass PB and AT with notes        ELSE IF &#40;midi.msg = PITCHBEND&#41; OR &#40;midi.msg = AFTERTOUCH&#41; THEN passOut&#40;midi&#41;        ELSE IF NOT&#40;IsNote&#40;midi&#41;&#41; THEN rejectOut&#40;midi&#41;        // everything else deals with note data....        ELSE IF IsInRange&#40;midi.data1&#41;and enabled THEN BEGIN            IF isNoteOn&#40;midi&#41; THEN BEGIN                ProcessNoteOn&#40;midi, enabled&#41;;            END ELSE BEGIN                       ProcessNoteOff&#40;midi&#41;            END;        END ELSE rejectOut&#40;midi&#41;; //notes that are out of range        IF doRelease THEN sendNoteOffs&#40;false&#41;;    END;  END;PROCEDURE ProcessLearn&#40;midi &#58; tMidi&#41;;BEGIN    IF &#40;isNoteOn&#40;midi&#41;&#41; and &#40;learnCount = 0&#41; THEN BEGIN        lowVal &#58;= midi.data1;        setValue&#40;pLowNoteOUT, lowVal&#41;;        learnCount &#58;= 1;                       END     ELSE IF &#40;isNoteOn&#40;midi&#41;&#41; and &#40;learnCount = 1&#41;  THEN BEGIN        hiVal &#58;= midi.data1;        setValue&#40;pHiNoteOUT, hiVal&#41;;        learnCount &#58;= 0;        isLearning &#58;= FALSE;  // we've set our outs....    END;END;PROCEDURE ProcessNoteOn&#40;midi &#58; tMidi; enabled &#58; boolean&#41;;BEGIN    IF enabled THEN BEGIN        transList&#91;midi.data1&#93; &#58;= transpose;         midi.data1 &#58;= midi.data1 + transpose;        PassOut&#40;midi&#41;;        heldNotes&#91;midi.data1&#93; &#58;= TRUE;    END;END;PROCEDURE ProcessNoteOff&#40;midi &#58; Tmidi&#41;;BEGIN    midi.data1 &#58;= midi.data1 + transList&#91;midi.data1&#93;;    heldNotes&#91;midi.data1&#93; &#58;= FALSE;    IF isSustaining THEN  storeNoteOff&#40;midi&#41; ELSE  PassOut&#40;midi&#41;;    IF bypassReady AND isClear&#40;&#41; THEN  BEGIN        setValue&#40;pBypassOut, 1&#41;;        isSustaining &#58;= FALSE;        isDroning &#58;= FALSE;        bypassReady &#58;= FALSE;    END;END;PROCEDURE storeNoteOff&#40;midi &#58; tMidi&#41;;BEGIN         // is this all we're doing here?  should this be in the method above??    IF &#40;midi.data1 > maxKey&#41; THEN maxKey &#58;= midi.data1;    IF &#40;midi.data1 < minKey&#41; THEN minKey &#58;= midi.data1;  END;PROCEDURE ProcessDrone&#40;n &#58; integer&#41;;BEGIN    IF n = 0 THEN SendNoteOffs&#40;TRUE&#41;;    isSustaining &#58;= FALSE;    isDroning &#58;= n > 0;   END;FUNCTION isClear&#40;&#41; &#58; boolean;VAR key &#58; integer; VAR clear &#58; boolean;BEGIN    clear &#58;= TRUE;    FOR key&#58;= minKey TO maxKey DO IF heldNotes&#91;key&#93; = TRUE THEN clear &#58;= FALSE;    isClear &#58;= clear;END;PROCEDURE SendNoteOffs&#40;closeAll &#58; boolean&#41;;VAR key &#58; integer;VAR midi &#58; tMidi;BEGIN    FOR key&#58;= minKey TO maxKey DO BEGIN            IF &#40;heldNotes&#91;key&#93; = FALSE&#41; OR closeAll THEN BEGIN             midi.msg &#58;= NOTEOFF;            midi.channel &#58;= Byte&#40;outChan&#41;;            midi.data1 &#58;= key;            midi.data2 &#58;= 0;            passOut&#40;midi&#41;;            heldNotes&#91;key&#93; &#58;= FALSE;        END;                                                              END;     doRelease &#58;= FALSE;END;////////////////////////       CALLBACK      /////////////////////////////////////////////PROCEDURE Callback&#40;n&#58; integer&#41;;VAR i &#58; integer;BEGIN    FOR i &#58;= 0 to INPUT_COUNT - 1 DO BEGIN        CASE n OF             pEnableINS&#91;i&#93; &#58;  BEGIN                                 isEnabled&#91;i&#93; &#58;= getValue&#40;n&#41; > 0;                                 UpdateBypass&#40;&#41;;                             END;               pMidiINS&#91;i&#93;   &#58;  midiInCounts&#91;i&#93; &#58;= GetLength&#40;n&#41;;        END;    END;        CASE n OF        pLearnIN      &#58;     isLearning     &#58;= TRUE;                pOutChanIN    &#58;     outChan        &#58;= Byte&#40;trunc&#40;getValue&#40;n&#41;&#41;&#41;;        pTranspIN     &#58;     transpose      &#58;=&#40;trunc&#40;getValue&#40;n&#41;&#41;&#41;;        pHiNoteIN     &#58;     setHiVal&#40;trunc&#40;getValue&#40;n&#41;&#41;&#41;;        pLowNoteIN    &#58;     setLowVal&#40;trunc&#40;getValue&#40;n&#41;&#41;&#41;;                pDroneIN      &#58;     ProcessDrone&#40;trunc&#40;getValue&#40;n&#41;&#41;&#41;;         END;END;/////////////////////////      PROCESS        //////////////////////////////////////////PROCEDURE Process;VAR i, inputNum &#58; Integer;VAR currMsg     &#58; tMidi;BEGIN    FOR inputNum &#58;= 0 TO &#40;INPUT_COUNT - 1&#41; DO BEGIN            FOR i &#58;= 0 TO &#40;midiInCounts&#91;inputNum&#93; - 1&#41; DO BEGIN                GetMidiArrayValue&#40;pMidiINS&#91;inputNum&#93;, i, currMsg&#41;;                ProcessMidi&#40;currMsg, isEnabled&#91;inputNum&#93;&#41;;            END;    END;    SetLength&#40;pPassOut, passCount&#41;;    SetLength&#40;pRejectOut, rejectCount&#41;;    passCount   &#58;= 0;    rejectCount &#58;= 0;END;

Statistics: Posted by woodslanding — 06 Mar 2010, 04:19


]]>