Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

spkrnote.cpp

Go to the documentation of this file.
00001 // $Id
00002 
00003 //**********************************************************************
00004 //                                                                     *
00005 //    Description:   Implementation using PC speaker to produce sound  *
00006 //                   for a single note.                                *
00007 //                                                                     *
00008 //    Author:        Chris White (whitecf@bcs.org.uk)                  *
00009 //                                                                     *
00010 //    Copyright (C) 2003  Monitor Computing Services Ltd.              *
00011 //                                                                     *
00012 //    This program is free software; you can redistribute it and/or    *
00013 //    modify it under the terms of the GNU General Public License      *
00014 //    as published by the Free Software Foundation; either version 2   *
00015 //    of the License, or any later version.                            *
00016 //                                                                     *
00017 //    This program is distributed in the hope that it will be useful,  *
00018 //    but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00019 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00020 //    GNU General Public License for more details.                     *
00021 //                                                                     *
00022 //    You should have received a copy of the GNU General Public        *
00023 //    License (http://www.gnu.org/copyleft/gpl.html) along with this   *
00024 //    program; if not, write to:                                       *
00025 //       The Free Software Foundation Inc.,                            *
00026 //       59 Temple Place - Suite 330,                                  *
00027 //       Boston, MA  02111-1307,                                       *
00028 //       USA.                                                          *
00029 //                                                                     *
00030 //**********************************************************************
00031 //                                                                     *
00032 //    Notes:                                                           *
00033 //                                                                     *
00034 //**********************************************************************
00035 
00036 #include <dos.h>
00037 
00038 #include <callback.h>
00039 #include <mytrace.h>
00040 #include <timeout.h>
00041 
00042 #include "spkrnote.h"
00043 
00044 
00045 
00046 using namespace Monitor::Utility;
00047 
00048 
00049 
00050 int    SpeakerNote::busy = 0;
00051 
00052 
00053 SpeakerNote::SpeakerNote(Frequency    newFrequency, Length    newLength)
00054     : frequency(newFrequency), length(newLength)
00055 {
00056     _USEMYTRACE_("SpeakerNote::SpeakerNote(newFrequency, newLength)")
00057 }
00058 
00059 
00060 
00061 SpeakerNote::~SpeakerNote()
00062 {
00063     _USEMYTRACE_("SpeakerNote::~SpeakerNote()")
00064 }
00065 
00066 
00067 
00068 void
00069 SpeakerNote::sound() const
00070 throw (Note::Busy)
00071 {
00072     _USEMYTRACE_("SpeakerNote::sound()")
00073 
00074     if (busy)
00075     {
00076         throw Busy();
00077     }
00078     else
00079     {
00080         busy = !0;
00081 
00082         // Turn speaker on at given frequency
00083         ::sound(frequency);
00084 
00085         // Time length of ring
00086         new Timeout(ConstCallback< SpeakerNote >(*this,
00087                                                  &SpeakerNote::endSound),
00088                     length,
00089                     "note length");
00090     }
00091 }
00092 
00093 
00094 
00095 void
00096 SpeakerNote::endSound() const
00097 {
00098     _USEMYTRACE_("SpeakerNote::endSound()")
00099 
00100     // Turn speaker off
00101     ::nosound();
00102 
00103     busy = 0;
00104 }
00105 
00106 
00107 
00108 SpeakerNote::Frequency
00109 SpeakerNote::getFrequency() const
00110 {
00111     _USEMYTRACE_("SpeakerNote::getFrequency()")
00112 
00113     return    frequency;
00114 }
00115 
00116 
00117 
00118 void
00119 SpeakerNote::setFrequency(Frequency    newFrequency)
00120 {
00121     _USEMYTRACE_("SpeakerNote::setFrequency(newFrequency)")
00122 
00123     frequency = newFrequency;
00124 }
00125 
00126 
00127 
00128 SpeakerNote::Length
00129 SpeakerNote::getLength() const
00130 {
00131     _USEMYTRACE_("SpeakerNote::getLength()")
00132 
00133     return length;
00134 }
00135 
00136 
00137 
00138 void
00139 SpeakerNote::setLength(Length    newLength)
00140 {
00141     _USEMYTRACE_("SpeakerNote::setLength(newLength)")
00142 
00143     length = newLength;
00144 }

Generated on Wed Oct 29 20:52:39 2003 for Utility BC Turbo Vision by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002