Page 1 of 1

Posted: 18 Nov 2008, 15:44
by amiga909
hi

my goal is to build a midi recorder, like the 'midi accumulator' but with syncable lengths. the piano roll would be an alternative but I want it without the editor and cpu light instead. it should be as cpu light as the internal recorder of the xy interface module.

- any general tips?

- want to tackle the sync problem first:
tried to understand the 'midi delay' script which has the sync div param I am looking for, and the 'data delay' script which is easier.

Code: Select all

///////////////////////////////////////////////////
// DATA Delay 
// Like an audio delay but works with DATA flows
//////////////////////////////////////////////////
// parameters declaration
var input   : Tparameter;
var output  : Tparameter;
var delay   : TParameter;

const N_BLOC_DELAY  = 1000;
var TabDelay  : array of Single;

// initialisation : create parameters
procedure init;
begin  
 Input := CreateParam('in',ptDataField);
 Output := CreateParam('out',ptDataField);
 delay := CreateParam('delay',ptDataFader); 
 
 SetIsInput(Output,false);
 SetIsOutPut(Input,false);
 SetIsOutPut(delay,false);
 SetFormat(delay,'%.0f');
 SetMin(delay,0);
 SetMax(delay,BlocDuration*(N_BLOC_DELAY-2));
 SetSymbol(delay,'ms');
 SetValue(delay,100);
 SetScale(delay,lsLog);

 SetArraylength(TabDelay,N_BLOC_DELAY);
 SetLength(outPut,1);
 
end;

// Global variables
var tmp      : Single;
var writepos : integer;
var readpos  : integer;

//////////////////////////////
// main proc
//////////////////////////////
begin

 readpos := (readpos+1) mod N_BLOC_DELAY;
 writepos := (readpos+Trunc(GetValue(delay)/Blocduration)) mod N_BLOC_DELAY;
 TabDelay [writePos] := GetValue(input);
 tmp := TabDelay[readPos];
 SetValue(output,tmp);  // set output value     


end.
some concrete questions:

Code: Select all

 SetMax(delay,BlocDuration*(N_BLOC_DELAY-2));

Code: Select all

 readpos := (readpos+1) mod N_BLOC_DELAY;
 writepos := (readpos+Trunc(GetValue(delay)/Blocduration)) mod N_BLOC_DELAY;
whats the math behind this?
why is midi delay based on PPQ values? would it be easier if i connect a local sync module as a script module input?

thanks for help.

Posted: 19 Nov 2008, 08:56
by senso
your question is very general and I can't answer so generally.
The tape delay works like an old 'audio tape delay' but with midi. In programing stuff we call it Circular Buffer.
But in an analog tape delay, the tape is moving and reading/writing heads a fixed. In computing it is the inverse, the 'tape' is fixed and the heads are moving.

when you write
readpos := (readpos+1) mod N_BLOC_DELAY;
it means that you move the reading head by one step (+1) and if you reach the end of the 'tape' you restart from the beginning.

now when write
writepos := (readpos+Trunc(GetValue(delay)/Blocduration)) mod N_BLOC_DELAY;
It mean that you write midi data's on the 'tape' N steps forward (N=GetValue(delay)/Blocduration)) so they will be read later.

Posted: 21 Nov 2008, 20:45
by amiga909
thanks for the answer.
to be more explicit its not the recording behavior its about to understand the N_BLOC_DELAY constant:

question:
how can I calculate eg. a length of 2bars in a script? like:

Code: Select all

IF(2BarsHavePassedNow) THEN countNoOfBars:=countNoOfBars+2;
I know how to calculate bars <-> milliseconds (+ a given BPM tempo), eg. when manually syncing an analog delay.

how to use N_BLOC_DELAY and PPQ data type (if I have to use them)?