]> Dogcows Code - chaz/yoink/blob - src/moof/sound_bindings.cc
remove some unused stlplus modules
[chaz/yoink] / src / moof / sound_bindings.cc
1
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
4 *
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
7 *
8 *****************************************************************************/
9
10 #include "script.hh"
11 #include "sound.hh"
12
13
14 namespace moof {
15
16
17 static int sound_new(script& script)
18 {
19 std::string str;
20 if (script[2].get(str))
21 {
22 sound sound(str);
23
24 for (int i = 3; script[i]; ++i)
25 {
26 if (script[i].get(str)) sound.queue(str);
27 else break;
28 }
29
30 script.push(sound);
31 return 1;
32 }
33
34 script.push(sound());
35 return 1;
36 }
37
38 static int sound_sample(script& script)
39 {
40 sound* sound;
41 script[1].require_object<moof::sound>("sound").get(sound);
42
43 std::string name;
44 script[2].require_string("sound name").get(name);
45
46 sound->sample(name);
47 return 0;
48 }
49
50 static int sound_queue(script& script)
51 {
52 sound* sound;
53 script[1].require_object<moof::sound>("sound").get(sound);
54
55 std::string name;
56 for (int i = 2; script[i]; ++i)
57 {
58 if (script[i].get(name)) sound->queue(name);
59 else break;
60 }
61 return 0;
62 }
63
64 static int sound_play(script& script)
65 {
66 sound* sound;
67 script[1].require_object<moof::sound>("sound").get(sound);
68 sound->play();
69 return 0;
70 }
71
72 static int sound_stop(script& script)
73 {
74 sound* sound;
75 script[1].require_object<moof::sound>("sound").get(sound);
76 sound->stop();
77 return 0;
78 }
79
80 static int sound_pause(script& script)
81 {
82 sound* sound;
83 script[1].require_object<moof::sound>("sound").get(sound);
84 sound->pause();
85 return 0;
86 }
87
88 static int sound_toggle(script& script)
89 {
90 sound* sound;
91 script[1].require_object<moof::sound>("sound").get(sound);
92 sound->toggle();
93 return 0;
94 }
95
96 static int sound_is_playing(script& script)
97 {
98 sound* sound;
99 script[1].require_object<moof::sound>("sound").get(sound);
100 script.push(sound->is_playing());
101 return 1;
102 }
103
104 void sound::import(script& script, const std::string& nspace)
105 {
106 script.check_stack(4);
107
108 script::slot parent = script.push_table(nspace);
109 script::slot meta = script.push_class<sound>(sound_new);
110
111 meta.set_field("is_playing", sound_is_playing);
112 meta.set_field("pause", sound_pause);
113 meta.set_field("play", sound_play);
114 meta.set_field("queue", sound_queue);
115 meta.set_field("sample", sound_sample);
116 meta.set_field("stop", sound_stop);
117 meta.set_field("toggle", sound_toggle);
118
119 parent.set_field("sound");
120 parent.pop();
121 }
122
123
124 } // namespace moof
125
This page took 0.033602 seconds and 4 git commands to generate.