author | sandman <sandman> | 2002-06-18 12:46:11 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-06-18 12:46:11 (UTC) |
commit | 61e2f9e5eb634b17ef480d79bdbcbc3a715990cb (patch) (unidiff) | |
tree | 013600ee0ababcc25f37ff98cede8f67cbdc9d2a | |
parent | e21322ab34a8df36344eece685e604abe4f83fc6 (diff) | |
download | opie-61e2f9e5eb634b17ef480d79bdbcbc3a715990cb.zip opie-61e2f9e5eb634b17ef480d79bdbcbc3a715990cb.tar.gz opie-61e2f9e5eb634b17ef480d79bdbcbc3a715990cb.tar.bz2 |
Moved platform specific things from custom-*.h #defines to virtual methods
in libopie/odevice.{h,cpp}
Minor fix in Sound + reformating
-rw-r--r-- | library/custom-ipaq.h | 60 | ||||
-rw-r--r-- | library/custom-sharp.h | 53 | ||||
-rw-r--r-- | library/sound.cpp | 63 |
3 files changed, 34 insertions, 142 deletions
diff --git a/library/custom-ipaq.h b/library/custom-ipaq.h index 2886940..553b571 100644 --- a/library/custom-ipaq.h +++ b/library/custom-ipaq.h | |||
@@ -1,80 +1,20 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <unistd.h> | ||
21 | #include <stdio.h> | ||
22 | #include <signal.h> | ||
23 | #include <fcntl.h> | ||
24 | #include <sys/ioctl.h> | ||
25 | #include <linux/soundcard.h> | ||
26 | #include <qpe/resource.h> | ||
27 | #include <qsound.h> | ||
28 | #include <qpe/sound.h> | ||
29 | |||
30 | |||
31 | #ifndef QT_NO_SOUND | ||
32 | |||
33 | #define CUSTOM_SOUND_ALARM \ | ||
34 | { \ | ||
35 | int fd; \ | ||
36 | int vol; \ | ||
37 | bool vol_reset = false; \ | ||
38 | \ | ||
39 | if ((( fd = open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) || \ | ||
40 | (( fd = open ( "/dev/mixer", O_RDWR )) >= 0 )) { \ | ||
41 | \ | ||
42 | if ( ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { \ | ||
43 | Config cfg ( "qpe" ); \ | ||
44 | cfg. setGroup ( "Volume" ); \ | ||
45 | \ | ||
46 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); \ | ||
47 | if ( volalarm < 0 ) \ | ||
48 | volalarm = 0; \ | ||
49 | else if ( volalarm > 100 ) \ | ||
50 | volalarm = 100; \ | ||
51 | volalarm |= ( volalarm << 8 ); \ | ||
52 | if ( ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) \ | ||
53 | vol_reset = true; \ | ||
54 | } \ | ||
55 | } \ | ||
56 | \ | ||
57 | Sound snd ( "alarm" ); \ | ||
58 | snd. play ( ); \ | ||
59 | while ( !snd. isFinished ( )) \ | ||
60 | qApp-> processEvents ( ); \ | ||
61 | \ | ||
62 | if ( fd >= 0 ) { \ | ||
63 | if ( vol_reset ) \ | ||
64 | ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); \ | ||
65 | ::close ( fd ); \ | ||
66 | } \ | ||
67 | } | ||
68 | |||
69 | #define CUSTOM_SOUND_KEYCLICK { QSound::play ( Resource::findSound ( "keysound" )); } | ||
70 | #define CUSTOM_SOUND_TOUCH { QSound::play ( Resource::findSound ( "screensound" )); } | ||
71 | |||
72 | #else | ||
73 | |||
74 | #define CUSTOM_SOUND_ALARM { ; } | ||
75 | #define CUSTOM_SOUND_KEYCLICK { ; } | ||
76 | #define CUSTOM_SOUND_TOUCH { ; } | ||
77 | |||
78 | |||
79 | #endif | ||
80 | 20 | ||
diff --git a/library/custom-sharp.h b/library/custom-sharp.h index 08f8a6f..3dab34f 100644 --- a/library/custom-sharp.h +++ b/library/custom-sharp.h | |||
@@ -1,150 +1,97 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define QPE_OWNAPM | 21 | #define QPE_OWNAPM |
22 | #define QPE_HAVE_TOGGLELIGHT | 22 | #define QPE_HAVE_TOGGLELIGHT |
23 | #define QPE_NOCIBAUD | 23 | #define QPE_NOCIBAUD |
24 | #define QPE_STARTMENU | 24 | #define QPE_STARTMENU |
25 | #include <asm/sharp_apm.h> | 25 | #include <asm/sharp_apm.h> |
26 | #ifndef APM_IOC_BATTERY_BACK_CHK | 26 | #ifndef APM_IOC_BATTERY_BACK_CHK |
27 | #define APM_IOC_BATTERY_BACK_CHK _IO(APM_IOC_MAGIC, 32) | 27 | #define APM_IOC_BATTERY_BACK_CHK _IO(APM_IOC_MAGIC, 32) |
28 | #endif | 28 | #endif |
29 | #ifndef APM_IOC_BATTERY_MAIN_CHK | 29 | #ifndef APM_IOC_BATTERY_MAIN_CHK |
30 | #define APM_IOC_BATTERY_MAIN_CHK _IO(APM_IOC_MAGIC, 33) | 30 | #define APM_IOC_BATTERY_MAIN_CHK _IO(APM_IOC_MAGIC, 33) |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #include <unistd.h> | 33 | #include <unistd.h> |
34 | #include <stdio.h> | 34 | #include <stdio.h> |
35 | #include <signal.h> | 35 | #include <signal.h> |
36 | #include <fcntl.h> | 36 | #include <fcntl.h> |
37 | #include <sys/ioctl.h> | 37 | #include <sys/ioctl.h> |
38 | 38 | ||
39 | #define SHARP_DEV_IOCTL_COMMAND_START 0x5680 | ||
40 | |||
41 | /* --- for SHARP_BUZZER device --- */ | ||
42 | #define SHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) | ||
43 | #define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) | ||
44 | #define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) | ||
45 | #define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2) | ||
46 | #define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3) | ||
47 | #define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4) | ||
48 | #define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5) | ||
49 | |||
50 | #define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ | ||
51 | #define SHARP_BUZ_KEYSOUND 2 /* key sound */ | ||
52 | #define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */ | ||
53 | #define SHARP_PDA_WARNSOUND 4 /* warning occurred */ | ||
54 | #define SHARP_PDA_ERRORSOUND 5 /* error occurred */ | ||
55 | #define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */ | ||
56 | #define SHARP_PDA_SYSSTARTSOUND 7 /* system start */ | ||
57 | #define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */ | ||
58 | #define SHARP_PDA_APPSTART 9 /* application start */ | ||
59 | #define SHARP_PDA_APPQUIT 10 /* application ends */ | ||
60 | #define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ | ||
61 | #define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */ | ||
62 | #define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */ | ||
63 | #define SHARP_BUZ_GOT_MAIL 14 /* mail sound */ | ||
64 | |||
65 | |||
66 | #define CUSTOM_BUZZER( sound ) \ | ||
67 | { \ | ||
68 | static int fd = open( "/dev/sharp_buz", O_RDWR|O_NONBLOCK ); \ | ||
69 | ioctl( fd, SHARP_BUZZER_MAKESOUND, sound ); \ | ||
70 | } | ||
71 | |||
72 | #define CUSTOM_SOUND_ALARM CUSTOM_BUZZER( SHARP_BUZ_SCHEDULE_ALARM ) | ||
73 | #define CUSTOM_SOUND_KEYCLICK CUSTOM_BUZZER( SHARP_BUZ_KEYSOUND ) | ||
74 | #define CUSTOM_SOUND_TOUCH CUSTOM_BUZZER( SHARP_BUZ_TOUCHSOUND ) | ||
75 | |||
76 | 39 | ||
77 | #include <sys/ioctl.h> | 40 | #include <sys/ioctl.h> |
78 | #include <asm/sharp_char.h> | 41 | #include <asm/sharp_char.h> |
79 | 42 | ||
80 | // a bit awkward, as this value is defined in emailclient.cpp aswell... | ||
81 | #define LED_MAIL 0 | ||
82 | #define SHARP_LED_MAIL 9 | ||
83 | |||
84 | #define CUSTOM_LEDS( led, status ) \ | ||
85 | { \ | ||
86 | if ( led == LED_MAIL ) \ | ||
87 | led = SHARP_LED_MAIL; \ | ||
88 | static int fd = open( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); \ | ||
89 | sharp_led_status leds; \ | ||
90 | memset(&leds, 0, sizeof(leds)); \ | ||
91 | leds.which = led; \ | ||
92 | leds.status = status; \ | ||
93 | ioctl( fd, SHARP_LED_SETSTATUS, (char*)&leds ); \ | ||
94 | } | ||
95 | |||
96 | #define QPE_HAVE_MEMALERTER | 43 | #define QPE_HAVE_MEMALERTER |
97 | 44 | ||
98 | #define QPE_MEMALERTER_IMPL \ | 45 | #define QPE_MEMALERTER_IMPL \ |
99 | static void sig_handler(int sig) \ | 46 | static void sig_handler(int sig) \ |
100 | { \ | 47 | { \ |
101 | switch (sig) { \ | 48 | switch (sig) { \ |
102 | case SIGHUP: \ | 49 | case SIGHUP: \ |
103 | memstate = VeryLow; \ | 50 | memstate = VeryLow; \ |
104 | break; \ | 51 | break; \ |
105 | case SIGUSR1: \ | 52 | case SIGUSR1: \ |
106 | memstate = Normal; \ | 53 | memstate = Normal; \ |
107 | break; \ | 54 | break; \ |
108 | case SIGUSR2: \ | 55 | case SIGUSR2: \ |
109 | memstate = Low; \ | 56 | memstate = Low; \ |
110 | break; \ | 57 | break; \ |
111 | } \ | 58 | } \ |
112 | } \ | 59 | } \ |
113 | static void initMemalerter() \ | 60 | static void initMemalerter() \ |
114 | { \ | 61 | { \ |
115 | struct sigaction sa; \ | 62 | struct sigaction sa; \ |
116 | memset(&sa, '\0', sizeof sa); \ | 63 | memset(&sa, '\0', sizeof sa); \ |
117 | sa.sa_handler = sig_handler; \ | 64 | sa.sa_handler = sig_handler; \ |
118 | sa.sa_flags = SA_RESTART; \ | 65 | sa.sa_flags = SA_RESTART; \ |
119 | if (sigaction(SIGHUP, &sa, NULL) < 0) { \ | 66 | if (sigaction(SIGHUP, &sa, NULL) < 0) { \ |
120 | return; \ | 67 | return; \ |
121 | } \ | 68 | } \ |
122 | if (sigaction(SIGUSR1, &sa, NULL) < 0) { \ | 69 | if (sigaction(SIGUSR1, &sa, NULL) < 0) { \ |
123 | return; \ | 70 | return; \ |
124 | } \ | 71 | } \ |
125 | if (sigaction(SIGUSR2, &sa, NULL) < 0) { \ | 72 | if (sigaction(SIGUSR2, &sa, NULL) < 0) { \ |
126 | return; \ | 73 | return; \ |
127 | } \ | 74 | } \ |
128 | FILE *fo = fopen("/proc/sys/vm/freepg_signal_proc", "w"); \ | 75 | FILE *fo = fopen("/proc/sys/vm/freepg_signal_proc", "w"); \ |
129 | \ | 76 | \ |
130 | if (!fo) \ | 77 | if (!fo) \ |
131 | return; \ | 78 | return; \ |
132 | fprintf(fo, "qpe\n"); \ | 79 | fprintf(fo, "qpe\n"); \ |
133 | fclose(fo); \ | 80 | fclose(fo); \ |
134 | } | 81 | } |
135 | 82 | ||
136 | #define QPE_INITIAL_NUMLOCK_STATE \ | 83 | #define QPE_INITIAL_NUMLOCK_STATE \ |
137 | { \ | 84 | { \ |
138 | bool numLock = FALSE; \ | 85 | bool numLock = FALSE; \ |
139 | sharp_kbdctl_modifstat st; \ | 86 | sharp_kbdctl_modifstat st; \ |
140 | int dev = ::open("/dev/sharp_kbdctl", O_RDWR); \ | 87 | int dev = ::open("/dev/sharp_kbdctl", O_RDWR); \ |
141 | if( dev >= 0 ) { \ | 88 | if( dev >= 0 ) { \ |
142 | memset(&st, 0, sizeof(st)); \ | 89 | memset(&st, 0, sizeof(st)); \ |
143 | st.which = 3; \ | 90 | st.which = 3; \ |
144 | int ret = ioctl(dev, SHARP_KBDCTL_GETMODIFSTAT, (char*)&st); \ | 91 | int ret = ioctl(dev, SHARP_KBDCTL_GETMODIFSTAT, (char*)&st); \ |
145 | if( !ret ) \ | 92 | if( !ret ) \ |
146 | numLock = (bool)st.stat; \ | 93 | numLock = (bool)st.stat; \ |
147 | ::close(dev); \ | 94 | ::close(dev); \ |
148 | } \ | 95 | } \ |
149 | return numLock; \ | 96 | return numLock; \ |
150 | } | 97 | } |
diff --git a/library/sound.cpp b/library/sound.cpp index 602fcf0..1ff3b3f 100644 --- a/library/sound.cpp +++ b/library/sound.cpp | |||
@@ -9,185 +9,190 @@ | |||
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include <qpe/sound.h> | 22 | #include <qpe/sound.h> |
23 | #include <qpe/qcopenvelope_qws.h> | 23 | #include <qpe/qcopenvelope_qws.h> |
24 | 24 | ||
25 | #include <qsound.h> | 25 | #include <qsound.h> |
26 | #include <qfile.h> | 26 | #include <qfile.h> |
27 | 27 | ||
28 | #include <unistd.h> | 28 | #include <unistd.h> |
29 | #include <fcntl.h> | 29 | #include <fcntl.h> |
30 | #include <sys/ioctl.h> | 30 | #include <sys/ioctl.h> |
31 | #include <sys/soundcard.h> | 31 | #include <sys/soundcard.h> |
32 | 32 | ||
33 | #include "config.h" | 33 | #include "config.h" |
34 | #include <qmessagebox.h> | 34 | #include <qmessagebox.h> |
35 | #ifndef QT_NO_SOUND | 35 | #ifndef QT_NO_SOUND |
36 | static int WAVsoundDuration(const QString& filename) | 36 | static int WAVsoundDuration(const QString& filename) |
37 | { | 37 | { |
38 | // bad solution | 38 | // bad solution |
39 | 39 | ||
40 | // most of this is copied from qsoundqss.cpp | 40 | // most of this is copied from qsoundqss.cpp |
41 | 41 | ||
42 | QFile input(filename); | 42 | QFile input(filename); |
43 | if ( !input.open(IO_ReadOnly) ) | 43 | if ( !input.open(IO_ReadOnly) ) |
44 | return 0; | 44 | return 0; |
45 | 45 | ||
46 | struct QRiffChunk { | 46 | struct QRiffChunk { |
47 | char id[4]; | 47 | char id[4]; |
48 | Q_UINT32 size; | 48 | Q_UINT32 size; |
49 | char data[4/*size*/]; | 49 | char data[4/*size*/]; |
50 | } chunk; | 50 | } chunk; |
51 | 51 | ||
52 | struct { | 52 | struct { |
53 | Q_INT16 formatTag; | 53 | Q_INT16 formatTag; |
54 | Q_INT16 channels; | 54 | Q_INT16 channels; |
55 | Q_INT32 samplesPerSec; | 55 | Q_INT32 samplesPerSec; |
56 | Q_INT32 avgBytesPerSec; | 56 | Q_INT32 avgBytesPerSec; |
57 | Q_INT16 blockAlign; | 57 | Q_INT16 blockAlign; |
58 | Q_INT16 wBitsPerSample; | 58 | Q_INT16 wBitsPerSample; |
59 | } chunkdata; | 59 | } chunkdata; |
60 | 60 | ||
61 | int total = 0; | 61 | int total = 0; |
62 | 62 | ||
63 | while(1) { | 63 | while(1) { |
64 | // Keep reading chunks... | 64 | // Keep reading chunks... |
65 | const int n = sizeof(chunk)-sizeof(chunk.data); | 65 | const int n = sizeof(chunk)-sizeof(chunk.data); |
66 | if ( input.readBlock((char*)&chunk,n) != n ) | 66 | if ( input.readBlock((char*)&chunk,n) != n ) |
67 | break; | 67 | break; |
68 | if ( qstrncmp(chunk.id,"data",4) == 0 ) { | 68 | if ( qstrncmp(chunk.id,"data",4) == 0 ) { |
69 | total += chunkdata.avgBytesPerSec ? | 69 | total += chunkdata.avgBytesPerSec ? |
70 | chunk.size * 1000 / chunkdata.avgBytesPerSec : 0; | 70 | chunk.size * 1000 / chunkdata.avgBytesPerSec : 0; |
71 | //qDebug("%d bytes of PCM (%dms)", chunk.size,chunkdata.avgBytesPerSec ? chunk.size * 1000 / chunkdata.avgBytesPerSec : 0); | 71 | //qDebug("%d bytes of PCM (%dms)", chunk.size,chunkdata.avgBytesPerSec ? chunk.size * 1000 / chunkdata.avgBytesPerSec : 0); |
72 | input.at(input.at()+chunk.size-4); | 72 | input.at(input.at()+chunk.size-4); |
73 | } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { | 73 | } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { |
74 | char d[4]; | 74 | char d[4]; |
75 | if ( input.readBlock(d,4) != 4 ) | 75 | if ( input.readBlock(d,4) != 4 ) |
76 | return 0; | 76 | return 0; |
77 | if ( qstrncmp(d,"WAVE",4) != 0 ) { | 77 | if ( qstrncmp(d,"WAVE",4) != 0 ) { |
78 | // skip | 78 | // skip |
79 | //qDebug("skip %.4s RIFF chunk",d); | 79 | //qDebug("skip %.4s RIFF chunk",d); |
80 | if ( chunk.size < 10000000 ) | 80 | if ( chunk.size < 10000000 ) |
81 | (void)input.at(input.at()+chunk.size-4); | 81 | (void)input.at(input.at()+chunk.size-4); |
82 | } | 82 | } |
83 | } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) { | 83 | } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) { |
84 | if ( input.readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) ) | 84 | if ( input.readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) ) |
85 | return 0; | 85 | return 0; |
86 | #define WAVE_FORMAT_PCM 1 | 86 | #define WAVE_FORMAT_PCM 1 |
87 | if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) { | 87 | if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) { |
88 | //qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag); | 88 | //qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag); |
89 | return 0; | 89 | return 0; |
90 | } | 90 | } |
91 | } else { | 91 | } else { |
92 | //qDebug("skip %.4s chunk",chunk.id); | 92 | //qDebug("skip %.4s chunk",chunk.id); |
93 | // ignored chunk | 93 | // ignored chunk |
94 | if ( chunk.size < 10000000 ) | 94 | if ( chunk.size < 10000000 ) |
95 | (void)input.at(input.at()+chunk.size); | 95 | (void)input.at(input.at()+chunk.size); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | //qDebug("%dms",total); | 99 | //qDebug("%dms",total); |
100 | return total; | 100 | return total; |
101 | } | 101 | } |
102 | 102 | ||
103 | class SoundData : public QSound { | 103 | class SoundData : public QSound { |
104 | public: | 104 | public: |
105 | SoundData(const QString& name) : | 105 | SoundData ( const QString& name ) : |
106 | QSound(Resource::findSound(name)), | 106 | QSound ( Resource::findSound ( name )), |
107 | filename(Resource::findSound(name)) | 107 | filename ( Resource::findSound ( name )) |
108 | { | 108 | { |
109 | loopsleft=0; | 109 | loopsleft=0; |
110 | } | 110 | ms = WAVsoundDuration(filename); |
111 | } | ||
111 | 112 | ||
112 | void playLoop(int loopcnt = -1) | 113 | void playLoop ( int loopcnt = -1 ) |
113 | { | 114 | { |
114 | // needs server support | 115 | // needs server support |
115 | loopsleft = loopcnt; | 116 | loopsleft = loopcnt; |
116 | 117 | ||
117 | int ms = WAVsoundDuration(filename); | 118 | if ( ms ) |
118 | if ( ms ) | 119 | startTimer ( ms > 50 ? ms-50 : 0 ); // 50 for latency |
119 | startTimer(ms > 50 ? ms-50 : 0); // 50 for latency | 120 | play ( ); |
120 | play(); | 121 | } |
121 | } | ||
122 | 122 | ||
123 | void timerEvent ( QTimerEvent *e ) | 123 | void timerEvent ( QTimerEvent *e ) |
124 | { | 124 | { |
125 | if (loopsleft >= 0) { | 125 | if ( loopsleft >= 0 ) { |
126 | if (--loopsleft <= 0) | 126 | if ( --loopsleft <= 0 ) { |
127 | killTimer (e->timerId()); | 127 | killTimer ( e-> timerId ( )); |
128 | return; | 128 | loopsleft = 0; |
129 | } | 129 | return; |
130 | play(); | 130 | } |
131 | } | 131 | } |
132 | play(); | ||
133 | } | ||
132 | 134 | ||
133 | bool isFinished ( ) const | 135 | bool isFinished ( ) const |
134 | { | 136 | { |
135 | return ( loopsleft == 0 ); | 137 | return ( loopsleft == 0 ); |
136 | } | 138 | } |
137 | 139 | ||
138 | private: | 140 | private: |
139 | QString filename; | 141 | QString filename; |
140 | int loopsleft; | 142 | int loopsleft; |
143 | int ms; | ||
141 | }; | 144 | }; |
145 | |||
142 | #endif | 146 | #endif |
143 | 147 | ||
144 | Sound::Sound(const QString& name) | 148 | Sound::Sound(const QString& name) |
145 | { | 149 | { |
146 | #ifndef QT_NO_SOUND | 150 | #ifndef QT_NO_SOUND |
147 | d = new SoundData(name); | 151 | d = new SoundData(name); |
148 | #endif | 152 | #endif |
149 | } | 153 | } |
150 | 154 | ||
151 | Sound::~Sound() | 155 | Sound::~Sound() |
152 | { | 156 | { |
153 | #ifndef QT_NO_SOUND | 157 | #ifndef QT_NO_SOUND |
154 | delete d; | 158 | delete d; |
155 | #endif | 159 | #endif |
156 | } | 160 | } |
157 | 161 | ||
158 | void Sound::play() | 162 | void Sound::play() |
159 | { | 163 | { |
160 | #ifndef QT_NO_SOUND | 164 | #ifndef QT_NO_SOUND |
161 | d->killTimers(); | ||
162 | d->playLoop(1); | 165 | d->playLoop(1); |
163 | #endif | 166 | #endif |
164 | } | 167 | } |
165 | 168 | ||
166 | void Sound::playLoop() | 169 | void Sound::playLoop() |
167 | { | 170 | { |
168 | #ifndef QT_NO_SOUND | 171 | #ifndef QT_NO_SOUND |
169 | d->killTimers(); | 172 | d->killTimers(); |
170 | d->playLoop(); | 173 | d->playLoop(); |
171 | #endif | 174 | #endif |
172 | } | 175 | } |
173 | 176 | ||
174 | void Sound::stop() | 177 | void Sound::stop() |
175 | { | 178 | { |
176 | #ifndef QT_NO_SOUND | 179 | #ifndef QT_NO_SOUND |
177 | d->killTimers(); | 180 | d->killTimers(); |
178 | #endif | 181 | #endif |
179 | } | 182 | } |
180 | 183 | ||
181 | bool Sound::isFinished() const | 184 | bool Sound::isFinished() const |
182 | { | 185 | { |
183 | #ifndef QT_NO_SOUND | 186 | #ifndef QT_NO_SOUND |
184 | return d->isFinished(); | 187 | return d->isFinished(); |
188 | #else | ||
189 | return true; | ||
185 | #endif | 190 | #endif |
186 | } | 191 | } |
187 | 192 | ||
188 | void Sound::soundAlarm() | 193 | void Sound::soundAlarm() |
189 | { | 194 | { |
190 | #ifndef QT_NO_COP | 195 | #ifndef QT_NO_COP |
191 | QCopEnvelope( "QPE/TaskBar", "soundAlarm()" ); | 196 | QCopEnvelope( "QPE/TaskBar", "soundAlarm()" ); |
192 | #endif | 197 | #endif |
193 | } | 198 | } |