Home Forums Macros How can I retrigger Matrix Macro so new Case Branch triggers?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #6299

    Hello,

    I have the below Macro as part of a Matrix. It is a way of randomly playing different sections of a loop and depending on triggered Case Branch the loop is divided in different numbers of slices. When I have triggered one Case Branch I cannot however retrigger the marco with a new Case Branch. It is somehow stuck in the current case branch loop. I have tried to overcome this by have in the “Set $rndSliceActivated$ = false” line before all Case Branches to break the While loop but this does not do any change. Thankful for any help
    —-
    Declare Local Once boolean $firstTime$ = true
    Declare Local int $itemID$ = 0
    Declare Local int $itemSize$ = 56
    Declare Local int $verticalPosition$ = 1

    Declare Once boolean $Loop1Selected$ = false
    Declare Once boolean $Loop2Selected$ = false
    Declare Once boolean $Loop3Selected$ = false
    Declare Once boolean $Loop4Selected$ = false
    Declare Once boolean $Loop5Selected$ = false
    Declare Once boolean $Loop6Selected$ = false

    Declare Once boolean $rndSliceActivated$ = false

    MetroActivateEvents true

    Set $rndSliceActivated$ = false

    If { $firstTime$ }
    $firstTime$ = false

    //WaitDuration 300
    SendData thispatcher itemamount 8

    WaitDuration 200

    SendData mainWindow setsize 463 {30 + ($itemSize$ * 1)}

    SendData item 0 fontface regular
    //SendData button 0 fontsize 40
    SendData item 0 bgcolor 0. 0. 0. 1.;
    SendData item 0 bgoncolor 0.773 0.145 0.196 1.;
    SendData item 0 bordercolor 0.2 0.2 0.2 1.;
    SendData item 0 borderoncolor 0.2 0.2 0.2 1.;
    SendData item 0 textcolor 0.827 0.827 0.824 1.
    SendData item 0 textoncolor 0.827 0.827 0.824 1.;

    SendData thispatcher basicdisposition

    SendData MacroInitialized
    MacroStop
    EndIf

    // Which Case is it ?
    Message { “Button, Dial or SVG number ” + currentCaseValueString() + ” : ” + currentCaseOptionValueFloat(0)}

    CaseBranch 1
    SlicerPresetLoad “2 Slices Test”
    WaitDuration 50
    Set $rndSliceActivated$ = true
    Declare int $rndReverse$ = 0
    InsertSendMessage fx1 1 Synchro “Free”
    RepeatWhile {$rndSliceActivated$ == true && $Loop1Selected$ == true}
    WaitMetroSomeBeats 1
    Set $rndReverse$ = {randomScaleInt(0,1)}
    If {$rndReverse$ == 1}
    TrackSpeed trk1 = -1.0
    InsertSendMessage fx1 1 ReverseDirection 1
    Else
    TrackSpeed trk1 = 1.0
    InsertSendMessage fx1 1 ReverseDirection 0
    EndIf
    SlicerStepLoad {round(randomScaleFloat(1.0,2.0))}
    WaitDuration 30
    EndRepeat
    TrackSpeed trk1 = 1.0
    InsertSendMessage fx1 1 ReverseDirection 0
    BreakCaseBranch

    CaseBranch 2
    Message “Case 2”
    SlicerPresetLoad “3 Slices Test”
    WaitDuration 50
    Set $rndSliceActivated$ = true
    Declare int $rndReverse$ = 0
    InsertSendMessage fx1 1 Synchro “Free”
    RepeatWhile {$rndSliceActivated$ == true && $Loop1Selected$ == true}
    WaitMetroSomeBeats 1
    Set $rndReverse$ = {randomScaleInt(0,1)}
    If {$rndReverse$ == 1}
    TrackSpeed trk1 = -1.0
    InsertSendMessage fx1 1 ReverseDirection 1
    Else
    TrackSpeed trk1 = 1.0
    InsertSendMessage fx1 1 ReverseDirection 0
    EndIf
    SlicerStepLoad {round(randomScaleFloat(1.0,3.0))}
    WaitDuration 30
    EndRepeat
    TrackSpeed trk1 = 1.0
    InsertSendMessage fx1 1 ReverseDirection 0
    BreakCaseBranch

    CaseBranch 3
    SlicerPresetLoad “4 Slices Test”
    WaitDuration 50
    Set $rndSliceActivated$ = true
    Declare int $rndReverse$ = 0
    InsertSendMessage fx1 1 Synchro “Free”
    RepeatWhile {$rndSliceActivated$ == true && $Loop1Selected$ == true}
    WaitMetroSomeBeats 1
    Set $rndReverse$ = {randomScaleInt(0,1)}
    If {$rndReverse$ == 1}
    TrackSpeed trk1 = -1.0
    InsertSendMessage fx1 1 ReverseDirection 1
    Else
    TrackSpeed trk1 = 1.0
    InsertSendMessage fx1 1 ReverseDirection 0
    EndIf
    SlicerStepLoad {round(randomScaleFloat(1.0,4.0))}
    WaitDuration 30
    EndRepeat
    TrackSpeed trk1 = 1.0
    InsertSendMessage fx1 1 ReverseDirection 0
    BreakCaseBranch

    CaseBranch 4
    SlicerPresetLoad “6 Slices Test”
    WaitDuration 50
    Set $rndSliceActivated$ = true
    Declare int $rndReverse$ = 0
    InsertSendMessage fx1 1 Synchro “Free”
    RepeatWhile {$rndSliceActivated$ == true && $Loop1Selected$ == true}
    WaitMetroSomeBeats 1
    Set $rndReverse$ = {randomScaleInt(0,1)}
    If {$rndReverse$ == 1}
    TrackSpeed trk1 = -1.0
    InsertSendMessage fx1 1 ReverseDirection 1
    Else
    TrackSpeed trk1 = 1.0
    InsertSendMessage fx1 1 ReverseDirection 0
    EndIf
    SlicerStepLoad {round(randomScaleFloat(1.0,6.0))}
    WaitDuration 30
    EndRepeat
    TrackSpeed trk1 = 1.0
    InsertSendMessage fx1 1 ReverseDirection 0
    BreakCaseBranch

    CaseBranch 5
    SlicerPresetLoad “8 Slices Test”
    WaitDuration 50
    Set $rndSliceActivated$ = true
    Declare int $rndReverse$ = 0
    InsertSendMessage fx1 1 Synchro “Free”
    RepeatWhile {$rndSliceActivated$ == true && $Loop1Selected$ == true}
    WaitMetroSomeBeats 1
    Set $rndReverse$ = {randomScaleInt(0,1)}
    If {$rndReverse$ == 1}
    TrackSpeed trk1 = -1.0
    InsertSendMessage fx1 1 ReverseDirection 1
    Else
    TrackSpeed trk1 = 1.0
    InsertSendMessage fx1 1 ReverseDirection 0
    EndIf
    SlicerStepLoad {round(randomScaleFloat(1.0,8.0))}
    WaitDuration 30
    EndRepeat
    TrackSpeed trk1 = 1.0
    InsertSendMessage fx1 1 ReverseDirection 0
    BreakCaseBranch

    CaseBranch 6
    SlicerPresetLoad “12 Slices Test”
    WaitDuration 50
    Set $rndSliceActivated$ = true
    Declare int $rndReverse$ = 0
    InsertSendMessage fx1 1 Synchro “Free”
    RepeatWhile {$rndSliceActivated$ == true && $Loop1Selected$ == true}
    WaitMetroSomeBeats 1
    Set $rndReverse$ = {randomScaleInt(0,1)}
    If {$rndReverse$ == 1}
    TrackSpeed trk1 = -1.0
    InsertSendMessage fx1 1 ReverseDirection 1
    Else
    TrackSpeed trk1 = 1.0
    InsertSendMessage fx1 1 ReverseDirection 0
    EndIf
    SlicerStepLoad {round(randomScaleFloat(1.0,12.0))}
    WaitDuration 30
    EndRepeat
    TrackSpeed trk1 = 1.0
    InsertSendMessage fx1 1 ReverseDirection 0
    BreakCaseBranch

    CaseBranch 7
    SlicerPresetLoad “16 Steps Test”
    WaitDuration 50
    Set $rndSliceActivated$ = true
    Declare int $rndReverse$ = 0
    InsertSendMessage fx1 1 Synchro “Free”
    RepeatWhile {$rndSliceActivated$ == true && $Loop1Selected$ == true}
    WaitMetroSomeBeats 1
    Set $rndReverse$ = {randomScaleInt(0,1)}
    If {$rndReverse$ == 1}
    TrackSpeed trk1 = -1.0
    InsertSendMessage fx1 1 ReverseDirection 1
    Else
    TrackSpeed trk1 = 1.0
    InsertSendMessage fx1 1 ReverseDirection 0
    EndIf
    SlicerStepLoad {round(randomScaleFloat(1.0,16.0))}
    WaitDuration 30
    EndRepeat
    TrackSpeed trk1 = 1.0
    InsertSendMessage fx1 1 ReverseDirection 0
    BreakCaseBranch

    CaseBranch 8
    BreakCaseBranch

    EndCaseBranches
    —-

    #6307
    Philippe OllivierPhilippe
    Keymaster

    Hi,
    The issue here comes from the fact we cannot stop the RepeatWhile loop from outside.

    I think you can set the buttons in toggle mode and add a condition to stop the RepeatWhile loop if the button is set to off or another button is pushed.
    I don’t know if this will work in your situation, but it could be a solution.
    Below is a simple example of this.
    Best,
    Philippe

    //******************************** Matrix ! Tab Items ********************************
    Declare Local Once boolean $firstTime$ = true
    Declare Local Once int $itemSize$ = 56
    Declare Local Once int $lastPushedItem$ = -1

    If { $firstTime$ }
    $firstTime$ = false
    SendData thispatcher itemamount 8
    WaitDuration 200
    SendData mainWindow setsize 463 {30 + ($itemSize$ * 1)}

    // Toggle mode On
    SendData item 0 mode 1

    SendData thispatcher basicdisposition
    SendData MacroInitialized
    MacroStop
    EndIf

    CaseBranch 1
    SendData item $lastPushedItem$ set 0
    $lastPushedItem$ = {currentCaseValueInt()}

    RepeatWhile {(currentCaseValueInt()==1) && (currentCaseOptionValueInt(0) == 1)}
    Post {“Loop ” + (currentCaseValueInt())}
    WaitDuration 30
    EndRepeat
    BreakCaseBranch

    CaseBranch 2
    SendData item $lastPushedItem$ set 0
    $lastPushedItem$ = {currentCaseValueInt()}

    RepeatWhile {(currentCaseValueInt()==2) && (currentCaseOptionValueInt(0) == 1)}
    Post {“Loop ” + (currentCaseValueInt())}
    WaitDuration 30
    EndRepeat
    BreakCaseBranch

    CaseBranch 3
    SendData item $lastPushedItem$ set 0
    $lastPushedItem$ = {currentCaseValueInt()}

    RepeatWhile {(currentCaseValueInt()==3) && (currentCaseOptionValueInt(0) == 1)}
    Post {“Loop ” + (currentCaseValueInt())}
    WaitDuration 30
    EndRepeat
    BreakCaseBranch

    CaseBranch 4
    SendData item $lastPushedItem$ set 0
    $lastPushedItem$ = {currentCaseValueInt()}

    RepeatWhile {(currentCaseValueInt()==4) && (currentCaseOptionValueInt(0) == 1)}
    Post {“Loop ” + (currentCaseValueInt())}
    WaitDuration 30
    EndRepeat
    BreakCaseBranch

    #6318

    Thanks!

    I will look into the above.

    One thing though. You write that a RepeatWhile Loop cannot be stopped from the outside. However when I trigger the below CaseBranch from a second matrix (where I set the same Global variable $rndSliceActivated$ used in the first Matrix RepeatWhile statement) then the loops selection is reset and the RepeatWhile loop in the first Matrix is stopped and I can trigger another CaseBranch. To me this means that the RepeatWhile CAN be stopped from the outside, right? Or am I misunderstanding something?

    —–Second Matrix—–
    CaseBranch 1
    Set $rndSliceActivated$ = false
    MidiSend “Launchpad MK2” 150 106 5
    WaitDuration 500
    TrackLoopReset trk_all
    InsertSendMessage fx1 1 SelectionReset
    BreakCaseBranch
    ——–

    #6319
    Philippe OllivierPhilippe
    Keymaster

    Yes, you are right, I was not precise enough.
    Yes, if you change the variable value and the RepeatWhile is false, then the loop is stopped.

    I was thinking to the Sleep function we put in normal Macro, they can be stopped by a new user action…

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.