Ticket #3025: mythmusic_resume_r12685.patch

File mythmusic_resume_r12685.patch, 13.2 KB (added by mythtv@…, 13 years ago)
  • mythmusic/mythmusic/playbackbox.cpp

     
    116116    else
    117117        setShuffleMode(SHUFFLE_OFF);
    118118
     119    QString resumestring = gContext->GetSetting("ResumeMode", "playlist");
     120    if (resumestring.lower() == "playlist")
     121        resumemode = RESUME_OFF;
     122    else if (resumestring.lower() == "track")
     123        resumemode = RESUME_TRACK;
     124    else
     125        resumemode = RESUME_EXACT;
     126
    119127    QString repeatmode = gContext->GetSetting("RepeatMode", "all");
    120128    if (repeatmode.lower() == "track")
    121129        setRepeatMode(REPEAT_TRACK);
     
    232240        delete cd_reader_thread;
    233241    }
    234242
     243    all_playlists->getActive()->setBookmark(all_playlists->getActive()->getBookmarkSong(), 1000*currentTime);
     244
    235245    if (playlist_tree)
    236246        delete playlist_tree;
    237247
     
    311321        else if (action == "STOP")
    312322        {
    313323            stop();
     324            currentTime = 0;
    314325        }
    315326        else if (action == "THMBUP")
    316327            increaseRating();
     
    923934                branches_to_current_node.append(0); //  Root node
    924935                branches_to_current_node.append(1); //  We're on a playlist (not "My Music")
    925936                branches_to_current_node.append(0); //  Active play Queue
    926                 music_tree_list->moveToNodesFirstChild(branches_to_current_node);
     937                if (resumemode > RESUME_OFF)
     938                {
     939                    if (all_playlists->getActive()->checkTrack(all_playlists->getActive()->getBookmarkSong(), false))
     940                    {
     941                        branches_to_current_node.append(all_playlists->getActive()->getBookmarkSong());
     942                        music_tree_list->moveToNode(branches_to_current_node);
     943                    }
     944                    else
     945                    {
     946                        music_tree_list->moveToNodesFirstChild(branches_to_current_node);
     947                    }
     948                }
     949                else
     950                {
     951                    if (all_playlists->getActive()->checkTrack(all_playlists->getActive()->getFirstTrackID(), false))
     952                    {
     953                        branches_to_current_node.append(all_playlists->getActive()->getFirstTrackID());
     954                        music_tree_list->moveToNode(branches_to_current_node);
     955                    }
     956                    else
     957                    {
     958                        music_tree_list->moveToNodesFirstChild(branches_to_current_node);
     959                    }
     960                }
    927961                music_tree_list->refresh();
    928962                if (show_whole_tree)
    929963                    setContext(1);
     
    937971
    938972                play();
    939973
     974                if (resumemode == RESUME_EXACT)
     975                    seek(all_playlists->getActive()->getBookmarkSongOffset()/1000);
     976
    940977                return;     // Do not restart Timer
    941978            }
    942979            else
     
    12461283                       mdata->Title());
    12471284}
    12481285
    1249 void PlaybackBoxMusic::pause(bool state)
     1286void PlaybackBoxMusic::pause(bool)
    12501287{
    12511288    if (output)
    12521289    {
     
    13241361    if (info_text)
    13251362        info_text->SetText("");
    13261363
     1364    all_playlists->getActive()->setBookmark(all_playlists->getActive()->getBookmarkSong(), 0);
     1365
    13271366    isplaying = false;
    13281367    if (play_button)
    13291368        play_button->setState(false);
     
    19271966        if (output)
    19281967        {
    19291968            stop();
     1969            all_playlists->getActive()->setBookmark(node_int, 0);
    19301970            play();
    1931        }
     1971        }
     1972        else
     1973        {
     1974            uint offset;
     1975            if (node_int == all_playlists->getActive()->getBookmarkSong())
     1976                offset = all_playlists->getActive()->getBookmarkSongOffset();
     1977            else
     1978                offset = 0;
     1979
     1980            all_playlists->getActive()->setBookmark(node_int, offset);
     1981        }
    19321982    }
    19331983    else
    19341984    {
  • mythmusic/mythmusic/playlist.h

     
    105105                                       int currentTrackID = 0);
    106106    QString  getSonglist(void) { return raw_songlist; }
    107107
     108    void setBookmark(uint song, uint offset);
     109    uint getBookmarkSong(void) { return resume_song; }
     110    uint getBookmarkSongOffset(void) { return resume_offset; }
     111
    108112    void moveTrackUpDown(bool flag, Track *the_track);
    109113
    110114    bool checkTrack(int a_track_id, bool cd_flag);
     
    140144    QString             name;
    141145    QString             raw_songlist;
    142146    QPtrList<Track>     songs;
     147    uint                resume_song;
     148    uint                resume_offset;
    143149    AllMusic            *all_available_music;
    144150    PlaylistsContainer  *parent;
    145151    bool                changed;
  • mythmusic/mythmusic/globalsettings.cpp

     
    312312    gc->addSelection(QObject::tr("Random"), "Random");
    313313    gc->addSelection(QObject::tr("Intelligent"), "Intelligent");
    314314    gc->setHelpText(QObject::tr("Starting shuffle mode for the player.  Can be "
    315                     "either normal, random, or intelligent (random)."));
     315                    "either normal, random, intelligent (random), or Album."));
     316    return gc;
     317};
     318
     319static HostComboBox *ResumeMode()
     320{
     321    HostComboBox *gc = new HostComboBox("ResumeMode");
     322    gc->setLabel(QObject::tr("Resume mode"));
     323    gc->addSelection(QObject::tr("Playlist"), "playlist");
     324    gc->addSelection(QObject::tr("Track"), "track");
     325    gc->addSelection(QObject::tr("Exact"), "exact");
     326    gc->setCurrent(0);
     327    gc->setHelpText(QObject::tr("Resume playback at either the beginning of the "
     328                    "playlist, the beginning of the last track, an exact point within "
     329                    "the last track."));
    316330    return gc;
    317331};
    318332
     
    533547    VerticalConfigurationGroup* playersettings = new VerticalConfigurationGroup(false);
    534548    playersettings->setLabel(QObject::tr("Playback Settings"));
    535549    playersettings->addChild(PlayMode());
     550    playersettings->addChild(ResumeMode());
    536551    playersettings->addChild(SetRatingWeight());
    537552    playersettings->addChild(SetPlayCountWeight());
    538553    playersettings->addChild(SetLastPlayWeight());
  • mythmusic/mythmusic/dbcheck.cpp

     
    99#include "mythtv/mythcontext.h"
    1010#include "mythtv/mythdbcon.h"
    1111
    12 const QString currentDatabaseVersion = "1007";
     12const QString currentDatabaseVersion = "1008";
    1313
    1414static bool UpdateDBVersionNumber(const QString &newnumber)
    1515{   
     
    477477            return false;
    478478    }
    479479
     480    if (dbver == "1007")
     481    {
     482        const QString updates[] = {
     483"ALTER TABLE music_playlists ADD COLUMN resume_song INTEGER UNSIGNED NOT NULL DEFAULT 0 AFTER playlist_songs;",
     484"ALTER TABLE music_playlists ADD COLUMN resume_offset INTEGER UNSIGNED NOT NULL DEFAULT 0 AFTER resume_song;",
     485""
     486};
     487        if (!performActualUpdate(updates, "1008", dbver))
     488            return false;
     489    }
     490
    480491/* in 0.21 */
    481492//"DROP TABLE musicmetadata;",
    482493//"DROP TABLE musicplaylist;",
  • mythmusic/mythmusic/playlist.cpp

     
    6363        }
    6464        else
    6565            it = songs.next();
    66     } 
     66    }
     67
     68    if (resume_song == 0)
     69        resume_song = getFirstTrackID();
    6770}
    6871
    6972bool Playlist::checkTrack(int a_track_id, bool cd_flag)
     
    183186        }
    184187        else
    185188            it = songs.next();
    186     } 
     189    }
     190
     191    if (static_cast<int>(resume_song) == the_track)
     192        resume_song = getFirstTrackID();
     193
    187194    changed = true;
    188195}
    189196
     
    375382    playlistid = 0;
    376383    name = QObject::tr("oops");
    377384    raw_songlist = "";
     385    resume_song = 0;
     386    resume_offset = 0;
    378387    songs.setAutoDelete(true);  //  mine!
    379388    all_available_music = all_music_ptr;
    380389    changed = false;
     
    436445    name = rhs.name;
    437446    raw_songlist = rhs.raw_songlist;
    438447    songs = rhs.songs;
     448    resume_song = rhs.resume_song;
     449    resume_offset = rhs.resume_offset;
    439450    return *this;
    440451}
    441452
     
    473484
    474485    if (name == "default_playlist_storage" || name == "backup_playlist_storage")
    475486    {
    476         query.prepare("SELECT playlist_id, playlist_name, playlist_songs "
     487        query.prepare("SELECT playlist_id, playlist_name, playlist_songs, resume_song, resume_offset "
    477488                      "FROM  music_playlists "
    478489                      "WHERE playlist_name = :NAME"
    479490                      " AND hostname = :HOST;");
     
    482493    {
    483494        // Technically this is never called as this function is only used to load
    484495        // the default/backup playlists.
    485         query.prepare("SELECT playlist_id, playlist_name, playlist_songs "
     496        query.prepare("SELECT playlist_id, playlist_name, playlist_songs, resume_song, resume_offset "
    486497                      "FROM music_playlists "
    487498                      "WHERE playlist_name = :NAME"
    488499                      " AND (hostname = '' OR hostname = :HOST);");
     
    497508            playlistid = query.value(0).toInt();
    498509            name = QString::fromUtf8(query.value(1).toString());
    499510            raw_songlist = query.value(2).toString();
     511            resume_song = query.value(3).toInt();
     512            resume_offset = query.value(4).toInt();
    500513        }
    501514        if (name == "default_playlist_storage")
    502515            name = "the user should never see this";
     
    517530void Playlist::loadPlaylistByID(int id, QString a_host)
    518531{
    519532    MSqlQuery query(MSqlQuery::InitCon());
    520     query.prepare("SELECT playlist_id, playlist_name, playlist_songs "
     533    query.prepare("SELECT playlist_id, playlist_name, playlist_songs, resume_song, resume_offset "
    521534                  "FROM music_playlists "
    522535                  "WHERE playlist_id = :ID"
    523536                  " AND (hostname = '' OR hostname = :HOST);");
     
    531544        playlistid = query.value(0).toInt();
    532545        name = QString::fromUtf8(query.value(1).toString());
    533546        raw_songlist = query.value(2).toString();
     547        resume_song = query.value(3).toInt();
     548        resume_offset = query.value(4).toInt();
    534549    }
    535550
    536551    if (name == "default_playlist_storage")
     
    799814    fillSonglistFromQuery(whereClause, removeDuplicates, insertOption, currentTrackID);
    800815}
    801816
     817void Playlist::setBookmark(uint song, uint offset)
     818{
     819    for (uint track = 0; track < songs.count(); track++)
     820        if (songs.at(track) && songs.at(track)->getValue() == static_cast<int>(song))
     821        {
     822            resume_song = song;
     823            resume_offset = offset;
     824            changed = true;
     825        }
     826}
     827
    802828void Playlist::savePlaylist(QString a_name, QString a_host)
    803829{
    804830    name = a_name.simplifyWhiteSpace();
     
    851877    if (playlistid > 0)
    852878    {
    853879        QString str_query = "UPDATE music_playlists SET playlist_songs = :LIST,"
    854                             " playlist_name = :NAME, songcount = :SONGCOUNT, length = :PLAYTIME";
     880                            " playlist_name = :NAME, songcount = :SONGCOUNT, length = :PLAYTIME,"
     881                            " resume_song = :BOOKMARKSONG, resume_offset = :BOOKMARKSONGOFFSET";
    855882        if (save_host)
    856883            str_query += ", hostname = :HOSTNAME";
    857884        str_query += " WHERE playlist_id = :ID ;";
     
    862889    else
    863890    {
    864891        QString str_query = "INSERT INTO music_playlists"
    865                             " (playlist_name, playlist_songs, songcount, length";
     892                            " (playlist_name, playlist_songs, songcount, length, resume_song, resume_offset";
    866893        if (save_host)
    867894            str_query += ", hostname";
    868895        str_query += ") VALUES(:NAME, :LIST, :SONGCOUNT, :PLAYTIME";
    869896        if (save_host)
    870897            str_query += ", :HOSTNAME";
    871         str_query += ");";
     898        str_query += ", :BOOKMARKSONG, :BOOKMARKSONGOFFSET);";
    872899
    873900        query.prepare(str_query);
    874901    }
     
    878905    query.bindValue(":PLAYTIME", playtime);
    879906    if (save_host)
    880907        query.bindValue(":HOSTNAME", a_host);
     908    query.bindValue(":BOOKMARKSONG", resume_song);
     909    query.bindValue(":BOOKMARKSONGOFFSET", resume_offset);
    881910
    882911    if (!query.exec() || (playlistid < 1 && query.numRowsAffected() < 1))
    883912    {
  • mythmusic/mythmusic/playbackbox.h

     
    135135      SHUFFLE_ALBUM,
    136136      MAX_SHUFFLE_MODES
    137137    };
     138    enum ResumeMode
     139    { RESUME_OFF,
     140      RESUME_TRACK,
     141      RESUME_EXACT,
     142      MAX_RESUME_MODES
     143    };
    138144
    139145    bool listAsShuffled;
    140146    int outputBufferSize;
     
    145151
    146152    unsigned int shufflemode;
    147153    unsigned int repeatmode;
     154    unsigned int resumemode;
    148155
    149156    bool isplaying;
    150157    bool lcd_volume_visible;