author | llornkcor <llornkcor> | 2002-06-29 05:31:39 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-06-29 05:31:39 (UTC) |
commit | 0252b90a4b2e7be6186518eaa12ea03ef26ae08c (patch) (unidiff) | |
tree | 89ee92dbbe5475da4c527a9fb67fd1bb9ccb1b14 | |
parent | 444ccb7e2adcb9b6690c6f9bba2c9185213e3ee7 (diff) | |
download | opie-0252b90a4b2e7be6186518eaa12ea03ef26ae08c.zip opie-0252b90a4b2e7be6186518eaa12ea03ef26ae08c.tar.gz opie-0252b90a4b2e7be6186518eaa12ea03ef26ae08c.tar.bz2 |
take out resource intensive animated button, that I bet no one knew was there anyway.
-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 4 | ||||
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 18 |
2 files changed, 11 insertions, 11 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp index 59e06a6..abbe5c8 100644 --- a/core/multimedia/opieplayer/audiodevice.cpp +++ b/core/multimedia/opieplayer/audiodevice.cpp | |||
@@ -1,389 +1,389 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of 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 | // L.J.Potter added better error code Fri 02-15-2002 14:37:47 | 20 | // L.J.Potter added better error code Fri 02-15-2002 14:37:47 |
21 | 21 | ||
22 | 22 | ||
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <stdio.h> | 24 | #include <stdio.h> |
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | #include <qpe/config.h> | 26 | #include <qpe/config.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | 28 | ||
29 | #include "audiodevice.h" | 29 | #include "audiodevice.h" |
30 | 30 | ||
31 | 31 | ||
32 | #include <errno.h> | 32 | #include <errno.h> |
33 | 33 | ||
34 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 34 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
35 | #include "qpe/qcopenvelope_qws.h" | 35 | #include "qpe/qcopenvelope_qws.h" |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | // #ifdef Q_WS_WIN | 38 | // #ifdef Q_WS_WIN |
39 | // #include <windows.h> | 39 | // #include <windows.h> |
40 | // #include <mmsystem.h> | 40 | // #include <mmsystem.h> |
41 | // #include <mmreg.h> | 41 | // #include <mmreg.h> |
42 | // #endif | 42 | // #endif |
43 | #if defined(Q_WS_X11) || defined(Q_WS_QWS) | 43 | #if defined(Q_WS_X11) || defined(Q_WS_QWS) |
44 | #include <fcntl.h> | 44 | #include <fcntl.h> |
45 | #include <sys/ioctl.h> | 45 | #include <sys/ioctl.h> |
46 | #include <sys/soundcard.h> | 46 | #include <sys/soundcard.h> |
47 | #include <sys/stat.h> | 47 | #include <sys/stat.h> |
48 | #include <sys/time.h> | 48 | #include <sys/time.h> |
49 | #include <sys/types.h> | 49 | #include <sys/types.h> |
50 | #include <unistd.h> | 50 | #include <unistd.h> |
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | // #if defined(Q_OS_WIN32) | 53 | // #if defined(Q_OS_WIN32) |
54 | // static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000; | 54 | // static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000; |
55 | // static const int timerResolutionMilliSeconds = 30; | 55 | // static const int timerResolutionMilliSeconds = 30; |
56 | // static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond; | 56 | // static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond; |
57 | // #else | 57 | // #else |
58 | # if defined(QT_QWS_IPAQ) | 58 | # if defined(QT_QWS_IPAQ) |
59 | static const int sound_fragment_shift = 14; | 59 | static const int sound_fragment_shift = 14; |
60 | # else | 60 | # else |
61 | static const int sound_fragment_shift = 16; | 61 | static const int sound_fragment_shift = 16; |
62 | # endif | 62 | # endif |
63 | static const int sound_fragment_bytes = (1<<sound_fragment_shift); | 63 | static const int sound_fragment_bytes = (1<<sound_fragment_shift); |
64 | //#endif | 64 | //#endif |
65 | 65 | ||
66 | 66 | ||
67 | class AudioDevicePrivate { | 67 | class AudioDevicePrivate { |
68 | public: | 68 | public: |
69 | int handle; | 69 | int handle; |
70 | unsigned int frequency; | 70 | unsigned int frequency; |
71 | unsigned int channels; | 71 | unsigned int channels; |
72 | unsigned int bytesPerSample; | 72 | unsigned int bytesPerSample; |
73 | unsigned int bufferSize; | 73 | unsigned int bufferSize; |
74 | //#ifndef Q_OS_WIN32 | 74 | //#ifndef Q_OS_WIN32 |
75 | bool can_GETOSPACE; | 75 | bool can_GETOSPACE; |
76 | char* unwrittenBuffer; | 76 | char* unwrittenBuffer; |
77 | unsigned int unwritten; | 77 | unsigned int unwritten; |
78 | //#endif | 78 | //#endif |
79 | 79 | ||
80 | static int dspFd; | 80 | static int dspFd; |
81 | static bool muted; | 81 | static bool muted; |
82 | static unsigned int leftVolume; | 82 | static unsigned int leftVolume; |
83 | static unsigned int rightVolume; | 83 | static unsigned int rightVolume; |
84 | }; | 84 | }; |
85 | 85 | ||
86 | 86 | ||
87 | #ifdef Q_WS_QWS | 87 | #ifdef Q_WS_QWS |
88 | // This is for keeping the device open in-between playing files when | 88 | // This is for keeping the device open in-between playing files when |
89 | // the device makes clicks and it starts to drive you insane! :) | 89 | // the device makes clicks and it starts to drive you insane! :) |
90 | // Best to have the device not open when not using it though | 90 | // Best to have the device not open when not using it though |
91 | //#define KEEP_DEVICE_OPEN | 91 | //#define KEEP_DEVICE_OPEN |
92 | #endif | 92 | #endif |
93 | 93 | ||
94 | 94 | ||
95 | int AudioDevicePrivate::dspFd = 0; | 95 | int AudioDevicePrivate::dspFd = 0; |
96 | bool AudioDevicePrivate::muted = FALSE; | 96 | bool AudioDevicePrivate::muted = FALSE; |
97 | unsigned int AudioDevicePrivate::leftVolume = 0; | 97 | unsigned int AudioDevicePrivate::leftVolume = 0; |
98 | unsigned int AudioDevicePrivate::rightVolume = 0; | 98 | unsigned int AudioDevicePrivate::rightVolume = 0; |
99 | 99 | ||
100 | 100 | ||
101 | void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { | 101 | void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { |
102 | muted = AudioDevicePrivate::muted; | 102 | muted = AudioDevicePrivate::muted; |
103 | unsigned int volume; | 103 | unsigned int volume; |
104 | // #ifdef Q_OS_WIN32 | 104 | // #ifdef Q_OS_WIN32 |
105 | // HWAVEOUT handle; | 105 | // HWAVEOUT handle; |
106 | // WAVEFORMATEX formatData; | 106 | // WAVEFORMATEX formatData; |
107 | // formatData.cbSize = sizeof(WAVEFORMATEX); | 107 | // formatData.cbSize = sizeof(WAVEFORMATEX); |
108 | // formatData.wFormatTag = WAVE_FORMAT_PCM; | 108 | // formatData.wFormatTag = WAVE_FORMAT_PCM; |
109 | // formatData.nAvgBytesPerSec = 4 * 44000; | 109 | // formatData.nAvgBytesPerSec = 4 * 44000; |
110 | // formatData.nBlockAlign = 4; | 110 | // formatData.nBlockAlign = 4; |
111 | // formatData.nChannels = 2; | 111 | // formatData.nChannels = 2; |
112 | // formatData.nSamplesPerSec = 44000; | 112 | // formatData.nSamplesPerSec = 44000; |
113 | // formatData.wBitsPerSample = 16; | 113 | // formatData.wBitsPerSample = 16; |
114 | // waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); | 114 | // waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); |
115 | // if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) | 115 | // if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) |
116 | // // qDebug( "get volume of audio device failed" ); | 116 | // // qDebug( "get volume of audio device failed" ); |
117 | // waveOutClose( handle ); | 117 | // waveOutClose( handle ); |
118 | // leftVolume = volume & 0xFFFF; | 118 | // leftVolume = volume & 0xFFFF; |
119 | // rightVolume = volume >> 16; | 119 | // rightVolume = volume >> 16; |
120 | // #else | 120 | // #else |
121 | int mixerHandle = open( "/dev/mixer", O_RDWR ); | 121 | int mixerHandle = open( "/dev/mixer", O_RDWR ); |
122 | if ( mixerHandle >= 0 ) { | 122 | if ( mixerHandle >= 0 ) { |
123 | if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) | 123 | if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) |
124 | perror("ioctl(\"MIXER_READ\")"); | 124 | perror("ioctl(\"MIXER_READ\")"); |
125 | close( mixerHandle ); | 125 | close( mixerHandle ); |
126 | } else | 126 | } else |
127 | perror("open(\"/dev/mixer\")"); | 127 | perror("open(\"/dev/mixer\")"); |
128 | leftVolume = ((volume & 0x00FF) << 16) / 101; | 128 | leftVolume = ((volume & 0x00FF) << 16) / 101; |
129 | rightVolume = ((volume & 0xFF00) << 8) / 101; | 129 | rightVolume = ((volume & 0xFF00) << 8) / 101; |
130 | //#endif | 130 | //#endif |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { | 134 | void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { |
135 | AudioDevicePrivate::muted = muted; | 135 | AudioDevicePrivate::muted = muted; |
136 | if ( muted ) { | 136 | if ( muted ) { |
137 | AudioDevicePrivate::leftVolume = leftVolume; | 137 | AudioDevicePrivate::leftVolume = leftVolume; |
138 | AudioDevicePrivate::rightVolume = rightVolume; | 138 | AudioDevicePrivate::rightVolume = rightVolume; |
139 | leftVolume = 0; | 139 | leftVolume = 0; |
140 | rightVolume = 0; | 140 | rightVolume = 0; |
141 | } else { | 141 | } else { |
142 | leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); | 142 | leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); |
143 | rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); | 143 | rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); |
144 | } | 144 | } |
145 | // #ifdef Q_OS_WIN32 | 145 | // #ifdef Q_OS_WIN32 |
146 | // HWAVEOUT handle; | 146 | // HWAVEOUT handle; |
147 | // WAVEFORMATEX formatData; | 147 | // WAVEFORMATEX formatData; |
148 | // formatData.cbSize = sizeof(WAVEFORMATEX); | 148 | // formatData.cbSize = sizeof(WAVEFORMATEX); |
149 | // formatData.wFormatTag = WAVE_FORMAT_PCM; | 149 | // formatData.wFormatTag = WAVE_FORMAT_PCM; |
150 | // formatData.nAvgBytesPerSec = 4 * 44000; | 150 | // formatData.nAvgBytesPerSec = 4 * 44000; |
151 | // formatData.nBlockAlign = 4; | 151 | // formatData.nBlockAlign = 4; |
152 | // formatData.nChannels = 2; | 152 | // formatData.nChannels = 2; |
153 | // formatData.nSamplesPerSec = 44000; | 153 | // formatData.nSamplesPerSec = 44000; |
154 | // formatData.wBitsPerSample = 16; | 154 | // formatData.wBitsPerSample = 16; |
155 | // waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); | 155 | // waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); |
156 | // unsigned int volume = (rightVolume << 16) | leftVolume; | 156 | // unsigned int volume = (rightVolume << 16) | leftVolume; |
157 | // if ( waveOutSetVolume( handle, volume ) ) | 157 | // if ( waveOutSetVolume( handle, volume ) ) |
158 | // // qDebug( "set volume of audio device failed" ); | 158 | // // qDebug( "set volume of audio device failed" ); |
159 | // waveOutClose( handle ); | 159 | // waveOutClose( handle ); |
160 | // #else | 160 | // #else |
161 | // Volume can be from 0 to 100 which is 101 distinct values | 161 | // Volume can be from 0 to 100 which is 101 distinct values |
162 | unsigned int rV = (rightVolume * 101) >> 16; | 162 | unsigned int rV = (rightVolume * 101) >> 16; |
163 | 163 | ||
164 | # if 0 | 164 | # if 0 |
165 | unsigned int lV = (leftVolume * 101) >> 16; | 165 | unsigned int lV = (leftVolume * 101) >> 16; |
166 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); | 166 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); |
167 | int mixerHandle = 0; | 167 | int mixerHandle = 0; |
168 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 168 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
169 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) | 169 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) |
170 | perror("ioctl(\"MIXER_WRITE\")"); | 170 | perror("ioctl(\"MIXER_WRITE\")"); |
171 | close( mixerHandle ); | 171 | close( mixerHandle ); |
172 | } else | 172 | } else |
173 | perror("open(\"/dev/mixer\")"); | 173 | perror("open(\"/dev/mixer\")"); |
174 | 174 | ||
175 | # else | 175 | # else |
176 | // This is the way this has to be done now I guess, doesn't allow for | 176 | // This is the way this has to be done now I guess, doesn't allow for |
177 | // independant right and left channel setting, or setting for different outputs | 177 | // independant right and left channel setting, or setting for different outputs |
178 | Config cfg("qpe"); // qtopia is "Sound" | 178 | Config cfg("qpe"); // qtopia is "Sound" |
179 | cfg.setGroup("Volume"); // qtopia is "Settings" | 179 | cfg.setGroup("Volume"); // qtopia is "Settings" |
180 | cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume | 180 | cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume |
181 | # endif | 181 | # endif |
182 | 182 | ||
183 | //#endif | 183 | //#endif |
184 | // qDebug( "setting volume to: 0x%x", volume ); | 184 | // qDebug( "setting volume to: 0x%x", volume ); |
185 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 185 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
186 | // Send notification that the volume has changed | 186 | // Send notification that the volume has changed |
187 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; | 187 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; |
188 | #endif | 188 | #endif |
189 | } | 189 | } |
190 | 190 | ||
191 | 191 | ||
192 | 192 | ||
193 | 193 | ||
194 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | 194 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { |
195 | qDebug("creating new audio device"); | 195 | qDebug("creating new audio device"); |
196 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; | 196 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; |
197 | d = new AudioDevicePrivate; | 197 | d = new AudioDevicePrivate; |
198 | d->frequency = f; | 198 | d->frequency = f; |
199 | d->channels = chs; | 199 | d->channels = chs; |
200 | d->bytesPerSample = bps; | 200 | d->bytesPerSample = bps; |
201 | qDebug("%d",bps); | 201 | qDebug("%d",bps); |
202 | int format=0; | 202 | int format=0; |
203 | if( bps == 8) format = AFMT_U8; | 203 | if( bps == 8) format = AFMT_U8; |
204 | else if( bps <= 0) format = AFMT_S16_LE; | 204 | else if( bps <= 0) format = AFMT_S16_LE; |
205 | else format = AFMT_S16_LE; | 205 | else format = AFMT_S16_LE; |
206 | qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); | 206 | qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); |
207 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); | 207 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); |
208 | 208 | ||
209 | int fragments = 0x10000 * 8 + sound_fragment_shift; | 209 | int fragments = 0x10000 * 8 + sound_fragment_shift; |
210 | int capabilities = 0; | 210 | int capabilities = 0; |
211 | 211 | ||
212 | 212 | ||
213 | #ifdef KEEP_DEVICE_OPEN | 213 | #ifdef KEEP_DEVICE_OPEN |
214 | if ( AudioDevicePrivate::dspFd == 0 ) { | 214 | if ( AudioDevicePrivate::dspFd == 0 ) { |
215 | #endif | 215 | #endif |
216 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { | 216 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { |
217 | 217 | ||
218 | // perror("open(\"/dev/dsp\") sending to /dev/null instead"); | 218 | // perror("open(\"/dev/dsp\") sending to /dev/null instead"); |
219 | perror("open(\"/dev/dsp\")"); | 219 | perror("open(\"/dev/dsp\")"); |
220 | QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now."); | 220 | QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now."); |
221 | QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort")); | 221 | QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort")); |
222 | exit(-1); //harsh? | 222 | exit(-1); //harsh? |
223 | // d->handle = ::open( "/dev/null", O_WRONLY ); | 223 | // d->handle = ::open( "/dev/null", O_WRONLY ); |
224 | // WTF?!?! | 224 | // WTF?!?! |
225 | } | 225 | } |
226 | #ifdef KEEP_DEVICE_OPEN | 226 | #ifdef KEEP_DEVICE_OPEN |
227 | AudioDevicePrivate::dspFd = d->handle; | 227 | AudioDevicePrivate::dspFd = d->handle; |
228 | } else { | 228 | } else { |
229 | d->handle = AudioDevicePrivate::dspFd; | 229 | d->handle = AudioDevicePrivate::dspFd; |
230 | } | 230 | } |
231 | #endif | 231 | #endif |
232 | 232 | ||
233 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) | 233 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) |
234 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); | 234 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); |
235 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) | 235 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) |
236 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); | 236 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); |
237 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) | 237 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) |
238 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 238 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
239 | qDebug("freq %d", d->frequency); | 239 | qDebug("freq %d", d->frequency); |
240 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) | 240 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) |
241 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 241 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
242 | qDebug("channels %d",d->channels); | 242 | qDebug("channels %d",d->channels); |
243 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { | 243 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { |
244 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; | 244 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; |
245 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) | 245 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) |
246 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 246 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
247 | } | 247 | } |
248 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; | ||
248 | 249 | ||
249 | d->bufferSize = sound_fragment_bytes; | 250 | d->bufferSize = sound_fragment_bytes; |
250 | d->unwrittenBuffer = new char[d->bufferSize]; | 251 | d->unwrittenBuffer = new char[d->bufferSize]; |
251 | d->unwritten = 0; | 252 | d->unwritten = 0; |
252 | d->can_GETOSPACE = TRUE; // until we find otherwise | 253 | d->can_GETOSPACE = TRUE; // until we find otherwise |
253 | 254 | ||
254 | //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); | 255 | //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); |
255 | //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); | 256 | //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); |
256 | //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); | 257 | //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); |
257 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); | 258 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); |
258 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); | 259 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); |
259 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); | 260 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); |
260 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; | ||
261 | 261 | ||
262 | } | 262 | } |
263 | 263 | ||
264 | 264 | ||
265 | AudioDevice::~AudioDevice() { | 265 | AudioDevice::~AudioDevice() { |
266 | qDebug("destryo audiodevice"); | 266 | qDebug("destryo audiodevice"); |
267 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; | 267 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; |
268 | 268 | ||
269 | // #ifdef Q_OS_WIN32 | 269 | // #ifdef Q_OS_WIN32 |
270 | // waveOutClose( (HWAVEOUT)d->handle ); | 270 | // waveOutClose( (HWAVEOUT)d->handle ); |
271 | // #else | 271 | // #else |
272 | # ifndef KEEP_DEVICE_OPEN | 272 | # ifndef KEEP_DEVICE_OPEN |
273 | close( d->handle ); // Now it should be safe to shut the handle | 273 | close( d->handle ); // Now it should be safe to shut the handle |
274 | # endif | 274 | # endif |
275 | delete d->unwrittenBuffer; | 275 | delete d->unwrittenBuffer; |
276 | delete d; | 276 | delete d; |
277 | //#endif | 277 | //#endif |
278 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; | 278 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; |
279 | 279 | ||
280 | } | 280 | } |
281 | 281 | ||
282 | 282 | ||
283 | void AudioDevice::volumeChanged( bool muted ) | 283 | void AudioDevice::volumeChanged( bool muted ) |
284 | { | 284 | { |
285 | AudioDevicePrivate::muted = muted; | 285 | AudioDevicePrivate::muted = muted; |
286 | } | 286 | } |
287 | 287 | ||
288 | 288 | ||
289 | void AudioDevice::write( char *buffer, unsigned int length ) | 289 | void AudioDevice::write( char *buffer, unsigned int length ) |
290 | { | 290 | { |
291 | // #ifdef Q_OS_WIN32 | 291 | // #ifdef Q_OS_WIN32 |
292 | // // returns immediately and (to be implemented) emits completedIO() when finished writing | 292 | // // returns immediately and (to be implemented) emits completedIO() when finished writing |
293 | // WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) ); | 293 | // WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) ); |
294 | // // maybe the buffer should be copied so that this fool proof, but its a performance hit | 294 | // // maybe the buffer should be copied so that this fool proof, but its a performance hit |
295 | // lpWaveHdr->lpData = buffer; | 295 | // lpWaveHdr->lpData = buffer; |
296 | // lpWaveHdr->dwBufferLength = length; | 296 | // lpWaveHdr->dwBufferLength = length; |
297 | // lpWaveHdr->dwFlags = 0L; | 297 | // lpWaveHdr->dwFlags = 0L; |
298 | // lpWaveHdr->dwLoops = 0L; | 298 | // lpWaveHdr->dwLoops = 0L; |
299 | // waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ); | 299 | // waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ); |
300 | // // waveOutWrite returns immediately. the data is sent in the background. | 300 | // // waveOutWrite returns immediately. the data is sent in the background. |
301 | // if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) ) | 301 | // if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) ) |
302 | // qDebug( "failed to write block to audio device" ); | 302 | // qDebug( "failed to write block to audio device" ); |
303 | // // emit completedIO(); | 303 | // // emit completedIO(); |
304 | // #else | 304 | // #else |
305 | int t = ::write( d->handle, buffer, length ); | 305 | int t = ::write( d->handle, buffer, length ); |
306 | if ( t<0 ) t = 0; | 306 | if ( t<0 ) t = 0; |
307 | if ( t != (int)length) { | 307 | if ( t != (int)length) { |
308 | qDebug("Ahhh!! memcpys 1"); | 308 | qDebug("Ahhh!! memcpys 1"); |
309 | memcpy(d->unwrittenBuffer,buffer+t,length-t); | 309 | memcpy(d->unwrittenBuffer,buffer+t,length-t); |
310 | d->unwritten = length-t; | 310 | d->unwritten = length-t; |
311 | } | 311 | } |
312 | //#endif | 312 | //#endif |
313 | } | 313 | } |
314 | 314 | ||
315 | 315 | ||
316 | unsigned int AudioDevice::channels() const | 316 | unsigned int AudioDevice::channels() const |
317 | { | 317 | { |
318 | return d->channels; | 318 | return d->channels; |
319 | } | 319 | } |
320 | 320 | ||
321 | 321 | ||
322 | unsigned int AudioDevice::frequency() const | 322 | unsigned int AudioDevice::frequency() const |
323 | { | 323 | { |
324 | return d->frequency; | 324 | return d->frequency; |
325 | } | 325 | } |
326 | 326 | ||
327 | 327 | ||
328 | unsigned int AudioDevice::bytesPerSample() const | 328 | unsigned int AudioDevice::bytesPerSample() const |
329 | { | 329 | { |
330 | return d->bytesPerSample; | 330 | return d->bytesPerSample; |
331 | } | 331 | } |
332 | 332 | ||
333 | 333 | ||
334 | unsigned int AudioDevice::bufferSize() const | 334 | unsigned int AudioDevice::bufferSize() const |
335 | { | 335 | { |
336 | return d->bufferSize; | 336 | return d->bufferSize; |
337 | } | 337 | } |
338 | 338 | ||
339 | unsigned int AudioDevice::canWrite() const | 339 | unsigned int AudioDevice::canWrite() const |
340 | { | 340 | { |
341 | // #ifdef Q_OS_WIN32 | 341 | // #ifdef Q_OS_WIN32 |
342 | // return bufferSize(); // Any better? | 342 | // return bufferSize(); // Any better? |
343 | // #else | 343 | // #else |
344 | audio_buf_info info; | 344 | audio_buf_info info; |
345 | if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { | 345 | if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { |
346 | d->can_GETOSPACE = FALSE; | 346 | d->can_GETOSPACE = FALSE; |
347 | fcntl( d->handle, F_SETFL, O_NONBLOCK ); | 347 | fcntl( d->handle, F_SETFL, O_NONBLOCK ); |
348 | } | 348 | } |
349 | if ( d->can_GETOSPACE ) { | 349 | if ( d->can_GETOSPACE ) { |
350 | int t = info.fragments * sound_fragment_bytes; | 350 | int t = info.fragments * sound_fragment_bytes; |
351 | return QMIN(t,(int)bufferSize()); | 351 | return QMIN(t,(int)bufferSize()); |
352 | } else { | 352 | } else { |
353 | if ( d->unwritten ) { | 353 | if ( d->unwritten ) { |
354 | int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); | 354 | int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); |
355 | if ( t<0 ) t = 0; | 355 | if ( t<0 ) t = 0; |
356 | if ( (unsigned)t!=d->unwritten ) { | 356 | if ( (unsigned)t!=d->unwritten ) { |
357 | memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); | 357 | memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); |
358 | d->unwritten -= t; | 358 | d->unwritten -= t; |
359 | } else { | 359 | } else { |
360 | d->unwritten = 0; | 360 | d->unwritten = 0; |
361 | } | 361 | } |
362 | } | 362 | } |
363 | if ( d->unwritten ) | 363 | if ( d->unwritten ) |
364 | return 0; | 364 | return 0; |
365 | else | 365 | else |
366 | return d->bufferSize; | 366 | return d->bufferSize; |
367 | } | 367 | } |
368 | //#endif | 368 | //#endif |
369 | } | 369 | } |
370 | 370 | ||
371 | 371 | ||
372 | int AudioDevice::bytesWritten() { | 372 | int AudioDevice::bytesWritten() { |
373 | // #ifdef Q_OS_WIN32 | 373 | // #ifdef Q_OS_WIN32 |
374 | // MMTIME pmmt = { TIME_BYTES, 0 }; | 374 | // MMTIME pmmt = { TIME_BYTES, 0 }; |
375 | // if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) { | 375 | // if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) { |
376 | // qDebug( "failed to get audio device position" ); | 376 | // qDebug( "failed to get audio device position" ); |
377 | // return -1; | 377 | // return -1; |
378 | // } | 378 | // } |
379 | // return pmmt.u.cb; | 379 | // return pmmt.u.cb; |
380 | // #else | 380 | // #else |
381 | int buffered = 0; | 381 | int buffered = 0; |
382 | if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { | 382 | if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { |
383 | qDebug( "failed to get audio device position" ); | 383 | qDebug( "failed to get audio device position" ); |
384 | return -1; | 384 | return -1; |
385 | } | 385 | } |
386 | return buffered; | 386 | return buffered; |
387 | //#endif | 387 | //#endif |
388 | } | 388 | } |
389 | 389 | ||
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index 54e7ceb..b96b1ef 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp | |||
@@ -1,367 +1,367 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of 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 <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | 23 | ||
24 | #include <qwidget.h> | 24 | #include <qwidget.h> |
25 | #include <qpixmap.h> | 25 | #include <qpixmap.h> |
26 | #include <qbutton.h> | 26 | #include <qbutton.h> |
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | #include <qframe.h> | 28 | #include <qframe.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | 30 | ||
31 | #include "audiowidget.h" | 31 | #include "audiowidget.h" |
32 | #include "mediaplayerstate.h" | 32 | #include "mediaplayerstate.h" |
33 | 33 | ||
34 | extern MediaPlayerState *mediaPlayerState; | 34 | extern MediaPlayerState *mediaPlayerState; |
35 | 35 | ||
36 | 36 | ||
37 | static const int xo = -2; // movable x offset | 37 | static const int xo = -2; // movable x offset |
38 | static const int yo = 22; // movable y offset | 38 | static const int yo = 22; // movable y offset |
39 | 39 | ||
40 | 40 | ||
41 | struct MediaButton { | 41 | struct MediaButton { |
42 | int xPos, yPos; | 42 | int xPos, yPos; |
43 | int color; | 43 | int color; |
44 | bool isToggle, isBig, isHeld, isDown; | 44 | bool isToggle, isBig, isHeld, isDown; |
45 | }; | 45 | }; |
46 | 46 | ||
47 | 47 | ||
48 | // Layout information for the audioButtons (and if it is a toggle button or not) | 48 | // Layout information for the audioButtons (and if it is a toggle button or not) |
49 | MediaButton audioButtons[] = { | 49 | MediaButton audioButtons[] = { |
50 | { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play | 50 | { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play |
51 | { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop | 51 | { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop |
52 | { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause | 52 | { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause |
53 | { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next | 53 | { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next |
54 | { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous | 54 | { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous |
55 | { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up | 55 | { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up |
56 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down | 56 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down |
57 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop | 57 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop |
58 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist | 58 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist |
59 | }; | 59 | }; |
60 | 60 | ||
61 | 61 | ||
62 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 62 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
63 | 63 | ||
64 | 64 | ||
65 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 65 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
66 | QWidget( parent, name, f ) | 66 | QWidget( parent, name, f ) |
67 | { | 67 | { |
68 | setCaption( tr("OpiePlayer") ); | 68 | setCaption( tr("OpiePlayer") ); |
69 | Config cfg("OpiePlayer"); | 69 | Config cfg("OpiePlayer"); |
70 | cfg.setGroup("AudioWidget"); | 70 | cfg.setGroup("AudioWidget"); |
71 | // QGridLayout *layout = new QGridLayout( this ); | 71 | // QGridLayout *layout = new QGridLayout( this ); |
72 | // layout->setSpacing( 2); | 72 | // layout->setSpacing( 2); |
73 | // layout->setMargin( 2); | 73 | // layout->setMargin( 2); |
74 | QString backgroundPix, buttonsAllPix, buttonsBigPix, controlsPix, animatedPix; | 74 | QString backgroundPix, buttonsAllPix, buttonsBigPix, controlsPix, animatedPix; |
75 | backgroundPix=cfg.readEntry( " backgroundPix", "opieplayer/metalFinish"); | 75 | backgroundPix=cfg.readEntry( " backgroundPix", "opieplayer/metalFinish"); |
76 | buttonsAllPix=cfg.readEntry( "buttonsAllPix","opieplayer/mediaButtonsAll"); | 76 | buttonsAllPix=cfg.readEntry( "buttonsAllPix","opieplayer/mediaButtonsAll"); |
77 | buttonsBigPix=cfg.readEntry( "buttonsBigPix","opieplayer/mediaButtonsBig"); | 77 | buttonsBigPix=cfg.readEntry( "buttonsBigPix","opieplayer/mediaButtonsBig"); |
78 | controlsPix=cfg.readEntry( "controlsPix","opieplayer/mediaControls"); | 78 | controlsPix=cfg.readEntry( "controlsPix","opieplayer/mediaControls"); |
79 | animatedPix=cfg.readEntry( "animatedPix", "opieplayer/animatedButton"); | 79 | // animatedPix=cfg.readEntry( "animatedPix", "opieplayer/animatedButton"); |
80 | 80 | ||
81 | setBackgroundPixmap( Resource::loadPixmap( backgroundPix) ); | 81 | setBackgroundPixmap( Resource::loadPixmap( backgroundPix) ); |
82 | pixmaps[0] = new QPixmap( Resource::loadPixmap( buttonsAllPix ) ); | 82 | pixmaps[0] = new QPixmap( Resource::loadPixmap( buttonsAllPix ) ); |
83 | pixmaps[1] = new QPixmap( Resource::loadPixmap( buttonsBigPix ) ); | 83 | pixmaps[1] = new QPixmap( Resource::loadPixmap( buttonsBigPix ) ); |
84 | pixmaps[2] = new QPixmap( Resource::loadPixmap( controlsPix ) ); | 84 | pixmaps[2] = new QPixmap( Resource::loadPixmap( controlsPix ) ); |
85 | pixmaps[3] = new QPixmap( Resource::loadPixmap( animatedPix) ); | 85 | // pixmaps[3] = new QPixmap( Resource::loadPixmap( animatedPix) ); |
86 | 86 | ||
87 | songInfo = new Ticker( this ); | 87 | songInfo = new Ticker( this ); |
88 | songInfo->setFocusPolicy( QWidget::NoFocus ); | 88 | songInfo->setFocusPolicy( QWidget::NoFocus ); |
89 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); | 89 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); |
90 | // layout->addMultiCellWidget( songInfo, 0, 0, 0, 2 ); | 90 | // layout->addMultiCellWidget( songInfo, 0, 0, 0, 2 ); |
91 | 91 | ||
92 | slider = new QSlider( Qt::Horizontal, this ); | 92 | slider = new QSlider( Qt::Horizontal, this ); |
93 | slider->setFixedWidth( 220 ); | 93 | slider->setFixedWidth( 220 ); |
94 | slider->setFixedHeight( 20 ); | 94 | slider->setFixedHeight( 20 ); |
95 | slider->setMinValue( 0 ); | 95 | slider->setMinValue( 0 ); |
96 | slider->setMaxValue( 1 ); | 96 | slider->setMaxValue( 1 ); |
97 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); | 97 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); |
98 | slider->setFocusPolicy( QWidget::NoFocus ); | 98 | slider->setFocusPolicy( QWidget::NoFocus ); |
99 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); | 99 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); |
100 | // layout->addMultiCellWidget( slider, 4, 4, 0, 2 ); | 100 | // layout->addMultiCellWidget( slider, 4, 4, 0, 2 ); |
101 | 101 | ||
102 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 102 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
103 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 103 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
104 | 104 | ||
105 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 105 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
106 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 106 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
107 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 107 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
108 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 108 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
109 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 109 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
110 | 110 | ||
111 | // Intialise state | 111 | // Intialise state |
112 | setLength( mediaPlayerState->length() ); | 112 | setLength( mediaPlayerState->length() ); |
113 | setPosition( mediaPlayerState->position() ); | 113 | setPosition( mediaPlayerState->position() ); |
114 | setLooping( mediaPlayerState->fullscreen() ); | 114 | setLooping( mediaPlayerState->fullscreen() ); |
115 | setPaused( mediaPlayerState->paused() ); | 115 | setPaused( mediaPlayerState->paused() ); |
116 | setPlaying( mediaPlayerState->playing() ); | 116 | setPlaying( mediaPlayerState->playing() ); |
117 | 117 | ||
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | AudioWidget::~AudioWidget() { | 121 | AudioWidget::~AudioWidget() { |
122 | mediaPlayerState->isStreaming = FALSE; | 122 | mediaPlayerState->isStreaming = FALSE; |
123 | for ( int i = 0; i < 4; i++ ) | 123 | for ( int i = 0; i < 3; i++ ) |
124 | delete pixmaps[i]; | 124 | delete pixmaps[i]; |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | static bool audioSliderBeingMoved = FALSE; | 128 | static bool audioSliderBeingMoved = FALSE; |
129 | 129 | ||
130 | 130 | ||
131 | void AudioWidget::sliderPressed() { | 131 | void AudioWidget::sliderPressed() { |
132 | audioSliderBeingMoved = TRUE; | 132 | audioSliderBeingMoved = TRUE; |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | void AudioWidget::sliderReleased() { | 136 | void AudioWidget::sliderReleased() { |
137 | audioSliderBeingMoved = FALSE; | 137 | audioSliderBeingMoved = FALSE; |
138 | if ( slider->width() == 0 ) | 138 | if ( slider->width() == 0 ) |
139 | return; | 139 | return; |
140 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 140 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
141 | mediaPlayerState->setPosition( val ); | 141 | mediaPlayerState->setPosition( val ); |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | void AudioWidget::setPosition( long i ) { | 145 | void AudioWidget::setPosition( long i ) { |
146 | // qDebug("set position %d",i); | 146 | // qDebug("set position %d",i); |
147 | updateSlider( i, mediaPlayerState->length() ); | 147 | updateSlider( i, mediaPlayerState->length() ); |
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
151 | void AudioWidget::setLength( long max ) { | 151 | void AudioWidget::setLength( long max ) { |
152 | updateSlider( mediaPlayerState->position(), max ); | 152 | updateSlider( mediaPlayerState->position(), max ); |
153 | } | 153 | } |
154 | 154 | ||
155 | 155 | ||
156 | void AudioWidget::setView( char view ) { | 156 | void AudioWidget::setView( char view ) { |
157 | if (mediaPlayerState->isStreaming) { | 157 | if (mediaPlayerState->isStreaming) { |
158 | if( !slider->isHidden()) slider->hide(); | 158 | if( !slider->isHidden()) slider->hide(); |
159 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 159 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
160 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 160 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
161 | } else { | 161 | } else { |
162 | // this stops the slider from being moved, thus | 162 | // this stops the slider from being moved, thus |
163 | // does not stop stream when it reaches the end | 163 | // does not stop stream when it reaches the end |
164 | slider->show(); | 164 | slider->show(); |
165 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 165 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
166 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 166 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
167 | } | 167 | } |
168 | 168 | ||
169 | if ( view == 'a' ) { | 169 | if ( view == 'a' ) { |
170 | startTimer( 150 ); | 170 | startTimer( 150 ); |
171 | // show(); | 171 | // show(); |
172 | showMaximized(); | 172 | showMaximized(); |
173 | } else { | 173 | } else { |
174 | killTimers(); | 174 | killTimers(); |
175 | hide(); | 175 | hide(); |
176 | } | 176 | } |
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
180 | void AudioWidget::updateSlider( long i, long max ) { | 180 | void AudioWidget::updateSlider( long i, long max ) { |
181 | if ( max == 0 ) | 181 | if ( max == 0 ) |
182 | return; | 182 | return; |
183 | // Will flicker too much if we don't do this | 183 | // Will flicker too much if we don't do this |
184 | // Scale to something reasonable | 184 | // Scale to something reasonable |
185 | int width = slider->width(); | 185 | int width = slider->width(); |
186 | int val = int((double)i * width / max); | 186 | int val = int((double)i * width / max); |
187 | if ( !audioSliderBeingMoved ) { | 187 | if ( !audioSliderBeingMoved ) { |
188 | if ( slider->value() != val ) | 188 | if ( slider->value() != val ) |
189 | slider->setValue( val ); | 189 | slider->setValue( val ); |
190 | if ( slider->maxValue() != width ) | 190 | if ( slider->maxValue() != width ) |
191 | slider->setMaxValue( width ); | 191 | slider->setMaxValue( width ); |
192 | } | 192 | } |
193 | } | 193 | } |
194 | 194 | ||
195 | 195 | ||
196 | void AudioWidget::setToggleButton( int i, bool down ) { | 196 | void AudioWidget::setToggleButton( int i, bool down ) { |
197 | if ( down != audioButtons[i].isDown ) | 197 | if ( down != audioButtons[i].isDown ) |
198 | toggleButton( i ); | 198 | toggleButton( i ); |
199 | } | 199 | } |
200 | 200 | ||
201 | 201 | ||
202 | void AudioWidget::toggleButton( int i ) { | 202 | void AudioWidget::toggleButton( int i ) { |
203 | audioButtons[i].isDown = !audioButtons[i].isDown; | 203 | audioButtons[i].isDown = !audioButtons[i].isDown; |
204 | QPainter p(this); | 204 | QPainter p(this); |
205 | paintButton ( &p, i ); | 205 | paintButton ( &p, i ); |
206 | } | 206 | } |
207 | 207 | ||
208 | 208 | ||
209 | void AudioWidget::paintButton( QPainter *p, int i ) { | 209 | void AudioWidget::paintButton( QPainter *p, int i ) { |
210 | int x = audioButtons[i].xPos; | 210 | int x = audioButtons[i].xPos; |
211 | int y = audioButtons[i].yPos; | 211 | int y = audioButtons[i].yPos; |
212 | int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; | 212 | int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; |
213 | int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); | 213 | int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); |
214 | p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); | 214 | p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); |
215 | p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); | 215 | p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); |
216 | } | 216 | } |
217 | 217 | ||
218 | 218 | ||
219 | void AudioWidget::timerEvent( QTimerEvent * ) { | 219 | void AudioWidget::timerEvent( QTimerEvent * ) { |
220 | static int frame = 0; | 220 | static int frame = 0; |
221 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { | 221 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { |
222 | frame = frame >= 7 ? 0 : frame + 1; | 222 | frame = frame >= 7 ? 0 : frame + 1; |
223 | int x = audioButtons[AudioPlay].xPos; | 223 | // int x = audioButtons[AudioPlay].xPos; |
224 | int y = audioButtons[AudioPlay].yPos; | 224 | // int y = audioButtons[AudioPlay].yPos; |
225 | QPainter p( this ); | 225 | // QPainter p( this ); |
226 | // Optimize to only draw the little bit of the changing images which is different | 226 | // // Optimize to only draw the little bit of the changing images which is different |
227 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); | 227 | // p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); |
228 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); | 228 | // p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); |
229 | } | 229 | } |
230 | } | 230 | } |
231 | 231 | ||
232 | 232 | ||
233 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 233 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
234 | for ( int i = 0; i < numButtons; i++ ) { | 234 | for ( int i = 0; i < numButtons; i++ ) { |
235 | int size = audioButtons[i].isBig; | 235 | int size = audioButtons[i].isBig; |
236 | int x = audioButtons[i].xPos; | 236 | int x = audioButtons[i].xPos; |
237 | int y = audioButtons[i].yPos; | 237 | int y = audioButtons[i].yPos; |
238 | if ( event->state() == QMouseEvent::LeftButton ) { | 238 | if ( event->state() == QMouseEvent::LeftButton ) { |
239 | // The test to see if the mouse click is inside the circular button or not | 239 | // The test to see if the mouse click is inside the circular button or not |
240 | // (compared with the radius squared to avoid a square-root of our distance) | 240 | // (compared with the radius squared to avoid a square-root of our distance) |
241 | int radius = 32 + 13 * size; | 241 | int radius = 32 + 13 * size; |
242 | QPoint center = QPoint( x + radius, y + radius ); | 242 | QPoint center = QPoint( x + radius, y + radius ); |
243 | QPoint dXY = center - event->pos(); | 243 | QPoint dXY = center - event->pos(); |
244 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); | 244 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); |
245 | bool isOnButton = dist <= (radius * radius); | 245 | bool isOnButton = dist <= (radius * radius); |
246 | // QRect r( x, y, 64 + 22*size, 64 + 22*size ); | 246 | // QRect r( x, y, 64 + 22*size, 64 + 22*size ); |
247 | // bool isOnButton = r.contains( event->pos() ); // Rectangular Button code | 247 | // bool isOnButton = r.contains( event->pos() ); // Rectangular Button code |
248 | if ( isOnButton && !audioButtons[i].isHeld ) { | 248 | if ( isOnButton && !audioButtons[i].isHeld ) { |
249 | audioButtons[i].isHeld = TRUE; | 249 | audioButtons[i].isHeld = TRUE; |
250 | toggleButton(i); | 250 | toggleButton(i); |
251 | qDebug("button toggled1 %d",i); | 251 | qDebug("button toggled1 %d",i); |
252 | switch (i) { | 252 | switch (i) { |
253 | case AudioVolumeUp: emit moreClicked(); return; | 253 | case AudioVolumeUp: emit moreClicked(); return; |
254 | case AudioVolumeDown: emit lessClicked(); return; | 254 | case AudioVolumeDown: emit lessClicked(); return; |
255 | } | 255 | } |
256 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 256 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
257 | audioButtons[i].isHeld = FALSE; | 257 | audioButtons[i].isHeld = FALSE; |
258 | toggleButton(i); | 258 | toggleButton(i); |
259 | qDebug("button toggled2 %d",i); | 259 | qDebug("button toggled2 %d",i); |
260 | } | 260 | } |
261 | } else { | 261 | } else { |
262 | if ( audioButtons[i].isHeld ) { | 262 | if ( audioButtons[i].isHeld ) { |
263 | audioButtons[i].isHeld = FALSE; | 263 | audioButtons[i].isHeld = FALSE; |
264 | if ( !audioButtons[i].isToggle ) | 264 | if ( !audioButtons[i].isToggle ) |
265 | setToggleButton( i, FALSE ); | 265 | setToggleButton( i, FALSE ); |
266 | qDebug("button toggled3 %d",i); | 266 | qDebug("button toggled3 %d",i); |
267 | switch (i) { | 267 | switch (i) { |
268 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; | 268 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; |
269 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; | 269 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; |
270 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; | 270 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; |
271 | case AudioNext: mediaPlayerState->setNext(); return; | 271 | case AudioNext: mediaPlayerState->setNext(); return; |
272 | case AudioPrevious: mediaPlayerState->setPrev(); return; | 272 | case AudioPrevious: mediaPlayerState->setPrev(); return; |
273 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; | 273 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; |
274 | case AudioVolumeUp: emit moreReleased(); return; | 274 | case AudioVolumeUp: emit moreReleased(); return; |
275 | case AudioVolumeDown: emit lessReleased(); return; | 275 | case AudioVolumeDown: emit lessReleased(); return; |
276 | case AudioPlayList: mediaPlayerState->setList(); return; | 276 | case AudioPlayList: mediaPlayerState->setList(); return; |
277 | } | 277 | } |
278 | } | 278 | } |
279 | } | 279 | } |
280 | } | 280 | } |
281 | } | 281 | } |
282 | 282 | ||
283 | 283 | ||
284 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 284 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
285 | mouseMoveEvent( event ); | 285 | mouseMoveEvent( event ); |
286 | } | 286 | } |
287 | 287 | ||
288 | 288 | ||
289 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 289 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
290 | mouseMoveEvent( event ); | 290 | mouseMoveEvent( event ); |
291 | } | 291 | } |
292 | 292 | ||
293 | 293 | ||
294 | void AudioWidget::showEvent( QShowEvent* ) { | 294 | void AudioWidget::showEvent( QShowEvent* ) { |
295 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 295 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
296 | mouseMoveEvent( &event ); | 296 | mouseMoveEvent( &event ); |
297 | } | 297 | } |
298 | 298 | ||
299 | 299 | ||
300 | void AudioWidget::closeEvent( QCloseEvent* ) { | 300 | void AudioWidget::closeEvent( QCloseEvent* ) { |
301 | mediaPlayerState->setList(); | 301 | mediaPlayerState->setList(); |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
305 | void AudioWidget::paintEvent( QPaintEvent * ) { | 305 | void AudioWidget::paintEvent( QPaintEvent * ) { |
306 | QPainter p( this ); | 306 | QPainter p( this ); |
307 | for ( int i = 0; i < numButtons; i++ ) | 307 | for ( int i = 0; i < numButtons; i++ ) |
308 | paintButton( &p, i ); | 308 | paintButton( &p, i ); |
309 | } | 309 | } |
310 | 310 | ||
311 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) | 311 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) |
312 | { | 312 | { |
313 | switch ( e->key() ) { | 313 | switch ( e->key() ) { |
314 | ////////////////////////////// Zaurus keys | 314 | ////////////////////////////// Zaurus keys |
315 | case Key_Home: | 315 | case Key_Home: |
316 | break; | 316 | break; |
317 | case Key_F9: //activity | 317 | case Key_F9: //activity |
318 | hide(); | 318 | hide(); |
319 | // qDebug("Audio F9"); | 319 | // qDebug("Audio F9"); |
320 | break; | 320 | break; |
321 | case Key_F10: //contacts | 321 | case Key_F10: //contacts |
322 | break; | 322 | break; |
323 | case Key_F11: //menu | 323 | case Key_F11: //menu |
324 | break; | 324 | break; |
325 | case Key_F12: //home | 325 | case Key_F12: //home |
326 | break; | 326 | break; |
327 | case Key_F13: //mail | 327 | case Key_F13: //mail |
328 | break; | 328 | break; |
329 | case Key_Space: { | 329 | case Key_Space: { |
330 | if(mediaPlayerState->playing()) { | 330 | if(mediaPlayerState->playing()) { |
331 | // toggleButton(1); | 331 | // toggleButton(1); |
332 | mediaPlayerState->setPlaying(FALSE); | 332 | mediaPlayerState->setPlaying(FALSE); |
333 | // toggleButton(1); | 333 | // toggleButton(1); |
334 | } else { | 334 | } else { |
335 | // toggleButton(0); | 335 | // toggleButton(0); |
336 | mediaPlayerState->setPlaying(TRUE); | 336 | mediaPlayerState->setPlaying(TRUE); |
337 | // toggleButton(0); | 337 | // toggleButton(0); |
338 | } | 338 | } |
339 | } | 339 | } |
340 | break; | 340 | break; |
341 | case Key_Down: | 341 | case Key_Down: |
342 | toggleButton(6); | 342 | toggleButton(6); |
343 | emit lessClicked(); | 343 | emit lessClicked(); |
344 | emit lessReleased(); | 344 | emit lessReleased(); |
345 | toggleButton(6); | 345 | toggleButton(6); |
346 | break; | 346 | break; |
347 | case Key_Up: | 347 | case Key_Up: |
348 | toggleButton(5); | 348 | toggleButton(5); |
349 | emit moreClicked(); | 349 | emit moreClicked(); |
350 | emit moreReleased(); | 350 | emit moreReleased(); |
351 | toggleButton(5); | 351 | toggleButton(5); |
352 | break; | 352 | break; |
353 | case Key_Right: | 353 | case Key_Right: |
354 | // toggleButton(3); | 354 | // toggleButton(3); |
355 | mediaPlayerState->setNext(); | 355 | mediaPlayerState->setNext(); |
356 | // toggleButton(3); | 356 | // toggleButton(3); |
357 | break; | 357 | break; |
358 | case Key_Left: | 358 | case Key_Left: |
359 | // toggleButton(4); | 359 | // toggleButton(4); |
360 | mediaPlayerState->setPrev(); | 360 | mediaPlayerState->setPrev(); |
361 | // toggleButton(4); | 361 | // toggleButton(4); |
362 | break; | 362 | break; |
363 | case Key_Escape: | 363 | case Key_Escape: |
364 | break; | 364 | break; |
365 | 365 | ||
366 | }; | 366 | }; |
367 | } | 367 | } |