aboutsummaryrefslogtreecommitdiff
path: root/src/lua/audio
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/audio')
-rw-r--r--src/lua/audio/Source.h93
-rw-r--r--src/lua/audio/luaopen_Source.cpp115
-rw-r--r--src/lua/audio/luaopen_audio.cpp109
3 files changed, 0 insertions, 317 deletions
diff --git a/src/lua/audio/Source.h b/src/lua/audio/Source.h
deleted file mode 100644
index 094ad12..0000000
--- a/src/lua/audio/Source.h
+++ /dev/null
@@ -1,93 +0,0 @@
-#ifndef __JIN_LUA_AUDIO_SOURCE_H
-#define __JIN_LUA_AUDIO_SOURCE_H
-#include "libjin/jin.h"
-#include "../luaopen_types.h"
-
-namespace jin
-{
-namespace lua
-{
-namespace audio
-{
-
- class Source : public Object
- {
- public:
- void play()
- {
- source->play();
- }
-
- void stop()
- {
- source->stop();
- }
-
- void pause()
- {
- source->pause();
- }
-
- void resume()
- {
- source->resume();
- }
-
- void rewind()
- {
- source->rewind();
- }
-
- bool isStopped() const
- {
- return source->isStopped();
- }
-
- bool isPaused() const
- {
- return source->isPaused();
- }
-
- void setPitch(float pitch)
- {
- source->setPitch(pitch);
- }
-
- void setVolume(float volume)
- {
- source->setVolume(volume);
- }
-
- bool setLoop(bool loop)
- {
- return source->setLoop(loop);
- }
-
- void setRate(float rate)
- {
- source->setRate(rate);
- }
-
- inline static Source * createSource(void* mem, size_t size)
- {
- Source* src = new Source;
- src->source = jin::audio::SDLSource::createSource(mem, size);
- return src;
- }
-
- private:
- ~Source()
- {
- source->stop();
- delete source;
- }
-
- jin::audio::SDLSource* source;
-
- };
-
-} // audio
-} // lua
-} // jin
-
-#endif \ No newline at end of file
diff --git a/src/lua/audio/luaopen_Source.cpp b/src/lua/audio/luaopen_Source.cpp
deleted file mode 100644
index aa71184..0000000
--- a/src/lua/audio/luaopen_Source.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-#include "lua/luax.h"
-#include "libjin/jin.h"
-#include "../common/common.h"
-
-namespace jin
-{
-namespace lua
-{
-
- using namespace jin::audio;
-
- typedef Ref<Source>& SourceRef;
-
- static inline SourceRef checkSource(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_AUDIO_SOURCE);
- return proxy->getRef<Source>();
- }
-
- static int l_play(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->play();
- return 0;
- }
-
- static int l_stop(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->stop();
- return 0;
- }
-
- static int l_pause(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->pause();
- return 0;
- }
-
- static int l_rewind(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->rewind();
- return 0;
- }
-
- static int l_resume(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->resume();
- return 0;
- }
-
- static int l_isStop(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- bool isStop = ref->isStopped();
- luax_pushboolean(L, isStop);
- return 1;
- }
-
- static int l_isPaused(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- bool isPaused = ref->isPaused();
- luax_pushboolean(L, isPaused);
- return 1;
- }
-
- static int l_setVolume(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- float volume = luax_checknumber(L, 2);
- ref->setVolume(volume);
- return 0;
- }
-
- static int l_setLoop(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- bool loop = luax_checkbool(L, 2);
- ref->setLoop(loop);
- return 0;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_AUDIO_SOURCE);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "play", l_play },
- { "stop", l_stop },
- { "pause", l_pause },
- { "resume", l_resume },
- { "rewind", l_rewind },
- { "isStop", l_isStop },
- { "isPaused", l_isPaused },
- { "setVolume", l_setVolume },
- { "setLoop", l_setLoop },
- { 0, 0 }
- };
-
- int luaopen_Source(lua_State* L)
- {
- luax_newtype(L, JIN_AUDIO_SOURCE, f);
- return 0;
- }
-
-} // lua
-} // jin \ No newline at end of file
diff --git a/src/lua/audio/luaopen_audio.cpp b/src/lua/audio/luaopen_audio.cpp
deleted file mode 100644
index c87df3a..0000000
--- a/src/lua/audio/luaopen_audio.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-#include "lua/luax.h"
-#include "../common/common.h"
-#include "libjin/jin.h"
-
-namespace jin
-{
-namespace lua
-{
-
- using namespace jin::audio;
- using namespace jin::filesystem;
-
- typedef SDLAudio Audio;
- typedef SDLSource Source;
-
- static int l_init(lua_State* L)
- {
- Audio::Setting setting;
- setting.samplerate = 44100;
- setting.samples = 44100;
- if (!Audio::get()->init(&setting))
- {
- luax_error(L, "could not init audio");
- luax_pushboolean(L, false);
- return 1;
- }
- luax_pushboolean(L, true);
- return 1;
- }
-
- static int l_play(lua_State* L)
- {
- Audio::get()->play();
- return 0;
- }
-
- static int l_stop(lua_State* L)
- {
- Audio::get()->stop();
- return 0;
- }
-
- static int l_pause(lua_State* L)
- {
- Audio::get()->pause();
- return 0;
- }
-
- static int l_resume(lua_State* L)
- {
- Audio::get()->resume();
- return 0;
- }
-
- static int l_setVolume(lua_State* L)
- {
- float volume = luax_checknumber(L, 1);
- Audio::get()->setVolume(volume);
- return 0;
- }
-
- static int l_newSource(lua_State* L)
- {
- Filesystem* fs = Filesystem::get();
- const char* f = luax_checkstring(L, 1);
- if (!fs->exists(f))
- {
- printf("Error: no such image %s\n", f);
- exit(1);
- }
- Buffer b;
- fs->read(f, &b);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_AUDIO_SOURCE, sizeof(Proxy));
- Source* src = Source::createSource(b.data, b.size);
- proxy->bind(new Ref<Source>(src, JIN_AUDIO_SOURCE));
- return 1;
- }
-
- static int l_destroy(lua_State* L)
- {
- Audio* audio = Audio::get();
- audio->quit();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "init", l_init },
- { "play", l_play },
- { "stop", l_stop },
- { "pause", l_pause },
- { "resume", l_resume },
- { "setVolume", l_setVolume },
- { "newSource", l_newSource },
- { "destroy", l_destroy },
- { 0, 0 }
- };
-
- extern int luaopen_Source(lua_State* L);
-
- int luaopen_audio(lua_State* L)
- {
- luaopen_Source(L);
-
- luax_newlib(L, f);
-
- return 1;
- }
-}
-} \ No newline at end of file