/*==========================================================================+ | autotempo.e | | automatically transpose/finetune sample to fit tempo | $VER: autotempo.e 1.1 (1999.08.05) © Claude Heiland-Allen +--------------------------------------------------------------------------*/ OPT OSVERSION=37 MODULE '*calculations', '*nsm' /*-------------------------------------------------------------------------*/ -> default settings CONST DEFAULTPITCH = 25, -> C-3 LINES = 16 /*-------------------------------------------------------------------------*/ PROC main() HANDLE DEF defaultpitch, samplelength, tempomode, tempo, tempolpb, rangestartline, rangeendline, note, lines, transpose, finetune, buffer[256] : STRING, screen = NIL -> lock octamed screen := LockPubScreen('OCTAMED') IF screen = NIL THEN Throw(1,'OctaMED must be running') -> get oss data defaultpitch := Val(nsm_sendrexx('IN_GETDEFAULTPITCH')) IF defaultpitch = 0 THEN defaultpitch := DEFAULTPITCH samplelength := Val(nsm_sendrexx('SA_GETSAMPLELENGTH')) IF samplelength=0 THEN Throw(1,'no sample') tempomode := nsm_sendrexx('SG_GETTEMPOMODE') IF StrCmp(tempomode,'BPM')=FALSE THEN Throw(1,'tempo mode must be BPM') tempo := Val(nsm_sendrexx('SG_GETTEMPO')) tempolpb := Val(nsm_sendrexx('SG_GETTEMPOLPB')) rangestartline := Val(nsm_sendrexx('RN_GETRANGESTARTLINE')) rangeendline := Val(nsm_sendrexx('RN_GETRANGEENDLINE')) lines := rangeendline - rangestartline + 1 IF lines = 1 THEN lines := LINES -> the all-important calculation -> freq = length * lpb * bpm / lines * 60 note,finetune := oss_Period2NoteFinetune(oss_Frequency2Period( Div(Mul(Mul(tempo,tempolpb),samplelength),Mul(lines,60)))) -> set oss data IF note = 0 THEN Throw(1,'pitch change required is too large') transpose := note - defaultpitch nsm_sendrexx(StringF(buffer, 'IN_SETTRANSPOSE \d', transpose)) nsm_sendrexx(StringF(buffer, 'IN_SETFINETUNE \d', finetune)) EXCEPT DO -> clean up nsm_freeresult() IF screen THEN UnlockPubScreen(NIL, screen) -> report errors SELECT exception CASE 0 -> no error CASE 1; WriteF('*** Error: \s\n', exceptioninfo) DEFAULT; WriteF('*** Unknown error: \z\h[8] \z\h[8]\n', exception, exceptioninfo) ENDSELECT -> return code ENDPROC IF exception THEN 10 ELSE 0 /*-------------------------------------------------------------------------*/ -> version string version: CHAR '$VER: autotempo 1.1 (1999.08.05) © Claude Heiland-Allen',0 /*--------------------------------------------------------------------------+ | END: autotempo.e | +==========================================================================*/