2013-09-01 14:27:21 +00:00
|
|
|
/*
|
|
|
|
** audio-binding.cpp
|
|
|
|
**
|
|
|
|
** This file is part of mkxp.
|
|
|
|
**
|
|
|
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
|
|
**
|
|
|
|
** mkxp is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 2 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** mkxp is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "audio.h"
|
2013-10-09 10:30:33 +00:00
|
|
|
#include "sharedstate.h"
|
2013-09-01 14:27:21 +00:00
|
|
|
#include "binding-util.h"
|
|
|
|
#include "exception.h"
|
|
|
|
|
|
|
|
#define DEF_PLAY_STOP(entity) \
|
|
|
|
RB_METHOD(audio_##entity##Play) \
|
|
|
|
{ \
|
|
|
|
RB_UNUSED_PARAM; \
|
|
|
|
const char *filename; \
|
|
|
|
int volume = 100; \
|
|
|
|
int pitch = 100; \
|
2013-12-20 10:29:12 +00:00
|
|
|
rb_get_args(argc, argv, "z|ii", &filename, &volume, &pitch RB_ARG_END); \
|
2013-10-09 10:30:33 +00:00
|
|
|
GUARD_EXC( shState->audio().entity##Play(filename, volume, pitch); ) \
|
2013-09-01 14:27:21 +00:00
|
|
|
return Qnil; \
|
|
|
|
} \
|
|
|
|
RB_METHOD(audio_##entity##Stop) \
|
|
|
|
{ \
|
|
|
|
RB_UNUSED_PARAM; \
|
2013-10-09 10:30:33 +00:00
|
|
|
shState->audio().entity##Stop(); \
|
2013-09-01 14:27:21 +00:00
|
|
|
return Qnil; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEF_FADE(entity) \
|
|
|
|
RB_METHOD(audio_##entity##Fade) \
|
|
|
|
{ \
|
|
|
|
RB_UNUSED_PARAM; \
|
|
|
|
int time; \
|
2013-12-20 10:29:12 +00:00
|
|
|
rb_get_args(argc, argv, "i", &time RB_ARG_END); \
|
2013-10-16 23:02:09 +00:00
|
|
|
shState->audio().entity##Fade(time); \
|
2013-09-01 14:27:21 +00:00
|
|
|
return Qnil; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEF_PLAY_STOP_FADE(entity) \
|
|
|
|
DEF_PLAY_STOP(entity) \
|
|
|
|
DEF_FADE(entity)
|
|
|
|
|
|
|
|
DEF_PLAY_STOP_FADE( bgm )
|
|
|
|
DEF_PLAY_STOP_FADE( bgs )
|
|
|
|
DEF_PLAY_STOP_FADE( me )
|
|
|
|
|
|
|
|
DEF_PLAY_STOP( se )
|
|
|
|
|
|
|
|
|
|
|
|
#define BIND_PLAY_STOP(entity) \
|
|
|
|
_rb_define_module_function(module, #entity "_play", audio_##entity##Play); \
|
|
|
|
_rb_define_module_function(module, #entity "_stop", audio_##entity##Stop);
|
|
|
|
|
|
|
|
#define BIND_FADE(entity) \
|
|
|
|
_rb_define_module_function(module, #entity "_fade", audio_##entity##Fade);
|
|
|
|
|
|
|
|
#define BIND_PLAY_STOP_FADE(entity) \
|
|
|
|
BIND_PLAY_STOP(entity) \
|
|
|
|
BIND_FADE(entity)
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
audioBindingInit()
|
|
|
|
{
|
|
|
|
VALUE module = rb_define_module("Audio");
|
|
|
|
|
|
|
|
BIND_PLAY_STOP_FADE( bgm )
|
|
|
|
BIND_PLAY_STOP_FADE( bgs )
|
|
|
|
BIND_PLAY_STOP_FADE( me )
|
|
|
|
|
|
|
|
BIND_PLAY_STOP( se )
|
|
|
|
}
|