home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / music / mrmidi / eject.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1998-03-08  |  5.2 KB  |  135 lines

  1. /* Eject.rexx */
  2.  
  3. options results; address MrMIDI; signal on syntax
  4.  
  5. ASLFR_InitialDrawer    = 0x80080009;    ASLFR_InitialFile    = 0x80080008
  6. MUIA_List_Active    = 0x8042391c;    MUIA_List_Entries    = 0x80421654
  7. MUIA_Window_Sleep    = 0x8042e7db;    MUIV_List_Active_Top    = -2
  8. MUIV_List_Insert_Active = -1;        MUIV_List_Insert_Bottom = -3
  9. MUIV_List_Insert_Sorted = -2
  10.  
  11. window ID WIND1 ATTRS MUIA_Window_Sleep 1
  12. window ID WIND2 ATTRS MUIA_Window_Sleep 1
  13. RC = 0
  14. popasl ID FPATH; fpath = result
  15. temp_name = TmpFile('PIPE:MIDI_List.')
  16. address command 'RequestFile >'temp_name' DRAWER "'fpath'" PATTERN "#?.(mid|midi|kar|list)"
  17.   TITLE "Select MIDI files/song lists" MULTISELECT NOICONS'
  18. if RC = 0 & open(1, temp_name, 'r') then do
  19.   list ID SLIST ATTRS MUIA_List_Entries; entries = result
  20.   if entries ~= 0 then do
  21.     call Clear.rexx
  22.     entries = 0
  23.   end
  24.   do while ~eof(1)
  25.     if readch(1, 1) = '"' then do
  26.       temp_list = ''
  27.       do until temp_char = '"'
  28.         temp_char = readch(1, 1)
  29.         if eof(1) then break
  30.         if temp_char ~= '"' then temp_list = temp_list||temp_char
  31.       end
  32.       if exists(temp_list) then do
  33.         if translate(right(temp_list, 5)) = '.LIST' then do
  34.           if open(2, temp_list, 'r') then do
  35.             do forever
  36.               temp = readln(2)
  37.               if eof(2) then leave
  38.               if entries = 0 then
  39.                 list ID SLIST INSERT POS MUIV_List_Insert_Bottom STRING temp
  40.               else do
  41.                 list ID SLIST ATTRS MUIA_List_Entries; temp_max = result
  42.                 skip = 0
  43.                 do i = 0 to temp_max - 1
  44.                   list ID SLIST POS i
  45.                   if temp = result then do
  46.                     skip = 1
  47.                     break
  48.                   end
  49.                 end
  50.                 if ~skip then
  51.                   list ID SLIST INSERT POS MUIV_List_Insert_Active STRING temp
  52.               end /* of if entries */
  53.             end /* of do forever */
  54.             call close(2)
  55.           end /* of if open */
  56.           else do
  57.             temp_string = "Could not open the file '"temp_list"'."
  58.             request ID WARN GADGETS '"OK"' temp_string
  59.           end
  60.         end /* of if right */
  61.         else do
  62.           popasl ID PATH; pathname = result
  63.           temp_name = TmpFile('PIPE:MIDI_Temp.')
  64.           address command 'ReadMIDI "'temp_list'" >'temp_name
  65.           if open(2, temp_name, 'r') then do
  66.             null = readln(2)
  67.             format = readln(2)
  68.             total_tracks = readln(2)
  69.             division = readln(2)
  70.             temp_song_time = readln(2)
  71.             call close(2)
  72.             if left(null, 4) = 'MIDI' then do
  73.               parse var format dummy': 'format
  74.               parse var total_tracks dummy': 'total_tracks
  75.               parse var division dummy': 'division
  76.               parse var temp_song_time dummy': 'temp_song_time
  77.               if index(temp_list, ',') = 0 then do
  78.                 if entries = 0 then
  79.                   list ID SLIST INSERT POS MUIV_List_Insert_Bottom,
  80.                     STRING temp_list','temp_song_time','format','total_tracks','division
  81.                 else do
  82.                   list ID SLIST ATTRS MUIA_List_Entries; temp_max = result
  83.                   skip = 0
  84.                   do i = 0 to temp_max - 1
  85.                     list ID SLIST POS i
  86.                     parse var result temp_name','dummy
  87.                     if temp_list = temp_name then do
  88.                       skip = 1
  89.                       break
  90.                     end
  91.                   end
  92.                   if ~skip then
  93.                     list ID SLIST INSERT POS MUIV_List_Insert_Active,
  94.                       STRING temp_list','temp_song_time','format','total_tracks','division
  95.                 end
  96.               end /* of if index */
  97.               else request ID WARN GADGETS '"OK"' '"Cannot insert the filename with comma."'
  98.             end /* of if null */
  99.             else request ID WARN GADGETS '"OK"' '"Corrupted MIDI file."'
  100.           end /* of if open */
  101.           else request ID WARN GADGETS '"OK"' '"Could not open a pipe."'
  102.         end
  103.       end /* of if exists */
  104.       else do
  105.         temp_string = "Could not open the file '"temp_list"'."
  106.         request ID WARN GADGETS '"OK"' temp_string
  107.       end
  108.     end /* of if readch */
  109.   end /* of do while */
  110.   call close(1)
  111.   list ID SLIST ATTRS MUIA_List_Entries; temp_max = result
  112.   setvar max temp_max
  113.   text ID MAX LABEL "\033b\033r"right(temp_max, 3)
  114.   temp_total_time = 0
  115.   do i = 0 to temp_max - 1
  116.     list ID SLIST POS i
  117.     parse var result dummy','temp_song_time','dummy2
  118.     temp_total_time = temp_total_time + left(temp_song_time, 2) * 60 + right(temp_song_time, 2)
  119.   end
  120.   temp_string = right(temp_total_time % 3600, 2, 0)||":"||,
  121.     right(temp_total_time // 3600 % 60, 2, 0)":"right(temp_total_time // 60, 2, 0)
  122.   setvar total_time temp_string
  123.   text ID TOTAL LABEL "\033b\033r"temp_string
  124.   list ID SLIST ATTRS MUIA_List_Active MUIV_List_Active_Top
  125. end /* of if open */
  126. window ID WIND2 ATTRS MUIA_Window_Sleep 0
  127. window ID WIND1 ATTRS MUIA_Window_Sleep 0
  128. return
  129.  
  130. syntax:
  131.   request ID WARN GADGETS '"OK"' '"\033b\033cError 'RC' in line 'SIGL':\033n\012\033c'errortext(RC)'"'
  132.   window ID WIND2 ATTRS MUIA_Window_Sleep 0
  133.   window ID WIND1 ATTRS MUIA_Window_Sleep 0
  134.   return
  135.