mirror of
https://github.com/projectM-visualizer/projectm.git
synced 2026-03-06 07:25:15 +00:00
added silly descriptors to rating increments
embedded rating concept into projectM-engine (in preparation for weighted random preset selection) git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@858 6778bc44-b910-0410-a7a0-be141de4315d
This commit is contained in:
@ -54,7 +54,8 @@ void PresetLoader::rescan()
|
||||
// Clear the directory entry collection
|
||||
m_entries.clear();
|
||||
m_presetNames.clear();
|
||||
|
||||
m_ratings.clear();
|
||||
|
||||
// If directory already opened, close it first
|
||||
if (m_dir)
|
||||
{
|
||||
@ -111,8 +112,11 @@ void PresetLoader::rescan()
|
||||
pos != alphaSortedPresetNameSet.end();++pos)
|
||||
m_presetNames.push_back(*pos);
|
||||
|
||||
// Give all presets equal rating of 3 - why 3? I don't know
|
||||
m_ratings = std::vector<int>(m_presetNames.size(), 3);
|
||||
}
|
||||
|
||||
|
||||
std::auto_ptr<Preset> PresetLoader::loadPreset(unsigned int index, PresetInputs & presetInputs, PresetOutputs & presetOutputs) const
|
||||
{
|
||||
|
||||
@ -157,21 +161,25 @@ void PresetLoader::handleDirectoryError()
|
||||
#endif
|
||||
}
|
||||
|
||||
void PresetLoader::setRating(unsigned int index, int rating) {
|
||||
assert(index >=0);
|
||||
assert(index < m_ratings.size());
|
||||
|
||||
m_ratings[index] = rating;
|
||||
}
|
||||
|
||||
unsigned int PresetLoader::addPresetURL(const std::string & url, const std::string & presetName) {
|
||||
unsigned int PresetLoader::addPresetURL(const std::string & url, const std::string & presetName, int rating) {
|
||||
m_entries.push_back(url);
|
||||
m_presetNames.push_back(presetName);
|
||||
m_ratings.push_back(rating);
|
||||
return m_entries.size()-1;
|
||||
}
|
||||
|
||||
void PresetLoader::removePreset(unsigned int index) {
|
||||
// std::vector<std::string>::iterator pos = m_entries.begin();
|
||||
//assert(pos != m_entries.end());
|
||||
|
||||
// pos += index;
|
||||
|
||||
m_entries.erase(m_entries.begin()+index);
|
||||
m_presetNames.erase(m_presetNames.begin()+index);
|
||||
m_ratings.erase(m_ratings.begin()+index);
|
||||
}
|
||||
|
||||
const std::string & PresetLoader::getPresetURL ( unsigned int index) const {
|
||||
@ -181,3 +189,7 @@ const std::string & PresetLoader::getPresetURL ( unsigned int index) const {
|
||||
const std::string & PresetLoader::getPresetName ( unsigned int index) const {
|
||||
return m_presetNames[index];
|
||||
}
|
||||
|
||||
int PresetLoader::getPresetRating ( unsigned int index) const {
|
||||
return m_ratings[index];
|
||||
}
|
||||
|
||||
@ -42,13 +42,18 @@ class PresetLoader {
|
||||
/// Add a preset to the loader's collection.
|
||||
/// \param url an url referencing the preset
|
||||
/// \returns The unique index assigned to the preset in the collection. Used with loadPreset
|
||||
unsigned int addPresetURL ( const std::string & url, const std::string & presetName);
|
||||
unsigned int addPresetURL ( const std::string & url, const std::string & presetName, int rating);
|
||||
|
||||
/// Clears all presets from the collection
|
||||
void clear() { m_entries.clear(); m_presetNames.clear(); }
|
||||
|
||||
void removePreset(unsigned int index);
|
||||
|
||||
void setRating(unsigned int index, int rating);
|
||||
|
||||
/// Get a preset rating given an index
|
||||
int getPresetRating ( unsigned int index) const;
|
||||
|
||||
/// Get a preset url given an index
|
||||
const std::string & getPresetURL ( unsigned int index) const;
|
||||
|
||||
@ -79,6 +84,7 @@ class PresetLoader {
|
||||
// vector chosen for speed, but not great for reverse index lookups
|
||||
std::vector<std::string> m_entries;
|
||||
std::vector<std::string> m_presetNames;
|
||||
std::vector<int> m_ratings;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -786,14 +786,14 @@ void projectM::removePreset(unsigned int index) {
|
||||
|
||||
}
|
||||
|
||||
unsigned int projectM::addPresetURL ( const std::string & presetURL, const std::string & presetName )
|
||||
unsigned int projectM::addPresetURL ( const std::string & presetURL, const std::string & presetName, int rating )
|
||||
{
|
||||
bool restorePosition = false;
|
||||
|
||||
if (*m_presetPos == m_presetChooser->end())
|
||||
restorePosition = true;
|
||||
restorePosition = true;
|
||||
|
||||
int index = m_presetLoader->addPresetURL ( presetURL, presetName );
|
||||
int index = m_presetLoader->addPresetURL ( presetURL, presetName, rating);
|
||||
|
||||
if (restorePosition)
|
||||
*m_presetPos = m_presetChooser->end();
|
||||
@ -855,6 +855,10 @@ std::string projectM::getPresetURL ( unsigned int index ) const
|
||||
return m_presetLoader->getPresetURL(index);
|
||||
}
|
||||
|
||||
int projectM::getPresetRating ( unsigned int index ) const
|
||||
{
|
||||
return m_presetLoader->getPresetRating(index);
|
||||
}
|
||||
|
||||
std::string projectM::getPresetName ( unsigned int index ) const
|
||||
{
|
||||
@ -911,12 +915,10 @@ unsigned int projectM::getPlaylistSize() const
|
||||
return m_presetLoader->getNumPresets();
|
||||
}
|
||||
|
||||
RandomizerFunctor::RandomizerFunctor(PresetChooser & chooser) : m_chooser(chooser) {}
|
||||
RandomizerFunctor::~RandomizerFunctor() {}
|
||||
|
||||
double RandomizerFunctor::operator() (int index) {
|
||||
return 1.0 / m_chooser.getNumPresets();
|
||||
void projectM:: changePresetRating (unsigned int index, int rating) {
|
||||
m_presetLoader->setRating(index, rating);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -194,7 +194,7 @@ public:
|
||||
bool selectedPresetIndex(unsigned int & index) const;
|
||||
|
||||
/// Add a preset url to the play list. Appended to bottom
|
||||
unsigned int addPresetURL(const std::string & presetURL, const std::string & presetName);
|
||||
unsigned int addPresetURL(const std::string & presetURL, const std::string & presetName, int rating);
|
||||
|
||||
/// Returns true if the selected preset position points to an actual preset in the
|
||||
/// currently loaded playlist
|
||||
@ -206,6 +206,11 @@ public:
|
||||
/// Returns the preset name associated with a preset index
|
||||
std::string getPresetName ( unsigned int index ) const;
|
||||
|
||||
/// Returns the rating associated with a preset index
|
||||
int getPresetRating (unsigned int index) const;
|
||||
|
||||
void changePresetRating (unsigned int index, int rating);
|
||||
|
||||
/// Returns the size of the play list
|
||||
unsigned int getPlaylistSize() const;
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ class XmlWriteFunctor {
|
||||
QPlaylistModel::QPlaylistModel ( projectM & _projectM, QObject * parent ) :
|
||||
QAbstractTableModel ( parent ), m_projectM ( _projectM )
|
||||
{
|
||||
m_ratings = QVector<int> ( rowCount(), 3 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -82,7 +82,7 @@ bool QPlaylistModel::setData ( const QModelIndex & index, const QVariant & value
|
||||
{
|
||||
if ( role == QPlaylistModel::RatingRole )
|
||||
{
|
||||
m_ratings[index.row() ] = value.toInt();
|
||||
m_projectM.changePresetRating(index.row(), value.toInt());
|
||||
emit ( dataChanged ( index, index ) );
|
||||
return true;
|
||||
}
|
||||
@ -123,17 +123,17 @@ QVariant QPlaylistModel::ratingToIcon ( int rating ) const
|
||||
{
|
||||
switch ( rating )
|
||||
{
|
||||
case 0:
|
||||
return QVariant ( QIcon ( ":/images/icons/face0.png" ) );
|
||||
case 1:
|
||||
return QVariant ( QIcon ( ":/images/icons/face1.png" ) );
|
||||
return QVariant ( QIcon ( ":/images/icons/face0.png" ) );
|
||||
case 2:
|
||||
return QVariant ( QIcon ( ":/images/icons/face2.png" ) );
|
||||
return QVariant ( QIcon ( ":/images/icons/face1.png" ) );
|
||||
case 3:
|
||||
return QVariant ( QIcon ( ":/images/icons/face3.png" ) );
|
||||
return QVariant ( QIcon ( ":/images/icons/face2.png" ) );
|
||||
case 4:
|
||||
return QVariant ( QIcon ( ":/images/icons/face4.png" ) );
|
||||
return QVariant ( QIcon ( ":/images/icons/face3.png" ) );
|
||||
case 5:
|
||||
return QVariant ( QIcon ( ":/images/icons/face4.png" ) );
|
||||
case 6:
|
||||
return QVariant ( QIcon ( ":/images/icons/face5.png" ) );
|
||||
default:
|
||||
if (rating < 0)
|
||||
@ -143,6 +143,30 @@ QVariant QPlaylistModel::ratingToIcon ( int rating ) const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString QPlaylistModel::getSillyRatingToolTip(int rating) {
|
||||
|
||||
switch (rating) {
|
||||
case 1:
|
||||
return QString("Rather watch grass grow than watch this");
|
||||
case 2:
|
||||
return QString("A very poor preset");
|
||||
case 3:
|
||||
return QString("Tolerable");
|
||||
case 4:
|
||||
return QString("Pretty good");
|
||||
case 5:
|
||||
return QString("Trippy eye candy");
|
||||
case 6:
|
||||
return QString("Crafted by a psychotic deity");
|
||||
default:
|
||||
if (rating <= 0 )
|
||||
return QString("So bad it literally makes other presets bad!");
|
||||
else
|
||||
return QString("Better than projectM itself!");
|
||||
}
|
||||
}
|
||||
|
||||
QVariant QPlaylistModel::data ( const QModelIndex & index, int role = Qt::DisplayRole ) const
|
||||
{
|
||||
|
||||
@ -157,19 +181,19 @@ QVariant QPlaylistModel::data ( const QModelIndex & index, int role = Qt::Displa
|
||||
if ( index.column() == 0 )
|
||||
return QVariant ( QString ( m_projectM.getPresetName ( index.row() ).c_str() ) );
|
||||
else
|
||||
return ratingToIcon ( m_ratings[index.row() ] );
|
||||
return ratingToIcon ( m_projectM.getPresetRating(index.row()) );
|
||||
case Qt::ToolTipRole:
|
||||
if ( index.column() == 0 )
|
||||
return QVariant ( QString ( m_projectM.getPresetName ( index.row() ).c_str() ) );
|
||||
else
|
||||
return QString ( "Current rating is %1 / 5" ).arg ( m_ratings[index.row() ] );
|
||||
return QString ( getSillyRatingToolTip(m_projectM.getPresetRating(index.row())));
|
||||
case Qt::DecorationRole:
|
||||
if ( index.column() == 1 )
|
||||
return ratingToIcon ( m_ratings[index.row() ] );
|
||||
return ratingToIcon ( m_projectM.getPresetRating(index.row()) );
|
||||
else
|
||||
return QVariant();
|
||||
case QPlaylistModel::RatingRole:
|
||||
return QVariant ( m_ratings[index.row() ] );
|
||||
return QVariant ( m_projectM.getPresetRating(index.row()) );
|
||||
case Qt::BackgroundRole:
|
||||
if (!m_projectM.selectedPresetIndex(pos))
|
||||
return QVariant();
|
||||
@ -216,8 +240,7 @@ int QPlaylistModel::columnCount ( const QModelIndex & parent ) const
|
||||
void QPlaylistModel::appendRow ( const QString & presetURL, const QString & presetName, int rating )
|
||||
{
|
||||
beginInsertRows ( QModelIndex(), rowCount(), rowCount() );
|
||||
m_projectM.addPresetURL ( presetURL.toStdString(), presetName.toStdString() );
|
||||
m_ratings.push_back ( rating );
|
||||
m_projectM.addPresetURL ( presetURL.toStdString(), presetName.toStdString(), rating );
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
@ -227,7 +250,6 @@ bool QPlaylistModel::removeRows ( int row, int count, const QModelIndex & parent
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
m_projectM.removePreset (row );
|
||||
m_ratings.remove (row);
|
||||
}
|
||||
endRemoveRows();
|
||||
return true;
|
||||
@ -236,8 +258,7 @@ bool QPlaylistModel::removeRows ( int row, int count, const QModelIndex & parent
|
||||
bool QPlaylistModel::removeRow ( int index, const QModelIndex & parent)
|
||||
{
|
||||
beginRemoveRows ( QModelIndex(), index, index );
|
||||
m_projectM.removePreset ( index );
|
||||
m_ratings.remove ( index );
|
||||
m_projectM.removePreset ( index );
|
||||
endRemoveRows();
|
||||
return true;
|
||||
}
|
||||
@ -253,7 +274,6 @@ void QPlaylistModel::clearItems()
|
||||
{
|
||||
beginRemoveRows ( QModelIndex(), 0, rowCount()-1 );
|
||||
m_projectM.clearPlaylist();
|
||||
m_ratings.clear();
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
|
||||
@ -100,12 +100,12 @@ void clearItems();
|
||||
public slots:
|
||||
void updateItemHighlights();
|
||||
|
||||
private:
|
||||
private:
|
||||
static QString getSillyRatingToolTip(int rating);
|
||||
void readPlaylistItem(QXmlStreamReader & reader);
|
||||
static QString PRESET_MIME_TYPE;
|
||||
QVariant ratingToIcon(int rating) const;
|
||||
projectM & m_projectM;
|
||||
QVector<int> m_ratings;
|
||||
QString m_playlistName;
|
||||
QString m_playlistDesc;
|
||||
};
|
||||
|
||||
@ -272,8 +272,23 @@ void QProjectM_MainWindow::changeRating ( const QModelIndex & index ) {
|
||||
if ( index.column() == 0 )
|
||||
return;
|
||||
|
||||
playlistModel->setData
|
||||
( index, ( playlistModel->data ( index, QPlaylistModel::RatingRole ).toInt() +1 ) % 6, QPlaylistModel::RatingRole );
|
||||
/// @bug get rid of hard coded rating boundaries
|
||||
int newRating = (( playlistModel->data ( index, QPlaylistModel::RatingRole ).toInt() ) % 6)+1 ;
|
||||
|
||||
|
||||
PlaylistItemVector & lastCache = *historyHash[previousFilter];
|
||||
|
||||
long id = lastCache[index.row()].id;
|
||||
|
||||
foreach (PlaylistItemVector * items, historyHash.values()) {
|
||||
foreach (PlaylistItemMetaData metaData, *items) {
|
||||
if (metaData.id == id)
|
||||
metaData.rating = newRating;
|
||||
}
|
||||
}
|
||||
qDebug() << "new rating: " << newRating ;
|
||||
playlistModel->setData( index, newRating, QPlaylistModel::RatingRole);
|
||||
|
||||
}
|
||||
|
||||
void QProjectM_MainWindow::keyReleaseEvent ( QKeyEvent * e )
|
||||
|
||||
Reference in New Issue
Block a user