forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[code/core] Some Music additions...

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
Durante



Joined: 02 Oct 2005
Posts: 65
Location: Austria

PostPosted: Mon Oct 31, 2005 1:46 am    Post subject: [code/core] Some Music additions... Reply with quote

I just made some trivial additions to the Music object, here's the code in a zip (sound.h, sound.c, luasound.c):
http://peter.metaclassofnil.com/stuff/psp/soundupdate.zip

These are non-breaking changes (well, compared to some of my recent graphics stuff, everything is...) so they should be easy to add to the svn version. Note that only the bpm stuff is tested as of now, but I'll get to the other functions soon and I don't believe that there's an easy way to mess up such simple stuff ;).

For completeness, here are the added parts. I even documented them o_O
sound.h:
Code:
/**
 * Sets the music's beats per minute.
 *
 * @pre (arg > 33 && arg < 240)
 * @param arg is the number of bpm
 * @return the old bpm
 */
extern unsigned setMusicBPM(unsigned arg);
/**
 * Gets the music's current beats per minute.
 *
 * @return the bpm
 */
extern unsigned getMusicBPM();
/**
 * Gets the music's initial beats per minute.
 *
 * @return the initial bpm of the current music file
 */
extern unsigned getMusicInitBPM();

/**
 * Sets the music's current position. All playing samples are cut off.
 *
 * @pre (arg < getMusicMaxPosition())
 * @param arg is the position you want to set
 * @return the old position
 */
extern unsigned setMusicPosition(unsigned arg);
/**
 * Gets the music's current pattern position.
 *
 * @return the position
 */
extern unsigned getMusicPosition();
/**
 * Gets the music's last pattern position.
 *
 * @return the last position of the current music file
 */
extern unsigned getMusicMaxPosition();

/**
 * Sets the music's positionto the current postion + 1.
 */
extern void nextMusicPosition();
/**
 * Sets the music's positionto the current postion - 1.
 */
extern void prevMusicPosition();

sound.c:
Code:
unsigned setMusicBPM(unsigned arg) {
   unsigned ret = musichandle->bpm;
   arg = (arg<33) ? 33 : arg;
   arg = (arg>240) ? 240 : arg;
   musichandle->bpm = arg;
   return ret;
}
unsigned getMusicBPM() {
   return musichandle->bpm;
}
unsigned getMusicInitBPM() {
   return musichandle->inittempo;
}

unsigned setMusicPosition(unsigned arg) {
   unsigned ret = musichandle->sngpos;
   arg = (arg>=musichandle->numpos) ? musichandle->numpos-1 : arg;
   Player_SetPosition(arg);
   return ret;
}
unsigned getMusicPosition() {
   return musichandle->sngpos;
}
unsigned getMusicMaxPosition() {
   return musichandle->numpos-1;
}

void nextMusicPosition() {
   Player_NextPosition();
}
void prevMusicPosition() {
   Player_PrevPosition();
}

luasound.c:
Code:
static int Music_bpm(lua_State *L)
{
   int argc = lua_gettop(L);
   if(argc != 1 && argc != 0) return luaL_error(L, "wrong number of arguments");
   if(argc)
      lua_pushnumber(L, setMusicBPM(luaL_checknumber(L, 1)));
   else
      lua_pushnumber(L, getMusicBPM());

   return 1;
}
static int Music_initialBpm(lua_State *L)
{
   int argc = lua_gettop(L);
   if(argc != 0) return luaL_error(L, "wrong number of arguments");
   lua_pushnumber(L, getMusicInitBPM());

   return 1;
}

static int Music_position(lua_State *L)
{
   int argc = lua_gettop(L);
   if(argc != 1 && argc != 0) return luaL_error(L, "wrong number of arguments");
   if(argc)
      lua_pushnumber(L, setMusicPosition(luaL_checknumber(L, 1)));
   else
      lua_pushnumber(L, getMusicPosition());

   return 1;
}
static int Music_maxPosition(lua_State *L)
{
   int argc = lua_gettop(L);
   if(argc != 0) return luaL_error(L, "wrong number of arguments");
   lua_pushnumber(L, getMusicMaxPosition());

   return 1;
}

static int Music_nextPosition(lua_State *L)
{
   int argc = lua_gettop(L);
   if(argc != 0) return luaL_error(L, "wrong number of arguments");
   nextMusicPosition();

   return 0;
}
static int Music_prevPosition(lua_State *L)
{
   int argc = lua_gettop(L);
   if(argc != 0) return luaL_error(L, "wrong number of arguments");
   prevMusicPosition();

   return 0;
}



static const luaL_reg Music_functions[] = {
  {"playFile",          Music_loadAndPlay},
  {"stop",              Music_StopAndUnload},
  {"pause",             Music_pause},
  {"resume",          Music_resume},
  {"playing",          Music_playing},
  {"volume",          Music_volume},
  {"bpm",         Music_bpm},
  {"initialBpm",      Music_initialBpm},
  {"position",         Music_position},
  {"maxPosition",      Music_maxPosition},
  {"nextPosition",      Music_nextPosition},
  {"prevPosition",      Music_prevPosition},
  {0, 0}
};
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group