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