Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches

Class: kodi::addon::CInstanceVisualization

Visualization add-on instance
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. More...

Topics

 Definitions, structures and enumerators
 Visualization add-on instance definition values
All visualization functions associated data structures.
 
 Information functions
 To get info about the device, display and several other parts
These are functions to query any values or to transfer them to Kodi.
 

Functions

 kodi::addon::CInstanceVisualization::CInstanceVisualization ()
 Visualization class constructor.
 
 kodi::addon::CInstanceVisualization::CInstanceVisualization (const IInstanceInfo &instance)
 Visualization class constructor used to support multiple instance types.
 
 kodi::addon::CInstanceVisualization::~CInstanceVisualization () override=default
 Destructor.
 
virtual bool kodi::addon::CInstanceVisualization::Start (int channels, int samplesPerSec, int bitsPerSample, const std::string &songName)
 Used to notify the visualization that a new song has been started.
 
virtual void kodi::addon::CInstanceVisualization::Stop ()
 Used to inform the visualization that the rendering control was stopped.
 
virtual void kodi::addon::CInstanceVisualization::AudioData (const float *audioData, size_t audioDataLength)
 Pass audio data to the visualization.
 
virtual bool kodi::addon::CInstanceVisualization::IsDirty ()
 Used to inform Kodi that the rendered region is dirty and need an update.
 
virtual void kodi::addon::CInstanceVisualization::Render ()
 Used to indicate when the add-on should render.
 
virtual int kodi::addon::CInstanceVisualization::GetSyncDelay ()
 Used to get the number of buffers from the current visualization.
 
virtual bool kodi::addon::CInstanceVisualization::GetPresets (std::vector< std::string > &presets)
 Used to get a list of visualization presets the user can select. from.
 
virtual int kodi::addon::CInstanceVisualization::GetActivePreset ()
 Get the index of the current preset.
 
virtual bool kodi::addon::CInstanceVisualization::IsLocked ()
 Check if the add-on is locked to the current preset.
 
virtual bool kodi::addon::CInstanceVisualization::PrevPreset ()
 Load the previous visualization preset.
 
virtual bool kodi::addon::CInstanceVisualization::NextPreset ()
 Load the next visualization preset.
 
virtual bool kodi::addon::CInstanceVisualization::LoadPreset (int select)
 Load a visualization preset.
 
virtual bool kodi::addon::CInstanceVisualization::RandomPreset ()
 Switch to a new random preset.
 
virtual bool kodi::addon::CInstanceVisualization::LockPreset (bool lockUnlock)
 Lock the current visualization preset, preventing it from changing.
 
virtual bool kodi::addon::CInstanceVisualization::RatePreset (bool plusMinus)
 Used to increase/decrease the visualization preset rating.
 
virtual bool kodi::addon::CInstanceVisualization::UpdateAlbumart (const std::string &albumart)
 Inform the visualization of the current album art image.
 
virtual bool kodi::addon::CInstanceVisualization::UpdateTrack (const kodi::addon::VisualizationTrack &track)
 Inform the visualization of the current track's tag information.
 

Detailed Description

Class: kodi::addon::CInstanceVisualization

Visualization add-on instance
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 #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 other functions available in which the child class can ask about the current hardware, including the device, display and several other parts.


Here's an example on addon.xml:

<?xml version="1.0" encoding="UTF-8"?>
<addon
id="visualization.myspecialnamefor"
version="1.0.0"
name="My special visualization addon"
provider-name="Your Name">
<requires>@ADDON_DEPENDS@</requires>
<extension
point="xbmc.player.musicviz"
library_@PLATFORM@="@LIBRARY_FILENAME@"/>
<extension point="xbmc.addon.metadata">
<summary lang="en_GB">My visualization addon addon</summary>
<description lang="en_GB">My visualization addon description</description>
<platform>@PLATFORM@</platform>
</extension>
</addon>

Description to visualization related addon.xml values:

