BASS and MaxGUI
BlitzMax Forums/Brucey's Modules/BASS and MaxGUI
| ||
| Brucey (or anybody who can help), Can you post an example of playing music with BASS and tracking the position with a MaxGUI slider? I would greatly appreciate it if you could help. Thanks! |
| ||
| Have a look at example 5 in the BASS examples folder. In this example it is "drawing" a slider to match the current position, but the idea is the same. You could set the Slider position/value instead. The same goes for the example where it changes the track position by pressing a number (0-6). You could catch a Slider change event and have it change the current track position. Not an exact example, but it shows everything you would need to do otherwise. :o) |
| ||
The application keeps freezing when I try to set the slider range. What am I doing wrong?Strict
Import maxgui.drivers
Import bah.bass
If Not TBass.Init(-1,44100,0,Null,Null)
Print "Unable to start BASS."
End
EndIf
Global file:TStream=ReadStream("music.mp3")
Global song:TBassStream=New TBassStream.CreateTStream(file,0,0)
If Not song End
Global window:TGadget=CreateWindow(AppTitle,0,0,640,480,Null)
Global slider:TGadget=CreateSlider(10,10,ClientWidth(window)-20,24,window,SLIDER_HORIZONTAL|SLIDER_TRACKBAR)
Global songlength:Long=song.GetLength(BASS_POS_BYTE)
SetSliderRange(slider,1,songlength)
Repeat
WaitEvent()
Select EventID()
Case event_windowclose
Select EventSource()
Case window
TBass.Free()
End
EndSelect
EndSelect
Forever |
| ||
| My first guess is that "songlength" is too large for SetSliderRange. In fact, since that function takes Ints, it's possible that it is casting it into a negative Int. You might need to scale the number down into something more managable. |
| ||
Thanks, Brucey! I got it working! Here's the code, just in case anybody wants to see how I did it:Strict
Import maxgui.win32maxgui
Import bah.bass
If Not TBass.Init(-1,44100,0,Null,Null)
Print "Unable to start BASS."
End
EndIf
Global file:TStream=ReadStream("music.mp3")
Global song:TBassStream=New TBassStream.CreateTStream(file,0,0)
If Not song End
Global window:TGadget=CreateWindow(AppTitle,0,0,640,480,Null)
Global slider:TGadget=CreateSlider(10,10,ClientWidth(window)-20,24,window,SLIDER_HORIZONTAL|SLIDER_TRACKBAR)
SetGadgetSensitivity(slider,SENSITIZE_MOUSE)
Global l:Long=song.GetLength(BASS_POS_BYTE)
Global songlength:Int=song.Bytes2Seconds(l)
Print Float(songlength/60)+" Minutes"
SetSliderRange(slider,1,songlength)
song.play(True)
Global updatetimer=MilliSecs()
Repeat
PollEvent()
Select EventID()
Case event_windowclose
Select EventSource()
Case window
TBass.Free()
End
EndSelect
Case event_mouseup
Select EventSource()
Case slider
Local v:Int=SliderValue(slider)
Local pos:Long=song.Seconds2Bytes(v)
song.SetPosition(pos,BASS_POS_BYTE)
EndSelect
EndSelect
If MilliSecs()>updatetimer+1000
Local pos:Long=song.GetPosition(BASS_POS_BYTE)
Local songpos:Int=song.Bytes2Seconds(pos)
SetSliderValue(slider,songpos)
updatetimer=MilliSecs()
EndIf
Forever |