1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Subs" script:language="StarBasic">'Option Explicit
function ApplyTemplate(sCode As String, sTemplate As String, sLilyPondCode As String) As Boolean
sLilyPondCode = sLilyPondCode & sCode
' Do nothing here...
ApplyTemplate=True
End Function
Function CallLilyPond() As Boolean
Dim sCommand As String
If sOSType = "Windows" Then
'MuseScore
sCommand = "cd /d " & Chr(34) & ConvertFromURL(sTmpPath) & Chr(34) & Chr(10) _
& Chr(34) & sLilyPondExecutable & Chr(34)
sCommand = sCommand & " tempMScore.msc -o tempMScore.pdf"
WindowsCommand(sCommand)
'ImageMagick Convert
sCommand = "cd /d " & Chr(34) & ConvertFromURL(sTmpPath) & Chr(34) & Chr(10) & Chr(34) & sImageMagicExecutable & "\convert" & Chr(34)
sCommand = sCommand & " -trim -density " & iGraphicDPI & " tempMScore.pdf tempMScore.png" '" & iGraphicDPI & "
WindowsCommand(sCommand)
ElseIf sOSType = "Unix" Then
sCommand="cd " & Chr(34) & ConvertFromURL(sTmpPath) & Chr(34) & "; " _
& Chr(34) & sLilyPondExecutable & Chr(34) & " tempMScore.msc -o tempMScore1.png -r " & iGraphicDPI
BashCommand(sCommand)
sCommand = "cd " & Chr(34) & ConvertFromURL(sTmpPath) & Chr(34) & "; " _
& sImageMagicExecutable & "/convert tempMScore1.png -trim tempMScore.png"
BashCommand(sCommand)
End If
CallLilyPond=True 'lilypond was executed
End Function
Sub CleanUp()
If FileExists(sTmpPath & "LilyPond-version.out") Then Kill(sTmpPath & "LilyPond-version.out")
If FileExists(sTmpPath & "LilyPond-cannot_execute") Then Kill(sTmpPath & "LilyPond-cannot_execute")
If FileExists(sTmpPath & "OOoLilyPond.out") Then Kill(sTmpPath & "OOoLilyPond.out")
If FileExists(sTmpPath & "OOoLilyPond.eps") Then Kill(sTmpPath & "OOoLilyPond.eps")
If FileExists(sTmpPath & "OOoLilyPond-1.eps") Then Kill(sTmpPath & "OOoLilyPond-1.eps")
If FileExists(sTmpPath & "OOoLilyPond-systems.tex") Then Kill(sTmpPath & "OOoLilyPond-systems.tex")
If FileExists(sTmpPath & "OOoLilyPond-systems.texi") Then Kill(sTmpPath & "OOoLilyPond-systems.texi")
If FileExists(sTmpPath & "OOoLilyPond.ly") Then Kill(sTmpPath & "OOoLilyPond.ly")
If FileExists(sTmpPath & "OOoLilyPond.png") Then Kill(sTmpPath & "OOoLilyPond.png")
End Sub
Sub InsertAttribute(oGraphic As Object, sName, sValue As String)
'MsgBox "InsertAttribute"
Dim oAttributes, oLilyPondAttribute As Object
' Add a user defined attribute to the image.
oAttributes = oGraphic.UserDefinedAttributes
oLilyPondAttribute = createUnoStruct( "com.sun.star.xml.AttributeData" )
oLilyPondAttribute.Type = "CDATA"
oLilyPondAttribute.Value = sValue
oAttributes.insertByName(sName, oLilyPondAttribute )
oGraphic.UserDefinedAttributes = oAttributes
End Sub
Sub InsertMusic(sCode, sTemplate As String, iAnchor, iWrap As Integer)
'MsgBox "InsertMusic"
Dim oDoc, oDocCtrl, oDispatcher, oAttributes, oViewCursor, oGraphic, oLilyPondAttribute As Object
Dim oBitmapInfo As Object
Dim oGraph As Object
Dim oSize As Object
Dim iSizeW, iSizeH As Integer
' Create the Controller and dispatcher for current document...
oDoc = StarDesktop.CurrentComponent
oDocCtrl = oDoc.getCurrentController()
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
if bInWriter then
if bShapeIsSelected then
'Remove the old image...
oDispatcher.executeDispatch( oDocCtrl.Frame, ".uno:Cut", "", 0, Array())
else
'Get the cursor position...
Dim oCursor, oText as Object
oViewCursor = oDocCtrl.ViewCursor
oText = oDoc.Text
oCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
end if
'Import the new image to the clipboard and paste it...
'ImportGraphicIntoClipboard(ConvertToURL( sTmpPath & "OOoLilyPond."& sFormat))
ImportGraphicIntoClipboard(ConvertToURL(ConvertFromURL(sTmpPath) & "tempMScore.png"))
oDispatcher.executeDispatch( oDocCtrl.Frame, ".uno:Paste", "", 0, Array())
oGraphic = oDocCtrl.getSelection().GetByIndex(0)
' set image properties
oGraphic.AnchorType = iAnchor
oGraphic.Surround = iWrap
oGraphic.TopMargin = 0
oGraphic.BottomMargin = 0
oGraphic.VertOrient = 0
oBitmapInfo = oGraphic.GraphicObjectFillBitmap
oSize = oBitmapInfo.getSize()
'MsgBox(oSize.Width)
'MsgBox(oSize.Height)
iSizeW = oSize.Width
iSizeH = oSize.Height
oSize.width = iSizeW * 8.4
oSize.height = iSizeH * 8.4
oGraphic.setSize(oSize)
if not bShapeIsSelected then
' Show cursor...
oDispatcher.executeDispatch(oDocCtrl.Frame, ".uno:Escape", "", 0, Array())
oCursor.goRight(0,false)
oViewCursor.gotoRange(oCursor, False)
end if
else 'We are in Impress
if bShapeIsSelected then
' Remove the old image...
oDispatcher.executeDispatch(oDocCtrl.Frame,".uno:Cut","", 0, Array() )
end if
'Import the new image to the clipboard and paste it...
ImportGraphicIntoClipboard(ConvertToURL( sTmpPath & "tempMScore.png"))
oDispatcher.executeDispatch( oDocCtrl.Frame, ".uno:Paste", "", 0, Array())
oGraphic = oDocCtrl.getSelection().getByIndex(0)
if bShapeIsSelected then oGraphic.position = oShapePosition
end if
InsertAttribute(oGraphic, "OOoLilyPondCode", sCode)
InsertAttribute(oGraphic, "OOoLilyPondTemplate", sTemplate)
End Sub
' Fills the ComboBox with the list of Templates
sub ListOfTemplates(oComboBox, bSilent)
Dim sTemplate(1000) As String
Dim t As String
Dim i As Integer
'Liste leeren
oComboBox.removeItems(0, oComboBox.getItemCount)
If Not FileExists(sTemplatePath) Then
If Not bSilent Then MsgBox("The specified path for templates does not exist: " & Chr(10) & Chr(34) & ConvertFromURL(sTemplatePath) & Chr(34) & "." & Chr(10) & "Please adjust the path in the configuration dialog.")
Else
i=0
t=Dir(sTemplatePath)
do while t<>""
If Right(t,4)=".msc" Then
sTemplate(i)=Left(t, Len(t)-4)
i=i+1
End If
t=Dir
loop
If i=0 Then
If Not bSilent Then MsgBox("No templates are found at the path: " & Chr(10) & Chr(34) & ConvertFromURL(sTemplatePath) & Chr(34) & "." & Chr(10) & "OOoLilyPond will not work without a template.")
Else
ReDim Preserve sTemplate(i-1) As String
SortStringArray(sTemplate)
oComboBox.addItems(sTemplate,0)
End If
EndIf
end sub
' args: 0:Template, 1:Anchor, 2:Wrap, 3:Code
'*********************************************************
Function ReadAttributes( oShape As Object, sCode, sTemplate As String, iAnchor, iWrap As Integer) As Boolean
'MsgBox("ReadAttributes")
Dim sLyAttributes As Variant
Dim control As Variant
If oShape.UserDefinedAttributes().hasByName("OOoLilyPondArgs") Then
'Object created by OOoLilyPond Versions <= 0.2.1
sLyAttributes=oShape.UserDefinedAttributes().getByName("OOoLilyPondArgs").Value
sLyAttributes=Split(oShape.UserDefinedAttributes().getByName("OOoLilyPondArgs").Value, "ยง", 4)
sTemplate=sLyAttributes(0)
sCode=sLyAttributes(3)
ElseIf oShape.UserDefinedAttributes().hasByName("OOoLilyPondCode") Then
'Object created by OOoLilyPond Versions >= 0.3
sCode=oShape.UserDefinedAttributes().getByName("OOoLilyPondCode").Value
sTemplate=oShape.UserDefinedAttributes().getByName("OOoLilyPondTemplate").Value
Else
'The selected Object is not a OOoLilyPond Object
Msgbox ("The selected object is not an OOoLilyPond object ...", 0, "Error")
ReadAttributes = False
Exit Function
End If
If bInWriter Then
iAnchor=oShape.AnchorType
iWrap=oShape.Surround
Else
iAnchor=-1
iWrap=-1
End IF
if sCode > "" then
'Disable template control
End If
ReadAttributes=True
Exit Function
End Function
Function WriteLyFile(sLilyPondCode) As Boolean
Dim sLyFile As String
Dim iNumber As Integer
'On Error Goto ErrorHandler
sLyFile=ConvertFromURL(sTmpPath & "tempMScore.msc")
iNumber = Freefile
Open sLyFile For Output As #iNumber
'Print #iNumber, sLilyPondCode
Print #iNumber, sLilyPondCode
Close #iNumber
WriteLyFile=True
End Function
</script:module>
|