Skip to content

Commit

Permalink
mythmusic: replace POSIX random() with MythRandom
Browse files Browse the repository at this point in the history
  • Loading branch information
ulmus-scott authored and linuxdude42 committed Apr 28, 2022
1 parent 9431903 commit ba26074
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
27 changes: 14 additions & 13 deletions mythplugins/mythmusic/mythmusic/bumpscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <compat.h>
#include <mythlogging.h>
#include <mythrandom.h>

// This was:
// Bump Scope - Visualization Plugin for XMMS
Expand Down Expand Up @@ -409,7 +410,7 @@ bool BumpScope::draw(QPainter *p, const QColor &back)
if (m_ixo > ((int)m_width / 2) || m_ixo < -((int)m_width / 2))
{
m_ixo = (m_ixo > 0) ? (m_width / 2) : -(m_width / 2);
if (random() & 1)
if (rand_bool())
{
m_ixd = (m_ixd > 0) ? -1 : 1;
m_iyd = 0;
Expand All @@ -425,7 +426,7 @@ bool BumpScope::draw(QPainter *p, const QColor &back)
if (m_iyo > ((int)m_height / 2) || m_iyo < -((int)m_height / 2))
{
m_iyo = (m_iyo > 0) ? (m_height / 2) : -(m_height / 2);
if (random() & 1)
if (rand_bool())
{
m_ixd = (m_ixd > 0) ? -1 : 1;
m_iyd = 0;
Expand All @@ -445,14 +446,14 @@ bool BumpScope::draw(QPainter *p, const QColor &back)
rgb_to_hsv(m_color, &m_ih, &m_is, &m_iv);
m_wasColor = 1;

if (random() & 1)
if (rand_bool())
{
m_ihd = (random() & 1) * 2 - 1;
m_ihd = rand_bool() ? -1 : 1;
m_isd = 0;
}
else
{
m_isd = 0.01 * ((random() & 1) * 2 - 1);
m_isd = rand_bool() ? -0.01 : 0.01;
m_ihd = 0;
}
}
Expand All @@ -468,16 +469,16 @@ bool BumpScope::draw(QPainter *p, const QColor &back)
m_ih = 0;
if (m_ih < 0)
m_ih = 359;
if ((random() % 150) == 0)
if (rand_bool(150))
{
if (random() & 1)
if (rand_bool())
{
m_ihd = (random() & 1) * 2 - 1;
m_ihd = rand_bool() ? -1 : 1;
m_isd = 0;
}
else
{
m_isd = 0.01 * ((random() & 1) * 2 - 1);
m_isd = rand_bool() ? -0.01 : 0.01;
m_ihd = 0;
}
}
Expand All @@ -494,19 +495,19 @@ bool BumpScope::draw(QPainter *p, const QColor &back)
m_isd = -0.01;
else if (m_is == 0)
{
m_ihd = random() % 360;
m_ihd = MythRandom(0, 360 - 1);
m_isd = 0.01;
}
else
{
if (random() & 1)
if (rand_bool())
{
m_ihd = (random() & 1) * 2 - 1;
m_ihd = rand_bool() ? -1 : 1;
m_isd = 0;
}
else
{
m_isd = 0.01 * ((random() & 1) * 2 - 1);
m_isd = rand_bool() ? -0.01 : 0.01;
m_ihd = 0;
}
}
Expand Down
4 changes: 2 additions & 2 deletions mythplugins/mythmusic/mythmusic/decoderhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <mythdownloadmanager.h>
#include <mythdirs.h>
#include <mythlogging.h>
#include <compat.h> // For random() on MINGW32
#include <mythrandom.h>
#include <remotefile.h>
#include <mythcorecontext.h>
#include <musicmetadata.h>
Expand Down Expand Up @@ -142,7 +142,7 @@ bool DecoderHandler::next(void)

if (m_meta.Format() == "cast")
{
m_playlistPos = random() % m_playlist.size();
m_playlistPos = MythRandom(0, m_playlist.size() - 1);
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion mythplugins/mythmusic/mythmusic/musiccommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <lcddevice.h>
#include <musicmetadata.h>
#include <mythdate.h>
#include <mythrandom.h>

// MythMusic includes
#include "musicdata.h"
Expand Down Expand Up @@ -1003,7 +1004,7 @@ void MusicCommon::cycleVisualizer(void)

//Find a visual thats not like the previous visual
do
next_visualizer = random() % m_visualModes.count();
next_visualizer = MythRandom(0, m_visualModes.count() - 1);
while (next_visualizer == m_currentVisual);
m_currentVisual = next_visualizer;
}
Expand Down
4 changes: 2 additions & 2 deletions mythplugins/mythmusic/mythmusic/vorbisencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// MythTV
#include <mythcontext.h>
#include <compat.h> // For random() on MINGW32
#include <mythrandom.h>
#include <musicmetadata.h>

// MythMusic
Expand Down Expand Up @@ -59,7 +59,7 @@ VorbisEncoder::VorbisEncoder(const QString &outfile, int qualitylevel,
vorbis_analysis_init(&m_vd, &m_vi);
vorbis_block_init(&m_vd, &m_vb);

ogg_stream_init(&m_os, random());
ogg_stream_init(&m_os, MythRandom());

ogg_packet header_main;
ogg_packet header_comments;
Expand Down

0 comments on commit ba26074

Please sign in to comment.