Site Tools


software:musicpdf:dev

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
software:musicpdf:dev [2009/10/15 06:50] adminsoftware:musicpdf:dev [2009/10/27 01:24] (current) admin
Line 6: Line 6:
 Please install [[http://www.autoitscript.com/autoit3/|autoit3]] to develop, test and work with the script below. Please install [[http://www.autoitscript.com/autoit3/|autoit3]] to develop, test and work with the script below.
 <code> <code>
 +; MusicPDF, Automatic cleaning and leveling pdf files with Neuratron
 +; Copyright (C) Oktober 2009 by Marc Nijdam
 +;
 +;    This program is free software: you can redistribute it and/or modify
 +;    it under the terms of the GNU General Public License as published by
 +;    the Free Software Foundation, either version 3 of the License, or
 +;    any later version.
 +;
 +;    This program is distributed in the hope that it will be useful,
 +;    but WITHOUT ANY WARRANTY; without even the implied warranty of
 +;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +;    GNU General Public License for more details.
 +;
 +;    You should have received a copy of the GNU General Public License
 +;    along with this program.  If not, see <http://www.gnu.org/licenses/>
 +;
 +;    Contact details: http://www.nijdam.de/marc.html
 +
 +#requireadmin ; This program should have proper rights to start external applications. Presumably this behaviour requires user admin rights
 +
 #include <Constants.au3> ; Used for registry constants like REG_SZ, REG_DWORD etc. #include <Constants.au3> ; Used for registry constants like REG_SZ, REG_DWORD etc.
 #include <Process.au3> #include <Process.au3>
Line 14: Line 34:
 #Include <String.au3> #Include <String.au3>
  
-#requireadmin I guess so. +Current version of MusicPDF is compatible with PhotoScore version Neuratron PhotoScore Ultimate 6
-; Automate Neuratron Photoscore, written by Marc Nijdam, Oktober 2009 +
- +
-; $CmdLine[0] = number of parameters +
-; $CmdLine[1] = first parameter +
- +
-; Compatible with PhotoScore version Neuratron PhotoScore Ultimate 6 +
-; The slider for Pending Pages should be beginning just under the middle of the configuration settings wheel.+
 ; ;
-; Requires Imagemagick installation from http://www.imagemagick.org (dynamic, 16 bit images)+; Requires Imagemagick installation from http://www.imagemagick.org (See over there. Choose the dynamic, 16 bit images version)
 ; Path environment variable should be pointing to imagemagick, (default installation will add this to the %PATH% environment variable, which is persistant) ; Path environment variable should be pointing to imagemagick, (default installation will add this to the %PATH% environment variable, which is persistant)
-; If not it the following should be added: %PROGRAMFILES%\imagemagick+; If not there, this script adds the following temporarily: %PROGRAMFILES%\imagemagick
 ; ;
-Requires Ghostview, which may be installed through Photoscore.+This program requires Ghostscript, which may be installed through Photoscore.
 ; Path environment variable should be pointing to: %PROGRAMFILES%\gs\gs8.56\bin;%PROGRAMFILES%\gs\gs8.56\lib ; Path environment variable should be pointing to: %PROGRAMFILES%\gs\gs8.56\bin;%PROGRAMFILES%\gs\gs8.56\lib
 ; ;
-Does this solve a R6034 error http://www.microsoft.com/downloads/details.aspx?familyid=A5C84275-3B97-4AB7-A40D-3802B2AF5FC2+This solve a R6034 (AutoIt3 related) error
 +http://www.microsoft.com/downloads/details.aspx?familyid=A5C84275-3B97-4AB7-A40D-3802B2AF5FC2
 ; ;
-; Write an environment variable +; Nb.: 
-EnvSet ( "envvariable" [, "value"] ) +; Write an environment variableEnvSet ( "envvariable" [, "value"] )
-; Code snippet:+
 ; ControlClick($parentWindowName,"ViewPages", ,2, 12, 81) ; ControlClick($parentWindowName,"ViewPages", ,2, 12, 81)
-Debug optie: ConsoleWrite("vertical: " & $y1) +; $CmdLine[0] = number of parameters 
-ConsoleWrite("Debug information"+; $CmdLine[1] first parameter 
-; Set program run environment. During code development it is easier if this program takes set input output files +
-Const $envDebug False ; True means the program skips command line parameter parsing and default to set input/output files+
 Const $NeuratronVersion = "6.0.0"; For which version is this program written and compatibl with? Const $NeuratronVersion = "6.0.0"; For which version is this program written and compatibl with?
 Const $Version6 = "6.0.0" ; This is Version 6, released in 2009 Const $Version6 = "6.0.0" ; This is Version 6, released in 2009
-Const $ThisProgramVersion = "0.9.0" ; Current release of this software+Const $ThisProgramVersion = "0.9.3" ; Current release of this software
 Const $_ERROR_MissingImageMagickObject = -1 Const $_ERROR_MissingImageMagickObject = -1
 Const $_ERROR_PdfInputFileIsNotValid = -2 Const $_ERROR_PdfInputFileIsNotValid = -2
Line 56: Line 68:
 Const $_ERROR_MSVisualCPlusPlus2008RedistNotInstalled = -12 Const $_ERROR_MSVisualCPlusPlus2008RedistNotInstalled = -12
  
-Const $Gui_Width = 300+Const $Gui_Title = "PDF Sheetmusic raw scan Processor" 
 +Const $Gui_Xpos = 140 
 +Const $Gui_Ypos = 23 
 +Const $Gui_Width = 518
 Const $Gui_Height = 200 Const $Gui_Height = 200
 Const $Gui_Border = 15 Const $Gui_Border = 15
Line 64: Line 79:
  
 Const $img_uniquename = "Neuratron6AU3_" ; Unique leading part of filename for temporary files Const $img_uniquename = "Neuratron6AU3_" ; Unique leading part of filename for temporary files
-Const $img_width = 2480 ; constant in pixels, defining what the page width may be at most +Const $img_width = 2480 ; constant in pixels, defining what the page width may be at most when portrait modus is used 
-Const $img_height = 3508 ; constant in pixels, defining what the page height may be at most+Const $img_height = 3508 ; constant in pixels, defining what the page height may be at most when portrait modus is used 
 +Const $resolution = 300 ; Resolution in dpi 
 +Const $img_dims[2] = [$img_width,$img_height] ; landscape modus swaps both variables 
 +Const $rastering = 72 ; PDF rastering value 
 +Const $pdf_dims[2] = [String(Int(($rastering*$img_width/$resolution)+0.5)),String(Int(($rastering*$img_height/$resolution)+0.5))] ; Array holding pdf rastering sizes a4 should be 595x842 
 +Dim   $max_dims[2] ; Array holding the largest found dimension (horizontal,vertical) 
 +Dim   $this_dims[2] ; Array holding the actual dimension (horizontal,vertical) 
 Const $img_empty_name = AddSlash(@TempDir) & $img_uniquename & "_temp.tif" Const $img_empty_name = AddSlash(@TempDir) & $img_uniquename & "_temp.tif"
 Const $Pdf_tmp_FileName = AddSlash(@TempDir) & $img_uniquename & "Processed.pdf" ; temporary filename which is used when something had been preprocessed. Const $Pdf_tmp_FileName = AddSlash(@TempDir) & $img_uniquename & "Processed.pdf" ; temporary filename which is used when something had been preprocessed.
-Const $QQ='"'+Const $QQ = '"' 
 +Const $SQ = "'" 
 +Dim $szDrive, $szDir, $szFName, $szExt 
 +Dim $i , $j
  
 Const $X_firstItem_Sel = 1 ; neuratron buttons window positions Const $X_firstItem_Sel = 1 ; neuratron buttons window positions
 Const $X_firstItem_Del = 2 ; neuratron buttons window positions Const $X_firstItem_Del = 2 ; neuratron buttons window positions
 Const $Y_firstItem = 3 ; neuratron buttons window positions Const $Y_firstItem = 3 ; neuratron buttons window positions
-Const $NeuratronDelay = ; loop is breaked when it runs for more than seconds+Const $NeuratronDelay = 10 ; loop is breaked when it runs for more than 10 seconds
  
 Const $Pdf_ListOfFiles2Proces = AddSlash(@TempDir) & $img_uniquename & "list.txt" ; Maintaing a list with all pdf pages for concatenating. Const $Pdf_ListOfFiles2Proces = AddSlash(@TempDir) & $img_uniquename & "list.txt" ; Maintaing a list with all pdf pages for concatenating.
Line 105: Line 130:
  
 ; Parse program start options ; Parse program start options
-If $envDebug Then ; $envDebug == True means Program runs in Debug mode+If @Compiled == 0 Then ; $envDebug == True means Program runs in Debug mode
 ; Dim $Pdf_InputFile = "Neuratron_Global_Settings.reg" ; Not a pdf file ; Dim $Pdf_InputFile = "Neuratron_Global_Settings.reg" ; Not a pdf file
 ; Dim $Pdf_InputFile = "test_empty.pdf" ; inputfile ; Dim $Pdf_InputFile = "test_empty.pdf" ; inputfile
Line 118: Line 143:
 ; Dim $Pdf_InputFile = "test_bwpages_tilted.pdf" ; inputfile ; Dim $Pdf_InputFile = "test_bwpages_tilted.pdf" ; inputfile
 ; Dim $Pdf_InputFile = "test_color.pdf" ; Dim $Pdf_InputFile = "test_color.pdf"
- Dim $Pdf_InputFile = "test_largeBW.pdf"+; Dim $Pdf_InputFile = "test_largeBW.pdf" 
 +; Dim $Pdf_InputFile = "test_2_pages_landscape.pdf" ; inputfile 
 + Dim $Pdf_InputFile = "test_2_pages_landscape_oversized.pdf" ; inputfile
  Dim $Pdf_OutputFile = "test_Processed.pdf" ; outputfile  Dim $Pdf_OutputFile = "test_Processed.pdf" ; outputfile
  $Pdf_InputFile = AddSlash(@WorkingDir) & $Pdf_InputFile ; Add absolute path to filename.  $Pdf_InputFile = AddSlash(@WorkingDir) & $Pdf_InputFile ; Add absolute path to filename.
Line 130: Line 157:
  Case 1  Case 1
  Dim $Pdf_InputFile = $CmdLine[1] ; inputfile  Dim $Pdf_InputFile = $CmdLine[1] ; inputfile
- local $szDrive, $szDir, $szFName, $szExt 
  _PathSplit($Pdf_InputFile, $szDrive, $szDir, $szFName, $szExt)  _PathSplit($Pdf_InputFile, $szDrive, $szDir, $szFName, $szExt)
  Dim $Pdf_OutputFile = '"' & $szDrive & $szDir & $szFName & "_Processed" & $szExt & '"'; outputfile  Dim $Pdf_OutputFile = '"' & $szDrive & $szDir & $szFName & "_Processed" & $szExt & '"'; outputfile
Line 144: Line 170:
 Opt("GUIOnEventMode", 1); GUI should be in OnEvent Mode, otherwise our cancelbutton event is not captured Opt("GUIOnEventMode", 1); GUI should be in OnEvent Mode, otherwise our cancelbutton event is not captured
 HotKeySet("{Esc}", "CancelButton"); Pressing the Escape button cancels operation HotKeySet("{Esc}", "CancelButton"); Pressing the Escape button cancels operation
-GUICreate("PDF Sheetmusic raw scan Processor",$Gui_Width,$Gui_Height,0,0)  ; will create a dialog box that when displayed is centered+GUICreate($Gui_Title,$Gui_Width,$Gui_Height,$Gui_Xpos,$Gui_Ypos)  ; will create a dialog box that when displayed is centered
 $nEdit = GUICtrlCreateEdit ("",$Gui_Border,$Gui_Border,$Gui_Width-$Gui_Border-$Gui_WidthSlider,$Gui_Height-$Gui_Border-2*$Gui_HeightButton, BitOr($ES_AUTOVSCROLL,$ES_READONLY,$ES_MULTILINE)) $nEdit = GUICtrlCreateEdit ("",$Gui_Border,$Gui_Border,$Gui_Width-$Gui_Border-$Gui_WidthSlider,$Gui_Height-$Gui_Border-2*$Gui_HeightButton, BitOr($ES_AUTOVSCROLL,$ES_READONLY,$ES_MULTILINE))
 GUICtrlSetBkColor($nEdit, 0xffffff) GUICtrlSetBkColor($nEdit, 0xffffff)
Line 160: Line 186:
 _RunDos("pdf2dsc " & $Param_Command) _RunDos("pdf2dsc " & $Param_Command)
 $Param_Command = OpenFileAndGrep(AddSlash(@TempDir) & $img_uniquename & "info.dsc", "%%Pages:") $Param_Command = OpenFileAndGrep(AddSlash(@TempDir) & $img_uniquename & "info.dsc", "%%Pages:")
- 
 If Not $Param_Command Then ; The supplied file is not an pdf file, exit program If Not $Param_Command Then ; The supplied file is not an pdf file, exit program
  ShowError ($_ERROR_PdfInputFileIsNotValid)  ShowError ($_ERROR_PdfInputFileIsNotValid)
Line 169: Line 194:
 Const $PdfPagesCount = Number(StringReplace($Param_Command, "%%Pages: ", "")) Const $PdfPagesCount = Number(StringReplace($Param_Command, "%%Pages: ", ""))
 GUICtrlSetData($nEdit, "->Found " & Number($PdfPagesCount) & " Page(s)" & @CRLF, 1) GUICtrlSetData($nEdit, "->Found " & Number($PdfPagesCount) & " Page(s)" & @CRLF, 1)
- 
 ; ############################################################################################################## ; ##############################################################################################################
 ; # Preprocessing scanned pages ; # Preprocessing scanned pages
Line 185: Line 209:
 ; # Empty pages, holding no data, give no output from the Identify command ; # Empty pages, holding no data, give no output from the Identify command
 ; ############################################################################################################## ; ##############################################################################################################
- 
 Dim $PagesStats Dim $PagesStats
 GUICtrlSetData($nEdit, @CRLF & "Extracting single pages from PDF document..." & @CRLF, 1) GUICtrlSetData($nEdit, @CRLF & "Extracting single pages from PDF document..." & @CRLF, 1)
  
-Dim $width_largest = $img_width +$max_dims[0] = $img_dims[0] 
-Dim $height_largest = $img_height+$max_dims[1] = $img_dims[1]
 Dim $img_dimensions Dim $img_dimensions
 Dim $img_scale = False ; False means scaling is not necessary, because image fits within $img_width and $img_height Dim $img_scale = False ; False means scaling is not necessary, because image fits within $img_width and $img_height
 Dim $img_greyconverted = False ; False means image has not been converted from black and white to grey scale Dim $img_greyconverted = False ; False means image has not been converted from black and white to grey scale
 +Dim $PaperOrientation[$PdfPagesCount] ; Store page orientation for each page, 0 means portrait, 1 means landscape
 ; Extract all pages from document to single pdf pages ; Extract all pages from document to single pdf pages
 for $i = 1 To $PdfPagesCount for $i = 1 To $PdfPagesCount
Line 202: Line 225:
  
  ; From pdf file extract a single pdf page (as pdf)  ; From pdf file extract a single pdf page (as pdf)
- $Param_Command = $QQ & "-sDEVICE=pdfwrite" & $QQ & _ ; Ghostview command to extract a single page from a pdf file + $Param_Command = $QQ & "-sDEVICE=pdfwrite" & $QQ & " " & _ ; Ghostview command to extract a single page from a pdf file. 
- " -dNOPAUSE -dQUIET -dBATCH " & _+ $QQ & "-dNOPAUSE" & $QQ & " " & _ 
 + $QQ & "-dQUIET" & $QQ & " " & _ 
 + $QQ & "-dBATCH" & $QQ & " " & _ 
 + $QQ & "-dAutoFilterGrayImages=false" & $QQ & " " & _ 
 + $QQ & "-dGrayImageFilter=/LZWEncode" & $QQ & " " & _ ; To prevent jpeg artifects add -dAutoFilterGrayImages=false -dGrayImageFilter=/LZWEncode
  $QQ & "-dFirstPage=" & Number($i) & $QQ & " " & _  $QQ & "-dFirstPage=" & Number($i) & $QQ & " " & _
  $QQ & "-dLastPage=" & Number($i) & $QQ & " " & _  $QQ & "-dLastPage=" & Number($i) & $QQ & " " & _
  $QQ & "-sOutputFile=" & $ThisFileName & $QQ & " " & _  $QQ & "-sOutputFile=" & $ThisFileName & $QQ & " " & _
  $QQ & $Pdf_InputFile & $QQ  $QQ & $Pdf_InputFile & $QQ
- 
  _RunDos("gswin32c " & $Param_Command)  _RunDos("gswin32c " & $Param_Command)
  
Line 216: Line 242:
  If StringInStr($PagesStats, "Bilevel") Then ; If a page is only black and white color, convert it to grey with some gaussian blurring  If StringInStr($PagesStats, "Bilevel") Then ; If a page is only black and white color, convert it to grey with some gaussian blurring
  GUICtrlSetData($nEdit, "-->Converting page " & Number($i) & " out of " & Number($PdfPagesCount) & " to grey" & @CRLF, 1)  GUICtrlSetData($nEdit, "-->Converting page " & Number($i) & " out of " & Number($PdfPagesCount) & " to grey" & @CRLF, 1)
- $oIMG.Convert("-density","300", $ThisFileName, "-depth", "8", $ThatFileName)+ $oIMG.Convert("-density",String($resolution), $ThisFileName, "-depth", "8", "-compress", "LZW", $ThatFileName)
  $oIMG.Mogrify("-gaussian-blur","1x0.5", $ThatFileName) ; Perform gaussian blur to improve ability to rotate, value found experimentally  $oIMG.Mogrify("-gaussian-blur","1x0.5", $ThatFileName) ; Perform gaussian blur to improve ability to rotate, value found experimentally
  $img_greyconverted = True  $img_greyconverted = True
  Else  Else
- $oIMG.Convert("-density","300", $ThisFileName, $ThatFileName)+ $oIMG.Convert("-density",String($resolution), $ThisFileName, $ThatFileName)
  EndIf  EndIf
  FileDelete($ThisFileName); Delete pdf file, because we don't need it anymore.  FileDelete($ThisFileName); Delete pdf file, because we don't need it anymore.
Line 228: Line 254:
  
  $img_dimensions = DOSResult("Identify " & $Param_Command)  $img_dimensions = DOSResult("Identify " & $Param_Command)
 + $this_dims[0] = Number(StringRegExpReplace($img_dimensions, "([0-9]+)x([0-9]+)", "$1")) ; From string holding dimensions (for example "1800x1600") extract first number
 + $this_dims[1] = Number(StringRegExpReplace($img_dimensions, "([0-9]+)x([0-9]+)", "$2")) ; From string holding dimensions (for example "1800x1600") extract second number
  
- If Number(StringRegExpReplace($img_dimensions, "([0-9]+)x([0-9]+)", "$1")) > $width_largest Then ; From string holding dimensions (for example "1800x1600") extract first number + If $this_dims[0] <= $this_dims[1] Then ; Normal portrait modus.  
- $width_largest = Number(StringRegExpReplace($img_dimensions, "([0-9]+)x([0-9]+)", "$1")) + $PaperOrientation[$i-10 
- $img_scale = True ; Image doesn't fit; scaling will be necessary + Else 
- EndIf + GUICtrlSetData($nEdit, "-->(Page Number($i) & has paper orientation set to landscape)" & @CRLF1
- + $PaperOrientation[$i-1] 1
- If Number(StringRegExpReplace($img_dimensions, "([0-9]+)x([0-9]+)", "$2")) $height_largest Then ; From string holding dimensions (for example "1800x1600") extract second number +
- $height_largest = Number(StringRegExpReplace($img_dimensions, "([0-9]+)x([0-9]+)", "$2")+
- $img_scale True ; Image doesn't fit; scaling will be necessary+
  EndIf  EndIf
 + ; $this_dims[$PaperOrientation[$i-1]] is always the short side
 + ; $this_dims[1-$PaperOrientation[$i-1]] is always the long side
 + ; $max_dims[0] carries always the maximum of the shorter side
 + ; $max_dims[1] carries always the maximum of the longer side
 + ; $j = 0 -> find the widest page for the short side 
 + ; $j = 1 -> find the longest page for the long side
 + ; The BitXOR function will output only a logical 1 of two arguments are different.
 + For $j = 0 To 1
 + If $this_dims[BitXOR($j,$PaperOrientation[$i-1])] > $max_dims[$j] Then ; From string holding dimensions (for example "1800x1600") extract first number
 + $max_dims[$j] = $this_dims[BitXOR($j,$PaperOrientation[$i-1])]
 + $img_scale = True ; Image doesn't fit; scaling will be necessary
 + EndIf
 + Next
  
 Next Next
 +
  ; # If there were one or more images exceeding size limit, scale them all with the same percentage.  ; # If there were one or more images exceeding size limit, scale them all with the same percentage.
 If $img_scale Then If $img_scale Then
- Dim $resize_scale + Dim $resize_scale = Calc_scalingfactor($max_dims[0],$max_dims[1],$img_dims[0],$img_dims[1]); calculate scaling percentage portrait: [0],[1] Landscape: [1],[0] 
- $resize_scale = Calc_scalingfactor($width_largest,$height_largest,$img_width,$img_height); calculate scaling percentage + If $resize_scale < 50 Then
- If $resize_scale < 25 Then ; Resizing to less than 50 % is kind of silly.+
  ; Remove previous orphans  ; Remove previous orphans
  For $i = 1 To $PdfPagesCount ; Delete all files we don't need anymore  For $i = 1 To $PdfPagesCount ; Delete all files we don't need anymore
  If FileExists(AddSlash(@TempDir) & $img_uniquename & Number($i) & ".tif") Then FileDelete(AddSlash(@TempDir) & $img_uniquename & Number($i) & ".tif")  If FileExists(AddSlash(@TempDir) & $img_uniquename & Number($i) & ".tif") Then FileDelete(AddSlash(@TempDir) & $img_uniquename & Number($i) & ".tif")
  Next  Next
- ShowError ($_ERROR_PdfImageSizeTooLarge)+ ShowError($_ERROR_PdfImageSizeTooLarge) ; Resizing to less than 50 % is kind of silly.
  EndIf  EndIf
- 
  GUICtrlSetData($nEdit, @CRLF & "Some pages exceed maximum size." & @CRLF & "Reducing page size to " & $resize_scale & "% ..." & @CRLF, 1)  GUICtrlSetData($nEdit, @CRLF & "Some pages exceed maximum size." & @CRLF & "Reducing page size to " & $resize_scale & "% ..." & @CRLF, 1)
- + For $i = 1 To $PdfPagesCount ; Delete all files we don't need anymore
- ; Resize all tiff images. +
- for $i = 1 To $PdfPagesCount+
  GUICtrlSetData($nEdit, "->Resizing page " & Number($i) & " out of " & Number($PdfPagesCount) & @CRLF, 1)  GUICtrlSetData($nEdit, "->Resizing page " & Number($i) & " out of " & Number($PdfPagesCount) & @CRLF, 1)
  $oIMG.Mogrify("-resize", $resize_scale & "%", AddSlash(@TempDir) & $img_uniquename & Number($i) & ".tif") ; ImageMagick command to find page dimensions  $oIMG.Mogrify("-resize", $resize_scale & "%", AddSlash(@TempDir) & $img_uniquename & Number($i) & ".tif") ; ImageMagick command to find page dimensions
  Next  Next
 EndIf EndIf
- 
-; # If one of the previous operations changed the image, it's necessary to merge these images into a pdf file. 
  
 If $img_greyconverted or $img_scale Then If $img_greyconverted or $img_scale Then
Line 270: Line 303:
  $FHandle = FileOpen($Pdf_ListOfFiles2Proces,1) ; $Pdf_ListOfFiles2Proces is a text file containg file names. (1 = Write mode append to the end of file)  $FHandle = FileOpen($Pdf_ListOfFiles2Proces,1) ; $Pdf_ListOfFiles2Proces is a text file containg file names. (1 = Write mode append to the end of file)
  
- $oIMG.Convert("","-size", String($img_width) & "x" & String($img_height), "xc:white", "-depth", "16", $img_empty_name) ; create one empty page with a4 size 
  for $i = 1 To $PdfPagesCount  for $i = 1 To $PdfPagesCount
 + $oIMG.Convert("","-size", String($img_dims[$PaperOrientation[$i-1]]) & "x" & String($img_dims[1-$PaperOrientation[$i-1]]), "xc:white", "-depth", "16", $img_empty_name) ; create one empty page with a4 size
  GUICtrlSetData($nEdit, "->Converting page " & Number($i) & " out of " & Number($PdfPagesCount) & " to pdf" & @CRLF, 1)  GUICtrlSetData($nEdit, "->Converting page " & Number($i) & " out of " & Number($PdfPagesCount) & " to pdf" & @CRLF, 1)
  $SourceFile = AddSlash(@TempDir) & $img_uniquename & Number($i)  $SourceFile = AddSlash(@TempDir) & $img_uniquename & Number($i)
- ; Note that the Composite command generates a black and white canvas, therefore the resulting image will lose also any bit depth. Not a problem here, but it's just important to realise this. + ; Note that the Composite command generates a black and white canvas, therefore the resulting image may lose also any bit depth. Not a problem here, but it's just important to realise this. 
- $oIMG.Composite($SourceFile & ".tif", "-density", "300", "-units", "PixelsPerInch", "-compose", "atop", "-gravity", "Center", $img_empty_name, $SourceFile & "_temp.tif"+ $oIMG.Composite($SourceFile & ".tif", "-density", String($resolution), "-units", "PixelsPerInch", "-compose", "atop", "-gravity", "Center", $img_empty_name, $SourceFile & "_temp.tif"
- $oIMG.Convert("-density", "300", "-units", "PixelsPerInch", $SourceFile & "_temp.tif", "ps:" & $SourceFile & "_temp.ps"+ $oIMG.Convert("-density",String($rastering),"-units", "PixelsPerInch", $SourceFile & "_temp.tif", "-page", $pdf_dims[$PaperOrientation[$i-1]] & "x" & $pdf_dims[1-$PaperOrientation[$i-1]] & "+0+0", "ps:" & $SourceFile & ".ps"
- _RunDos("ps2pdf " & $QQ & "-sPAPERSIZE=a4& $QQ & " " & $QQ & $SourceFile & "_temp.ps" & $QQ & " " & $QQ & $SourceFile & ".pdf& $QQ)+ _RunDos("gswin32c -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dAutoFilterGrayImages=false -dGrayImageFilter=/LZWEncode -sOutputFile=" & $SourceFile & ".pdf" & " -dDEVICEWIDTHPOINTS=" & $pdf_dims[$PaperOrientation[$i-1]] & " -dDEVICEHEIGHTPOINTS=" & $pdf_dims[1-$PaperOrientation[$i-1]] & " " & $SourceFile & ".ps") 
  FileWriteLine($FHandle,$SourceFile & ".pdf" & @CRLF)  FileWriteLine($FHandle,$SourceFile & ".pdf" & @CRLF)
  FileDelete($SourceFile & "_temp.tif")  FileDelete($SourceFile & "_temp.tif")
- FileDelete($SourceFile & "_temp.ps")+ FileDelete($SourceFile & ".ps")
  FileDelete($SourceFile & ".tif")  FileDelete($SourceFile & ".tif")
  Next  Next
  FileDelete($img_empty_name)  FileDelete($img_empty_name)
  FileClose($FHandle)  FileClose($FHandle)
- GUICtrlSetData($nEdit, @CRLF & "Merging " & Number($PdfPagesCount) & " pages into one document." & @CRLF, 1)+ GUICtrlSetData($nEdit, @CRLF & "Merging " & Number($PdfPagesCount) & " page(s) into one document." & @CRLF, 1)
  ; # Merge all pdf files into one pdf file  ; # Merge all pdf files into one pdf file
  MergePDF($Pdf_tmp_FileName, $Pdf_ListOfFiles2Proces)  MergePDF($Pdf_tmp_FileName, $Pdf_ListOfFiles2Proces)
Line 302: Line 336:
 ; Overwrite Preferences with custom values ; Overwrite Preferences with custom values
 SetNeuratronPrefs() SetNeuratronPrefs()
-RemoveSomeTempFiles()+RemoveSomeTempFiles() ; Before writing to temp directory with files, first remove possible reminiscents
  
 ; Neuratron 6 specific details like its Window Name. Execute the program as well. ; Neuratron 6 specific details like its Window Name. Execute the program as well.
Line 310: Line 344:
 Const $programRunName = "C:\Program Files\Neuratron PhotoScore Ultimate\Neuratron PhotoScore.exe"    Const $programRunName = "C:\Program Files\Neuratron PhotoScore Ultimate\Neuratron PhotoScore.exe"   
 ; run the application ; run the application
-GUICtrlSetData($nEdit, @CRLF & "Starting Neuratron 6" & @CRLF, 1)+GUICtrlSetData($nEdit, @CRLF & "Starting Neuratron PhotoScore Ultimate 6" & @CRLF, 1)
 run($programRunName)  run($programRunName) 
-sleep(3000) ; wait for Neuratron to become initialized+WinWaitNotActive ($Gui_Title) ; wait for Neuratron to become initialized 
 +sleep(250) 
 ; wait until the window is showing, time out in 3 secs ; wait until the window is showing, time out in 3 secs
 WinWaitActive($parentWindowName,"",3)    WinWaitActive($parentWindowName,"",3)   
Line 321: Line 356:
 GUICtrlSetData($nEdit, "Open document in Neuratron..." & @CRLF, 1) GUICtrlSetData($nEdit, "Open document in Neuratron..." & @CRLF, 1)
 Send("!f") Send("!f")
-WinWaitActive($parentWindowName,"",1  +WinWaitActive($parentWindowName,"",5)
 Send("n") Send("n")
-WinWaitActive($parentWindowName,"",1   +WinWaitActive("Open","",5; Wait for the Open window to become active
 ; # If there had been no processing before, we can send the original file, otherwise send the processed file. ; # If there had been no processing before, we can send the original file, otherwise send the processed file.
 If $img_greyconverted or $img_scale Then If $img_greyconverted or $img_scale Then
- Send($Pdf_tmp_FileName)+ Const $Pdf2Open = $Pdf_tmp_FileName
 Else Else
- Send($Pdf_InputFile)+ Const $Pdf2Open = $Pdf_InputFile
 EndIf EndIf
 +Send($Pdf2Open)
 +Send("{ENTER}")
 +WinWaitNotActive("Open","",4) ; Wait for the Open window to dissapear
  
-WinWaitActive($parentWindowName,"",1)   +;WinWaitActive($parentWindowName,"",6)   
-Send("{ENTER}") + _PathSplit($Pdf2Open, $szDrive, $szDir, $szFName, $szExt) 
-WinWaitActive($parentWindowName,"",1)+;WinWaitActive("Processing & $SQ & $szFName & $szExt & $SQ & "...","",5
 +WinWaitActive("Processing ","",8)
 ; ... and confirm 300 dpi resolution ; ... and confirm 300 dpi resolution
 Send("{ENTER}") Send("{ENTER}")
- 
-WinWaitActive($parentWindowName,"",1) 
- 
 ; Now wait for Progress Report window to get finished ; Now wait for Progress Report window to get finished
-While Not WinActive($parentWindowName) +WinWaitNotActive("Processing","",8)
-WEnd+
  
- +GUICtrlSetData($nEdit, "Waiting for Neuratron image processing..." & @CRLF, 1) 
-for $i=1 to $PdfPagesCount +; Check whether Windowfocus is stable: Count timer, reset if window is not active and exitloop if timer exceeds $NeuratronDelay. 
- GUICtrlSetData($nEdit, "->Processing page " & Number($i) & out of & Number($PdfPagesCount) & @CRLF1+;WinWaitActive($parentWindowName,"",8
- $begin = TimerInit() +$begin = TimerInit() 
- While WinActive($parentWindowName) +While 
- if TimerDiff($begin)/1000 > $NeuratronDelay Then + If Not WinActive($parentWindowName) Then $begin = TimerInit() 
- ExitLoop + If TimerDiff($begin)/1000 > $NeuratronDelay Then ExitLoop
- EndIf +
- WEnd +
- $begin = TimerInit() +
- While Not WinActive($parentWindowName) +
- if TimerDiff($begin)/1000 > $NeuratronDelay Then +
- ExitLoop +
- EndIf +
- WEnd +
-Next +
- +
-Sleep(1000) +
-; Now wait for Progress Report window to get finished +
-While Not WinActive($parentWindowName)+
 WEnd WEnd
 +WinWaitActive($parentWindowName,"",8)
 ; move slider to the top. ; move slider to the top.
 Opt("MouseCoordMode", 0) Opt("MouseCoordMode", 0)
Line 385: Line 406:
  
 Sleep(1000) Sleep(1000)
- 
 ; save from all pdf pages, each image as tiff ... ; save from all pdf pages, each image as tiff ...
 for $i = 1 To $PdfPagesCount for $i = 1 To $PdfPagesCount
Line 396: Line 416:
  Send("!s")  Send("!s")
  sleep(400)  sleep(400)
- 
  If $i < $PdfPagesCount Then ; last time clicking is not needed  If $i < $PdfPagesCount Then ; last time clicking is not needed
  MouseClick("left", $x1+178, $y1+50, 1)  MouseClick("left", $x1+178, $y1+50, 1)
Line 405: Line 424:
  EndIf  EndIf
  WEnd  WEnd
 + WinWaitActive($parentWindowName, "", 4)
  MouseClick("left", $x1+178, $y1+72, 1) ; Click one time extra on the window with the staves. Otherwise keyboard shortcuts don't work. This seems a bug to me...  MouseClick("left", $x1+178, $y1+72, 1) ; Click one time extra on the window with the staves. Otherwise keyboard shortcuts don't work. This seems a bug to me...
  EndIf  EndIf
Line 417: Line 437:
  GUICtrlSetData($nEdit, "->Removing page " & Number($i) & " out of " & Number($PdfPagesCount) & @CRLF, 1)  GUICtrlSetData($nEdit, "->Removing page " & Number($i) & " out of " & Number($PdfPagesCount) & @CRLF, 1)
  MouseClick("left", $x1-NeuratronObjPos($X_firstItem_Del) , $y1+NeuratronObjPos($Y_firstItem) , 1)  MouseClick("left", $x1-NeuratronObjPos($X_firstItem_Del) , $y1+NeuratronObjPos($Y_firstItem) , 1)
- sleep(1200)+ sleep(800)
  MouseClick("left", $x1-NeuratronObjPos($X_firstItem_Del)-2 , $y1+NeuratronObjPos($Y_firstItem) , 1)  MouseClick("left", $x1-NeuratronObjPos($X_firstItem_Del)-2 , $y1+NeuratronObjPos($Y_firstItem) , 1)
  Send("y")  Send("y")
- sleep(600)+ sleep(300)
 Next  Next
- GUICtrlSetData($nEdit, "Exit Neuratron" & @CRLF & @CRLF, 1)+ GUICtrlSetData($nEdit, "Exiting Neuratron" & @CRLF & @CRLF, 1)
  Send("!f")  Send("!f")
  sleep(400)  sleep(400)
Line 432: Line 452:
 ; # Finished with Neuratron ; # Finished with Neuratron
 ; ################################################################################################################# ; #################################################################################################################
-; Convert each tiff page to an pdf page.+; Below is for portrait paper orientation: 
 +; Convert each tiff page to pdf page.
 ; Convert -size 2480x3508 xc:white miff: ; Convert -size 2480x3508 xc:white miff:
 ; composite -density 300 -units PixelsPerInch -compose atop -gravity Center /tmp/$ptmpf.pbm - miff:- ; composite -density 300 -units PixelsPerInch -compose atop -gravity Center /tmp/$ptmpf.pbm - miff:-
 ; convert -monochrome -density 300 -units PixelsPerInch - ps:- ; convert -monochrome -density 300 -units PixelsPerInch - ps:-
 ; ps2pdf13 -sPAPERSIZE=a4 - "/tmp/$ptmpf-$nmb.pdf" ; ps2pdf13 -sPAPERSIZE=a4 - "/tmp/$ptmpf-$nmb.pdf"
 +
 +; There is a problem with ImageMagick writing directly to pdf, not outputting in the proper colorspace (grey instead of black and white). A solution is to write first to ps and then use ps2pdf. 
 +; The solution to specify the page size is done with the following example: 
 +; gswin32c.exe -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -sOutputFile=outgsr.pdf -dDEVICEWIDTHPOINTS=842 -dDEVICEHEIGHTPOINTS=595 outr.ps 
 +; See: http://www.groupsrv.com/computers/about63231.html
 If FileExists($Pdf_ListOfFiles2Proces) Then If FileExists($Pdf_ListOfFiles2Proces) Then
  FileDelete($Pdf_ListOfFiles2Proces)  FileDelete($Pdf_ListOfFiles2Proces)
Line 443: Line 468:
 $FHandle = FileOpen($Pdf_ListOfFiles2Proces,1) ; Write mode append to the end of file $FHandle = FileOpen($Pdf_ListOfFiles2Proces,1) ; Write mode append to the end of file
 GUICtrlSetData($nEdit, "Converting and combining images to PDF" & @CRLF, 1) GUICtrlSetData($nEdit, "Converting and combining images to PDF" & @CRLF, 1)
-$oIMG.Convert("","-size", String($img_width) & "x" & String($img_height), "xc:white", $img_empty_name) ; create one empty page with a4 size 
 for $i = 1 To $PdfPagesCount for $i = 1 To $PdfPagesCount
 + $oIMG.Convert("","-size", String($img_dims[$PaperOrientation[$i-1]]) & "x" & String($img_dims[1-$PaperOrientation[$i-1]]), "xc:white", $img_empty_name) ; create one empty page with a4 size
  GUICtrlSetData($nEdit, "->Converting page " & Number($i) & " out of " & Number($PdfPagesCount) & @CRLF, 1)  GUICtrlSetData($nEdit, "->Converting page " & Number($i) & " out of " & Number($PdfPagesCount) & @CRLF, 1)
  $SourceFile = AddSlash(@TempDir) & $img_uniquename & Number($i)  $SourceFile = AddSlash(@TempDir) & $img_uniquename & Number($i)
- $oIMG.Composite($SourceFile & ".tif", "-density", "300", "-units", "PixelsPerInch", "-compose", "atop", "-gravity", "Center", $img_empty_name, $SourceFile & "_temp.tif"+ $oIMG.Composite($SourceFile & ".tif", "-density", String($resolution), "-units", "PixelsPerInch", "-compose", "atop", "-gravity", "Center", $img_empty_name, $SourceFile & "_temp.tif"
- $oIMG.Convert("-monochrome","-density","300",$SourceFile & "_temp.tif", "ps:" & $SourceFile & "_temp.ps"+ $oIMG.Convert("-monochrome", "-density",String($rastering),"-units", "PixelsPerInch", $SourceFile & "_temp.tif", "-page", $pdf_dims[$PaperOrientation[$i-1]] & "x" & $pdf_dims[1-$PaperOrientation[$i-1]] & "+0+0", "ps:" & $SourceFile & ".ps"
- _RunDos("ps2pdf " & $QQ & "-sPAPERSIZE=a4" & $QQ & " " & $SourceFile & "_temp.ps " & $SourceFile & ".pdf")+ _RunDos("gswin32c -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -sOutputFile=" & $SourceFile & ".pdf" & " -dDEVICEWIDTHPOINTS=" & $pdf_dims[$PaperOrientation[$i-1]] & " -dDEVICEHEIGHTPOINTS=" & $pdf_dims[1-$PaperOrientation[$i-1]] & " " & $SourceFile & ".ps")
  FileWriteLine($FHandle,$SourceFile & ".pdf" & @CRLF)  FileWriteLine($FHandle,$SourceFile & ".pdf" & @CRLF)
- FileDelete($SourceFile & "_temp.ps") 
  FileDelete($SourceFile & ".tif")  FileDelete($SourceFile & ".tif")
 + FileDelete($SourceFile & ".ps")
  FileDelete($SourceFile & "_temp.tif")  FileDelete($SourceFile & "_temp.tif")
 +
 Next Next
 FileDelete($img_empty_name) FileDelete($img_empty_name)
 If $img_greyconverted or $img_scale Then FileDelete($Pdf_tmp_FileName) If $img_greyconverted or $img_scale Then FileDelete($Pdf_tmp_FileName)
 FileClose($FHandle) FileClose($FHandle)
-GUICtrlSetData($nEdit, @CRLF & "Merging " & Number($PdfPagesCount) & " pages into one document." & @CRLF, 1) +GUICtrlSetData($nEdit, @CRLF & "Merging " & Number($PdfPagesCount) & " page(s) into one document." & @CRLF, 1) 
-MergePDF($Pdf_OutputFile ,$Pdf_ListOfFiles2Proces)+MergePDF(UniqueFileName($Pdf_OutputFile,$Pdf_ListOfFiles2Proces)
 Sleep(1500) Sleep(1500)
 GUIDelete() GUIDelete()
Line 468: Line 494:
 ; # ; #
 ; ############################################################################################################## ; ##############################################################################################################
-; Capture console output into string + 
-Func DOSResult($DR_LINE)+Func DOSResult(Const $DR_LINE)
  _RunDOS($DR_LINE & " > " & @TempDir & "\DosResult.txt") ;==> Did you take into consideration the working path?  _RunDOS($DR_LINE & " > " & @TempDir & "\DosResult.txt") ;==> Did you take into consideration the working path?
- $DR_FILE = FileOpen(@TempDir & "\DosResult.txt",0) + Local $DR_FILE = FileOpen(@TempDir & "\DosResult.txt",0) 
- $DR_RESULT = FileRead($DR_FILE)+ Local $DR_RESULT = FileRead($DR_FILE)
  FileDelete(@TempDir & "\DosResult.txt")  FileDelete(@TempDir & "\DosResult.txt")
  FileClose($DR_FILE)  FileClose($DR_FILE)
Line 480: Line 506:
 ; merge pdf pages into one pdf page and deletes intermediate files ; merge pdf pages into one pdf page and deletes intermediate files
 Func MergePDF(Const $PDFFILE, Const $PDFFILE_list) Func MergePDF(Const $PDFFILE, Const $PDFFILE_list)
- _RunDos("gswin32c -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -sOutputFile=" & $PDFFILE & " " & "@" & $PDFFILE_list)+ _RunDos("gswin32c -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dAutoFilterGrayImages=false -dGrayImageFilter=/LZWEncode -sOutputFile=" & $PDFFILE & " " & "@" & $PDFFILE_list)
  FileDelete(@TempDir & "\" & $img_uniquename & "???.pdf") ; Delete only pdf files whose name contain an index.  FileDelete(@TempDir & "\" & $img_uniquename & "???.pdf") ; Delete only pdf files whose name contain an index.
  FileDelete($PDFFILE_list)   FileDelete($PDFFILE_list)
Line 486: Line 512:
  
 ; Opens a file and returns a line which contains a specified keyword ; Opens a file and returns a line which contains a specified keyword
-Func OpenFileAndGrep($OFAG_path,$OFAG_query) +Func OpenFileAndGrep(Const $OFAG_path,Const $OFAG_query) 
- $OFAG_file = FileOpen($OFAG_path,0) + Local $OFAG_file = FileOpen($OFAG_path,0) 
- $OFAG_result = FileRead($OFAG_file)+ Local $OFAG_result = FileRead($OFAG_file)
  FileClose($OFAG_file)  FileClose($OFAG_file)
  
Line 494: Line 520:
  Return  Return
  Else  Else
- $OFAG_q = "" + Local $OFAG_q = "" 
- $OFAG_stdinArray = StringSplit($OFAG_result, @LF, 1) ; put read data, separated by LineFeed characters, in an array+ Local $OFAG_stdinArray = StringSplit($OFAG_result, @LF, 1) ; put read data, separated by LineFeed characters, in an array 
 + Local $OFAG_i
  For $OFAG_i In $OFAG_stdinArray  For $OFAG_i In $OFAG_stdinArray
  If StringInStr($OFAG_i,$OFAG_query) Then  If StringInStr($OFAG_i,$OFAG_query) Then
Line 715: Line 742:
  ; RegWrite("HKEY_CURRENT_USER\Software\Neuratron\PhotoScore\Ultimate\Global settings","Save Directory","REG_SZ","C:\DOCUME~1\admin\LOCALS~1\Temp\")  ; RegWrite("HKEY_CURRENT_USER\Software\Neuratron\PhotoScore\Ultimate\Global settings","Save Directory","REG_SZ","C:\DOCUME~1\admin\LOCALS~1\Temp\")
  RegWrite("HKEY_CURRENT_USER\Software\Neuratron\PhotoScore\Ultimate\Global settings","Print guitar tab rhythm","REG_SZ","False")  RegWrite("HKEY_CURRENT_USER\Software\Neuratron\PhotoScore\Ultimate\Global settings","Print guitar tab rhythm","REG_SZ","False")
- RegWrite("HKEY_CURRENT_USER\Software\Neuratron\PhotoScore\Ultimate\Global settings","Main window position","REG_BINARY",Binary("0x2C0000000000000001000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF01000000E10000000D02000035020000"))+ RegWrite("HKEY_CURRENT_USER\Software\Neuratron\PhotoScore\Ultimate\Global settings","Main window position","REG_BINARY",Binary("0x2C0000000000000001000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8C000000F8000000980200004C020000"))
  RegWrite("HKEY_CURRENT_USER\Software\Neuratron\PhotoScore\Ultimate\Global settings","Show BPPWarning dialog","REG_SZ","True")  RegWrite("HKEY_CURRENT_USER\Software\Neuratron\PhotoScore\Ultimate\Global settings","Show BPPWarning dialog","REG_SZ","True")
  RegWrite("HKEY_CURRENT_USER\Software\Neuratron\PhotoScore\Ultimate\Global settings","Scanning preview area","REG_BINARY",Binary("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"))  RegWrite("HKEY_CURRENT_USER\Software\Neuratron\PhotoScore\Ultimate\Global settings","Scanning preview area","REG_BINARY",Binary("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"))
Line 972: Line 999:
 Func RemoveSlash(Const $var) Func RemoveSlash(Const $var)
  Return StringRegExpReplace($var, "(.)\\*$","$1")  Return StringRegExpReplace($var, "(.)\\*$","$1")
 +EndFunc
 +
 +; This function will remove a trailing slash to a windows file path
 +Func RemoveDoubleQuotes(Const $var)
 + Return StringRegExpReplace($var, "^""(.*)""$","$1")
 EndFunc EndFunc
  
Line 1018: Line 1050:
 Func RemoveSomeTempFiles() Func RemoveSomeTempFiles()
  If FileExists(AddSlash(@TempDir) & $img_uniquename & "*") Then FileDelete(AddSlash(@TempDir) & $img_uniquename & "?????????????") ; only delete files with 13 or added characters  If FileExists(AddSlash(@TempDir) & $img_uniquename & "*") Then FileDelete(AddSlash(@TempDir) & $img_uniquename & "?????????????") ; only delete files with 13 or added characters
 +EndFunc
 +
 +; Prevent overwriting a file, when it already exists. This function will find the 'first' free filename.
 +Func UniqueFileName(Const $Pdf_OutputFile)
 + If FileExists(RemoveDoubleQuotes($Pdf_OutputFile)) Then
 + Local $i = 1
 + Local $szDrive, $szDir, $szFName, $szExt
 + _PathSplit(RemoveDoubleQuotes($Pdf_OutputFile), $szDrive, $szDir, $szFName, $szExt)
 + While FileExists($szDrive & $szDir & $szFName & "(" & String($i) & ")" & $szExt)
 + $i += 1
 + WEnd
 + Return $QQ & $szDrive & $szDir & $szFName & "(" & String($i) & ")" & $szExt & $QQ
 + Else
 + Return $Pdf_OutputFile
 + EndIf
 EndFunc EndFunc
  
software/musicpdf/dev.1255582251.txt.gz · Last modified: 2009/10/15 06:50 by admin