Later Once I get enough info on reading variable-length quantities I'll fnish making it also snatch the midi running events such as note on and note off and the other pitch wheel and sound control functions. IF there was a way to sync a midi to play at the same time as you could scan through the DETLA-TIME ticks ou could theoretically track midi position "but only in theory it would be impractile and wouldnt be very reliable" however this is a great start to a midi loader all in due time:
+ Code Snippetopen to read 1,"midifile.mid"
Header$=ByteChunk$(1,3)
print Header$
HeaderSize$=ByteHex$(1,3)
print HeaderSize$
MidiFormat$=ByteHex$(1,1)
print MidiFormat$
MidiTracks$=ByteHex$(1,1)
print MidiTracks$
DeltaTime$=ByteHex$(1,1)
print DeltaTime$
tracknex:
print
TrackHeader$=ByteChunk$(1,3)
print TrackHeader$
MidiData$=ByteHex$(1,3)
print MidiData$
recall:
Delta=Readvarlen(1)
`cls:print "DeltaTime - "+str$(Delta)
`For now lets not display anything but meta events
`until i figure out how to read the delta times
`enough to seprate the running commands from the delta times
aftercall:
Dat$=ByteHex$(1,0)
if Dat$="FF " then goto metaevent:
goto recall:
`---------------- MIDI META EVENTS ----------------------------
metaevent:
Print "Midi Meta Event FF:"
Cmd$=ByteHex$(1,0):TrackGo=0:print cmd$
if Cmd$="00 "
print "Set Sequence Number (00)":Lng$=ByteHex$(1,0)
print "Parameter Length:"+Lng$:Para$=ByteHex$(1,1)
print "Parameters:"+Para$
endif
if Cmd$="03 "
print "Sequence Or Track Name (03)":Lng$=ByteHex$(1,0)
print "Parameter Length:"+Lng$:TxtBytes=HexVal(Lng$)
Para$=ByteChunk$(1,TxtBytes-1)
print "Name:"+Para$
endif
if Cmd$="04 "
print "Track Instrument Name (04)":Lng$=ByteHex$(1,0)
print "Parameter Length:"+Lng$:TxtBytes=HexVal(Lng$)
Para$=ByteChunk$(1,TxtBytes-1)
print "Name:"+Para$
endif
if Cmd$="51 "
print "Set Tempo (51)":Lng$=ByteHex$(1,0)
print "Parameter Length:"+Lng$:Para$=ByteHex$(1,2)
print "Parameters:"+Para$
endif
if Cmd$="58 "
print "Time Singature (58)":Lng$=ByteHex$(1,0)
print "Parameter Length:"+Lng$:Para$=ByteHex$(1,3)
print "Parameters:"+Para$
endif
if Cmd$="59 "
print "Key Singature (59)":Lng$=ByteHex$(1,0)
print "Parameter Length:"+Lng$:Para$=ByteHex$(1,1)
print "Parameters:"+Para$
endif
if Cmd$="2F "
print "End Track (2F)":Lng$=ByteHex$(1,0)
print "Parameter Length:"+Lng$:TrackGo=1
endif
wait key:cls
if TrackGo=1 then goto tracknex:
goto recall:
`-------------------------------------------------------------------------
function ByteChunk$(Filenumber,Chunklength)
tmp$=""
for i=0 to Chunklength
read byte Filenumber,N
tmp$=tmp$+chr$(N)
next i
endfunction tmp$
function ByteHex$(Filenumber,Chunklength)
tmp$=""
for i=0 to Chunklength
read byte Filenumber,N
if len(Hex$(N))=1 then fore$="0"+Hex$(N) else fore$=Hex$(N)
tmp$=tmp$+fore$+" "
next i
endfunction tmp$
function HexVal(hexnum$)
if len(hexnum$)=1 then h$="0"+hexnum$:hexnum$=h$
NYBBLE$=mid$(hexnum$,1):V=0
if val(NYBBLE$)>0 then V=Val(NYBBLE$)
if NYBBLE$="A" then V=10
if NYBBLE$="B" then V=11
if NYBBLE$="C" then V=12
if NYBBLE$="D" then V=13
if NYBBLE$="E" then V=14
if NYBBLE$="F" then V=15
NYBBLE$=mid$(hexnum$,2):V2=V*16:V=0
if val(NYBBLE$)>0 then V=Val(NYBBLE$)
if NYBBLE$="A" then V=10
if NYBBLE$="B" then V=11
if NYBBLE$="C" then V=12
if NYBBLE$="D" then V=13
if NYBBLE$="E" then V=14
if NYBBLE$="F" then V=15
endfunction V2+V
function Readvarlen(Filenumber)
read byte Filenumber,value
if value & hexval("80")
value=value & hexval("7F")
while (c & hexval("80"))
read byte Filenumber,c
value=(BSL(value,7) + (c & hexval("7F")))
endwhile
endif
endfunction value
function BSL(Initial,ShiftAmount)
ANW=Initial*(2^ShiftAmount)
endfunction ANW
function MSB(H$)
if HexVal(H$)>128 then toggle=1 else toggle=0
endfunction toggle