Name Description
point Addon type specification
At all addon types and for this kind always "xbmc.player.musicviz".
library_@PLATFORM@ Sets the used library name, which is automatically set by cmake at addon build.

Here is an example of the minimum required code to start a visualization:

class CMyVisualization : public kodi::addon::CAddonBase,
{
public:
CMyVisualization();
bool Start(int channels, int samplesPerSec, int bitsPerSample, const std::string& songName) override;
void AudioData(const float* audioData, size_t audioDataLength) override;
void Render() override;
};
CMyVisualization::CMyVisualization()
{
...
}
bool CMyVisualization::Start(int channels, int samplesPerSec, int bitsPerSample, const std::string& songName)
{
...
return true;
}
void CMyVisualization::AudioData(const float* audioData, size_t audioDataLength)
{
...
}
void CMyVisualization::Render()
{
...
}
ADDONCREATOR(CMyVisualization)
const char unsigned int int * channels
Definition addons/kodi-dev-kit/include/kodi/c-api/addon-instance/AudioDecoder.h:108
Definition kodi-dev-kit/include/kodi/AddonBase.h:775
Definition kodi-dev-kit/include/kodi/addon-instance/visualization.h:386
virtual void Render()
Used to indicate when the add-on should render.
Definition kodi-dev-kit/include/kodi/addon-instance/visualization.h:513
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 kodi-dev-kit/include/kodi/addon-instance/visualization.h:472
virtual void AudioData(const float *audioData, size_t audioDataLength)
Pass audio data to the visualization.
Definition kodi-dev-kit/include/kodi/addon-instance/visualization.h:496
#define ADDONCREATOR(AddonClass)
Definition kodi-dev-kit/include/kodi/AddonBase.h:2047

Here is another example where the visualization is used together with other instance types:

