~ubuntu-branches/ubuntu/raring/workrave/raring

« back to all changes in this revision

Viewing changes to frontend/common/src/win32/W32SoundPlayer.cc

  • Committer: Package Import Robot
  • Author(s): Francois Marier, Francois Marier, Jordi Mallach
  • Date: 2012-05-28 11:29:40 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20120528112940-bbbsjkk30fom9s8x
Tags: 1.9.909+abc941eb70-1
[ Francois Marier ]
* New upstream snapshot
  - Drop leak-fix patch (applied upstream)
  - Document how the tarball is built in README.source
* Build GNOME applets and use gsettings
* Massive update of Build-Depends as per configure.ac

* Update README.source with snapshot instructions
* Switch to machine-readable copyright file
* Update alioth git repo links
* Bump debhelper version to 9
* Bump Standards-Version to 3.9.3

[ Jordi Mallach ]
* Avoid references to GNU/Linux in manpage.
* Drop build dependency on libgnet-dev, it's obsolete and unneeded.
* Add myself to Uploaders.
* Rewrite d/rules into dh style.
  - Move all install tweaks to .install files.
  - Install manpages using dh_installman.
* As a side effect, the package installs arch-dependant data in the
  arch triplet directory; add the required Pre-Depends for m-a-support.
* Bring back GNOME Panel applet (for GNOME 3 fallback mode) and ship the
  new GNOME Shell extension (closes: #642514, #666100).
* Add private_dirs.patch: move libworkrave-private and GObject
  Introspection files to a private dir, so they are really out of the
  way, but disable it for now as it breaks the Shell extension.
* Move typelib out of the triplet dir as gobject-introspection is not
  M-A ready yet.
* Enable dh_autoreconf for the above patches.
* Add lintian overrides.
* Add necessary Breaks/Replaces as the xpm icon has moved to workrave-data.
* Prefix all debhelper files with package name.
* Suggest gnome-shell and gnome-panel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// W32SoundPlayer.cc --- Sound player
2
2
//
3
 
// Copyright (C) 2002 - 2008, 2010 Raymond Penners & Ray Satiro
 
3
// Copyright (C) 2002 - 2008, 2010, 2012 Raymond Penners & Ray Satiro
4
4
// All rights reserved.
5
5
//
6
6
// This program is free software: you can redistribute it and/or modify
139
139
    {
140
140
      TRACE_MSG("Sound already queued");
141
141
    }
142
 
  else 
 
142
  else
143
143
    {
144
144
      DWORD id;
145
145
      sound_filename = wavfile;
154
154
W32SoundPlayer::get_sound_enabled(SoundEvent snd, bool &enabled)
155
155
{
156
156
  char key[MAX_PATH], val[MAX_PATH];
157
 
  
 
157
 
158
158
  strcpy(key, "AppEvents\\Schemes\\Apps\\Workrave\\");
159
159
  strcat(key, SoundPlayer::sound_registry[snd].label);
160
160
  strcat(key, "\\.current");
163
163
    {
164
164
      enabled = (val[0] != '\0');
165
165
    }
166
 
  
 
166
 
167
167
  return true;
168
168
}
169
169
 
174
174
  if (enabled)
175
175
    {
176
176
      char key[MAX_PATH], def[MAX_PATH];
177
 
      
 
177
 
178
178
      strcpy(key, "AppEvents\\Schemes\\Apps\\Workrave\\");
179
179
      strcat(key, SoundPlayer::sound_registry[snd].label);
180
180
      strcat(key, "\\.default");
189
189
  else
190
190
    {
191
191
      char key[MAX_PATH];
192
 
      
 
192
 
193
193
      strcpy(key, "AppEvents\\Schemes\\Apps\\Workrave\\");
194
194
      strcat(key, SoundPlayer::sound_registry[snd].label);
195
195
      strcat(key, "\\.current");
196
 
  
 
196
 
197
197
      registry_set_value(key, NULL, "");
198
198
    }
199
199
}
207
207
  strcpy(key, "AppEvents\\Schemes\\Apps\\Workrave\\");
208
208
  strcat(key, SoundPlayer::sound_registry[snd].label);
209
209
  strcat(key, "\\.current");
210
 
  
 
210
 
211
211
  if (registry_get_value(key, NULL, val))
212
212
    {
213
213
      wav_file = val;
222
222
          wav_file = val;
223
223
        }
224
224
    }
225
 
  
226
 
  return true;;
 
225
 
 
226
  return true;
227
227
}
228
228
 
229
229
void
237
237
    {
238
238
      registry_set_value(key, NULL, SoundPlayer::sound_registry[snd].friendly_name);
239
239
    }
240
 
  
 
240
 
241
241
  strcpy(key, "AppEvents\\Schemes\\Apps\\Workrave\\");
242
242
  strcat(key, SoundPlayer::sound_registry[snd].label);
243
243
  strcat(key, "\\.default");
284
284
    }
285
285
 
286
286
  sound_filename = "";
287
 
  
 
287
 
288
288
  TRACE_EXIT();
