MODBASS.DLL

Share your advanced PureBasic knowledge/code with the community.
darklordz
Enthusiast
Enthusiast
Posts: 119
Joined: Wed May 21, 2003 1:44 pm
Location: Netherlands
Contact:

MODBASS.DLL

Post by darklordz »

Code updated for 5.20+

for those that want it
to use wih the freeware bass.dll called modbass.dll v1.6 is the latest. just save it as modbass.pbi and include this in your pb projects... 8) ModBass is a 36 KB dll so it'll be a breeze to include in your projects...

Code: Select all

;-BASSMOD DLL Include v1.6

;-Constants
#BASS_DEVICE_8BITS    = 1   ;// Use 8 bit resolution, else 16 bit.
#BASS_DEVICE_MONO     = 2   ;// Use mono, else stereo.
#BASS_DEVICE_LEAVEVOL = 16  ;// Leave volume as it is. If this flag is not specified, then the volume will initially be set to 100 (max), and will be reset back to what it was when BASSMOD_Free is called.
#BASS_DEVICE_NOSYNC   = 32  ;// Disable synchronizers. If you are not using any syncs, then you may as well use this flag to save a little CPU time.

#BASS_ERROR_UNKNOWN  = -1   ;// Some other mystery error
#BASS_OK             = 0    ;//
#BASS_ERROR_MEM      = 1    ;// There is insufficent memory.
#BASS_ERROR_FILEOPEN = 2    ;// The file could not be opened.
#BASS_ERROR_DRIVER   = 3    ;// There is no available device driver. The device may already be in use.
#BASS_ERROR_HANDLE   = 5    ;// Invalid Handle
#BASS_ERROR_FORMAT   = 6    ;// The file's format is not recognised/supported.
#BASS_ERROR_POSITION = 7    ;// Position is invalid.
#BASS_ERROR_INIT     = 8    ;// BASSMOD_Init has not been successfully called. This error is also returned when trying to get the volume level of the no sound device.
#BASS_ERROR_ALREADY  = 14   ;// BASSMOD has already been initialized. You must call BASSMOD_Free before calling BASSMOD_Init again.
#BASS_ERROR_NOPAUSE  = 16   ;// The MOD music is not paused.
#BASS_ERROR_ILLTYPE  = 19   ;// An illegal type was specified.
#BASS_ERROR_ILLPARAM = 20   ;// The BASS_MUSIC_CALCLEN flag was not used with BASSMOD_MusicLoad, or the playback length could not be calculated (the music does not end).
#BASS_ERROR_DEVICE   = 23   ;// The device number specified is invalid.
#BASS_ERROR_NOPLAY   = 24   ;// The MOD music is not playing.
#BASS_ERROR_NOMUSIC  = 28   ;// A MOD music has not been loaded.
#BASS_ERROR_NOSYNC   = 30   ;// Synchronizers have been disabled

#BASS_MUSIC_LOOP      = 4           ;// Loop Music
#BASS_MUSIC_RAMP      = 1           ;// Use "normal" ramping (as used in FastTracker 2).
#BASS_MUSIC_RAMPS     = 2           ;// Use "sensitive" ramping
#BASS_MUSIC_FT2MOD    = 16          ;// Play .MOD file as FastTracker 2 would.
#BASS_MUSIC_PT1MOD    = 32          ;// Play .MOD file as ProTracker 1 would.
#BASS_MUSIC_POSRESET  = 256         ;// Stop all notes when moving position (using BASSMOD_MusicSetPosition or BASSMOD_MusicPlayEx).
#BASS_MUSIC_SURROUND  = 512         ;// Apply XMPlay's surround sound to the music (ignored in mono).
#BASS_MUSIC_SURROUND2 = 1024        ;// Apply XMPlay's surround sound mode 2 to the music (ignored in mono).
#BASS_MUSIC_STOPBACK  = 2048        ;// Stop the music when a backward jump effect is played. This stops musics that never reach the end from going into endless loops. Some MOD musics are designed to jump all over the place, so this flag would cause those to be stopped prematurely. If this flag is used together with the BASS_MUSIC_LOOP flag, then the music would not be stopped but any BASS_SYNC_END sync would be called.
#BASS_MUSIC_CALCLEN   = 8192        ;// Calculate the playback length of the music. This also slightly increases the time taken to load the music, depending on how long it is. Use BASSMOD_MusicGetLength to retrieve the calculated length. Note that it's not always possible to calculate a length because some musics never actually reach an end.
#BASS_MUSIC_NOSAMPLE  = $400000     ;// Don't load the music's samples. This slightly reduces the time taken to load the music, which is useful if you just want to get the name and length of the music without playing it.

