summaryrefslogtreecommitdiffstats
path: root/xbmc/guilib/GUIVisualisationControl.h
blob: 5d674aafc16de8c4cde72b5ed225ea8d0038124a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 *  Copyright (C) 2005-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include "GUIControl.h"
#include "cores/AudioEngine/Interfaces/IAudioCallback.h"

#include <list>
#include <string>
#include <vector>

namespace KODI
{
namespace ADDONS
{
class CVisualization;
} // namespace ADDONS
} // namespace KODI

class CAudioBuffer
{
public:
  explicit CAudioBuffer(int iSize);
  virtual ~CAudioBuffer();
  const float* Get() const;
  int Size() const;
  void Set(const float* psBuffer, int iSize);

private:
  CAudioBuffer(const CAudioBuffer&) = delete;
  CAudioBuffer& operator=(const CAudioBuffer&) = delete;
  CAudioBuffer();
  float* m_pBuffer;
  int m_iLen;
};

class CGUIVisualisationControl : public CGUIControl, public IAudioCallback
{
public:
  CGUIVisualisationControl(
      int parentID, int controlID, float posX, float posY, float width, float height);
  CGUIVisualisationControl(const CGUIVisualisationControl& from);
  CGUIVisualisationControl* Clone() const override
  {
    return new CGUIVisualisationControl(*this);
  }; //! @todo check for naughties

  // Child functions related to IAudioCallback
  void OnInitialize(int channels, int samplesPerSec, int bitsPerSample) override;
  void OnAudioData(const float* audioData, unsigned int audioDataLength) override;

  // Child functions related to CGUIControl
  void FreeResources(bool immediately = false) override;
  void Process(unsigned int currentTime, CDirtyRegionList& dirtyregions) override;
  void Render() override;
  void UpdateVisibility(const CGUIListItem* item = nullptr) override;
  bool OnAction(const CAction& action) override;
  bool OnMessage(CGUIMessage& message) override;
  bool CanFocus() const override { return false; }
  bool CanFocusFromPoint(const CPoint& point) const override;

  std::string Name();
  void UpdateTrack();
  bool HasPresets();
  void SetPreset(int idx);
  bool IsLocked();
  int GetActivePreset();
  std::string GetActivePresetName();
  bool GetPresetList(std::vector<std::string>& vecpresets);

private:
  bool InitVisualization();
  void DeInitVisualization();
  inline void CreateBuffers();
  inline void ClearBuffers();

  bool m_callStart{false};
  bool m_alreadyStarted{false};
  bool m_attemptedLoad{false};
  bool m_updateTrack{false};

  std::list<std::unique_ptr<CAudioBuffer>> m_vecBuffers;
  unsigned int m_numBuffers; /*!< Number of Audio buffers */
  std::vector<std::string> m_presets; /*!< cached preset list */

  /* values set from "OnInitialize" IAudioCallback  */
  int m_channels;
  int m_samplesPerSec;
  int m_bitsPerSample;

  std::string m_albumThumb; /*!< track information */
  std::string m_name; /*!< To add-on sended name */
  std::string m_presetsPath; /*!< To add-on sended preset path */
  std::string m_profilePath; /*!< To add-on sended profile path */

  std::unique_ptr<KODI::ADDONS::CVisualization> m_instance;
};