edit: correct a little error
WINAMP-PLUGINs
--------------
GPI 12.02.2003
IMPORTANT: The "Inline ASM" must aktivated or the program will crash!
Normaly the in-plugin send a #WM_WA_MPEG_EOF, if the file is played.
This message can be read with WindowEvent() and WaitWindowEvent().
return=Init_Winamp(in_dll$,out_dll$,WindowId)
--------------------------------------
must called befor you can use the other routines or the programm will crash!
return error
0 no error
-1 out_dll is no winamp-dll
-2 can't open out_dll
-3 in_dll is no winamp-dll
-4 can't open in_dll
Quit_Winamp()
-------------
end winamp.
return.s=Winamp_OutName()
-------------------------
return the name of the out-plugin.
Winamp_OutConfig(WindowId)
--------------------------
Open the config-dialog of the out-plugin.
Winamp_OutAbout(WindowId)
-------------------------
Open the about-dialog of the out-plugin.
return=Winamp_IsPlaying()
-------------------------
Return 0 if a sound is playing.
WARNING: This function checks only the state of the out-plugin. It is possible, that a in-plugin don't need the out-plugin. In this case the Winamp_IsPlaying() will always return 0.
return.s=Winamp_InName()
------------------------
Return the name of the in-plugin.
return=Winamp_isSeekable()
--------------------------
return 0, if a the in-plugin is seekable.
IMPORTANT: This check isn't alway right. For example the in_mp3.dll does say, that it isn't seekable. Ignore it.
return.s=Winamp_OnlyExtensions()
--------------------------------
Return all the supported mediafiles. ("*.mp1;*.mp2;*.mp3)
return.s=Winamp_Extensions()
----------------------------
Return the extentions and the type name of all supported mediafiles. Ready for use with OpenFileRequester and SaveFileRequester. ("Layer3 MPEG|*.mp3|Layer 2 MPEG|*.mp2|Layer 1 MPEG|*.mp1")
Winamp_InConfig(WindowId)
-------------------------
Open the config-dialog of the in-plugin.
Winamp_Inabout(WindowId)
------------------------
Open the about-dialog of the in-plugin.
return.s=Winamp_GetFileInfo(playfile$,@length_ms)
-------------------------------------------------
return the title of a file and the length in ms.
IMPORTANT: the function will overwrite the length_ms! Don't forget the @ or the program can crash.
Winamp_InfoBox(playfile$,WindowId)
----------------------------------
Open the file-info-dialog of the in-plugin. Not supported of all pluggins (=the will do nothing)
return=Winamp_IsOurFile(stream$)
--------------------------------
used For detecting URL streams
return=Winamp_Play(playfile$)
-----------------------------
Play the file. Return 0 if no error happend.
WARNING: When call Winamp_Play() again without stop the playing before, some in-plugin can crash. I insert a small test with Winamp_IsPlaying(), but if the in-plugin doesn't use the out-plugin the test is useless.
return=Winamp_IsPaused()
------------------------
Return 0 if paused.
Winamp_Pause()
--------------
First call pause the sound and the second call unpause it.
Winamp_Stop()
-------------
Stop playing.
WARNING: If no sound is playing, some plugin can crash.
return=Winamp_GetLength()
-------------------------
Returns the length of the playing file in ms.
return$=Winamp_LengthStr(length)
--------------------------------
Convert the length to a string. Format: "h:mm:ss".
Return=Winamp_GetOutputTime()
-----------------------------
Return the current playing position.
Winamp_SetOutputTime(length)
----------------------------
Set the playing position position. Not supported of all in-plugins. Also it can be very slow.
Winamp_SetVolume(volume)
------------------------
Set the volume (0 to 255)
Winamp_SetPan(pan)
------------------
Set the pan (left=-127 to 127=right)
winamp.pbi
Code: Select all
;***;*** Winamp-Pluginuser
;***
#WM_WA_MPEG_EOF=#WM_USER+2
#DLL_WINAMP_IN=100
#DLL_WINAMP_OUT=101
;-Structure
Structure winamp_out_module
version.l ;module version (OUT_VER)
*description.s ;description of module, with version string
id.l ;module id. each input module gets its own. non-nullsoft modules should be >= 65536.
hMainWindow.l ;winamp's main window (filled in by winamp)
hDllInstance.l ;DLL instance handle (filled in by winamp)
Config.l ;void (*Config)(HWND hwndParent); // configuration dialog
About.l ;void (*About)(HWND hwndParent); // about dialog
Init.l ;void (*Init)(); // called when loaded
Quit.l ;void (*Quit)(); // called when unloaded
Open.l ; Int (*Open)(int samplerate, int numchannels, int bitspersamp, int bufferlenms, int prebufferms);
; // returns >=0 on success, GetOutputTime()
SetOutputTime.l ;void (*SetOutputTime)(int time_in_ms); // seeks to point in stream (in ms). Usually you signal yoru thread to seek, which seeks and calls outMod->Flush()..
;volume stuff
SetVolume.l ;void (*SetVolume)(int volume); // from 0 to 255.. usually just call outMod->SetVolume
SetPan.l ;void (*SetPan)(int pan); // from -127 to 127.. usually just call outMod->SetPan
;in-window builtin vis stuff
SAVSAInit.l ;void (*SAVSAInit)(int maxlatency_in_ms, int srate);
; // call once in Play(). maxlatency_in_ms should be the value returned from outMod->Open()
; // call after opening audio device with max latency in ms And samplerate
SAVSADeInit.l ;void (*SAVSADeInit)(); // call in Stop()
;simple vis supplying mode
SAAddPCMData.l ;void (*SAAddPCMData)(void *PCMData, int nch, int bps, int timestamp);
; // sets the spec Data directly from PCM Data
; // quick And easy way To get vis working :)
; // needs at least 576 samples :)
;advanced vis supplying mode, only use If you're cool. Use SAAddPCMData for most stuff.
SAGetMode.l ; Int (*SAGetMode)(); // gets csa (the current type (4=ws,2=osc,1=spec))
; // use when calling SAAdd()
SAAdd.l ;void (*SAAdd)(void *data, int timestamp, int csa);
; // sets the spec data, filled in by winamp
;vis stuff (plug-in)
; simple vis supplying mode
VSAAddPCMData.l ;void (*VSAAddPCMData)(void *PCMData, int nch, int bps, int timestamp)
; // sets the vis data directly from PCM data
; // quick And easy way To get vis working :)
; // needs at least 576 samples :)
; advanced vis supplying mode, only use If you're cool. Use VSAAddPCMData for most stuff.
VSAGetMode.l ;Int (*VSAGetMode)(int *specNch, int *waveNch)
; // use to figure out what to give to VSAAdd
VSAAdd.l ;void (*VSAAdd)(void *data, int timestamp);// filled in by winamp, called by plug-in
;call this in Play() To tell the vis plug-ins the current output params.
VSASetInfo.l ;void (*VSASetInfo)(int nch, int srate);
;dsp plug-in processing:
;(filled in by winamp, called by input plug)
;returns 1 If active (which means that the number of samples returned by dsp_dosamples
;could be greater than went in.. Use it To estimate If you'll have enough room in the
;output buffer
dsp_isactive.l ;Int (*dsp_isactive)();
;returns number of samples To output. This can be as much as twice numsamples.
;be sure To allocate enough buffer For samples, then.
dsp_dosamples.l ;Int (*dsp_dosamples)(short int *samples, int numsamples, int bps, int nch, int srate);
;eq stuff
EQSet.l ;void (*EQSet)(int on, char data[10], int preamp); // 0-64 each, 31 is +0, 0 is +12, 63 is -12. Do nothing to ignore.
;info setting (filled in by winamp)
SetInfo.l ;void (*SetInfo)(int bitrate, int srate, int stereo, int synched); // if -1, changes ignored? :)
outMod.l ;winamp_out_module *outMod; // filled in by winamp, optionally used :)
EndStructure
;-Global
Global *winamp_out_head.winamp_out_module
Global *winamp_in_head.winamp_in_module
Global winamp_return_long.l
Global winamp_return_string.s
Procedure winamp_setinfo_():EndProcedure
Procedure winamp_dsp_isactive_():EndProcedure
Procedure winamp_dsp_dosamples_(pointer,numsamples,bps,nch,srate)
ProcedureReturn numsamples
EndProcedure
Procedure winamp_SAVSAInit_():EndProcedure
Procedure winamp_SAVSADeInit_():EndProcedure
Procedure winamp_SAAddPCMData_():EndProcedure
Procedure winamp_SAGetMode_():EndProcedure
Procedure winamp_SAAdd_():EndProcedure
Procedure winamp_VSAAddPCMData_():EndProcedure
Procedure winamp_VSAGetMode_():EndProcedure
Procedure winamp_VSAAdd_():EndProcedure
Procedure winamp_VSASetInfo_():EndProcedure
Declare winamp_stop()
Declare winamp_setoutputtime(time)
Declare winamp_isplaying()
Procedure Quit_Winamp()
If *winamp_in_head
If winamp_isplaying() :winamp_stop():EndIf
CallFunctionFast(*winamp_in_head\quit)
CloseLibrary(#dll_winamp_in)
*winamp_in_head=0
EndIf
If *winamp_out_head
CallFunctionFast(*winamp_out_head\quit)
CloseLibrary(#DLL_WINAMP_OUT)
*winamp_out_head=0
EndIf
EndProcedure
Procedure Init_Winamp(in_dll$,out_dll$,windowid)
;return
; 0 no error.
; -1 out_dll is no winamp-dll
; -2 can't open out_dll
; -3 in_dll is no winamp-dll
; -4 can't open in_dll
If *winamp_out_head0 Or *winamp_in_head0
quit_winamp()
EndIf
out_DLLinstance=OpenLibrary(#DLL_WINAMP_OUT, out_dll$)
If out_DLLinstance
*winamp_out_head=CallFunction(#DLL_WINAMP_OUT,"winampGetOutModule")
If *winamp_out_head
*winamp_out_head\hMainWindow=WindowID()
*winamp_out_head\hDllInstance=out_DLLinstance
CallFunctionFast(*winamp_out_head\Init)
Else
CloseLibrary(#DLL_WINAMP_OUT)
*winamp_out_head=0:*winamp_in_head=0
ProcedureReturn -1
EndIf
Else
*winamp_out_head=0:*winamp_in_head=0
ProcedureReturn -2
EndIf
in_DLLinstance= OpenLibrary(#dll_winamp_in, in_dll$)
If in_DLLinstance
*winamp_in_head = CallFunction(#dll_winamp_in, "winampGetInModule2" )
If *winamp_in_head
*winamp_in_head\hMainWindow=WindowID
*winamp_in_head\hDllInstance=in_DLLinstance
*winamp_in_head\outMod=*winamp_out_head
CallFunctionFast(*winamp_in_head\Init)
;dummy-routines
*winamp_in_head\SetInfo=@winamp_setinfo_()
*winamp_in_head\dsp_isactive =@winamp_dsp_isactive_()
*winamp_in_head\dsp_dosamples=@winamp_dsp_dosamples_()
*winamp_in_head\SAVSAInit =@winamp_SAVSAInit_()
*winamp_in_head\SAVSADeInit =@winamp_SAVSADeInit_()
*winamp_in_head\SAAddPCMData =@winamp_SAAddPCMData_()
*winamp_in_head\SAGetMode =@winamp_SAGetMode_()
*winamp_in_head\SAAdd =@winamp_SAAdd_()
*winamp_in_head\VSASetInfo =@winamp_VSASetInfo_()
*winamp_in_head\VSAAddPCMData=@winamp_VSAAddPCMData_()
*winamp_in_head\VSAGetMode =@winamp_VSAGetMode_()
*winamp_in_head\VSAAdd =@winamp_VSAAdd_()
Else
CallFunctionFast(*winamp_out_head\quit)
CloseLibrary(#DLL_WINAMP_OUT)
CloseLibrary(#dll_winamp_in)
*winamp_out_head=0:*winamp_in_head=0
ProcedureReturn -3
EndIf
Else
CallFunctionFast(*winamp_out_head\quit)
CloseLibrary(#DLL_WINAMP_OUT)
*winamp_out_head=0:*winamp_in_head=0
ProcedureReturn -4
EndIf
ProcedureReturn 0
EndProcedure
Procedure.s Winamp_OutName()
ProcedureReturn *winamp_out_head\description
EndProcedure
Procedure Winamp_OutConfig(windowid)
CallFunctionFast(*winamp_out_head\config,windowid)
!ADD esp,4
EndProcedure
Procedure Winamp_OutAbout(windowid)
CallFunctionFast(*winamp_out_head\about,windowid)
!ADD esp,4
EndProcedure
Procedure Winamp_IsPlaying()
winamp_return_long=CallFunctionFast(*winamp_out_head\IsPlaying)
ProcedureReturn winamp_return_long
EndProcedure
Procedure.s Winamp_InName()
ProcedureReturn *winamp_in_head\description
EndProcedure
Procedure Winamp_isSeekable()
ProcedureReturn *winamp_in_head\is_seekable
EndProcedure
Procedure.s Winamp_OnlyExtensions()
adr=*winamp_in_head\FileExtensions
ok=0:out$="*.":exit=0:l=1
Repeat
a=PeekB(adr):adr+1
If a=0 And ok=0
ok=-1
ElseIf a=0 And ok
exit=-1
Else
If ok
ok=0
If l=0
out$+";*."
l=1
Else
l=0
EndIf
EndIf
EndIf
If l
If a=59
out$+";*."
Else
out$+Chr(a)
EndIf
EndIf
Until exit
ProcedureReturn out$
EndProcedure
Procedure.s Winamp_Extensions()
adr=*winamp_in_head\FileExtensions
ok=0:exit=0:l=0
Repeat
a=PeekB(adr):adr=adr+1
If a=0 And o1$"" And o2$""
If out$"":out$+"|":EndIf
If Left(o2$,2)"*.":o2$="*."+o2$:EndIf
out$+o1$+"|"+o2$
o1$="":o2$=""
EndIf
If a=0 And ok=0
ok=-1
ElseIf a=0 And ok
exit=-1
Else
If ok
ok=0
If l=0
o1$="*."
l=1
Else
o2$=""
l=0
EndIf
EndIf
If l=0
If a=59
o2$+";*."
Else
o2$+Chr(a)
EndIf
Else
o1$+Chr(a)
EndIf
EndIf
Until exit
ProcedureReturn out$
EndProcedure
Procedure Winamp_InConfig(windowid)
CallFunctionFast(*winamp_in_head\config,windowid)
!ADD esp,4
EndProcedure
Procedure Winamp_InAbout(windowid)
CallFunctionFast(*winamp_in_head\about,WindowID)
!ADD esp,4
EndProcedure
Procedure.s Winamp_GetFileInfo(playfile$,length_adr)
winamp_return_string=Space(1000)
CallFunctionFast(*winamp_in_head\getfileinfo,@playfile$,@winamp_return_string,length_adr)
!ADD esp,12
ProcedureReturn winamp_return_string
EndProcedure
Procedure Winamp_InfoBox(playfile$,windowid)
winamp_return_long=CallFunctionFast(*winamp_in_head\infobox,@playfile$,windowid)
!ADD esp,8
ProcedureReturn winamp_return_long
EndProcedure
Procedure Winamp_IsOurFile(playfile$)
;used For detecting URL streams.. unused here. strncmp(fn,"http://",7) To detect HTTP streams, etc
winamp_return_long=CallFunctionFast(*winamp_in_head\isourfile,@playfile$)
!add esp,4
ProcedureReturn winamp_return_long
EndProcedure
Procedure Winamp_Play(playfile$)
If winamp_isplaying() :winamp_stop():EndIf ; or it can crash
winamp_return_long=CallFunctionFast(*winamp_in_head\play,@playfile$)
!ADD esp,4
ProcedureReturn winamp_return_long
EndProcedure
Procedure Winamp_IsPaused()
winamp_return_long=CallFunctionFast(*winamp_in_head\ispaused)
ProcedureReturn winamp_return_long
EndProcedure
Procedure Winamp_Pause()
If winamp_ispaused()
CallFunctionFast(*winamp_in_head\unpause)
Else
CallFunctionFast(*winamp_in_head\pause)
EndIf
EndProcedure
Procedure Winamp_Stop()
CallFunctionFast(*winamp_in_head\stop)
EndProcedure
Procedure Winamp_GetLength()
winamp_return_long=CallFunctionFast(*winamp_in_head\getlength)
ProcedureReturn winamp_return_long
EndProcedure
Procedure.s Winamp_LengthStr(length)
out$=""
a=length/(60*60*1000):length-(a*60*60*1000)
out$=Str(a)
a=length/(60*1000):length-(a*60*1000)
out$+":"+Right("0"+Str(a),2)
a=length/1000
out$+":"+Right("0"+Str(a),2)
ProcedureReturn out$
EndProcedure
Procedure Winamp_GetOutputTime()
winamp_return_long=CallFunctionFast(*winamp_in_head\getoutputtime)
ProcedureReturn winamp_return_long
EndProcedure
Procedure Winamp_SetOutputTime(time)
CallFunctionFast(*winamp_in_head\setoutputtime,time)
!ADD esp,4
EndProcedure
Procedure Winamp_SetVolume(volume)
CallFunctionFast(*winamp_in_head\setvolume,volume)
!ADD esp,4
EndProcedure
Procedure Winamp_SetPan(pan)
CallFunctionFast(*winamp_in_head\setpan,pan)
!ADD esp,4
EndProcedure
Code: Select all
;Small Winamp-Demo
;WM_WA_MPEG_EOF
IncludeFile "winamp.pbi"
If OpenWindow(0, 0,0,340,265,#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget ,"Winamp-Plugin-Test")
If CreateGadgetList(WindowID())
top=10
ButtonGadget( 0, 10,top ,100,20, "ChangeOut")
ButtonGadget( 1, 120,top ,100,20, "OutConfig")
ButtonGadget( 2, 230,top ,100,20, "OutAbout"):top+22
TextGadget ( 3, 10,top ,100,20, "",#PB_Text_center)
TextGadget ( 4, 120,top ,210,20, "",#PB_Text_center):top+22
top+5
ButtonGadget( 5, 10,top ,100,20, "ChangeIn")
ButtonGadget( 6, 120,top ,100,20, "InConfig")
ButtonGadget( 7, 230,top ,100,20, "InAbout"):top+22
TextGadget ( 8, 10,top ,100,20, "",#PB_Text_center)
TextGadget ( 9, 120,top ,210,20, "",#PB_Text_center):top+22
top+5
ButtonGadget(10, 10,top ,100,20, "Open")
ButtonGadget(11, 120,top ,100,20, "InfoBox")
TextGadget (12, 230,top ,100,20, ""):top+22
TextGadget (13, 10,top ,210,20, "",#PB_Text_center)
TextGadget (14, 230,top ,100,20, ""):top+22
top+5
ButtonGadget(15, 10,top ,100,20, "Play")
ButtonGadget(16, 120,top ,100,20, "Stop")
ButtonGadget(17, 230,top ,100,20, "Pause"):top+22
top+5
TextGadget (18, 10,top , 64,20, "Volume")
TrackBarGadget(19, 74,top ,256,20,0,255):top+22
TextGadget (20, 10,top , 64,20, "Pan")
TrackBarGadget(21, 74,top ,256,20,-127+127,127+127):top+22
top+5
TextGadget (22, 10,top , 64,20, "Position")
TrackBarGadget(23, 74,top ,256,20,0,255):top+22
DisableGadget(23,1)
in_dll$="": in_des$=""
out_dll$="":out_des$=""
playfile$="":title$="":length$="":length_ms=0
volume=255:pan=0:position=0:pos$=""
SetGadgetState(19,volume): SetGadgetState(21,pan+127)
changed=1:winamp_install=-1:reload=1
Repeat
If reload
If out_dll$"" And in_dll$""
winamp_install=init_winamp(in_dll$,out_dll$,WindowID())
Select winamp_install
Case 0
winamp_setvolume(volume)
winamp_setpan(pan)
in_des$=winamp_inname()
out_des$=winamp_outname()
;If winamp_isseekable() ;0
i=Winamp_GetOutputTime()
a$=winamp_lengthstr(i)
If a$pos$
SetGadgetText(22,a$)
pos$=a$
endif
i=i*255/length_ms
If i255:i=255:EndIf
If iGetGadgetState(23)
position=i
SetGadgetState(23,position)
EndIf
eventid=WindowEvent()
Else
EventId=WaitWindowEvent()
EndIf
Until eventid0
Select EventID
Case #WM_WA_MPEG_EOF; File played!
MessageRequester("MiniWinamp","File Played.",#PB_MessageRequester_Ok)
Case #PB_Event_CloseWindow
quit=1
Case #PB_Event_Gadget
eventtype=EventType()
gadgetid=EventGadgetID()
Select gadgetid
Case 0;ChangeOut
out_dll$=OpenFileRequester("Winamp Out-Plugin","out_","Winamp Out-Plugin|out_*.dll|all|*.*",0)
reload=1
Case 5;ChangeIn
in_dll$=OpenFileRequester("Winamp In-Plugin","in_","Winamp In-Plugin|in_*.dll|all|*.*",0)
reload=1
Case 19;volume
volume=GetGadgetState(19)
If volume255:volume=255:EndIf
If winamp_install=0:winamp_setvolume(volume):EndIf
Case 21;pan
pan=GetGadgetState(21)-127
If pan127:pan=127:EndIf
If winamp_install=0:winamp_setpan(pan):EndIf
Default; only when winamp function
If winamp_install=0
Select gadgetid
Case 1:winamp_outconfig(WindowID())
Case 2:winamp_outabout(WindowID())
Case 6:winamp_inconfig(WindowID())
Case 7:winamp_inabout(WindowID())
Case 10;open
If winamp_isplaying() :winamp_stop():EndIf
pat$="Modul|"+winamp_onlyextensions()+"|"+winamp_extensions()
playfile$=OpenFileRequester("Winamp File","",pat$,0)
title$=winamp_getfileinfo(playfile$,@length_ms)
length$=winamp_lengthstr(length_ms)
changed=1
Default
If playfile$=""
MessageRequester("MiniWinamp","Please open file first.",#PB_MessageRequester_Ok)
If gadgetid=23
SetGadgetState(23,0)
EndIf
Else
Select gadgetid
Case 11;infobox
winamp_infobox(playfile$,WindowID())
Case 15;play
i=winamp_play(playfile$)
If i0
MessageRequester("MiniWinamp","Can't play "+GetFilePart(playfile$),#PB_MessageRequester_Ok)
EndIf
Case 16;stop
winamp_stop()
Case 17;pause
winamp_pause()
Case 23
i=GetGadgetState(23)
If iposition
i=i*length_ms/255
If ilength_ms:i=length_ms:EndIf
winamp_SetOutputTime(i)
EndIf
EndSelect
EndIf
EndSelect
Else
If eventid>0 And eventid<19
MessageRequester("MiniWinamp","Please load first the plugins.",#PB_MessageRequester_Ok)
EndIf
EndIf
EndSelect
EndSelect
Until quit
EndIf
EndIf
If winamp_install=0 :quit_winamp():EndIf