Skip to content

Commit

Permalink
Allow inserting a track into the middle of the playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Apr 24, 2017
1 parent 7ea83d4 commit 6542ec7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/scripting/lua_audio.cpp
Expand Up @@ -107,6 +107,11 @@ static int intf_music_play(lua_State* L) {
}

static int intf_music_add(lua_State* L) {
int i = -1;
if(lua_isinteger(L, 1)) {
i = lua_tointeger(L, 1);
lua_remove(L, 1);
}
config cfg = config_of
("name", luaL_checkstring(L, 1))
("append", true);
Expand All @@ -132,7 +137,7 @@ static int intf_music_add(lua_State* L) {
return luaL_argerror(L, i, "unrecognized argument");
}
}
sound::play_music_config(cfg);
sound::play_music_config(cfg, i);
return 0;
}

Expand Down
11 changes: 9 additions & 2 deletions src/sound.cpp
Expand Up @@ -577,7 +577,7 @@ void play_music_repeatedly(const std::string &id)
}
}

void play_music_config(const config &music_node)
void play_music_config(const config &music_node, int i)
{
music_track track( music_node );

Expand Down Expand Up @@ -609,7 +609,14 @@ void play_music_config(const config &music_node)
}

if(itor == current_track_list.end()) {
current_track_list.push_back(track);
if(i < 0 || static_cast<size_t>(i) >= current_track_list.size()) {
current_track_list.push_back(track);
} else {
current_track_list.insert(current_track_list.begin() + 1, track);
if(current_track_index >= static_cast<size_t>(i)) {
current_track_index++;
}
}
} else {
ERR_AUDIO << "tried to add duplicate track '" << track.file_path() << "'" << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sound.hpp
Expand Up @@ -41,7 +41,7 @@ void stop_UI_sound();
void stop_bell();

// Read config entry, alter track list accordingly.
void play_music_config(const config &music_node);
void play_music_config(const config &music_node, int i = -1);
// Act on any track list changes from above.
void commit_music_changes();

Expand Down

0 comments on commit 6542ec7

Please sign in to comment.