home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn User 10
/
AU_CD10.iso
/
Updates
/
AMP
/
!Amp
/
Docs
/
PluginSpec
< prev
next >
Wrap
Text File
|
2000-05-14
|
6KB
|
178 lines
Plug-in Protocol
----------------
The !Amp plug-in protocol is fairly simple. It works by using the "pollword
non-zero" feature of the Wimp_Poll SWI. However, if your plugin is fairly
simple, you don't even need to know this much. You can just use the supplied
library (assuming you're writing in BASIC, otherwise you'll have to write
your own library).
If in doubt about any of the following information, take a look at on of the
existing plugins to see how it works!
Using the library
-----------------
If you want to use the library, simply have the following line at or near the
start of your program:
LIBRARY"<Amp$PluginDir>.Library.BASIC"
The next thing to do is to load any modules you might need (from
<Amp$ModuleDir>) and then call PROCinit. If you pass TRUE as a parameter,
"Wimp_Initialise" will automatically be called, otherwise you'll have to call
it yourself.
If you wish to support a specific version of the protocol, you can tell the
library by calling PROCversion. This takes the version supported and the
major filetype of the plugin. Valid versions are currently:
(0) version_basic% - minumum plugin protocol
(1) version_info% - supports info window
(2) version_config% - supports config protocol
If you pass a major filetype which is not -1 then templates will
automatically be loaded from !Amp.Plug-ins.Templates.<territory>.<filetype>
The window "fileinfo" will be created with window handle plugin_infoh% and
the window "config" will be created with window handle plugin_configh%. If
you're not supporting the config protocol, simply copy the config window from
the "default" template file.
Once you've done all the set up you need, simply call PROCpoll and the rest
of your code will be called as needed. There are various procedures you'll
need to add. This is a list of the ones required for version_basic%:
DEFPROCmessage(pollblock%)
Called when a wimp user message is received. Passed the wimp poll block.
DEFFNtime(RETURN min%, RETURN sec%, RETURN base%)
Called to get the current song position. You'll need to set the min%, sec%
and base% variables. (base% is how many secs there are in a min). You'll
also need to return a value. This can be ipc_time% if everything's ok,
ipc_stop% if the song is finished, ipc_pause% if the song has been paused,
or ipc_none% if the song is still paused.
DEFPROCpause(pause%)
Called to pause/unpause the song. pause% is TRUE or FALSE.
DEFFNload
Called to load a new song. You should try to load the file
"<Amp$SongName>" and return TRUE or FALSE as an indication of success.
DEFPROCstop
Called to stop a song.
DEFPROCvolume(volume%,balance%)
Called to set the volume/balance.
volume% is 0 to 27, balance% is -127 to +127
DEFPROCsongInfo(RETURN length%, RETURN songname$, RETURN stereo%, RETURN
kbps$, RETURN khz$)
Called to get the song information. You'll need to return the length (in
whatever you're using for secs), the songname, TRUE/FALSE for stereo% and
values to display in the kbps and kHz fields.
DEFPROCjumpto(min%,sec%)
Called to set the song position to min%:sec%
If you passed version_info% (or later) as the version supported, you'll also
need to write the following:
DEFPROCinfoWindow
Called to open the infoWindow. You should call "Wimp_GetPointerInfo" to
work out where you should open it, and you should open it with
"Wimp_CreateMenu" rather than "Wimp_OpenWindow"
DEFPROCeject
Called when the eject button on the frontend is pressed. Most plugins just
return without doing anything.
If you passed version_config% (or later) as the version supported, you'll
also need to write the following:
DEFPROCconfigok
Called when the ok button is pressed in the config window - you should
read the state of the window and update options as appropriate.
DEFPROCconfigcancel
Called when the cancel button is pressed in the config window - you
should update the window with the current options. This is also called
just before the window is opened, to ensure it contains correct
information.
DEFPROCconfigsave
Called to save the current config. You should save the options as they
are currently. If it was due to the save button in the config window,
PROCconfigok will be called first to ensure the options are set as they
are displayed in the window.
Finally, if you want to update the song information at any time, you can call
PROCsendinfo with the details:
PROCsendinfo(length%,songname$,stereo%,kbps$,khz$)
More technical information
--------------------------
If you want to write a plugin without using the library or in C or some other
language, it's perfectly possible. The only info you need is the format of
the pollword block. When your task is started, you should read the value of
<Amp$Pollword> - this gives you the memory address of the ipc block. The
format of it is like this (c syntax):
typedef enum {false=0,true=~false} Boolean;
typedef enum
{
IPC_NONE,
IPC_TIME,
IPC_PAUSE,
IPC_STOP,
IPC_LOAD,
IPC_VOLUME,
IPC_SONG_INFO,
IPC_PLUGIN_INFO,
IPC_REPEAT,
IPC_JUMPTO,
IPC_PLAYING,
IPC_NEXT,
IPC_PREV,
IPC_EJECT,
IPC_INFOWIN,
IPC_CONFIG,
IPC_CONFIGCANCEL,
IPC_CONFIGSAVE,
IPC_CONFIGOK
} Ipc;
typedef struct
{
char kbps[8];
char khz[4];
Boolean stereo;
int length;
char name[128];
} SongInfo;
typedef struct
{
Ipc request; /* What you're being asked for */
Ipc supply; /* What you're supplying */
union
{
struct { int min,sec,base,type; } time;
struct { int paused; } pause;
struct { int stop; } stop;
struct { int success; } load;
struct { int volume,balance; } volume;
SongInfo songInfo;
struct { int dummy; } pluginInfo;
struct { int repeat; } repeat;
struct { int min,sec; } jumpto;
struct { int type; } playing;
struct { int parent; } config;
} data;
} IpcBlock;