summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp68
-rw-r--r--core/applets/vmemo/vmemo.h5
2 files changed, 39 insertions, 34 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index e14d532..7e91ef0 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -160,229 +160,233 @@ static char * vmemo_xpm[] = {
"S c #6E6E74",
"T c #95959C",
"U c #74747A",
"V c #1D1D1E",
"W c #91929A",
"X c #42444A",
"Y c #22282E",
"Z c #B0B2BC",
"` c #898A90",
" . c #65656A",
".. c #999AA2",
"+. c #52535A",
"@. c #151B21",
"#. c #515257",
"$. c #B5B5BE",
"%. c #616167",
"&. c #1A1D22",
"*. c #000713",
"=. c #1F1F21",
" ",
" . + @ # ",
" $ % & * = - ",
" ; > , ' ) ! ~ ",
" { ] ^ / ( _ : ",
" < [ } | 1 2 3 ",
" 4 5 6 7 8 9 0 a b c ",
" d e f g h i j 3 k l m n ",
" o p q r s t u v w n ",
" o x y z A B C D E n ",
" F G H I J K L M N O ",
" P Q R S T U V W X ",
" Y Z ` b ...+. ",
" @.#.$.%.&. ",
" *.B =. ",
" n n n n n n n n n "};
VMemo::VMemo( QWidget *parent, const char *_name )
: QWidget( parent, _name )
{
setFixedHeight( 18 );
setFixedWidth( 14 );
recording = FALSE;
struct utsname name; /* check for embedix kernel running on the zaurus*/
if (uname(&name) != -1) {
QString release=name.release;
- if(release.find("embedix",0,TRUE) !=-1)
+ Config vmCfg("VMemo");
+ vmCfg.setGroup("Defaults");
+
+ if(release.find("embedix",0,TRUE) !=-1) {
+ int toggleKey = vmCfg.readNumEntry("toggleKey", -1);
systemZaurus=TRUE;
- else {
+ } else {
+ int toggleKey = vmCfg.readNumEntry("toggleKey", 4096);
+//default key for ipaq record button is Key_Escape = 4096
systemZaurus=FALSE;
+ }
+
myChannel = new QCopChannel( "QPE/VMemo", this );
connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)),
this, SLOT(receive(const QCString&, const QByteArray&)) );
-// // Register the REC key press, for ipaq only
+ if( toggleKey != -1 ) {
QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)");
- e << 4096;
+// e << 4096; // Key_Escape
+// e << Key_F5; //4148
+ e << toggleKey;
e << QString("QPE/VMemo");
e << QString("toggleRecord()");
}
}
}
VMemo::~VMemo()
{
}
void VMemo::receive( const QCString &msg, const QByteArray &data )
{
QDataStream stream( data, IO_ReadOnly );
if (msg == "toggleRecord()") {
- if (recording)
- mouseReleaseEvent(NULL);
- else
- mousePressEvent(NULL);
+ if (recording) {
+ fromToggle = TRUE;
+ stopRecording();
+ } else {
+ fromToggle = TRUE;
+ startRecording();
+ }
}
}
void VMemo::paintEvent( QPaintEvent* )
{
QPainter p(this);
p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
}
-void VMemo::mousePressEvent( QMouseEvent *me )
+void VMemo::mousePressEvent( QMouseEvent * )
{
- // just to be safe
- if (recording) {
- recording = FALSE;
- return;
+ startRecording();
}
- /*
- No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions
- mousePressEvent and mouseReleaseEvent with a NULL parameter.
- */
-// #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
-// if (!systemZaurus )
-// return;
-// #endif
+void VMemo::mouseReleaseEvent( QMouseEvent * )
+{
+ stopRecording();
+}
+
+bool VMemo::startRecording() {
+ if ( recording)
+ return FALSE;;
Config config( "Sound" );
config.setGroup( "System" );
useAlerts = config.readBoolEntry("Alert");
// if(useAlerts)
// QMessageBox::message("VMemo","Really Record?");//) ==1)
// return;
// } else {
if (!systemZaurus )
QSound::play(Resource::findSound("vmemob"));
// }
qDebug("Start recording");
recording = TRUE;
if (openDSP() == -1) {
QMessageBox::critical(0, "VMemo", "Could not open dsp device.\n"+errorMsg, "Abort");
recording = FALSE;
- return;
+ return FALSE;
}
Config vmCfg("VMemo");
vmCfg.setGroup("Defaults");
QDateTime dt = QDateTime::currentDateTime();
QString fName;
Config cfg( "Sound" );
cfg.setGroup( "System" );
fName = QPEApplication::documentDir() ;
fileName = cfg.readEntry("RecLocation", fName);
int s;
s=fileName.find(':');
if(s)
fileName=fileName.right(fileName.length()-s-2);
qDebug("filename will be "+fileName);
if( fileName.right(1).find('/') == -1)
fileName+="/";
-
-// if(systemZaurus)
-// fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs
-// else
-// fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/");
-
fName = "vm_"+ dt.toString()+ ".wav";
fileName+=fName;
qDebug("filename is "+fileName);
// No spaces in the filename
fileName.replace(QRegExp("'"),"");
fileName.replace(QRegExp(" "),"_");
fileName.replace(QRegExp(":"),".");
fileName.replace(QRegExp(","),"");
if(openWAV(fileName.latin1()) == -1) {
QString err("Could not open the output file\n");
err += fileName;
QMessageBox::critical(0, "VMemo", err, "Abort");
close(dsp);
- return;
+ return FALSE;
}
QArray<int> cats(1);
cats[0] = vmCfg.readNumEntry("Category", 0);
QString dlName("vm_");
dlName += dt.toString();
DocLnk l;
l.setFile(fileName);
l.setName(dlName);
l.setType("audio/x-wav");
l.setCategories(cats);
l.writeLink();
record();
+ return TRUE;
}
-void VMemo::mouseReleaseEvent( QMouseEvent * )
-{
+void VMemo::stopRecording() {
recording = FALSE;
}
int VMemo::openDSP()
{
Config cfg("Sound");
cfg.setGroup("Record");
speed = cfg.readNumEntry("SampleRate", 22050);
channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
if (cfg.readNumEntry("SixteenBit", 1)==1) {
format = AFMT_S16_LE;
resolution = 16;
} else {
format = AFMT_U8;
resolution = 8;
}
qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution);
if(systemZaurus) {
dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1
channels=1; //zaurus has one input channel
} else {
dsp = open("/dev/dsp", O_RDWR);
}
if(dsp == -1) {
perror("open(\"/dev/dsp\")");
errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno);
return -1;
}
if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) {
perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
errorMsg="ioctl(\"SNDCTL_DSP_SETFMT\")\n%d\n"+(QString)strerror(errno),format;
return -1;
}
if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) {
perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
errorMsg="ioctl(\"SNDCTL_DSP_CHANNELS\")\n%d\n"+(QString)strerror(errno),channels;
return -1;
}
if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) {
perror("ioctl(\"SNDCTL_DSP_SPEED\")");
errorMsg="ioctl(\"SNDCTL_DSP_SPEED\")\n%d\n"+(QString)strerror(errno),speed;
return -1;
}
@@ -434,82 +438,82 @@ void VMemo::record(void)
if(systemZaurus) {
signed short sound[512], monoBuffer[512];
if(format==AFMT_S16_LE) {
while(recording) {
result = read(dsp, sound, 512); // 8192
int j=0;
if(systemZaurus) {
for (int i = 0; i < result; i++) { //since Z is mono do normally
monoBuffer[i] = sound[i];
}
length+=write(wav, monoBuffer, result);
} else { //ipaq /stereo inputs
for (int i = 0; i < result; i+=2) {
monoBuffer[j] = (sound[i]+sound[i+1])/2;
j++;
}
length+=write(wav, monoBuffer, result/2);
}
// printf("%d\r",length);
// fflush(stdout);
}
} else { //AFMT_U8
// 8bit unsigned
unsigned short sound[512], monoBuffer[512];
while(recording) {
result = read(dsp, sound, 512); // 8192
int j=0;
if(systemZaurus) {
for (int i = 0; i < result; i++) { //since Z is mono do normally
monoBuffer[i] = sound[i];
}
length+=write(wav, monoBuffer, result);
} else { //ipaq /stereo inputs
for (int i = 0; i < result; i+=2) {
monoBuffer[j] = (sound[i]+sound[i+1])/2;
j++;
}
length+=write(wav, monoBuffer, result/2);
}
length += result;
// printf("%d\r",length);
// fflush(stdout);
}
qApp->processEvents();
}
- } else {
+ } else { // this is specific for ipaqs that do not have 8 bit capabilities
signed short sound[512], monoBuffer[512];
while(recording) {
result = read(dsp, sound, 512); // 8192
write(wav, sound, result);
length += result;
qApp->processEvents();
}
// printf("%d\r",length);
// fflush(stdout);
// qDebug("file has length of %d lasting %d seconds",
// length, (( length / speed) / channels) / 2 );
// medialplayer states wrong length in secs
}
value = length+36;
lseek(wav, 4, SEEK_SET);
write(wav, &value, 4);
lseek(wav, 40, SEEK_SET);
write(wav, &length, 4);
track.close();
if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)
perror("ioctl(\"SNDCTL_DSP_RESET\")");
::close(dsp);
fileName = fileName.left(fileName.length()-4);
if(useAlerts)
QMessageBox::message("Vmemo"," Done recording\n"+ fileName);
qDebug("done recording "+fileName);
QSound::play(Resource::findSound("vmemoe"));
}
diff --git a/core/applets/vmemo/vmemo.h b/core/applets/vmemo/vmemo.h
index 3972877..701663f 100644
--- a/core/applets/vmemo/vmemo.h
+++ b/core/applets/vmemo/vmemo.h
@@ -1,56 +1,57 @@
/**************************************************************************************94x78**
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
*********************************************************************************************/
/*
* $Id$
*/
#ifndef __VMEMO_H__
#define __VMEMO_H__
#include <qwidget.h>
#include <qpixmap.h>
#include <qpe/applnk.h>
#include <qfile.h>
#include <qpe/qcopenvelope_qws.h>
class VMemo : public QWidget
{
Q_OBJECT
public:
VMemo( QWidget *parent, const char *name = NULL);
~VMemo();
QFile track;
QString fileName, errorMsg;
public slots:
void record();
void mousePressEvent( QMouseEvent * );
void mouseReleaseEvent( QMouseEvent * );
void receive( const QCString &msg, const QByteArray &data );
-
+ bool startRecording();
+ void stopRecording();
private:
bool useAlerts;
void paintEvent( QPaintEvent* );
int openDSP();
int openWAV(const char *filename);
-
+ bool fromToggle;
QPixmap vmemoPixmap;
QCopChannel *myChannel;
bool systemZaurus;
int dsp, wav, rate, speed, channels, format, resolution;
bool recording;
};
#endif // __VMEMO_H__