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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
|
<?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="Main" script:language="StarBasic">'
' OOoLilyPondMusic : main module
' Copyright (C) 2005 geoffroy piroux
' Copyright (C) 2006 Samuel Hartmann
'
' 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 2 of the License, or
' (at your option) 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, write to the Free Software
' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
'
'
'
Option Explicit
Private sConfigFile, sTmpPath, sLilyPondExecutable, sImageMagicExecutable, sTemplatePath, sFormat, sOSType As String
Private sWriterTemplate As String
Private sImpressTemplate As String
Private iWriterAnchor, iWriterWrap As Integer
Private iGraphicDPI As Integer
Private bInWriter As Boolean
' Selected shape's variables...
Private oShapeSize, oShapePosition, oShapeCrop As Object
Private bShapeIsSelected As Boolean
'---------------------------------------------------------------------------------------
Sub main
Dim oDoc, oDocCtrl, oSelection, oAttributes, oGraphic, oShape As Object
Dim sCode, sTemplate As String
Dim iAnchor, iWrap As Integer
Initialisation()
' Get the current document and controller
oDoc = ThisComponent
oDocCtrl = oDoc.getCurrentController()
' Test if we are in OOoWriter or OOoImpress
' And set the default user configuration.
If oDoc.getImplementationName() = "SwXTextDocument" Then
bInWriter=true
Elseif oDoc.getImplementationName() = "SdXImpressDocument" Then
bInWriter=false
Else
Msgbox(oDoc.getImplementationName() & ": document type not supported by OOoLilyPond", 0, "Error")
Exit Sub
End If
' Set default values
if bInWriter then
' We are in a Writer doc, set default configuration...
sCode=""
sTemplate=sWriterTemplate
iAnchor=iWriterAnchor
iWrap=iWriterWrap
else
' We are in a Impress doc, set default configuration...
sCode=""
sTemplate=sImpressTemplate
end if
' If an OOoLilyPond object is selected, read the LilyPond Code
bShapeIsSelected = False
If Not isEmpty(oDocCtrl.selection()) Then 'only False in Impress when nothing is selected
oSelection = oDocCtrl.getSelection()
If oSelection.getImplementationName() = "com.sun.star.drawing.SvxShapeCollection" then
oShape = oSelection.getByIndex(0)
If Not ReadAttributes(oShape, sCode, sTemplate, iAnchor, iWrap) Then Exit Sub
oShapePosition = oShape.position()
bShapeIsSelected = True
ElseIf oSelection.getImplementationName() = "SwXTextRanges" Then
'Nothing or normal text is selected
bShapeIsSelected = False
Else
Msgbox ("The selected object is not an OOoLilyPond object ...", 0, "Error")
Exit Sub
End If
End If
' Open the dialogue box
OOoLilyPondDialog(sCode, sTemplate, iAnchor, iWrap)
End Sub
' ToDo:
' Load Configration if Config File Exists
Sub Initialisation
DefaultConfig()
if FileExists( sConfigFile ) then ReadConfigFile
End Sub
' This is the core macro! It is called by the dialogue box.
' It calls the subroutinges that generate the image and insert it into the document.
sub MakeMusic(sCode, sTemplate As String, iAnchor, iWrap As Integer)
' Definitions of variables...
Dim iNumber As Integer
Dim sShellArg,sMsg,sLilyPondCode as String
' We test if there is LilyPond code...
If sCode = "" then
Msgbox ("Enter LilyPond code...", 0, "Error")
exit sub
end if
If Not ApplyTemplate(sCode, sTemplate, sLilyPondCode) Then Exit Sub
CleanUp()
If Not WriteLyFile(sLilyPondCode) Then Exit Sub
If Not CallLilyPond() Then Exit Sub
'Check the result !
'If Not FileExists(sTmpPath & "OOoLilyPond.eps") Then ' LilyPond error.
' PrintFile("OOoLilyPond.out")
' Exit Sub
'End If
'If sFormat = "png" And (Not FileExists(sTmpPath & "OOoLilyPond.png")) Then
' MsgBox("No png output is found", 0, "Error")
' Exit Sub
'End If
' If we arrive here, the compilation succeed. We can close the dialog...
oDlgMain.endExecute()
InsertMusic(sCode, sTemplate, iAnchor, iWrap)
end sub
sub test
Dim oDoc, oDocCtrl, oSelection, oAttributes, oGraphic, oShape As Object
oDoc = ThisComponent
oDocCtrl = oDoc.getCurrentController()
MsgBox isEmpty(oDocCtrl.selection())
end sub
sub test2
MsgBox("Test3")
Dim sCommand As String
sCommand = "cd /d " & Chr(34) & "c:\slask\" & Chr(34) & Chr(10) _
& Chr(34) & sLilyPondExecutable & Chr(34) '"C:\Program\MuseScore 0.9\bin\mscore.exe"
sCommand = sCommand & " " 'testWrite.msc -o test.pdf
MsgBox (sCommand)
WindowsCommand(sCommand)
end sub
sub loadDefaultCode
Dim sLyFile As String
Dim iNumber As Integer
Dim sLilyPondCode As String
Dim sCode As String
Dim sLine As String
Dim sTemplate As String
'sLilyPondCode = "hejsan hoppsan"
'Open sLyFile For Output As #iNumber
'Print #iNumber, sLilyPondCode
'Close #iNumber
'Open sLyFile For Input As #iNumber
'Read #iNumber, sLilyPondCode
'Close #iNumber
'MsgBox ("Hej")
'sCode = oDlgMain.getControl("LilyPondCode").getText()
'Msgbox sMsg
sTemplate = oDlgMain.getControl("Template").getText()
sLyFile=ConvertFromURL(sTemplatePath & sTemplate & ".msc")
MsgBox(sLyFile)
iNumber = Freefile
sCode = ""
Open sLyFile For Input As #iNumber
While not eof(#iNumber)
Line Input #iNumber, sLine
If sLine <>"" then
sCode = sCode & sLine & chr(13)
end if
wend
Close #iNumber
'Msgbox sMsg
oDlgMain.getControl("LilyPondCode").setText(sCode)
end sub
sub saveCodeToTempFile
Dim sLyFile As String
Dim sCode As String
Dim iNumber As Integer
sLyFile=ConvertFromURL(sTmpPath & "temp.msc")
'MsgBox sLyFile
sCode = oDlgMain.getControl("LilyPondCode").getText()
'Msgbox sCode
iNumber = Freefile
Open sLyFile For Output As #iNumber
Print #iNumber, sCode
Close #iNumber
end sub
sub runMScoreWithTempFile
Dim sCommand As String
'MuseScore
If sOSType = "Windows" Then
'MsgBox sTmpPath
sCommand = "cd /d " & Chr(34) & ConvertFromURL(sTmpPath) & Chr(34) & Chr(10) ' "c:\slask\"
sCommand = sCommand & Chr(34) & sLilyPondExecutable & Chr(34)
sCommand = sCommand & " " & "temp.msc"
WindowsCommand(sCommand)
ElseIf sOSType = "Unix" Then
sCommand = "cd " & Chr(34) & ConvertFromURL(sTmpPath) & Chr(34) & "; " & sLilyPondExecutable & " temp.msc"
BashCommand(sCommand)
EndIf
end sub
sub loadCodeFromTempFile
Dim sLyFile As String
Dim iNumber As Integer
Dim sLilyPondCode As String
Dim sCode As String
Dim sLine As String
sLyFile=ConvertFromURL(sTmpPath & "temp.msc")
'MsgBox(sLyFile)
iNumber = Freefile
sCode = ""
Open sLyFile For Input As #iNumber
While not eof(#iNumber)
Line Input #iNumber, sLine
If sLine <>"" then
sCode = sCode & sLine & chr(13)
end if
wend
Close #iNumber
'Msgbox sMsg
oDlgMain.getControl("LilyPondCode").setText(sCode)
end sub
sub handleMScore
Dim sCode As String
Dim control As Object
sCode = oDlgMain.getControl("LilyPondCode").getText()
if sCode = "" Then
loadDefaultCode()
End If
'msgBox "Hej"
saveCodeToTempFile()
runMScoreWithTempFile()
loadCodeFromTempFile()
LilyPondButton_Clicked()
end sub
</script:module>
|