Skip to content

Commit

Permalink
add track name in player
Browse files Browse the repository at this point in the history
some renaming: active or displayed instead of current
  • Loading branch information
mbruel committed Nov 21, 2020
1 parent 671134f commit e4fd7e6
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 52 deletions.
25 changes: 14 additions & 11 deletions src/ClementineRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#endif

const QString ClementineRemote::sAppName = QStringLiteral("ClemRemote");
const QString ClementineRemote::sVersion = "1.0-rc2";
const QString ClementineRemote::sVersion = "1.0-rc3";
const QString ClementineRemote::sAppTitle = tr("Clementine Remote");
const QString ClementineRemote::sProjectUrl = QStringLiteral("https://github.com/mbruel/ClementineRemote");
const QString ClementineRemote::sBTCaddress = QStringLiteral("3BGbnvnnBCCqrGuq1ytRqUMciAyMXjXAv6");
Expand All @@ -67,13 +67,14 @@ const QMap<pb::remote::ShuffleMode, ushort> ClementineRemote::sQmlShuffleCodes =
};

const QMap<ClementineRemote::Settings, QString> ClementineRemote::sSettings = {
{Settings::host, QStringLiteral("host")},
{Settings::port, QStringLiteral("port")},
{Settings::pass, QStringLiteral("pass")},
{Settings::downloadPath, QStringLiteral("downloadPath")},
{Settings::remotePath, QStringLiteral("remotePath")},
{Settings::verticalVolume, QStringLiteral("verticalVolume")},
{Settings::iconSize, QStringLiteral("iconSize")}
{Settings::host, QStringLiteral("host")},
{Settings::port, QStringLiteral("port")},
{Settings::pass, QStringLiteral("pass")},
{Settings::downloadPath, QStringLiteral("downloadPath")},
{Settings::remotePath, QStringLiteral("remotePath")},
{Settings::verticalVolume, QStringLiteral("verticalVolume")},
{Settings::iconSize, QStringLiteral("iconSize")},
{Settings::dispArtistInTrackName, QStringLiteral("dispArtistInTrackName")},
};

ClementineRemote::ClementineRemote(QObject *parent):
Expand Down Expand Up @@ -158,6 +159,8 @@ ClementineRemote::ClementineRemote(QObject *parent):

connect(this, &ClementineRemote::libraryDownloaded, this, &ClementineRemote::onLibraryDownloaded, Qt::QueuedConnection);

RemoteSong::sDispArtistInName = _settings.value(sSettings[Settings::dispArtistInTrackName], true).toBool();

#ifdef Q_OS_IOS
if (!_settings.contains(sSettings[Settings::verticalVolume]))
setVerticalVolumeSlider(true);
Expand Down Expand Up @@ -400,7 +403,7 @@ void ClementineRemote::parseMessage(const QByteArray &data)

case pb::remote::UPDATE_TRACK_POSITION:
_trackPostition = msg.response_update_track_position().position();
emit currentTrackPosition(_trackPostition);
emit activeTrackPosition(_trackPostition);
qDebug() << "[MsgType::UPDATE_TRACK_POSITION] " << _trackPostition;
break;

Expand Down Expand Up @@ -681,7 +684,7 @@ int ClementineRemote::getAtivePlaylistIndex()
return idx;
}

qint32 ClementineRemote::currentPlaylistID() const
qint32 ClementineRemote::displayedPlaylistID() const
{
if (_dispPlaylist)
return _dispPlaylist->id;
Expand Down Expand Up @@ -883,7 +886,7 @@ void ClementineRemote::updateActiveSong(RemoteSong &&activeSong)
++idx;
}

emit activeSongLength(_activeSong.length, _activeSong.pretty_length);
emit activeSongDetails(_activeSong.name(), _activeSong.length, _activeSong.pretty_length);
qDebug() << "[MsgType::CURRENT_METAINFO] " << _activeSong.str();
}

Expand Down
44 changes: 25 additions & 19 deletions src/ClementineRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class ClementineRemote : public QObject, public Singleton<ClementineRemote>
enum class Settings {
host, port, pass,
downloadPath, remotePath,
verticalVolume, iconSize
verticalVolume, iconSize,
dispArtistInTrackName
};
static const QMap<Settings, QString> sSettings;

Expand Down Expand Up @@ -204,6 +205,9 @@ class ClementineRemote : public QObject, public Singleton<ClementineRemote>
inline Q_INVOKABLE bool verticalVolumeSlider() const;
inline Q_INVOKABLE void setVerticalVolumeSlider(bool isVertical);

inline Q_INVOKABLE bool dispArtistInTrackName() const;
inline Q_INVOKABLE void setDispArtistInTrackName(bool display);

inline Q_INVOKABLE uint iconSize() const;
inline Q_INVOKABLE void setIconSize(uint size);
inline Q_INVOKABLE bool hideServerFilesPreviousNextNavButtons() const;
Expand Down Expand Up @@ -260,7 +264,7 @@ class ClementineRemote : public QObject, public Singleton<ClementineRemote>
Q_INVOKABLE bool isCurrentPlaylistSaved() const;
Q_INVOKABLE int getAtivePlaylistIndex();

Q_INVOKABLE qint32 currentPlaylistID() const;
Q_INVOKABLE qint32 displayedPlaylistID() const;
qint32 activePlaylistID() const;
bool isActivePlaylistDisplayed() const;
void closingPlaylist(qint32 playlistID);
Expand Down Expand Up @@ -304,11 +308,10 @@ class ClementineRemote : public QObject, public Singleton<ClementineRemote>
inline const RemoteSong &playlistSong(int index) const;
inline RemoteSong &playlistSong(int index);

inline Q_INVOKABLE const QString currentTrackDuration() const;
inline Q_INVOKABLE qint32 currentTrackLength() const;

inline const RemoteSong & currentSong() const;
inline Q_INVOKABLE int currentSongIndex() const;
inline Q_INVOKABLE const QString activeTrackName() const;
inline Q_INVOKABLE const QString activeTrackDuration() const;
inline Q_INVOKABLE qint32 activeTrackLength() const;
inline const RemoteSong & activeSong() const;
Q_INVOKABLE int getActiveSongIndex() const;
void updateActiveSong(RemoteSong &&activeSong);

Expand Down Expand Up @@ -402,8 +405,8 @@ class ClementineRemote : public QObject, public Singleton<ClementineRemote>
void connectionError(const QString &err);

void activeSongIdx(qint32 idx);
void activeSongLength(qint32 length, const QString &pretty_length);
void currentTrackPosition(qint32 pos);
void activeSongDetails(const QString &name, qint32 length, const QString &pretty_length);
void activeTrackPosition(qint32 pos);
void updateVolume(qint32 vol);

void updateEngineState();
Expand Down Expand Up @@ -588,6 +591,14 @@ bool ClementineRemote::overwriteDownloadedSongs() const {return false;}
bool ClementineRemote::verticalVolumeSlider() const { return _settings.value(sSettings[Settings::verticalVolume], false).toBool(); }
void ClementineRemote::setVerticalVolumeSlider(bool isVertical) { _settings.setValue(sSettings[Settings::verticalVolume], isVertical); }

bool ClementineRemote::dispArtistInTrackName() const { return RemoteSong::sDispArtistInName; }
void ClementineRemote::setDispArtistInTrackName(bool display)
{
RemoteSong::sDispArtistInName = display;
_settings.setValue(sSettings[Settings::dispArtistInTrackName], display);
}


