haha! its funny cause the source for qmidi is starting to get realy messy....but strangly it still works
ok some code then explained:
dim devname$(4)
dim t_c(250)
dim music(7000,10,27,3)
dim instrument(10)
dim vol(10)
dim pan1(10)
dim modual1(10)
dim mutes(10)
dim oct(10)
dim pitch(7000,10)
dim sustain(10)
for x=1 to 10
vol(x)=48
pan1(x)=3
oct(x)=0
mutes(x)=0
next x
Thats some dims...
updateplay:
bpm=val(getgadgettext(ed3))
if bpm>250 then bpm=250:setgadgettext ed3,"250"
if bpm<1 then bpm=1:setgadgettext ed3,"1"
temp#=t_c(bpm)
if tmdelay#+temp#=>timer() then return
left_over#=timer()-tmdelay#
left_over#=left_over#-temp#
tmdelay#=timer():`-left_over#:
qrepeat=getchecked(rept)
size=val(getgadgettext(ed5))
if playbar>size then playing=0:
if playing=0 and qrepeat=1 then playing=1:playbar=0:`if getchecked(rep2)=1 then setscrollbarposition sbar,0
if playing=0 then gosub offnotes:return
for x=1 to 120
for t=1 to 10
octave=oct(t)
if playin(x,t,0)=1 then playin(x,t,1)=playin(x,t,1)-1:if playin(x,t,1)=<0 then midi note off midi,x-1+(octave*12),t:playin(x,t,0)=0:playin(x,t,1)=0:
next t
next x
if pitch(playbar,0)<>0 then setgadgettext ed3,str$(pitch(playbar,0))
for x=1 to 10
if x=recon and rec=1 then goto skmute1
if mutes(x)=1 then goto skmute1
if music(playbar,x,0,3)>4 then vol(x)=music(playbar,x,0,3)/2
vol=vol(x)
vol=vol+vol
set channel volume midi,x,vol
modual1(x)=music(playbar,x,1,3)/2
modu=modual1(x)
modu=modu+modu
set modwheel midi,x,modu
set midi instrument midi,x,instrument(x)
octave=oct(x)
panboy=music(playbar,x,2,3)
if panboy=4 then set channel pan midi,x,64
if panboy=7 then set channel pan midi,x,128
if panboy=1 then set channel pan midi,x,0
if panboy=2 then set channel pan midi,x,22
if panboy=3 then set channel pan midi,x,43
if panboy=5 then set channel pan midi,x,85
if panboy=6 then set channel pan midi,x,106
if pitch(playbar,x)=1 then w=10:set pitch midi,x,84
if pitch(playbar,x)=2 then w=30:set pitch midi,x,44
if pitch(playbar,x)=0 then set pitch midi,x,64
if pitch(playbar,x)=3 then set sustain pedal midi,x,1
if pitch(playbar,x)=4 then set sustain pedal midi,x,0
for y=0 to 27
if music(playbar,x,y,0)=1 then midi note off midi,music(playbar,x,y,2)+(octave*12),x:midi note on midi,music(playbar,x,y,2)-1+(octave*12),x,100:playin(music(playbar,x,y,2),x,1)=16:playin(music(playbar,x,y,2),x,0)=1
if music(playbar,x,y,0)=2 then midi note off midi,music(playbar,x,y,2)+(octave*12),x:midi note on midi,music(playbar,x,y,2)-1+(octave*12),x,100:playin(music(playbar,x,y,2),x,1)=8:playin(music(playbar,x,y,2),x,0)=1
if music(playbar,x,y,0)=3 then midi note off midi,music(playbar,x,y,2)+(octave*12),x:midi note on midi,music(playbar,x,y,2)-1+(octave*12),x,100:playin(music(playbar,x,y,2),x,1)=4:playin(music(playbar,x,y,2),x,0)=1
if music(playbar,x,y,0)=4 then midi note off midi,music(playbar,x,y,2)+(octave*12),x:midi note on midi,music(playbar,x,y,2)-1+(octave*12),x,100:playin(music(playbar,x,y,2),x,1)=2:playin(music(playbar,x,y,2),x,0)=1
if music(playbar,x,y,0)=5 then midi note off midi,music(playbar,x,y,2)+(octave*12),x:midi note on midi,music(playbar,x,y,2)-1+(octave*12),x,100:playin(music(playbar,x,y,2),x,1)=1:playin(music(playbar,x,y,2),x,0)=1
next y
skmute1:
next x
playbar=playbar+1
sync
return
offnotes:
for x=1 to 10
set sustain pedal midi,x,0
for y=1 to 120
midi note off midi,y,x
next y
next x
return
So that was the main play function to see how all that works
and now the file format:
loadsong:
cd getappdir$()
if quickld$<>"" then file$=quickld$:goto skipny
file$=""
file$=opendialog("Open Midi Song","Qmidi... [*.QMO]|*.qmo",0,".")
skipny:
if file$="" then return
`if right$(file$,3)="mid" then message "This format will be available soon... Please load using the regular format for now until i resolve a few midi issues":goto loadsong
`if right$(file$,3)="qmo" then goto loadsong2
cls
set cursor 10,150,:print "Loading Song......please wait"
sync
`reg format
if file exist(file$)=0 then return
gosub resetall
open to read 1,file$
size=val(getgadgettext(ed5))
read string 1,dumby$:if dumby$="QMIDI 1.1" then goto newload
if dumby$="QMIDI 1.5" then goto newload5
return
gosub resetall
read long 1,size:setgadgettext ed5,str$(size)
read long 1,tempo:setgadgettext ed3,str$(tempo)
for x=1 to 10
read long 1,oct(x)
next x
for x=0 to size
for y=0 to 10
read byte 1,pitch(x,y)
next y
next x
lm22:
read byte 1,s:if s=98 then goto lm23
read long 1,x:read byte 1,t:read byte 1,y:read byte 1,music(x,y,t,3)
goto lm22
lm23:
do
read byte 1,qq
if qq=0 then read long 1,x:read byte 1,y:read byte 1,t:read byte 1,music(x,t,y,0):read byte 1,music(x,t,y,1):read byte 1,music(x,t,y,2):
if qq=1 then goto nexsk
loop
nexsk:
rem fix glitch
for x=0 to size
for t=1 to 10
for b=0 to 2
if music(x,t,27,b)<>0 then music(x,t,0,b)=music(x,t,27,b):music(x,t,27,b)=0
next b
next t
next x
rem end fix glitch
for x=1 to 10
read byte 1,instrument(x)
read byte 1,vol(x)
read byte 1,pan1(x)
read byte 1,modual1(x)
next x
read long 1,b:setchecked lock1,b
read long 1,b:setchecked lock2,b
local fileText as string=""
for i=0 to 10
read string 1,tmp$
if fileText=""
fileText=tmp$
else
fileText=fileText+chr$(13)+chr$(10)+tmp$
endif
if file end(1) : i=10 : else : i=0 : endif
next i
setGadgetText copyedt,fileText
close file 1
if getchecked(lock1)=1 then setgadgetenabled copyedt,0 else setgadgetenabled copyedt,1
if getchecked(lock1)=1 then setgadgetenabled lock1,0 else setgadgetenabled lock1,1
settrackbarposition trackedt,1
settrackbarposition pan,pan1(1)
settrackbarposition vol1,vol(1)
settrackbarposition modul,modual1(1)
settrackbarposition trackins,instrument(1)
activetrack=1
setgadgettext insname,names$(instrument(1))
setgadgettext boxinfo,str$(instrument(1))
playbar=0
page=0
setgadgettext ed4,"1"
setgadgetenabled lock2,1
setgadgetenabled frametracks,1
`for x=1 to 10
`oct(x)=0
`next x
return
resetall:
playbar=0
page=1
setgadgettext ed4,"1"
setgadgettext ed5,"63"
for x=0 to 7000
for y=0 to 10
pitch(x,y)=0
next y
next x
pitch(0,0)=60
for x=0 to 7000
for y=0 to 27
for t=1 to 10
for b=0 to 3
music(x,t,y,b)=0
next b
next t
next y
next x
for x=1 to 10
mutes(x)=0
instrument(x)=1
vol(x)=48
pan1(x)=3
modual1(x)=0
sustain(x)=0
set midi instrument midi,x,1
next x
settrackbarposition trackins,1
settrackbarposition vol1,48
settrackbarposition sust,0
setgadgetenabled copyedt,1
setgadgettext copyedt,"Copyright Notices / Author Here"
setgadgetenabled lock1,1
setchecked lock1,0
setgadgetenabled lock2,1
setchecked lock2,0
setgadgetenabled frametracks,1
for x=0 to 64:for y=0 to 27:for z=0 to 3
copy(x,y,z)=0
next z
next y
next x
for x=1 to 10
oct(x)=0
next x
setgadgettext boxinfo,str$(instrument(1))
setgadgettext insname,names$(instrument(1))
setgadgettext ed3,"60"
for x=0 to 7000
for y=0 to 10
music(x,y,2,3)=4
next y
next x
return
sorry its alot of code to look at but you can key in on how the files written and played.
also the files are kinda big..... i didnt do much to keep the file sizes down....oh well
any questions about it of coarse ask! lol
Im expecting allot of questions since my coding skills are crap!
SMD3DInteractive