Welcome to %s forums

BrainModular Users Forum

Login Register

get the index of the changed value in a sequencer

I need help on a Patch
Post Reply
ceasless
Member
Posts: 330
Contact:

Unread post by ceasless » 22 Sep 2013, 19:25

I'm trying to set up a 'default' value for for a step sequencer such that when a switch in a separate switch sequencer is clicked, the default value will be set in the step in the same index. I was thinking to use 'mouse dwn' from the switch sequencer, but then I still don't know which step to fill in with the default value.

I can write another script probably but I was hoping there would be an easier solution (maybe it doesn't take much to add this as an output in the sequencers?).

ceasless
Member
Posts: 330
Contact:

Unread post by ceasless » 23 Sep 2013, 13:36

Nevermind, I've scripted it myself.

Code: Select all

//////////////////////////
// Index of Changed Array Value
/////////////////////////
// parameters declaration


var mem, arrIn, value,
    index       : tParameter;
var s,l         : integer;
var m,x         : single;
var hasRun      : integer;

// initialisation : create parameters
procedure init;
begin  
    mem := createParam('memory',ptArray);
    setIsInput(mem,false);
    setIsOutput(mem,false);
   
    arrIn := createParam('array in',ptArray);
    setIsOutput(arrIn,false);

    index := createParam('index',ptDatafield);
    setIsInput(index,false);

    value := createParam('value',ptDatafield);
    setIsInput(value,false);

    hasRun := 0;
end;

// Callback procedure
Procedure Callback(N:integer); 
begin

    case N of
        arrIn: begin
            if hasRun = 1
            then begin 
                l := getLength(arrIn);
                for s:=0 to l-1
                do begin
                    x := getDataArrayValue(arrIn,s);
                    m := getDataArrayValue(mem,s);   
                                                 
                    if x <> m
                    then begin
                        setValue&#40;index,s&#41;;
                        setValue&#40;value,x&#41;;
                    end;
                end;
            end;

            l &#58;= getLength&#40;arrIn&#41;;
            setLength&#40;mem,l&#41;;
            for s&#58;=0 to l-1 
            do begin  
                x &#58;= getDataArrayValue&#40;arrIn,s&#41;;
                setDataArrayValue&#40;mem,s,x&#41;;
            end;            
                       
            hasRun &#58;= 1;   
        end;               
    end;

end;

// Global variables

//////////////////////////////
// main proc
//////////////////////////////
Procedure Process;
begin
    if hasRun = 0
    then begin
       l &#58;= getLength&#40;arrIn&#41;;
       setLength&#40;mem,l&#41;;
       for s&#58;=0 to l-1 
       do begin  
           x &#58;= getDataArrayValue&#40;arrIn,s&#41;;
           setDataArrayValue&#40;mem,s,x&#41;;
       end;            
                       
       hasRun &#58;= 1;
    end;
end;

sephult
Member
Posts: 1144
Contact:

Unread post by sephult » 23 Sep 2013, 13:44

Hi ceaseless! I was wondering too...would you not use the step-position of the switch sequence to determine the index?
I guess I don't have a good idea of your approach...but I looked at once and found the step position was not only where the sequencer "was" but the index of each button.

-S
"Every act of creation is first an act of destruction." -Picasso

ceasless
Member
Posts: 330
Contact:

Unread post by ceasless » 23 Sep 2013, 14:25

Hi Sephult,

Indeed, it seems that it is very hard to translate patching concepts in words. Thank you for responding and trying to help! It can really mean a lot, especially as threads can go unanswered here for long stretches. That is to be expected, especially with the development pace of Holylhock, but it can still be a little demotivating.

As regards step position, yes definitely it carries the index with it (using the trunc module gets you exactly the index). This is perfectly fine for inputting new step/switch values in real-time.

However, I'm designing a drum sequencer that can also be used just with a mouse. So what I need is to get the index value of a switch that has changed. This can be 'in the future' relative to step position: step position is on the second switch, while I've just clicked to activate the 15th switch.

The script above takes care of that, I'm just starting to worry that I have so many scripts in my patch :)

Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests