LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Articles > Technical
User Name
Password

Notices

By stomfi at 2006-04-13 18:47
Power to the Users. Shell Scripting & GUI interfacing for Desktop Users. By Stomfi © 2006

Part 9 - Adding the Sound functions to the Storyboard


Create this window from the RunRev file menu using "New Substack of SB"

Picture of record window: [img=640x480]http://images.linuxquestions.org/articles/recorder1.png[/img]

Most of the objects are buttons. Recording time is a drop down menu with items from 1 to 10. The sliders can be used to preset recording and playback volumes. The test button opens two terminal windows, one which runs the alsamixer, and the other ecasignalview from the ecasound package. You may have to compile and install ecasound. To do this follow the same procedure as used for gifsicle in the previous article. You can find ecasound by typing its name into your search browser.

The next pictures show the alsamixer and two for the signal monitor.

Picture of alsamixer:
[img=640x480]http://images.linuxquestions.org/articles/alsamix.png[/img]


Picture of monitor xterm message:
[img=640x480]http://images.linuxquestions.org/articles/monitor1.png[/url]


Picture of Monitor in progress:
[img=640x480]http://images.linuxquestions.org/articles/monitor.jpg[/url]


These two xterm windows have to be closed before the record window reactivates. The record button records the selected input source and display the corresponding finished button when completed. The playback button performs in a similar fashion.

This picture shows the Application Browser window for all the objects on this card.

Picture of Application Browser:
[img=640x480]http://images.linuxquestions.org/articles/abrowse.png[/url]


The figures in the right hand column of each pane tell you how many lines of script there are for each object. As you can see DUNREC and DUNPLAY are the buttons for the FINISHED messages.

In the order they are shown here, these are the RunRev SOUND stack scripts starting with the RECPLAY card

Code:
on openCard
  global RECTIME
  put 1 into RECTIME
  global RECNUM
  put 0 into RECNUM
  global SNDNAME
  global SNDSOURCE
  put "MICROPHONE" into SNDSOURCE
  put the shell of ($HOME & "/SB/bin/micboostoff.sh") into DUBOOST
  set the label of button "BOOST" to "BOOST OFF"
  set the visible of button "BOOST" to true
  set the visible of button "DUNREC" to false
  set the visible of button "DUNPLAY" to false
end openCard
This Recording time menu get used to set only one value.

Code:
on menuPick timeItem
  global RECTIME
  put timeItem into RECTIME
end menuPick
This Record button script shows you how to use a scroll bar's thumbPosition to return a value.

The property values for these scroll bars are shown in the pictures below all the RunRev scripts.

Code:
on mouseUp
  set the visible of button "DUNREC" to false
  global RECNUM
  add 1 to RECNUM
  global SNDNAME
  global SOUNDNAME
  put (SNDNAME & RECNUM & ".wav")  into SNAME
  put ($HOME & "/SB/work/sounds/" & SNAME) into SOUNDNAME
  #Make sure record levels are set on
  global SNDSOURCE
  put the thumbPosition of scrollbar "VSOUND"  into SETVOL
  if SNDSOURCE = "MICROPHONE"
  then
    put the shell of ($HOME & "/SB/bin/miclevel.sh" && SETVOL) into MICVOL
  else
    put the shell of ($HOME & "/SB/bin/linelevel.sh" && SETVOL) into MICVOL
  end if
  global RECTIME
  put  ($HOME & "/SB/bin/recordsnd.sh" && RECTIME && SOUNDNAME) into DUSNDREC
  replace return with empty in DUSNDREC
  put the shell of DUSNDREC into DUNSNDREC
  set the visible of button "DUNREC" to true
  set the visible of button "DUNPLAY" to false
end mouseUp
This is the Test button script

Code:
on mouseUp
  put the shell of ($HOME & "/SB/bin/dumon.sh") into RECVOL
end mouseUp
This is the Vsound scroll bar
Code:
on mouseUp
  global SNDSOURCE
  put the thumbPosition of scrollbar "VSOUND"  into SETVOL
  if SNDSOURCE = "MICROPHONE"
  then
    put the shell of ($HOME & "/SB/bin/miclevel.sh" && SETVOL) into MICVOL
  else
    put the shell of ($HOME & "/SB/bin/linelevel.sh" && SETVOL) into MICVOL
  end if
end mouseUp
This is the QUIT button
Code:
on mouseUp
  global RECDUN
  put 1 into RECDUN
  set the visible of stack "SB" to true
  go card "mygraphics" of stack "SB"
  set the visible of stack "SOUNDS" to false
end mouseUp
This is the Sound Source menu
Code:
on menuPick SSOURCE
  global SNDSOURCE
  put SSOURCE into SNDSOURCE
  switch SSOURCE
    case "MICROPHONE"
      set the visible of button "BOOST" to true
      break
    case "LINE IN"
      set the visible of button "BOOST" to false
      break
  end switch
