MythTV  master
mythgoom.cpp
Go to the documentation of this file.
1 #include "mythgoom.h"
2 
3 #include <cmath>
4 #include <cstdlib>
5 
6 #include <iostream>
7 using namespace std;
8 
9 #include <QCoreApplication>
10 #include <QPainter>
11 
12 #include <compat.h>
13 #include <mythcontext.h>
14 #include <mythlogging.h>
15 
16 #include "goom_tools.h"
17 #include "goom_core.h"
18 
20 {
21  m_fps = 20;
22 
23  goom_init(800, 600, 0);
24 
25  m_scalew = gCoreContext->GetNumSetting("VisualScaleWidth", 2);
26  m_scaleh = gCoreContext->GetNumSetting("VisualScaleHeight", 2);
27 
28  // we allow 1, 2 or 4 for the scale since goom likes its resolution to be a multiple of 2
29  if (m_scaleh == 3 || m_scaleh > 4)
30  m_scaleh = 4;
31  if (m_scaleh < 1)
32  m_scaleh = 1;
33 
34  if (m_scalew == 3 || m_scalew > 4)
35  m_scalew = 4;
36  if (m_scalew < 1)
37  m_scalew = 1;
38 }
39 
41 {
42  goom_close();
43 }
44 
45 void Goom::resize(const QSize &newsize)
46 {
47  m_size = newsize;
48 
49  m_size.setHeight((m_size.height() / 2) * 2);
50  m_size.setWidth((m_size.width() / 2) * 2);
51 
52  // only scale the resolution if it is > 256
53  // this ensures the small visualisers don't look too blocky
54  if (m_size.width() > 256)
55  goom_set_resolution(m_size.width() / m_scalew, m_size.height() / m_scaleh, 0);
56  else
57  goom_set_resolution(m_size.width(), m_size.height(), 0);
58 }
59 
61 {
62  if (!node || node->m_length == 0)
63  return false;
64 
65  int numSamps = 512;
66  if (node->m_length < 512)
67  numSamps = node->m_length;
68 
69  signed short int data[2][512];
70 
71  int i = 0;
72  for (i = 0; i < numSamps; i++)
73  {
74  data[0][i] = node->m_left[i];
75  if (node->m_right)
76  data[1][i] = node->m_right[i];
77  else
78  data[1][i] = data[0][i];
79  }
80 
81  for (; i < 512; i++)
82  {
83  data[0][i] = 0;
84  data[1][i] = 0;
85  }
86 
87  m_buffer = goom_update(data, 0);
88 
89  return false;
90 }
91 
92 bool Goom::draw(QPainter *p, const QColor &back)
93 {
94  p->fillRect(0, 0, m_size.width(), m_size.height(), back);
95 
96  if (!m_buffer)
97  return true;
98 
99  int width = m_size.width();
100  int height = m_size.height();
101 
102  if (m_size.width() > 256)
103  {
104  width /= m_scalew;
105  height /= m_scaleh;
106  }
107 
108  auto *image = new QImage((uchar*) m_buffer, width, height, width * 4, QImage::Format_RGB32);
109 
110  p->drawImage(QRect(0, 0, m_size.width(), m_size.height()), *image);
111 
112  delete image;
113 
114  return true;
115 }
116 
117 static class GoomFactory : public VisFactory
118 {
119  public:
120  const QString &name(void) const override // VisFactory
121  {
122  static QString s_name = QCoreApplication::translate("Visualizers",
123  "Goom");
124  return s_name;
125  }
126 
127  uint plugins(QStringList *list) const override // VisFactory
128  {
129  *list << name();
130  return 1;
131  }
132 
133  VisualBase *create(MainVisual *parent, const QString &pluginName) const override // VisFactory
134  {
135  (void)parent;
136  (void)pluginName;
137  return new Goom();
138  }
139 }GoomFactory;
~Goom() override
Definition: mythgoom.cpp:40
Goom(void)
Definition: mythgoom.cpp:19
static guint32 * back
Definition: goom_core.cpp:29
void goom_close()
Definition: goom_core.cpp:854
void goom_set_resolution(guint32 resx, guint32 resy, int cinemascope)
Definition: goom_core.cpp:109
guint32 * goom_update(gint16 data[2][512], int forceMode)
Definition: goom_core.cpp:138
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
short * m_right
Definition: videovisual.h:35
GoomFactory GoomFactory
unsigned int uint
Definition: compat.h:140
void goom_init(guint32 resx, guint32 resy, int cinemascope)
Definition: goom_core.cpp:68
VisualBase * create(MainVisual *parent, const QString &pluginName) const override
Definition: mythgoom.cpp:133
int GetNumSetting(const QString &key, int defaultval=0)
void resize(const QSize &size) override
Definition: mythgoom.cpp:45
long m_length
Definition: videovisual.h:36
bool draw(QPainter *p, const QColor &back) override
Definition: mythgoom.cpp:92
bool process(VisualNode *node) override
Definition: mythgoom.cpp:60
Definition: mythgoom.h:9
uint plugins(QStringList *list) const override
Definition: mythgoom.cpp:127
const QString & name(void) const override
Definition: mythgoom.cpp:120
short * m_left
Definition: videovisual.h:34