REM > MakePScr REM REM Build a Cubase patch script from lists of patch names. REM REM Hipposoft 2005. REM REM History REM ======= REM REM v0.01 (14-Jul-2005) (ADH): Created. REM v0.02 (16-Jul-2005) (ADH): Option to add patch number and bank as a REM prefix or suffix. Modified the layout of the REM output file a bit. REM v0.03 (16-Jul-2005) (ADH): Added ability to specify modes and drum maps. REM Fixed a few bugs and typos; split main REM section up into various black box functions. REM v0.04 (17-Jul-2005) (ADH): Added Cubase SX XML drum map export. This REM perhaps ought to be in a separate program, REM since the name "MakePScr" is no longer very REM accurate! But there is so much shared data in REM this and the patch script, it's worth keeping REM them combined for now. in%=0 ou%=0 ON ERROR PROCclose: PRINT REPORT$; " at line ";ERL: END REM Base path of patch name files basepath$="hostfs::HardDisc4.$.MyFiles.Supernova." REM Leaf name of Cubase patch script; used as the left hand of REM the name of the Cubase SX drum map files (if any) too. script$="Supernova-2" REM You can add a prefix or suffix to each patch name. It takes REM the form of the last letter of the bank name, then the patch REM number padded to three digits - e.g. "A044". prefix% = TRUE suffix% = FALSE REM User banks (see below) are defined in groups of userpatches% REM patches, with base name username$. If you want to prefix or REM suffix with patch numbers, as with prefix% and suffix% REM above, set userprefix% and usersuffix%. User *drum* banks REM for the patch scripts are defined in groups of drumpatches% REM items. userpatches% = 128 username$ = "User defined" userprefix% = TRUE usersuffix% = FALSE drumpatches% = 50 REM Drum bank channel. Drum maps in Cubase SX seem to work with REM each drum having an independent channel output specifier. Use REM a MIDI channel number from 1 to 16, or 0 for "any". When set REM to 0 for "any", the channel number for the MIDI track using REM the drum map is used; else the drum map overrides it. drumchannel% = 0 REM Most of the other configuration is done through data REM statements in the following functions: REM REM PROCdefineheaderdata REM PROCdefinepatchdata REM PROCdefinedrumdata REM Output the header. PRINT "Creating '"+basepath$+script$+"'..." ou%=OPENOUT(basepath$+script$) PROCdefineheaderdata PROCoutputheader REM Run through all of the patch name files. PROCdefinepatchdata PROCoutputpatches REM Run through all of the drum name files. PROCdefinedrumdata PROCoutputvstdrums REM Output the footer and close the output file, setting REM the filetype to plain text. PROCoutputfooter CLOSE#ou%:ou%=0 OSCLI "SetType "+basepath$+script$+" Text" REM Now output any accompanying XML drum map REM definitions for Cubase SX. PROCdefinedrumdata PROCoutputxmldrums REM All done. PRINT "Done!" END : REM Utility functions DEFPROCclose IF in%<>0 THEN CLOSE#in%: in%=0 IF ou%<>0 THEN CLOSE#ou%: ou%=0 ENDPROC : DEFFNtruncate(a$) WHILE RIGHT$(a$)=" " a$=LEFT$(a$) ENDWHILE =a$ : REM Data functions DEFPROCdefineheaderdata REM Comment, creators first and last name, device manufacturer, REM device name, script name, script version RESTORE +1 DATA "Made by Pond: http://pond.org.uk" DATA "Andrew" DATA "Hodgkinson" DATA "Novation" DATA "Supernova 2 OS 2" DATA "Supernova-2" DATA "Version 1.01" ENDPROC : DEFPROCdefinepatchdata REM Data defining patch banks. REM REM Bank number, associated patch file, bank name. An entry REM with a bank number of -1 terminates the list. An entry REM with a bank number of -2 defines a new mode for the REM following sections; use -2, an empty string, then the REM mode name. REM REM A bank defined with an empty filename is taken as a user REM bank, and defined according to the various "user..." REM variables described above. RESTORE +1 DATA -2, "", "Performances" DATA 01, "OS2 perf bank A", "Performance A" DATA 02, "OS2 perf bank B", "Performance B" DATA 03, "", "Performance C" DATA 04, "", "Performance D" DATA -2, "", "Programs" DATA 05, "OS2 prog bank A", "Program A" DATA 06, "OS2 prog bank B", "Program B" DATA 07, "OS2 prog bank C", "Program C" DATA 08, "OS2 prog bank D", "Program D" DATA 09, "OS2 prog bank E", "Program E" DATA 10, "OS2 prog bank F", "Program F" DATA 11, "OS2 prog bank G", "Program G" DATA 12, "OS2 prog bank H", "Program H" DATA -2, "", "Arpeggiator" DATA 13, "SN 2 Arp 1", "Arp (Mono) S" DATA 14, "SN 2 Arp 2", "Arp (Poly) T" DATA 15, "", "Arp (User) U" DATA 16, "", "Arp (User) V" DATA 17, "", "Arp (User) W" DATA -1, "", "" ENDPROC : DEFPROCdefinedrumdata REM Data defining drum maps. REM REM Bank number, starting key number (60 is middle 'C' or REM C3 in Cubase; drum maps usually start at C1, key 36), REM associated patch file, bank name, and finally, a value REM to append to the leaf name of the Cubase patch script REM to get the leafname of the XML file for Cubase SX. REM REM End the list with a bank number of -1. As with patch REM names, use -2 for a mode specifier, for example: REM REM DATA -2, 0, "", "Mode name" RESTORE +1 DATA -2, 0, "", "Drum maps", "" DATA 18, 36, "OS2 drum bank a", "Drum bank A", "-DrumA" DATA 19, 36, "OS2 drum bank b", "Drum bank B", "-DrumB" DATA 20, 36, "OS2 drum bank c", "Drum bank C", "-DrumC" DATA 21, 36, "OS2 drum bank d", "Drum bank D", "-DrumD" DATA 22, 36, "", "Drum bank E", "" DATA 23, 36, "", "Drum bank F", "" DATA 24, 36, "", "Drum bank G", "" DATA 25, 36, "OS2 drum bank h", "Drum bank H", "-DrumH" DATA -1, 0, "", "", "" ENDPROC : REM Data output routines DEFPROCoutputheader READ comment$ BPUT#ou%,"[cubase parse file]"+CHR$(13) BPUT#ou%,"[parser version 0001]"+CHR$(13) BPUT#ou%,"[comment] "+comment$+CHR$(13) BPUT#ou%,CHR$(13) READ firstname$, lastname$, maker$ READ dname$, sname$, version$ BPUT#ou%,"[creators first name] "+firstname$+CHR$(13) BPUT#ou%,"[creators last name] "+lastname$+CHR$(13) BPUT#ou%,"[device manufacturer] "+maker$+CHR$(13) BPUT#ou%,"[device name] "+dname$+CHR$(13) BPUT#ou%,"[script name] "+sname$+CHR$(13) BPUT#ou%,"[script version] "+version$+CHR$(13) BPUT#ou%,CHR$(13) BPUT#ou%,"[define patchnames]"+CHR$(13) ENDPROC : DEFPROCoutputpatches REPEAT READ bank%, namefile$, name$ REM Define a new bank and output the patches. IF bank% >= 0 THEN BPUT#ou%,CHR$(13) BPUT#ou%,"[g1] " + name$ + CHR$(13) REM Is this user defined, or is there a patch file? IF namefile$<>"" THEN REM Read patch names from a patch file. PRINT "Processing "+namefile$+"..." in%=OPENIN(basepath$+namefile$) patch%=0 REPEAT patch$=FNtruncate(GET$#in%) IF patch$<>"" THEN REM Compile the program level and patch change instruction, REM padded to 20 spaces wide. output$ = STRING$(20, " ") LEFT$(output$) = "[p2, " + STR$(patch%) + ", -1, " + STR$(bank%) + "]" REM Work out the patch name, including optional prefix or REM suffix. add$ = RIGHT$(name$, 1) + "000" RIGHT$(add$) = STR$(patch%) IF prefix% = TRUE THEN patch$ = add$ + " " + patch$ IF suffix% = TRUE THEN patch$ = patch$ + " " + add$ REM Add the patch name to the change instruction and REM increment the patch number. Then output the whole line. output$ += patch$ patch% += 1 BPUT#ou%, output$ + CHR$(13) ENDIF UNTIL EOF#in% CLOSE#in%:in%=0 ELSE: REM From 'IF namefile$<>""' REM User defined bank. PRINT "Processing user defined bank..." FOR patch%=0 TO userpatches% - 1 REM Compile the program level and patch change instruction, REM padded to 20 spaces wide. output$ = STRING$(20, " ") LEFT$(output$) = "[p2, " + STR$(patch%) + ", -1, " + STR$(bank%) + "]" REM Work out the patch name, including optional prefix or REM suffix. patch$ = username$ add$ = RIGHT$(name$, 1) + "000" RIGHT$(add$) = STR$(patch%) IF userprefix% = TRUE THEN patch$ = add$ + " " + patch$ IF usersuffix% = TRUE THEN patch$ = patch$ + " " + add$ REM Add the patch name to the change instruction and REM output the line. output$ += patch$ BPUT#ou%, output$ + CHR$(13) NEXT ENDIF: REM From ELSE of 'IF namefile$<>""' ELSE: REM From 'IF bank% >= 0' REM Output a 'mode' specifier if bank% is -2 IF bank% = -2 THEN BPUT#ou%,CHR$(13) BPUT#ou%,"[mode] " + name$ + CHR$(13) ENDIF ENDIF: REM From ELSE of 'IF bank% >= 0' UNTIL bank% = -1 ENDPROC : DEFPROCoutputvstdrums REPEAT READ bank%, key%, namefile$, name$, ext$ REM Define a new bank and output the patches. IF bank% >= 0 THEN REM Is this user defined, or is there a patch file? IF namefile$<>"" THEN REM Read patch names from a patch file. PRINT "Processing "+namefile$+"..." in%=OPENIN(basepath$+namefile$) REM Compile the program level and patch change instruction; REM use the bank name as the patch name and output the line. output$ = "[p2, 0, -1, " + STR$(bank%) + "] " + name$ BPUT#ou%, CHR$(13) BPUT#ou%, output$ + CHR$(13) REM Run through the drum names REPEAT patch$=FNtruncate(GET$#in%) IF patch$<>"" THEN REM Compile the key number and patch name; output the REM line after incrementing the key number. output$ = "[k " + STR$(key%) + "] " + patch$ key% += 1 BPUT#ou%, output$ + CHR$(13) ENDIF UNTIL EOF#in% CLOSE#in%:in%=0 ELSE: REM From 'IF namefile$<>""' REM User defined bank. PRINT "Processing user drum map..." REM Compile the program level and patch change instruction; REM use the bank name as the patch name and output the line. output$ = "[p2 , 0, -1, " + STR$(bank%) + "] " + name$ BPUT#ou%, CHR$(13) BPUT#ou%, output$ + CHR$(13) REM Create the drum map FOR patch%=key% TO key% + drumpatches% - 1 patch$ = username$ add$ = RIGHT$(name$, 1) + "000" RIGHT$(add$) = STR$(patch%) IF userprefix% = TRUE THEN patch$ = add$ + " " + patch$ IF usersuffix% = TRUE THEN patch$ = patch$ + " " + add$ output$ = "[k " + STR$(patch%) + "] " + patch$ BPUT#ou%, output$ + CHR$(13) NEXT ENDIF: REM From ELSE of 'IF namefile$<>""' ELSE: REM From 'IF bank% >= 0' REM Output a 'mode' specifier if bank% is -2 IF bank% = -2 THEN BPUT#ou%,CHR$(13) BPUT#ou%,"[mode] " + name$ + CHR$(13) ENDIF ENDIF: REM From ELSE of 'IF bank% >= 0' UNTIL bank% = -1 ENDPROC : DEFPROCoutputfooter BPUT#ou%,CHR$(13) BPUT#ou%,"[end]"+CHR$(13) ENDPROC : DEFPROCoutputxmldrums REM Output a series of files containing XML definitions REM of Cubase drum maps. Cubase SX does not seem to REM expose the drum maps in patch scripts, despite them REM being documented, instead using a comparatively REM verbose and undocumented XML format. REM REM I've guessed at the contents based on exporting the REM built in GM drum map. REM REM Mode specifiers in the definition data are ignored REM as they don't apply to drum maps, and user-defined REM banks are ignored as there seems little point in REM building default XML files when Cubase can do that REM in only two or three clicks within the GUI. PROCdefinedrumdata REPEAT READ bank%, key%, namefile$, name$, ext$ REM Define a new bank and output the patches. IF bank% >= 0 THEN REM Only do predefined banks. IF namefile$<>"" THEN PRINT "Creating '"+basepath$+script$+ext$+"'..." ou%=OPENOUT(basepath$+script$+ext$) REM Header BPUT#ou%,""+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) REM Output placeholder definitions up to the first key FOR patch%=0 TO key%-1 PROCoutputdrumentry(patch%, "---") NEXT REM Read patch names from a patch file. PRINT "Processing "+namefile$+"..." in%=OPENIN(basepath$+namefile$) REM Run through the drum names patch%=key% REPEAT patch$=FNtruncate(GET$#in%) IF patch$<>"" THEN PROCoutputdrumentry(patch%, patch$) patch% += 1 ENDIF UNTIL EOF#in% CLOSE#in%:in%=0 REM Output placeholder definitions up to the last key endkey% = patch% IF endkey% < 127 THEN FOR patch%=endkey% TO 127 PROCoutputdrumentry(patch%, "---") NEXT ENDIF BPUT#ou%," "+CHR$(13) REM Output the order list BPUT#ou%," "+CHR$(13) FOR patch%=key% TO endkey%-1 BPUT#ou%," "+CHR$(13) NEXT IF key% > 0 THEN FOR patch%=0 TO key%-1 BPUT#ou%," "+CHR$(13) NEXT ENDIF IF endkey% < 127 THEN FOR patch%=endkey% TO 127 BPUT#ou%," "+CHR$(13) NEXT ENDIF BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%,""+CHR$(13) CLOSE#ou%:ou%=0 OSCLI "SetType "+basepath$+script$+ext$+" Text" ENDIF: REM From ELSE of 'IF namefile$<>""' ENDIF: REM From ELSE of 'IF bank% >= 0' UNTIL bank% = -1 ENDPROC : DEFPROCoutputdrumentry(key%, name$) REM Output an XML drum map entry for the given key number REM and name. BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) BPUT#ou%," "+CHR$(13) ENDPROC :