Ticket #3025: mythmusic_resume_r12872.patch

File mythmusic_resume_r12872.patch, 12.8 KB (added by mythtv@…, 13 years ago)

Patch refresh against head revision 12872

  • mythmusic/mythmusic/playbackbox.cpp

     
    115115    else
    116116        setShuffleMode(SHUFFLE_OFF);
    117117
     118    QString resumestring = gContext->GetSetting("ResumeMode", "playlist");
     119    if (resumestring.lower() == "playlist")
     120        resumemode = RESUME_OFF;
     121    else if (resumestring.lower() == "track")
     122        resumemode = RESUME_TRACK;
     123    else
     124        resumemode = RESUME_EXACT;
     125
    118126    QString repeatmode = gContext->GetSetting("RepeatMode", "all");
    119127    if (repeatmode.lower() == "track")
    120128        setRepeatMode(REPEAT_TRACK);
     
    237245        delete cd_reader_thread;
    238246    }
    239247
     248    all_playlists->getActive()->setBookmark(all_playlists->getActive()->getBookmarkSong(), 1000*currentTime);
     249
    240250    if (playlist_tree)
    241251        delete playlist_tree;
    242252
     
    316326        else if (action == "STOP")
    317327        {
    318328            stop();
     329            currentTime = 0;
    319330        }
    320331        else if (action == "THMBUP")
    321332            increaseRating();
     
    928939                branches_to_current_node.append(0); //  Root node
    929940                branches_to_current_node.append(1); //  We're on a playlist (not "My Music")
    930941                branches_to_current_node.append(0); //  Active play Queue
    931                 music_tree_list->moveToNodesFirstChild(branches_to_current_node);
     942                if (resumemode > RESUME_OFF)
     943                {
     944                    if (all_playlists->getActive()->checkTrack(all_playlists->getActive()->getBookmarkSong(), false))
     945                    {
     946                        branches_to_current_node.append(all_playlists->getActive()->getBookmarkSong());
     947                        music_tree_list->moveToNode(branches_to_current_node);
     948                    }
     949                    else
     950                    {
     951                        music_tree_list->moveToNodesFirstChild(branches_to_current_node);
     952                    }
     953                }
     954                else
     955                {
     956                    if (all_playlists->getActive()->checkTrack(all_playlists->getActive()->getFirstTrackID(), false))
     957                    {
     958                        branches_to_current_node.append(all_playlists->getActive()->getFirstTrackID());
     959                        music_tree_list->moveToNode(branches_to_current_node);
     960                    }
     961                    else
     962                    {
     963                        music_tree_list->moveToNodesFirstChild(branches_to_current_node);
     964                    }
     965                }
    932966                music_tree_list->refresh();
    933967                if (show_whole_tree)
    934968                    setContext(1);
     
    942976
    943977                play();
    944978
     979                if (resumemode == RESUME_EXACT)
     980                    seek(all_playlists->getActive()->getBookmarkSongOffset()/1000);
     981
    945982                return;     // Do not restart Timer
    946983            }
    947984            else
     
    13371374    if (info_text)
    13381375        info_text->SetText("");
    13391376
     1377    all_playlists->getActive()->setBookmark(all_playlists->getActive()->getBookmarkSong(), 0);
     1378
    13401379    isplaying = false;
    13411380    if (play_button)
    13421381        play_button->setState(false);
     
    19541993        if (output)
    19551994        {
    19561995            stop();
     1996            all_playlists->getActive()->setBookmark(node_int, 0);
    19571997            play();
    1958        }
     1998        }
     1999        else
     2000        {
     2001            uint offset;
     2002            if (node_int == all_playlists->getActive()->getBookmarkSong())
     2003                offset = all_playlists->getActive()->getBookmarkSongOffset();
     2004            else
     2005                offset = 0;
     2006
     2007            all_playlists->getActive()->setBookmark(node_int, offset);
     2008        }
    19592009    }
    19602010    else
    19612011    {
  • 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

     
    321321    return gc;
    322322};
    323323
     324static HostComboBox *ResumeMode()
     325{
     326    HostComboBox *gc = new HostComboBox("ResumeMode");
     327    gc->setLabel(QObject::tr("Resume mode"));
     328    gc->addSelection(QObject::tr("Playlist"), "playlist");
     329    gc->addSelection(QObject::tr("Track"), "track");
     330    gc->addSelection(QObject::tr("Exact"), "exact");
     331    gc->setCurrent(0);
     332    gc->setHelpText(QObject::tr("Resume playback at either the beginning of the "
     333                    "playlist, the beginning of the last track, an exact point within "
     334                    "the last track."));
     335    return gc;
     336};
     337
    324338static HostSlider *VisualModeDelay()
    325339{
    326340    HostSlider *gc = new HostSlider("VisualModeDelay", 0, 100, 1);
     
    549563    VerticalConfigurationGroup* playersettings = new VerticalConfigurationGroup(false);
    550564    playersettings->setLabel(QObject::tr("Playback Settings"));
    551565    playersettings->addChild(PlayMode());
     566    playersettings->addChild(ResumeMode());
    552567    playersettings->addChild(SetRatingWeight());
    553568    playersettings->addChild(SetPlayCountWeight());
    554569    playersettings->addChild(SetLastPlayWeight());
  • mythmusic/mythmusic/dbcheck.cpp

     
    99#include "mythtv/mythcontext.h"
    1010#include "mythtv/mythdbcon.h"
    1111
    12 const QString currentDatabaseVersion = "1008";
     12const QString currentDatabaseVersion = "1009";
    1313
    1414static bool UpdateDBVersionNumber(const QString &newnumber)
    1515{   
     
    497497            return false;
    498498    }
    499499
     500    if (dbver == "1008")
     501    {
     502        const QString updates[] = {
     503"ALTER TABLE music_playlists ADD COLUMN resume_song INTEGER UNSIGNED NOT NULL DEFAULT 0 AFTER playlist_songs;",
     504"ALTER TABLE music_playlists ADD COLUMN resume_offset INTEGER UNSIGNED NOT NULL DEFAULT 0 AFTER resume_song;",
     505""
     506};
     507        if (!performActualUpdate(updates, "1009", dbver))
     508            return false;
     509    }
     510
    500511/* in 0.21 */
    501512//"DROP TABLE musicmetadata;",
    502513//"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")
     
    800815    fillSonglistFromQuery(whereClause, removeDuplicates, insertOption, currentTrackID);
    801816}
    802817
     818void Playlist::setBookmark(uint song, uint offset)
     819{
     820    for (uint track = 0; track < songs.count(); track++)
     821        if (songs.at(track) && songs.at(track)->getValue() == static_cast<int>(song))
     822        {
     823            resume_song = song;
     824            resume_offset = offset;
     825            changed = true;
     826        }
     827}
     828
    803829void Playlist::savePlaylist(QString a_name, QString a_host)
    804830{
    805831    name = a_name.simplifyWhiteSpace();
     
    852878    if (playlistid > 0)
    853879    {
    854880        QString str_query = "UPDATE music_playlists SET playlist_songs = :LIST,"
    855                             " playlist_name = :NAME, songcount = :SONGCOUNT, length = :PLAYTIME";
     881                            " playlist_name = :NAME, songcount = :SONGCOUNT, length = :PLAYTIME,"
     882                            " resume_song = :BOOKMARKSONG, resume_offset = :BOOKMARKSONGOFFSET";
    856883        if (save_host)
    857884            str_query += ", hostname = :HOSTNAME";
    858885        str_query += " WHERE playlist_id = :ID ;";
     
    863890    else
    864891    {
    865892        QString str_query = "INSERT INTO music_playlists"
    866                             " (playlist_name, playlist_songs, songcount, length";
     893                            " (playlist_name, playlist_songs, songcount, length, resume_song, resume_offset";
    867894        if (save_host)
    868895            str_query += ", hostname";
    869896        str_query += ") VALUES(:NAME, :LIST, :SONGCOUNT, :PLAYTIME";
    870897        if (save_host)
    871898            str_query += ", :HOSTNAME";
    872         str_query += ");";
     899        str_query += ", :BOOKMARKSONG, :BOOKMARKSONGOFFSET);";
    873900
    874901        query.prepare(str_query);
    875902    }
     
    879906    query.bindValue(":PLAYTIME", playtime);
    880907    if (save_host)
    881908        query.bindValue(":HOSTNAME", a_host);
     909    query.bindValue(":BOOKMARKSONG", resume_song);
     910    query.bindValue(":BOOKMARKSONGOFFSET", resume_offset);
    882911
    883912    if (!query.exec() || (playlistid < 1 && query.numRowsAffected() < 1))
    884913    {
  • mythmusic/mythmusic/playbackbox.h

     
    136136      SHUFFLE_ALBUM,
    137137      MAX_SHUFFLE_MODES
    138138    };
     139    enum ResumeMode
     140    { RESUME_OFF,
     141      RESUME_TRACK,
     142      RESUME_EXACT,
     143      MAX_RESUME_MODES
     144    };
    139145
    140146    bool listAsShuffled;
    141147    int outputBufferSize;
     
    146152
    147153    unsigned int shufflemode;
    148154    unsigned int repeatmode;
     155    unsigned int resumemode;
    149156
    150157    bool isplaying;
    151158