/*
      $VER: dIROPUS_eAGLEpLAYER_aREXX_cONTROL_sCRIPT v1.5 (05.09.94)

                              bY STuN/MYSTiC

             (tESTED wITH eAGLEpLAYER v1.52b & dIROPUS v4.11)

     This script is based on the original ones by DEFECT, but it's so
     greatly improved that you'll hardly notice anything in common!
     For usage infoz read the doc file included in the original LHA
     archive...

     To contact me call tRACKLAND (+39-2-798035) from 22:30 to 02:30
     (Italian time!)... bYE!!!
*/

parse arg filename   /* 'filename' is the mod filename or an argument */

options results

pausedstate=0
EPactive=pos('rexx_EP',show('Ports'))  /* inactive if 0 */

address 'DOPUS.1'
toptext '-    -   -  - - -+ bE pATIENT -+- - -  -   -    -'

/****** Argument: None ******/
If length(filename)<1 then
do
 call NOARGS
 exit
end
/****** Argument: PAUSE ******/
if upper(filename)='PAUSE' then
do
 call PAUSE
 exit
end
/****** Argument: REPLAY ******/
if upper(filename)='REPLAY' then
do
 call REPLAY
 exit
end
/****** Argument: EJECT ******/
if upper(filename)='EJECT' then
do
 call EJECT
 exit
end
/****** Argument: MODINFO1 ******/
if upper(filename)='MODINFO1' then
do
 call MODINFO1
 exit
end
/****** Argument: MODINFO2 ******/
if upper(filename)='MODINFO2' then
do
 call MODINFO2
 exit
end
/****** Argument: PLAYINFO ******/
if upper(filename)='PLAYINFO' then
do
 call PLAYINFO
 exit
end
/****** Argument: NEXTSUBSONG - PREVSUBSONG *******/
if upper(filename)='NEXTSUBSONG' then
do
 subsongchmode=1
 call CHSUBSONG
 exit
end
if upper(filename)='PREVSUBSONG' then
do
 subsongchmode=2
 call CHSUBSONG
 exit
end
/****** Argument: EP2DOPUS *******/
if upper(filename)='EP2DOPUS' then
do
 call EP2DOPUS
 exit
end
/****** Argument: QUIT *******/
if upper(filename)='QUIT' then
do
 call QUIT
 exit
end
/****** Argument: Module filename (loads EP if not active) ******/
if EPactive = 0 then
do
 address 'DOPUS.1'
 busy on
 checkabort
 Waittime=60         /* 1 min waiting time (to see if something
                        goes wrong while loading)... adapt it
                        to your needs! */
 toptext 'EaglePlayer not active! (Press both mouse buttons NOW to abort loading)'
 call delayabort 2
 if ~ Exists('EaglePlayer') then
 do
  toptext 'Canīt find EaglePlayer in current dir! (Check DirOpus configuration!)'
  busy off
  exit
 end
 toptext '           .o(  eAGLEpLAYER cONTROL sCRIPT bY STuN/MYSTiC  )o.           '
 call delayabort 1
 toptext '!wAIT!     .o(  eAGLEpLAYER cONTROL sCRIPT bY STuN/MYSTiC  )o.     !wAIT!'
 busy off
 address COMMAND 'EaglePlayer'  /* No need to change path here cuz the */
 testflag=0                     /* 'EP Play' button does it! */
 time ('R')
 do while (testflag=0) & (time('E') < Waittime)
  if (pos('rexx_EP',show('Ports')) ~= 0) then testflag=1
 end

 if pos('rexx_EP',show('Ports')) ~= 0 then
 do
  toptext 'EaglePlayer loaded! Now initializing...'
  address 'rexx_EP'
  LittleWin      /* Possible iconify modes: LittleWin, AppItem, AppIcon */
  Iconify on     /* Delete these two lines if you don't wanna iconify */
  Quickstart on  /* I recommend that you leave these prefs as they are! */
  LoadDir off
  SongEnd off
  UseSongName on
  NoNewModule
 end
 else
 do
  address 'DOPUS.1'
  toptext 'Error while loading EaglePlayer!'
  exit
 end
end
call GETDAMOD
EPactive=pos('rexx_EP',show('Ports'))
call MODINFO1
exit


/****** Routinez ******/

DELAY:
 arg delaytime
 time ('R')
 do while time('E') < delaytime
 end
 delaytime=0
return

DELAYABORT:
 arg delaytime
 time ('R')
 do while time('E') < delaytime
  checkabort
  if result then
  do
   toptext 'EaglePlayer loading aborted!'
   busy off
   exit
  end
 end
 delaytime=0