#BASS_SYNC_POS        = 0           ;//
#BASS_SYNC_MUSICPOS   = 0           ;//
#BASS_SYNC_MUSICINST  = 1           ;//
#BASS_SYNC_END        = 2           ;//
#BASS_SYNC_MUSICFX    = 3           ;//
#BASS_SYNC_ONETIME    = 2147483648  ;//

#BASS_ACTIVE_STOPPED = 0  ;// The MOD music is not active.
#BASS_ACTIVE_PLAYING = 1  ;// The MOD music is playing.
#BASS_ACTIVE_PAUSED  = -1 ;// The MOD music is paused.

Procedure.w MAKEWORD(a.w,b.w)
  ProcedureReturn a | ($10000*b)
EndProcedure

Procedure.l HIWORD(a.l)
  ProcedureReturn Int(a / $10000)
EndProcedure

Procedure.l LOWORD(a.l)
  ProcedureReturn Int(a - (Int(a/$10000)*$10000))
EndProcedure

; Get the BASS_ERROR_xxx error code. Use this function to get the reason for an error.
Procedure.s _ErrorGetCode(hwnd)
  BASS_ERRORCODE.l=CallFunction(hwnd,"BASSMOD_ErrorGetCode")
  Select BASS_ERRORCODE
    Case #BASS_OK
      BASSMOD_GetErrorDescription.s = "All is OK"
    Case #BASS_ERROR_MEM
      BASSMOD_GetErrorDescription.s = "Memory Error"
    Case #BASS_ERROR_FILEOPEN
      BASSMOD_GetErrorDescription.s = "Can't Open the File"
    Case #BASS_ERROR_DRIVER
      BASSMOD_GetErrorDescription.s = "Can't Find a Free Sound Driver"
    Case #BASS_ERROR_HANDLE
      BASSMOD_GetErrorDescription.s = "Invalid Handle"
    Case #BASS_ERROR_FORMAT
      BASSMOD_GetErrorDescription.s = "Unsupported Format"
    Case #BASS_ERROR_POSITION
      BASSMOD_GetErrorDescription.s = "Invalid Playback Position"
    Case #BASS_ERROR_INIT
      BASSMOD_GetErrorDescription.s = "BASS_Init Has Not Been Successfully Called"
    Case #BASS_ERROR_ALREADY
      BASSMOD_GetErrorDescription.s = "Already Initialized"
    Case #BASS_ERROR_NOPAUSE
      BASSMOD_GetErrorDescription.s = "Not Paused"
    Case #BASS_ERROR_ILLTYPE
      BASSMOD_GetErrorDescription.s = "An Illegal Type Was Specified"
    Case #BASS_ERROR_ILLPARAM
      BASSMOD_GetErrorDescription.s = "An Illegal Parameter Was Specified"
    Case #BASS_ERROR_DEVICE
      BASSMOD_GetErrorDescription.s = "Illegal Device Number"
    Case #BASS_ERROR_NOPLAY
      BASSMOD_GetErrorDescription.s = "Not Playing"
    Case #BASS_ERROR_NOMUSIC
      BASSMOD_GetErrorDescription.s = "No Music"
    Case #BASS_ERROR_NOSYNC
      BASSMOD_GetErrorDescription.s = "No Sync Avaliable"
    Case #BASS_ERROR_UNKNOWN
      BASSMOD_GetErrorDescription.s = "Some Other Mystery Error"
  EndSelect
  If BASSMOD_GetErrorDescription.s = ""
    MessageRequester("Error","Error Description:"+Chr(13)+BASSMOD_GetErrorDescription.s,#MB_ICONERROR)
  EndIf
  ProcedureReturn BASSMOD_GetErrorDescription.s
EndProcedure

; Free all resources used by the digital output, including the MOD music.
Procedure.l _Free(hwnd)
  BASS_FREE.l=CallFunction(hwnd,"BASSMOD_Free")
  CloseLibrary(hwnd)
  ProcedureReturn BASS_FREE.l
EndProcedure

; Get the current CPU usage of BASSMOD To mix the MOD music.
; Return : The CPU usage percentage
Procedure.l _GetCPU(hwnd)
  BASS_GETCPU.f=CallFunction(hwnd,"BASSMOD_GetCPU")
  ProcedureReturn Int(BASS_GETCPU.f)
EndProcedure

; Get the text description of a device. This function can be used to enumerate the available devices.
; Device : The device (0=first)
; Return : The text description of the device (NULL=error)
Procedure.s _GetDeviceDescription(hwnd,device)
  BASS_GETDEVICEDISC.l=CallFunction(hwnd,"BASSMOD_GetDeviceDescription",device)
  If BASS_GETDEVICEDISC.l = 0 : Error.s = _ErrorGetCode(hwnd) : EndIf
  If BASS_GETDEVICEDISC<>0 : BASS_GETDEVICE.s= PeekS(BASS_GETDEVICEDISC) : EndIf
  ProcedureReturn BASS_GETDEVICE.s
EndProcedure

; Retrieve the version number of BASSMOD that is loaded.
; Return : The BASSMOD version (LOWORD.HIWORD)
Procedure.s _GetVersion(hwnd)
  BASSVERSION.l=CallFunction(hwnd,"BASSMOD_GetVersion")
  LOWWORD.s=Str(LOWORD(BASSVERSION)) : HIWORD.s=Str(HIWORD(BASSVERSION))
  BASS_VERSION.s=LOWWORD + "." + HIWORD
  ProcedureReturn BASS_VERSION.s
EndProcedure

; Retrieves the current volume level.
Procedure.l _GetVolume(hwnd)
  BASS_GETVOLUME.l=CallFunction(hwnd,"BASSMOD_GetVolume")
  ProcedureReturn BASS_GETVOLUME.l
EndProcedure

; Initialize the digital output. This must be called before all following BASSMOD functions.
; Device : Device To use (0=first, -1=default, -2=no sound)
; Freq   : Output sample rate
; Flags  : BASS_DEVICE_xxx flags
Procedure.l _Init(hwnd,DllLoc.s,Device.l,Freq.l,Flags.l)
  If OpenLibrary(hwnd,DllLoc.s)
    BASS_INIT.l = CallFunction(Hwnd,"BASSMOD_Init",Device.l,Freq.l,Flags.l)
  Else
    BASS_INIT.l = 0
  EndIf
  ProcedureReturn BASS_INIT.l
EndProcedure

; Free the music's resources.
Procedure.l _MusicFree(hwnd)
  BASS_MUSICFREE.l=CallFunction(hwnd,"BASSMOD_MusicFree")
  ProcedureReturn BASS_MUSICFREE.l
EndProcedure

; Retrieves the length of the music in patterns (how many "orders" there are) or in output bytes (requires BASS_MUSIC_CALCLEN was used with BASSMOD_MusicLoad).
; length : BASSTRUE=get the playback length, BASSFALSE=get the pattern length
; Return : The length of the music (-1=error)
Procedure.w _MusicGetLength(hwnd,length.l)
  BASS_GETMUSICLENGTH.w=CallFunction(hwnd,"BASSMOD_MusicGetLength",length.l)
  If BASS_GETMUSICLENGTH.w = -1 : Error.s = _ErrorGetCode(hwnd) : EndIf
  ProcedureReturn BASS_GETMUSICLENGTH.w
EndProcedure

; Retrieves the music's name.
; Return : The music's name (NULL=error)
Procedure.s _MusicGetName(hwnd)
  BASS_GETNAME.l=CallFunction(hwnd,"BASSMOD_MusicGetName")
  If BASS_GETNAME.l = 0 : Error.s = _ErrorGetCode(hwnd) : EndIf
  If BASS_GETNAME<>0 : BASS_MUSICGETNAME.s = PeekS(BASS_GETNAME) : EndIf
  ProcedureReturn BASS_MUSICGETNAME.s
EndProcedure

; Get the current playback position of the MOD music.
; Return : the position... LOWORD=order HIWORD=row (see BASSMOD_MusicSetPositionScaler)
; (-1=error)
Procedure.w _MusicGetPosition(hwnd)
  BASS_GETPOS.w=CallFunction(hwnd,"BASSMOD_MusicGetPosition")
  If BASS_GETPOS.w = -1 : Error.s = _ErrorGetCode(hwnd) : EndIf
  ProcedureReturn BASS_GETPOS.w
EndProcedure

; Checks if the MOD music is active (playing).
; The Return value is one of the folowing.
; BASS_ACTIVE_STOPPED The MOD music is not active.
; BASS_ACTIVE_PLAYING The MOD music is playing.
; BASS_ACTIVE_PAUSED The MOD music is paused.
Procedure _MusicIsActive(hwnd)
  BASS_ISACTIVE=CallFunction(hwnd,"BASSMOD_MusicIsActive")
  ProcedureReturn BASS_ISACTIVE
EndProcedure

; Load a music (XM/MOD/S3M/IT/MTM/UMX). The amplification And pan seperation are initially set To 50, use BASSMOD_MusicSetAmplify() And BASSMOD_MusicSetPanSep() To adjust them.
; mem    : TRUE = Load music from memory
; file   : Filename (mem=FALSE) Or memory location (mem=TRUE)
; offset : File offset to load the music from (only used if mem=FALSE)
; length : Data length (only used If mem=FALSE, 0=use To End of file)
; flags  : BASS_MUSIC_xxx flags
; Return : The loaded music's handle (NULL=error)
Procedure _MusicLoad(hwnd,mem,file.s,offset,length,flag)
  BASS_LOAD=CallFunction(hwnd,"BASSMOD_MusicLoad",mem,@file.s,offset,length,flag)
  If BASS_LOAD = 0 : Error.s = _ErrorGetCode(hwnd) : EndIf
  ProcedureReturn BASS_LOAD
EndProcedure

; Pause the MOD music. Use BASSMOD_MusicPlay To resume playback.
Procedure _MusicPause(hwnd)
  BASS_PAUSE=CallFunction(hwnd,"BASSMOD_MusicPause")
  ProcedureReturn BASS_PAUSE
EndProcedure

; Play the music. Playback continues from where it was last stopped/paused.
Procedure _MusicPlay(hwnd)
  BASS_PLAY=CallFunction(hwnd,"BASSMOD_MusicPlay")
  ProcedureReturn BASS_PLAY
EndProcedure

; Play the music, specifying start position And playback flags.
; pos    : Position To start playback from, LOWORD=order HIWORD=row
; flags  : BASS_MUSIC_xxx flags. These flags overwrite the defaults specified when the music was loaded. (-1=use current flags)
; reset  : TRUE = Stop all current playing notes And reset bpm/etc...
Procedure _MusicPlayEx(hwnd,pos.w,flags,reset)
  BASS_PLAYEX=CallFunction(hwnd,"BASSMOD_MusicPlayEx",pos.w,flags,reset)
  ProcedureReturn BASS_PLAYEX
EndProcedure

; Remove a sync from the music
; sync   : Handle of sync To remove
Procedure _MusicRemoveSync(hwnd,sync)
  BASS_REMOVESYNC= CallFunction(hwnd,"BASSMOD_MusicRemoveSync",sync)
  ProcedureReturn BASS_REMOVESYNC
EndProcedure

; Set the music's amplification level.
; amplify : Amplification level (0-100)
Procedure _MusicSetAmplify(hwnd,amplify)
  If amplify>100 : amplify=100 : EndIf
  BASS_SETAPMLIFY=CallFunction(hwnd,"BASSMOD_MusicSetAmplify",amplify)
  ProcedureReturn BASS_SETAPMLIFY
EndProcedure

; Set a music's pan seperation.
; pan    : Pan seperation (0-100, 50=linear)
Procedure _MusicSetPanSep(hwnd,pan)
  If Pan>100 : Pan=100 : EndIf
  BASS_SETPANSEP=CallFunction(hwnd,"BASSMOD_MusicSetPanSep",pan)
  ProcedureReturn BASS_SETPANSEP
EndProcedure

; Set the current playback position of the MOD music.
; pos    : LOWORD=order HIWORD=row ... use MAKELONG(order,row)
Procedure _MusicSetPosition(hwnd,order.w,row.w)
  LONGWORD.w= MAKEWORD(order.w,row.w)
  BASS_MUSICSETPOS=CallFunction(hwnd,"BASSMOD_MusicSetPosition",LONGWORD.w)
  ProcedureReturn BASS_MUSICSETPOS
EndProcedure

; Set the music's "GetPosition" scaler when you call BASSMOD_MusicGetPosition, the "row" (HIWORD) will be scaled by this value. By using a higher scaler, you can get a more precise position indication.
; scale  : The scaler (1-256)
Procedure _MusicSetPositionScaler(hwnd,scale)
  If scale>256 : scale=256 : EndIf
  BASS_MUSICSETPOSITIONSCALER=CallFunction(hwnd,"BASSMOD_MusicSetPositionScaler",scale)
  ProcedureReturn BASS_MUSICSETPOSITIONSCALER
EndProcedure

; Setup a sync on the music. Multiple syncs may be used.
; ptype   : Sync type (BASS_SYNC_xxx type & flags)
; param  : Sync parameters (see the BASS_SYNC_xxx type description)
; proc   : User defined callback function  (use AddressOf SYNCPROC)
; user   : The 'user' value passed To the callback function
; Return : Sync handle (NULL=error)
Procedure _MusicSetSync(hwnd,type.w,param.w,proc,user.w)
  BASS_MUSICSETSYNC=CallFunction(hwnd,"BASSMOD_MusicSetSync",type.w,param.w,proc,user.w)
  If BASS_MUSICSETSYNC = 0 : Error.s = _ErrorGetCode(hwnd) : EndIf
  ProcedureReturn BASS_MUSICSETSYNC
EndProcedure

; Stops the MOD music.If successful, TRUE is returned, else FALSE is returned
Procedure _MusicStop(hwnd)
  BASS_MUSICSTOP=CallFunction(hwnd,"BASSMOD_MusicStop")
  ProcedureReturn BASS_MUSICSTOP
EndProcedure

; Set the digital output master volume.
; Volume : Desired volume level (0-100)
; Get the digital output master volume.
; Return : The volume level (0-100, -1=error)
Procedure _SetVolume(hwnd,volume)
  If Volume>100 : Volume=100 : EndIf
  BASS_VOLUME=CallFunction(hwnd,"BASSMOD_SetVolume",volume)
  If BASS_VOLUME = -1 : Error.s = _ErrorGetCode(hwnd) : EndIf
  ProcedureReturn BASS_VOLUME
EndProcedure

Procedure SYNCPROC(hwnd,handle,datat.w,user.w)
  SYNCPROC=CallFunction(hwnd,"SYNCPROC",handle,datat.w,user.w)
  ProcedureReturn SYNCPROC
EndProcedure
Fash_FD
New User
New User
Posts: 3
Joined: Tue Jun 10, 2003 10:47 pm

bassmod :)

