dsm: adds utils.playRingTone() function

development of this sponsored by TelTech Systems Inc.
sayer/1.4-spce2.6
Stefan Sayer 16 years ago
parent ea20cfa4da
commit f9439a1dd4

@ -33,6 +33,7 @@
#include "DSMSession.h"
#include "AmSession.h"
#include "AmPlaylist.h"
SC_EXPORT(MOD_CLS_NAME);
@ -48,6 +49,8 @@ MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
DEF_CMD("utils.sub", SCUSSubAction);
DEF_CMD("utils.int", SCUIntAction);
DEF_CMD("utils.splitStringCR", SCUSplitStringAction);
DEF_CMD("utils.playRingTone", SCUPlayRingToneAction);
} MOD_ACTIONEXPORT_END;
MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
@ -238,3 +241,39 @@ EXEC_ACTION_START(SCUSplitStringAction) {
last_p = p+1;
}
} EXEC_ACTION_END;
CONST_ACTION_2P(SCUPlayRingToneAction, ',', true);
EXEC_ACTION_START(SCUPlayRingToneAction) {
int length = 0;
int rtparams[4] = {2000, 4000, 440, 480}; // US
string s_length = resolveVars(par1, sess, sc_sess, event_params);
if (!str2int(s_length, length)) {
WARN("could not decipher ringtone length: '%s'\n", s_length.c_str());
}
vector<string> r_params = explode(par2, ",");
for (vector<string>::iterator it=
r_params.begin(); it !=r_params.end(); it++) {
string p = resolveVars(*it, sess, sc_sess, event_params);
if (p.empty())
continue;
if (!str2int(p, rtparams[it-r_params.begin()])) {
WARN("could not decipher ringtone parameter %u: '%s', using default\n",
it-r_params.begin(), p.c_str());
continue;
}
}
DBG("Playing ringtone length %d, on %d, off %d, f %d, f2 %d\n",
length, rtparams[0], rtparams[1], rtparams[2], rtparams[3]);
DSMRingTone* rt = new DSMRingTone(length, rtparams[0], rtparams[1],
rtparams[2], rtparams[3]);
sc_sess->addToPlaylist(new AmPlaylistItem(rt, NULL));
sc_sess->transferOwnership(rt);
} EXEC_ACTION_END;

@ -28,6 +28,9 @@
#define _MOD_UTILS_H
#include "DSMModule.h"
#include "AmRingTone.h"
#include "DSMSession.h"
#define MOD_CLS_NAME SCUtilsModule
DECLARE_MODULE(MOD_CLS_NAME);
@ -42,4 +45,17 @@ DEF_ACTION_2P(SCUSAddAction);
DEF_ACTION_2P(SCUSSubAction);
DEF_ACTION_2P(SCUIntAction);
DEF_ACTION_2P(SCUSplitStringAction);
DEF_ACTION_2P(SCUPlayRingToneAction);
class DSMRingTone
: public AmRingTone,
public DSMDisposable
{
public:
DSMRingTone(int length, int on, int off, int f, int f2=0)
: AmRingTone(length, on, off, f, f2) { }
~DSMRingTone() { }
};
#endif

@ -41,3 +41,10 @@ Actions:
example:
sys.popen($myresult="/bin/ls wav/*");
utils.splitStringCR($myresult);
utils.playRingTone(length [, on [, off [, f [, f2]]]])
play a RingTone (ringback tone)
defaults to length=0 (indefinite), on 1000ms, off 2000ms, f 440Hz, f2 480Hz
Example:
utils.playRingTone(0, 1000, 4000, 425, 0); -- Germany

Loading…
Cancel
Save