return

GETDAMOD:
 address 'DOPUS.1'
 toptext 'Loading possible module '||filename
 address 'rexx_EP'
 LoadModule filename
 aha=result
 address 'DOPUS.1'
 toptext 'Eagleplayer: '||aha
 call delay 2
 address 'rexx_EP'
 call GETSTATUS
 if left(upper(author),4)='STUN' then
 do
  address 'DOPUS.1'
  toptext 'Oouuuhyeah! This is a production by STuN!!!'
  call delay 2
 end
 if maxsubs>1 then
 do
  address 'DOPUS.1'
  toptext 'Note: This module contains '||maxsubs||' different subsongs! (not 100% sure!)'
  call delay 3
 end
return

NOARGS:
 if EPactive=0 then
 do
  address 'DOPUS.1'
  toptext 'No file selected for playing! (Note: EaglePlayer not yet active)'
  exit
 end
 address 'rexx_EP'
 call GETSTATUS
 if (pnum>0) & (playing="no") then     /* It's paused! */
 do
  Play
  pausedstate=1
  call MODINFO1
 end
 else
 do
  address 'DOPUS.1'
  toptext 'No file selected for playing!'
 end
return

PAUSE:
 if EPactive=0 then
 do
  address 'DOPUS.1'
  toptext 'EaglePlayer not loaded! Nothing to pause!'
  exit
 end
 address 'rexx_EP'
 call GETSTATUS
 if name='RESULT' then
 do
  address 'DOPUS.1'
  toptext 'No module loaded! Nothing to Pause!'
 end
 else
 do
  if playing="yes" then
  do
   Pause
   address 'DOPUS.1'
   toptext 'Module paused! (Select Play or Pause to continue playing!)'
  end
  else
  do
   Play
   pausedstate=1
   call MODINFO1
  end
 end
return

REPLAY:
 if EPactive=0 then
 do
  address 'DOPUS.1'
  toptext 'EaglePlayer not loaded! Nothing to replay!'
  exit
 end
 address 'rexx_EP'
 call GETSTATUS
 if name='RESULT' then
 do
  address 'DOPUS.1'
  toptext 'No module loaded! Nothing to replay!'
  exit
 end
 if restart="no" then
 do
  address 'DOPUS.1'
  toptext 'Sorry, current replayer doesnīt support replay function!'
  call delay 2
  call MODINFO1
 end
 ReplaySong
 address 'DOPUS.1'
 toptext 'Replaying module from the beginning...'
 call delay 2
 call MODINFO1
return

EJECT:
 if EPactive=0 then
 do
  address 'DOPUS.1'
  toptext 'EaglePlayer not loaded! Nothing to eject!'
  exit
 end
 address 'rexx_EP'
 call GETSTATUS
 if name='RESULT' then
 do
  address 'DOPUS.1'
  toptext 'No module loaded! Nothing to eject!'
 end
 else
 do
  Eject
  address 'DOPUS.1'
  toptext 'Module ejected! (Note: EP is still alive!)'
 end
return

QUIT:
 if EPactive=0 then
 do
  address 'DOPUS.1'
  toptext 'Why shall I quit EaglePlayer if itīs not yet loaded???'
 end
 else
 do
  address 'rexx_EP'
  Quit
  address 'DOPUS.1'
  toptext 'EaglePlayer quitted!'
 end
return

EP2DOPUS:
 if EPactive=0 then
 do
  address 'DOPUS.1'
  toptext 'EaglePlayer not loaded! Canīt change public screen!'
 end
 else
 do
  address 'rexx_EP'
  PubScreen DOPUS.1
  address 'DOPUS.1'
  toptext 'EaglePlayer opened on public screen DOPUS.1!'
 end
return

MODINFO1:
 if EPactive=0 then
 do
  address 'DOPUS.1'
  toptext 'EaglePlayer not loaded! Canīt get module infoz!'
  exit
 end
 address 'rexx_EP'
 call GETSTATUS
 if name='RESULT' then
 do
  address 'DOPUS.1'
  toptext 'No module loaded! Canīt get any infoz!'
 end
 else
 do
  address 'DOPUS.1'
  uh='Playing "'
  if pausedstate=1 then uh='UnPaused "'
  if playing="no" then uh='Paused "'
  toptext uh||songname||'" ('||player||') by '||author
 end
return

