Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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