File: Main.xba

package info (click to toggle)
musescore 1.3%2Bdfsg1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 148,004 kB
  • ctags: 30,854
  • sloc: cpp: 372,716; xml: 148,276; ansic: 6,156; python: 2,202; perl: 710; sh: 505; makefile: 227
file content (285 lines) | stat: -rw-r--r-- 8,714 bytes parent folder | download | duplicates (3)
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">&apos;	
&apos;    OOoLilyPondMusic : main module
&apos;    Copyright (C) 2005  geoffroy piroux
&apos;    Copyright (C) 2006  Samuel Hartmann
&apos;
&apos;    This program is free software; you can redistribute it and/or modify
&apos;    it under the terms of the GNU General Public License as published by
&apos;    the Free Software Foundation; either version 2 of the License, or
&apos;    (at your option) any later version.
&apos;
&apos;    This program is distributed in the hope that it will be useful,
&apos;    but WITHOUT ANY WARRANTY; without even the implied warranty of
&apos;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
&apos;    GNU General Public License for more details.
&apos;
&apos;    You should have received a copy of the GNU General Public License
&apos;    along with this program; if not, write to the Free Software
&apos;    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
&apos;
&apos; 
&apos;

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

&apos; Selected shape&apos;s variables...
Private oShapeSize, oShapePosition, oShapeCrop As Object
Private bShapeIsSelected As Boolean

&apos;---------------------------------------------------------------------------------------
Sub main
	Dim oDoc, oDocCtrl, oSelection, oAttributes, oGraphic, oShape  As Object
	Dim sCode, sTemplate As String
	Dim iAnchor, iWrap As Integer

	Initialisation()

	&apos; Get the current document and controller
 	oDoc = ThisComponent
	oDocCtrl = oDoc.getCurrentController()

	&apos; Test if we are in OOoWriter or OOoImpress 
	&apos; And set the default user configuration.
	If oDoc.getImplementationName() =  &quot;SwXTextDocument&quot; Then
		bInWriter=true
	Elseif oDoc.getImplementationName() = &quot;SdXImpressDocument&quot; Then
		bInWriter=false
	Else
		Msgbox(oDoc.getImplementationName() &amp; &quot;: document type not supported by OOoLilyPond&quot;, 0, &quot;Error&quot;)
		Exit Sub
	End If

	&apos; Set default values
	if bInWriter then
		&apos; We are in a Writer doc, set default configuration... 
		sCode=&quot;&quot;
		sTemplate=sWriterTemplate
		iAnchor=iWriterAnchor
		iWrap=iWriterWrap
	else
		&apos; We are in a Impress doc, set default configuration...
		sCode=&quot;&quot;
		sTemplate=sImpressTemplate
	end if

	&apos; If an OOoLilyPond object is selected, read the LilyPond Code
	bShapeIsSelected = False
	If Not isEmpty(oDocCtrl.selection()) Then &apos;only False in Impress when nothing is selected
		oSelection = oDocCtrl.getSelection()
		If oSelection.getImplementationName() = &quot;com.sun.star.drawing.SvxShapeCollection&quot; then
			oShape = oSelection.getByIndex(0)
			If Not ReadAttributes(oShape, sCode, sTemplate, iAnchor, iWrap) Then Exit Sub
			oShapePosition = oShape.position()
			bShapeIsSelected = True
		ElseIf oSelection.getImplementationName() = &quot;SwXTextRanges&quot; Then
			&apos;Nothing or normal text is selected
			bShapeIsSelected = False
		Else
			Msgbox (&quot;The selected object is not an OOoLilyPond object ...&quot;, 0, &quot;Error&quot;)
			Exit Sub
		End If
	End If

	&apos; Open the dialogue box
	OOoLilyPondDialog(sCode, sTemplate, iAnchor, iWrap)
End Sub

&apos; ToDo:
&apos; Load Configration if Config File Exists
Sub Initialisation

	DefaultConfig()
	if FileExists( sConfigFile ) then ReadConfigFile

End Sub


