|
|
@ -26,6 +26,7 @@ module sound.music;
|
|
|
|
import sound.audio;
|
|
|
|
import sound.audio;
|
|
|
|
import sound.al;
|
|
|
|
import sound.al;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import std.stdio;
|
|
|
|
import std.string;
|
|
|
|
import std.string;
|
|
|
|
|
|
|
|
|
|
|
|
import core.config;
|
|
|
|
import core.config;
|
|
|
@ -54,6 +55,7 @@ struct MusicManager
|
|
|
|
throw new SoundException(name ~ " Jukebox", msg);
|
|
|
|
throw new SoundException(name ~ " Jukebox", msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* KILLME
|
|
|
|
// Used when randomizing playlist
|
|
|
|
// Used when randomizing playlist
|
|
|
|
struct rndListStruct
|
|
|
|
struct rndListStruct
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -61,6 +63,7 @@ struct MusicManager
|
|
|
|
bool used;
|
|
|
|
bool used;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rndListStruct[] rndList;
|
|
|
|
rndListStruct[] rndList;
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: How do we handle the play list? Randomize should be an
|
|
|
|
// TODO: How do we handle the play list? Randomize should be an
|
|
|
|
// option. We could also support things like M3U files, etc.
|
|
|
|
// option. We could also support things like M3U files, etc.
|
|
|
@ -112,17 +115,33 @@ struct MusicManager
|
|
|
|
randomize();
|
|
|
|
randomize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Randomize playlist. An N^2 algorithm, but our current playlists
|
|
|
|
// Randomize playlist. If the argument is true, then we don't want
|
|
|
|
// are small. Improve it later if you really have to. If the
|
|
|
|
// the old last to be the new first.
|
|
|
|
// argument is true, then we don't want the old last to be the new
|
|
|
|
|
|
|
|
// first.
|
|
|
|
|
|
|
|
private void randomize(bool checklast = false)
|
|
|
|
private void randomize(bool checklast = false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(playlist.length < 2) return;
|
|
|
|
if(playlist.length < 2) return;
|
|
|
|
|
|
|
|
|
|
|
|
// Get the name of the last song played
|
|
|
|
// Get the index of the last song played
|
|
|
|
char[] last = playlist[(index==0) ? ($-1) : (index-1)];
|
|
|
|
int lastidx = ((index==0) ? (playlist.length-1) : (index-1));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach(int i, char[] s; playlist)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int idx = rnd.randInt(i,playlist.length-1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Don't put the last idx as the first entry
|
|
|
|
|
|
|
|
if(i == 0 && checklast && lastidx == idx)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
|
|
|
|
if(idx == playlist.length)
|
|
|
|
|
|
|
|
idx = i;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(idx == i) /* skip if swapping with self */
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
playlist[i] = playlist[idx];
|
|
|
|
|
|
|
|
playlist[idx] = s;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* KILLME
|
|
|
|
int left = playlist.length;
|
|
|
|
int left = playlist.length;
|
|
|
|
rndList.length = left;
|
|
|
|
rndList.length = left;
|
|
|
|
|
|
|
|
|
|
|
@ -159,7 +178,7 @@ struct MusicManager
|
|
|
|
playlist[0] = playlist[$-1];
|
|
|
|
playlist[0] = playlist[$-1];
|
|
|
|
playlist[$-1] = last;
|
|
|
|
playlist[$-1] = last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// Skip to the next track
|
|
|
|
// Skip to the next track
|
|
|
|
void playNext()
|
|
|
|
void playNext()
|
|
|
|