Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: DontAlign
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<[a-z0-9_]+>$'
Priority: 3
- Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)\.h>$'
Priority: 3
- Regex: '^<'
Priority: 3
- Regex: '^["<](kodi|p8-platform)\/.*\.h[">]$'
Priority: 2
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '$'
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60000
PointerAlignment: Left
ReflowComments: false
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.18)
project(visualization.waveform)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})
Expand Down
4 changes: 2 additions & 2 deletions debian/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Format: http://dep.debian.net/deps/dep5
Upstream-Name: visualization.waveform

Files: *
Copyright: 2005-2022 Team Kodi
Copyright: 2005-2026 Team Kodi
License: GPL-2+
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -24,7 +24,7 @@ License: GPL-2+
Files: debian/*
Copyright: 2013 Arne Morten Kvarving <arne.morten.kvarving@sintef.no>
2013 wsnipex <wsnipex@a1.net>
2005-2022 Team Kodi
2005-2026 Team Kodi
License: GPL-2+
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
4 changes: 2 additions & 2 deletions src/DefaultPixelShader.hlsl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2005-2021 Team Kodi (https://kodi.tv)
* Copyright (C) 2005-2026 Team Kodi (https://kodi.tv)
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSE.md for more information.
*/

float4 main(float4 pos: SV_POSITION, float4 col : COLOR) : SV_TARGET
float4 main(float4 pos : SV_POSITION, float4 col : COLOR) : SV_TARGET
{
return col;
}
12 changes: 6 additions & 6 deletions src/DefaultVertexShader.hlsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2021 Team Kodi (https://kodi.tv)
* Copyright (C) 2005-2026 Team Kodi (https://kodi.tv)
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSE.md for more information.
Expand All @@ -22,10 +22,10 @@ cbuffer cbViewPort : register(b0)
VS_OUT main(float4 pos : POSITION, float4 col : COLOR)
{
VS_OUT r = (VS_OUT)0;
r.pos.x = (pos.x / (g_viewPortWidth / 2.0)) - 1;
r.pos.y = -(pos.y / (g_viewPortHeigh / 2.0)) + 1;
r.pos.z = pos.z;
r.pos.w = 1.0;
r.col = col;
r.pos.x = (pos.x / (g_viewPortWidth / 2.0)) - 1;
r.pos.y = -(pos.y / (g_viewPortHeigh / 2.0)) + 1;
r.pos.z = pos.z;
r.pos.w = 1.0;
r.col = col;
return r;
}
84 changes: 37 additions & 47 deletions src/Main_dx.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2022 Team Kodi (https://kodi.tv)
* Copyright (C) 2008-2026 Team Kodi (https://kodi.tv)
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSE.md for more information.
Expand All @@ -8,25 +8,23 @@
// Waveform.vis
// A simple visualisation example by MrC

#include <kodi/addon-instance/Visualization.h>
#include <stdio.h>
#include <d3d11_1.h>
#include <DirectXMath.h>
#include <DirectXPackedVector.h>
#include <stdio.h>

#include <d3d11_1.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <kodi/addon-instance/Visualization.h>
#include <stdio.h>

using namespace DirectX;
using namespace DirectX::PackedVector;

// Include the precompiled shader code.
namespace
{
#include "DefaultPixelShader.inc"
#include "DefaultVertexShader.inc"
}
#include "DefaultPixelShader.inc"
#include "DefaultVertexShader.inc"
} // namespace

struct cbViewPort
{
Expand All @@ -41,16 +39,14 @@ struct Vertex_t
XMFLOAT4 col;
};

class CVisualizationWaveForm
: public kodi::addon::CAddonBase,
public kodi::addon::CInstanceVisualization
class CVisualizationWaveForm : public kodi::addon::CAddonBase,
public kodi::addon::CInstanceVisualization
{
public:
CVisualizationWaveForm() = default;
~CVisualizationWaveForm() override;

ADDON_STATUS Create() override;
bool Start(int channels, int samplesPerSec, int bitsPerSample, const std::string& songName) override;
bool Init() override;
void Render() override;
void AudioData(const float* audioData, size_t audioDataLength) override;

Expand Down Expand Up @@ -96,10 +92,10 @@ CVisualizationWaveForm::~CVisualizationWaveForm()
m_device->Release();
}

//-- Create -------------------------------------------------------------------
//-- Init -------------------------------------------------------------------
// Called on load. Addon should fully initalize or return error status
//-----------------------------------------------------------------------------
ADDON_STATUS CVisualizationWaveForm::Create()
bool CVisualizationWaveForm::Init()
{
m_viewport.TopLeftX = static_cast<float>(X());
m_viewport.TopLeftY = static_cast<float>(Y());
Expand All @@ -110,20 +106,7 @@ ADDON_STATUS CVisualizationWaveForm::Create()
m_context = (ID3D11DeviceContext*)Device();
m_context->GetDevice(&m_device);
if (!init_renderer_objs())
return ADDON_STATUS_PERMANENT_FAILURE;

return ADDON_STATUS_OK;
}

//-- Start -------------------------------------------------------------------
// Called on load. Addon should fully initalize or return error status
//-----------------------------------------------------------------------------
bool CVisualizationWaveForm::Start(int channels, int samplesPerSec, int bitsPerSample, const std::string& songName)
{
(void)channels;
(void)samplesPerSec;
(void)bitsPerSample;
(void)songName;
return false;

kodi::addon::CheckSettingInt("points-per-line", m_usedLinePoints);

Expand Down Expand Up @@ -173,13 +156,13 @@ void CVisualizationWaveForm::AudioData(const float* pAudioData, size_t iAudioDat

while (ipos < m_usedLinePoints)
{
for (size_t i=0; i < length; i+=usedStep)
for (size_t i = 0; i < length; i += usedStep)
{
m_fWaveform[0][ipos] = pAudioData[i ]; // left channel
m_fWaveform[1][ipos] = pAudioData[i+1]; // right channel
m_fWaveform[0][ipos] = pAudioData[i]; // left channel
m_fWaveform[1][ipos] = pAudioData[i + 1]; // right channel
ipos++;
if (ipos >= m_usedLinePoints)
break;
break;
}
}
}
Expand Down Expand Up @@ -237,8 +220,10 @@ void CVisualizationWaveForm::Render()
for (int i = 0; i < m_usedLinePoints; i++)
{
m_verts[j].col = XMFLOAT4(glm::value_ptr(m_lineColor));
m_verts[j].x = m_viewport.TopLeftX + (-1.0f + ((i / float(m_usedLinePoints)) * 2.0f) * m_viewport.Width);
m_verts[j].y = m_viewport.TopLeftY + m_viewport.Height * 0.25f + (m_fWaveform[0][i] * m_viewport.Height * 0.3f);
m_verts[j].x =
m_viewport.TopLeftX + (-1.0f + ((i / float(m_usedLinePoints)) * 2.0f) * m_viewport.Width);
m_verts[j].y = m_viewport.TopLeftY + m_viewport.Height * 0.25f +
(m_fWaveform[0][i] * m_viewport.Height * 0.3f);
m_verts[j].z = 1.0;
j++;
}
Expand All @@ -247,8 +232,10 @@ void CVisualizationWaveForm::Render()
for (int i = 0; i < m_usedLinePoints; i++)
{
m_verts[j].col = XMFLOAT4(glm::value_ptr(m_lineColor));
m_verts[j].x = m_viewport.TopLeftX + (-1.0f + ((i / float(m_usedLinePoints)) * 2.0f) * m_viewport.Width);
m_verts[j].y = m_viewport.TopLeftY + m_viewport.Height * 0.75f + (m_fWaveform[1][i] * m_viewport.Height * 0.3f);
m_verts[j].x =
m_viewport.TopLeftX + (-1.0f + ((i / float(m_usedLinePoints)) * 2.0f) * m_viewport.Width);
m_verts[j].y = m_viewport.TopLeftY + m_viewport.Height * 0.75f +
(m_fWaveform[1][i] * m_viewport.Height * 0.3f);
m_verts[j].z = 1.0;
j++;
}
Expand All @@ -268,24 +255,27 @@ void CVisualizationWaveForm::Render()
bool CVisualizationWaveForm::init_renderer_objs()
{
// Create vertex shader
if (S_OK != m_device->CreateVertexShader(DefaultVertexShaderCode, sizeof(DefaultVertexShaderCode), nullptr, &m_vShader))
if (S_OK != m_device->CreateVertexShader(DefaultVertexShaderCode, sizeof(DefaultVertexShaderCode),
nullptr, &m_vShader))
return false;

// Create input layout
D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
D3D11_INPUT_ELEMENT_DESC layout[] = {
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
};
if (S_OK != m_device->CreateInputLayout(layout, ARRAYSIZE(layout), DefaultVertexShaderCode, sizeof(DefaultVertexShaderCode), &m_inputLayout))
if (S_OK != m_device->CreateInputLayout(layout, ARRAYSIZE(layout), DefaultVertexShaderCode,
sizeof(DefaultVertexShaderCode), &m_inputLayout))
return false;

// Create pixel shader
if (S_OK != m_device->CreatePixelShader(DefaultPixelShaderCode, sizeof(DefaultPixelShaderCode), nullptr, &m_pShader))
if (S_OK != m_device->CreatePixelShader(DefaultPixelShaderCode, sizeof(DefaultPixelShaderCode),
nullptr, &m_pShader))
return false;

// create buffers
CD3D11_BUFFER_DESC desc(sizeof(Vertex_t) * 1024 * 2, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
CD3D11_BUFFER_DESC desc(sizeof(Vertex_t) * 1024 * 2, D3D11_BIND_VERTEX_BUFFER,
D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
if (S_OK != m_device->CreateBuffer(&desc, NULL, &m_vBuffer))
return false;

Expand All @@ -294,7 +284,7 @@ bool CVisualizationWaveForm::init_renderer_objs()
desc.Usage = D3D11_USAGE_DEFAULT;
desc.CPUAccessFlags = 0;

cbViewPort viewPort = { (float)m_viewport.Width, (float)m_viewport.Height, 0.0f, 0.0f };
cbViewPort viewPort = {(float)m_viewport.Width, (float)m_viewport.Height, 0.0f, 0.0f};
D3D11_SUBRESOURCE_DATA initData;
initData.pSysMem = &viewPort;

Expand Down
Loading