11 #include "../AddonBase.h"
12 #include "../c-api/addon-instance/visualization.h"
13 #include "../gui/renderHelper.h"
58 m_title = right.m_title;
59 m_artist = right.m_artist;
60 m_album = right.m_album;
61 m_albumArtist = right.m_albumArtist;
62 m_genre = right.m_genre;
63 m_comment = right.m_comment;
64 m_lyrics = right.m_lyrics;
66 m_trackNumber = right.m_trackNumber;
67 m_discNumber = right.m_discNumber;
68 m_duration = right.m_duration;
69 m_year = right.m_year;
70 m_rating = right.m_rating;
99 void SetTitle(
const std::string& title) { m_title = title; }
102 const std::string&
GetTitle()
const {
return m_title; }
105 void SetArtist(
const std::string& artist) { m_artist = artist; }
108 const std::string&
GetArtist()
const {
return m_artist; }
111 void SetAlbum(
const std::string& album) { m_album = album; }
114 const std::string&
GetAlbum()
const {
return m_album; }
117 void SetAlbumArtist(
const std::string& albumArtist) { m_albumArtist = albumArtist; }
123 void SetGenre(
const std::string& genre) { m_genre = genre; }
126 const std::string&
GetGenre()
const {
return m_genre; }
135 void SetTrack(
int trackNumber) { m_trackNumber = trackNumber; }
141 void SetDisc(
int discNumber) { m_discNumber = discNumber; }
153 void SetLyrics(
const std::string& lyrics) { m_lyrics = lyrics; }
156 const std::string&
GetLyrics()
const {
return m_lyrics; }
165 void SetComment(
const std::string& comment) { m_comment = comment; }
178 m_title = tag->title ? tag->title :
"";
179 m_artist = tag->artist ? tag->artist :
"";
180 m_album = tag->album ? tag->album :
"";
181 m_albumArtist = tag->albumArtist ? tag->albumArtist :
"";
182 m_genre = tag->genre ? tag->genre :
"";
183 m_comment = tag->comment ? tag->comment :
"";
184 m_lyrics = tag->lyrics ? tag->lyrics :
"";
186 m_trackNumber = tag->trackNumber;
187 m_discNumber = tag->discNumber;
188 m_duration = tag->duration;
190 m_rating = tag->rating;
194 std::string m_artist;
196 std::string m_albumArtist;
198 std::string m_comment;
199 std::string m_lyrics;
201 int m_trackNumber = 0;
202 int m_discNumber = 0;
408 if (CAddonBase::m_interface->globalSingleInstance !=
nullptr)
409 throw std::logic_error(
410 "kodi::addon::CInstanceVisualization: Cannot create multiple instances of add-on.");
412 SetAddonStruct(CAddonBase::m_interface->firstKodiInstance);
413 CAddonBase::m_interface->globalSingleInstance =
this;
460 !kodiVersion.empty() ? kodiVersion
463 if (CAddonBase::m_interface->globalSingleInstance !=
nullptr)
464 throw std::logic_error(
"kodi::addon::CInstanceVisualization: Creation of multiple together "
465 "with single instance way is not allowed!");
467 SetAddonStruct(instance);
488 virtual bool Start(
int channels,
int samplesPerSec,
int bitsPerSample, std::string songName)
554 virtual void GetInfo(
bool& wantsFreq,
int& syncDelay)
571 virtual bool GetPresets(std::vector<std::string>& presets) {
return false; }
723 m_instanceData->toKodi->clear_presets(m_instanceData->toKodi->kodiInstance);
724 for (
const auto& it : presets)
725 m_instanceData->toKodi->transfer_preset(m_instanceData->toKodi->kodiInstance, it.c_str());
750 inline kodi::HardwareContext
Device() {
return m_instanceData->props->device; }
759 inline int X() {
return m_instanceData->props->x; }
768 inline int Y() {
return m_instanceData->props->y; }
777 inline int Width() {
return m_instanceData->props->width; }
786 inline int Height() {
return m_instanceData->props->height; }
796 inline float PixelRatio() {
return m_instanceData->props->pixelRatio; }
805 inline std::string
Name() {
return m_instanceData->props->name; }
814 inline std::string
Presets() {
return m_instanceData->props->presets; }
827 inline std::string
Profile() {
return m_instanceData->props->profile; }
833 void SetAddonStruct(KODI_HANDLE instance)
835 if (instance ==
nullptr)
836 throw std::logic_error(
"kodi::addon::CInstanceVisualization: Null pointer instance passed.");
839 m_instanceData->toAddon->addonInstance =
this;
840 m_instanceData->toAddon->start = ADDON_Start;
841 m_instanceData->toAddon->stop = ADDON_Stop;
842 m_instanceData->toAddon->audio_data = ADDON_AudioData;
843 m_instanceData->toAddon->is_dirty = ADDON_IsDirty;
844 m_instanceData->toAddon->render = ADDON_Render;
845 m_instanceData->toAddon->get_info = ADDON_GetInfo;
846 m_instanceData->toAddon->prev_preset = ADDON_PrevPreset;
847 m_instanceData->toAddon->next_preset = ADDON_NextPreset;
848 m_instanceData->toAddon->load_preset = ADDON_LoadPreset;
849 m_instanceData->toAddon->random_preset = ADDON_RandomPreset;
850 m_instanceData->toAddon->lock_preset = ADDON_LockPreset;
851 m_instanceData->toAddon->rate_preset = ADDON_RatePreset;
852 m_instanceData->toAddon->update_albumart = ADDON_UpdateAlbumart;
853 m_instanceData->toAddon->update_track = ADDON_UpdateTrack;
854 m_instanceData->toAddon->get_presets = ADDON_GetPresets;
855 m_instanceData->toAddon->get_active_preset = ADDON_GetActivePreset;
856 m_instanceData->toAddon->is_locked = ADDON_IsLocked;
863 const char* songName)
865 CInstanceVisualization* thisClass =
866 static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance);
867 thisClass->m_renderHelper = kodi::gui::GetRenderHelper();
868 return thisClass->Start(channels, samplesPerSec, bitsPerSample, songName);
873 CInstanceVisualization* thisClass =
874 static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance);
876 thisClass->m_renderHelper =
nullptr;
880 const float* audioData,
885 static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance)
886 ->AudioData(audioData, audioDataLength, freqData, freqDataLength);
891 return static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance)->IsDirty();
896 CInstanceVisualization* thisClass =
897 static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance);
898 if (!thisClass->m_renderHelper)
900 thisClass->m_renderHelper->Begin();
902 thisClass->m_renderHelper->End();
907 static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance)
908 ->GetInfo(info->bWantsFreq, info->iSyncDelay);
913 CInstanceVisualization* thisClass =
914 static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance);
915 std::vector<std::string> presets;
916 if (thisClass->GetPresets(presets))
918 for (
const auto& it : presets)
919 thisClass->m_instanceData->toKodi->transfer_preset(addon->toKodi->kodiInstance, it.c_str());
922 return static_cast<unsigned int>(presets.size());
927 return static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance)->GetActivePreset();
932 return static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance)->PrevPreset();
937 return static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance)->NextPreset();
943 return static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance)->LoadPreset(select);
948 return static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance)->RandomPreset();
953 CInstanceVisualization* thisClass =
954 static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance);
955 thisClass->m_presetLockedByUser = !thisClass->m_presetLockedByUser;
956 return thisClass->LockPreset(thisClass->m_presetLockedByUser);
961 return static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance)
962 ->RatePreset(plus_minus);
967 return static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance)->IsLocked();
971 const char* albumart)
973 return static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance)
974 ->UpdateAlbumart(albumart);
980 VisualizationTrack cppTrack(track);
981 return static_cast<CInstanceVisualization*
>(addon->toAddon->addonInstance)
982 ->UpdateTrack(cppTrack);
985 std::shared_ptr<kodi::gui::IRenderHelper> m_renderHelper;
986 bool m_presetLockedByUser =
false;
Definition: Visualization.h:396
Definition: AddonBase.h:186
Definition: Visualization.h:40
@ ADDON_INSTANCE_VISUALIZATION
Music visualization instance, see kodi::addon::CInstanceVisualization.
Definition: versions.h:238
std::string Presets()
Used to get the full path where the add-on is installed.
Definition: Visualization.h:814
int Height()
Returns the height of the rendering window.
Definition: Visualization.h:786
kodi::HardwareContext Device()
Device that represents the display adapter.
Definition: Visualization.h:750
std::string Profile()
Used to get the full path to the add-on's user profile.
Definition: Visualization.h:827
void TransferPresets(const std::vector< std::string > &presets)
To transfer available presets on addon.
Definition: Visualization.h:721
int X()
Returns the X position of the rendering window.
Definition: Visualization.h:759
int Width()
Returns the width of the rendering window.
Definition: Visualization.h:777
int Y()
Returns the Y position of the rendering window.
Definition: Visualization.h:768
std::string Name()
Used to get the name of the add-on defined in addon.xml.
Definition: Visualization.h:805
float PixelRatio()
Pixel aspect ratio (often abbreviated PAR) is a ratio that describes how the width of a pixel compare...
Definition: Visualization.h:796
int GetDisc() const
Get disk number (if present)
Definition: Visualization.h:144
void SetAlbum(const std::string &album)
Set Album that the current song is from.
Definition: Visualization.h:111
void SetTrack(int trackNumber)
Set track number (if present) from music info as integer.
Definition: Visualization.h:135
void SetComment(const std::string &comment)
Set additional information comment (if present).
Definition: Visualization.h:165
void SetDuration(int duration)
Set the duration of music as integer from info.
Definition: Visualization.h:129
int GetYear() const
Get year that the current song was released.
Definition: Visualization.h:150
void SetLyrics(const std::string &lyrics)
Set string from lyrics.
Definition: Visualization.h:153
int GetRating() const
Get the user-defined rating of the current song.
Definition: Visualization.h:162
const std::string & GetArtist() const
Get artist names, as a single string-.
Definition: Visualization.h:108
void SetTitle(const std::string &title)
Set title of the current song.
Definition: Visualization.h:99
const std::string & GetAlbum() const
Get Album that the current song is from.
Definition: Visualization.h:114
void SetArtist(const std::string &artist)
Set artist names, as a single string-.
Definition: Visualization.h:105
void SetAlbumArtist(const std::string &albumArtist)
Set album artist names, as a single stringalbum artist name.
Definition: Visualization.h:117
const std::string & GetLyrics() const
Get string from lyrics.
Definition: Visualization.h:156
int GetDuration() const
Get the duration of music as integer from info.
Definition: Visualization.h:132
void SetDisc(int discNumber)
Set disk number (if present) from music info as integer.
Definition: Visualization.h:141
void SetRating(int rating)
Set the user-defined rating of the current song.
Definition: Visualization.h:159
void SetYear(int year)
Set year that the current song was released.
Definition: Visualization.h:147
const std::string & GetGenre() const
Get genre name from music as string if present.
Definition: Visualization.h:126
int GetTrack() const
Get track number (if present).
Definition: Visualization.h:138
const std::string & GetTitle() const
Get title of the current song.
Definition: Visualization.h:102
void SetGenre(const std::string &genre)
Set genre name from music as string if present.
Definition: Visualization.h:123
const std::string & GetAlbumArtist() const
Get album artist names, as a single string-.
Definition: Visualization.h:120
const std::string & GetComment() const
Get additional information comment (if present).
Definition: Visualization.h:168
virtual bool LockPreset(bool lockUnlock)
Lock the current visualization preset, preventing it from changing.
Definition: Visualization.h:638
virtual void Render()
Used to indicate when the add-on should render.
Definition: Visualization.h:538
virtual bool RandomPreset()
Switch to a new random preset.
Definition: Visualization.h:628
virtual bool LoadPreset(int select)
Load a visualization preset.
Definition: Visualization.h:619
virtual bool IsDirty()
Used to inform Kodi that the rendered region is dirty and need an update.
Definition: Visualization.h:531
virtual bool UpdateTrack(const kodi::addon::VisualizationTrack &track)
Inform the visualization of the current track's tag information.
Definition: Visualization.h:699
virtual bool PrevPreset()
Load the previous visualization preset.
Definition: Visualization.h:598
virtual bool GetPresets(std::vector< std::string > &presets)
Used to get a list of visualization presets the user can select. from.
Definition: Visualization.h:571
virtual void GetInfo(bool &wantsFreq, int &syncDelay)
Used to get the number of buffers from the current visualization.
Definition: Visualization.h:554
virtual void AudioData(const float *audioData, int audioDataLength, float *freqData, int freqDataLength)
Pass audio data to the visualization.
Definition: Visualization.h:516
virtual int GetActivePreset()
Get the index of the current preset.
Definition: Visualization.h:580
virtual bool Start(int channels, int samplesPerSec, int bitsPerSample, std::string songName)
Used to notify the visualization that a new song has been started.
Definition: Visualization.h:488
~CInstanceVisualization() override=default
Destructor.
virtual bool UpdateAlbumart(std::string albumart)
Inform the visualization of the current album art image.
Definition: Visualization.h:659
CInstanceVisualization()
Visualization class constructor.
Definition: Visualization.h:405
virtual bool NextPreset()
Load the next visualization preset.
Definition: Visualization.h:607
virtual bool IsLocked()
Check if the add-on is locked to the current preset.
Definition: Visualization.h:589
virtual bool RatePreset(bool plusMinus)
Used to increase/decrease the visualization preset rating.
Definition: Visualization.h:649
virtual void Stop()
Used to inform the visualization that the rendering control was stopped.
Definition: Visualization.h:499
CInstanceVisualization(KODI_HANDLE instance, const std::string &kodiVersion="")
Visualization class constructor used to support multiple instance types.
Definition: Visualization.h:458
std::string ATTRIBUTE_HIDDEN GetKodiTypeVersion(int type)
To get used version inside Kodi itself about asked type.
Definition: AddonBase.h:630
Definition: visualization.h:110
Definition: visualization.h:22
Definition: visualization.h:28