October, 2003 -- all LB commands, no API calls!
'Alyce Watson, October, 2003
'
'LB4 features used:
'subs as event handlers
'on error
'global variables
'enable
'disable
'playmidi
'stopmidi
'midipos
if val(Version$)<4 then
notice "For LB4."
end
end if
NoMainWin
WindowWidth=300:WindowHeight=200
global file$ 'filename of current MIDI
file$=""
global howLong 'length of current MIDI
howLong=0
on error goto [handleError]
button #1.open, "Open",OpenFile,UL,10,10,130,30
button #1.exit, "Exit",QuitProg,UL,150,10,130,30
statictext #1.s, "Playing:",10,50,280,60
statictext #1.t, "Position:",10,120,280,60
Open "MIDI Player" for window as #1
#1 "trapclose Quit"
wait
sub OpenFile handle$
filedialog "Open MIDI","*.mid",fname$
file$=fname$
playmidi file$, howLong
#1.s "Playing: ";file$
#1.t "Length is ";howLong;". Position is ";midipos()
timer 1000, checkPlay
#handle$ "!disable" 'disable open button
end sub
sub checkPlay
#1.t "Length is ";howLong;". Position is ";midipos()
if howLong = midipos( ) then
stopmidi
timer 0
howLong = 0
#1.t "MIDI is finished."
#1.open "!enable"
end if
end sub
sub Quit handle$
close #handle$
if howLong>0 then stopmidi
end
end sub
sub QuitProg handle$
close #1
if howLong>0 then stopmidi
end
end sub
[handleError]
notice Err$
wait