summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Visualization.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
committermanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
commitbe933ef2241d79558f91796cc5b3a161f72ebf9c (patch)
treefe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Visualization.h
parent5f8335c1e49ce108ef3481863833c98efa00411b (diff)
downloadkodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip
sync with upstream
Diffstat (limited to 'xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Visualization.h')
-rw-r--r--xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Visualization.h992
1 files changed, 992 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Visualization.h b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Visualization.h
new file mode 100644
index 0000000..7b1db65
--- /dev/null
+++ b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Visualization.h
@@ -0,0 +1,992 @@
1/*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#pragma once
10
11#include "../AddonBase.h"
12#include "../c-api/addon-instance/visualization.h"
13#include "../gui/renderHelper.h"
14
15#ifdef __cplusplus
16namespace kodi
17{
18namespace addon
19{
20
21
22//==============================================================================
23/// @defgroup cpp_kodi_addon_visualization_Defs_VisualizationTrack class VisualizationTrack
24/// @ingroup cpp_kodi_addon_visualization_Defs
25/// @brief **Info tag data structure**\n
26/// Representation of available information of processed audio file.
27///
28/// This is used to store all the necessary data of audio stream and to have on
29/// e.g. GUI for information.
30///
31/// Called from @ref kodi::addon::CInstanceVisualization::UpdateTrack() with the
32/// information of the currently-playing song.
33///
34/// ----------------------------------------------------------------------------
35///
36/// @copydetails cpp_kodi_addon_visualization_Defs_VisualizationTrack_Help
37///
38///@{
39class VisualizationTrack
40{
41 /*! \cond PRIVATE */
42 friend class CInstanceVisualization;
43 /*! \endcond */
44
45public:
46 /*! \cond PRIVATE */
47 VisualizationTrack() = default;
48 VisualizationTrack(const VisualizationTrack& tag)
49 {
50 *this = tag;
51 }
52
53 VisualizationTrack& operator=(const VisualizationTrack& right)
54 {
55 if (&right == this)
56 return *this;
57
58 m_title = right.m_title;
59 m_artist = right.m_artist;
60 m_album = right.m_album;
61 m_albumArtist = right.m_albumArtist;
62 m_genre = right.m_genre;
63 m_comment = right.m_comment;
64 m_lyrics = right.m_lyrics;
65
66 m_trackNumber = right.m_trackNumber;
67 m_discNumber = right.m_discNumber;
68 m_duration = right.m_duration;
69 m_year = right.m_year;
70 m_rating = right.m_rating;
71 return *this;
72 }
73 /*! \endcond */
74
75 /// @defgroup cpp_kodi_addon_visualization_Defs_VisualizationTrack_Help Value Help
76 /// @ingroup cpp_kodi_addon_visualization_Defs_VisualizationTrack
77 ///
78 /// <b>The following table contains values that can be set with @ref cpp_kodi_addon_visualization_Defs_VisualizationTrack :</b>
79 /// | Name | Type | Set call | Get call
80 /// |------|------|----------|----------
81 /// | **Title of the current song.** | `std::string` | @ref VisualizationTrack::SetTitle "SetTitle" | @ref VisualizationTrack::GetTitle "GetTitle"
82 /// | **Artist names, as a single string** | `std::string` | @ref VisualizationTrack::SetArtist "SetArtist" | @ref VisualizationTrack::GetArtist "GetArtist"
83 /// | **Album that the current song is from.** | `std::string` | @ref VisualizationTrack::SetAlbum "SetAlbum" | @ref VisualizationTrack::GetAlbum "GetAlbum"
84 /// | **Album artist names, as a single string** | `std::string` | @ref VisualizationTrack::SetAlbumArtist "SetAlbumArtist" | @ref VisualizationTrack::GetAlbumArtist "GetAlbumArtist"
85 /// | **The genre name from the music tag, if present** | `std::string` | @ref VisualizationTrack::SetGenre "SetGenre" | @ref VisualizationTrack::GetGenre "GetGenre"
86 /// | **Duration of the current song, in seconds** | `int` | @ref VisualizationTrack::SetDuration "SetDuration" | @ref VisualizationTrack::GetDuration "GetDuration"
87 /// | **Track number of the current song** | `int` | @ref VisualizationTrack::SetTrack "SetTrack" | @ref VisualizationTrack::GetTrack "GetTrack"
88 /// | **Disc number of the current song stored in the ID tag info** | `int` | @ref VisualizationTrack::SetDisc "SetDisc" | @ref VisualizationTrack::GetDisc "GetDisc"
89 /// | **Year that the current song was released** | `int` | @ref VisualizationTrack::SetYear "SetYear" | @ref VisualizationTrack::GetYear "GetYear"
90 /// | **Lyrics of the current song, if available** | `std::string` | @ref VisualizationTrack::SetLyrics "SetLyrics" | @ref VisualizationTrack::GetLyrics "GetLyrics"
91 /// | **The user-defined rating of the current song** | `int` | @ref VisualizationTrack::SetRating "SetRating" | @ref VisualizationTrack::GetRating "GetRating"
92 /// | **Comment of the current song stored in the ID tag info** | `std::string` | @ref VisualizationTrack::SetComment "SetComment" | @ref VisualizationTrack::GetComment "GetComment"
93 ///
94
95 /// @addtogroup cpp_kodi_addon_visualization_Defs_VisualizationTrack
96 ///@{
97
98 /// @brief Set title of the current song.
99 void SetTitle(const std::string& title) { m_title = title; }
100
101 /// @brief Get title of the current song.
102 const std::string& GetTitle() const { return m_title; }
103
104 /// @brief Set artist names, as a single string-
105 void SetArtist(const std::string& artist) { m_artist = artist; }
106
107 /// @brief Get artist names, as a single string-
108 const std::string& GetArtist() const { return m_artist; }
109
110 /// @brief Set Album that the current song is from.
111 void SetAlbum(const std::string& album) { m_album = album; }
112
113 /// @brief Get Album that the current song is from.
114 const std::string& GetAlbum() const { return m_album; }
115
116 /// @brief Set album artist names, as a single stringalbum artist name
117 void SetAlbumArtist(const std::string& albumArtist) { m_albumArtist = albumArtist; }
118
119 /// @brief Get album artist names, as a single string-
120 const std::string& GetAlbumArtist() const { return m_albumArtist; }
121
122 /// @brief Set genre name from music as string if present.
123 void SetGenre(const std::string& genre) { m_genre = genre; }
124
125 /// @brief Get genre name from music as string if present.
126 const std::string& GetGenre() const { return m_genre; }
127
128 /// @brief Set the duration of music as integer from info.
129 void SetDuration(int duration) { m_duration = duration; }
130
131 /// @brief Get the duration of music as integer from info.
132 int GetDuration() const { return m_duration; }
133
134 /// @brief Set track number (if present) from music info as integer.
135 void SetTrack(int trackNumber) { m_trackNumber = trackNumber; }
136
137 /// @brief Get track number (if present).
138 int GetTrack() const { return m_trackNumber; }
139
140 /// @brief Set disk number (if present) from music info as integer.
141 void SetDisc(int discNumber) { m_discNumber = discNumber; }
142
143 /// @brief Get disk number (if present)
144 int GetDisc() const { return m_discNumber; }
145
146 /// @brief Set year that the current song was released.
147 void SetYear(int year) { m_year = year; }
148
149 /// @brief Get year that the current song was released.
150 int GetYear() const { return m_year; }
151
152 /// @brief Set string from lyrics.
153 void SetLyrics(const std::string& lyrics) { m_lyrics = lyrics; }
154
155 /// @brief Get string from lyrics.
156 const std::string& GetLyrics() const { return m_lyrics; }
157
158 /// @brief Set the user-defined rating of the current song.
159 void SetRating(int rating) { m_rating = rating; }
160
161 /// @brief Get the user-defined rating of the current song.
162 int GetRating() const { return m_rating; }
163
164 /// @brief Set additional information comment (if present).
165 void SetComment(const std::string& comment) { m_comment = comment; }
166
167 /// @brief Get additional information comment (if present).
168 const std::string& GetComment() const { return m_comment; }
169
170 ///@}
171
172private:
173 VisualizationTrack(const VIS_TRACK* tag)
174 {
175 if (!tag)
176 return;
177
178 m_title = tag->title ? tag->title : "";
179 m_artist = tag->artist ? tag->artist : "";
180 m_album = tag->album ? tag->album : "";
181 m_albumArtist = tag->albumArtist ? tag->albumArtist : "";
182 m_genre = tag->genre ? tag->genre : "";
183 m_comment = tag->comment ? tag->comment : "";
184 m_lyrics = tag->lyrics ? tag->lyrics : "";
185
186 m_trackNumber = tag->trackNumber;
187 m_discNumber = tag->discNumber;
188 m_duration = tag->duration;
189 m_year = tag->year;
190 m_rating = tag->rating;
191 }
192
193 std::string m_title;
194 std::string m_artist;
195 std::string m_album;
196 std::string m_albumArtist;
197 std::string m_genre;
198 std::string m_comment;
199 std::string m_lyrics;
200
201 int m_trackNumber = 0;
202 int m_discNumber = 0;
203 int m_duration = 0;
204 int m_year = 0;
205 int m_rating = 0;
206};
207///@}
208//------------------------------------------------------------------------------
209
210//==============================================================================
211/// @defgroup cpp_kodi_addon_visualization_Defs Definitions, structures and enumerators
212/// @ingroup cpp_kodi_addon_visualization
213/// @brief **Visualization add-on instance definition values**\n
214/// All visualization functions associated data structures.
215///
216/// Used to exchange the available options between Kodi and addon.
217///
218
219//==============================================================================
220/// @addtogroup cpp_kodi_addon_visualization
221/// @brief \cpp_class{ kodi::addon::CInstanceVisualization }
222/// **Visualization add-on instance**\n
223/// [Music visualization](https://en.wikipedia.org/wiki/Music_visualization),
224/// or music visualisation, is a feature in Kodi that generates animated
225/// imagery based on a piece of music. The imagery is usually generated and
226/// rendered in real time synchronized to the music.
227///
228/// Visualization techniques range from simple ones (e.g., a simulation of an
229/// oscilloscope display) to elaborate ones, which often include a plurality
230/// of composited effects. The changes in the music's loudness and frequency
231/// spectrum are among the properties used as input to the visualization.
232///
233/// Include the header @ref Visualization.h "#include <kodi/addon-instance/Visualization.h>"
234/// to use this class.
235///
236/// This interface allows the creation of visualizations for Kodi, based upon
237/// **DirectX** or/and **OpenGL** rendering with `C++` code.
238///
239/// Additionally, there are several @ref cpp_kodi_addon_visualization_CB "other functions"
240/// available in which the child class can ask about the current hardware,
241/// including the device, display and several other parts.
242///
243/// ----------------------------------------------------------------------------
244///
245/// **Here's an example on addon.xml:**
246/// ~~~~~~~~~~~~~{.xml}
247/// <?xml version="1.0" encoding="UTF-8"?>
248/// <addon
249/// id="visualization.myspecialnamefor"
250/// version="1.0.0"
251/// name="My special visualization addon"
252/// provider-name="Your Name">
253/// <requires>@ADDON_DEPENDS@</requires>
254/// <extension
255/// point="xbmc.player.musicviz"
256/// library_@PLATFORM@="@LIBRARY_FILENAME@"/>
257/// <extension point="xbmc.addon.metadata">
258/// <summary lang="en_GB">My visualization addon addon</summary>
259/// <description lang="en_GB">My visualization addon description</description>
260/// <platform>@PLATFORM@</platform>
261/// </extension>
262/// </addon>
263/// ~~~~~~~~~~~~~
264///
265/// Description to visualization related addon.xml values:
266/// | Name | Description
267/// |:------------------------------|----------------------------------------
268/// | <b>`point`</b> | Addon type specification<br>At all addon types and for this kind always <b>"xbmc.player.musicviz"</b>.
269/// | <b>`library_@PLATFORM@`</b> | Sets the used library name, which is automatically set by cmake at addon build.
270///
271/// --------------------------------------------------------------------------
272///
273/// **Here is an example of the minimum required code to start a visualization:**
274/// ~~~~~~~~~~~~~{.cpp}
275/// #include <kodi/addon-instance/Visualization.h>
276///
277/// class CMyVisualization : public kodi::addon::CAddonBase,
278/// public kodi::addon::CInstanceVisualization
279/// {
280/// public:
281/// CMyVisualization();
282///
283/// bool Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName) override;
284/// void AudioData(const float* audioData, int audioDataLength, float* freqData, int freqDataLength) override;
285/// void Render() override;
286/// };
287///
288/// CMyVisualization::CMyVisualization()
289/// {
290/// ...
291/// }
292///
293/// bool CMyVisualization::Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName)
294/// {
295/// ...
296/// return true;
297/// }
298///
299/// void CMyVisualization::AudioData(const float* audioData, int audioDataLength, float* freqData, int freqDataLength)
300/// {
301/// ...
302/// }
303///
304/// void CMyVisualization::Render()
305/// {
306/// ...
307/// }
308///
309/// ADDONCREATOR(CMyVisualization)
310/// ~~~~~~~~~~~~~
311///
312///
313/// --------------------------------------------------------------------------
314///
315///
316/// **Here is another example where the visualization is used together with
317/// other instance types:**
318///
319/// ~~~~~~~~~~~~~{.cpp}
320/// #include <kodi/addon-instance/Visualization.h>
321///
322/// class CMyVisualization : public kodi::addon::CInstanceVisualization
323/// {
324/// public:
325/// CMyVisualization(KODI_HANDLE instance, const std::string& version);
326///
327/// bool Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName) override;
328/// void AudioData(const float* audioData, int audioDataLength, float* freqData, int freqDataLength) override;
329/// void Render() override;
330/// };
331///
332/// CMyVisualization::CMyVisualization(KODI_HANDLE instance, const std::string& version)
333/// : kodi::addon::CInstanceAudioDecoder(instance, version)
334/// {
335/// ...
336/// }
337///
338/// bool CMyVisualization::Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName)
339/// {
340/// ...
341/// return true;
342/// }
343///
344/// void CMyVisualization::AudioData(const float* audioData, int audioDataLength, float* freqData, int freqDataLength)
345/// {
346/// ...
347/// }
348///
349/// void CMyVisualization::Render()
350/// {
351/// ...
352/// }
353///
354///
355/// //----------------------------------------------------------------------
356///
357/// class CMyAddon : public kodi::addon::CAddonBase
358/// {
359/// public:
360/// CMyAddon() { }
361/// ADDON_STATUS CreateInstance(int instanceType,
362/// const std::string& instanceID,
363/// KODI_HANDLE instance,
364/// const std::string& version,
365/// KODI_HANDLE& addonInstance) override;
366/// };
367///
368/// // If you use only one instance in your add-on, can be instanceType and
369/// // instanceID ignored
370/// ADDON_STATUS CMyAddon::CreateInstance(int instanceType,
371/// const std::string& instanceID,
372/// KODI_HANDLE instance,
373/// const std::string& version,
374/// KODI_HANDLE& addonInstance)
375/// {
376/// if (instanceType == ADDON_INSTANCE_VISUALIZATION)
377/// {
378/// kodi::Log(ADDON_LOG_INFO, "Creating my visualization");
379/// addonInstance = new CMyVisualization(instance, version);
380/// return ADDON_STATUS_OK;
381/// }
382/// else if (...)
383/// {
384/// ...
385/// }
386/// return ADDON_STATUS_UNKNOWN;
387/// }
388///
389/// ADDONCREATOR(CMyAddon)
390/// ~~~~~~~~~~~~~
391///
392/// The destruction of the example class `CMyVisualization` is called from
393/// Kodi's header. Manually deleting the add-on instance is not required.
394///
395class ATTRIBUTE_HIDDEN CInstanceVisualization : public IAddonInstance
396{
397public:
398 //============================================================================
399 ///
400 /// @ingroup cpp_kodi_addon_visualization
401 /// @brief Visualization class constructor
402 ///
403 /// Used by an add-on that only supports visualizations.
404 ///
405 CInstanceVisualization()
406 : IAddonInstance(ADDON_INSTANCE_VISUALIZATION, GetKodiTypeVersion(ADDON_INSTANCE_VISUALIZATION))
407 {
408 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
409 throw std::logic_error(
410 "kodi::addon::CInstanceVisualization: Cannot create multiple instances of add-on.");
411
412 SetAddonStruct(CAddonBase::m_interface->firstKodiInstance);
413 CAddonBase::m_interface->globalSingleInstance = this;
414 }
415 //----------------------------------------------------------------------------
416
417 //==========================================================================
418 /// @ingroup cpp_kodi_addon_visualization
419 /// @brief Visualization class constructor used to support multiple instance
420 /// types.
421 ///
422 /// @param[in] instance The instance value given to
423 /// <b>`kodi::addon::CAddonBase::CreateInstance(...)`</b>.
424 /// @param[in] kodiVersion [opt] Version used in Kodi for this instance, to
425 /// allow compatibility to older Kodi versions.
426 ///
427 /// @note Recommended to set <b>`kodiVersion`</b>.
428 ///
429 ///
430 /// --------------------------------------------------------------------------
431 ///
432 /// **Here's example about the use of this:**
433 /// ~~~~~~~~~~~~~{.cpp}
434 /// class CMyVisualization : public kodi::addon::CInstanceAudioDecoder
435 /// {
436 /// public:
437 /// CMyVisualization(KODI_HANDLE instance, const std::string& kodiVersion)
438 /// : kodi::addon::CInstanceAudioDecoder(instance, kodiVersion)
439 /// {
440 /// ...
441 /// }
442 ///
443 /// ...
444 /// };
445 ///
446 /// ADDON_STATUS CMyAddon::CreateInstance(int instanceType,
447 /// const std::string& instanceID,
448 /// KODI_HANDLE instance,
449 /// const std::string& version,
450 /// KODI_HANDLE& addonInstance)
451 /// {
452 /// kodi::Log(ADDON_LOG_INFO, "Creating my visualization");
453 /// addonInstance = new CMyVisualization(instance, version);
454 /// return ADDON_STATUS_OK;
455 /// }
456 /// ~~~~~~~~~~~~~
457 ///
458 explicit CInstanceVisualization(KODI_HANDLE instance, const std::string& kodiVersion = "")
459 : IAddonInstance(ADDON_INSTANCE_VISUALIZATION,
460 !kodiVersion.empty() ? kodiVersion
461 : GetKodiTypeVersion(ADDON_INSTANCE_VISUALIZATION))
462 {
463 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
464 throw std::logic_error("kodi::addon::CInstanceVisualization: Creation of multiple together "
465 "with single instance way is not allowed!");
466
467 SetAddonStruct(instance);
468 }
469 //----------------------------------------------------------------------------
470
471 //============================================================================
472 /// @ingroup cpp_kodi_addon_visualization
473 /// @brief Destructor.
474 ///
475 ~CInstanceVisualization() override = default;
476 //----------------------------------------------------------------------------
477
478 //============================================================================
479 /// @ingroup cpp_kodi_addon_visualization
480 /// @brief Used to notify the visualization that a new song has been started.
481 ///
482 /// @param[in] channels Number of channels in the stream
483 /// @param[in] samplesPerSec Samples per second of stream
484 /// @param[in] bitsPerSample Number of bits in one sample
485 /// @param[in] songName The name of the currently-playing song
486 /// @return true if start successful done
487 ///
488 virtual bool Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName)
489 {
490 return true;
491 }
492 //----------------------------------------------------------------------------
493
494 //============================================================================
495 /// @ingroup cpp_kodi_addon_visualization
496 /// @brief Used to inform the visualization that the rendering control was
497 /// stopped.
498 ///
499 virtual void Stop() {}
500 //----------------------------------------------------------------------------
501
502 //============================================================================
503 /// @ingroup cpp_kodi_addon_visualization
504 /// @brief Pass audio data to the visualization.
505 ///
506 /// @param[in] audioData The raw audio data
507 /// @param[in] audioDataLength Length of the audioData array
508 /// @param[in] freqData The [FFT](https://en.wikipedia.org/wiki/Fast_Fourier_transform)
509 /// of the audio data
510 /// @param[in] freqDataLength Length of frequency data array
511 ///
512 /// Values **freqData** and **freqDataLength** are used if GetInfo() returns
513 /// true for the `wantsFreq` parameter. Otherwise, **freqData** is set to
514 /// `nullptr` and **freqDataLength** is `0`.
515 ///
516 virtual void AudioData(const float* audioData,
517 int audioDataLength,
518 float* freqData,
519 int freqDataLength)
520 {
521 }
522 //----------------------------------------------------------------------------
523
524 //============================================================================
525 /// @ingroup cpp_kodi_addon_visualization
526 /// @brief Used to inform Kodi that the rendered region is dirty and need an
527 /// update.
528 ///
529 /// @return True if dirty
530 ///
531 virtual bool IsDirty() { return true; }
532 //----------------------------------------------------------------------------
533
534 //============================================================================
535 /// @ingroup cpp_kodi_addon_visualization
536 /// @brief Used to indicate when the add-on should render.
537 ///
538 virtual void Render() {}
539 //----------------------------------------------------------------------------
540
541 //============================================================================
542 /// @ingroup cpp_kodi_addon_visualization
543 /// @brief Used to get the number of buffers from the current visualization.
544 ///
545 /// @param[out] wantsFreq Indicates whether the add-on wants FFT data. If set
546 /// to true, the **freqData** and **freqDataLength**
547 /// parameters of @ref AudioData() are used
548 /// @param[out] syncDelay The number of buffers to delay before calling
549 /// @ref AudioData()
550 ///
551 /// @note If this function is not implemented, it will default to
552 /// `wantsFreq` = false and `syncDelay` = 0.
553 ///
554 virtual void GetInfo(bool& wantsFreq, int& syncDelay)
555 {
556 wantsFreq = false;
557 syncDelay = 0;
558 }
559 //----------------------------------------------------------------------------
560
561 //============================================================================
562 /// @ingroup cpp_kodi_addon_visualization
563 /// @brief Used to get a list of visualization presets the user can select.
564 /// from
565 ///
566 /// @param[out] presets The vector list containing the names of presets that
567 /// the user can select
568 /// @return Return true if successful, or false if there are no presets to
569 /// choose from
570 ///
571 virtual bool GetPresets(std::vector<std::string>& presets) { return false; }
572 //----------------------------------------------------------------------------
573
574 //============================================================================
575 /// @ingroup cpp_kodi_addon_visualization
576 /// @brief Get the index of the current preset.
577 ///
578 /// @return Index number of the current preset
579 ///
580 virtual int GetActivePreset() { return -1; }
581 //----------------------------------------------------------------------------
582
583 //============================================================================
584 /// @ingroup cpp_kodi_addon_visualization
585 /// @brief Check if the add-on is locked to the current preset.
586 ///
587 /// @return True if locked to the current preset
588 ///
589 virtual bool IsLocked() { return false; }
590 //----------------------------------------------------------------------------
591
592 //============================================================================
593 /// @ingroup cpp_kodi_addon_visualization
594 /// @brief Load the previous visualization preset.
595 ///
596 /// @return Return true if the previous preset was loaded
597 ///
598 virtual bool PrevPreset() { return false; }
599 //----------------------------------------------------------------------------
600
601 //============================================================================
602 /// @ingroup cpp_kodi_addon_visualization
603 /// @brief Load the next visualization preset.
604 ///
605 /// @return Return true if the next preset was loaded
606 ///
607 virtual bool NextPreset() { return false; }
608 //----------------------------------------------------------------------------
609
610 //============================================================================
611 /// @ingroup cpp_kodi_addon_visualization
612 /// @brief Load a visualization preset.
613 ///
614 /// This function is called after a new preset is selected.
615 ///
616 /// @param[in] select Preset index to use
617 /// @return Return true if the preset is loaded
618 ///
619 virtual bool LoadPreset(int select) { return false; }
620 //----------------------------------------------------------------------------
621
622 //============================================================================
623 /// @ingroup cpp_kodi_addon_visualization
624 /// @brief Switch to a new random preset.
625 ///
626 /// @return Return true if a random preset was loaded
627 ///
628 virtual bool RandomPreset() { return false; }
629 //----------------------------------------------------------------------------
630
631 //============================================================================
632 /// @ingroup cpp_kodi_addon_visualization
633 /// @brief Lock the current visualization preset, preventing it from changing.
634 ///
635 /// @param[in] lockUnlock If set to true, the preset should be locked
636 /// @return Return true if the current preset is locked
637 ///
638 virtual bool LockPreset(bool lockUnlock) { return false; }
639 //----------------------------------------------------------------------------
640
641 //============================================================================
642 /// @ingroup cpp_kodi_addon_visualization
643 /// @brief Used to increase/decrease the visualization preset rating.
644 ///
645 /// @param[in] plusMinus If set to true the rating is increased, otherwise
646 /// decreased
647 /// @return Return true if the rating is modified
648 ///
649 virtual bool RatePreset(bool plusMinus) { return false; }
650 //----------------------------------------------------------------------------
651
652 //============================================================================
653 /// @ingroup cpp_kodi_addon_visualization
654 /// @brief Inform the visualization of the current album art image.
655 ///
656 /// @param[in] albumart Path to the current album art image
657 /// @return Return true if the image is used
658 ///
659 virtual bool UpdateAlbumart(std::string albumart) { return false; }
660 //----------------------------------------------------------------------------
661
662 //============================================================================
663 /// @ingroup cpp_kodi_addon_visualization
664 /// @brief Inform the visualization of the current track's tag information.
665 ///
666 /// @param[in] track Visualization track information structure
667 /// @return Return true if the track information is used
668 ///
669 /// --------------------------------------------------------------------------
670 ///
671 /// @copydetails cpp_kodi_addon_visualization_Defs_VisualizationTrack_Help
672 ///
673 ///-------------------------------------------------------------------------
674 ///
675 /// **Example:**
676 /// ~~~~~~~~~~~~~{.cpp}
677 ///
678 /// #include <kodi/addon-instance/Visualization.h>
679 ///
680 /// class CMyVisualization : public kodi::addon::CInstanceVisualization
681 /// {
682 /// public:
683 /// CMyVisualization(KODI_HANDLE instance, const std::string& version);
684 ///
685 /// ...
686 ///
687 /// private:
688 /// kodi::addon::VisualizationTrack m_runningTrack;
689 /// };
690 ///
691 /// bool CMyVisualization::UpdateTrack(const kodi::addon::VisualizationTrack& track)
692 /// {
693 /// m_runningTrack = track;
694 /// return true;
695 /// }
696 ///
697 /// ~~~~~~~~~~~~~
698 ///
699 virtual bool UpdateTrack(const kodi::addon::VisualizationTrack& track) { return false; }
700 //----------------------------------------------------------------------------
701
702 //============================================================================
703 /// @defgroup cpp_kodi_addon_visualization_CB Information functions
704 /// @ingroup cpp_kodi_addon_visualization
705 /// @brief **To get info about the device, display and several other parts**\n
706 /// These are functions to query any values or to transfer them to Kodi.
707 ///
708 ///@{
709
710 //============================================================================
711 /// @ingroup cpp_kodi_addon_visualization_CB
712 /// @brief To transfer available presets on addon.
713 ///
714 /// Used if @ref GetPresets not possible to use, e.g. where available presets
715 /// are only known during @ref Start call.
716 ///
717 /// @param[in] presets List to store available presets.
718 ///
719 /// @note The function should only be called once, if possible
720 ///
721 inline void TransferPresets(const std::vector<std::string>& presets)
722 {
723 m_instanceData->toKodi->clear_presets(m_instanceData->toKodi->kodiInstance);
724 for (auto it : presets)
725 m_instanceData->toKodi->transfer_preset(m_instanceData->toKodi->kodiInstance, it.c_str());
726 }
727 //----------------------------------------------------------------------------
728
729 //============================================================================
730 /// @ingroup cpp_kodi_addon_visualization_CB
731 /// @brief Device that represents the display adapter.
732 ///
733 /// @return A pointer to the used device with @ref cpp_kodi_Defs_HardwareContext "HardwareContext"
734 ///
735 /// @note This is only available on **DirectX**, It us unused (`nullptr`) on
736 /// **OpenGL**
737 ///
738 ///-------------------------------------------------------------------------
739 ///
740 /// **Example:**
741 /// ~~~~~~~~~~~~~{.cpp}
742 /// #include <d3d11_1.h>
743 /// ..
744 /// // Note: Device() there is used inside addon child class about
745 /// // kodi::addon::CInstanceVisualization
746 /// ID3D11DeviceContext1* context = static_cast<ID3D11DeviceContext1*>(kodi::addon::CInstanceVisualization::Device());
747 /// ..
748 /// ~~~~~~~~~~~~~
749 ///
750 inline kodi::HardwareContext Device() { return m_instanceData->props->device; }
751 //----------------------------------------------------------------------------
752
753 //============================================================================
754 /// @ingroup cpp_kodi_addon_visualization_CB
755 /// @brief Returns the X position of the rendering window.
756 ///
757 /// @return The X position, in pixels
758 ///
759 inline int X() { return m_instanceData->props->x; }
760 //----------------------------------------------------------------------------
761
762 //============================================================================
763 /// @ingroup cpp_kodi_addon_visualization_CB
764 /// @brief Returns the Y position of the rendering window.
765 ///
766 /// @return The Y position, in pixels
767 ///
768 inline int Y() { return m_instanceData->props->y; }
769 //----------------------------------------------------------------------------
770
771 //============================================================================
772 /// @ingroup cpp_kodi_addon_visualization_CB
773 /// @brief Returns the width of the rendering window.
774 ///
775 /// @return The width, in pixels
776 ///
777 inline int Width() { return m_instanceData->props->width; }
778 //----------------------------------------------------------------------------
779
780 //============================================================================
781 /// @ingroup cpp_kodi_addon_visualization_CB
782 /// @brief Returns the height of the rendering window.
783 ///
784 /// @return The height, in pixels
785 ///
786 inline int Height() { return m_instanceData->props->height; }
787 //----------------------------------------------------------------------------
788
789 //============================================================================
790 /// @ingroup cpp_kodi_addon_visualization_CB
791 /// @brief Pixel aspect ratio (often abbreviated PAR) is a ratio that
792 /// describes how the width of a pixel compares to the height of that pixel.
793 ///
794 /// @return The pixel aspect ratio used by the display
795 ///
796 inline float PixelRatio() { return m_instanceData->props->pixelRatio; }
797 //----------------------------------------------------------------------------
798
799 //============================================================================
800 /// @ingroup cpp_kodi_addon_visualization_CB
801 /// @brief Used to get the name of the add-on defined in `addon.xml`.
802 ///
803 /// @return The add-on name
804 ///
805 inline std::string Name() { return m_instanceData->props->name; }
806 //----------------------------------------------------------------------------
807
808 //============================================================================
809 /// @ingroup cpp_kodi_addon_visualization_CB
810 /// @brief Used to get the full path where the add-on is installed.
811 ///
812 /// @return The add-on installation path
813 ///
814 inline std::string Presets() { return m_instanceData->props->presets; }
815 //----------------------------------------------------------------------------
816
817 //============================================================================
818 /// @ingroup cpp_kodi_addon_visualization_CB
819 /// @brief Used to get the full path to the add-on's user profile.
820 ///
821 /// @note The trailing folder (consisting of the add-on's ID) is not created
822 /// by default. If it is needed, you must call kodi::vfs::CreateDirectory()
823 /// to create the folder.
824 ///
825 /// @return Path to the user profile
826 ///
827 inline std::string Profile() { return m_instanceData->props->profile; }
828 //----------------------------------------------------------------------------
829
830 ///@}
831
832private:
833 void SetAddonStruct(KODI_HANDLE instance)
834 {
835 if (instance == nullptr)
836 throw std::logic_error("kodi::addon::CInstanceVisualization: Null pointer instance passed.");
837
838 m_instanceData = static_cast<AddonInstance_Visualization*>(instance);
839 m_instanceData->toAddon->addonInstance = this;
840 m_instanceData->toAddon->start = ADDON_Start;
841 m_instanceData->toAddon->stop = ADDON_Stop;
842 m_instanceData->toAddon->audio_data = ADDON_AudioData;
843 m_instanceData->toAddon->is_dirty = ADDON_IsDirty;
844 m_instanceData->toAddon->render = ADDON_Render;
845 m_instanceData->toAddon->get_info = ADDON_GetInfo;
846 m_instanceData->toAddon->prev_preset = ADDON_PrevPreset;
847 m_instanceData->toAddon->next_preset = ADDON_NextPreset;
848 m_instanceData->toAddon->load_preset = ADDON_LoadPreset;
849 m_instanceData->toAddon->random_preset = ADDON_RandomPreset;
850 m_instanceData->toAddon->lock_preset = ADDON_LockPreset;
851 m_instanceData->toAddon->rate_preset = ADDON_RatePreset;
852 m_instanceData->toAddon->update_albumart = ADDON_UpdateAlbumart;
853 m_instanceData->toAddon->update_track = ADDON_UpdateTrack;
854 m_instanceData->toAddon->get_presets = ADDON_GetPresets;
855 m_instanceData->toAddon->get_active_preset = ADDON_GetActivePreset;
856 m_instanceData->toAddon->is_locked = ADDON_IsLocked;
857 }
858
859 inline static bool ADDON_Start(const AddonInstance_Visualization* addon,
860 int channels,
861 int samplesPerSec,
862 int bitsPerSample,
863 const char* songName)
864 {
865 CInstanceVisualization* thisClass =
866 static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance);
867 thisClass->m_renderHelper = kodi::gui::GetRenderHelper();
868 return thisClass->Start(channels, samplesPerSec, bitsPerSample, songName);
869 }
870
871 inline static void ADDON_Stop(const AddonInstance_Visualization* addon)
872 {
873 CInstanceVisualization* thisClass =
874 static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance);
875 thisClass->Stop();
876 thisClass->m_renderHelper = nullptr;
877 }
878
879 inline static void ADDON_AudioData(const AddonInstance_Visualization* addon,
880 const float* audioData,
881 int audioDataLength,
882 float* freqData,
883 int freqDataLength)
884 {
885 static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance)
886 ->AudioData(audioData, audioDataLength, freqData, freqDataLength);
887 }
888
889 inline static bool ADDON_IsDirty(const AddonInstance_Visualization* addon)
890 {
891 return static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance)->IsDirty();
892 }
893
894 inline static void ADDON_Render(const AddonInstance_Visualization* addon)
895 {
896 CInstanceVisualization* thisClass =
897 static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance);
898 if (!thisClass->m_renderHelper)
899 return;
900 thisClass->m_renderHelper->Begin();
901 thisClass->Render();
902 thisClass->m_renderHelper->End();
903 }
904
905 inline static void ADDON_GetInfo(const AddonInstance_Visualization* addon, VIS_INFO* info)
906 {
907 static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance)
908 ->GetInfo(info->bWantsFreq, info->iSyncDelay);
909 }
910
911 inline static unsigned int ADDON_GetPresets(const AddonInstance_Visualization* addon)
912 {
913 CInstanceVisualization* thisClass =
914 static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance);
915 std::vector<std::string> presets;
916 if (thisClass->GetPresets(presets))
917 {
918 for (auto it : presets)
919 thisClass->m_instanceData->toKodi->transfer_preset(addon->toKodi->kodiInstance, it.c_str());
920 }
921
922 return static_cast<unsigned int>(presets.size());
923 }
924
925 inline static int ADDON_GetActivePreset(const AddonInstance_Visualization* addon)
926 {
927 return static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance)->GetActivePreset();
928 }
929
930 inline static bool ADDON_PrevPreset(const AddonInstance_Visualization* addon)
931 {
932 return static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance)->PrevPreset();
933 }
934
935 inline static bool ADDON_NextPreset(const AddonInstance_Visualization* addon)
936 {
937 return static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance)->NextPreset();
938 }
939
940 inline static bool ADDON_LoadPreset(const AddonInstance_Visualization* addon, int select)
941
942 {
943 return static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance)->LoadPreset(select);
944 }
945
946 inline static bool ADDON_RandomPreset(const AddonInstance_Visualization* addon)
947 {
948 return static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance)->RandomPreset();
949 }
950
951 inline static bool ADDON_LockPreset(const AddonInstance_Visualization* addon)
952 {
953 CInstanceVisualization* thisClass =
954 static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance);
955 thisClass->m_presetLockedByUser = !thisClass->m_presetLockedByUser;
956 return thisClass->LockPreset(thisClass->m_presetLockedByUser);
957 }
958
959 inline static bool ADDON_RatePreset(const AddonInstance_Visualization* addon, bool plus_minus)
960 {
961 return static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance)
962 ->RatePreset(plus_minus);
963 }
964
965 inline static bool ADDON_IsLocked(const AddonInstance_Visualization* addon)
966 {
967 return static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance)->IsLocked();
968 }
969
970 inline static bool ADDON_UpdateAlbumart(const AddonInstance_Visualization* addon,
971 const char* albumart)
972 {
973 return static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance)
974 ->UpdateAlbumart(albumart);
975 }
976
977 inline static bool ADDON_UpdateTrack(const AddonInstance_Visualization* addon,
978 const VIS_TRACK* track)
979 {
980 VisualizationTrack cppTrack(track);
981 return static_cast<CInstanceVisualization*>(addon->toAddon->addonInstance)
982 ->UpdateTrack(cppTrack);
983 }
984
985 std::shared_ptr<kodi::gui::IRenderHelper> m_renderHelper;
986 bool m_presetLockedByUser = false;
987 AddonInstance_Visualization* m_instanceData;
988};
989
990} /* namespace addon */
991} /* namespace kodi */
992#endif /* __cplusplus */