home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / jukemb10.zip / player.nrx < prev    next >
Text File  |  1997-05-24  |  6KB  |  249 lines

  1. options nocrossref
  2.  
  3. import RXFile
  4.  
  5. class player extends Frame implements MainThread
  6.  
  7. properties public
  8.  
  9. rx = RXFile()
  10. rx2 = RXFile()
  11. rxSet = RXFile()
  12. rHowManyFld = Rexx
  13. rHowManyRec = Rexx
  14. rFieldName = Rexx[]
  15. rFieldValue = Rexx[,]
  16. iCount = int
  17. iCount2 = int
  18. iSongPlaying = int 1
  19. iMaxLength = 0
  20. -- rCommand = Rexx 'f:\\progs\\timidos2\\timidity.exe -Od1S -idq -L f:\\progs\\timidos2 d:\\folders\\midi\\best\\'
  21. rCommand = Rexx 'cmd.exe /c play.cmd FILE="DRIVE:\\DIRECTORY\\'
  22. pr2 = Process
  23. rtime = Runtime
  24. bPlaying = boolean 0
  25. bStopped = boolean 0
  26. jbplayer = jbplay
  27. laCommand = Label("Command:")
  28. lacurr2 = Label("[NONE]                           ")
  29. tfCommand = TextField(rCommand)
  30. bStartIt = Button("Start")
  31. bNext = Button("Next >>")
  32. bPrev = Button("<< Prev")
  33. bStop = Button("Stop")
  34. cbLoop = Checkbox("Loop list")
  35. liTitles = List
  36. iTitle = int
  37.  
  38.  
  39.  
  40. method main(s=String[]) static
  41.  s=s
  42.  player()
  43.  
  44.  
  45.  
  46. method player
  47.  
  48. super("Jukebox! (1 song)")
  49. super.setResizable(1)
  50.  
  51. jbplayer = jbplay(MainThread this)
  52.  
  53. rHowManyFld = rx.linein() /* How many fields? */
  54. rFieldName = Rexx[rHowManyFld + 1]
  55. loop iCount = 1 to rHowManyFld
  56.  rFieldName[iCount] = rx.linein() /* Get field names */
  57.  if rFieldName[iCount].length > iMaxLength then
  58.   iMaxLength = rFieldName[iCount].length
  59. end
  60.  
  61. rHowManyRec = rx.linein() /* How many records? */
  62. rFieldValue = Rexx[rHowManyFld + 1, rHowManyRec + 1]
  63. loop iCount = 1 to rHowManyRec /* Records */
  64.  loop iCount2 = 1 to rHowManyFld
  65.   rFieldValue[iCount2, iCount] = rx.linein()
  66.  end
  67. end
  68.  
  69. /* 
  70.    Now we have:
  71.       in rFieldName[1..rHowManyFld] all the field names.
  72.       in rFieldValue[1..rHowManyFld, 1..rHowManyRec] all the records that the user
  73.       has selected before calling the plugin, field by field and record by record.
  74. */
  75.  
  76. iTitle = 0
  77. loop iCount = 1 to rHowManyFld
  78.  if rFieldName[iCount].upper().lastpos("TIT") \= 0 then
  79.   iTitle = iCount
  80. end
  81. if iTitle = 0 then exit
  82. setupFrame
  83.  
  84.  
  85.  
  86. method setupFrame
  87.  cbLoop.setState(1)
  88.  
  89.  liTitles = List(10, 0)
  90.   loop i = 1 to rHowManyRec
  91.   liTitles.addItem(rFieldValue[iTitle, i].strip())
  92.  end 
  93.  
  94.  if rxSet.stream("launcher.ini", "c", "query exists") \= "" then
  95.  do
  96.   rxSet.stream("launcher.ini", "c", "open read")
  97.   rCommand = rxSet.linein
  98.   rxSet.stream("c", "close")
  99.  end
  100.  if rCommand.strip() = "" then
  101.   rCommand = Rexx 'cmd.exe /c play.cmd FILE="DRIVE:\\DIRECTORY\\'
  102.  tfCommand.setText(rCommand)
  103.  
  104.  pTwo = Panel()
  105.  pThree = Panel()
  106.  pFour = Panel()
  107.  pFive = Panel()
  108.  
  109.  rtime = Runtime.getRuntime()
  110.  
  111.  pTwo.setLayout(GridLayout(1, 2))
  112.  pTwo.add(laCurr2)
  113.  pTwo.add(cbLoop)
  114.  pFive.setLayout(GridLayout(2, 1))
  115.  pThree.setLayout(FlowLayout(FlowLayout.LEFT))
  116.  pThree.add(laCommand)
  117.  pThree.add(tfCommand)
  118.  pFive.add(pThree)
  119.  pFive.add(pTwo)
  120.  
  121.  pFour.setLayout(GridLayout(1, 4))
  122.  pFour.add(bStartit)
  123.  pFour.add(bPrev)
  124.  pFour.add(bNext)
  125.  pFour.add(bStop)
  126.  
  127.  this.add("North", pFive)
  128.  this.add("Center", liTitles)
  129.  this.add("South", pFour)
  130.  this.reshape(Toolkit.getDefaultToolkit.getScreenSize.width % 2 - 300, Toolkit.getDefaultToolkit.getScreenSize.height %2 - 140, 600, 280)
  131.  if rHowManyRec > 1 then
  132.   this.setTitle("Jukebox! ("rHowManyRec" songs)")
  133.  this.show()
  134.  
  135.  
  136. method handleEvent(e=Event) returns boolean
  137.   if e.target = bStartIt then Stop(3)
  138.   if e.target = bNext then Stop(1)
  139.   if e.target = bPrev then Stop(2)
  140.   if e.target = bStop then Stop(0)
  141.   if e.target = liTitles & e.id = Event.LIST_SELECT then PlayAt(liTitles.getSelectedIndex() + 1)
  142.   if e.id=Event.WINDOW_DESTROY then
  143.   do
  144.    Stop(0)
  145.    rxSet.delete("launcher.ini")
  146.    rxSet.stream("launcher.ini", "c", "open write")
  147.    rxSet.lineout(tfCommand.getText)
  148.    rxSet.stream("c", "close")
  149.    exit
  150.   end
  151.   return super.handleEvent(e)
  152.  
  153.  
  154.  
  155. method Stop(i = int)
  156.   bStopped = 1
  157.   if pr2 \= null then
  158.   do
  159.    pr2.destroy()
  160.    pr2.waitFor()
  161.    pr2 = null
  162.   catch InterruptedException
  163.   end
  164.   bplaying = 0
  165.   if i = 1 then
  166.    sendNext2
  167.   else if i = 2 then
  168.    sendPrev 
  169.   else if i = 3 then
  170.    sendIt
  171.  
  172.  
  173. method sendNext
  174.  
  175.  if bStopped = 1 then return
  176.  
  177.  if iSongPlaying = rHowManyRec then 
  178.   if cbLoop.getState = 0 then
  179.    return
  180.   else
  181.    iSongPlaying = 0
  182.  
  183.  bPlaying = 1
  184.  iSongPlaying = iSongPlaying + 1
  185.  DiscChanger()
  186.  
  187.  
  188. method sendIt
  189.  
  190.  bPlaying = 1
  191.  DiscChanger()
  192.  bStopped = 0
  193.  
  194.  
  195. method PlayAt(index = int)
  196.  bStopped = 1
  197.  if pr2 \= null then
  198.  do
  199.   pr2.destroy()
  200.   pr2.waitFor()
  201.   pr2 = null
  202.  catch InterruptedException
  203.  end
  204.  bPlaying = 1
  205.  iSongPlaying = index
  206.  DiscChanger()
  207.  bStopped = 0
  208.  
  209.  
  210. method sendNext2
  211.  
  212.  if iSongPlaying = rHowManyRec then 
  213.   if cbLoop.getState = 0 then
  214.    return
  215.   else
  216.    iSongPlaying = 0
  217.  
  218.  bPlaying = 1
  219.  iSongPlaying = iSongPlaying + 1
  220.  DiscChanger()
  221.  bStopped = 0
  222.  
  223. method sendPrev
  224.  
  225.  if iSongPlaying = 1 then return
  226.  bPlaying = 1
  227.  iSongPlaying = iSongPlaying - 1
  228.  DiscChanger()
  229.  bStopped = 0
  230.  
  231.  
  232. method DiscChanger
  233.  
  234.  lacurr2.setText("Q:"rFieldValue[iTitle, iSongPlaying].strip())
  235.  jbplayer = jbplay(MainThread this)
  236.  rCommand = tfCommand.getText()
  237.  if (rCommand.countstr('"') % 2 * 2) \= rCommand.countstr('"') then
  238.   jbplayer.PlayIt(tfCommand.getText() || rFieldValue[iTitle, iSongPlaying].strip() || '"')
  239.  else
  240.   jbplayer.PlayIt(tfCommand.getText() || rFieldValue[iTitle, iSongPlaying].strip())
  241.  jbPlayer.start()
  242.  lacurr2.setText("P:"rFieldValue[iTitle, iSongPlaying].strip())
  243.  liTitles.makeVisible(iSongPlaying - 1)
  244.  liTitles.select(iSongPlaying - 1)
  245.  
  246.  
  247. method setProcess(pr = Process)
  248.  pr2 = pr
  249.