-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DemoWindow.rbfrm
525 lines (508 loc) · 13.9 KB
/
DemoWindow.rbfrm
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
#tag Window
Begin Window DemoWindow
BackColor = &hFFFFFF
Backdrop = ""
CloseButton = True
Composite = False
Frame = 0
FullScreen = False
HasBackColor = False
Height = 1.18e+2
ImplicitInstance= True
LiveResize = True
MacProcID = 0
MaxHeight = 32000
MaximizeButton = False
MaxWidth = 32000
MenuBar = ""
MenuBarVisible = True
MinHeight = 64
MinimizeButton = True
MinWidth = 64
Placement = 2
Resizeable = False
Title = "HP MidiFile Demo"
Visible = True
Width = 3.68e+2
Begin Label Label1
AutoDeactivate = False
Bold = ""
DataField = ""
DataSource = ""
Enabled = True
Height = 20
HelpTag = ""
Index = -2147483648
InitialParent = ""
Italic = ""
Left = 6
LockBottom = ""
LockedInPosition= False
LockLeft = True
LockRight = ""
LockTop = True
Multiline = ""
Scope = 0
Selectable = False
TabIndex = 10
TabPanelIndex = 0
Text = "-Tempo+"
TextAlign = 1
TextColor = &h000000
TextFont = "System"
TextSize = 8
TextUnit = 0
Top = 57
Transparent = True
Underline = ""
Visible = True
Width = 100
End
Begin Timer Timer1
Height = 32
Index = -2147483648
Left = 384
LockedInPosition= False
Mode = 0
Period = 100
Scope = 0
TabPanelIndex = 0
Top = 10
Width = 32
End
Begin Slider Slider1
AutoDeactivate = True
Enabled = True
Height = 23
HelpTag = ""
Index = -2147483648
InitialParent = ""
Left = 6
LineStep = 1
LiveScroll = False
LockBottom = ""
LockedInPosition= False
LockLeft = True
LockRight = ""
LockTop = True
Maximum = 100
Minimum = 0
PageStep = 20
Scope = 0
TabIndex = 1
TabPanelIndex = 0
TabStop = True
TickStyle = 1
Top = 41
Value = 0
Visible = True
Width = 356
End
Begin PushButton LoadBtn
AutoDeactivate = True
Bold = ""
ButtonStyle = 0
Cancel = ""
Caption = "Load"
Default = ""
Enabled = True
Height = 22
HelpTag = ""
Index = -2147483648
InitialParent = ""
Italic = ""
Left = 6
LockBottom = ""
LockedInPosition= False
LockLeft = True
LockRight = ""
LockTop = True
Scope = 0
TabIndex = 3
TabPanelIndex = 0
TabStop = True
TextFont = "System"
TextSize = 0
TextUnit = 0
Top = 7
Underline = ""
Visible = True
Width = 80
End
Begin PushButton PlayBtn
AutoDeactivate = True
Bold = ""
ButtonStyle = 0
Cancel = ""
Caption = "Play"
Default = ""
Enabled = False
Height = 22
HelpTag = ""
Index = -2147483648
InitialParent = ""
Italic = ""
Left = 88
LockBottom = ""
LockedInPosition= False
LockLeft = True
LockRight = ""
LockTop = True
Scope = 0
TabIndex = 4
TabPanelIndex = 0
TabStop = True
TextFont = "System"
TextSize = 0
TextUnit = 0
Top = 7
Underline = ""
Visible = True
Width = 80
End
Begin PushButton StopBtn
AutoDeactivate = True
Bold = ""
ButtonStyle = 0
Cancel = ""
Caption = "Stop"
Default = ""
Enabled = False
Height = 22
HelpTag = ""
Index = -2147483648
InitialParent = ""
Italic = ""
Left = 170
LockBottom = ""
LockedInPosition= False
LockLeft = True
LockRight = ""
LockTop = True
Scope = 0
TabIndex = 5
TabPanelIndex = 0
TabStop = True
TextFont = "System"
TextSize = 0
TextUnit = 0
Top = 7
Underline = ""
Visible = True
Width = 80
End
Begin Label TimeLabel
AutoDeactivate = True
Bold = ""
DataField = ""
DataSource = ""
Enabled = True
Height = 20
HelpTag = ""
Index = -2147483648
InitialParent = ""
Italic = ""
Left = 138
LockBottom = False
LockedInPosition= False
LockLeft = True
LockRight = ""
LockTop = False
Multiline = ""
Scope = 0
Selectable = False
TabIndex = 7
TabPanelIndex = 0
Text = "00:00:00/00:00:00"
TextAlign = 1
TextColor = &h000000
TextFont = "System"
TextSize = 0
TextUnit = 0
Top = 66
Transparent = True
Underline = ""
Visible = True
Width = 92
End
Begin Timer TimeTimer
Height = 32
Index = -2147483648
Left = 384
LockedInPosition= False
Mode = 0
Period = 1
Scope = 0
TabPanelIndex = 0
Top = 54
Width = 32
End
Begin Slider Slider2
AutoDeactivate = True
Enabled = True
Height = 15
HelpTag = ""
Index = -2147483648
InitialParent = ""
Left = 6
LineStep = 1
LiveScroll = ""
LockBottom = ""
LockedInPosition= False
LockLeft = True
LockRight = ""
LockTop = True
Maximum = 400
Minimum = 10
PageStep = 20
Scope = 0
TabIndex = 2
TabPanelIndex = 0
TabStop = True
TickStyle = 0
Top = 71
Value = 100
Visible = True
Width = 100
End
Begin ComboBox DeviceList
AutoComplete = False
AutoDeactivate = True
Bold = ""
DataField = ""
DataSource = ""
Enabled = True
Height = 20
HelpTag = ""
Index = -2147483648
InitialValue = ""
Italic = ""
Left = 6
ListIndex = 0
LockBottom = ""
LockedInPosition= False
LockLeft = True
LockRight = ""
LockTop = True
Scope = 0
TabIndex = 11
TabPanelIndex = 0
TabStop = True
TextFont = "System"
TextSize = 0
TextUnit = 0
Top = 92
Underline = ""
UseFocusRing = True
Visible = True
Width = 356
End
Begin PushButton EditBtn
AutoDeactivate = True
Bold = ""
ButtonStyle = 0
Cancel = ""
Caption = "Edit"
Default = ""
Enabled = False
Height = 22
HelpTag = ""
Index = -2147483648
InitialParent = ""
Italic = ""
Left = 252
LockBottom = ""
LockedInPosition= False
LockLeft = True
LockRight = ""
LockTop = True
Scope = 0
TabIndex = 12
TabPanelIndex = 0
TabStop = True
TextFont = "System"
TextSize = 0
TextUnit = 0
Top = 7
Underline = ""
Visible = True
Width = 80
End
End
#tag EndWindow
#tag WindowCode
#tag Event
Sub Open()
If Midi.IsAvailable Then
Me.Title = Midi.Version + " demo"
End If
End Sub
#tag EndEvent
#tag Method, Flags = &h1
Protected Function FormatTime(Milliseconds As Int64, FractionalSeconds As Boolean = False) As String
' Formats the period of time denoted by Milliseconds as HH:MM:SS. If FractionalSeconds is true then fractions of a second are included.
Dim hours As Integer = (Milliseconds / (1000 * 60 * 60))
Dim minutes As Integer = (Milliseconds / (1000 * 60)) Mod 60
Dim seconds As Integer = (Milliseconds / 1000) Mod 60
Dim frac As Integer = Milliseconds Mod 1000
Dim out As String
If hours > 0 Then
out = Str(hours) + ":" + Format(minutes, "00") + ":"
Else
out = out + Format(minutes, "#0") + ":"
End If
If FractionalSeconds Then
out = out + Format(seconds + (frac / 1000), "00.00")
Else
out = out + Format(seconds, "00")
End If
Return out
End Function
#tag EndMethod
#tag Property, Flags = &h1
Protected mFractionalSeconds As Boolean
#tag EndProperty
#tag Property, Flags = &h0
Player As Midi.MidiFile
#tag EndProperty
#tag Property, Flags = &h21
Private UILock As Boolean
#tag EndProperty
#tag EndWindowCode
#tag Events Timer1
#tag Event
Sub Action()
If UILock Or PlayBtn.Caption = "Resume" Then Return
If Not player.IsPlaying Then
Me.Mode = Timer.ModeOff
TimeTimer.Mode = Timer.ModeOff
PlayBtn.Caption = "Play"
StopBtn.Enabled = False
Return
End If
Dim total As Int32 = player.Duration
Dim now As Integer = player.PlayTime
UILock = True
Slider1.Value = now * 100 / total
UILock = False
End Sub
#tag EndEvent
#tag EndEvents
#tag Events Slider1
#tag Event
Sub ValueChanged()
If UILock Then Return
UILock = True
player.EventTime = Me.Value * player.Duration / Me.Maximum
UILock = False
End Sub
#tag EndEvent
#tag EndEvents
#tag Events LoadBtn
#tag Event
Sub Action()
Dim f As FolderItem = GetOpenFolderItem(FileTypes1.All)
If f = Nil Or Not f.Exists Then Return
player = New Midi.MidiFile
player.Load(f)
PlayBtn.Enabled = True
EditBtn.Enabled = True
End Sub
#tag EndEvent
#tag EndEvents
#tag Events PlayBtn
#tag Event
Sub Action()
Select Case Me.Caption
Case "Play"
player.Play()
Me.Caption = "Pause"
TimeTimer.Mode = Timer.ModeMultiple
Case "Pause"
player.Pause()
Me.Caption = "Resume"
TimeTimer.Mode = Timer.ModeOff
Case "Resume"
player.Resume()
Me.Caption = "Pause"
TimeTimer.Mode = Timer.ModeMultiple
End Select
StopBtn.Enabled = True
Slider2.Value = player.Tempo
Timer1.Mode = Timer.ModeMultiple
End Sub
#tag EndEvent
#tag EndEvents
#tag Events StopBtn
#tag Event
Sub Action()
player.Stop
PlayBtn.Caption = "Play"
Me.Enabled = False
End Sub
#tag EndEvent
#tag EndEvents
#tag Events TimeLabel
#tag Event
Function MouseDown(X As Integer, Y As Integer) As Boolean
#pragma Unused X
#pragma Unused Y
Return True
End Function
#tag EndEvent
#tag Event
Sub MouseUp(X As Integer, Y As Integer)
Dim r As New REALbasic.Rect(0, 0, Me.Width, Me.Height)
Dim p As New REALbasic.Point(X, Y)
If r.Contains(p) Then
mFractionalSeconds = Not mFractionalSeconds
Self.Refresh(False)
End If
End Sub
#tag EndEvent
#tag EndEvents
#tag Events TimeTimer
#tag Event
Sub Action()
If UILock Then Return
TimeLabel.Text = FormatTime(Player.PlayTime, mFractionalSeconds) + "/" + FormatTime(Player.Duration, mFractionalSeconds)
End Sub
#tag EndEvent
#tag EndEvents
#tag Events Slider2
#tag Event
Sub ValueChanged()
player.Tempo = Me.Value
End Sub
#tag EndEvent
#tag EndEvents
#tag Events DeviceList
#tag Event
Sub Open()
Dim c As Integer = Midi.Device.Count
For i As Integer = 0 To c - 1
Dim d As Midi.Device = Midi.Device.GetDevice(i)
Me.AddRow(d.Name)
Me.RowTag(Me.ListCount - 1) = d
Next
If Me.ListCount > 0 Then Me.ListIndex = 0
End Sub
#tag EndEvent
#tag Event
Sub Change()
If player = Nil Or player.IsPlaying Then Return
Dim err As Midi.ErrorCodes = Midi.SelectMidiDevice(Me.RowTag(Me.ListIndex))
If err <> Midi.ErrorCodes.None Then Break
End Sub
#tag EndEvent
#tag EndEvents
#tag Events EditBtn
#tag Event
Sub Action()
If Player <> Nil Then
Dim evntlst As New EventList
evntlst.LoadEvents(New Midi.EventSource(Player))
End If
End Sub
#tag EndEvent
#tag EndEvents