summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Visualization.h
blob: 452085a52880f2fc1ce7500f7c1d6cf704d9fbf1 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
#pragma once
/*
 *      Copyright (C) 2005-2017 Team Kodi
 *      http://kodi.tv
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Kodi; see the file COPYING.  If not, see
 *  <http://www.gnu.org/licenses/>.
 *
 */

/*
 * Parts with a comment named "internal" are only used inside header and not
 * used or accessed direct during add-on development!
 */

#include "../AddonBase.h"

namespace kodi { namespace addon { class CInstanceVisualization; }}

extern "C"
{

struct AddonInstance_Visualization;

typedef enum VIS_ACTION : unsigned int /* internal */
{ 
  VIS_ACTION_NONE = 0,
  VIS_ACTION_NEXT_PRESET,
  VIS_ACTION_PREV_PRESET,
  VIS_ACTION_LOAD_PRESET,
  VIS_ACTION_RANDOM_PRESET,
  VIS_ACTION_LOCK_PRESET,
  VIS_ACTION_RATE_PRESET_PLUS,
  VIS_ACTION_RATE_PRESET_MINUS,
  VIS_ACTION_UPDATE_ALBUMART,
  VIS_ACTION_UPDATE_TRACK
} VIS_ACTION;

struct VIS_INFO /* internal */
{
  bool bWantsFreq;
  int iSyncDelay;
};

typedef struct AddonProps_Visualization /* internal */
{
  void *device;
  int x;
  int y;
  int width;
  int height;
  float pixelRatio;
  const char *name;
  const char *presets;
  const char *profile;
} AddonProps_Visualization;

typedef struct AddonToKodiFuncTable_Visualization /* internal */
{
  KODI_HANDLE kodiInstance;
  void (__cdecl* transfer_preset) (void* kodiInstance, const char* preset);
} AddonToKodiFuncTable_Visualization;

typedef struct KodiToAddonFuncTable_Visualization /* internal */
{
  kodi::addon::CInstanceVisualization* addonInstance;
  bool (__cdecl* start)(const AddonInstance_Visualization* instance, int channels, int samples_per_sec, int bits_per_sample, const char* song_name);
  void (__cdecl* stop)(const AddonInstance_Visualization* instance);
  void (__cdecl* audio_data)(const AddonInstance_Visualization* instance, const float* audio_data, int audio_data_length, float *freq_data, int freq_data_length);
  bool (__cdecl* is_dirty)(const AddonInstance_Visualization* instance);
  void (__cdecl* render)(const AddonInstance_Visualization* instance);
  void (__cdecl* get_info)(const AddonInstance_Visualization* instance, VIS_INFO *info);
  bool (__cdecl* on_action)(const AddonInstance_Visualization* instance, VIS_ACTION action, const void *param);
  unsigned int (__cdecl *get_presets)(const AddonInstance_Visualization* instance);
  int (__cdecl *get_active_preset)(const AddonInstance_Visualization* instance);
  bool (__cdecl* is_locked)(const AddonInstance_Visualization* instance);
} KodiToAddonFuncTable_Visualization;

typedef struct AddonInstance_Visualization /* internal */
{
  AddonProps_Visualization props;
  AddonToKodiFuncTable_Visualization toKodi;
  KodiToAddonFuncTable_Visualization toAddon;
} AddonInstance_Visualization;

//============================================================================
/// \defgroup cpp_kodi_addon_visualization_VisTrack class VisTrack
/// \ingroup cpp_kodi_addon_visualization
/// @brief **Visualization track information structure**
///
/// Called from kodi::addon::CInstanceVisualization::UpdateTrack() with the
/// information of the currently-playing song.
///
//@{
struct VisTrack
{
  /// @brief Title of the current song.
  const char *title;

  /// @brief Artist names, as a single string
  const char *artist;

  /// @brief Album that the current song is from.
  const char *album;

  /// @brief Album artist names, as a single string
  const char *albumArtist;

  /// @brief The genre name from the music tag, if present.
  const char *genre;

  /// @brief Comment of the current song stored in the ID tag info.
  const char *comment;

  /// @brief Lyrics of the current song, if available.
  const char *lyrics;

  const char *reserved1;
  const char *reserved2;

  /// @brief Track number of the current song.
  int trackNumber;

  /// @brief Disc number of the current song stored in the ID tag info.
  int discNumber;

  /// @brief Duration of the current song, in seconds.
  int duration;

  /// @brief Year that the current song was released.
  int year;

  /// @brief The user-defined rating of the current song.
  int rating;

  int reserved3;
  int reserved4;
};
//@}
//----------------------------------------------------------------------------

} /* extern "C" */

