summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp78
-rw-r--r--core/applets/vmemo/vmemo.h6
2 files changed, 72 insertions, 12 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index f5d2b20..e327098 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -192,36 +192,38 @@ static char * vmemo_xpm[] = {
" @.#.$.%.&. ",
" *.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;
- Config vmCfg("VMemo");
+ Config vmCfg("Vmemo");
vmCfg.setGroup("Defaults");
- int toggleKey = vmCfg.readNumEntry("toggleKey", -1);
-
+ int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1));
+
+ qDebug("toggleKey %d", toggleKey);
+
if(release.find("embedix",0,TRUE) !=-1)
systemZaurus=TRUE;
else
systemZaurus=FALSE;
myChannel = new QCopChannel( "QPE/VMemo", this );
connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)),
this, SLOT(receive(const QCString&, const QByteArray&)) );
if( toggleKey != -1 ) {
QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)");
// e << 4096; // Key_Escape
// e << Key_F5; //4148
e << toggleKey;
e << QString("QPE/VMemo");
e << QString("toggleRecord()");
@@ -256,47 +258,55 @@ void VMemo::paintEvent( QPaintEvent* )
}
void VMemo::mousePressEvent( QMouseEvent * )
{
startRecording();
}
void VMemo::mouseReleaseEvent( QMouseEvent * )
{
stopRecording();
}
bool VMemo::startRecording() {
if ( recording)
return FALSE;;
- Config config( "Vmemo" );
+
+ Config config( "Vmemo" );
config.setGroup( "System" );
+
useAlerts = config.readBoolEntry("Alert");
+ if(useAlerts) {
+
+ msgLabel = new QLabel( 0, "alertLabel" );
+ msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>");
+ msgLabel->show();
+ }
// 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");
+ QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort");
recording = FALSE;
return FALSE;
}
config.setGroup("Defaults");
QDateTime dt = QDateTime::currentDateTime();
QString fName;
config.setGroup( "System" );
fName = QPEApplication::documentDir() ;
fileName = config.readEntry("RecLocation", fName);
int s;
s=fileName.find(':');
if(s)
@@ -306,55 +316,58 @@ bool VMemo::startRecording() {
fileName="/"+fileName;
if( fileName.right(1).find('/') == -1)
fileName+="/";
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");
+ QMessageBox::critical(0, "vmemo", err, "Abort");
close(dsp);
return FALSE;
}
QArray<int> cats(1);
cats[0] = config.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::stopRecording() {
recording = FALSE;
+ if(useAlerts)
+ if( msgLabel) delete msgLabel;
}
int VMemo::openDSP()
{
Config cfg("Vmemo");
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;
}
@@ -416,56 +429,66 @@ int VMemo::openWAV(const char *filename)
wh.sample_fq = speed;
wh.byte_p_sec = speed * channels * resolution/8;
wh.byte_p_spl = channels * (resolution / 8);
wh.bit_p_spl = resolution;
wh.data_chunk = DATA;
wh.data_length= 0;
// qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d"
// , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl );
write (wav, &wh, sizeof(WaveHeader));
return 1;
}
void VMemo::record(void)
{
int length=0, result, value;
- qDebug("Recording");
+ QString msg;
+ msg.sprintf("Recording format %d", format);
+ qDebug(msg);
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);
}
+ qApp->processEvents();
// printf("%d\r",length);
// fflush(stdout);
}
- } else { //AFMT_U8
+ } 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);
@@ -494,21 +517,56 @@ void VMemo::record(void)
// 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);
+// if(useAlerts)
+// QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName);
qDebug("done recording "+fileName);
QSound::play(Resource::findSound("vmemoe"));
}
+
+int VMemo::setToggleButton(int tog) {
+
+ for( int i=0; i < 10;i++) {
+ switch (tog) {
+ case 0:
+ return -1;
+ break;
+ case 1:
+ return 0;
+ break;
+ case 2:
+ return Key_Escape;
+ break;
+ case 3:
+ return Key_Space;
+ break;
+ case 4:
+ return Key_F12;
+ break;
+ case 5:
+ return Key_F9;
+ break;
+ case 6:
+ return Key_F10;
+ break;
+ case 7:
+ return Key_F11;
+ break;
+ case 8:
+ return Key_F13;
+ break;
+ };
+ }
+}
diff --git a/core/applets/vmemo/vmemo.h b/core/applets/vmemo/vmemo.h
index 701663f..b33ab55 100644
--- a/core/applets/vmemo/vmemo.h
+++ b/core/applets/vmemo/vmemo.h
@@ -4,54 +4,56 @@
** 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>
+#include <qlabel.h>
class VMemo : public QWidget
{
Q_OBJECT
public:
VMemo( QWidget *parent, const char *name = NULL);
~VMemo();
QFile track;
QString fileName, errorMsg;
-
+ QLabel* msgLabel;
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 setToggleButton(int);
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__