uint ClementineRemote::iconSize() const { return _settings.value(sSettings[Settings::iconSize], sDefaultIconSize).toUInt(); }
void ClementineRemote::setIconSize(uint size) { _settings.setValue(sSettings[Settings::iconSize], size); }
bool ClementineRemote::hideServerFilesPreviousNextNavButtons() const { return true; }
Expand Down Expand Up @@ -723,8 +734,7 @@ void ClementineRemote::selectAllSongsFromProxyModel(bool selectAll)
_songsProxyModel->selectAllSongs(selectAll);
}
int ClementineRemote::activeSongIndex() const
{
_songsModel->index(0);
{
QModelIndex modelIndex = _songsModel->index(_activeSongIndex, 0);
if (modelIndex.isValid())
{
Expand All @@ -738,15 +748,11 @@ int ClementineRemote::numberOfPlaylistSongs() const { return _songs.size(); }
const RemoteSong &ClementineRemote::playlistSong(int index) const { return _songs.at(index); }
RemoteSong &ClementineRemote::playlistSong(int index) { return _songs[index]; }

const QString ClementineRemote::currentTrackDuration() const { return _activeSong.pretty_length; }
qint32 ClementineRemote::currentTrackLength() const{ return _activeSong.length; }

const RemoteSong & ClementineRemote::currentSong() const { return _activeSong; }
const QString ClementineRemote::activeTrackName() const{ return _activeSong.name(); }
const QString ClementineRemote::activeTrackDuration() const { return _activeSong.pretty_length; }
qint32 ClementineRemote::activeTrackLength() const{ return _activeSong.length; }

int ClementineRemote::currentSongIndex() const
{
return _songsProxyModel->mapFromSource(_songsModel->index(_activeSongIndex)).row();
}
const RemoteSong & ClementineRemote::activeSong() const { return _activeSong; }



Expand Down
1 change: 1 addition & 0 deletions src/ClementineRemote.pro
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ SOURCES += \
model/RemoteFileModel.cpp \
model/RemoteSongModel.cpp \
main.cpp \
player/RemoteSong.cpp \
protobuf/remotecontrolmessages.pb.cc \
utils/Downloader.cpp

Expand Down
10 changes: 5 additions & 5 deletions src/ConnectionWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void ConnectionWorker::onDisconnectFromServer()
void ConnectionWorker::onNextSong()
{
qDebug() << "[ConnectionWorker::onNextSong]";
int nextIndex = 1 + static_cast<int>(_remote->currentSongIndex());
int nextIndex = 1 + static_cast<int>(_remote->activeSongIndex());
if (_remote->isActivePlaylistDisplayed())
onChangeToSong(nextIndex);
else
Expand All @@ -145,7 +145,7 @@ void ConnectionWorker::onNextSong()
void ConnectionWorker::onPreviousSong()
{
qDebug() << "[ConnectionWorker::onPreviousSong]";
int previousIndex = static_cast<int>(_remote->currentSongIndex()) - 1;
int previousIndex = static_cast<int>(_remote->activeSongIndex()) - 1;
if (previousIndex >= 0 )
{
if (_remote->isActivePlaylistDisplayed())
Expand Down Expand Up @@ -337,7 +337,7 @@ void ConnectionWorker::onAddRadioToPlaylist(int radioIdx)
msg.set_type(pb::remote::INSERT_URLS);

pb::remote::RequestInsertUrls *req = msg.mutable_request_insert_urls();
req->set_playlist_id(_remote->currentPlaylistID());
req->set_playlist_id(_remote->displayedPlaylistID());
req->set_play_now(true);
*req->add_urls() = _remote->radioStream(radioIdx).url.toStdString();

Expand Down Expand Up @@ -451,7 +451,7 @@ void ConnectionWorker::onChangeToSong(int proxyRow)
{
int modelRow = _remote->modelRowFromProxyRow(proxyRow);
if (modelRow != -1)
_remote->changeAndPlaySong(modelRow, _remote->currentPlaylistID());
_remote->changeAndPlaySong(modelRow, _remote->displayedPlaylistID());
else
qCritical() << "[ConnectionWorker::onChangeToSong] ERROR getting model row from proxy one: " << proxyRow;
}
Expand All @@ -463,7 +463,7 @@ void ConnectionWorker::onSetTrackPostion(qint32 newPos)
msg.mutable_request_set_track_position()->set_position(newPos);

qDebug() << "[ConnectionWorker::onSetTrackPostion] new Pos: " << newPos
<< " ("<< _remote->prettyLength(newPos) << " for track: " << _remote->currentSong().title;
<< " ("<< _remote->prettyLength(newPos) << " for track: " << _remote->activeSong().title;

sendDataToServer(msg);
}
Expand Down
13 changes: 13 additions & 0 deletions src/player/RemoteSong.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "RemoteSong.h"

bool RemoteSong::sDispArtistInName = true;

QString RemoteSong::name() const
{
QString n(title);
if (track != -1)
n.prepend(QString("%1-").arg(track));
if (sDispArtistInName && !artist.isEmpty())
n.prepend(QString("%1: ").arg(artist));
return n;
}
5 changes: 4 additions & 1 deletion src/player/RemoteSong.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ typedef struct RemoteSong

bool selected; // for its selection in ListView

static bool sDispArtistInName;

public:
RemoteSong() = default;
RemoteSong(const RemoteSong &) = default;
Expand All @@ -77,7 +79,8 @@ typedef struct RemoteSong

~RemoteSong() = default;

inline QString str() const;
inline QString str() const;
QString name() const;

// inline RemoteSong& operator=(const pb::remote::SongMetadata &m);
} RemoteSong;
Expand Down
30 changes: 23 additions & 7 deletions src/qml/MainApp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Item {


property int headerButtonSize : cppRemote.iconSize();
property int trackLength: cppRemote.currentTrackLength()
property int trackLength: cppRemote.activeTrackLength()

property color bgGradiantStart: "#8b008b" // darkmagenta (https://doc.qt.io/qt-5/qml-color.html)
property color bgGradiantStop: "#ff8c00" // darkorange
Expand Down Expand Up @@ -80,13 +80,14 @@ Item {
function onInfo(title, msg) { info(title, msg); }
function onError(title, msg) { error(title, msg); }

function onActiveSongLength(length, pretty_length){
function onActiveSongDetails(title, length, pretty_length){
if (cppRemote.debugBuild())
print("[MainApp] active track duration: "+pretty_length + " ("+length+")");
trackLength = length;
print("[MainApp] new playing track: " + title + ", duration: " + pretty_length + " ("+length+")");
trackName.text = title;
trackLength = length;
trackDuration.text = pretty_length;
}
function onCurrentTrackPosition(pos){
function onActiveTrackPosition(pos){
trackPosition.text = cppRemote.prettyLength(pos);
trackSlider.value = pos / trackLength;
}
Expand Down Expand Up @@ -581,9 +582,24 @@ You can change that in:<br/>Tools -> Preferences -> Network Remote"));
rightMargin: 1.5*headerButtonSize + toolBarMargin
topMargin: -5
}
text: cppRemote.currentTrackDuration()
text: cppRemote.activeTrackDuration()
} // trackDuration

Text{
id: trackName
anchors{
top: playerBar.top
left: playerBar.left
topMargin: trackSlider.height/2
leftMargin: headerButtonSize
}
width: trackSlider.width - 15
elide: Text.ElideRight
horizontalAlignment: Text.AlignHCenter
text: cppRemote.isPlaying() ? cppRemote.activeTrackName() : ""
// text: "short track name"
// text: "this is my track name that is rather quite a big long"
} // trackDuration


// Second line
Expand Down Expand Up @@ -841,7 +857,7 @@ You can change that in:<br/>Tools -> Preferences -> Network Remote"));
wrapMode: Text.WordWrap
}
}
}
} // noInternetRadioPage

Dialog {
id: infoDialog
Expand Down
12 changes: 6 additions & 6 deletions src/qml/Playlist.qml
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ Rectangle {
title: qsTr("Delete Playlist")

standardButtons: Dialog.Yes | Dialog.No
onAccepted: cppRemote.closePlaylist(cppRemote.currentPlaylistID());
onAccepted: cppRemote.closePlaylist(cppRemote.displayedPlaylistID());

Label {
width: parent.width - 5
Expand Down Expand Up @@ -583,7 +583,7 @@ Are you sure you want to continue?")
if (createNewPlaylist)
cppRemote.createPlaylist(newNameField.text);
else
cppRemote.renamePlaylist(cppRemote.currentPlaylistID(), newNameField.text);
cppRemote.renamePlaylist(cppRemote.displayedPlaylistID(), newNameField.text);
}
}

Expand Down Expand Up @@ -620,7 +620,7 @@ Are you sure you want to continue?")
onTriggered: {
if (!mainApp.checkClementineVersion())
return
cppRemote.savePlaylist(cppRemote.currentPlaylistID());
cppRemote.savePlaylist(cppRemote.displayedPlaylistID());
}
}
Action {
Expand All @@ -640,7 +640,7 @@ Are you sure you want to continue?")
onTriggered: {
if (!mainApp.checkClementineVersion())
return
cppRemote.clearPlaylist(cppRemote.currentPlaylistID());
cppRemote.clearPlaylist(cppRemote.displayedPlaylistID());
}
}
Action {
Expand All @@ -654,10 +654,10 @@ Are you sure you want to continue?")
if (!cppRemote.isCurrentPlaylistSaved())
playlistDestructionConfirmationDialog.open();
else
cppRemote.closePlaylist(cppRemote.currentPlaylistID());
cppRemote.closePlaylist(cppRemote.displayedPlaylistID());
}
else
cppRemote.closePlaylist(cppRemote.currentPlaylistID());
cppRemote.closePlaylist(cppRemote.displayedPlaylistID());
}
}
Action {
Expand Down
Loading

0 comments on commit e4fd7e6

Please sign in to comment.