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