This is a first start. It doesn't do much yet except getting all the ".wrk" files below a given root
directory into Cakewalk and saving them in MidiFormat1. The opening in Finale is already prepared and I was intending to copy information from the File/Info dialog next. The code is uncommented since I wasn't able to select the MDI child window properly. This is a limitation of AutoHotKey and windows. I found some workaround in a forum post of 2006 but it looked to complicated for me to bother. Feel free to comment with a solution here.
Hope this is of some use for some folks out there.
;
; Copyright (C) 2009 Wolfgang Fahl
; For the license details please contact me via
; http://cakewalktofinale.blogspot.com
;
; Script to convert Cakewalk Professional 8 Wrk files to Finale
;
; $Header: /usr/cvsroot/Source/bat/cake2final.ahk,v 1.3 2009/12/07 16:32:36 wf Exp $
; $Id: cake2final.ahk,v 1.3 2009/12/07 16:32:36 wf Exp $
; $Log: cake2final.ahk,v $
; Revision 1.3 2009/12/07 16:32:36 wf
; basic loop - possibly with finale loading and saving
;
; Revision 1.2 2009/12/06 17:49:53 wf
; file open loop works
;
; Revision 1.1 2009/12/06 16:24:24 wf
; initial check in
;
;
;
; run the software at the given relative path
;
runSoftwareWithPath(path,wintitle) {
ifWinExist, %wintitle%
{
WinActivate, %wintitle%
return false
}
IfWinNotExist, %wintitle%
{
;MsgBox would run %path% now,%wintitle%
run %path%
WinWaitActive, %wintitle%
WinGetTitle, wintitle
WinSetTitle, %wintitle% - Script controlled
return true
}
}
;
; run software relative to Program files directory
;
runSoftware(relPath,wintitle) {
path:=A_ProgramFiles . relPath
;".relPath
runSoftwareWithPath(path,wintitle)
}
;
; Move Window to left Half of screen
;
LeftHalf(WinTitle, WinText="",xofs=0,yofs=0)
{
WinWaitActive, %WinTitle%,,2
WinGetPos, X, Y, Width, Height, %WinTitle%
WinMove, %WinTitle%,%WinText%,xofs,yofs,A_ScreenWidth/2-xofs, A_ScreenHeight-yofs
}
;
; Move Window to Right Half of screen
;
RightHalf(WinTitle, WinText="",xofs=0,yofs=0)
{
WinWaitActive, %WinTitle%,,2
WinGetPos, X, Y, Width, Height, %WinTitle%
WinMove, %WinTitle%,%WinText%,A_ScreenWidth/2+xofs,yofs,A_ScreenWidth/2-xofs, A_ScreenHeight-yofs
}
;
; Move the specified Window to topLeft position
;
TopLeft(WinTitle,WinText, Width,Height,xofs=0,yofs=0)
{
;MsgBox %WinTitle%
WinWaitActive, %WinTitle%,,2
WinMove, %WinTitle%,%WinText%, xofs,yofs, Width-xofs, Height-yofs
}
;
; Move the specified Window to bottomRight position
;
BottomRight(WinTitle,WinText, Width,Height,xofs=0,yofs=0)
{
WinWaitActive, %WinTitle%,,2
WinMove, %WinTitle%,%WinText%, (A_ScreenWidth-Width+xofs),(A_ScreenHeight-Height+yofs), Width, Height
}
;
; start Cakewalk Professional
;
runCakewalk() {
runSoftware("\Cakewalk\Cakewalk Professional\cwpr.exe","Cakewalk")
LeftHalf("Cakewalk","",0,A_ScreenHeight/5)
}
;
; start Finale
;
runFinale() {
runSoftware("\Finale PrintMusic 2009\printmusic.exe","Finale")
RightHalf("Finale")
}
;
; run Explorer
;
runExplorer() {
global
; show the result
relFolder:=rootFolder . "\" . Folder
run explorer %relFolder%
WinWaitActive, ahk_Class CabinetWClass,%relFolder%,2
WinGetActiveTitle, winTitle
; move the explorer window
BottomRight(winTitle,"",A_ScreenWidth*39/100,A_ScreenHeight*72/100,0,-25)
return relFolder
}
;
; set the status
;
displayStatus(line) {
GuiControl,,sStatusLine,%line%
}
;
; localize the GUI
;
localizeGUI() {
global
; GERMAN
guiCakeWalk2Finale:="C a k e w a l k - F i n a l e Konverter"
guiTabList:="Konvertieren|Einstellungen|Software|Info"
guiLabelRootFolder:="Hauptordner"
guiButtonNewRootFolder:="Neuer Hauptordner"
guiButtonNewFolder:="Neuer Ordner"
Neuer_Ordner_TT=Neues Ordnerverzeichnis auswählen
guiLabelFolder:="Ordner:"
Ordner_TT=Ordner in dem die erfassten Dokumente abgelegt werden sollen
guiButtonNewDocument:="Neue Musikdatei"
guiLabelDocument:="Datei:"
Neue_Musikdatei_TT=Andere Cakewalk Professional Datei wählen
guiNewRootFolder:="Neuen Hauptordner auswählen"
guiSameRootFolder:="Hauptordner unverändert"
; Software
guiButtonCakewalk:="Cakewalk"
Cakewalk_TT:="Cakewalk Professional 8 starten"
guiButtonFinale:="Finale"
Finale_TT:="Finale PrintMusic 2009 starten"
guiButtonExplorer:="Explorer"
guiNewFolder:="Ordner auswählen"
guiSameFolder:="Ordner unverändert"
guiButtonNext:="Nächste Datei"
guiButtonCancel:="Abbruch"
guiMenuFileCakewalk:="File"
guiMenuFileFinale:="Datei"
guiOpenDialog:="Öffnen"
guiSaveAsDialog:="Speichern unter"
; ENGLISH
guiCakeWalk2Finale:="C a k e w a l k 2 F i n a l e Conversion"
guiTabList:="Convert|Settings|Software|Info"
guiLabelRootFolder:="Root Folder"
guiButtonNewRootFolder:="New Root Folder"
New_Root_Folder_TT="Select a new root folder"
guiButtonNewFolder:="New Folder"
New_Folder_TT="Select a new Folder"
guiLabelFolder:="Folder:"
guiNewRootFolder:="Select new root folder"
guiSameRootFolder:="root folder unchanged"
; Software
guiButtonCakewalk:="Cakewalk"
Cakewalk_TT:="start Cakewalk Professional 8"
guiButtonFinale:="Finale"
Finale_TT:="start Finale PrintMusic 2009"
guiButtonExplorer:="Explorer"
guiNewFolder:="Select a new folder"
guiSameFolder:="Folder unchanged"
guiButtonNext:="Next File"
guiButtonCancel:="Cancel"
;guiOpenDialog:="Open"
;guiSaveAsDialog:="Save As"
guiMenuFileCakewalk:="File"
;guiMenuFileFinale:="File"
}
;
; set a new root folder
;
newRootFolder() {
global
FileSelectFolder, newRootFolder,*%rootFolder% , 3, %guiNewRootFolder%
if newRootFolder =
MsgBox %guiSameRootFolder% : %rootFolder%
else
rootFolder:=newRootFolder
guiUpdate()
}
;
; set a new folder
;
newFolder() {
global
FileSelectFolder, newFolder,%rootFolder% , 3, %guiNewFolder%
if newFolder =
MsgBox %guiSameFolder% : %folder%
else
{
; strip the rootFolder part
stripLen:=StrLen(newFolder) - StrLen(rootFolder) - 1
StringRight, newFolder,newFolder,stripLen
Folder:=newFolder
docX:=""
docY:=""
document:=""
guiUpdate()
getFiles()
}
guiUpdate()
}
;
; get the files
;
getFiles() {
global
docY:=0
docX:=0
path:=rootFolder "\" . Folder . "\*.wrk"
FileList := ""
Loop, %path%, , 1 ; Recurse into subfolders.
{
FileList = %FileList%%A_LoopFileFullPath%`n
docY:=docy+1
}
guiUpdate()
}
;
; next File
;
nextFile() {
global
if (docX < docY)
docX:=docX+1
else
return
guiUpdate()
Loop, parse, FileList, `n
{
if A_LoopField = ; Ignore the blank item at the end of the list.
continue
if ( A_Index = docX )
{
document:=A_LoopField
;MsgBox %A_LoopField% - %A_Index% - %docX%
break
}
}
guiUpdate()
cakeOpen(document,guiOpenDialog,guiMenuFileCakewalk)
;infoGet()
finaleConvert(document,guiSaveAsDialog,guiMenuFileCakewalk)
;finaleOpen(document,guiOpenDialog,guiMenuFileFinale)
;infoSet()
}
;
; Get File/Info information
;
infoGet() {
global
sleep 300
WinMenuSelectItem,Cakewalk,,File,Info
sleep 300
lTitle:=""
lSubTitle:=""
lInstructions:=""
lAuthor:=""
lCopyright:=""
lKeywords:=""
loop, 30 {
sleep 100
ControlGetText,lTitle,Edit1,File Info
ControlGetText,lSubTitle,Edit2,File Info
ControlGetText,lInstructions,Edit3,File Info
ControlGetText,lAuthor,Edit4,File Info
ControlGetText,lCopyright,Edit5,File Info
ControlGetText,lKeywords,Edit6,File Info
lInfo:=lTitle . lSubTitle . lInstructions . lAuthor . lCopyright . lKeywords
if ( lInfo <>"") {
MsgBox %lInfo%
SendInput {Ctrl}{F4}
return
}
}
MsgBox failed to get info
}
;
; Set File/Info information
;
infoSet() {
global
WinMenuSelectItem, Finale, ,%guiMenuFileFinale%, info
}
;
; open in finale
;
finaleOpen(document,guiOpenDialog,guiMenuFile) {
runFinale()
StringReplace, midiDocument,document,.wrk,.mid
;MsgBox %midiDocument%
WinMenuSelectItem, Finale, ,%guiMenuFile%, %guiOpenDialog%
openFile(midiDocument,guiOpenDialog)
}
;
; save finale
;
finaleSave(document,guiSaveDialog) {
}
;
; convert
;
finaleConvert(document,guiSaveAsDialog,guiMenuFileCakewalk) {
; This will select File->Open in Cakewalk:
WinMenuSelectItem, Cakewalk, , %guiMenuFileCakewalk%, Save As
sleep 200
winActivate, %guiSaveAsDialog%
winWaitActive, %guiSaveAsDialog%
; check the filename
loop, 30 {
sleep 10
ControlGetText,lText,Edit1,%guiSaveAsDialog%
; check that the right part of the document is what is in the dialog right now (file part)
StringRight lFile,document,StrLen(lText)
if (lText=lText) {
SetcontrolDelay -1
; Control, chooseString,MIDI Format 1, ComboBox2, %guiSaveAsDialog%
Control, choose, 6, ComboBox2, %guiSaveAsDialog%
break
}
}
loop, 30 {
sleep 10
ControlGetText,lText,Edit1,%guiSaveAsDialog%
StringRight,lExt,lText,4
if (lext=".mid") {
ControlClick, Button2,%guiSaveDialog%,,,,NA
; wait for open for up to 10 secs
WinWaitClose, %guiOpenDialog%, ,10
return
}
}
; i18n
MsgBox %guiSaveAsDialog% %document% failed
}
;
; open the given file
;
openFile(document,guiOpenDialog) {
sleep 200
winActivate, %guiOpenDialog%
winWaitActive, %guiOpenDialog%
loop, 10 {
sleep 10
ControlFocus, Edit1, %guiOpenDialog%
ControlGetFocus,lCtlName,%guiOpenDialog%
;msgbox %guiOpenDialog% ? %winTitle% - %lCtlName%
if (lCtlName="Edit1") {
; ControlSetText, Edit,%document%,%guiOpenDialog%
send %document%
break
}
}
loop, 30 {
sleep 10
ControlGetText,lText,Edit1,%guiOpenDialog%
if (lText=document) {
SetcontrolDelay -1
ControlClick, Button2,%guiOpenDialog%,,,,NA
; wait for open for up to 10 secs
WinWaitClose, %guiOpenDialog%, ,10
return
}
}
; i18n
MsgBox %guiOpenDialog% %document% failed
}
;
; open the given document in cakewalk
;
cakeOpen(document,guiOpenDialog,guiMenuFileCakewalk){
;msgBox %document% - %guiOpenDialog%
; This will select File->Open in Cakewalk:
WinMenuSelectItem, Cakewalk, , %guiMenuFileCakewalk%, Open
openFile(document,guiOpenDialog)
}
;
; set a new Document
;
newDocument() {
global
; get current state
guiSubmit()
; put page in gui
guiUpdate()
; get back new file name ...
guiSubmit()
}
;
; Tool tip support
;
WM_MOUSEMOVE()
{
static CurrControl, PrevControl, _TT ; _TT is kept blank for use by the ToolTip command below.
lCurrControl := A_GuiControl
; Replace all spaces and colons with underscore:
StringReplace, CurrControl, lCurrControl, %A_SPACE%, _, All
StringReplace, CurrControl, CurrControl, :, _, All
StringReplace, CurrControl, CurrControl, /, _, All
StringReplace, CurrControl, CurrControl, ., _, All
If (CurrControl <> PrevControl)
{
ToolTip ; Turn off any previous tooltip.
SetTimer, DisplayToolTip, 1000
PrevControl := CurrControl
}
return
DisplayToolTip:
SetTimer, DisplayToolTip, Off
ToolTip % %CurrControl%_TT ; The leading percent sign tell it to use an expression.
SetTimer, RemoveToolTip, 3000
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
}
;
; get the settings File
;
getSettingsFile() {
settingsDir:=A_AppData . "\Cake2Finale\"
IfNotExist, %settingsDir%
{
FileCreateDir, %settingsDir%
}
settingsFile:=settingsDir . "cake2finale.ini"
IfNotExist, %settingsFile%
{
initSettings(settingsFile)
}
return settingsFile
}
;
; initialize the global settings
;
initSettings(settingsFile)
{
global
rootFolder:=A_WorkingDir
Folder=Music
Document=Sample.wrk
writeSettings(settingsFile)
}
;
; get the global settings
;
readSettings()
{
global
settingsFile:=getSettingsFile()
IniRead, rootFolder ,%settingsFile%, rootFolder1, rootFolder
IniRead, Folder ,%settingsFile%, rootFolder1, Folder
IniRead, Document ,%settingsFile%, rootFolder1, Document
IniRead, DocX ,%settingsFile%, rootFolder1, DocX
IniRead, Docy ,%settingsFile%, rootFolder1, DocY
}
;
; write the global settings
;
writeSettings(settingsFile)
{
global
;msgBox %rootFolder%-%settingsFile%
IniWrite, %rootFolder% ,%settingsFile%, rootFolder1, rootFolder
IniWrite, %Folder% ,%settingsFile%, rootFolder1, Folder
IniWrite, %Document% ,%settingsFile%, rootFolder1, Document
IniWrite, %DocX% ,%settingsFile%, rootFolder1, DocX
IniWrite, %DocY% ,%settingsFile%, rootFolder1, DocY
}
;
; finish the application
;
finish() {
guiSubmit()
ExitApp
}
;
; go to webpage
;
launchWeb() {
run http://cakewalktofinale.blogspot.com/
}
;
; submit the GUI content to the variables
; write to settings so that the result is available later
;
guiSubmit() {
global
; the actual gui submission
Gui, Submit, NoHide
; recalculate (if any)
; put the recalculated results back into the gui and
; save to settings file
guiUpdate()
}
;
; put the variable contents back into the gui
;
guiUpdate() {
global
GuiControl,, rootFolder,%rootFolder%
GuiControl,, Folder ,%Folder%
GuiControl,, Document ,%Document%
GuiControl,, DocX ,%DocX%
GuiControl,, DocY ,%DocY%
writeSettings(settingsFile)
;writeSettings(settingsFile)
}
;
; show the GUI
;
showGui() {
global
localizeGUI()
buttonColor:=clBlue
Gui, Add, Tab2,w500 h200, %guiTabList%
; Conversion
Gui, Tab, 1
; Folder
Gui, Add, Button ,x20 y30 w%lWidth% h35 gNewFolder , %guiButtonNewFolder%
Gui, Add, Text ,x100 y35 +right , %guiLabelFolder%
Gui, Add, Edit ,x160 y35 w300 vFolder ,%Folder%
; File
;Gui, Add, Button ,x20 y65 w%lWidth% h35 gNewDocument, %guiButtonNewDocument%
Gui, Add, Text ,x100 y70 +right , %guiLabelDocument%
Gui, Add, Edit ,x160 y70 w300 vDocument,%Document%
Gui, Add, Button , x20 y105 w60 h35 gnextFile , %guiButtonNext%
Gui, Add, Edit , x100 y105 w60 vDocX,%DocX%
Gui, add, Text , X170 y105 , /
Gui, Add, Edit , x190 y105 w60 vDocY,%DocY%
;Gui, Add, Button ,x20 y70 w60 h35 gdodelete , %dodelete%
Gui, Add, Button , x20 y145 w60 h35 glCancel, %guiButtonCancel%
; Status line is outside tabs
Gui, Tab
Gui, Add, Text ,x20 y210 w440 vsStatusLine
; Settings
Gui, Tab, 2
Gui, Add, Text , section ,%guiLabelRootFolder%
Gui, Add, Edit , w300 ys vRootFolder,%rootFolder% ; the root folder
Gui, Add, Button , ys gNewRootFolder, %guiButtonNewRootFolder%
; Software
Gui, Tab, 3
; Cakewalk
Gui, Add, Button , gCakewalk, %guiButtonCakewalk%
; Finale
Gui, Add, Button , gFinale, %guiButtonFinale%
; Explorer
Gui, Add, Button , gExplorer, %guiButtonExplorer%
; Info
Gui, Tab, 4
Gui, Add, Text,, Copyright 2009 Wolfgang Fahl
Gui, Font, underline
Gui, Add, Text,cBlue gLaunchWeb, http://cakewalktofinale.blogspot.com
Gui, Font, norm
; NoActivate avoids deactivating the currently active window
Gui, Show, NoActivate, %guiCakewalk2Finale%
; activate tool tips
OnMessage(0x200, "WM_MOUSEMOVE")
return
; start Explorer in folder directory
Explorer:
guiSubmit()
runExplorer()
return
;
Finale:
guiSubmit()
runFinale()
return
; start Cakewalk Software
Cakewalk:
guiSubmit()
runCakewalk()
return
; select a new root folder
newRootFolder:
guiSubmit()
newRootFolder()
return
; select a new folder
newFolder:
guiSubmit()
newFolder()
return
; move to the next file
nextFile:
nextFile()
return
; link to Cakewalk to Finale web page
launchWeb:
launchWeb()
return
lcancel:
guiSubmit()
docancel:=true
return
GuiClose:
finish()
}
; force a single instance
#SingleInstance force
; make sure we find hidden titles e.g. for explorer
setTitleMatchMode slow
; partial window title
SetTitleMatchMode, 2
; use fast sendmode Input (make configurable ...)
;sendMode Input
;sendMode Event
SendMode InputThenPlay
; small delay
;setKeyDelay, 20
;setControlDelay -1
;read the setting from an ini file
readSettings()
; show the gui
showGui()
topLeft(guiCakewalk2Finale,"",A_ScreenWidth/2,A_ScreenWidth/5)
; start Cakewalk (if not running yet)
runCakewalk()
; start Finale (if not running yet)
runFinale()
; get the current files
getFiles()
Montag, 7. Dezember 2009
Abonnieren
Kommentare zum Post (Atom)
Keine Kommentare:
Kommentar veröffentlichen