&apos; This is the core macro! It is called by the dialogue box.
&apos; It calls the subroutinges that generate the image and insert it into the document.
sub MakeMusic(sCode, sTemplate As String, iAnchor, iWrap As Integer)

	&apos; Definitions of variables...
	Dim iNumber As Integer
	Dim sShellArg,sMsg,sLilyPondCode as String

	&apos; We test if there is LilyPond code...
	If sCode = &quot;&quot; then 
		Msgbox (&quot;Enter LilyPond code...&quot;, 0, &quot;Error&quot;)
		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

	&apos;Check the result !

	&apos;If Not FileExists(sTmpPath &amp; &quot;OOoLilyPond.eps&quot;) Then &apos; LilyPond error.
  	&apos;	PrintFile(&quot;OOoLilyPond.out&quot;)
  	&apos;	Exit Sub
  	&apos;End If
 	&apos;If sFormat = &quot;png&quot; And (Not FileExists(sTmpPath &amp; &quot;OOoLilyPond.png&quot;)) Then
 	&apos;	MsgBox(&quot;No png output is found&quot;, 0, &quot;Error&quot;)
  	&apos;	Exit Sub
 	&apos;End If

	&apos; 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(&quot;Test3&quot;)
	
	Dim sCommand As String
	
		sCommand = &quot;cd /d &quot; &amp; Chr(34) &amp; &quot;c:\slask\&quot; &amp; Chr(34) &amp; Chr(10) _
		&amp; Chr(34) &amp; sLilyPondExecutable  &amp; Chr(34) &apos;&quot;C:\Program\MuseScore 0.9\bin\mscore.exe&quot;
		sCommand = sCommand &amp;  &quot; &quot; &apos;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
	
	&apos;sLilyPondCode = &quot;hejsan hoppsan&quot;

	&apos;Open sLyFile For Output As #iNumber
	&apos;Print #iNumber, sLilyPondCode	
	&apos;Close #iNumber
	
	&apos;Open sLyFile For Input As #iNumber
	&apos;Read #iNumber, sLilyPondCode
	&apos;Close #iNumber	
	&apos;MsgBox (&quot;Hej&quot;)
	
	&apos;sCode = 	oDlgMain.getControl(&quot;LilyPondCode&quot;).getText()
	&apos;Msgbox sMsg	

	sTemplate = oDlgMain.getControl(&quot;Template&quot;).getText()
	sLyFile=ConvertFromURL(sTemplatePath &amp; sTemplate &amp; &quot;.msc&quot;)
	MsgBox(sLyFile)
	iNumber = Freefile	
	sCode = &quot;&quot;
	Open sLyFile For Input As #iNumber
	While not eof(#iNumber)
		Line Input #iNumber, sLine
		If sLine &lt;&gt;&quot;&quot; then
		sCode = sCode &amp; sLine &amp; chr(13)
		end if
	wend
	Close #iNumber
	&apos;Msgbox sMsg	
	oDlgMain.getControl(&quot;LilyPondCode&quot;).setText(sCode)


end sub

sub saveCodeToTempFile
	Dim sLyFile As String
	Dim sCode As String
	Dim iNumber As Integer

	sLyFile=ConvertFromURL(sTmpPath &amp; &quot;temp.msc&quot;)		
	&apos;MsgBox sLyFile
	sCode = 	oDlgMain.getControl(&quot;LilyPondCode&quot;).getText()
	&apos;Msgbox sCode
	iNumber = Freefile	
	Open sLyFile For Output As #iNumber
	Print #iNumber, sCode	
	Close #iNumber

end sub

sub runMScoreWithTempFile
	Dim sCommand As String
	&apos;MuseScore
	
	If sOSType = &quot;Windows&quot; Then
	&apos;MsgBox sTmpPath
		sCommand = &quot;cd /d &quot; &amp; Chr(34) &amp; ConvertFromURL(sTmpPath) &amp; Chr(34) &amp; Chr(10) &apos; &quot;c:\slask\&quot;
		sCommand = sCommand &amp; Chr(34) &amp; sLilyPondExecutable &amp; Chr(34)
		sCommand = sCommand &amp; &quot; &quot; &amp; &quot;temp.msc&quot;
		WindowsCommand(sCommand)
    ElseIf sOSType = &quot;Unix&quot; Then
    	sCommand = &quot;cd &quot; &amp; Chr(34) &amp; ConvertFromURL(sTmpPath) &amp; Chr(34) &amp; &quot;; &quot; &amp; sLilyPondExecutable &amp; &quot; temp.msc&quot;
    	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 &amp; &quot;temp.msc&quot;)
	&apos;MsgBox(sLyFile)
	iNumber = Freefile	
	sCode = &quot;&quot;
	Open sLyFile For Input As #iNumber
	While not eof(#iNumber)
		Line Input #iNumber, sLine
		If sLine &lt;&gt;&quot;&quot; then
		sCode = sCode &amp; sLine &amp; chr(13)
		end if
	wend
	Close #iNumber
	&apos;Msgbox sMsg	
	oDlgMain.getControl(&quot;LilyPondCode&quot;).setText(sCode)
end sub

sub handleMScore
	Dim sCode As String
	Dim control As Object
	
	sCode = 	oDlgMain.getControl(&quot;LilyPondCode&quot;).getText()
	if sCode = &quot;&quot; Then
		loadDefaultCode()
	End If
	&apos;msgBox &quot;Hej&quot;
	saveCodeToTempFile()
	runMScoreWithTempFile()
	loadCodeFromTempFile()	
	LilyPondButton_Clicked()
end sub


</script:module>