MODINFO2:
 if EPactive=0 then
 do
  address 'DOPUS.1'
  toptext 'EaglePlayer not loaded! Canīt get module infoz!'
  exit
 end
 address 'rexx_EP'
 call GETSTATUS
 if name='RESULT' then
 do
  address 'DOPUS.1'
  toptext 'No module loaded! Canīt get any infoz!'
 end
 else
 do
  address 'DOPUS.1'
  toptext '"'||name||'"... Pos.'||posit||'/'||pattlen||' ('||songnumb||'/'||maxsubs||')  '||diffpat||' diff.pattz  '||samplez||' sampz'
 end
return

PLAYINFO:
 if EPactive=0 then
 do
  address 'DOPUS.1'
  toptext 'EaglePlayer not loaded! Canīt get player infoz!'
  exit
 end
 address 'rexx_EP'
 call GETSTATUS
 if name='RESULT' then
 do
  address 'DOPUS.1'
  toptext 'No module loaded! Canīt get any infoz!'
 end
 else
 do
  address 'DOPUS.1'
  toptext player||' v'||version||' ('||date||')   Subsongs: '||subs||'  Replay: '||restart
 end
return

CHSUBSONG:
 if EPactive=0 then
 do
  address 'DOPUS.1'
  toptext 'EaglePlayer not loaded! Canīt change anything!'
  exit
 end
 call GETSTATUS
 if name='RESULT' then
 do
  address 'DOPUS.1'
  toptext 'No module loaded! Sucker!'
  exit
 end
 address 'rexx_EP'
 if subs="no" then
 do
  address 'DOPUS.1'
  toptext 'The '||player||' replayer doesnīt support subsongs!'
  address 'rexx_EP'
  if playing="yes" then
  do
   call delay 3
   call MODINFO1
  end
  exit
 end
 if (songnumb=1) & (maxsubs=1) then
 do
  address 'DOPUS.1'
  toptext 'Hey, this is the only song available!'
  if playing="yes" then
  do
   call delay 3
   call MODINFO2
  end
  exit
 end
 if (subsongchmode=1) & (songnumb=maxsubs) then
 do
  address 'DOPUS.1'
  toptext 'This is the last subsong!'
  if playing="yes" then
  do
   call delay 3
   call MODINFO2
  end
  exit
 end
 if (subsongchmode=2) & (songnumb=1) then
 do
  address 'DOPUS.1'
  toptext 'This is the first subsong!'
  if playing="yes" then
  do
   call delay 3
   call MODINFO2
  end
  exit
 end
 address 'DOPUS.1'
 if subsongchmode=1 then
 do
  toptext 'Playing next subsong (nr.'||songnumb+1||')...'
  address 'rexx_EP'
  NextSong
 end
 else
 do
  toptext 'Playing previous subsong (nr.'||songnumb-1||')...'
  address 'rexx_EP'
  PrevSong
 end
 call delay 3
 call MODINFO2
return

GETSTATUS:
 address 'rexx_EP'

 status g ply           /* Is the module playing? */
 playing=result

 status g snd          /* Actual Songnumber */
 songnumb=result

 status m fil           /* Filename of current module */
 name=result

 status m son           /* Songname of current module */
 songname=result
 if songname='Unknown !' then songname=name

 status m aut           /* Name of composer */
 author=result
 if author='Unknown !' then author='<Unknown>'

 status m pnr           /* Number of current player (0 -> no module!) */
 pnum=result

 status m pon           /* Actual position number */
 posit=result

 status m len           /* Patternlength */
 pattlen=result
 if posit+pattlen>510 then
 do
  posit=N
  pattlen=A
 end

 status m max           /* Max. subsongs available */
 maxsubs=result

 status m dpt           /* Number of different patterns */
 diffpat=result
 if diffpat>255 then diffpat='N/A'

 status m sam           /* Number of used samples */
 samplez=result
 if samplez>255 then samplez='N/A'

 'status p 'pnum' nam'  /* Name of current player */
 player = result

 'status p 'pnum' ver'  /* Version number of current player */
 version=result

 'status p 'pnum' dat'  /* Creation date of current player */
 date=result
 if date='Unknown !' then date='??.??.??'

 'status p 'pnum' sub'  /* Player supports subsongs? */
 subs=result

 'status p 'pnum' rst'  /* Player supports Replay? */
 restart=result

 /*** Here we get around some 'defects' of EaglePlayer (v1.52b) ***/

 /* Subsongnumbers are crap! */
 if songnumb=0 then songnumb=1
 maxsubs=maxsubs+1

 /* Name of TrackerPacker3 songs isn't detected correctly!!! */
 if upper(songname)='TP3' then songname=name
return
