11#include "../AddonBase.h"
12#include "../c-api/addon-instance/visualization.h"
13#include "../gui/renderHelper.h"
54 m_title = right.m_title;
55 m_artist = right.m_artist;
56 m_album = right.m_album;
57 m_albumArtist = right.m_albumArtist;
58 m_genre = right.m_genre;
59 m_comment = right.m_comment;
60 m_lyrics = right.m_lyrics;
62 m_trackNumber = right.m_trackNumber;
63 m_discNumber = right.m_discNumber;
64 m_duration = right.m_duration;
65 m_year = right.m_year;
66 m_rating = right.m_rating;
95 void SetTitle(
const std::string& title) { m_title = title; }
98 const std::string&
GetTitle()
const {
return m_title; }
101 void SetArtist(
const std::string& artist) { m_artist = artist; }
104 const std::string&
GetArtist()
const {
return m_artist; }
107 void SetAlbum(
const std::string& album) { m_album = album; }
110 const std::string&
GetAlbum()
const {
return m_album; }
113 void SetAlbumArtist(
const std::string& albumArtist) { m_albumArtist = albumArtist; }
119 void SetGenre(
const std::string& genre) { m_genre = genre; }
122 const std::string&
GetGenre()
const {
return m_genre; }
131 void SetTrack(
int trackNumber) { m_trackNumber = trackNumber; }
137 void SetDisc(
int discNumber) { m_discNumber = discNumber; }
149 void SetLyrics(
const std::string& lyrics) { m_lyrics = lyrics; }
152 const std::string&
GetLyrics()
const {
return m_lyrics; }
161 void SetComment(
const std::string& comment) { m_comment = comment; }
174 m_title = tag->title ? tag->title :
"";
175 m_artist = tag->artist ? tag->artist :
"";
176 m_album = tag->album ? tag->album :
"";
177 m_albumArtist = tag->albumArtist ? tag->albumArtist :
"";
178 m_genre = tag->genre ? tag->genre :
"";
179 m_comment = tag->comment ? tag->comment :
"";
180 m_lyrics = tag->lyrics ? tag->lyrics :
"";
182 m_trackNumber = tag->trackNumber;
183 m_discNumber = tag->discNumber;
184 m_duration = tag->duration;
186 m_rating = tag->rating;
190 std::string m_artist;
192 std::string m_albumArtist;
194 std::string m_comment;
195 std::string m_lyrics;
197 int m_trackNumber = 0;
198 int m_discNumber = 0;
398 if (CPrivateBase::m_interface->globalSingleInstance !=
nullptr)
399 throw std::logic_error(
400 "kodi::addon::CInstanceVisualization: Cannot create multiple instances of add-on.");
402 SetAddonStruct(CPrivateBase::m_interface->firstKodiInstance);
403 CPrivateBase::m_interface->globalSingleInstance =
this;
447 if (CPrivateBase::m_interface->globalSingleInstance !=
nullptr)
448 throw std::logic_error(
"kodi::addon::CInstanceVisualization: Creation of multiple together "
449 "with single instance way is not allowed!");
451 SetAddonStruct(instance);
475 const std::string& songName)
496 virtual void AudioData(
const float* audioData,
size_t audioDataLength) {}
537 virtual bool GetPresets(std::vector<std::string>& presets) {
return false; }
689 m_instanceData->visualization->toKodi->clear_presets(m_instanceData->info->kodi);
690 for (
const auto& it : presets)
691 m_instanceData->visualization->toKodi->transfer_preset(m_instanceData->info->kodi,
717 inline kodi::HardwareContext
Device() {
return m_props.device; }
726 inline int X() {
return m_props.x; }
735 inline int Y() {
return m_props.y; }
744 inline int Width() {
return m_props.width; }
753 inline int Height() {
return m_props.height; }
771 m_instanceData = instance;
772 m_instanceData->hdl =
this;
773 m_instanceData->visualization->toAddon->start = ADDON_start;
774 m_instanceData->visualization->toAddon->stop = ADDON_stop;
775 m_instanceData->visualization->toAddon->audio_data = ADDON_audio_data;
776 m_instanceData->visualization->toAddon->is_dirty = ADDON_is_dirty;
777 m_instanceData->visualization->toAddon->render = ADDON_render;
778 m_instanceData->visualization->toAddon->get_sync_delay = ADDON_get_sync_delay;
779 m_instanceData->visualization->toAddon->prev_preset = ADDON_prev_preset;
780 m_instanceData->visualization->toAddon->next_preset = ADDON_next_preset;
781 m_instanceData->visualization->toAddon->load_preset = ADDON_load_preset;
782 m_instanceData->visualization->toAddon->random_preset = ADDON_random_preset;
783 m_instanceData->visualization->toAddon->lock_preset = ADDON_lock_preset;
784 m_instanceData->visualization->toAddon->rate_preset = ADDON_rate_preset;
785 m_instanceData->visualization->toAddon->update_albumart = ADDON_update_albumart;
786 m_instanceData->visualization->toAddon->update_track = ADDON_update_track;
787 m_instanceData->visualization->toAddon->get_presets = ADDON_get_presets;
788 m_instanceData->visualization->toAddon->get_active_preset = ADDON_get_active_preset;
789 m_instanceData->visualization->toAddon->is_locked = ADDON_is_locked;
791 m_instanceData->visualization->toKodi->get_properties(instance->info->kodi, &m_props);
794 inline static bool ADDON_start(
const KODI_ADDON_VISUALIZATION_HDL hdl,
798 const char* songName)
800 CInstanceVisualization* thisClass =
static_cast<CInstanceVisualization*
>(hdl);
801 thisClass->m_renderHelper = kodi::gui::GetRenderHelper();
802 return thisClass->Start(channels, samplesPerSec, bitsPerSample, songName);
805 inline static void ADDON_stop(
const KODI_ADDON_VISUALIZATION_HDL hdl)
807 CInstanceVisualization* thisClass =
static_cast<CInstanceVisualization*
>(hdl);
809 thisClass->m_renderHelper =
nullptr;
812 inline static void ADDON_audio_data(
const KODI_ADDON_VISUALIZATION_HDL hdl,
813 const float* audioData,
814 size_t audioDataLength)
816 static_cast<CInstanceVisualization*
>(hdl)->AudioData(audioData, audioDataLength);
819 inline static bool ADDON_is_dirty(
const KODI_ADDON_VISUALIZATION_HDL hdl)
821 return static_cast<CInstanceVisualization*
>(hdl)->IsDirty();
824 inline static void ADDON_render(
const KODI_ADDON_VISUALIZATION_HDL hdl)
826 CInstanceVisualization* thisClass =
static_cast<CInstanceVisualization*
>(hdl);
827 if (!thisClass->m_renderHelper)
829 thisClass->m_renderHelper->Begin();
831 thisClass->m_renderHelper->End();
834 inline static int ADDON_get_sync_delay(
const KODI_ADDON_VISUALIZATION_HDL hdl)
836 return static_cast<CInstanceVisualization*
>(hdl)->GetSyncDelay();
839 inline static unsigned int ADDON_get_presets(
const KODI_ADDON_VISUALIZATION_HDL hdl)
841 CInstanceVisualization* thisClass =
static_cast<CInstanceVisualization*
>(hdl);
842 std::vector<std::string> presets;
843 if (thisClass->GetPresets(presets))
845 for (
const auto& it : presets)
846 thisClass->m_instanceData->visualization->toKodi->transfer_preset(
847 thisClass->m_instanceData->info->kodi, it.c_str());
850 return static_cast<unsigned int>(presets.size());
853 inline static int ADDON_get_active_preset(
const KODI_ADDON_VISUALIZATION_HDL hdl)
855 return static_cast<CInstanceVisualization*
>(hdl)->GetActivePreset();
858 inline static bool ADDON_prev_preset(
const KODI_ADDON_VISUALIZATION_HDL hdl)
860 return static_cast<CInstanceVisualization*
>(hdl)->PrevPreset();
863 inline static bool ADDON_next_preset(
const KODI_ADDON_VISUALIZATION_HDL hdl)
865 return static_cast<CInstanceVisualization*
>(hdl)->NextPreset();
868 inline static bool ADDON_load_preset(
const KODI_ADDON_VISUALIZATION_HDL hdl,
int select)
871 return static_cast<CInstanceVisualization*
>(hdl)->LoadPreset(select);
874 inline static bool ADDON_random_preset(
const KODI_ADDON_VISUALIZATION_HDL hdl)
876 return static_cast<CInstanceVisualization*
>(hdl)->RandomPreset();
879 inline static bool ADDON_lock_preset(
const KODI_ADDON_VISUALIZATION_HDL hdl)
881 CInstanceVisualization* thisClass =
static_cast<CInstanceVisualization*
>(hdl);
882 thisClass->m_presetLockedByUser = !thisClass->m_presetLockedByUser;
883 return thisClass->LockPreset(thisClass->m_presetLockedByUser);
886 inline static bool ADDON_rate_preset(
const KODI_ADDON_VISUALIZATION_HDL hdl,
bool plus_minus)
888 return static_cast<CInstanceVisualization*
>(hdl)->RatePreset(plus_minus);
891 inline static bool ADDON_is_locked(
const KODI_ADDON_VISUALIZATION_HDL hdl)
893 return static_cast<CInstanceVisualization*
>(hdl)->IsLocked();
896 inline static bool ADDON_update_albumart(
const KODI_ADDON_VISUALIZATION_HDL hdl,
897 const char* albumart)
899 return static_cast<CInstanceVisualization*
>(hdl)->UpdateAlbumart(albumart);
902 inline static bool ADDON_update_track(
const KODI_ADDON_VISUALIZATION_HDL hdl,
905 VisualizationTrack cppTrack(
track);
906 return static_cast<CInstanceVisualization*
>(hdl)->UpdateTrack(cppTrack);
909 std::shared_ptr<kodi::gui::IRenderHelper> m_renderHelper;
910 bool m_presetLockedByUser =
false;
Definition Visualization.h:386
Definition AddonBase.h:565
Definition AddonBase.h:498
Definition Visualization.h:39
int Height()
Returns the height of the rendering window.
Definition Visualization.h:753
kodi::HardwareContext Device()
Device that represents the display adapter.
Definition Visualization.h:717
void TransferPresets(const std::vector< std::string > &presets)
To transfer available presets on addon.
Definition Visualization.h:687
int X()
Returns the X position of the rendering window.
Definition Visualization.h:726
int Width()
Returns the width of the rendering window.
Definition Visualization.h:744
int Y()
Returns the Y position of the rendering window.
Definition Visualization.h:735
float PixelRatio()
Pixel aspect ratio (often abbreviated PAR) is a ratio that describes how the width of a pixel compare...
Definition Visualization.h:763
int GetDisc() const
Get disk number (if present)
Definition Visualization.h:140
const std::string & GetAlbumArtist() const
Get album artist names, as a single string-.
Definition Visualization.h:116
void SetAlbum(const std::string &album)
Set Album that the current song is from.
Definition Visualization.h:107
void SetTrack(int trackNumber)
Set track number (if present) from music info as integer.
Definition Visualization.h:131
void SetComment(const std::string &comment)
Set additional information comment (if present).
Definition Visualization.h:161
void SetDuration(int duration)
Set the duration of music as integer from info.
Definition Visualization.h:125
int GetYear() const
Get year that the current song was released.
Definition Visualization.h:146
void SetLyrics(const std::string &lyrics)
Set string from lyrics.
Definition Visualization.h:149
int GetRating() const
Get the user-defined rating of the current song.
Definition Visualization.h:158
const std::string & GetAlbum() const
Get Album that the current song is from.
Definition Visualization.h:110
void SetTitle(const std::string &title)
Set title of the current song.
Definition Visualization.h:95
void SetArtist(const std::string &artist)
Set artist names, as a single string-.
Definition Visualization.h:101
void SetAlbumArtist(const std::string &albumArtist)
Set album artist names, as a single stringalbum artist name.
Definition Visualization.h:113
const std::string & GetComment() const
Get additional information comment (if present).
Definition Visualization.h:164
int GetDuration() const
Get the duration of music as integer from info.
Definition Visualization.h:128
const std::string & GetGenre() const
Get genre name from music as string if present.
Definition Visualization.h:122
void SetDisc(int discNumber)
Set disk number (if present) from music info as integer.
Definition Visualization.h:137
const std::string & GetLyrics() const
Get string from lyrics.
Definition Visualization.h:152
void SetRating(int rating)
Set the user-defined rating of the current song.
Definition Visualization.h:155
void SetYear(int year)
Set year that the current song was released.
Definition Visualization.h:143
const std::string & GetTitle() const
Get title of the current song.
Definition Visualization.h:98
int GetTrack() const
Get track number (if present).
Definition Visualization.h:134
void SetGenre(const std::string &genre)
Set genre name from music as string if present.
Definition Visualization.h:119
const std::string & GetArtist() const
Get artist names, as a single string-.
Definition Visualization.h:104
virtual bool LockPreset(bool lockUnlock)
Lock the current visualization preset, preventing it from changing.
Definition Visualization.h:604
virtual void Render()
Used to indicate when the add-on should render.
Definition Visualization.h:513
virtual bool RandomPreset()
Switch to a new random preset.
Definition Visualization.h:594
virtual bool LoadPreset(int select)
Load a visualization preset.
Definition Visualization.h:585
virtual bool IsDirty()
Used to inform Kodi that the rendered region is dirty and need an update.
Definition Visualization.h:506
virtual bool UpdateTrack(const kodi::addon::VisualizationTrack &track)
Inform the visualization of the current track's tag information.
Definition Visualization.h:665
virtual bool PrevPreset()
Load the previous visualization preset.
Definition Visualization.h:564
virtual bool GetPresets(std::vector< std::string > &presets)
Used to get a list of visualization presets the user can select. from.
Definition Visualization.h:537
virtual void AudioData(const float *audioData, size_t audioDataLength)
Pass audio data to the visualization.
Definition Visualization.h:496
virtual int GetActivePreset()
Get the index of the current preset.
Definition Visualization.h:546
~CInstanceVisualization() override=default
Destructor.
CInstanceVisualization()
Visualization class constructor.
Definition Visualization.h:395
virtual bool NextPreset()
Load the next visualization preset.
Definition Visualization.h:573
virtual bool Start(int channels, int samplesPerSec, int bitsPerSample, const std::string &songName)
Used to notify the visualization that a new song has been started.
Definition Visualization.h:472
virtual bool UpdateAlbumart(const std::string &albumart)
Inform the visualization of the current album art image.
Definition Visualization.h:625
virtual bool IsLocked()
Check if the add-on is locked to the current preset.
Definition Visualization.h:555
CInstanceVisualization(const IInstanceInfo &instance)
Visualization class constructor used to support multiple instance types.
Definition Visualization.h:445
virtual bool RatePreset(bool plusMinus)
Used to increase/decrease the visualization preset rating.
Definition Visualization.h:615
virtual void Stop()
Used to inform the visualization that the rendering control was stopped.
Definition Visualization.h:486
virtual int GetSyncDelay()
Used to get the number of buffers from the current visualization.
Definition Visualization.h:524
Definition addon_base.h:268
Definition visualization.h:45
Definition visualization.h:22
Internal used structure to have stored C API data above and available for everything below.
Definition AddonBase.h:73