MythTV  master
videovisualmonoscope.cpp
Go to the documentation of this file.
1 #include <algorithm>
2 
3 // MythTV
5 #include "videovisualmonoscope.h"
6 
7 #ifdef USING_OPENGL
9 #endif
10 #ifdef USING_VULKAN
12 #endif
13 
15  : VideoVisual(Audio, Render),
16  m_fade(Fade)
17 {
18 }
19 
21 {
22  return m_fade ? FADE_NAME : SIMPLE_NAME;
23 }
24 
26 {
27  m_hue = 0.0;
28  m_area = Area;
29  m_rate = 1.0;
30  m_lastTime = nowAsDuration<std::chrono::milliseconds>();
31  m_lineWidth = std::max(1.0F, m_area.height() * 0.004F);
32 }
33 
35 {
36  if (!Buffer)
37  return false;
38 
39  QMutexLocker locker(mutex());
40  auto * node = GetNode();
41 
42  if (m_area.isEmpty() || !node)
43  return false;
44 
45  float y = (static_cast<float>(m_area.height()) / 2.0F) + m_area.top();
46  float x = m_area.left();
47  float xstep = static_cast<float>(m_area.width()) / (NUM_SAMPLES - 1);
48 
49  double index = 0;
50  double const step = static_cast<double>(node->m_length) / NUM_SAMPLES;
51  for (size_t i = 0; i < NUM_SAMPLES; i++)
52  {
53  auto indexTo = static_cast<long>(index + step);
54  if (indexTo == static_cast<long>(index))
55  indexTo = static_cast<long>(index + 1);
56 
57  double value = 0.0;
58  for (auto s = static_cast<long>(index); s < indexTo && s < node->m_length; s++)
59  {
60  double temp = (static_cast<double>(node->m_left[s]) +
61  (node->m_right ? static_cast<double>(node->m_right[s]) : 0.0) *
62  (static_cast<double>(m_area.height())) ) / 65536.0;
63  value = temp > 0.0 ? std::max(temp, value) : std::min(temp, value);
64  }
65 
66  index += step;
67  Buffer[i * 2] = x;
68  Buffer[(i * 2) + 1] = y + static_cast<float>(value);
69  x += xstep;
70  }
71  return true;
72 }
73 
75 {
76  // try and give a similar rate of transitions for different playback speeds
77  auto timenow = nowAsDuration<std::chrono::milliseconds>();
78  m_rate = (timenow - m_lastTime).count();
79  m_lastTime = timenow;
80  m_hue += m_rate / 7200.0F;
81  if (m_hue > 1.0F)
82  m_hue -= static_cast<uint>(m_hue);
83 }
84 
86 {
87  public:
88  const QString& name() const override
89  {
90  static QString s_name(FADE_NAME);
91  return s_name;
92  }
93 
94  VideoVisual* Create(AudioPlayer* Audio, MythRender* Render) const override
95  {
96 #ifdef USING_OPENGL
97  auto * render1 = dynamic_cast<MythRenderOpenGL*>(Render);
98  if (render1)
99  return new MythVisualMonoScopeOpenGL(Audio, Render, true);
100 #endif
101 #ifdef USING_VULKAN
102  auto * render2 = dynamic_cast<MythRenderVulkan*>(Render);
103  if (render2)
104  return new MythVisualMonoScopeVulkan(Audio, Render, true);
105 #endif
106  return nullptr;
107  }
108 
109  bool SupportedRenderer(RenderType Type) override;
111 
113 {
114  return ((Type == kRenderOpenGL) || (Type == kRenderVulkan));
115 }
116 
118 {
119  public:
120  const QString& name() const override
121  {
122  static QString s_name(SIMPLE_NAME);
123  return s_name;
124  }
125 
126  VideoVisual* Create(AudioPlayer* Audio, MythRender* Render) const override
127  {
128 #ifdef USING_OPENGL
129  auto * render1 = dynamic_cast<MythRenderOpenGL*>(Render);
130  if (render1)
131  return new MythVisualMonoScopeOpenGL(Audio, Render, false);
132 #endif
133 #ifdef USING_VULKAN
134  auto * render2 = dynamic_cast<MythRenderVulkan*>(Render);
135  if (render2)
136  return new MythVisualMonoScopeVulkan(Audio, Render, false);
137 #endif
138  return nullptr;
139  }
140 
141  bool SupportedRenderer(RenderType Type) override;
143 
145 {
146  return ((Type == kRenderOpenGL) || (Type == kRenderVulkan));
147 }
VideoVisualMonoScope::UpdateVertices
bool UpdateVertices(float *Buffer)
Definition: videovisualmonoscope.cpp:34
videovisualmonoscope.h
VideoVisualMonoScopeFactory::name
const QString & name() const override
Definition: videovisualmonoscope.cpp:88
NUM_SAMPLES
static constexpr size_t NUM_SAMPLES
Definition: videovisualmonoscope.h:7
MythVisualMonoScopeVulkan
Definition: mythvisualmonoscopevulkan.h:25
AudioPlayer
Definition: audioplayer.h:22
mythvisualmonoscopevulkan.h
SIMPLE_NAME
#define SIMPLE_NAME
Definition: videovisualmonoscope.h:9
kRenderOpenGL
@ kRenderOpenGL
Definition: mythrender_base.h:19
kRenderVulkan
@ kRenderVulkan
Definition: mythrender_base.h:20
FADE_NAME
#define FADE_NAME
Definition: videovisualmonoscope.h:8
VideoVisualMonoScopeFactory::Create
VideoVisual * Create(AudioPlayer *Audio, MythRender *Render) const override
Definition: videovisualmonoscope.cpp:94
VideoVisualSimpleScopeFactory::SupportedRenderer
bool SupportedRenderer(RenderType Type) override
Definition: videovisualmonoscope.cpp:144
VideoVisualMonoScopeFactory
VideoVisualMonoScopeFactory VideoVisualMonoScopeFactory
VideoVisualMonoScope::m_lastTime
std::chrono::milliseconds m_lastTime
Definition: videovisualmonoscope.h:23
VideoVisualMonoScopeFactory::SupportedRenderer
bool SupportedRenderer(RenderType Type) override
Definition: videovisualmonoscope.cpp:112
VideoVisualFactory
Definition: videovisual.h:78
VideoVisualSimpleScopeFactory
Definition: videovisualmonoscope.cpp:117
MythTV::Visual::mutex
QMutex * mutex()
Definition: visual.h:26
mythvisualmonoscopeopengl.h
VideoVisualMonoScopeFactory
Definition: videovisualmonoscope.cpp:85
RenderType
RenderType
Definition: mythrender_base.h:15
uint
unsigned int uint
Definition: compat.h:81
VideoVisualMonoScope::m_lineWidth
float m_lineWidth
Definition: videovisualmonoscope.h:26
MythRenderOpenGL
Definition: mythrenderopengl.h:96
Buffer
Definition: MythExternControl.h:36
VideoVisualSimpleScopeFactory::Create
VideoVisual * Create(AudioPlayer *Audio, MythRender *Render) const override
Definition: videovisualmonoscope.cpp:126
MythRender
Definition: mythrender_base.h:23
VideoVisualMonoScope::Name
QString Name() override
Definition: videovisualmonoscope.cpp:20
mythchrono.h
MythVisualMonoScopeOpenGL
Definition: mythvisualmonoscopeopengl.h:13
VideoVisualSimpleScopeFactory::name
const QString & name() const override
Definition: videovisualmonoscope.cpp:120
VideoVisual
Definition: videovisual.h:43
MythRenderVulkan
Definition: mythrendervulkan.h:57
VideoVisualSimpleScopeFactory
VideoVisualSimpleScopeFactory VideoVisualSimpleScopeFactory
VideoVisualMonoScope::m_hue
float m_hue
Definition: videovisualmonoscope.h:24
VideoVisual::m_area
QRect m_area
Definition: videovisual.h:72
VideoVisualMonoScope::m_rate
float m_rate
Definition: videovisualmonoscope.h:25
VideoVisual::GetNode
VisualNode * GetNode(void)
Definition: videovisual.cpp:84
VideoVisualMonoScope::m_fade
bool m_fade
Definition: videovisualmonoscope.h:28
VideoVisualMonoScope::InitCommon
void InitCommon(QRect Area)
Definition: videovisualmonoscope.cpp:25
VideoVisualMonoScope::UpdateTime
void UpdateTime()
Definition: videovisualmonoscope.cpp:74
VideoVisualMonoScope::VideoVisualMonoScope
VideoVisualMonoScope(AudioPlayer *Audio, MythRender *Render, bool Fade)
Definition: videovisualmonoscope.cpp:14