forked from Mudlet/Mudlet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into development
- Loading branch information
Showing
6 changed files
with
265 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/*************************************************************************** | ||
* Copyright (C) 2024 by Mike Conley - [email protected] * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program; if not, write to the * | ||
* Free Software Foundation, Inc., * | ||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | ||
***************************************************************************/ | ||
|
||
#include "TMediaPlaylist.h" | ||
|
||
#include "pre_guard.h" | ||
#include <QRandomGenerator> | ||
#include "post_guard.h" | ||
|
||
TMediaPlaylist::TMediaPlaylist() | ||
: mCurrentIndex(0), mPlaybackMode(Sequential) {} | ||
|
||
TMediaPlaylist::~TMediaPlaylist() {} | ||
|
||
void TMediaPlaylist::addMedia(const QUrl &url) { | ||
mMediaList.append(url); | ||
} | ||
|
||
void TMediaPlaylist::removeMedia(int startIndex, int endIndex) { | ||
if (endIndex >= startIndex && startIndex >= 0 && endIndex < mMediaList.size()) { | ||
for (int i = endIndex; i >= startIndex; --i) { | ||
mMediaList.removeAt(i); | ||
} | ||
} | ||
} | ||
|
||
void TMediaPlaylist::clear() { | ||
mMediaList.clear(); | ||
} | ||
|
||
int TMediaPlaylist::mediaCount() const { | ||
return mMediaList.count(); | ||
} | ||
|
||
bool TMediaPlaylist::isEmpty() const { | ||
return mMediaList.isEmpty(); | ||
} | ||
|
||
void TMediaPlaylist::setPlaybackMode(PlaybackMode mode) { | ||
mPlaybackMode = mode; | ||
} | ||
|
||
TMediaPlaylist::PlaybackMode TMediaPlaylist::playbackMode() const { | ||
return mPlaybackMode; | ||
} | ||
|
||
QUrl TMediaPlaylist::currentMedia() const { | ||
if (!mMediaList.isEmpty() && mCurrentIndex >= 0 && mCurrentIndex < mMediaList.size()) { | ||
return mMediaList.at(mCurrentIndex); | ||
} | ||
return QUrl(); | ||
} | ||
|
||
bool TMediaPlaylist::setCurrentIndex(int index) { | ||
if (index >= 0 && index < mMediaList.size()) { | ||
mCurrentIndex = index; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
int TMediaPlaylist::currentIndex() const { | ||
return mCurrentIndex; | ||
} | ||
|
||
int TMediaPlaylist::nextIndex() const { | ||
if (mPlaybackMode == Loop && (mCurrentIndex + 1 == mMediaList.size())) { | ||
return 0; | ||
} else if (mPlaybackMode == Random) { | ||
return QRandomGenerator::global()->bounded(mMediaList.size()); | ||
} else if (mCurrentIndex + 1 < mMediaList.size()) { | ||
return mCurrentIndex + 1; | ||
} | ||
return -1; // No valid next index if out of range | ||
} | ||
|
||
QUrl TMediaPlaylist::next() { | ||
if (mMediaList.isEmpty()) { | ||
return QUrl(); | ||
} | ||
|
||
if (mPlaybackMode == Loop && (mCurrentIndex + 1 == mMediaList.size())) { | ||
mCurrentIndex = 0; | ||
} else if (mPlaybackMode == Random) { | ||
mCurrentIndex = QRandomGenerator::global()->bounded(mMediaList.size()); | ||
} else { | ||
mCurrentIndex++; | ||
} | ||
|
||
if (mCurrentIndex < mMediaList.size()) { | ||
return mMediaList.at(mCurrentIndex); | ||
} | ||
|
||
return QUrl(); | ||
} | ||
|
||
QUrl TMediaPlaylist::previous() { | ||
if (mPlaybackMode == Loop && mCurrentIndex == 0) { | ||
mCurrentIndex = mMediaList.size() - 1; | ||
} else { | ||
mCurrentIndex--; | ||
} | ||
|
||
if (mCurrentIndex >= 0) { | ||
return mMediaList.at(mCurrentIndex); | ||
} | ||
|
||
return QUrl(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#ifndef TMEDIAPLAYLIST_H | ||
#define TMEDIAPLAYLIST_H | ||
|
||
/*************************************************************************** | ||
* Copyright (C) 2024 by Mike Conley - [email protected] * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program; if not, write to the * | ||
* Free Software Foundation, Inc., * | ||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | ||
***************************************************************************/ | ||
|
||
#include "pre_guard.h" | ||
#include <QList> | ||
#include <QUrl> | ||
#include "post_guard.h" | ||
|
||
class TMediaPlaylist | ||
{ | ||
public: | ||
enum PlaybackMode { | ||
Sequential, | ||
Loop, | ||
Random | ||
}; | ||
|
||
TMediaPlaylist(); | ||
~TMediaPlaylist(); | ||
|
||
void addMedia(const QUrl &url); | ||
void removeMedia(int startIndex, int endIndex); | ||
void clear(); | ||
int mediaCount() const; | ||
bool isEmpty() const; | ||
void setPlaybackMode(PlaybackMode mode); | ||
PlaybackMode playbackMode() const; | ||
|
||
QUrl currentMedia() const; | ||
bool setCurrentIndex(int index); | ||
int currentIndex() const; | ||
int nextIndex() const; | ||
QUrl next(); | ||
QUrl previous(); | ||
|
||
private: | ||
QList<QUrl> mMediaList; | ||
int mCurrentIndex; | ||
PlaybackMode mPlaybackMode; | ||
}; | ||
|
||
#endif // TMEDIAPLAYLIST_H |
Oops, something went wrong.