source: trunk/src/sampler.cpp @ 686

Last change on this file since 686 was 686, checked in by sam, 9 years ago

Put everything in the "lol" namespace. Better late than never.

  • Property svn:keywords set to Id
File size: 1.2 KB
RevLine 
[251]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
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include "core.h"
16
[686]17namespace lol
18{
19
[251]20/*
21 * Sampler implementation class
22 */
23
24static class SamplerData
25{
26    friend class Sampler;
27
28public:
29    Dict samples;
30}
31samplerdata;
32
33static SamplerData * const data = &samplerdata;
34
35/*
36 * Public Sampler class
37 */
38
39int Sampler::Register(char const *path)
40{
41    int id = data->samples.MakeSlot(path);
42
43    if (!data->samples.GetEntity(id))
44    {
45        Sample *sample = new Sample(path);
46        data->samples.SetEntity(id, sample);
47    }
48
49    return id + 1; /* ID 0 is for the empty sample */
50}
51
52void Sampler::Deregister(int id)
53{
54    data->samples.RemoveSlot(id - 1); /* ID 0 is for the empty sample */
55}
56
57void Sampler::PlaySample(int id)
58{
[253]59    Sample *sample = (Sample *)data->samples.GetEntity(id - 1);
[251]60    sample->Play();
61}
62
[686]63} /* namespace lol */
64
Note: See TracBrowser for help on using the repository browser.