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

« back to all changes in this revision

Viewing changes to frontend/common/src/win32/W32DirectSoundPlayer.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
// W32DirectSoundPlayer.cc --- Sound player
2
2
//
3
 
// Copyright (C) 2002 - 2010 Raymond Penners & Ray Satiro
 
3
// Copyright (C) 2002 - 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
111
111
//! Constructor
112
112
W32DirectSoundPlayer::W32DirectSoundPlayer()
113
113
{
114
 
  direct_sound = NULL;
115
114
}
116
115
 
117
116
 
118
117
//! Destructor
119
118
W32DirectSoundPlayer::~W32DirectSoundPlayer()
120
119
{
121
 
  if (direct_sound != NULL)
122
 
    {
123
 
      direct_sound->Release();
124
 
      direct_sound = NULL;
125
 
    }
126
120
}
127
121
 
128
122
//!
129
123
void
130
124
W32DirectSoundPlayer::init(ISoundDriverEvents *events)
131
125
{
132
 
  HRESULT             hr = S_OK;
133
 
 
134
126
  this->events = events;
135
 
  
136
 
  if (direct_sound != NULL)
137
 
    {
138
 
      direct_sound->Release();
139
 
      direct_sound = NULL;
140
 
    }
141
 
 
142
 
  try
143
 
    {
144
 
      hr = DirectSoundCreate8(NULL, &direct_sound, NULL);
145
 
      if (FAILED(hr) || direct_sound == NULL)
146
 
        {
147
 
          throw Exception(string("DirectSoundCreate8") + DXGetErrorString8(hr));
148
 
        }
149
 
 
150
 
      hr = direct_sound->SetCooperativeLevel(GetDesktopWindow(), DSSCL_PRIORITY);
151
 
      if (FAILED(hr))
152
 
        {
153
 
          throw Exception(string("IDirectSound_SetCooperativeLevel") + DXGetErrorString8(hr));
154
 
        }
155
 
    }
156
 
  catch (Exception)
157
 
    {
158
 
      if (direct_sound != NULL)
159
 
        {
160
 
          direct_sound->Release();
161
 
          direct_sound = NULL;
162
 
        }
163
 
      
164
 
      throw;
165
 
    }
166
127
}
167
128
 
168
129
 
198
159
{
199
160
  TRACE_ENTER_MSG( "W32DirectSoundPlayer::play_sound", wavfile);
200
161
 
201
 
  if (direct_sound != NULL && wavfile != "")
 
162
  if (wavfile != "")
202
163
    {
203
164
      DWORD id;
204
 
 
205
 
      SoundClip *clip = new SoundClip(direct_sound, wavfile, events);
 
165
      
 
166
      SoundClip *clip = new SoundClip(wavfile, events);
206
167
      CloseHandle(CreateThread(NULL, 0, play_thread, clip, 0, &id));
207
168
    }
208
169
 
214
175
W32DirectSoundPlayer::get_sound_enabled(SoundEvent snd, bool &enabled)
215
176
{
216
177
  char key[MAX_PATH], val[MAX_PATH];
217
 
  
 
178
 
218
179
  strcpy(key, "AppEvents\\Schemes\\Apps\\Workrave\\");
219
180
  strcat(key, SoundPlayer::sound_registry[snd].label);
220
181
  strcat(key, "\\.current");
224
185
      enabled = (val[0] != '\0');
225
186
      return true;
226
187
    }
227
 
  
 
188
 
228
189
  return false;
229
190
}
230
191
 
235
196
  if (enabled)
236
197
    {
237
198
      char key[MAX_PATH], def[MAX_PATH];
238
 
      
 
199
 
239
200
      strcpy(key, "AppEvents\\Schemes\\Apps\\Workrave\\");
240
201
      strcat(key, SoundPlayer::sound_registry[snd].label);
241
202
      strcat(key, "\\.default");
250
211
  else
251
212
    {
252
213
      char key[MAX_PATH];
253
 
      
 
214
 
254
215
      strcpy(key, "AppEvents\\Schemes\\Apps\\Workrave\\");
255
216
      strcat(key, SoundPlayer::sound_registry[snd].label);
256
217
      strcat(key, "\\.current");
257
 
  
 
218
 
258
219
      registry_set_value(key, NULL, "");
259
220
    }
260
221
}
268
229
  strcpy(key, "AppEvents\\Schemes\\Apps\\Workrave\\");
