Example #1
0
void immediateAutoplayStart() {
    Playlist *p = Playlists::currentPlaylist();
    AutoplayStructure settings;
    p->getAutoplaySettings(&settings);

    immediateAutoplayCount = min(settings.maxChirps, p->nChirps); // items to play
    immediateAutoplayTimeSeconds = 0; // will play immediately
}
Example #2
0
void autoplayLoop() {
    static int32_t then; // now field from last time in loop

    int32_t now = timeNowSecondsSinceMidnight();
    int16_t nowMinute = now / 60;

    // start any new autoplays
    if(nowMinute > then / 60 || autoplayNow) {
        // its a new minute; check the playlists to see if any due to start autoplaying this minute
        autoplayNow = false;

        for(int ix = 0; ix < N_PLAYLISTS; ix++) {
            Playlist *p = Playlists::playlist(ix);

            if(p->nChirps > 0 && p->autoplayCount == 0) { // only check if playlist has chirps and isn't already playing
                AutoplayStructure settings;
                p->getAutoplaySettings(&settings);

                int16_t startMinute = settings.startMinute;

                // run through all start times for playlist
                // doesn't play before initial start time and doesn't continue repeating past midnight
                for(uint8_t n = 0; n < settings.count && nowMinute >= startMinute && startMinute < minutesInOneDay; n++) {
                    if(startMinute == nowMinute) {
                        if(p->getUpdateFlags() & UPDATE_WHEN_AUTOPLAY) {
                            p->requestUpdate();
                        }

                        // setting non-zero count makes autoplay active
                        p->autoplayCount = min(settings.maxChirps, p->nChirps); 
                        p->autoplayTimeSeconds = 0; // play as soon as possible
                        break;
                    }
                    startMinute += settings.repeatMinutes;
                }
            }
        }
    }

    // autoplay up to one chirp per new second

    if(now > then) {
        // it's a new second

        // first check to see if current playlist is being autoplayed from the command line
        if(immediateAutoplayCount > 0 && now >= immediateAutoplayTimeSeconds) {
            Playlist *p = Playlists::currentPlaylist();

            if(p->playSequenced()) {
                immediateAutoplayCount--;
                immediateAutoplayTimeSeconds = now + p->getInterval();
            }
            else {
                // empty playlist: turn off
                immediateAutoplayCount = 0;
            }
            if(immediateAutoplayCount == 0) {
                showPrompt();
            }
        }
        else {
            // check any timed autoplaying playlists for any due to play now
            for(int ix = 0; ix < N_PLAYLISTS; ix++) {
                Playlist *p = Playlists::playlist(ix);

                if(p->autoplayCount > 0 && now >= p->autoplayTimeSeconds && p->awaitingUpdate == NOT_AWAITING_UPDATE) {
                    if(p->playSequenced()) {
                        p->autoplayCount--;
                        p->autoplayTimeSeconds = now + p->getInterval();
                        break; // only one play per vsit to this function
                    }
                    else {
                        p->autoplayCount = 0; // empty playlist (shouldn't happen here)
                    }
                }
            }
        }
    }

    then = now;
}