aboutsummaryrefslogtreecommitdiff
path: root/src/qmmpui/playstate.cpp
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2013-08-05 13:37:05 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2013-08-05 13:37:05 +0000
commitd1d915ea7dbb89f0f5b15cdb27c18765102696ce (patch)
tree19891def16c981b8f18de079f8ebb498aea38421 /src/qmmpui/playstate.cpp
parent664d78f03b2ae95368c70ca8a45cc746a1612ccd (diff)
downloadqmmp-d1d915ea7dbb89f0f5b15cdb27c18765102696ce.tar.gz
qmmp-d1d915ea7dbb89f0f5b15cdb27c18765102696ce.tar.bz2
qmmp-d1d915ea7dbb89f0f5b15cdb27c18765102696ce.zip
fixed shuffle playback
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@3568 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/qmmpui/playstate.cpp')
-rw-r--r--src/qmmpui/playstate.cpp65
1 files changed, 30 insertions, 35 deletions
diff --git a/src/qmmpui/playstate.cpp b/src/qmmpui/playstate.cpp
index b06f1e659..1a108b3d5 100644
--- a/src/qmmpui/playstate.cpp
+++ b/src/qmmpui/playstate.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2006 by Ilya Kotov *
+ * Copyright (C) 2006-2013 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -27,32 +27,28 @@ ShufflePlayState::ShufflePlayState(PlayListModel * model) : PlayState(model)
bool ShufflePlayState::next()
{
- int itm_count = m_model->items().count();
+ if(!m_model->count())
+ return false;
- if (itm_count > 0)
+ if (m_shuffled_current >= m_shuffled_indexes.count() - 1)
{
- if (m_shuffled_current >= m_shuffled_indexes.count() - 1)
- {
- if (!m_model->isRepeatableList())
- return false;
- else
- prepare();
- }
+ if (!m_model->isRepeatableList())
+ return false;
else
- m_shuffled_current = (m_shuffled_current + 1) % m_shuffled_indexes.count();
-
- return m_model->setCurrent(m_shuffled_indexes.at(m_shuffled_current));
+ prepare();
}
- return false;
+ else
+ m_shuffled_current = (m_shuffled_current + 1) % m_shuffled_indexes.count();
+
+ return m_model->setCurrent(m_shuffled_indexes.at(m_shuffled_current));
+
}
int ShufflePlayState::nextIndex()
{
- int itm_count = m_model->items().count();
- if(!itm_count)
+ if(!m_model->count())
return -1;
-
if (m_shuffled_current >= m_shuffled_indexes.count() - 1)
{
if (!m_model->isRepeatableList())
@@ -65,36 +61,32 @@ int ShufflePlayState::nextIndex()
bool ShufflePlayState::previous()
{
- int itm_count = m_model->items().count();
+ if(!m_model->count())
+ return false;
- if (itm_count > 0)
+ if (m_shuffled_current <= 0)
{
- if (m_shuffled_current <= 0)
+ if (!m_model->isRepeatableList())
+ return false;
+ else
{
- if (!m_model->isRepeatableList())
- return false;
- else
- {
- prepare();
- m_shuffled_current = m_shuffled_indexes.count() - 1;
- }
+ prepare();
+ m_shuffled_current = m_shuffled_indexes.count() - 1;
}
+ }
- if (itm_count > 1)
- m_shuffled_current --;
+ if (m_model->count() > 1)
+ m_shuffled_current--;
- m_model->setCurrent(m_shuffled_indexes.at(m_shuffled_current));
- return true;
- }
- return false;
+ return m_model->setCurrent(m_shuffled_indexes.at(m_shuffled_current));
}
void ShufflePlayState::prepare()
{
resetState();
- for(int i = 0;i < m_model->items().count();i++)
+ for(int i = 0; i < m_model->count(); i++)
{
- if (i != m_model->currentIndex())
+ if (i != m_model->currentIndex() && m_model->isTrack(i))
m_shuffled_indexes << i;
}
@@ -102,6 +94,9 @@ void ShufflePlayState::prepare()
m_shuffled_indexes.swap(i, qrand()%m_shuffled_indexes.size());
m_shuffled_indexes.prepend(m_model->currentIndex());
+
+ for (int i = 0; i < m_shuffled_indexes.count(); i++)
+ qDebug("++%d++", m_shuffled_indexes.at(i));
}
void ShufflePlayState::resetState()