namespace kodi
{
namespace addon
{

  //============================================================================
  ///
  /// \addtogroup cpp_kodi_addon_visualization
  /// @brief \cpp_class{ kodi::addon::CInstanceVisualization }
  /// **Visualization add-on instance**
  ///
  /// [Music visualization](https://en.wikipedia.org/wiki/Music_visualization),
  /// or music visualisation, is a feature in Kodi that generates animated
  /// imagery based on a piece of music. The imagery is usually generated and
  /// rendered in real time synchronized to the music.
  ///
  /// Visualization techniques range from simple ones (e.g., a simulation of an
  /// oscilloscope display) to elaborate ones, which often include a plurality
  /// of composited effects. The changes in the music's loudness and frequency
  /// spectrum are among the properties used as input to the visualization.
  ///
  /// Include the header \ref Visualization.h "#include <kodi/addon-instance/Visualization.h>"
  /// to use this class.
  ///
  /// This interface allows the creation of visualizations for Kodi, based upon
  /// **DirectX** or/and **OpenGL** rendering with `C++` code.
  ///
  /// Additionally, there are several \ref cpp_kodi_addon_visualization_CB "other functions"
  /// available in which the child class can ask about the current hardware,
  /// including the device, display and several other parts.
  ///
  /// --------------------------------------------------------------------------
  ///
  ///
  /// **Here is an example of the minimum required code to start a visualization:**
  /// ~~~~~~~~~~~~~{.cpp}
  /// #include <kodi/addon-instance/Visualization.h>
  ///
  /// class CMyVisualization : public kodi::addon::CAddonBase,
  ///                          public kodi::addon::CInstanceVisualization
  /// {
  /// public:
  ///   CMyVisualization();
  ///
  ///   bool Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName) override;
  ///   void AudioData(const float* audioData, int audioDataLength, float* freqData, int freqDataLength) override;
  ///   void Render() override;
  /// };
  ///
  /// CMyVisualization::CMyVisualization()
  /// {
  ///   ...
  /// }
  ///
  /// bool CMyVisualization::Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName)
  /// {
  ///   ...
  ///   return true;
  /// }
  ///
  /// void CMyVisualization::AudioData(const float* audioData, int audioDataLength, float* freqData, int freqDataLength)
  /// {
  ///   ...
  /// }
  ///
  /// void CMyVisualization::Render()
  /// {
  ///   ...
  /// }
  ///
  /// ADDONCREATOR(CMyVisualization)
  /// ~~~~~~~~~~~~~
  ///
  ///
  /// --------------------------------------------------------------------------
  ///
  ///
  /// **Here is another example where the visualization is used together with
  /// other instance types:**
  ///
  /// ~~~~~~~~~~~~~{.cpp}
  /// #include <kodi/addon-instance/Visualization.h>
  ///
  /// class CMyVisualization : public ::kodi::addon::CInstanceVisualization
  /// {
  /// public:
  ///   CMyVisualization(KODI_HANDLE instance);
  ///
  ///   bool Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName) override;
  ///   void AudioData(const float* audioData, int audioDataLength, float* freqData, int freqDataLength) override;
  ///   void Render() override;
  /// };
  ///
  /// CMyVisualization::CMyVisualization(KODI_HANDLE instance)
  ///   : CInstanceVisualization(instance)
  /// {
  ///   ...
  /// }
  ///
  /// bool CMyVisualization::Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName)
  /// {
  ///   ...
  ///   return true;
  /// }
  ///
  /// void CMyVisualization::AudioData(const float* audioData, int audioDataLength, float* freqData, int freqDataLength)
  /// {
  ///   ...
  /// }
  ///
  /// void CMyVisualization::Render()
  /// {
  ///   ...
  /// }
  ///
  ///
  /// /*----------------------------------------------------------------------*/
  ///
  /// class CMyAddon : public ::kodi::addon::CAddonBase
  /// {
  /// public:
  ///   CMyAddon() { }
  ///   ADDON_STATUS CreateInstance(int instanceType,
  ///                               std::string instanceID,
  ///                               KODI_HANDLE instance,
  ///                               KODI_HANDLE& addonInstance) override;
  /// };
  ///
  /// /* If you use only one instance in your add-on, can be instanceType and
  ///  * instanceID ignored */
  /// ADDON_STATUS CMyAddon::CreateInstance(int instanceType,
  ///                                       std::string instanceID,
  ///                                       KODI_HANDLE instance,
  ///                                       KODI_HANDLE& addonInstance)
  /// {
  ///   if (instanceType == ADDON_INSTANCE_VISUALIZATION)
  ///   {
  ///     kodi::Log(ADDON_LOG_NOTICE, "Creating my Visualization");
  ///     addonInstance = new CMyVisualization(instance);
  ///     return ADDON_STATUS_OK;
  ///   }
  ///   else if (...)
  ///   {
  ///     ...
  ///   }
  ///   return ADDON_STATUS_UNKNOWN;
  /// }
  ///
  /// ADDONCREATOR(CMyAddon)
  /// ~~~~~~~~~~~~~
  ///
  /// The destruction of the example class `CMyVisualization` is called from
  /// Kodi's header. Manually deleting the add-on instance is not required.
  ///
  //----------------------------------------------------------------------------
  class CInstanceVisualization : public IAddonInstance
  {
  public:
    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Visualization class constructor
    ///
    /// Used by an add-on that only supports visualizations.
    ///
    CInstanceVisualization()
      : IAddonInstance(ADDON_INSTANCE_VISUALIZATION),
        m_presetLockedByUser(false)
    {
      if (CAddonBase::m_interface->globalSingleInstance != nullptr)
        throw std::logic_error("kodi::addon::CInstanceVisualization: Cannot create multiple instances of add-on.");

      SetAddonStruct(CAddonBase::m_interface->firstKodiInstance);
      CAddonBase::m_interface->globalSingleInstance = this;
    }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Visualization class constructor used to support multiple instance
    /// types
    ///
    /// @param[in] instance               The instance value given to
    ///                                   <b>`kodi::addon::CAddonBase::CreateInstance(...)`</b>.
    ///
    /// @warning Only use `instance` from the CreateInstance call
    ///
    explicit CInstanceVisualization(KODI_HANDLE instance)
      : IAddonInstance(ADDON_INSTANCE_VISUALIZATION),
        m_presetLockedByUser(false)
    {
      if (CAddonBase::m_interface->globalSingleInstance != nullptr)
        throw std::logic_error("kodi::addon::CInstanceVisualization: Creation of multiple together with single instance way is not allowed!");

      SetAddonStruct(instance);
    }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Destructor
    ///
    ~CInstanceVisualization() override = default;
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Used to notify the visualization that a new song has been started
    ///
    /// @param[in] channels             Number of channels in the stream
    /// @param[in] samplesPerSec        Samples per second of stream
    /// @param[in] bitsPerSample        Number of bits in one sample
    /// @param[in] songName             The name of the currently-playing song
    /// @return                         true if start successful done
    ///
    virtual bool Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName) { return true; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Used to inform the visualization that the rendering control was
    /// stopped
    ///
    virtual void Stop() {}
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Pass audio data to the visualization
    ///
    /// @param[in] audioData            The raw audio data
    /// @param[in] audioDataLength      Length of the audioData array
    /// @param[in] freqData             The [FFT](https://en.wikipedia.org/wiki/Fast_Fourier_transform)
    ///                                 of the audio data
    /// @param[in] freqDataLength       Length of frequency data array
    ///
    /// Values **freqData** and **freqDataLength** are used if GetInfo() returns
    /// true for the `wantsFreq` parameter. Otherwise, **freqData** is set to
    /// `nullptr` and **freqDataLength** is `0`.
    ///
    virtual void AudioData(const float* audioData, int audioDataLength, float* freqData, int freqDataLength) {}
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Used to inform Kodi that the rendered region is dirty and need an
    /// update
    ///
    /// @return True if dirty
    ///
    virtual bool IsDirty() { return true; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Used to indicate when the add-on should render
    ///
    virtual void Render() {}
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Used to get the number of buffers from the current visualization
    ///
    /// @param[out] wantsFreq           Indicates whether the add-on wants FFT
    ///                                 data. If set to true, the **freqData**
    ///                                 and **freqDataLength** parameters of
    ///                                 AudioData() are used
    /// @param[out] syncDelay           The number of buffers to delay before
    ///                                 calling AudioData()
    ///
    /// @note If this function is not implemented, it will default to
    /// `wantsFreq` = false and `syncDelay` = 0.
    ///
    virtual void GetInfo(bool& wantsFreq, int& syncDelay) { wantsFreq = false; syncDelay = 0; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Used to get a list of visualization presets the user can select
    /// from
    ///
    /// @param[out] presets             The vector list containing the names of
    ///                                 presets that the user can select
    /// @return                         Return true if successful, or false if
    ///                                 there are no presets to choose from
    ///
    virtual bool GetPresets(std::vector<std::string>& presets) { return false; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Get the index of the current preset
    ///
    /// @return                         Index number of the current preset
    ///
    virtual int GetActivePreset() { return -1; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Check if the add-on is locked to the current preset
    ///
    /// @return                         True if locked to the current preset
    ///
    virtual bool IsLocked() { return false; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Load the previous visualization preset
    ///
    /// @return                 Return true if the previous preset was loaded
    virtual bool PrevPreset() { return false; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Load the next visualization preset
    ///
    /// @return                 Return true if the next preset was loaded
    virtual bool NextPreset() { return false; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Load a visualization preset
    ///
    /// This function is called after a new preset is selected.
    ///
    /// @param[in] select       Preset index to use
    /// @return                 Return true if the preset is loaded
    virtual bool LoadPreset(int select) { return false; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Switch to a new random preset
    ///
    /// @return                 Return true if a random preset was loaded
    virtual bool RandomPreset() { return false; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Lock the current visualization preset, preventing it from changing
    ///
    /// @param[in] lockUnlock   If set to true, the preset should be locked
    /// @return                 Return true if the current preset is locked
    virtual bool LockPreset(bool lockUnlock) { return false; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Used to increase/decrease the visualization preset rating
    ///
    /// @param[in] plusMinus    If set to true the rating is increased, otherwise
    ///                         decreased
    /// @return                 Return true if the rating is modified
    virtual bool RatePreset(bool plusMinus) { return false; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Inform the visualization of the current album art image
    ///
    /// @param[in] albumart     Path to the current album art image
    /// @return                 Return true if the image is used
    virtual bool UpdateAlbumart(std::string albumart) { return false; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization
    /// @brief Inform the visualization of the current track's tag information
    ///
    /// @param[in] track        Visualization track information structure
    /// @return                 Return true if the track information is used
    virtual bool UpdateTrack(const VisTrack &track) { return false; }

    //==========================================================================
    ///
    /// \defgroup cpp_kodi_addon_visualization_CB Information functions
    /// \ingroup cpp_kodi_addon_visualization
    /// @brief **To get info about the device, display and several other parts**
    ///
    //@{

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization_CB
    /// @brief Device that represents the display adapter
    ///
    /// @return A pointer to the used device
    ///
    /// @note This is only available on **DirectX**, It us unused (`nullptr`) on
    /// **OpenGL**
    ///
    inline void* Device() { return m_instanceData->props.device; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization_CB
    /// @brief Returns the X position of the rendering window
    ///
    /// @return The X position, in pixels
    ///
    inline int X() { return m_instanceData->props.x; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization_CB
    /// @brief Returns the Y position of the rendering window
    ///
    /// @return The Y position, in pixels
    ///
    inline int Y() { return m_instanceData->props.y; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization_CB
    /// @brief Returns the width of the rendering window
    ///
    /// @return The width, in pixels
    ///
    inline int Width() { return m_instanceData->props.width; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization_CB
    /// @brief Returns the height of the rendering window
    ///
    /// @return The height, in pixels
    ///
    inline int Height() { return m_instanceData->props.height; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization_CB
    /// @brief Pixel aspect ratio (often abbreviated PAR) is a ratio that
    /// describes how the width of a pixel compares to the height of that pixel.
    ///
    /// @return The pixel aspect ratio used by the display
    ///
    inline float PixelRatio() { return m_instanceData->props.pixelRatio; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization_CB
    /// @brief Used to get the name of the add-on defined in `addon.xml`
    ///
    /// @return The add-on name
    ///
    inline std::string Name() { return m_instanceData->props.name; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization_CB
    /// @brief Used to get the full path where the add-on is installed
    ///
    /// @return The add-on installation path
    ///
    inline std::string Presets() { return m_instanceData->props.presets; }
    //--------------------------------------------------------------------------

    //==========================================================================
    ///
    /// @ingroup cpp_kodi_addon_visualization_CB
    /// @brief Used to get the full path to the add-on's user profile
    ///
    /// @note The trailing folder (consisting of the add-on's ID) is not created
    /// by default. If it is needed, you must call kodi::vfs::CreateDirectory()
    /// to create the folder.
    ///
    /// @return Path to the user profile
    ///
    inline std::string Profile() { return m_instanceData->props.profile; }
    //--------------------------------------------------------------------------
    //@}

  private:
    void SetAddonStruct(KODI_HANDLE instance)
    {
      if (instance == nullptr)
        throw std::logic_error("kodi::addon::CInstanceVisualization: Null pointer instance passed.");

      m_instanceData = static_cast<AddonInstance_Visualization*>(instance);
      m_instanceData->toAddon.addonInstance = this;
      m_instanceData->toAddon.start = ADDON_Start;
      m_instanceData->toAddon.stop = ADDON_Stop;
      m_instanceData->toAddon.audio_data = ADDON_AudioData;
      m_instanceData->toAddon.render = ADDON_Render;
      m_instanceData->toAddon.get_info = ADDON_GetInfo;
      m_instanceData->toAddon.on_action = ADDON_OnAction;
      m_instanceData->toAddon.get_presets = ADDON_GetPresets;
      m_instanceData->toAddon.get_active_preset = ADDON_GetActivePreset;
      m_instanceData->toAddon.is_locked = ADDON_IsLocked;
    }

    inline static bool ADDON_Start(const AddonInstance_Visualization* addon, int channels, int samplesPerSec, int bitsPerSample, const char* songName)
    {
      return addon->toAddon.addonInstance->Start(channels, samplesPerSec, bitsPerSample, songName);
    }

    inline static void ADDON_Stop(const AddonInstance_Visualization* addon)
    {
      addon->toAddon.addonInstance->Stop();
    }

    inline static void ADDON_AudioData(const AddonInstance_Visualization* addon, const float* audioData, int audioDataLength, float *freqData, int freqDataLength)
    {
      addon->toAddon.addonInstance->AudioData(audioData, audioDataLength, freqData, freqDataLength);
    }
    
    inline static bool ADDON_IsDirty(const AddonInstance_Visualization* addon)
    {
      return addon->toAddon.addonInstance->IsDirty();
    }

    inline static void ADDON_Render(const AddonInstance_Visualization* addon)
    {
      addon->toAddon.addonInstance->Render();
    }

    inline static void ADDON_GetInfo(const AddonInstance_Visualization* addon, VIS_INFO *info)
    {
      addon->toAddon.addonInstance->GetInfo(info->bWantsFreq, info->iSyncDelay);
    }

    inline static bool ADDON_OnAction(const AddonInstance_Visualization* addon, VIS_ACTION action, const void *param)
    {
      switch (action)
      {
        case VIS_ACTION_NEXT_PRESET:
          return addon->toAddon.addonInstance->NextPreset();
        case VIS_ACTION_PREV_PRESET:
          return addon->toAddon.addonInstance->PrevPreset();
        case VIS_ACTION_LOAD_PRESET:
          return addon->toAddon.addonInstance->LoadPreset(*static_cast<const int*>(param));
        case VIS_ACTION_RANDOM_PRESET:
          return addon->toAddon.addonInstance->RandomPreset();
        case VIS_ACTION_LOCK_PRESET:
          addon->toAddon.addonInstance->m_presetLockedByUser = !addon->toAddon.addonInstance->m_presetLockedByUser;
          return addon->toAddon.addonInstance->LockPreset(addon->toAddon.addonInstance->m_presetLockedByUser);
        case VIS_ACTION_RATE_PRESET_PLUS:
          return addon->toAddon.addonInstance->RatePreset(true);
        case VIS_ACTION_RATE_PRESET_MINUS:
          return addon->toAddon.addonInstance->RatePreset(false);
        case VIS_ACTION_UPDATE_ALBUMART:
          return addon->toAddon.addonInstance->UpdateAlbumart(static_cast<const char*>(param));
        case VIS_ACTION_UPDATE_TRACK:
          return addon->toAddon.addonInstance->UpdateTrack(*static_cast<const VisTrack*>(param));
        case VIS_ACTION_NONE:
        default:
          break;
      }
      return false;
    }

    inline static unsigned int ADDON_GetPresets(const AddonInstance_Visualization* addon)
    {
      std::vector<std::string> presets;
      if (addon->toAddon.addonInstance->GetPresets(presets))
      {
        for (auto it : presets)
          addon->toAddon.addonInstance->m_instanceData->toKodi.transfer_preset(addon->toKodi.kodiInstance, it.c_str());
      }

      return presets.size();
    }

    inline static int ADDON_GetActivePreset(const AddonInstance_Visualization* addon)
    {
      return addon->toAddon.addonInstance->GetActivePreset();
    }

    inline static bool ADDON_IsLocked(const AddonInstance_Visualization* addon)
    {
      return addon->toAddon.addonInstance->IsLocked();
    }

    bool m_presetLockedByUser;
    AddonInstance_Visualization* m_instanceData;
  };

} /* namespace addon */
} /* namespace kodi */