-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 16 | ||||
-rw-r--r-- | core/applets/vmemo/vmemo.h | 4 |
2 files changed, 18 insertions, 2 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index cfa07b4..63ee0b8 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp @@ -1,77 +1,78 @@ /************************************************************************************ ** ** 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. ** ************************************************************************************/ // copyright 2002 Jeremy Cowgar <jc@cowgar.com> /* * $Id$ */ // Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> #include <sys/utsname.h> #include <sys/time.h> #include <sys/types.h> #include <unistd.h> #include <stdio.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/ioctl.h> #include <linux/soundcard.h> #include <string.h> #include <stdlib.h> #include <errno.h> +#include <qtimer.h> typedef struct _waveheader { u_long main_chunk; /* 'RIFF' */ u_long length; /* filelen */ u_long chunk_type; /* 'WAVE' */ u_long sub_chunk; /* 'fmt ' */ u_long sc_len; /* length of sub_chunk, =16 (chunckSize) format len */ u_short format; /* should be 1 for PCM-code (formatTag) */ u_short modus; /* 1 Mono, 2 Stereo (channels) */ u_long sample_fq; /* samples per second (samplesPerSecond) */ u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ u_long data_chunk; /* 'data' */ u_long data_length;/* samplecount */ } WaveHeader; #define RIFF 0x46464952 #define WAVE 0x45564157 #define FMT 0x20746D66 #define DATA 0x61746164 #define PCM_CODE 1 #define WAVE_MONO 1 #define WAVE_STEREO 2 #include "vmemo.h" #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <qpe/config.h> #include <qpainter.h> #include <qdatetime.h> #include <qregexp.h> #include <qsound.h> #include <qfile.h> #include <qmessagebox.h> int seq = 0; /* XPM */ static char * vmemo_xpm[] = { "16 16 102 2", " c None", @@ -156,96 +157,99 @@ static char * vmemo_xpm[] = { "O c #000407", "P c #2D3137", "Q c #B0B1BC", "R c #3B3C40", "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; + + t_timer = new QTimer( this ); + connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); struct utsname name; /* check for embedix kernel running on the zaurus*/ if (uname(&name) != -1) { QString release=name.release; Config vmCfg("Vmemo"); vmCfg.setGroup("Defaults"); 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 ) { // QPEApplication::grabKeyboard(); 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()"); } // if( vmCfg.readNumEntry("hideIcon",0) == 1 || toggleKey > 0) // hide(); } } VMemo::~VMemo() { } void VMemo::receive( const QCString &msg, const QByteArray &data ) { QDataStream stream( data, IO_ReadOnly ); if (msg == "toggleRecord()") { if (recording) { fromToggle = TRUE; stopRecording(); } else { fromToggle = TRUE; startRecording(); } @@ -408,112 +412,113 @@ int VMemo::openDSP() perror("ioctl(\"SOUND_PCM_READ_RATE\")"); return -1; } QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute return 1; } int VMemo::openWAV(const char *filename) { track.setName(filename); if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { errorMsg=filename; return -1; } wav=track.handle(); WaveHeader wh; wh.main_chunk = RIFF; wh.length=0; wh.chunk_type = WAVE; wh.sub_chunk = FMT; wh.sc_len = 16; wh.format = PCM_CODE; wh.modus = channels; 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; QString msg; msg.sprintf("Recording format %d", format); qDebug(msg); + t_timer->start( 30 * 1000+1000, TRUE); + if(systemZaurus) { msg.sprintf("Recording format zaurus"); qDebug(msg); 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); if(length<0) recording=false; // for (int i = 0; i < result; i+=2) { // monoBuffer[j] = sound[i]; // // monoBuffer[j] = (sound[i]+sound[i+1])/2; // j++; // } qApp->processEvents(); // 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); // 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 { // 16 bit only capabilities @@ -566,48 +571,55 @@ void VMemo::record(void) // if(useAlerts) // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); qDebug("done recording "+fileName); QSound::play(Resource::findSound("vmemoe")); Config cfg("qpe"); cfg.setGroup("Volume"); QString foo = cfg.readEntry("Mute","TRUE"); if(foo.find("TRUE",0,TRUE) != -1) QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute } 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; }; } return -1; } + +void VMemo::timerBreak() { + //stop + recording=false; + + QMessageBox::message("Vmemo","Vmemo recording has \ntimed out"); +} diff --git a/core/applets/vmemo/vmemo.h b/core/applets/vmemo/vmemo.h index b33ab55..51ace35 100644 --- a/core/applets/vmemo/vmemo.h +++ b/core/applets/vmemo/vmemo.h @@ -1,59 +1,63 @@ /**************************************************************************************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> #include <qlabel.h> +#include <qtimer.h> class VMemo : public QWidget { Q_OBJECT public: VMemo( QWidget *parent, const char *name = NULL); ~VMemo(); QFile track; QString fileName, errorMsg; QLabel* msgLabel; + QTimer *t_timer; + public slots: void record(); void mousePressEvent( QMouseEvent * ); void mouseReleaseEvent( QMouseEvent * ); void receive( const QCString &msg, const QByteArray &data ); bool startRecording(); void stopRecording(); + void timerBreak(); 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__ |