289
289
}
290
290
 
315
315
 
316
316
  int volume = 100;
317
317
  CoreFactory::get_configurator()->get_value(SoundPlayer::CFG_KEY_SOUND_VOLUME, volume);
318
 
  
 
318
 
319
319
  volume = (volume * 0xFFFF / 100);
320
320
  volume = volume | (volume << 16);
321
 
        
 
321
 
322
322
  res = waveOutSetVolume(waveout, volume);
323
323
  if (res != MMSYSERR_NOERROR)
324
324
    {
325
325
      throw Exception("waveOutSetVolume");
326
326
    }
327
 
  
 
327
 
328
328
  buffers = (WAVEHDR**) malloc(number_of_buffers * sizeof(WAVEHDR**));
329
329
  for (i = 0; i < number_of_buffers; i++)
330
330
    {
333
333
        {
334
334
          throw Exception("buffers malloc");
335
335
        }
336
 
          
 
336
 
337
337
      if (buffers[i] != NULL)
338
338
        {
339
339
          buffers[i]->lpData = (CHAR *)malloc(WAVE_BUFFER_SIZE);
352
352
        unsigned char *ptr = buf;
353
353
        unsigned char *end = buf + size;
354
354
        MMRESULT res;
355
 
        
 
355
 
356
356
        for (int i = buffer_position; ptr < end; i = (i + 1) % number_of_buffers)
357
357
    {
358
358
      while ((buffers[i]->dwFlags & WHDR_INQUEUE) != 0)
362
362
            {
363
363
              throw Exception("waveOutRestart");
364
364
            }
365
 
          
 
365
 
366
366
          WaitForSingleObject(wave_event, INFINITE);
367
367
        }
368
 
      
 
368
 
369
369
      int chunck_size = WAVE_BUFFER_SIZE - buffers[i]->dwBytesRecorded;
370
370
      if (ptr + chunck_size > end)
371
371
        {
372
372
          chunck_size = end - ptr;
373
373
        }
374
 
      
 
374
 
375
375
      memcpy(buffers[i]->lpData + buffers[i]->dwBytesRecorded, ptr, chunck_size);
376
376
      ptr += chunck_size;
377
377
      buffers[i]->dwBytesRecorded += chunck_size;
378
 
      
 
378
 
379
379
      if (buffers[i]->dwBytesRecorded == WAVE_BUFFER_SIZE)
380
380
        {
381
381
          flush_buffer(i);
431
431
        {
432
432
          WaitForSingleObject(wave_event, INFINITE);
433
433
        }
434
 
      
 
434
 
435
435
      res = waveOutUnprepareHeader(waveout, buffers[i], sizeof(WAVEHDR));
436
436
      if (res != MMSYSERR_NOERROR)
437
437
        {
442
442
      free(buffers[i]);
443
443
      buffers[i] = NULL;
444
444
    }
445
 
  
 
445
 
446
446
  free(buffers);
447
447
  free(sample);
448
448
 
460
460
W32SoundPlayer::load_wav_file(const string &filename)
461
461
{
462
462
  MMRESULT res;
463
 
  
 
463
 
464
464
  HMMIO handle = mmioOpen((CHAR*)filename.c_str(), NULL, MMIO_ALLOCBUF | MMIO_READ);
465
465
  if (handle == NULL)
466
466
    {
475
475
    {
476
476
      throw Exception("mmioDescend");
477
477
    }
478
 
  
 
478
 
479
479
  if (parent.ckid != FOURCC_RIFF || parent.fccType != mmioFOURCC('W', 'A', 'V', 'E' ))
480
480
    {
481
481
      throw Exception("no Wave");
482
482
    }
483
483
 
484
 
  
 
484
 
485
485
  MMCKINFO child;
486
486
  memset((void *)&child, 0, sizeof(child));
487
487
 
488
488
  parent.ckid = mmioFOURCC('f', 'm', 't', ' ');
489
 
  
 
489
 
490
490
  res = mmioDescend(handle, &child, &parent, MMIO_FINDCHUNK);
491
491
  if (res != MMSYSERR_NOERROR)
492
492
    {
531
531
    {
532
532
      throw Exception("malloc");
533
533
    }
534
 
  
 
534
 
535
535
  MMIOINFO mmio;
536
536
  res = mmioGetInfo(handle, &mmio, 0);
537
537
  if (res != MMSYSERR_NOERROR)
545
545
    {
546
546
      size_t copy = mmio.pchEndRead - mmio.pchNext;
547
547
 
548
 
      if (copy > 0) 
549
 
        {       
 
548
      if (copy > 0)
 
549
        {
550
550
          if (copy > sample_size - pos)
551
551
            {
552
552
              copy = sample_size - pos;
559
559
      mmio.pchNext = mmio.pchEndRead;
560
560
 
561
561
    } while (pos < (int)sample_size && mmioAdvance(handle, &mmio, MMIO_READ) == 0);
562
 
  
 
562
 
563
563
 
564
564
  mmioClose(handle, 0);
565
565
}