source: trunk/src/sampler.cpp @ 253

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

Add preliminary support for sound samples. Implement click.

  • Property svn:keywords set to Id
File size: 1.1 KB
Line 
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
17/*
18 * Sampler implementation class
19 */
20
21static class SamplerData
22{
23    friend class Sampler;
24
25public:
26    Dict samples;
27}
28samplerdata;
29
30static SamplerData * const data = &samplerdata;
31
32/*
33 * Public Sampler class
34 */
35
36int Sampler::Register(char const *path)
37{
38    int id = data->samples.MakeSlot(path);
39
40    if (!data->samples.GetEntity(id))
41    {
42        Sample *sample = new Sample(path);
43        data->samples.SetEntity(id, sample);
44    }
45
46    return id + 1; /* ID 0 is for the empty sample */
47}
48
49void Sampler::Deregister(int id)
50{
51    data->samples.RemoveSlot(id - 1); /* ID 0 is for the empty sample */
52}
53
54void Sampler::PlaySample(int id)
55{
56    Sample *sample = (Sample *)data->samples.GetEntity(id - 1);
57    sample->Play();
58}
59
Note: See TracBrowser for help on using the repository browser.