function Get-TemporaryDirectory { $parent = [System.IO.Path]::GetTempPath() do { $name = [System.IO.Path]::GetRandomFileName() $item = New-Item -Path $parent -Name $name -ItemType "directory" -ErrorAction SilentlyContinue } while (-not $item) return $item.FullName } function Get-TemporaryFile { param( [string]$extension ) $parent = [System.IO.Path]::GetTempPath() do { $name = [System.IO.Path]::GetRandomFileName() + $extension $item = New-Item -Path $parent -Name $name -ItemType "file" -ErrorAction SilentlyContinue } while (-not $item) return $item.FullName } function Get-Mscx-Content { param( [string]$mscz_file ) # First rename (a copy) of the original score (=.mscz) to ".zip" to be able to unzip $tmpZIP = Get-TemporaryFile ".zip" Copy-Item $mscz_file $tmpZIP # uncompress score $uncompressed = Get-TemporaryDirectory Expand-Archive $tmpZIP -DestinationPath $uncompressed Remove-Item $tmpZIP $mscx = Get-ChildItem -Path $uncompressed -Filter "*.mscx" $content = Get-Content $mscx.FullName Remove-Item $uncompressed -Recurse return $content } function Start-of-staffs { param( [System.Object[]]$content_mscx ) $line_no = 0 $found = $false while ( -not $found -and $line_no -lt $content_mscx.Count ) { $line = $content_mscx[$line_no++] if ( $line -imatch "") { $inPart = $false } elseif ( $line -imatch " extracting score '" + $score + "'" # extend content array $c = Get-Mscx-Content $score $null = $content_of_scores.Add( $c ) # remember line number of each score file $null = $line_no_in_score.Add(0) } [System.Collections.ArrayList]$new_score = @() # where do all the staffs begin in scores? for ( $score_no = 0 ; $score_no -lt $content_of_scores.Count ; $score_no++ ) { $line_no_in_score[$score_no] = Start-of-staffs $content_of_scores[$score_no] } # take header of first score till start of staffs for ( $i = 0; $i -lt $line_no_in_score[0]; $i++ ) { $null = $new_score.Add($content_of_scores[0][$i]) } while ( $line_no_in_score[0] -lt $content_of_scores[0].Count -and $content_of_scores[0][$line_no_in_score[0]] -inotmatch "" ) { # insert staffs of other score for ( $score_no = 0 ; $score_no -lt $content_of_scores.Count ; $score_no++ ) { # take stuff till " do { $inner_line = $content_of_scores[$score_no][$line_no_in_score[$score_no]++] if ( $score_no -eq ($content_of_scores.Count-1) -or $inner_line -inotmatch "" ) { $null = $new_score.Add($inner_line) } else { # add staff line "end" and page break at end of score if not last one if ( $score_no -lt ($content_of_scores.Count - 1) ) { # "end" must be before $null = $new_score.Insert($new_score.Count-2, " ") $null = $new_score.Insert($new_score.Count-2, " end") $null = $new_score.Insert($new_score.Count-2, " ") # page and sectin break must be before $null = $new_score.Insert($new_score.Count-1, " ") $null = $new_score.Insert($new_score.Count-1, " section") $null = $new_score.Insert($new_score.Count-1, " ") $null = $new_score.Insert($new_score.Count-1, " ") $null = $new_score.Insert($new_score.Count-1, " page") $null = $new_score.Insert($new_score.Count-1, " ") } } } while ( $line_no_in_score[$score_no] -lt $content_of_scores[$score_no].Count -and $inner_line -inotmatch "" ) # find next line starting a staff (may not be necessary for first staff) if ( $score_no -ne 0 -and $content_of_scores[$score_no][$line_no_in_score[$score_no]] -imatch "