'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