Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

73 рядки
1.3 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://www.wtfpl.net/ for more details.
  9. //
  10. #include <lol/engine-internal.h>
  11. namespace lol
  12. {
  13. /*
  14. * Sampler implementation class
  15. */
  16. static class SamplerData
  17. {
  18. friend class Sampler;
  19. public:
  20. Dict samples;
  21. }
  22. samplerdata;
  23. static SamplerData * const data = &samplerdata;
  24. /*
  25. * Public Sampler class
  26. */
  27. int Sampler::Register(char const *path)
  28. {
  29. int id = data->samples.MakeSlot(path);
  30. if (!data->samples.GetEntity(id))
  31. {
  32. Sample *sample = new Sample(path);
  33. data->samples.SetEntity(id, sample);
  34. }
  35. return id + 1; /* ID 0 is for the empty sample */
  36. }
  37. void Sampler::Deregister(int id)
  38. {
  39. data->samples.RemoveSlot(id - 1); /* ID 0 is for the empty sample */
  40. }
  41. void Sampler::PlaySample(int id)
  42. {
  43. Sample *sample = (Sample *)data->samples.GetEntity(id - 1);
  44. sample->Play();
  45. }
  46. void Sampler::LoopSample(int id)
  47. {
  48. Sample *sample = (Sample *)data->samples.GetEntity(id - 1);
  49. sample->Loop();
  50. }
  51. void Sampler::StopSample(int id)
  52. {
  53. Sample *sample = (Sample *)data->samples.GetEntity(id - 1);
  54. sample->Stop();
  55. }
  56. } /* namespace lol */