end menuPick
This is the Psound scroll bar
Code:
on mouseUp
  put the thumbPosition of scrollbar "PSOUND"  into SETVOL
  put the shell of ($HOME & "/SB/bin/playvol.sh" && SETVOL) into PLAYVOL
end mouseUp
This is the playback button
Code:
on mouseUp
  set the visible of button "DUNPLAY" to false
  global SOUNDNAME
  put the thumbPosition of scrollbar "PSOUND"  into SETVOL
  put the shell of ($HOME & "/SB/bin/playvol.sh" && SETVOL) into PLAYVOL
  put the shell of ($HOME & "/SB/bin/playback.sh" && SOUNDNAME) into DUPLAY
  set the visible of button "DUNPLAY" to true
end mouseUp
This is the Mic Boost button.
Code:
on mouseUp
  global BOOST
  if BOOST = "OFF"
  then
    put the shell of ($HOME & "/SB/bin/micbooston.sh") into DUBOOST
    set the label of button "BOOST" to "BOOST ON"
    put "ON" into BOOST
  else
    put the shell of ($HOME & "/SB/bin/micboostoff.sh") into DUBOOST
    set the label of button "BOOST" to "BOOST OFF"
    put "OFF" into BOOST
  end if
end mouseUp

The scroll bars need to have their start and end values set so that we can use them to set the volume between 0 and 100%. The Orientation is set to vertical.

Picture of the scroll bar property:
[img=640x480]http://images.linuxquestions.org/articles/scroll.png[/img]



Finally we need the shell scripts that make it all work. In the order that they appear first in the RunRev scripts, here they are:

Code:
#!/bin/bash
#micboostoff.sh 
#
#Reset the microphone sound volume
#
. ./gplnotice.txt
#
#Find out if and what Boost is called
BOOST=`amixer -c 0 controls|grep Boost`
if [ ${#BOOST} -gt 0 ]
then
  #Cut the names off
  BLINES=`echo $BOOST | cut -d= -f3`
  for B in $BLINES
  do
     amixer -c 0 sset $Boost mute
  done
fi
No that is not a typo "sset" is the correct option.

Code:
#!/bin/bash
#miclevel.sh  level
#
#Reset the microphone sound volume
#
. ./gplnotice.txt
#
aumix -m $1
Code:
#!/bin/bash
#linevol.sh  level
#
#Reset the line sound volume
#
. ./gplnotice.txt
#
aumix -i $1
Code:
#!/bin/bash
#recordsnd.sh  TIME FileName
#
#Record a sound for TIME seconds and save it to FileName in work/sounds
#
. ./gplnotice.txt
#
RTIME="$1"
FILE="$HOME/SB/work/sounds/$2"
ecasound "-i alsahw,0,0 -t $RTIME -o $FILE"
Code:
#!/bin/bash
#dumon.sh 
#
#Run monitor as background program
#
. ./gplnotice.txt
#
#we need to start up alsamixer in case some things need changing
/usr/X11R6/bin/xterm -geometry +10+10 -e alsamixer &
#This needs to run in a terminal window
/usr/X11R6/bin/xterm -T "Monitor Recording Levels" -hold -geometry +500+10 -e $HOME/SB/bin/monitorsnd.sh &
#Get out of here
exit
Code:
#!/bin/bash
#monitorsnd.sh 
#
#Monitor the real recording volume level
#
. ./gplnotice.txt
#
#This needs to run in a terminal window
RMSG="\n\
\n\
Read this message carefully\n\
\n\
Use Microphone Boost and or Yellow Volume Slider to set a\n\
recording level with no clipping\n\
 \n\
Delete this Window when happy with the level by using\n\
an arrow key then the window top right x button\n\
 \n\
 \n\
Press Return when ready to do the test"
echo -e $RMSG
read
#
ecasignalview alsa,default null -l -r 20
Code:
#!/bin/bash
#playvol.sh  level
#
#Reset the play sound volume with play
#
. ./gplnotice.txt
#
play -v $1 $HOME/info/template.wav
Code:
#!/bin/bash
#playback.sh  soundfile
#
#playback the sound
#
. ./gplnotice.txt
#
aplay -c 2 $1
Code:
#!/bin/bash
#micbooston.sh 
#
#Reset the microphone boost
#
. ./gplnotice.txt
#
#Find out if and what Boost is called
BOOST=`amixer -c 0 controls|grep Boost`
if [ ${#BOOST} -gt 0 ]
then
  #Cut the names off
  BLINES=`echo $BOOST | cut -d= -f3`
  for B in $BLINES
  do
     amixer -c 0 sset $Boost unmute
  done
fi
You obviously need aumix as well, so that need to be installed if you haven't got it. If you can't get the sound tools I used, you can substitute them for some you can find for your distro. The ecasound signalview tool was the only one I could find that showed the real time signal level on the input source.

This is the end of this article series. Good luck and have a lot of fun being a power user.


  



All times are GMT -5. The time now is 11:06 PM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration