/* FuNNy HippoPlayer aka SlideSHOW - Eli0t/cONTORTIOn (c) 01/07/96

      configure the following and be sure you have NO start-up
     PROGRAM "ON" and your playing mode is "MODULE REPEATEDLY",
   also the display mode MUST be "Time/duration, pos/len", because
        only in this mode REXX can retrieve the playing time!

   Don't kick my ass for the use of "signal" command - it's funny!

                                                            - Eli0t - */



MAXTIME='360'                /* maximal time limit */
RNDTIME='18'                 /* time to wait on the starting track */

PRELOAD='7'                  /* "preload" time */
ZIPSTAT='0'                  /* start-up ZIP status */

CBINARY='C:hip'              /* HippoPlayer path + name => fullpath */
PROGRAM='MODS:progs/hippo'   /* "slideshow" Hippo-program to be played */


/* if ya TOUCH the following "code", let me know at <eliot@sci.muni.cz> */



SIGNAL ON break_c
SIGNAL ON failure
SIGNAL ON syntax
SIGNAL ON halt

options results
parse arg FILENAME

if getclip('HippoFuNNyPlayer')=='PLAYING' then
call setclip('HippoFuNNyPlayer','FUCKOFF')

cliploop:
if getclip('HippoFuNNyPlayer')~=='' then signal cliploop:
call setclip('HippoFuNNyPlayer','PLAYING')


call random(,,time(s))

if ~show("p","HIPPOPLAYER") then
do
     say 'EXECUTING THE HIPPO BINARY'
     address 'COMMAND'
     CBINARY
     address
end

hiploop:
if ~show("p","HIPPOPLAYER") then signal hiploop

if pos(':',filename)=0 then
do
     address 'HIPPOPLAYER'
     zip ZIPSTAT
     loadprg PROGRAM
     address

     WAITER=1
     NUMSNG=1
     STARTPOS=1

     JMENO=''
     STARTCAS=time(s)

mainloop1:
if ~show("p","HIPPOPLAYER") then signal halt

     if NUMSNG=1 then
     do
          say ''
          say 'LOADING RANDOM MODULE...'
          if ~show("p","HIPPOPLAYER") then signal halt
          address 'HIPPOPLAYER'
          randplay
          CLEARING=1
          get cspo
          STARTPOS=result
          STARTCAS=time(s)
          address
     end
     else
     do
          if ~show("p","HIPPOPLAYER") then signal halt
          address 'HIPPOPLAYER'
          get csng
          k=result
          address
          MEMO.k=1
          k=random(1,NUMSNG)
          j=k
          if MEMO.k=1 then
               do k=j to (NUMSNG-1) until MEMO.k=0
               end
          if MEMO.k=1 then
               do k=1 to (j-1) until MEMO.k=0
               end
          if MEMO.k=1 then
          do
               if ~show("p","HIPPOPLAYER") then signal halt
               CLEARING=1
               say ''
               say 'ALL MULTIS PLAYED!'
               say 'LOADING RANDOM MODULE...'
               address 'HIPPOPLAYER'
               randplay
               get nsng
               if result>1 then CLEARING=1
               else CLEARING=0
               get cspo
               STARTPOS=result
               STARTCAS=time(s)
               address
          end
          else
          do
               if ~show("p","HIPPOPLAYER") then signal halt
               CLEARING=0
               address 'HIPPOPLAYER'
               stop
               songplay k
               get cspo
               STARTPOS=result
               STARTCAS=time(s)
               address
               say 'Song:' k
          end
     end

     if ~show("p","HIPPOPLAYER") then signal halt
     address 'HIPPOPLAYER'
     get mspo
     MAXPOS=result
     get dura
     if result>0 then WAITER=result-PRELOAD
          else WAITER=random(3 * (MAXPOS-STARTPOS),(10 * (MAXPOS-STARTPOS)))
     if WAITER<40 then WAITER=40+random(1,30)
     if WAITER>=MAXTIME then WAITER=MAXTIME
     get curr
     JMENO=result
     get nsng
     NUMSNG=result
     address
     if CLEARING=1 then say '['JMENO']' NUMSNG 'song(s) | timeout:' WAITER
     else say 'timeout:' WAITER

     if CLEARING=1 then
     do i=1 to NUMSNG
          MEMO.i=0
     end

mainloop2:
     if getclip('HippoFuNNyPlayer')=='FUCKOFF' then signal stop
     if ~show("p","HIPPOPLAYER") then signal halt
     address 'HIPPOPLAYER'
     get play
     address
     if result~=1 then signal stop
     if ~show("p","HIPPOPLAYER") then signal halt
     address 'HIPPOPLAYER'
     get curr
     address
     if result~=JMENO then
     do
          if ~show("p","HIPPOPLAYER") then signal halt
          address 'HIPPOPLAYER'
          get mspo
          MAXPOS=result
          get cspo
          STARTPOS=result
          get curr
          JMENO=result
          get dura
          if result>0 then WAITER=result-PRELOAD
               else WAITER=random(3 * (MAXPOS-STARTPOS),(10 * (MAXPOS-STARTPOS)))
          if WAITER<40 then WAITER=40+random(1,30)
          if WAITER>=MAXTIME then WAITER=MAXTIME
          address
          if ~show("p","HIPPOPLAYER") then signal halt
          address 'HIPPOPLAYER'
          get nsng
          NUMSNG=result
          address
          STARTCAS=time(s)
          say '['JMENO']' NUMSNG 'song(s) | timeout:' WAITER
          do i=1 to NUMSNG
               MEMO.i=0
          end
     end
     if NUMSNG>1 then
     do
          if ~show("p","HIPPOPLAYER") then signal halt
          address 'HIPPOPLAYER'
          get cspo
          CURRPOS=result
          if CURRPOS=STARTPOS then
          do
               if (time(s)>(STARTCAS+RNDTIME)) then
               do
                    STARTCAS=time(s)
                    WAITER=0
               end
          end
          else STARTPOS=0
          address
     end

     CAS=time(s)
     if (CAS-STARTCAS)>=WAITER then signal mainloop1
     else signal mainloop2

end
else
do
     say 'PLAYING:' FILENAME
     if ~show("p","HIPPOPLAYER") then signal halt
     address 'HIPPOPLAYER'
     play FILENAME
     address
end
signal blah

stop:
say ''
say 'STOPPED!'
signal blah

syntax:
break_c:
failure:
halt:
say ''
say 'TERMINATING on line:' SIGL

blah:
if getclip('HippoFuNNyPlayer')~=='' then
     call setclip('HippoFuNNyPlayer','')
exit
