diff options
| author | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
| commit | be933ef2241d79558f91796cc5b3a161f72ebf9c (patch) | |
| tree | fe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Visualization.h | |
| parent | 5f8335c1e49ce108ef3481863833c98efa00411b (diff) | |
| download | kodi-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-addon-dev-kit/include/kodi/addon-instance/Visualization.h')
| -rw-r--r-- | xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Visualization.h | 789 |
1 files changed, 0 insertions, 789 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Visualization.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Visualization.h deleted file mode 100644 index 4be785d..0000000 --- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Visualization.h +++ /dev/null | |||
| @@ -1,789 +0,0 @@ | |||
| 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 | /* | ||
| 12 | * Parts with a comment named "internal" are only used inside header and not | ||
| 13 | * used or accessed direct during add-on development! | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include "../AddonBase.h" | ||
| 17 | #include "../gui/renderHelper.h" | ||
| 18 | |||
| 19 | namespace kodi { namespace addon { class CInstanceVisualization; }} | ||
| 20 | |||
| 21 | extern "C" | ||
| 22 | { | ||
| 23 | |||
| 24 | struct AddonInstance_Visualization; | ||
| 25 | |||
| 26 | typedef enum VIS_ACTION : unsigned int /* internal */ | ||
| 27 | { | ||
| 28 | VIS_ACTION_NONE = 0, | ||
| 29 | VIS_ACTION_NEXT_PRESET, | ||
| 30 | VIS_ACTION_PREV_PRESET, | ||
| 31 | VIS_ACTION_LOAD_PRESET, | ||
| 32 | VIS_ACTION_RANDOM_PRESET, | ||
| 33 | VIS_ACTION_LOCK_PRESET, | ||
| 34 | VIS_ACTION_RATE_PRESET_PLUS, | ||
| 35 | VIS_ACTION_RATE_PRESET_MINUS, | ||
| 36 | VIS_ACTION_UPDATE_ALBUMART, | ||
| 37 | VIS_ACTION_UPDATE_TRACK | ||
| 38 | } VIS_ACTION; | ||
| 39 | |||
| 40 | struct VIS_INFO /* internal */ | ||
| 41 | { | ||
| 42 | bool bWantsFreq; | ||
| 43 | int iSyncDelay; | ||
| 44 | }; | ||
| 45 | |||
| 46 | typedef struct AddonProps_Visualization /* internal */ | ||
| 47 | { | ||
| 48 | void *device; | ||
| 49 | int x; | ||
| 50 | int y; | ||
| 51 | int width; | ||
| 52 | int height; | ||
| 53 | float pixelRatio; | ||
| 54 | const char *name; | ||
| 55 | const char *presets; | ||
| 56 | const char *profile; | ||
| 57 | } AddonProps_Visualization; | ||
| 58 | |||
| 59 | typedef struct AddonToKodiFuncTable_Visualization /* internal */ | ||
| 60 | { | ||
| 61 | KODI_HANDLE kodiInstance; | ||
| 62 | void (__cdecl* transfer_preset) (void* kodiInstance, const char* preset); | ||
| 63 | void (__cdecl* clear_presets) (void* kodiInstance); | ||
| 64 | } AddonToKodiFuncTable_Visualization; | ||
| 65 | |||
| 66 | typedef struct KodiToAddonFuncTable_Visualization /* internal */ | ||
| 67 | { | ||
| 68 | kodi::addon::CInstanceVisualization* addonInstance; | ||
| 69 | bool (__cdecl* start)(const AddonInstance_Visualization* instance, int channels, int samples_per_sec, int bits_per_sample, const char* song_name); | ||
| 70 | void (__cdecl* stop)(const AddonInstance_Visualization* instance); | ||
| 71 | void (__cdecl* audio_data)(const AddonInstance_Visualization* instance, const float* audio_data, int audio_data_length, float *freq_data, int freq_data_length); | ||
| 72 | bool (__cdecl* is_dirty)(const AddonInstance_Visualization* instance); | ||
| 73 | void (__cdecl* render)(const AddonInstance_Visualization* instance); | ||
| 74 | void (__cdecl* get_info)(const AddonInstance_Visualization* instance, VIS_INFO *info); | ||
| 75 | bool (__cdecl* on_action)(const AddonInstance_Visualization* instance, VIS_ACTION action, const void *param); | ||
| 76 | unsigned int (__cdecl *get_presets)(const AddonInstance_Visualization* instance); | ||
| 77 | int (__cdecl *get_active_preset)(const AddonInstance_Visualization* instance); | ||
| 78 | bool (__cdecl* is_locked)(const AddonInstance_Visualization* instance); | ||
| 79 | } KodiToAddonFuncTable_Visualization; | ||
| 80 | |||
| 81 | typedef struct AddonInstance_Visualization /* internal */ | ||
| 82 | { | ||
| 83 | AddonProps_Visualization* props; | ||
| 84 | AddonToKodiFuncTable_Visualization* toKodi; | ||
| 85 | KodiToAddonFuncTable_Visualization* toAddon; | ||
| 86 | } AddonInstance_Visualization; | ||
| 87 | |||
| 88 | //============================================================================ | ||
| 89 | /// \defgroup cpp_kodi_addon_visualization_VisTrack class VisTrack | ||
| 90 | /// \ingroup cpp_kodi_addon_visualization | ||
| 91 | /// @brief **Visualization track information structure** | ||
| 92 | /// | ||
| 93 | /// Called from kodi::addon::CInstanceVisualization::UpdateTrack() with the | ||
| 94 | /// information of the currently-playing song. | ||
| 95 | /// | ||
| 96 | //@{ | ||
| 97 | struct VisTrack | ||
| 98 | { | ||
| 99 | /// @brief Title of the current song. | ||
| 100 | const char *title; | ||
| 101 | |||
| 102 | /// @brief Artist names, as a single string | ||
| 103 | const char *artist; | ||
| 104 | |||
| 105 | /// @brief Album that the current song is from. | ||
| 106 | const char *album; | ||
| 107 | |||
| 108 | /// @brief Album artist names, as a single string | ||
| 109 | const char *albumArtist; | ||
| 110 | |||
| 111 | /// @brief The genre name from the music tag, if present. | ||
| 112 | const char *genre; | ||
| 113 | |||
| 114 | /// @brief Comment of the current song stored in the ID tag info. | ||
| 115 | const char *comment; | ||
| 116 | |||
| 117 | /// @brief Lyrics of the current song, if available. | ||
| 118 | const char *lyrics; | ||
| 119 | |||
| 120 | const char *reserved1; | ||
| 121 | const char *reserved2; | ||
| 122 | |||
| 123 | /// @brief Track number of the current song. | ||
| 124 | int trackNumber; | ||
| 125 | |||
| 126 | /// @brief Disc number of the current song stored in the ID tag info. | ||
| 127 | int discNumber; | ||
| 128 | |||
| 129 | /// @brief Duration of the current song, in seconds. | ||
| 130 | int duration; | ||
| 131 | |||
| 132 | /// @brief Year that the current song was released. | ||
| 133 | int year; | ||
| 134 | |||
| 135 | /// @brief The user-defined rating of the current song. | ||
| 136 | int rating; | ||
| 137 | |||
| 138 | int reserved3; | ||
| 139 | int reserved4; | ||
| 140 | }; | ||
| 141 | //@} | ||
| 142 | //---------------------------------------------------------------------------- | ||
| 143 | |||
| 144 | } /* extern "C" */ | ||
| 145 | |||
| 146 | namespace kodi | ||
| 147 | { | ||
| 148 | namespace addon | ||
| 149 | { | ||
| 150 | |||
| 151 | //============================================================================ | ||
| 152 | /// | ||
| 153 | /// \addtogroup cpp_kodi_addon_visualization | ||
| 154 | /// @brief \cpp_class{ kodi::addon::CInstanceVisualization } | ||
| 155 | /// **Visualization add-on instance** | ||
| 156 | /// | ||
| 157 | /// [Music visualization](https://en.wikipedia.org/wiki/Music_visualization), | ||
| 158 | /// or music visualisation, is a feature in Kodi that generates animated | ||
| 159 | /// imagery based on a piece of music. The imagery is usually generated and | ||
| 160 | /// rendered in real time synchronized to the music. | ||
| 161 | /// | ||
| 162 | /// Visualization techniques range from simple ones (e.g., a simulation of an | ||
| 163 | /// oscilloscope display) to elaborate ones, which often include a plurality | ||
| 164 | /// of composited effects. The changes in the music's loudness and frequency | ||
| 165 | /// spectrum are among the properties used as input to the visualization. | ||
| 166 | /// | ||
| 167 | /// Include the header \ref Visualization.h "#include <kodi/addon-instance/Visualization.h>" | ||
| 168 | /// to use this class. | ||
| 169 | /// | ||
| 170 | /// This interface allows the creation of visualizations for Kodi, based upon | ||
| 171 | /// **DirectX** or/and **OpenGL** rendering with `C++` code. | ||
| 172 | /// | ||
| 173 | /// Additionally, there are several \ref cpp_kodi_addon_visualization_CB "other functions" | ||
| 174 | /// available in which the child class can ask about the current hardware, | ||
| 175 | /// including the device, display and several other parts. | ||
| 176 | /// | ||
| 177 | /// -------------------------------------------------------------------------- | ||
| 178 | /// | ||
| 179 | /// | ||
| 180 | /// **Here is an example of the minimum required code to start a visualization:** | ||
| 181 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 182 | /// #include <kodi/addon-instance/Visualization.h> | ||
| 183 | /// | ||
| 184 | /// class CMyVisualization : public kodi::addon::CAddonBase, | ||
| 185 | /// public kodi::addon::CInstanceVisualization | ||
| 186 | /// { | ||
| 187 | /// public: | ||
| 188 | /// CMyVisualization(); | ||
| 189 | /// | ||
| 190 | /// bool Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName) override; | ||
| 191 | /// void AudioData(const float* audioData, int audioDataLength, float* freqData, int freqDataLength) override; | ||
| 192 | /// void Render() override; | ||
| 193 | /// }; | ||
| 194 | /// | ||
| 195 | /// CMyVisualization::CMyVisualization() | ||
| 196 | /// { | ||
| 197 | /// ... | ||
| 198 | /// } | ||
| 199 | /// | ||
| 200 | /// bool CMyVisualization::Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName) | ||
| 201 | /// { | ||
| 202 | /// ... | ||
| 203 | /// return true; | ||
| 204 | /// } | ||
| 205 | /// | ||
| 206 | /// void CMyVisualization::AudioData(const float* audioData, int audioDataLength, float* freqData, int freqDataLength) | ||
| 207 | /// { | ||
| 208 | /// ... | ||
| 209 | /// } | ||
| 210 | /// | ||
| 211 | /// void CMyVisualization::Render() | ||
| 212 | /// { | ||
| 213 | /// ... | ||
| 214 | /// } | ||
| 215 | /// | ||
| 216 | /// ADDONCREATOR(CMyVisualization) | ||
| 217 | /// ~~~~~~~~~~~~~ | ||
| 218 | /// | ||
| 219 | /// | ||
| 220 | /// -------------------------------------------------------------------------- | ||
| 221 | /// | ||
| 222 | /// | ||
| 223 | /// **Here is another example where the visualization is used together with | ||
| 224 | /// other instance types:** | ||
| 225 | /// | ||
| 226 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 227 | /// #include <kodi/addon-instance/Visualization.h> | ||
| 228 | /// | ||
| 229 | /// class CMyVisualization : public ::kodi::addon::CInstanceVisualization | ||
| 230 | /// { | ||
| 231 | /// public: | ||
| 232 | /// CMyVisualization(KODI_HANDLE instance); | ||
| 233 | /// | ||
| 234 | /// bool Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName) override; | ||
| 235 | /// void AudioData(const float* audioData, int audioDataLength, float* freqData, int freqDataLength) override; | ||
| 236 | /// void Render() override; | ||
| 237 | /// }; | ||
| 238 | /// | ||
| 239 | /// CMyVisualization::CMyVisualization(KODI_HANDLE instance) | ||
| 240 | /// : CInstanceVisualization(instance) | ||
| 241 | /// { | ||
| 242 | /// ... | ||
| 243 | /// } | ||
| 244 | /// | ||
| 245 | /// bool CMyVisualization::Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName) | ||
| 246 | /// { | ||
| 247 | /// ... | ||
| 248 | /// return true; | ||
| 249 | /// } | ||
| 250 | /// | ||
| 251 | /// void CMyVisualization::AudioData(const float* audioData, int audioDataLength, float* freqData, int freqDataLength) | ||
| 252 | /// { | ||
| 253 | /// ... | ||
| 254 | /// } | ||
| 255 | /// | ||
| 256 | /// void CMyVisualization::Render() | ||
| 257 | /// { | ||
| 258 | /// ... | ||
| 259 | /// } | ||
| 260 | /// | ||
| 261 | /// | ||
| 262 | /// /*----------------------------------------------------------------------*/ | ||
| 263 | /// | ||
| 264 | /// class CMyAddon : public ::kodi::addon::CAddonBase | ||
| 265 | /// { | ||
| 266 | /// public: | ||
| 267 | /// CMyAddon() { } | ||
| 268 | /// ADDON_STATUS CreateInstance(int instanceType, | ||
| 269 | /// std::string instanceID, | ||
| 270 | /// KODI_HANDLE instance, | ||
| 271 | /// KODI_HANDLE& addonInstance) override; | ||
| 272 | /// }; | ||
| 273 | /// | ||
| 274 | /// /* If you use only one instance in your add-on, can be instanceType and | ||
| 275 | /// * instanceID ignored */ | ||
| 276 | /// ADDON_STATUS CMyAddon::CreateInstance(int instanceType, | ||
| 277 | /// std::string instanceID, | ||
| 278 | /// KODI_HANDLE instance, | ||
| 279 | /// KODI_HANDLE& addonInstance) | ||
| 280 | /// { | ||
| 281 | /// if (instanceType == ADDON_INSTANCE_VISUALIZATION) | ||
| 282 | /// { | ||
| 283 | /// kodi::Log(ADDON_LOG_NOTICE, "Creating my Visualization"); | ||
| 284 | /// addonInstance = new CMyVisualization(instance); | ||
| 285 | /// return ADDON_STATUS_OK; | ||
| 286 | /// } | ||
| 287 | /// else if (...) | ||
| 288 | /// { | ||
| 289 | /// ... | ||
| 290 | /// } | ||
| 291 | /// return ADDON_STATUS_UNKNOWN; | ||
| 292 | /// } | ||
| 293 | /// | ||
| 294 | /// ADDONCREATOR(CMyAddon) | ||
| 295 | /// ~~~~~~~~~~~~~ | ||
| 296 | /// | ||
| 297 | /// The destruction of the example class `CMyVisualization` is called from | ||
| 298 | /// Kodi's header. Manually deleting the add-on instance is not required. | ||
| 299 | /// | ||
| 300 | //---------------------------------------------------------------------------- | ||
| 301 | class ATTRIBUTE_HIDDEN CInstanceVisualization : public IAddonInstance | ||
| 302 | { | ||
| 303 | public: | ||
| 304 | //========================================================================== | ||
| 305 | /// | ||
| 306 | /// @ingroup cpp_kodi_addon_visualization | ||
| 307 | /// @brief Visualization class constructor | ||
| 308 | /// | ||
| 309 | /// Used by an add-on that only supports visualizations. | ||
| 310 | /// | ||
| 311 | CInstanceVisualization() | ||
| 312 | : IAddonInstance(ADDON_INSTANCE_VISUALIZATION, | ||
| 313 | GetKodiTypeVersion(ADDON_INSTANCE_VISUALIZATION)) | ||
| 314 | { | ||
| 315 | if (CAddonBase::m_interface->globalSingleInstance != nullptr) | ||
| 316 | throw std::logic_error("kodi::addon::CInstanceVisualization: Cannot create multiple instances of add-on."); | ||
| 317 | |||
| 318 | SetAddonStruct(CAddonBase::m_interface->firstKodiInstance); | ||
| 319 | CAddonBase::m_interface->globalSingleInstance = this; | ||
| 320 | } | ||
| 321 | //-------------------------------------------------------------------------- | ||
| 322 | |||
| 323 | //========================================================================== | ||
| 324 | /// | ||
| 325 | /// @ingroup cpp_kodi_addon_visualization | ||
| 326 | /// @brief Visualization class constructor used to support multiple instance | ||
| 327 | /// types | ||
| 328 | /// | ||
| 329 | /// @param[in] instance The instance value given to | ||
| 330 | /// <b>`kodi::addon::CAddonBase::CreateInstance(...)`</b>. | ||
| 331 | /// @param[in] kodiVersion [opt] Version used in Kodi for this instance, to | ||
| 332 | /// allow compatibility to older Kodi versions. | ||
| 333 | /// @note Recommended to set. | ||
| 334 | /// | ||
| 335 | /// @warning Only use `instance` from the CreateInstance call | ||
| 336 | /// | ||
| 337 | explicit CInstanceVisualization(KODI_HANDLE instance, const std::string& kodiVersion = "") | ||
| 338 | : IAddonInstance(ADDON_INSTANCE_VISUALIZATION, | ||
| 339 | !kodiVersion.empty() ? kodiVersion | ||
| 340 | : GetKodiTypeVersion(ADDON_INSTANCE_VISUALIZATION)) | ||
| 341 | { | ||
| 342 | if (CAddonBase::m_interface->globalSingleInstance != nullptr) | ||
| 343 | throw std::logic_error("kodi::addon::CInstanceVisualization: Creation of multiple together with single instance way is not allowed!"); | ||
| 344 | |||
| 345 | SetAddonStruct(instance); | ||
| 346 | } | ||
| 347 | //-------------------------------------------------------------------------- | ||
| 348 | |||
| 349 | //========================================================================== | ||
| 350 | /// | ||
| 351 | /// @ingroup cpp_kodi_addon_visualization | ||
| 352 | /// @brief Destructor | ||
| 353 | /// | ||
| 354 | ~CInstanceVisualization() override = default; | ||
| 355 | //-------------------------------------------------------------------------- | ||
| 356 | |||
| 357 | //========================================================================== | ||
| 358 | /// | ||
| 359 | /// @ingroup cpp_kodi_addon_visualization | ||
| 360 | /// @brief Used to notify the visualization that a new song has been started | ||
| 361 | /// | ||
| 362 | /// @param[in] channels Number of channels in the stream | ||
| 363 | /// @param[in] samplesPerSec Samples per second of stream | ||
| 364 | /// @param[in] bitsPerSample Number of bits in one sample | ||
| 365 | /// @param[in] songName The name of the currently-playing song | ||
| 366 | /// @return true if start successful done | ||
| 367 | /// | ||
| 368 | virtual bool Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName) { return true; } | ||
| 369 | //-------------------------------------------------------------------------- | ||
| 370 | |||
| 371 | //========================================================================== | ||
| 372 | /// | ||
| 373 | /// @ingroup cpp_kodi_addon_visualization | ||
| 374 | /// @brief Used to inform the visualization that the rendering control was | ||
| 375 | /// stopped | ||
| 376 | /// | ||
| 377 | virtual void Stop() {} | ||
| 378 | //-------------------------------------------------------------------------- | ||
| 379 | |||
| 380 | //========================================================================== | ||
| 381 | /// | ||
| 382 | /// @ingroup cpp_kodi_addon_visualization | ||
| 383 | /// @brief Pass audio data to the visualization | ||
| 384 | /// | ||
| 385 | /// @param[in] audioData The raw audio data | ||
| 386 | /// @param[in] audioDataLength Length of the audioData array | ||
| 387 | /// @param[in] freqData The [FFT](https://en.wikipedia.org/wiki/Fast_Fourier_transform) | ||
| 388 | /// of the audio data | ||
| 389 | /// @param[in] freqDataLength Length of frequency data array | ||
| 390 | /// | ||
| 391 | /// Values **freqData** and **freqDataLength** are used if GetInfo() returns | ||
| 392 | /// true for the `wantsFreq` parameter. Otherwise, **freqData** is set to | ||
| 393 | /// `nullptr` and **freqDataLength** is `0`. | ||
| 394 | /// | ||
| 395 | virtual void AudioData(const float* audioData, int audioDataLength, float* freqData, int freqDataLength) {} | ||
| 396 | //-------------------------------------------------------------------------- | ||
| 397 | |||
| 398 | //========================================================================== | ||
| 399 | /// | ||
| 400 | /// @ingroup cpp_kodi_addon_visualization | ||
| 401 | /// @brief Used to inform Kodi that the rendered region is dirty and need an | ||
| 402 | /// update | ||
| 403 | /// | ||
| 404 | /// @return True if dirty | ||
| 405 | /// | ||
| 406 | virtual bool IsDirty() { return true; } | ||
| 407 | //-------------------------------------------------------------------------- | ||
| 408 | |||
| 409 | //========================================================================== | ||
| 410 | /// | ||
| 411 | /// @ingroup cpp_kodi_addon_visualization | ||
| 412 | /// @brief Used to indicate when the add-on should render | ||
| 413 | /// | ||
| 414 | virtual void Render() {} | ||
| 415 | //-------------------------------------------------------------------------- | ||
| 416 | |||
| 417 | //========================================================================== | ||
| 418 | /// | ||
| 419 | /// @ingroup cpp_kodi_addon_visualization | ||
| 420 | /// @brief Used to get the number of buffers from the current visualization | ||
| 421 | /// | ||
| 422 | /// @param[out] wantsFreq Indicates whether the add-on wants FFT | ||
| 423 | /// data. If set to true, the **freqData** | ||
| 424 | /// and **freqDataLength** parameters of | ||
| 425 | /// AudioData() are used | ||
| 426 | /// @param[out] syncDelay The number of buffers to delay before | ||
| 427 | /// calling AudioData() | ||
| 428 | /// | ||
| 429 | /// @note If this function is not implemented, it will default to | ||
| 430 | /// `wantsFreq` = false and `syncDelay` = 0. | ||
| 431 | /// | ||
| 432 | virtual void GetInfo(bool& wantsFreq, int& syncDelay) { wantsFreq = false; syncDelay = 0; } | ||
| 433 | //-------------------------------------------------------------------------- | ||
| 434 | |||
| 435 | //========================================================================== | ||
| 436 | /// | ||
| 437 | /// @ingroup cpp_kodi_addon_visualization | ||
| 438 | /// @brief Used to get a list of visualization presets the user can select | ||
| 439 | /// from | ||
| 440 | /// | ||
| 441 | /// @param[out] presets The vector list containing the names of | ||
| 442 | /// presets that the user can select | ||
| 443 | /// @return Return true if successful, or false if | ||
| 444 | /// there are no presets to choose from | ||
| 445 | /// | ||
| 446 | virtual bool GetPresets(std::vector<std::string>& presets) { return false; } | ||
| 447 | //-------------------------------------------------------------------------- | ||
| 448 | |||
| 449 | //========================================================================== | ||
| 450 | /// | ||
| 451 | /// @ingroup cpp_kodi_addon_visualization | ||
| 452 | /// @brief Get the index of the current preset | ||
| 453 | /// | ||
| 454 | /// @return Index number of the current preset | ||
| 455 | /// | ||
| 456 | virtual int GetActivePreset() { return -1; } | ||
| 457 | //-------------------------------------------------------------------------- | ||
| 458 | |||
| 459 | //========================================================================== | ||
| 460 | /// | ||
| 461 | /// @ingroup cpp_kodi_addon_visualization | ||
| 462 | /// @brief Check if the add-on is locked to the current preset | ||
| 463 | /// | ||
| 464 | /// @return True if locked to the current preset | ||
| 465 | /// | ||
| 466 | virtual bool IsLocked() { return false; } | ||
| 467 | //-------------------------------------------------------------------------- | ||
| 468 | |||
| 469 | //========================================================================== | ||
| 470 | /// | ||
| 471 | /// @ingroup cpp_kodi_addon_visualization | ||
| 472 | /// @brief Load the previous visualization preset | ||
| 473 | /// | ||
| 474 | /// @return Return true if the previous preset was loaded | ||
| 475 | virtual bool PrevPreset() { return false; } | ||
| 476 | //-------------------------------------------------------------------------- | ||
| 477 | |||
| 478 | //========================================================================== | ||
| 479 | /// | ||
| 480 | /// @ingroup cpp_kodi_addon_visualization | ||
| 481 | /// @brief Load the next visualization preset | ||
| 482 | /// | ||
| 483 | /// @return Return true if the next preset was loaded | ||
| 484 | virtual bool NextPreset() { return false; } | ||
| 485 | //-------------------------------------------------------------------------- | ||
| 486 | |||
| 487 | //========================================================================== | ||
| 488 | /// | ||
| 489 | /// @ingroup cpp_kodi_addon_visualization | ||
| 490 | /// @brief Load a visualization preset | ||
| 491 | /// | ||
| 492 | /// This function is called after a new preset is selected. | ||
| 493 | /// | ||
| 494 | /// @param[in] select Preset index to use | ||
| 495 | /// @return Return true if the preset is loaded | ||
| 496 | virtual bool LoadPreset(int select) { return false; } | ||
| 497 | //-------------------------------------------------------------------------- | ||
| 498 | |||
| 499 | //========================================================================== | ||
| 500 | /// | ||
| 501 | /// @ingroup cpp_kodi_addon_visualization | ||
| 502 | /// @brief Switch to a new random preset | ||
| 503 | /// | ||
| 504 | /// @return Return true if a random preset was loaded | ||
| 505 | virtual bool RandomPreset() { return false; } | ||
| 506 | //-------------------------------------------------------------------------- | ||
| 507 | |||
| 508 | //========================================================================== | ||
| 509 | /// | ||
| 510 | /// @ingroup cpp_kodi_addon_visualization | ||
| 511 | /// @brief Lock the current visualization preset, preventing it from changing | ||
| 512 | /// | ||
| 513 | /// @param[in] lockUnlock If set to true, the preset should be locked | ||
| 514 | /// @return Return true if the current preset is locked | ||
| 515 | virtual bool LockPreset(bool lockUnlock) { return false; } | ||
| 516 | //-------------------------------------------------------------------------- | ||
| 517 | |||
| 518 | //========================================================================== | ||
| 519 | /// | ||
| 520 | /// @ingroup cpp_kodi_addon_visualization | ||
| 521 | /// @brief Used to increase/decrease the visualization preset rating | ||
| 522 | /// | ||
| 523 | /// @param[in] plusMinus If set to true the rating is increased, otherwise | ||
| 524 | /// decreased | ||
| 525 | /// @return Return true if the rating is modified | ||
| 526 | virtual bool RatePreset(bool plusMinus) { return false; } | ||
| 527 | //-------------------------------------------------------------------------- | ||
| 528 | |||
| 529 | //========================================================================== | ||
| 530 | /// | ||
| 531 | /// @ingroup cpp_kodi_addon_visualization | ||
| 532 | /// @brief Inform the visualization of the current album art image | ||
| 533 | /// | ||
| 534 | /// @param[in] albumart Path to the current album art image | ||
| 535 | /// @return Return true if the image is used | ||
| 536 | virtual bool UpdateAlbumart(std::string albumart) { return false; } | ||
| 537 | //-------------------------------------------------------------------------- | ||
| 538 | |||
| 539 | //========================================================================== | ||
| 540 | /// | ||
| 541 | /// @ingroup cpp_kodi_addon_visualization | ||
| 542 | /// @brief Inform the visualization of the current track's tag information | ||
| 543 | /// | ||
| 544 | /// @param[in] track Visualization track information structure | ||
| 545 | /// @return Return true if the track information is used | ||
| 546 | virtual bool UpdateTrack(const VisTrack &track) { return false; } | ||
| 547 | |||
| 548 | //========================================================================== | ||
| 549 | /// | ||
| 550 | /// \defgroup cpp_kodi_addon_visualization_CB Information functions | ||
| 551 | /// \ingroup cpp_kodi_addon_visualization | ||
| 552 | /// @brief **To get info about the device, display and several other parts** | ||
| 553 | /// | ||
| 554 | //@{ | ||
| 555 | |||
| 556 | //========================================================================== | ||
| 557 | /// | ||
| 558 | /// @ingroup cpp_kodi_addon_visualization_CB | ||
| 559 | /// @brief To transfer available presets on addon | ||
| 560 | /// | ||
| 561 | /// Used if @ref GetPresets not possible to use, e.g. where available presets | ||
| 562 | /// are only known during @ref Start call. | ||
| 563 | /// | ||
| 564 | /// @param[in] presets List to store available presets. | ||
| 565 | /// | ||
| 566 | /// @note The function should only be called once, if possible | ||
| 567 | /// | ||
| 568 | inline void TransferPresets(const std::vector<std::string>& presets) | ||
| 569 | { | ||
| 570 | m_instanceData->toKodi->clear_presets(m_instanceData->toKodi->kodiInstance); | ||
| 571 | for (auto it : presets) | ||
| 572 | m_instanceData->toKodi->transfer_preset(m_instanceData->toKodi->kodiInstance, it.c_str()); | ||
| 573 | } | ||
| 574 | //-------------------------------------------------------------------------- | ||
| 575 | |||
| 576 | //========================================================================== | ||
| 577 | /// | ||
| 578 | /// @ingroup cpp_kodi_addon_visualization_CB | ||
| 579 | /// @brief Device that represents the display adapter | ||
| 580 | /// | ||
| 581 | /// @return A pointer to the used device | ||
| 582 | /// | ||
| 583 | /// @note This is only available on **DirectX**, It us unused (`nullptr`) on | ||
| 584 | /// **OpenGL** | ||
| 585 | /// | ||
| 586 | inline void* Device() { return m_instanceData->props->device; } | ||
| 587 | //-------------------------------------------------------------------------- | ||
| 588 | |||
| 589 | //========================================================================== | ||
| 590 | /// | ||
| 591 | /// @ingroup cpp_kodi_addon_visualization_CB | ||
| 592 | /// @brief Returns the X position of the rendering window | ||
| 593 | /// | ||
| 594 | /// @return The X position, in pixels | ||
| 595 | /// | ||
| 596 | inline int X() { return m_instanceData->props->x; } | ||
| 597 | //-------------------------------------------------------------------------- | ||
| 598 | |||
| 599 | //========================================================================== | ||
| 600 | /// | ||
| 601 | /// @ingroup cpp_kodi_addon_visualization_CB | ||
| 602 | /// @brief Returns the Y position of the rendering window | ||
| 603 | /// | ||
| 604 | /// @return The Y position, in pixels | ||
| 605 | /// | ||
| 606 | inline int Y() { return m_instanceData->props->y; } | ||
| 607 | //-------------------------------------------------------------------------- | ||
| 608 | |||
| 609 | //========================================================================== | ||
| 610 | /// | ||
| 611 | /// @ingroup cpp_kodi_addon_visualization_CB | ||
| 612 | /// @brief Returns the width of the rendering window | ||
| 613 | /// | ||
| 614 | /// @return The width, in pixels | ||
| 615 | /// | ||
| 616 | inline int Width() { return m_instanceData->props->width; } | ||
| 617 | //-------------------------------------------------------------------------- | ||
| 618 | |||
| 619 | //========================================================================== | ||
| 620 | /// | ||
| 621 | /// @ingroup cpp_kodi_addon_visualization_CB | ||
| 622 | /// @brief Returns the height of the rendering window | ||
| 623 | /// | ||
| 624 | /// @return The height, in pixels | ||
| 625 | /// | ||
| 626 | inline int Height() { return m_instanceData->props->height; } | ||
| 627 | //-------------------------------------------------------------------------- | ||
| 628 | |||
| 629 | //========================================================================== | ||
| 630 | /// | ||
| 631 | /// @ingroup cpp_kodi_addon_visualization_CB | ||
| 632 | /// @brief Pixel aspect ratio (often abbreviated PAR) is a ratio that | ||
| 633 | /// describes how the width of a pixel compares to the height of that pixel. | ||
| 634 | /// | ||
| 635 | /// @return The pixel aspect ratio used by the display | ||
| 636 | /// | ||
| 637 | inline float PixelRatio() { return m_instanceData->props->pixelRatio; } | ||
| 638 | //-------------------------------------------------------------------------- | ||
| 639 | |||
| 640 | //========================================================================== | ||
| 641 | /// | ||
| 642 | /// @ingroup cpp_kodi_addon_visualization_CB | ||
| 643 | /// @brief Used to get the name of the add-on defined in `addon.xml` | ||
| 644 | /// | ||
| 645 | /// @return The add-on name | ||
| 646 | /// | ||
| 647 | inline std::string Name() { return m_instanceData->props->name; } | ||
| 648 | //-------------------------------------------------------------------------- | ||
| 649 | |||
| 650 | //========================================================================== | ||
| 651 | /// | ||
| 652 | /// @ingroup cpp_kodi_addon_visualization_CB | ||
| 653 | /// @brief Used to get the full path where the add-on is installed | ||
| 654 | /// | ||
| 655 | /// @return The add-on installation path | ||
| 656 | /// | ||
| 657 | inline std::string Presets() { return m_instanceData->props->presets; } | ||
| 658 | //-------------------------------------------------------------------------- | ||
| 659 | |||
| 660 | //========================================================================== | ||
| 661 | /// | ||
| 662 | /// @ingroup cpp_kodi_addon_visualization_CB | ||
| 663 | /// @brief Used to get the full path to the add-on's user profile | ||
| 664 | /// | ||
| 665 | /// @note The trailing folder (consisting of the add-on's ID) is not created | ||
| 666 | /// by default. If it is needed, you must call kodi::vfs::CreateDirectory() | ||
| 667 | /// to create the folder. | ||
| 668 | /// | ||
| 669 | /// @return Path to the user profile | ||
| 670 | /// | ||
| 671 | inline std::string Profile() { return m_instanceData->props->profile; } | ||
| 672 | //-------------------------------------------------------------------------- | ||
| 673 | //@} | ||
| 674 | |||
| 675 | private: | ||
| 676 | void SetAddonStruct(KODI_HANDLE instance) | ||
| 677 | { | ||
| 678 | if (instance == nullptr) | ||
| 679 | throw std::logic_error("kodi::addon::CInstanceVisualization: Null pointer instance passed."); | ||
| 680 | |||
| 681 | m_instanceData = static_cast<AddonInstance_Visualization*>(instance); | ||
| 682 | m_instanceData->toAddon->addonInstance = this; | ||
| 683 | m_instanceData->toAddon->start = ADDON_Start; | ||
| 684 | m_instanceData->toAddon->stop = ADDON_Stop; | ||
| 685 | m_instanceData->toAddon->audio_data = ADDON_AudioData; | ||
| 686 | m_instanceData->toAddon->is_dirty = ADDON_IsDirty; | ||
| 687 | m_instanceData->toAddon->render = ADDON_Render; | ||
| 688 | m_instanceData->toAddon->get_info = ADDON_GetInfo; | ||
| 689 | m_instanceData->toAddon->on_action = ADDON_OnAction; | ||
| 690 | m_instanceData->toAddon->get_presets = ADDON_GetPresets; | ||
| 691 | m_instanceData->toAddon->get_active_preset = ADDON_GetActivePreset; | ||
| 692 | m_instanceData->toAddon->is_locked = ADDON_IsLocked; | ||
| 693 | } | ||
| 694 | |||
| 695 | inline static bool ADDON_Start(const AddonInstance_Visualization* addon, int channels, int samplesPerSec, int bitsPerSample, const char* songName) | ||
| 696 | { | ||
| 697 | addon->toAddon->addonInstance->m_renderHelper = kodi::gui::GetRenderHelper(); | ||
| 698 | return addon->toAddon->addonInstance->Start(channels, samplesPerSec, bitsPerSample, songName); | ||
| 699 | } | ||
| 700 | |||
| 701 | inline static void ADDON_Stop(const AddonInstance_Visualization* addon) | ||
| 702 | { | ||
| 703 | addon->toAddon->addonInstance->Stop(); | ||
| 704 | addon->toAddon->addonInstance->m_renderHelper = nullptr; | ||
| 705 | } | ||
| 706 | |||
| 707 | inline static void ADDON_AudioData(const AddonInstance_Visualization* addon, const float* audioData, int audioDataLength, float *freqData, int freqDataLength) | ||
| 708 | { | ||
| 709 | addon->toAddon->addonInstance->AudioData(audioData, audioDataLength, freqData, freqDataLength); | ||
| 710 | } | ||
| 711 | |||
| 712 | inline static bool ADDON_IsDirty(const AddonInstance_Visualization* addon) | ||
| 713 | { | ||
| 714 | return addon->toAddon->addonInstance->IsDirty(); | ||
| 715 | } | ||
| 716 | |||
| 717 | inline static void ADDON_Render(const AddonInstance_Visualization* addon) | ||
| 718 | { | ||
| 719 | if (!addon->toAddon->addonInstance->m_renderHelper) | ||
| 720 | return; | ||
| 721 | addon->toAddon->addonInstance->m_renderHelper->Begin(); | ||
| 722 | addon->toAddon->addonInstance->Render(); | ||
| 723 | addon->toAddon->addonInstance->m_renderHelper->End(); | ||
| 724 | } | ||
| 725 | |||
| 726 | inline static void ADDON_GetInfo(const AddonInstance_Visualization* addon, VIS_INFO *info) | ||
| 727 | { | ||
| 728 | addon->toAddon->addonInstance->GetInfo(info->bWantsFreq, info->iSyncDelay); | ||
| 729 | } | ||
| 730 | |||
| 731 | inline static bool ADDON_OnAction(const AddonInstance_Visualization* addon, VIS_ACTION action, const void *param) | ||
| 732 | { | ||
| 733 | switch (action) | ||
| 734 | { | ||
| 735 | case VIS_ACTION_NEXT_PRESET: | ||
| 736 | return addon->toAddon->addonInstance->NextPreset(); | ||
| 737 | case VIS_ACTION_PREV_PRESET: | ||
| 738 | return addon->toAddon->addonInstance->PrevPreset(); | ||
| 739 | case VIS_ACTION_LOAD_PRESET: | ||
| 740 | return addon->toAddon->addonInstance->LoadPreset(*static_cast<const int*>(param)); | ||
| 741 | case VIS_ACTION_RANDOM_PRESET: | ||
| 742 | return addon->toAddon->addonInstance->RandomPreset(); | ||
| 743 | case VIS_ACTION_LOCK_PRESET: | ||
| 744 | addon->toAddon->addonInstance->m_presetLockedByUser = !addon->toAddon->addonInstance->m_presetLockedByUser; | ||
| 745 | return addon->toAddon->addonInstance->LockPreset(addon->toAddon->addonInstance->m_presetLockedByUser); | ||
| 746 | case VIS_ACTION_RATE_PRESET_PLUS: | ||
| 747 | return addon->toAddon->addonInstance->RatePreset(true); | ||
| 748 | case VIS_ACTION_RATE_PRESET_MINUS: | ||
| 749 | return addon->toAddon->addonInstance->RatePreset(false); | ||
| 750 | case VIS_ACTION_UPDATE_ALBUMART: | ||
| 751 | return addon->toAddon->addonInstance->UpdateAlbumart(static_cast<const char*>(param)); | ||
| 752 | case VIS_ACTION_UPDATE_TRACK: | ||
| 753 | return addon->toAddon->addonInstance->UpdateTrack(*static_cast<const VisTrack*>(param)); | ||
| 754 | case VIS_ACTION_NONE: | ||
| 755 | default: | ||
| 756 | break; | ||
| 757 | } | ||
| 758 | return false; | ||
| 759 | } | ||
| 760 | |||
| 761 | inline static unsigned int ADDON_GetPresets(const AddonInstance_Visualization* addon) | ||
| 762 | { | ||
| 763 | std::vector<std::string> presets; | ||
| 764 | if (addon->toAddon->addonInstance->GetPresets(presets)) | ||
| 765 | { | ||
| 766 | for (auto it : presets) | ||
| 767 | addon->toAddon->addonInstance->m_instanceData->toKodi->transfer_preset(addon->toKodi->kodiInstance, it.c_str()); | ||
| 768 | } | ||
| 769 | |||
| 770 | return static_cast<unsigned int>(presets.size()); | ||
| 771 | } | ||
| 772 | |||
| 773 | inline static int ADDON_GetActivePreset(const AddonInstance_Visualization* addon) | ||
| 774 | { | ||
| 775 | return addon->toAddon->addonInstance->GetActivePreset(); | ||
| 776 | } | ||
| 777 | |||
| 778 | inline static bool ADDON_IsLocked(const AddonInstance_Visualization* addon) | ||
| 779 | { | ||
| 780 | return addon->toAddon->addonInstance->IsLocked(); | ||
| 781 | } | ||
| 782 | |||
| 783 | std::shared_ptr<kodi::gui::IRenderHelper> m_renderHelper; | ||
| 784 | bool m_presetLockedByUser = false; | ||
| 785 | AddonInstance_Visualization* m_instanceData; | ||
| 786 | }; | ||
| 787 | |||
| 788 | } /* namespace addon */ | ||
| 789 | } /* namespace kodi */ | ||
