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

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