1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
/**
@file MsgHandler.cpp
@brief Handling of playback of audio clips
@author Tobias Blomberg / SM0SVX
@date 2005-10-22
This file contains an object that handles the playback of audio clips.
\verbatim
SvxLink - A Multi Purpose Voice Services System for Ham Radio Use
Copyright (C) 2003-2015 Tobias Blomberg / SM0SVX
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\endverbatim
*/
#ifndef MSG_HANDLER_INCLUDED
#define MSG_HANDLER_INCLUDED
/****************************************************************************
*
* System Includes
*
****************************************************************************/
#include <string>
#include <list>
#include <map>
#include <sigc++/sigc++.h>
/****************************************************************************
*
* Project Includes
*
****************************************************************************/
#include <AsyncAudioSource.h>
/****************************************************************************
*
* Local Includes
*
****************************************************************************/
/****************************************************************************
*
* Forward declarations
*
****************************************************************************/
class QueueItem;
/****************************************************************************
*
* Namespace
*
****************************************************************************/
//namespace MyNameSpace
//{
/****************************************************************************
*
* Forward declarations of classes inside of the declared namespace
*
****************************************************************************/
/****************************************************************************
*
* Defines & typedefs
*
****************************************************************************/
/****************************************************************************
*
* Exported Global Variables
*
****************************************************************************/
/****************************************************************************
*
* Class definitions
*
****************************************************************************/
/**
@brief Handling of playback of audio clips
@author Tobias Blomberg / SM0SVX
@date 2005-10-22
This class handles the playback of audio clips.
*/
class MsgHandler : public sigc::trackable, public Async::AudioSource
{
public:
/**
* @brief Default constuctor
* @param sample_rate The sample rate of the playback system
*/
explicit MsgHandler(int sample_rate);
/**
* @brief Destructor
*/
~MsgHandler(void);
/**
* @brief Play a file
* @param path The full path to the file to play
* @param idle_marked Choose if the playback should be idle marked or not
*
* Use this function to play a file.
* If idle_marked is true, the isIdle function will return true when
* the file is being played.
*/
void playFile(const std::string& path, bool idle_marked=false);
/**
* @brief Play the given number of milliseconds of silence
* @param length The length in milliseconds of the silence
* @param idle_marked Choose if the playback should be idle marked or not
*
* Use this function to play a given milliseconds of silence.
* If idle_marked is true, the isIdle function will return true when
* the silence is being played.
*/
void playSilence(int length, bool idle_marked=false);
/**
* @brief Play a sinus tone
* @param fq The frequency of the tone to play
* @param amp The amplitude of the tone to play (0-1000)
* @param length The length in milliseconds of the tone to play
* @param idle_marked Choose if the playback should be idle marked or not
*
* Use this function to play a sinus tone with the given frequency,
* amplitude and length.
* If idle_marked is true, the isIdle function will return true when
* the silence is being played.
*/
void playTone(int fq, int amp, int length, bool idle_marked=false);
/**
* @brief Check if a message is beeing written
* @return Return \em true if a message is beeing written
*/
bool isWritingMessage(void) const { return is_writing_message; }
/**
* @brief Check if the message writer is idle (ignoring idle marked items)
* @return Returns \em true if the idle or else \em false
*/
bool isIdle(void) const { return non_idle_cnt == 0; }
/**
* @brief Clear all messages
*/
void clear(void);
/**
* @brief Mark the beginning of a block of messages
*
* All the playXxx functions will be queued until the end() method is
* called. Multiple begin/end can be nested.
*/
void begin(void);
/**
* @brief Mark the end of a block of messages
*
* All the playXxx functions that have been previously queued will be
* executed.
*/
void end(void);
/**
* @brief A signal that is emitted when all messages has been written
*/
sigc::signal<void> allMsgsWritten;
/**
* @brief Resume audio output to the sink
*
* This function will be called when the registered audio sink is ready
* to accept more samples.
* This function is normally only called from a connected sink object.
*/
virtual void resumeOutput(void);
protected:
/**
* @brief The registered sink has flushed all samples
*
* This function will be called when all samples have been flushed in the
* registered sink.
* This function is normally only called from a connected sink object.
*/
virtual void allSamplesFlushed(void);
private:
std::list<QueueItem*> msg_queue;
int sample_rate;
int nesting_level;
bool pending_play_next;
QueueItem *current;
bool is_writing_message;
int non_idle_cnt;
MsgHandler(const MsgHandler&);
MsgHandler& operator=(const MsgHandler&);
void addItemToQueue(QueueItem *item);
void playMsg(void);
void writeSamples(void);
void deleteQueueItem(QueueItem *item);
void clearP(void);
}; /* class MsgHandler */
//} /* namespace */
#endif /* MSG_HANDLER_INCLUDED */
/*
* This file has not been truncated
*/
|