diff --git a/main.go b/main.go index 5c60a7c..3ececa2 100644 --- a/main.go +++ b/main.go @@ -47,7 +47,7 @@ func xPrintIdle() (idle uint64) { } func speakToday() { - cmdSetVolume := exec.Command("amixer", "-D", "pulse", "set", "Master", fmt.Sprintf("%d%%", 50+50/(int64(MaxRunTime.Seconds()/3)/ntick+1))) + cmdSetVolume := exec.Command("amixer", "-D", "pulse", "set", "Master", fmt.Sprintf("%d%%", 50+(ntick/int64(MaxRunTime.Seconds()/3))*50)) if err := cmdSetVolume.Run(); err != nil { log.Println(err) } @@ -101,7 +101,7 @@ func speakWeather() { log.Println(err) } - cmdSetVolume := exec.Command("amixer", "-D", "pulse", "set", "Master", fmt.Sprintf("%d%%", 50+50/(int64(MaxRunTime.Seconds()/3)/ntick+1))) + cmdSetVolume := exec.Command("amixer", "-D", "pulse", "set", "Master", fmt.Sprintf("%d%%", 50+(ntick/int64(MaxRunTime.Seconds()/3))*50)) if err := cmdSetVolume.Run(); err != nil { log.Println(err) } @@ -121,11 +121,6 @@ func speakWeather() { log.Println(err) } - cmd3 := exec.Command("/home/nemunaire/scripts/wakeup/ratp-traffic.sh", "rers", "B") - if err := cmd3.Run(); err != nil { - log.Println(err) - } - if cmdAmbiant.Process != nil { (*cmdAmbiant.Process).Kill() } @@ -137,13 +132,11 @@ func speakWeather() { } } -func loadFile(filepath string) (name string, s beep.StreamSeekCloser, format beep.Format, err error) { +func loadFile(path string) (s beep.StreamSeekCloser, format beep.Format, err error) { for _, decoder := range []func(io.ReadCloser) (beep.StreamSeekCloser, beep.Format, error){flac.Decode, mp3.Decode, wav.Decode} { var fd *os.File - name = path.Base(filepath) - - fd, err = os.Open(filepath) + fd, err = os.Open(path) if err != nil { return } @@ -166,7 +159,6 @@ func loadFile(filepath string) (name string, s beep.StreamSeekCloser, format bee func main() { var weatherTime = flag.Duration("weather", -1, "Speak weather?") var noshuffle = flag.Bool("noshuffle", false, "Don't shuffle music order") - var ignoreidle = flag.Bool("ignoreidle", false, "Don't stop the reveil on idle detection change") var sr = flag.Int("samplerate", 44100, "Samplerate for unifying output stream") var claironTime = flag.Duration("clairon", -1, "Time before running the wake up clairon song") flag.DurationVar(&MaxRunTime, "maxruntime", MaxRunTime, "Maximum duration before auto exit") @@ -177,27 +169,21 @@ func main() { return } - seed := time.Now().Unix() % 172800 * 64 - - log.Println("Starting reveil with seed:", seed) - - rand.Seed(seed) + rand.Seed(time.Now().UnixNano()) sampleRate := beep.SampleRate(*sr) - paths := []string{} playlist := []beep.Streamer{} formats := []beep.Format{} // Load playlist log.Println("Loading playlist...") for _, arg := range flag.Args() { - p, s, f, err := loadFile(arg) + s, f, err := loadFile(arg) if err != nil { log.Printf("Unable to load %s: %s", arg, err) continue } - paths = append(paths, p) playlist = append(playlist, s) formats = append(formats, f) } @@ -206,7 +192,6 @@ func main() { log.Println("Shuffling playlist...") // Shuffle the playlist rand.Shuffle(len(playlist), func(i, j int) { - paths[i], paths[j] = paths[j], paths[i] playlist[i], playlist[j] = playlist[j], playlist[i] formats[i], formats[j] = formats[j], formats[i] }) @@ -218,15 +203,14 @@ func main() { dontUpdateVolume := false hasClaironed := claironTime == nil || *claironTime == -1 hasSpokeWeather := weatherTime == nil || *weatherTime == -1 - reverseOrder := time.Now().Unix()%86400%2 == 0 - playedItem := -1 // Create infinite stream + playedItem := -1 stream := beep.Iterate(func() beep.Streamer { if !hasClaironed && time.Since(launched) >= *claironTime { log.Println("clairon time!") - *claironTime += *claironTime / 2 - _, sample, format, err := loadFile("/home/nemunaire/www/audio/miracle-morning/clairon-reveil.mp3") + hasClaironed = true + sample, format, err := loadFile("/home/nemunaire/www/audio/miracle-morning/clairon-reveil.mp3") if err == nil { volume.Volume = 1 dontUpdateVolume = true @@ -235,8 +219,6 @@ func main() { } else { return sample } - } else { - log.Println("Error loading clairon:", err) } } @@ -248,17 +230,9 @@ func main() { dontUpdateVolume = false volume.Volume = -2 - math.Log(5/float64(ntick))/3 - - if reverseOrder { - playedItem -= 1 - } else { - playedItem += 1 - } - + playedItem += 1 if playedItem >= len(playlist) { playedItem = 0 - } else if playedItem < 0 { - playedItem = len(playlist) - 1 } if i, ok := playlist[playedItem].(beep.StreamSeekCloser); ok { @@ -304,12 +278,8 @@ loop: volume.Volume = -2 - math.Log(5/float64(ntick))/3 } - if ignoreidle == nil || !*ignoreidle { - if idle < 60000 { - idle = xPrintIdle() - } else if xPrintIdle() < idle { - break loop - } + if xPrintIdle() < idle { + break loop } case <-interrupt: break loop