Bass23

Blitz3D Forums/Blitz3D Userlibs/Bass23

Hmm.....hmmmmm..well i dont have a creative card....but here a first demo. Read the first lines. I you hear nothing download the 4mb soundfont from the (new) toolbox entry as shown.
http://www.blitzbasic.com/toolbox/toolbox.php?tool=207
(Dont forget to use "your" midifile.) Next will be a demo how to load soundfonts (a 30mb soundfont monster XD) and a tutorial how to work with midi_events (BASS_MIDI_StreamGetEvent).

@ .riKmAn. The BASS_ChannelGetTags command only returns tags, a midi file has only chunks. But the tutorial about StreamGetEvent will fix your problems in "some" hours.

; Important !!
; BASS use "a" default soundfont from "creative labs"  (like "CT4MGM.SF2") from the windows/system32 folder to
; play midi files. If you dont have a creative card or no compatible file is present, you can download one from the toolbox
; (http://www.blitzbasic.com/toolbox/toolbox.php?tool=207) and copy (unzip it)it into this folder 
; (windows/system32). To avoid any problems you can also "load" other soundfonts (see demo_soundfont.bb)

Include "includes\bass.bb"
Include "includes\bass_midi.bb" ;plugin

HWND = BASS_HWND() 
If Not BASS_Init(-1,44100,0,HWND,0) RuntimeError " Bass Init error"

midiplug = BASS_PluginLoad("bass_midi.dll",0)  ; load plugin for midi

Timer=CreateTimer (60)
Graphics 640,480,0,2
SetBuffer BackBuffer()		
Global vubar = LoadImage ("media\vumeter.png") 
MaskImage vubar,255,0,255
Global peakl, peakr
music  = BASS_MIDI_StreamCreateFile(0,"media\ff8piano.mid",0,0,0,0) ; we load a midi file

If Not BASS_ChannelPlay (music,0) RuntimeError "There was a problem" ; we play the file

While Not KeyHit (1) ; mainloop
Cls
Color 255,0,255
Text 0,0,"Bass midi demo (ESC to quit)"

time = BASS_ChannelGetPosition(music)
Text 0,20, "Position: " +time +" bytes"
Text 0,40, "Titel: 'Piano' from FinalFantasy 8"

; More visualisation ;)
Local vumono = BASS_ChannelGetLevel (music)
Local vuleft = BASS_MakeLoWord (vumono)
Local vuright = BASS_MakeHiWord (vumono)
Color 255,0,0
Text 0,170,"Left channel : "+vuleft
DrawImageRect vubar,0,200,0,0,vuleft/52,20
DrawImageRect vubar,0,240,0,0,vuright/52,20
Text 0,270,"Right channel : "+vuright
Color 255,255,0
peakl = peakl - 2
If peakl < (vuleft/52) Then peakl = vuleft/52
If peakl >350 Color 255,0,0
If peakl <150 Color 0,255,0
Rect peakl,200,3,20,1
Color 255,255,0
peakr = peakr - 2
If peakr < (vuright/52) Then peakr = vuright/52
If peakr >350 Then Color 255,0,0
If peakr <100 Then Color 0,255,0
Rect peakr,240,3,20,1
; end visualisation

WaitTimer Timer 
Flip 0
Wend

BASS_PluginFree(midiplug) ; unload plugin
BASS_Free() ; unload bass
End


Yes! I love vumeters. XD

BTW: You dont need BASS_update() , this is only used in some special cases if you want "force" updates of the engine. In 99% of cases the autoupdate function of bass is enought.

@hectic
1) There is no fast and easy way to get 1/100 seconds on playback. But i recommand to write a litle timer with millisecs after each second has started. So you can see in every frame the millisecs passed. If a new second starts, reset the counter. This will be more fast and makes only what is necessary. (You dont need 1000 or 100 steps if your framerate ist only 60). Else you must "force" updates with BASS_update and this is only cool if you have 100 or 1000 frames ;) )

2) You can get the sample rate of a playing channel with BASS_ChannelGetAttributes or BASS_ChannelGetInfo (with a Type). If you have problems with this pointers tell me and i will write a function. I you do so, feel free to post it so i can include it. (hehe)

Mery Chrismas. :)

PS: If someone wants the finalfantasy midi files (from FF1 to FF9), feel free to ask and i will upload them. ;)