Novell Home

HowTo: Add Sounds To RunRev Poem Project

Novell Cool Solutions: Feature
By Stomfi

Digg This - Slashdot This

Posted: 9 Dec 2004
 

StomfiLearning to use Linux at Home and Work
Welcome to my ongoing series of HowTo articles designed to help Linux newbies get comfortable with Linux. Before trying any of these HowTos, take a few minutes to study the prerequisites so you can hit the ground running.
--Stomfi

This HowTo shows how to add a random wave file sound to play while the animation is being displayed in the Poems project. There is only one more HowTo left in this project, which will show you how to distribute your project so that other users can enjoy your work. See HowTo: Add Animations to the Poem Project for creating sounds with Audacity.

First make sure you have a folder HOME/sounds that contains a few .wav files. Next start the Runtime Revolution (RunRev) application and open your poems.rev file, which should be in your HOME/bin/develop folder.

I am going to use Revolution 2.5 for this how to to show you the differences between the older version and this newer one, and that the file that was created with the older version works just as well in the newer one.

The newer application looks a bit different.

Graphic1

All the bar functions we have been using are the same, although they may be in different menu items. This is usually changed to make things more cognitive, because RunRev tries to make things easy for newbies and developers alike. I like that, because it means I don't have to strain my brains to get thing to work.

The side panel is also different. The two top buttons switch between browse mode, where you test your work - and pointer mode, where you modify things.

Graphic2

The Application browser where we can see all the cards, fields and buttons in our development, is in the Tools menu item. In the Tools menu is a new item called Paint and Draw Tools, which extends the side panel. You can also do this by clicking the triangle at the bottom right of the side panel.

The other big difference is the properties pop up. You can still access this by double clicking on an object when in pointer mode, or by right clicking on an object and selecting "Property Inspector", or click Object in the menu bar and "Object Properties". It depends how your own brain likes to work as to which method you choose.

There is a book on the RunRev site called "Programming at the Speed of Thought" and this title really sums up their design philosophy. Luckily it also fits in with the Linux shell toolkit which was designed for exactly the same reasons, although in their case it consists of lots of single purpose tools, each being designed just for one job. Easy to learn, remember, and apply. They can be stuck together to do more complex tasks with special glue programs called pipes or shells. Pipes let the results of one tool become the input for the next before the preceding tool has finished. Shells let you save the completed results of tools in containers which can be poured into subsequent tools.

This is a pretty general explanation of shell tools as everything is integrated, but it makes for clearer understanding by end users. I think the people at Bell Labs, who invented the tool kit, had water pipes in mind to describe the process, where instead of water, information was the flow medium.

Enough of that, let's get on with the project

Here is the Application browser window for our Poems project. Click on the box with the plus sign at the right of POEMS to expand the tree. You can see that I have highlighted the READ card and its objects are shown in the Control window.

Graphic3

The "Select" button is where all the work is done. The script of this button, allowed us to display an animation before the poem is displayed. We will add the sound play functions to the script of this button. To show the script window. We can right click on the left icon associated with this button in the Control window and select "Edit Script" to pop up the script window.

RunRev 2.5 puts colours in the script. Because at time of writing there is no native QuickTime player for Linux, we will use a simple non looping player via the shell.

We display the animation before we start the sound - otherwise, the sound may take up all our resources and prevent the animation from starting.

These are little things that the users find out when developing.

Add these lines and apply.

Save the file.

Graphic4

Next is the shell script in our HOME/bin folder. The easiest way to do this is to open and Save As the randani.sh script to the name randsnd.sh, and modify that file in the editor as shown.

#!/bin/bash

#randsnd.sh

#return the path of a random sound .wav file from $HOME/sounds and play it

#We count how many there are using word count (wc)

#piping ls to awk allows us to strip off the leading spaces

#and print the first figure result from wc

NSNDS=`ls $HOME/sounds/*.wav | wc | awk '{print $1}'`

#Use the inbuilt shell function random to get a random one

THISNUM=$RANDOM

#Use the % maths operator to get the remainder of a division

let THISNSND=$THISNUM%$NSNDS

#If the remainder is zero let it be one

if [ $THISNSND -lt 1 ]

then

THISNSND=1

fi

#We need a carriage return separated list of files

#man ls gives us the -1 option for this ie one per line

#pipe this to awk and print the line that equals the one we want

THISSND=`ls -1 $HOME/sounds/*.wav | awk -v SNDNUM=$THISNSND '{ if ( NR == SNDNUM ) print $0 }'`

#We need to return this shell to RunRev so it can get on with its script

#Use Linux to play the sound as RunRev uses QuickTime which is not on my computer

#play is part of the sox suite and is usually on most Linux distros

#Play the sound in the background so that this process will

#return to the calling program and lower its priority with nice so it doesn't take too much resources

#send any shell output into the bottomless pit with 2>&1

#

nice play $THISSND 2>&1 >/dev/null &

echo "Playing $THISSND"

#End of shell script

You will notice that where the previous script used IMG this uses SND. This random selection process is exactly the same, allowing us to reuse a previously learned routine.

Instead of returning the name of the sound file to RunRev for it to play. This shell plays the sound.

The special file /dev/null is a bottomless pit, where we can send things we don't want. Hum, not everything! 2>&1 is special shell speak for the standard input/output which would normally be in a terminal window, which we don't use here.

The shell command "nice" can lower or raise the priority of programs so that the users can use less or more resources. The system screensaver is usually "niced" to run at a lower priority. If the sound stops your computer from displaying the animation, you can modify the command to run at an even lower priority. See the man page or use nice -n 20 for the lowest possible.

The "echo" at the end returns the file name for simple debugging in our RunRev script.

This is the shell script for stopping the sound.

Graphic5

Save it and change the mode of this file to executable. You can do this in the file manager as follows:

  1. Right click on the file and choose Properties.


  2. Click the Permissions Tab.


  3. Click to tick all the Execute boxes in Nautilus on Gnome or the Exec boxes in Konqueror in KDE as shown.
Graphic6 Graphic7

The play command in Linux only plays the file once. I tried using Mplayer which has a looping option, but there is a lot of output that interferes with a proper return to RunRev. One of the readers may be able to send in a working solution. In any case you can always make your sound files 8 of more seconds long so that they play till the end or get killed with the killall script.

Back in RunRev, enter browse mode and go to the Read card and press the Select button etc, to try it out. Don't forget to turn your sound on first. You can use the play command to check that your sound card is working by "play $HOME/mysound.wav".

When you are satisfied that everything is happening according to plan, save the RunRev file, and build the distribution.

RunRev 2.5 scores much higher in the ease-of-use rating for building the application than previous versions.

The process consists simply of selecting "Save As Standalone Application" from the File menu.

Graphic8

Then you select a folder to build the Application in. In my case "/home/tom/bin/develop"

Click the Choose button and the following pop up appears.

Graphic9

Graphic10

What could be simpler. The application is in a sub folder called by the name of the Stack. I.E. POEMS and the executable is called POEMS.

If you want to change these defaults, there is a separate menu item for doing so in "Standalone Application Settings", which brings up the following window.

Graphic11

Test the executable to make sure everything is working.

Copy the file to your HOME/bin folder.

You can rename it to lowercase if you like.

The final HowTo in this project will summarise all the things that you have learned while doing the Poems project and will show you how to make your application distributable on a CD.

All the tasks and skills you have learned can be applied to real world projects, and as this series progresses, you will see lots of things you can use to make your computing more productive and beneficial, and hopefully lots of fun.

For more information about Runtime Revolution visit http://www.novell.com/coolsolutions/feature/1863.html


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell