MasterClass : November 95




One of the things the Amiga is best at is doing several
things at once: find out how to make your own SlideShow in
the Masterclass. 




If you have been playing with the great OctaMed 5.04
coverdisk giveaway from the September 1995 issue of CU, you
might have discovered a program called "OctaMedPlayer". This
small utility is for playing back sound modules: no editing,
no saving, only load and play.

It has been designed for sitations when you only need a
simple player program: for example, you might use a
directory utility such as Directory Opus in which case you
can configure OctaMedPlayer to handle any Mod files you
select.

The player utility also has an ARexx port which means it's
possible to control it from other programs. ARexx, if you
need reminding, is the programming lauguage which comes free
with all Amigas and allows application programs to
communicate with each other. An application can launch an
ARexx program to communicate with another program which is
running in background, or alternatively an ARexx program can
be started by the user from the Shell.

A good demonstration of ARexx is creating a SlideShow
program which is capable of displaying a sequence images on
the screen, whilst playing some music.

For this experiment we will need the OctaMedPlayer, plus a
picture viewer program. I'm using a viewer called FastView
by John Hendrikx because it has some very useful features,
and it makes a welcome change from the Viewtek program I
seem to use all the time. You can find FastView (and
Viewtek) on the Aminet (either the CDROMs or Internet site)
or from The Heart of Gold BBS (use your modem to dial 01247
274919)


Starting with ARexx

ARexx is very simple language and is particularly easy to
use. You enter the programs using a standard text editor
such as ED (or perhaps something better like GoldEd or
Cygnus Ed) and save them to disk. If you give the programs a
name which ends in .rexx ( for example, program1.rexx) this
helps mark them out as ARexx programs.

There are only a few tricks to know when writing ARexx
programs, and one of the first is to make sure you always
start your program with a title, between comment markers.
The comments are normally ignored by ARexx, but for some
reason it insists that you use one on the first line. Here
is a simple ARexx program which you should type in and save
as program1.rexx.

( *** slightly different font here please, DTP person ***)

/* 
    Program 1
    A simple example
*/

say "Hello World!"

exit

(*** end of font, thanks ***)


Now you can run the program using the "rx" command from an
AmigaDOS Shell. If the RexxMast program is running in the
background (if it is not, type RexxMast to start it) the rx
command will take the name of the program you give it
(assuming that it ends in .rexx) and executes it. If you run
our example program, you'll see something exciting like
this:

(picture1.iff)

With the preliminaries out of the way, we can now see how
ARexx can be used to control other programs. Find the
OctaMedPlayer program and start it running. If you wish,
minimize it to give yourself more space on the Workbench.
Next find a Mod tune to experiment with, and save it to the
Ram disk. 

Now enter the following program, and save it as
program2.rexx

( *** slightly different font here please, DTP person ***)

/*
    Program 2
    Controlling OctaMedPlayer
*/

address OCTAMEDPLAYER
loadmod "ram:mod.mytune1"
play

exit

(*** end of font, thanks ***)


If, when you run the program with rx, you see an error
message such as "Host environment not found", this means
that either the OctaMedPlayer is not running in the
background, or that you have spelt its name wrong in the
address function in the first lines of the ARexx program.

It is the task of "address" to make sure that ARexx sends
instructions to the correct programs. Each program has a
unique ARexx port name, which must be entered exactly. You
will normally find the port name in the program
documentation.

When you get the program to run, you will see the player
load the module and start play it -- exactly as though you
had done it manually.


Vision On

Adding image control to our ARexx program is slightly more
difficuly. Ideally, we need a viewing program which also
supports ARexx but unfortunately there aren't many of those
about. However, ARexx allows you to use any program as
though you had entered the commands directly into the Shell.
This means we can still make full use of a program such as
FastView.

When you obtain and use FastView, you should experiment with
it at the shell. When you are happy that it is working,
create a few images in Deluxe or Personal paint and save
them as 1.iff, 2.iff and 3.iff.