269
230
  strcat(key, SoundPlayer::sound_registry[snd].label);
270
231
  strcat(key, "\\.current");
271
 
  
 
232
 
272
233
  if (registry_get_value(key, NULL, val))
273
234
    {
274
235
      wav_file = val;
283
244
          wav_file = val;
284
245
        }
285
246
    }
286
 
  
287
 
  return true;;
 
247
 
 
248
  return true;
288
249
}
289
250
 
290
251
void
298
259
    {
299
260
      registry_set_value(key, NULL, SoundPlayer::sound_registry[snd].friendly_name);
300
261
    }
301
 
  
 
262
 
302
263
  strcpy(key, "AppEvents\\Schemes\\Apps\\Workrave\\");
303
264
  strcat(key, SoundPlayer::sound_registry[snd].label);
304
265
  strcat(key, "\\.default");
337
298
  catch(...)
338
299
    {
339
300
    }
340
 
 
 
301
 
341
302
  delete clip;
342
 
 
 
303
  
343
304
  TRACE_EXIT();
344
305
  return (DWORD) 0;
345
306
}
346
307
 
347
308
 
348
309
 
349
 
SoundClip::SoundClip(LPDIRECTSOUND8 direct_sound, const string &filename, ISoundDriverEvents *events)
 
310
SoundClip::SoundClip(const string &filename, ISoundDriverEvents *events)
350
311
{
351
312
  TRACE_ENTER("SoundClip::SoundClip");
352
 
  direct_sound->AddRef();
353
313
 
354
 
  this->direct_sound = direct_sound;
 
314
  this->direct_sound = NULL;
355
315
  this->filename = filename;
356
316
  this->events = events;
357
317
 
367
327
SoundClip::~SoundClip()
368
328
{
369
329
  TRACE_ENTER("SoundClip::~SoundClip");
370
 
  if (direct_sound != NULL)
371
 
    {
372
 
      direct_sound->Release();
373
 
      direct_sound = NULL;
374
 
    }
375
 
 
376
330
  if (sound_buffer != NULL)
377
331
    {
378
332
      sound_buffer->Release();
384
338
      CloseHandle(stop_event);
385
339
      stop_event = NULL;
386
340
    }
387
 
  
 
341
 
 
342
  if (direct_sound != NULL)
 
343
    {
 
344
      direct_sound->Release();
 
345
      direct_sound = NULL;
 
346
    }
 
347
 
388
348
  delete wave_file;
389
349
  wave_file = NULL;
390
350
 
398
358
  HRESULT hr = S_OK;
399
359
 
400
360
  TRACE_ENTER("SoundClip::init");
 
361
 
 
362
  hr = DirectSoundCreate8(NULL, &direct_sound, NULL);
 
363
  if (FAILED(hr) || direct_sound == NULL)
 
364
    {
 
365
      throw Exception(string("DirectSoundCreate8") + DXGetErrorString8(hr));
 
366
    }
 
367
 
 
368
  hr = direct_sound->SetCooperativeLevel(GetDesktopWindow(), DSSCL_PRIORITY);
 
369
  if (FAILED(hr))
 
370
    {
 
371
      throw Exception(string("IDirectSound_SetCooperativeLevel") + DXGetErrorString8(hr));
 
372
    }
401
373
  
402
374
  wave_file = new WaveFile(filename);
403
375
  wave_file->init();
437
409
  DSBPOSITIONNOTIFY pn;
438
410
  pn.dwOffset = DSBPN_OFFSETSTOP;
439
411
  pn.hEventNotify = stop_event;
440
 
  
 
412
 
441
413
  hr = notify->SetNotificationPositions(1, &pn);
442
414
  if (FAILED(hr))
443
415
    {
460
432
{
461
433
  TRACE_ENTER("SoundClip::fill_buffer");
462
434
 
463
 
  HRESULT hr; 
 
435
  HRESULT hr;
464
436
  VOID *locked_sound_buffer = NULL;
465
437
  DWORD locked_sound_buffer_size = 0;
466
438
 
467
439
  restore_buffer();
468
440
 
469
 
  hr = sound_buffer->Lock(0, sound_buffer_size, 
470
 
                          &locked_sound_buffer, &locked_sound_buffer_size, 
 
441
  hr = sound_buffer->Lock(0, sound_buffer_size,
 
442
                          &locked_sound_buffer, &locked_sound_buffer_size,
471
443
                          NULL, NULL, 0L);
472
444
  if (FAILED(hr))
473
445
    {
480
452
 
481
453
  if (locked_sound_buffer_size - bytes_read > 0)
482
454
    {
483
 
      FillMemory((BYTE*) locked_sound_buffer + bytes_read, 
484
 
                 locked_sound_buffer_size - bytes_read, 
 
455
      FillMemory((BYTE*) locked_sound_buffer + bytes_read,
 
456
                 locked_sound_buffer_size - bytes_read,
485
457
                 (BYTE)(wave_file->get_format()->wBitsPerSample == 8 ? 128 : 0));
486
458
    }
487
 
  
 
459
 
488
460
  sound_buffer->Unlock(locked_sound_buffer, locked_sound_buffer_size, NULL, 0);
489
461
  sound_buffer->SetCurrentPosition(0);
490
462
  TRACE_EXIT();
516
488
{
517
489
  TRACE_ENTER("SoundClip::restore_buffer");
518
490
  HRESULT hr = S_OK;
519
 
  do 
 
491
  do
520
492
    {
521
493
      hr = sound_buffer->Restore();
522
494
      if (hr == DSERR_BUFFERLOST)
544
516
    {
545
517
      events->eos_event();
546
518
    }
547
 
  
 
519
 
548
520
  TRACE_EXIT();
549
521
}
550
522
 
556
528
  if (sound_buffer != NULL)
557
529
    {
558
530
      long dsVolume;
559
 
      
 
531
 
560
532
      if (volume == 0)
561
533
        {
562
534
          dsVolume = -10000;
565
537
        {
566
538
          dsVolume = 100 * (long) (20 * log10((double) volume / 100.0));
567
539
        }
568
 
      
 
540
 
569
541
      dsVolume = CLAMP(dsVolume, -10000, 0);
570
542
 
571
543
      sound_buffer->SetVolume(dsVolume);
620
592
      TRACE_RETURN("Exception: mmioDescend1");
621
593
      throw Exception("mmioDescend1");
622
594
    }
623
 
  
 
595
 
624
596
  if (parent.ckid != FOURCC_RIFF || parent.fccType != mmioFOURCC('W', 'A', 'V', 'E' ))
625
597
    {
626
598
      TRACE_RETURN("Exception: no Wave");
630
602
  memset((void *)&child, 0, sizeof(child));
631
603
 
632
604
  child.ckid = mmioFOURCC('f', 'm', 't', ' ');
633
 
  
 
605
 
634
606
  res = mmioDescend(mmio, &child, &parent, MMIO_FINDCHUNK);
635
607
  if (res != MMSYSERR_NOERROR)
636
608
    {
709
681
      TRACE_RETURN("Exception: mmioGetInfo");
710
682
      throw Exception("mmioGetInfo");
711
683
    }
712
 
  
 
684
 
713
685
  int pos = 0;
714
686
  do
715
687
    {
716
688
      size_t copy = mmioInfo.pchEndRead - mmioInfo.pchNext;
717
689
 
718
 
      if (copy > 0) 
719
 
        {       
 
690
      if (copy > 0)
 
691
        {
720
692
          if (copy > size - pos)
721
693
            {
722
694
              copy = size - pos;
730
702
 
731
703
    } while (pos < (int)size && mmioAdvance(mmio, &mmioInfo, MMIO_READ) == 0);
732
704
 
733
 
  mmioSetInfo(mmio, &mmioInfo, 0); 
 
705
  mmioSetInfo(mmio, &mmioInfo, 0);
734
706
 
735
707
  TRACE_EXIT();
736
708
  return pos;