/* Convert ONESHOT-Instruments into CONT's in a macro */
/* Note: This does not create a LOOP-Definition, but it
         exchanges eg. 'A' into 'a', etc. */

options results
address 'mmv8'

call checkifvalid

ASKMACROLENGTH  ; mlen=result
GETMACRONUM     ; mnum=result
GETSLOTNUM      ; slot=result
say 'Received results are: Macro:'mnum' Slot#:'slot' Macrolen:'mlen

ASKMACRO mnum     /* Does macro exist ? Or is it empty ? */
if result='UNUSED'|result='EMPTY' then do
   say 'Macro is empty !'
   exit
end

options prompt "Please enter ONESHOT-Instrument to convert: "
qwe=0
do while qwe=0
  parse pull osht
  qwe = index(' ABCDEFGHIJKLMNOPQRSTUVWXYZ',osht)
end
cont= word('a b c d e f g h i j k l m n o p q r s t u v w x y z',qwe-1)

do i=0 to mlen-1
   GETNOTE mnum i
   if result~='' & result~='------' & word(result,1)=osht then do
         SETNOTE mnum i cont word(result,2) word(result,3)
         end
end

exit


/* Standard */
checkifvalid: PROCEDURE
ASKCOMMANDSET     /* Returns: 'EXTENDED' when from MacEd */
 if result='NORMAL' then coset='TrEd or CommandMode'
                    else coset='MacEd'
say 'MusicMaker called this ARexx macro from 'coset
if result='NORMAL' then do
                        say 'This is a MacEd-ARexx macro !'
                        exit 20
                        end
return