Using Shell commands from ARexx is as simple as using the
option "command" after the address function. This means you
could write a program to perform a directory listing as
easily as this:

(** font **)

/* Display a Directory listing */

address command
dir

(** end font **)


The only catch is to make sure you enter any commands which
have following options inside inverted commas, like this:


(** font **)

/* Display a Directory listing */
/* only of files created after */
/* 11:15 this morning */

address command
"list since 11:15"

(** end font **)


Bearing this in mind, here is a first attempt at a program
which we could use to display images using FastView:


(** font **)


/*
    Program to display several images
    using the FastView picture viewer
*/


address command


"fastview 1.iff"
"fastview 2.iff" 
"fastview 3.iff" 

exit



(** end font **)



If you run this program you'll see a major problem
immediately: between pictures the Workbench display briefly
reappears and then vanishes which gives a very
unprofessional appearance.

Thankfully, FastView has an option which greatly improve
this glitching. If you provide a list of files instead of
oly one, FastView will display one picture and then start
loading in the next. Only when the picture is fully loaded
will it be displayed.

We can therefore alter our program to look like this:

(** font **)

/*
    Program to display several images
    using the FastView picture viewer
    with no glitches
*/


address command

"fastview 1.iff 2.iff 3.iff " waitforpic delay 10"

exit


(** end font **)


You can use wildcards if you don't want to specifiy all the
files (try #?.iff), and if you want more or less time
between the images alter the number 10. If you are loading
files from floppy, the default time delay probably won't be
long enough.



Sound and Vision


With both sound and video mastered, it's time to link them
together into one multimedia program. To make life easier, I
have included several user-defined functions which keep the
address commands separate.

Creating your own functions is easy in ARexx. You need to
think of a name, and put a colon (:) after it. Then type the
instructions you want performed and end with "return". To
use your function, precede the name with "call" and add some
brackets. Here's a simple example:

(** font **)

/*
    Function example
*/

call hello()
exit

hello:
    say "Hello world"
    return

(** end font **)


OK, here's the biggie: a program which loads a module or
two, starts playing and then first displays all the IFF
images in a drawer called "pictures", and then all the GIF
images.

You should be able to adapt it to your own needs very
easily, and add more tunes or whatever else is needed. One
possibility would be to add some movement: if you use the
freely distributable image and animation display program
Viewtek, you can add commands to load and play an animation
as well as still images. Viewtek will also play animations
directly from harddrive, which means you can create some
very complicated multimedia performances.

It's exactly this technique of using ARexx to link different
programs together which makes the Amiga so special. If you
think what we have just done is neat, you have only scraped
the surface. ARexx can do just about anything: with a little
extra hardware it is even possible to use an old TV remote
control to play OctaMed modules or turn your Amiga into a
high tech presentation system. Forget Windows95, this is
what multitasking multimedia is really about.



(** font **)

/* 
      Slideview program v.01
*/


/* Start of Performance */

call loadtune ("med.tune1")
call pictures1()
call playtune()
call pause(10)
call loadtune ("med.tune2")
call playtune()
call pictures1()
exit


/* Music Player functions */

loadtune:
	address OCTAMEDPLAYER
	filename=arg(1)
	loadmod filename
	return

playtune:
	address OCTAMEDPLAYER
	play
	return

stoptune:
	address OCTAMEDPLAYER
	play
	return

continuetune:
	address OCTAMEDPLAYER
	cont
	return




/* Image Viewer functions */


pictures1:
    /* Display all the IFF images in the picture drawer */
	address command
	"fastview pictures/#?.iff waitforpic delay 10"
	return

pictures2:
    /* Display all the GIF images in the picture drawer */
	address command
	"fastview pictures/#?.gif waitforpic delay 10"
	return



/* Misc */

pause:
    /* Go to sleep for a number of seconds */
	address command
	delay=arg(1)
	wait delay
	return



(*** end font ***)