; Octamed Echo by Invect
; version two (with added gui, and supporting new buzzscript engine 2 arrays)
; by djboo

HIDEDEBUG
DEBUGOFF
EXECOFF

 WINDOW_CREATE somewin2 name=Octamed Echo (invect/djboo),width=275,height=100,state=normal,icon=someicon.ico
TEXTFIELD_CREATE somewin2 handle=mytext1,name=EchoStep,x=15,y=15,width=100,height=25
TEXTFIELD_CREATE somewin2 handle=mytext2,name=MinEcho,x=15,y=45,width=100,height=25
LABEL_CREATE somewin2 handle=thing1,name=EchoStop,x=115,y=15,width=100,height=15
LABEL_CREATE somewin2 handle=thing2,name=MinEcho,x=115,y=45,width=100,height=15
BUTTON_CREATE somewin2 name=Go Do It,jump=init,x=195,y=45,width=50,height=25

TEXTFIELD_SETSTRING somewin2 handle=mytext1,text=3
TEXTFIELD_SETSTRING somewin2 handle=mytext2,text=4
IDLE WINDOWED


label init
TEXTFIELD_GETSTRING somewin2 handle=mytext1,destvariable=dialog
TEXTFIELD_GETSTRING somewin2 handle=mytext2,destvariable=MinEcho
; Init
SETACTIVESCREEN PATTERN
ACTIVATE
UPDATEPATTERN
VBKEY {F8}
SETSTRING minval 32

setstring NumRows ROWS
setstring NumTracks TRACKS

;QUESTION Echo Setting?
COMPARE Dialog 1
ISLESS SkipScript
setstring EchoSetting Dialog
setstring SettingNumRows ROWS
SUBTRACT EchoSetting SettingNumRows

; Find Note Column and Save Position in NoteX
FINDCOLUMN Note NoteX
GOTOCOLUMN NoteX
READCOLUMNINTOARRAY 1 ROWS

; Find Volume Column and Save Position in VolumeX
FINDVOLUME VolumeX
GOTOCOLUMN VolumeX
READCOLUMNINTOARRAY 2 ROWS

 WINDOW_CREATE somewin name=Working,width=375,height=65,state=normal,icon=someicon.ico
TEXTFIELD_CREATE somewin handle=mytext,name=Stuff,x=15,y=15,width=100,height=25
; Main Loop
vbkey {HOME}{HOME}{HOME}{HOME}
setstring TickNum 1
;debugoff
mtoff
LABEL BeginEcho

; Move to Note Position
SETARRAYPOINTER 1 ticknum 0
; Read Note Value
GETARRAY NoteValue

; If note = -1 then skip.
COMPARE NoteValue -1
ISEQUAL NextNote
; (with no UPS)

; Check if Echo Note is Empty
;
setstring count Ticknum
ADD EchoSetting count
;
SETARRAYPOINTER 1 count 0
GETARRAY EchoNoteValue
COMPARE EchoNoteValue -1
ISGREATER NextNote2

; Key in the Note

SETARRAYPOINTER 2 ticknum 0
GETARRAY VolumeValue
COMPARE VolumeValue -1
ISGREATER SkipSet128
setstring VolumeValue 128
LABEL SkipSet128

DIVIDE 2 VolumeValue

compare minecho VolumeValue
isgreater NextNote

SETARRAYPOINTER 2 count 0
SETARRAY VolumeValue
SETARRAYPOINTER 1 count 0
SETARRAY NoteValue
LABEL NextNote2

LABEL NextNote

ADD 1 TickNum

mton
TEXTFIELD_SETSTRING somewin handle=mytext,text=TickNum
mtoff

COMPARE SettingNumRows TickNum
ISGREATER BeginEcho
mton
SETACTIVESCREEN PATTERN
ACTIVATE

VBKEY {PGUP}{PGUP}{PGUP}{PGUP}{PGUP}{PGUP}
VBKEY {PGUP}{PGUP}{PGUP}{PGUP}{PGUP}{PGUP}
VBKEY {PGUP}{PGUP}{PGUP}{PGUP}{PGUP}{PGUP}
VBKEY {PGUP}{PGUP}{PGUP}{PGUP}{PGUP}{PGUP}{home}
VBKEY {home}{home}{home}{home}

GOTOCOLUMN VolumeX

WRITEARRAYTOCOLUMN 2 rows

VBKEY {PGUP}{PGUP}{PGUP}{PGUP}{PGUP}{PGUP}
VBKEY {PGUP}{PGUP}{PGUP}{PGUP}{PGUP}{PGUP}
VBKEY {PGUP}{PGUP}{PGUP}{PGUP}{PGUP}{PGUP}
VBKEY {PGUP}{PGUP}{PGUP}{PGUP}{PGUP}{PGUP}{home}

GOTOCOLUMN NoteX

WRITEARRAYTONOTECOLUMN 1 rows

LABEL SkipScript

ENDSCRIPT