1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ags/engine/ac/audio_channel.h"
#include "ags/engine/ac/game_state.h"
#include "ags/engine/ac/global_audio.h"
#include "ags/engine/ac/dynobj/cc_audio_clip.h"
#include "ags/engine/debugging/debug_log.h"
#include "ags/shared/game/room_struct.h"
#include "ags/engine/script/runtime_script_value.h"
#include "ags/engine/media/audio/audio_system.h"
#include "ags/shared/ac/game_setup_struct.h"
#include "ags/shared/debugging/out.h"
#include "ags/engine/script/script_api.h"
#include "ags/engine/script/script_runtime.h"
#include "ags/globals.h"
namespace AGS3 {
using namespace AGS::Shared;
int AudioChannel_GetID(ScriptAudioChannel *channel) {
return channel->id;
}
int AudioChannel_GetIsPlaying(ScriptAudioChannel *channel) {
if (_GP(play).fast_forward) {
return 0;
}
return AudioChans::ChannelIsPlaying(channel->id) ? 1 : 0;
}
bool AudioChannel_GetIsPaused(ScriptAudioChannel *channel) {
auto *ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch) return ch->is_paused();
return false;
}
int AudioChannel_GetPanning(ScriptAudioChannel *channel) {
auto *ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch) {
return ch->get_panning();
}
return 0;
}
void AudioChannel_SetPanning(ScriptAudioChannel *channel, int newPanning) {
if ((newPanning < -100) || (newPanning > 100))
quitprintf("!AudioChannel.Panning: panning value must be between -100 and 100 (passed=%d)", newPanning);
auto *ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch) {
ch->set_panning(newPanning);
}
}
ScriptAudioClip *AudioChannel_GetPlayingClip(ScriptAudioChannel *channel) {
auto *ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch && ch->_sourceClipID >= 0) {
return &_GP(game).audioClips[ch->_sourceClipID];
}
return nullptr;
}
int AudioChannel_GetPosition(ScriptAudioChannel *channel) {
auto *ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch) {
if (_GP(play).fast_forward)
return 999999999;
return ch->get_pos();
}
return 0;
}
int AudioChannel_GetPositionMs(ScriptAudioChannel *channel) {
auto *ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch) {
if (_GP(play).fast_forward)
return 999999999;
return ch->get_pos_ms();
}
return 0;
}
int AudioChannel_GetLengthMs(ScriptAudioChannel *channel) {
auto *ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch) {
return ch->get_length_ms();
}
return 0;
}
int AudioChannel_GetVolume(ScriptAudioChannel *channel) {
auto *ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch) {
return ch->get_volume100();
}
return 0;
}
int AudioChannel_SetVolume(ScriptAudioChannel *channel, int newVolume) {
if ((newVolume < 0) || (newVolume > 100))
quitprintf("!AudioChannel.Volume: new value out of range (supplied: %d, range: 0..100)", newVolume);
auto *ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch) {
ch->set_volume100(newVolume);
}
return 0;
}
int AudioChannel_GetSpeed(ScriptAudioChannel *channel) {
auto *ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch) {
return ch->get_speed();
}
return 0;
}
void AudioChannel_SetSpeed(ScriptAudioChannel *channel, int new_speed) {
auto *ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch) {
ch->set_speed(new_speed);
}
}
void AudioChannel_Stop(ScriptAudioChannel *channel) {
if (channel->id == SCHAN_SPEECH && _GP(play).IsNonBlockingVoiceSpeech())
stop_voice_nonblocking();
else
stop_or_fade_out_channel(channel->id, -1, nullptr);
}
void AudioChannel_Pause(ScriptAudioChannel *channel) {
auto *ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch) ch->pause();
}
void AudioChannel_Resume(ScriptAudioChannel *channel) {
auto *ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch) ch->resume();
}
void AudioChannel_Seek(ScriptAudioChannel *channel, int newPosition) {
if (newPosition < 0)
quitprintf("!AudioChannel.Seek: invalid seek position %d", newPosition);
auto *ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch)
ch->seek(newPosition);
}
void AudioChannel_SeekMs(ScriptAudioChannel *channel, int newPosition) {
if (newPosition < 0)
quitprintf("!AudioChannel.SeekMs: invalid seek position %d", newPosition);
auto* ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch)
ch->seek_ms(newPosition);
}
void AudioChannel_SetRoomLocation(ScriptAudioChannel *channel, int xPos, int yPos) {
auto *ch = AudioChans::GetChannelIfPlaying(channel->id);
if (ch) {
int maxDist = ((xPos > _GP(thisroom).Width / 2) ? xPos : (_GP(thisroom).Width - xPos)) - AMBIENCE_FULL_DIST;
ch->_xSource = (xPos > 0) ? xPos : -1;
ch->_ySource = yPos;
ch->_maximumPossibleDistanceAway = maxDist;
if (xPos > 0) {
update_directional_sound_vol();
} else {
ch->apply_directional_modifier(0);
}
}
}
//=============================================================================
//
// Script API Functions
//
//=============================================================================
// int | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetID(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetID);
}
// int | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetIsPlaying(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetIsPlaying);
}
// int | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetPanning(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetPanning);
}
// void | ScriptAudioChannel *channel, int newPanning
RuntimeScriptValue Sc_AudioChannel_SetPanning(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptAudioChannel, AudioChannel_SetPanning);
}
// ScriptAudioClip* | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetPlayingClip(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_OBJ(ScriptAudioChannel, ScriptAudioClip, _GP(ccDynamicAudioClip), AudioChannel_GetPlayingClip);
}
// int | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetPosition(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetPosition);
}
// int | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetPositionMs(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetPositionMs);
}
// int | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetLengthMs(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetLengthMs);
}
// int | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_GetVolume(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetVolume);
}
// int | ScriptAudioChannel *channel, int newVolume
RuntimeScriptValue Sc_AudioChannel_SetVolume(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT_PINT(ScriptAudioChannel, AudioChannel_SetVolume);
}
// void | ScriptAudioChannel *channel
RuntimeScriptValue Sc_AudioChannel_Stop(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID(ScriptAudioChannel, AudioChannel_Stop);
}
// void | ScriptAudioChannel *channel, int newPosition
RuntimeScriptValue Sc_AudioChannel_Seek(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptAudioChannel, AudioChannel_Seek);
}
RuntimeScriptValue Sc_AudioChannel_SeekMs(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptAudioChannel, AudioChannel_SeekMs);
}
// void | ScriptAudioChannel *channel, int xPos, int yPos
RuntimeScriptValue Sc_AudioChannel_SetRoomLocation(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT2(ScriptAudioChannel, AudioChannel_SetRoomLocation);
}
RuntimeScriptValue Sc_AudioChannel_GetSpeed(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_INT(ScriptAudioChannel, AudioChannel_GetSpeed);
}
RuntimeScriptValue Sc_AudioChannel_SetSpeed(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID_PINT(ScriptAudioChannel, AudioChannel_SetSpeed);
}
RuntimeScriptValue Sc_AudioChannel_Pause(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID(ScriptAudioChannel, AudioChannel_Pause);
}
RuntimeScriptValue Sc_AudioChannel_Resume(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_VOID(ScriptAudioChannel, AudioChannel_Resume);
}
RuntimeScriptValue Sc_AudioChannel_GetIsPaused(void *self, const RuntimeScriptValue *params, int32_t param_count) {
API_OBJCALL_BOOL(ScriptAudioChannel, AudioChannel_GetIsPaused);
}
void RegisterAudioChannelAPI() {
ScFnRegister audiochan_api[] = {
{"AudioChannel::Pause^0", API_FN_PAIR(AudioChannel_Pause)},
{"AudioChannel::Resume^0", API_FN_PAIR(AudioChannel_Resume)},
{"AudioChannel::Seek^1", API_FN_PAIR(AudioChannel_Seek)},
{"AudioChannel::SeekMs^1", API_FN_PAIR(AudioChannel_SeekMs)},
{"AudioChannel::SetRoomLocation^2", API_FN_PAIR(AudioChannel_SetRoomLocation)},
{"AudioChannel::Stop^0", API_FN_PAIR(AudioChannel_Stop)},
{"AudioChannel::get_ID", API_FN_PAIR(AudioChannel_GetID)},
{"AudioChannel::get_IsPaused", API_FN_PAIR(AudioChannel_GetIsPaused)},
{"AudioChannel::get_IsPlaying", API_FN_PAIR(AudioChannel_GetIsPlaying)},
{"AudioChannel::get_LengthMs", API_FN_PAIR(AudioChannel_GetLengthMs)},
{"AudioChannel::get_Panning", API_FN_PAIR(AudioChannel_GetPanning)},
{"AudioChannel::set_Panning", API_FN_PAIR(AudioChannel_SetPanning)},
{"AudioChannel::get_PlayingClip", API_FN_PAIR(AudioChannel_GetPlayingClip)},
{"AudioChannel::get_Position", API_FN_PAIR(AudioChannel_GetPosition)},
{"AudioChannel::get_PositionMs", API_FN_PAIR(AudioChannel_GetPositionMs)},
{"AudioChannel::get_Volume", API_FN_PAIR(AudioChannel_GetVolume)},
{"AudioChannel::set_Volume", API_FN_PAIR(AudioChannel_SetVolume)},
{"AudioChannel::get_Speed", API_FN_PAIR(AudioChannel_GetSpeed)},
{"AudioChannel::set_Speed", API_FN_PAIR(AudioChannel_SetSpeed)},
// For compatibility with Ahmet Kamil's (aka Gord10) custom engine
{"AudioChannel::SetSpeed^1", API_FN_PAIR(AudioChannel_SetSpeed)},
};
ccAddExternalFunctions361(audiochan_api);
}
} // namespace AGS3
|