// grab a list of musics to play. Can be local list of musics if no argument is provided.
grab a list of musics to play. Can be local list of musics if no argument is provided.
// grab a list of musics to play . Can be local list of musics if no argument is provided .
func musicToPlay() ([]string, error) {
	s := rand.NewSource(time.Now().UnixNano())
	r := rand.New(s)
	musics := flag.Args()
	if len(musics) == 0 {
		musicdir := path.Join(rootdir, "musics")
		files, _ := ioutil.ReadDir(musicdir)
		for _, f := range files {
			musics = append(musics, path.Join(musicdir, f.Name()))
		}
		for i := range musics {
			j := r.Intn(i + 1)
			musics[i], musics[j] = musics[j], musics[i]
		}
		biasm := []string{"12_Days_Of_Christmas.mid", "Carol_Of_The_Bells.mid", "Jingle_Bells.mid", "Let_It_Snow.mid",
			"O_Come_All_Ye_Faithful.mid", "Rudolph_The_Red_Nosed_Reindeer.mid", "Rockin_Around_The_Christmas_Tree.mid",
			"Santa_Claus_Is_Coming_To_Town.mid", "Sleigh_Ride.mid", "What_Child_Is_This.mid"}
	bias:
		for i, title := range musics {
			for _, tchosen := range biasm {
				if strings.HasSuffix(title, tchosen) {
					musics[0], musics[i] = musics[i], musics[0]
					break bias
				}
			}
		}
	}
	Debug.Printf("List of musics to play: %v", musics)
	return musics, nil
}
func musicToPlay ( ) ( [ ] string , error ) { s := rand . NewSource ( time . Now ( ) . UnixNano ( ) ) r := rand . New ( s ) musics := flag . Args ( ) if len ( musics ) == 0 { musicdir := path . Join ( rootdir , " " ) files , _ := ioutil . ReadDir ( musicdir ) for _ , f := range files { musics = append ( musics , path . Join ( musicdir , f . Name ( ) ) ) } for i := range musics { j := r . Intn ( i + 1 ) musics [ i ] , musics [ j ] = musics [ j ] , musics [ i ] } biasm := [ ] string { " " , " " , " " , " " , " " , " " , " " , " " , " " , " " } bias : for i , title := range musics { for _ , tchosen := range biasm { if strings . HasSuffix ( title , tchosen ) { musics [ 0 ] , musics [ i ] = musics [ i ] , musics [ 0 ] break bias } } } } Debug . Printf ( " " , musics ) return musics , nil }
grab a list of musics to play.
grab a list of musics to play .
// load musics from args // load from directory then // shuffling // add a little bit of bias by swapping in a chosen list the first music to play