BASS Question

BlitzMax Forums/Brucey's Modules/BASS Question

Ked(Posted 2008) [#1]
Hey, am I using BASS correctly?

Strict

Framework maxgui.win32maxgui
Import bah.bass
Import brl.directsoundaudio
Import brl.eventqueue

SetAudioDriver "directsound"

If Not tbass.init(-1,44100,0,Null,Null)
	End
EndIf

Local window:tgadget=CreateWindow("WINDOW",0,0,320,240,Desktop(),1+WINDOW_TOOL+WINDOW_CENTER)
Local playb:tgadget=CreateButton("Play",5,5,50,24,window)
Local stopb:tgadget=CreateButton("Stop",60,5,50,24,window)
Local openb:tgadget=CreateButton("Open",115,5,50,24,window)

Local stream:tbasschannel
Local playing:Int
Local active:Int
Local musicbass:Int=False

Repeat
	WaitEvent()
	Select EventID()
		Case event_windowclose
			Select EventSource()
				Case window
					tbass.free()
					End
			EndSelect
		
		Case event_gadgetaction
			Select EventSource()
				Case openb
					Local f:String=RequestFile("Open","MP3 Files:mp3")
					If f
						If playing=True
							stream.stop()
						EndIf
						stream=New tbassstream.CreateFile(f,0,0,0)
						If Not stream
							stream=New tbassmusic.fileload(f,0,0,BASS_MUSIC_RAMPS|BASS_MUSIC_PRESCAN,0)
							If Not stream
								tbass.free()
								End
							Else
								musicbass=True
							EndIf
						EndIf
						
						If Not stream.play(False)
							Notify "Cannot play!",True
							tbass.free()
							End
						EndIf
						
						playing=True
					EndIf
				
				Case stopb
					If stream.isactive()
						stream.stop()
					EndIf
				
				Case playb
					If stream
						stream.play()
					EndIf
						
			EndSelect
	EndSelect
	
	If playing=True
		If Not stream.isactive()
			playing=False
		EndIf
	EndIf
Forever



Ked(Posted 2008) [#2]
Could someone show me an example of getting and setting a song's position and displaying the position on a bar or something?


Brucey(Posted 2008) [#3]
On your channel object, you can use GetPosition(mode:int) to get the current position in bytes.
To convert that to seconds, you can use the Bytes2Seconds(pos:Long) method.


Ked(Posted 2008) [#4]
I know. I was just wondering if someone could show me some code where you can select where on a trackbar (CreateSlider(x,y,w,h,g,SLIDER_TRACKBAR|SLIDER_HORIZONTAL)) to skip around in the song.


Ked(Posted 2008) [#5]
How come there isn't a SetPosition method?


Brucey(Posted 2008) [#6]
Oversight, I would guess :-p

Anyhoo, if you get out the latest now it's in there. Also check out example 5 which demonstrates using it (press keys 0-5).


Ked(Posted 2008) [#7]
Sweet! Thanks, Brucey.