You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

60 lines
1.1 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include "core.h"
  14. /*
  15. * Sampler implementation class
  16. */
  17. static class SamplerData
  18. {
  19. friend class Sampler;
  20. public:
  21. Dict samples;
  22. }
  23. samplerdata;
  24. static SamplerData * const data = &samplerdata;
  25. /*
  26. * Public Sampler class
  27. */
  28. int Sampler::Register(char const *path)
  29. {
  30. int id = data->samples.MakeSlot(path);
  31. if (!data->samples.GetEntity(id))
  32. {
  33. Sample *sample = new Sample(path);
  34. data->samples.SetEntity(id, sample);
  35. }
  36. return id + 1; /* ID 0 is for the empty sample */
  37. }
  38. void Sampler::Deregister(int id)
  39. {
  40. data->samples.RemoveSlot(id - 1); /* ID 0 is for the empty sample */
  41. }
  42. void Sampler::PlaySample(int id)
  43. {
  44. Sample *sample = (Sample *)data->samples.GetEntity(id - 1);
  45. sample->Play();
  46. }