Post by Fash_FD »

No chance of a quick little replay example for us beginners >
:)
darklordz
Enthusiast
Enthusiast
Posts: 119
Joined: Wed May 21, 2003 1:44 pm
Location: Netherlands
Contact:

Post by darklordz »

Code: Select all

Global DLLHandle.l
Global InitDevice.l
Global InitFrequency.l
Global InitFlags.l

DLLHandle = 1
InitDevice = -1
InitFrequency = 44100
InitFlags = #BASS_DEVICE_NOSYNC | #BASS_DEVICE_LEAVEVOL

ProcedureDLL InitMod()
  Init_Bass=_Init(DLLHandle,"C:\Bassmod.dll",InitDevice,InitFrequency,InitFlags)
  If Init_Bass=0
    MessageRequester("Error Music Initialize","Cannot Initialize Sound Enviroment "+Str(Init_Bass),#MB_ICONERROR)
    ExitProg()
  EndIf
  
  _MusicLoad(DLLHandle,0,"Music.mod",0,0,#BASS_MUSIC_RAMP | #BASS_MUSIC_LOOP)
  _MusicPlay(DLLHandle)
EndProcedure

InitMod()
I have currently converted the bassmod.dll into a userlib. witch would mean that i would not have to use the call dll feature and give me the ability to use bassmod.dll functions from withing pb like it was built in....

im currently compiling an archive for this userlib with all needed files so that you can use them to, examples will be included....
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

darklordz wrote: I have currently converted the bassmod.dll into a userlib. witch would mean that i would not have to use the call dll feature and give me the ability to use bassmod.dll functions from withing pb like it was built in....
HOW? Which tool have you used ?

I am to provide the public with beneficial shocks.
Alfred Hitshock
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Where might I find some information on making userlibs in PB? either I'm blind or there isn't much out there!

(I'm very likely blind!)
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
WolfgangS
Enthusiast
Enthusiast
Posts: 174
Joined: Fri Apr 25, 2003 3:30 pm

Post by WolfgangS »

look in your \PureBasic\Library SDK folder.

MFG
WolfgangS
.:.mrbig.:.
New User
New User
Posts: 4
Joined: Mon Jul 14, 2003 8:52 pm

How to use it?

Post by .:.mrbig.:. »

hi, friends!, anyone can tell how to use BASSMOD.PBI or how to create it.
Please explain nice!, im are a beginner!.

I think in > code

> IncludeBinary("bassmod.dll") < but no work... :cry:

Thanks alot!
darklordz
Enthusiast
Enthusiast
Posts: 119
Joined: Wed May 21, 2003 1:44 pm
Location: Netherlands
Contact:

Post by darklordz »

Put the code n the first post into a pb file and save it as modbass.pb
then include "modbass.pb" in your file. Use the second example provided by me in this topic to play music. The demo's require bassmod.dll.....

All the code you need is right here....
Post Reply