Code: Alles auswählen
EnableExplicit
;Die Bass.dll für Einsteiger
;Gib mir BASS !!!
IncludeFile "bass.pbi"
;- Prototype Macros
Macro GetFunctionProtoQuote
"
EndMacro
Macro GetFunctionProto(dll, name)
Global name.name
name = GetFunction(dll, GetFunctionProtoQuote#name#GetFunctionProtoQuote)
CompilerIf #PB_Compiler_Debugger ; Only enable assert in debug mode
If name = #Null
Debug "Assert on line " + #PB_Compiler_Line + ", GetFunction(" + GetFunctionProtoQuote#dll#GetFunctionProtoQuote + ", " + GetFunctionProtoQuote#name#GetFunctionProtoQuote + ")"
EndIf
CompilerEndIf
EndMacro
; BASS_Load_Library
Threaded _BASS_Load_Library_DLL_.i
Procedure BASS_Free_Library()
If IsLibrary(_BASS_Load_Library_DLL_)
CloseLibrary(_BASS_Load_Library_DLL_)
EndIf
EndProcedure
Procedure.i BASS_Load_Library(dllpath$)
Protected dll.i, result.i
If IsLibrary(_BASS_Load_Library_DLL_)
ProcedureReturn #False
EndIf
_BASS_Load_Library_DLL_ = OpenLibrary(#PB_Any, dllpath$)
dll = _BASS_Load_Library_DLL_
If IsLibrary(dll) = #False
ProcedureReturn #False
EndIf
GetFunctionProto(dll, BASS_GetVersion)
If BASS_GetVersion = #Null
;BASS_GetVersion() not found, is this really bass.dll ?
BASS_Free_Library()
ProcedureReturn #False
EndIf
;Make sure BASS API and bass.dll are compatible.
result = BASS_GetVersion()
If (result & $FFFF0000) <> (#BASSVERSION & $FFFF0000) Or (result < #BASSVERSION)
BASS_Free_Library()
ProcedureReturn #False
EndIf
;You should only use the GetFunctionProto() for the BASS functions you actually need/use,
;these are macros thus you will save some memory/exe size by removing the functions you don't use,
;during debugging the GetFunctionProto() macro will also check if the BASS function exists in the loaded library to catch wrong library versions.
GetFunctionProto(dll, BASS_SetConfig)
GetFunctionProto(dll, BASS_GetConfig)
GetFunctionProto(dll, BASS_SetConfigPtr)
GetFunctionProto(dll, BASS_GetConfigPtr)
GetFunctionProto(dll, BASS_ErrorGetCode)
GetFunctionProto(dll, BASS_GetDeviceInfo)
GetFunctionProto(dll, BASS_Init)
GetFunctionProto(dll, BASS_SetDevice)
GetFunctionProto(dll, BASS_GetDevice)
GetFunctionProto(dll, BASS_Free)
;GetFunctionProto(dll, BASS_GetDSoundObject)
GetFunctionProto(dll, BASS_GetInfo)
GetFunctionProto(dll, BASS_Update)
GetFunctionProto(dll, BASS_GetCPU)
GetFunctionProto(dll, BASS_Start)
GetFunctionProto(dll, BASS_Stop)
GetFunctionProto(dll, BASS_Pause)
GetFunctionProto(dll, BASS_SetVolume)
GetFunctionProto(dll, BASS_GetVolume)
GetFunctionProto(dll, BASS_PluginLoad)
GetFunctionProto(dll, BASS_PluginFree)
GetFunctionProto(dll, BASS_PluginGetInfo)
GetFunctionProto(dll, BASS_Set3DFactors)
GetFunctionProto(dll, BASS_Get3DFactors)
GetFunctionProto(dll, BASS_Set3DPosition)
GetFunctionProto(dll, BASS_Get3DPosition)
GetFunctionProto(dll, BASS_Apply3D)
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
GetFunctionProto(dll, BASS_SetEAXParameters)
GetFunctionProto(dll, BASS_GetEAXParameters)
CompilerEndIf
GetFunctionProto(dll, BASS_MusicLoad)
GetFunctionProto(dll, BASS_MusicFree)
GetFunctionProto(dll, BASS_SampleLoad)
GetFunctionProto(dll, BASS_SampleCreate)
GetFunctionProto(dll, BASS_SampleFree)
GetFunctionProto(dll, BASS_SampleSetData)
GetFunctionProto(dll, BASS_SampleGetData)
GetFunctionProto(dll, BASS_SampleGetInfo)
GetFunctionProto(dll, BASS_SampleSetInfo)
GetFunctionProto(dll, BASS_SampleGetChannel)
GetFunctionProto(dll, BASS_SampleGetChannels)
GetFunctionProto(dll, BASS_SampleStop)
GetFunctionProto(dll, BASS_StreamCreate)
GetFunctionProto(dll, BASS_StreamCreateFile)
GetFunctionProto(dll, BASS_StreamCreateURL)
GetFunctionProto(dll, BASS_StreamCreateFileUser)
GetFunctionProto(dll, BASS_StreamFree)
GetFunctionProto(dll, BASS_StreamGetFilePosition)
GetFunctionProto(dll, BASS_StreamPutData)
GetFunctionProto(dll, BASS_StreamPutFileData)
GetFunctionProto(dll, BASS_RecordGetDeviceInfo)
GetFunctionProto(dll, BASS_RecordInit)
GetFunctionProto(dll, BASS_RecordSetDevice)
GetFunctionProto(dll, BASS_RecordGetDevice)
GetFunctionProto(dll, BASS_RecordFree)
GetFunctionProto(dll, BASS_RecordGetInfo)
GetFunctionProto(dll, BASS_RecordGetInputName)
GetFunctionProto(dll, BASS_RecordSetInput)
GetFunctionProto(dll, BASS_RecordGetInput)
GetFunctionProto(dll, BASS_RecordStart)
GetFunctionProto(dll, BASS_ChannelBytes2Seconds)
GetFunctionProto(dll, BASS_ChannelSeconds2Bytes)
GetFunctionProto(dll, BASS_ChannelGetDevice)
GetFunctionProto(dll, BASS_ChannelSetDevice)
GetFunctionProto(dll, BASS_ChannelIsActive)
GetFunctionProto(dll, BASS_ChannelGetInfo)
GetFunctionProto(dll, BASS_ChannelGetTags)
GetFunctionProto(dll, BASS_ChannelFlags)
GetFunctionProto(dll, BASS_ChannelUpdate)
GetFunctionProto(dll, BASS_ChannelLock)
GetFunctionProto(dll, BASS_ChannelPlay)
GetFunctionProto(dll, BASS_ChannelStop)
GetFunctionProto(dll, BASS_ChannelPause)
GetFunctionProto(dll, BASS_ChannelSetAttribute)
GetFunctionProto(dll, BASS_ChannelSetAttributeEx)
GetFunctionProto(dll, BASS_ChannelGetAttribute)
GetFunctionProto(dll, BASS_ChannelGetAttributeEx)
GetFunctionProto(dll, BASS_ChannelSlideAttribute)
GetFunctionProto(dll, BASS_ChannelIsSliding)
GetFunctionProto(dll, BASS_ChannelSet3DAttributes)
GetFunctionProto(dll, BASS_ChannelGet3DAttributes)
GetFunctionProto(dll, BASS_ChannelSet3DPosition)
GetFunctionProto(dll, BASS_ChannelGet3DPosition)
GetFunctionProto(dll, BASS_ChannelGetLength)
GetFunctionProto(dll, BASS_ChannelSetPosition)
GetFunctionProto(dll, BASS_ChannelGetPosition)
GetFunctionProto(dll, BASS_ChannelGetLevel)
GetFunctionProto(dll, BASS_ChannelGetLevelEx)
GetFunctionProto(dll, BASS_ChannelGetData)
GetFunctionProto(dll, BASS_ChannelSetSync)
GetFunctionProto(dll, BASS_ChannelRemoveSync)
GetFunctionProto(dll, BASS_ChannelSetDSP)
GetFunctionProto(dll, BASS_ChannelRemoveDSP)
GetFunctionProto(dll, BASS_ChannelSetLink)
GetFunctionProto(dll, BASS_ChannelRemoveLink)
GetFunctionProto(dll, BASS_ChannelSetFX)
GetFunctionProto(dll, BASS_ChannelRemoveFX)
GetFunctionProto(dll, BASS_FXSetParameters)
GetFunctionProto(dll, BASS_FXGetParameters)
GetFunctionProto(dll, BASS_FXReset)
ProcedureReturn #True
EndProcedure
If BASS_Load_Library("bass.dll") = #False
Debug "bass.dll kann nicht geladen werden."
End
EndIf
;- Hier geht es los!
;Wir legen ein Bass-Handle fest.
Global Handle
Global key.s ;ANY KEY ;)
Global apos, ppos ;Abspielposition
Global volume.f = 0.5 ;Lautstärke
Global balance.f = 0 ;Balance
Global active, ende
Global Filename.s = ""
;Wir sagen mal Hallo und legen unsere Grundeinstellungen fest.
BASS_Init(-1,44100,#BASS_DEVICE_3D,#Null,#Null)
;BASS_Apply3D()
BASS_SetConfig(#BASS_CONFIG_UNICODE, #True)
;Wir legen die globale Abspiellautstärke fest.
BASS_SetVolume(50)
;Falls hier mysteriöser Weise schon ein Handle existiert.
BASS_StreamFree(Handle)
Procedure RenderMenu()
ConsoleLocate(0,0)
ConsoleColor(5,15)
ClearConsole()
PrintN("Bass-Musikplayer")
PrintN("::::::::::::::::")
PrintN("1 = Musikdatei oeffnen")
PrintN("2 = Musikdatei abspielen")
PrintN("3 = Musikdatei pausieren")
PrintN("4 = Musikdatei stoppen")
PrintN("5 = Musikdatei vorspulen")
PrintN("6 = Musikdatei zurueckspulen")
PrintN("7 = Lautstaerke verringern")
PrintN("8 = Lautstaerke erhoehen")
PrintN("9 = Balance erhoehen (Links)")
PrintN("0 = Balance erhoehen (Rechts)")
PrintN("")
EndProcedure
Procedure RenderSoundInfo()
Protected fPos, ePos, aktSec.d, aktMin.d = 0, eTime.d, aktTime.s, endTime.s
;Infos anzeigen:
If Handle
fPos = BASS_ChannelGetPosition(Handle, #BASS_POS_BYTE)
ePos = BASS_ChannelGetLength(Handle, #BASS_POS_BYTE)
aktSec = BASS_ChannelBytes2Seconds(Handle, fPos)
eTime = BASS_ChannelBytes2Seconds(Handle, ePos)
aktMin = Int(aktSec / 60)
aktSec = Int(Mod(aktSec, 60))
If aktSec < 10
aktTime = StrD(aktMin) + ":" + "0" + StrD(aktSec)
Else
aktTime = StrD(aktMin) + ":" + StrD(aktSec)
EndIf
If Int(Mod(eTime, 60)) < 10
endTime = StrD(Int(eTime / 60)) + ":" + "0" + StrD(Int(Mod(eTime, 60)))
Else
endTime = StrD(Int(eTime / 60)) + ":" + StrD(Int(Mod(eTime, 60)))
EndIf
ConsoleLocate(0, 15)
PrintN("Datei: " + GetFilePart(Filename))
PrintN("Musik-Position: " + aktTime + " Min / " + endTime + " Min")
PrintN("")
If balance > 0.0
PrintN("Balance: +"+StrF(balance,1))
ElseIf balance <= 0.0
PrintN("Balance: "+StrF(balance,1))
EndIf
PrintN("Lautstaerke: "+StrF(Abs(volume),1))
PrintN("")
EndIf
EndProcedure
Procedure.s OpenMusic()
ProcedureReturn OpenFileRequester("","","Musik|*.mp3;*.wav",0)
EndProcedure
OpenConsole()
EnableGraphicalConsole(1)
RenderMenu()
Repeat
key = Inkey()
If key = Chr(49) ;Musik laden
Filename = OpenMusic()
BASS_ChannelStop(Handle)
BASS_StreamFree(Handle)
Handle = BASS_StreamCreateFile(#False, UTF8(Filename), 0, 0, 0)
If Handle
BASS_ChannelGetAttribute(Handle, #BASS_ATTRIB_VOL, @volume) ;Wir bekommen die aktuelle Lautstärke
BASS_ChannelGetAttribute(Handle, #BASS_ATTRIB_PAN, @balance); Wir bekommen die Lautsprecher-Balance
active = #True
Else
active = #False
EndIf
RenderMenu()
ElseIf key = Chr(50) And active = #True ;Musik abspielen
If Handle
BASS_ChannelPlay(Handle,0)
EndIf
ElseIf key = Chr(51) And active = #True ;Musik pausieren
If Handle
BASS_ChannelPause(Handle)
EndIf
ElseIf key = Chr(52) And active = #True ;Musik stoppen
If Handle
BASS_ChannelStop(Handle)
BASS_ChannelSetPosition(Handle, 0, #BASS_POS_BYTE)
EndIf
ElseIf key = Chr(53) And active = #True ;Musik vorspulen
If Handle
apos = BASS_ChannelGetPosition(Handle, #BASS_POS_BYTE)
ppos = BASS_ChannelSeconds2Bytes(Handle, 1)
BASS_ChannelSetPosition(Handle, (apos+ppos), #BASS_POS_BYTE)
EndIf
ElseIf key = Chr(54) And active = #True ;Musik zurueckspulen
If Handle
apos = BASS_ChannelGetPosition(Handle, #BASS_POS_BYTE)
ppos = BASS_ChannelSeconds2Bytes(Handle, 1)
BASS_ChannelSetPosition(Handle, (apos-ppos), #BASS_POS_BYTE)
EndIf
ElseIf key = Chr(55) And active = #True ;Lautstärke verringern
If Handle And volume > 0
volume = volume - 0.1
BASS_ChannelSetAttribute(Handle, #BASS_ATTRIB_VOL, Abs(volume))
EndIf
ElseIf key = Chr(56) And active = #True ;Lautstärke erhöhen
If Handle And volume < 1
volume = volume + 0.1
BASS_ChannelSetAttribute(Handle, #BASS_ATTRIB_VOL, Abs(volume))
EndIf
ElseIf key = Chr(57) And active = #True ;Balance erhöhen (Links)
If Handle And balance > -1
balance = balance - 0.1
BASS_ChannelSetAttribute(Handle, #BASS_ATTRIB_PAN, balance)
EndIf
ElseIf key = Chr(48) And active = #True ;Balance erhöhen (Rechts)
If Handle And balance < 1
balance = balance + 0.1
BASS_ChannelSetAttribute(Handle, #BASS_ATTRIB_PAN, balance)
EndIf
ElseIf key = Chr(27) ;Programm beenden
ende = #True
EndIf
RenderSoundInfo()
Until ende = #True
;Bass beenden!!!
BASS_Free()
CloseConsole()