From 5f50a8ea260f9a9114ac0a11a651f0385586465a Mon Sep 17 00:00:00 2001 From: Kyzentun Keeslala Date: Wed, 10 Jun 2015 14:41:28 -0600 Subject: [PATCH] Added get_music_file_length and RageSound:get_length lua functions. Updated changelog. --- Docs/Changelog_sm5.txt | 8 +++++++ Docs/Luadoc/Lua.xml | 2 ++ Docs/Luadoc/LuaDocumentation.xml | 10 +++++++- src/RageSound.cpp | 14 +++++++++++ src/RageUtil.cpp | 40 ++++++++++++++++++++++++++------ 5 files changed, 66 insertions(+), 8 deletions(-) diff --git a/Docs/Changelog_sm5.txt b/Docs/Changelog_sm5.txt index 4e22dff4dc..967abc4c6a 100644 --- a/Docs/Changelog_sm5.txt +++ b/Docs/Changelog_sm5.txt @@ -4,6 +4,14 @@ The StepMania 5 Changelog covers all post-sm-ssc changes. For a list of changes from StepMania 4 alpha 5 to sm-ssc v1.2.5, see Changelog_sm-ssc.txt. ________________________________________________________________________________ +2015/06/10 +---------- +* [global] get_music_file_length lua function added. [kyzentun] + multiapproach lua function now takes an optional 4th argument to multiply + the speeds by. [kyzentun] +* [NoteDisplay] 1px seam in hold cap rendering fixed. [A.C/waiei] +* [RageSound] get_length lua function added. [kyzentun] + 2015/06/06 ---------- * [ScreenInitialScreenIsInvalid] Error screen for themes that set an invalid diff --git a/Docs/Luadoc/Lua.xml b/Docs/Luadoc/Lua.xml index 426391f963..d0cab7118c 100644 --- a/Docs/Luadoc/Lua.xml +++ b/Docs/Luadoc/Lua.xml @@ -221,6 +221,7 @@ + @@ -1393,6 +1394,7 @@ + diff --git a/Docs/Luadoc/LuaDocumentation.xml b/Docs/Luadoc/LuaDocumentation.xml index 6cc77d8986..2142ce3cb5 100644 --- a/Docs/Luadoc/LuaDocumentation.xml +++ b/Docs/Luadoc/LuaDocumentation.xml @@ -208,6 +208,10 @@ save yourself some time, copy this for undocumented things: Returns the current Life Difficulty. + + Returns the length of the music file found at path.
+ If you are loading the sound into an ActorSound, ActorSound:get to get its RageSound then use RageSound's get_length function instead to avoid loading the file twice. +
Returns a string representing the name of the operating system being used. (e.g. "Windows", "Linux", "Mac, "Unknown") @@ -402,9 +406,10 @@ save yourself some time, copy this for undocumented things: Returns Month m as a string. - + Similar to approach, but operates on tables of values instead of single values. This will modify the contents of currents in place, as well as returning currents.
currents, goals, and speeds must all be the same size and contain only numbers.
+ multiplier is optional. The speeds in the speeds table will be multiplied by multiplier. This makes it more convenient to use multiapproach in a per-frame update: pass in the frame delta and the speeds will be scaled to the time that passed.
Note: When you see the error "approach: speed 1 is negative." it means that a speed value passed was negative. The 1 tells you which entry in the table was invalid.
@@ -4112,6 +4117,9 @@ save yourself some time, copy this for undocumented things: See for loading a sound. + + Returns the length of the sound loaded into this RageSound. Returns -1 if no sound is loaded. + Actually sets the value of sProperty to fVal. The supported properties depend on how the associated was loaded. diff --git a/src/RageSound.cpp b/src/RageSound.cpp index 771f850e30..81fafdcfe4 100644 --- a/src/RageSound.cpp +++ b/src/RageSound.cpp @@ -645,6 +645,19 @@ void RageSound::SetStopModeFromString( const RString &sStopMode ) class LunaRageSound: public Luna { public: + static int get_length(T* p, lua_State* L) + { + RageSoundReader* reader= p->GetSoundReader(); + if(reader == NULL) + { + lua_pushnumber(L, -1.0f); + } + else + { + lua_pushnumber(L, reader->GetLength() / 1000.0f); + } + return 1; + } static int pitch( T* p, lua_State *L ) { RageSoundParams params( p->GetParams() ); @@ -703,6 +716,7 @@ public: LunaRageSound() { + ADD_METHOD(get_length); ADD_METHOD( pitch ); ADD_METHOD( speed ); ADD_METHOD( volume ); diff --git a/src/RageUtil.cpp b/src/RageUtil.cpp index 9f5dbc57f1..6efc61883b 100644 --- a/src/RageUtil.cpp +++ b/src/RageUtil.cpp @@ -3,6 +3,7 @@ #include "RageMath.h" #include "RageLog.h" #include "RageFile.h" +#include "RageSoundReader_FileReader.h" #include "Foreach.h" #include "LocalizedString.h" #include "LuaBinding.h" @@ -2431,8 +2432,8 @@ int LuaFunc_commify(lua_State* L) } LUAFUNC_REGISTER_COMMON(commify); -void luafunc_approach_internal(lua_State* L, int valind, int goalind, int speedind); -void luafunc_approach_internal(lua_State* L, int valind, int goalind, int speedind, int process_index) +void luafunc_approach_internal(lua_State* L, int valind, int goalind, int speedind, const float mult); +void luafunc_approach_internal(lua_State* L, int valind, int goalind, int speedind, const float mult, int process_index) { #define TONUMBER_NICE(dest, num_name, index) \ if(!lua_isnumber(L, index)) \ @@ -2451,7 +2452,7 @@ void luafunc_approach_internal(lua_State* L, int valind, int goalind, int speedi { luaL_error(L, "approach: speed %d is negative.", process_index); } - fapproach(val, goal, speed); + fapproach(val, goal, speed*mult); lua_pushnumber(L, val); } @@ -2460,7 +2461,7 @@ int LuaFunc_approach(lua_State* L) { // Args: current, goal, speed // Returns: new_current - luafunc_approach_internal(L, 1, 2, 3, 1); + luafunc_approach_internal(L, 1, 2, 3, 1.0f, 1); return 1; } LUAFUNC_REGISTER_COMMON(approach); @@ -2468,16 +2469,24 @@ LUAFUNC_REGISTER_COMMON(approach); int LuaFunc_multiapproach(lua_State* L); int LuaFunc_multiapproach(lua_State* L) { - // Args: {currents}, {goals}, {speeds} + // Args: {currents}, {goals}, {speeds}, speed_multiplier + // speed_multiplier is optional, and is intended to be the delta time for + // the frame, so that this can be used every frame and have the current + // approach the goal at a framerate independent speed. // Returns: {currents} // Modifies the values in {currents} in place. - if(lua_gettop(L) != 3) + if(lua_gettop(L) < 3) { luaL_error(L, "multiapproach: A table of current values, a table of goal values, and a table of speeds must be passed."); } size_t currents_len= lua_objlen(L, 1); size_t goals_len= lua_objlen(L, 2); size_t speeds_len= lua_objlen(L, 3); + float mult= 1.0f; + if(lua_isnumber(L, 4)) + { + mult= lua_tonumber(L, 4); + } if(currents_len != goals_len || currents_len != speeds_len) { luaL_error(L, "multiapproach: There must be the same number of current values, goal values, and speeds."); @@ -2491,7 +2500,7 @@ int LuaFunc_multiapproach(lua_State* L) lua_rawgeti(L, 1, i); lua_rawgeti(L, 2, i); lua_rawgeti(L, 3, i); - luafunc_approach_internal(L, -3, -2, -1, i); + luafunc_approach_internal(L, -3, -2, -1, mult, i); lua_rawseti(L, 1, i); lua_pop(L, 3); } @@ -2500,6 +2509,23 @@ int LuaFunc_multiapproach(lua_State* L) } LUAFUNC_REGISTER_COMMON(multiapproach); +int LuaFunc_get_music_file_length(lua_State* L); +int LuaFunc_get_music_file_length(lua_State* L) +{ + // Args: file_path + // Returns: The length of the music in seconds. + RString path= SArg(1); + RString error; + RageSoundReader* sample= RageSoundReader_FileReader::OpenFile(path, error); + if(sample == NULL) + { + luaL_error(L, "The music file '%s' does not exist.", path.c_str()); + } + lua_pushnumber(L, sample->GetLength() / 1000.0f); + return 1; +} +LUAFUNC_REGISTER_COMMON(get_music_file_length); + /* * Copyright (c) 2001-2005 Chris Danford, Glenn Maynard * All rights reserved.