class CMyVisualization : public kodi::addon::CInstanceVisualization
{
public:
CMyVisualization(const kodi::addon::IInstanceInfo& instance);
bool Start(int channels, int samplesPerSec, int bitsPerSample, const std::string& songName) override;
void AudioData(const float* audioData, size_t audioDataLength) override;
void Render() override;
};
CMyVisualization::CMyVisualization(const kodi::addon::IInstanceInfo& instance)
: kodi::addon::CInstanceAudioDecoder(instance)
{
...
}
bool CMyVisualization::Start(int channels, int samplesPerSec, int bitsPerSample, const std::string& songName)
{
...
return true;
}
void CMyVisualization::AudioData(const float* audioData, size_t audioDataLength)
{
...
}
void CMyVisualization::Render()
{
...
}
//----------------------------------------------------------------------
class CMyAddon : public kodi::addon::CAddonBase
{
public:
CMyAddon() = default;
};
// If you use only one instance in your add-on, can be instanceType and
// instanceID ignored
ADDON_STATUS CMyAddon::CreateInstance(const kodi::addon::IInstanceInfo& instance,
{
{
kodi::Log(ADDON_LOG_INFO, "Creating my visualization");
hdl = new CMyVisualization(instance);
}
else if (...)
{
...
}
}
ADDONCREATOR(CMyAddon)
void * KODI_ADDON_INSTANCE_HDL
Definition addon_base.h:121
KODI_ADDON_HDL * hdl
Definition addon_base.h:344
Definition kodi-dev-kit/include/kodi/AddonBase.h:498
@ ADDON_LOG_INFO
1 : To include information messages in the log file.
Definition addon_base.h:187
ADDON_STATUS
Definition addon_base.h:138
@ ADDON_STATUS_OK
For everything OK and no error.
Definition addon_base.h:140
@ ADDON_STATUS_UNKNOWN
Unknown and incomprehensible error.
Definition addon_base.h:152
@ ADDON_INSTANCE_VISUALIZATION
Music visualization instance, see kodi::addon::CInstanceVisualization.
Definition versions.h:240
virtual ADDON_STATUS CreateInstance(const kodi::addon::IInstanceInfo &instance, KODI_ADDON_INSTANCE_HDL &hdl)
Instance created.
Definition kodi-dev-kit/include/kodi/AddonBase.h:924
void ATTR_DLL_LOCAL Log(const ADDON_LOG loglevel, const char *format,...)
Add a message to Kodi's log.
Definition kodi-dev-kit/include/kodi/AddonBase.h:1938
Definition addons/kodi-dev-kit/include/kodi/addon-instance/AudioDecoder.h:21
Definition addon_base.h:268

The destruction of the example class CMyVisualization is called from Kodi's header. Manually deleting the add-on instance is not required.

Function Documentation

◆ AudioData()

virtual void kodi::addon::CInstanceVisualization::AudioData ( const float * audioData,
size_t audioDataLength )
inlinevirtual

Pass audio data to the visualization.

Parameters
[in]audioDataThe raw audio data
[in]audioDataLengthLength of the audioData array

◆ CInstanceVisualization() [1/2]

kodi::addon::CInstanceVisualization::CInstanceVisualization ( )
inline

Visualization class constructor.

Used by an add-on that only supports visualizations.

◆ CInstanceVisualization() [2/2]

kodi::addon::CInstanceVisualization::CInstanceVisualization ( const IInstanceInfo & instance)
inlineexplicit

Visualization class constructor used to support multiple instance types.

Parameters
[in]instanceThe instance value given to kodi::addon::CAddonBase::CreateInstance(...).
[in]kodiVersion[opt] Version used in Kodi for this instance, to allow compatibility to older Kodi versions.
Note
Recommended to set kodiVersion.

Here's example about the use of this:

class CMyVisualization : public kodi::addon::CInstanceAudioDecoder
{
public:
CMyVisualization(const kodi::addon::IInstanceInfo& instance)
{
...
}
...
};
ADDON_STATUS CMyAddon::CreateInstance(const kodi::addon::IInstanceInfo& instance,
{
kodi::Log(ADDON_LOG_INFO, "Creating my visualization");
hdl = new CMyVisualization(instance);
}
Definition addons/kodi-dev-kit/include/kodi/addon-instance/AudioDecoder.h:431

◆ GetActivePreset()

virtual int kodi::addon::CInstanceVisualization::GetActivePreset ( )
inlinevirtual

Get the index of the current preset.

Returns
Index number of the current preset

◆ GetPresets()

virtual bool kodi::addon::CInstanceVisualization::GetPresets ( std::vector< std::string > & presets)
inlinevirtual

Used to get a list of visualization presets the user can select. from.

Parameters
[out]presetsThe vector list containing the names of presets that the user can select
Returns
Return true if successful, or false if there are no presets to choose from

◆ GetSyncDelay()

virtual int kodi::addon::CInstanceVisualization::GetSyncDelay ( )
inlinevirtual

Used to get the number of buffers from the current visualization.

Returns
The number of buffers to delay before calling AudioData()
Note
If this function is not implemented, it will default to 0.

◆ IsDirty()

virtual bool kodi::addon::CInstanceVisualization::IsDirty ( )
inlinevirtual

Used to inform Kodi that the rendered region is dirty and need an update.

Returns
True if dirty

◆ IsLocked()

virtual bool kodi::addon::CInstanceVisualization::IsLocked ( )
inlinevirtual

Check if the add-on is locked to the current preset.

Returns
True if locked to the current preset

◆ LoadPreset()

virtual bool kodi::addon::CInstanceVisualization::LoadPreset ( int select)
inlinevirtual

Load a visualization preset.

This function is called after a new preset is selected.

Parameters
[in]selectPreset index to use
Returns
Return true if the preset is loaded

◆ LockPreset()

virtual bool kodi::addon::CInstanceVisualization::LockPreset ( bool lockUnlock)
inlinevirtual

Lock the current visualization preset, preventing it from changing.

Parameters
[in]lockUnlockIf set to true, the preset should be locked
Returns
Return true if the current preset is locked

◆ NextPreset()

virtual bool kodi::addon::CInstanceVisualization::NextPreset ( )
inlinevirtual

Load the next visualization preset.

Returns
Return true if the next preset was loaded

◆ PrevPreset()

virtual bool kodi::addon::CInstanceVisualization::PrevPreset ( )
inlinevirtual

Load the previous visualization preset.

Returns
Return true if the previous preset was loaded

◆ RandomPreset()

virtual bool kodi::addon::CInstanceVisualization::RandomPreset ( )
inlinevirtual

Switch to a new random preset.

Returns
Return true if a random preset was loaded

◆ RatePreset()

virtual bool kodi::addon::CInstanceVisualization::RatePreset ( bool plusMinus)
inlinevirtual

Used to increase/decrease the visualization preset rating.

Parameters
[in]plusMinusIf set to true the rating is increased, otherwise decreased
Returns
Return true if the rating is modified

◆ Render()

virtual void kodi::addon::CInstanceVisualization::Render ( )
inlinevirtual

Used to indicate when the add-on should render.

◆ Start()

virtual bool kodi::addon::CInstanceVisualization::Start ( int channels,
int samplesPerSec,
int bitsPerSample,
const std::string & songName )
inlinevirtual

Used to notify the visualization that a new song has been started.

Parameters
[in]channelsNumber of channels in the stream
[in]samplesPerSecSamples per second of stream
[in]bitsPerSampleNumber of bits in one sample
[in]songNameThe name of the currently-playing song
Returns
true if start successful done

◆ Stop()

virtual void kodi::addon::CInstanceVisualization::Stop ( )
inlinevirtual

Used to inform the visualization that the rendering control was stopped.

◆ UpdateAlbumart()

virtual bool kodi::addon::CInstanceVisualization::UpdateAlbumart ( const std::string & albumart)
inlinevirtual

Inform the visualization of the current album art image.

Parameters
[in]albumartPath to the current album art image
Returns
Return true if the image is used

◆ UpdateTrack()

virtual bool kodi::addon::CInstanceVisualization::UpdateTrack ( const kodi::addon::VisualizationTrack & track)
inlinevirtual

Inform the visualization of the current track's tag information.

Parameters
[in]trackVisualization track information structure
Returns
Return true if the track information is used

The following table contains values that can be set with class VisualizationTrack :

Name Type Set call Get call
Title of the current song. std::string SetTitle GetTitle
Artist names, as a single string std::string SetArtist GetArtist
Album that the current song is from. std::string SetAlbum GetAlbum
Album artist names, as a single string std::string SetAlbumArtist GetAlbumArtist
The genre name from the music tag, if present std::string SetGenre GetGenre
Duration of the current song, in seconds int SetDuration GetDuration
Track number of the current song int SetTrack GetTrack
Disc number of the current song stored in the ID tag info int SetDisc GetDisc
Year that the current song was released int SetYear GetYear
Lyrics of the current song, if available std::string SetLyrics GetLyrics
The user-defined rating of the current song int SetRating GetRating
Comment of the current song stored in the ID tag info std::string SetComment GetComment

Example:

class CMyVisualization : public kodi::addon::CInstanceVisualization
{
public:
CMyVisualization(KODI_HANDLE instance, const std::string& version);
...
private:
};
bool CMyVisualization::UpdateTrack(const kodi::addon::VisualizationTrack& track)
{
m_runningTrack = track;
return true;
}
void * KODI_HANDLE
Standard undefined pointer handle.
Definition addon_base.h:291
Definition kodi-dev-kit/include/kodi/addon-instance/visualization.h:39
const struct KODI_ADDON_VISUALIZATION_TRACK * track
Definition kodi-dev-kit/include/kodi/c-api/addon-instance/visualization.h:95
Definition kodi-dev-kit/include/kodi/c-api/addon-instance/visualization.h:22

◆ ~CInstanceVisualization()

kodi::addon::CInstanceVisualization::~CInstanceVisualization ( )
overridedefault

Destructor.