diff --git a/plugins/editor/CMakeLists.txt b/plugins/editor/CMakeLists.txt index 8edb39b1..d2153d32 100644 --- a/plugins/editor/CMakeLists.txt +++ b/plugins/editor/CMakeLists.txt @@ -36,6 +36,8 @@ add_library(sfizz_editor STATIC EXCLUDE_FROM_ALL src/editor/GUIComponents.cpp src/editor/GUIPiano.h src/editor/GUIPiano.cpp + src/editor/ColorHelpers.h + src/editor/ColorHelpers.cpp src/editor/NativeHelpers.h src/editor/NativeHelpers.cpp src/editor/layout/main.hpp diff --git a/plugins/editor/src/editor/ColorHelpers.cpp b/plugins/editor/src/editor/ColorHelpers.cpp new file mode 100644 index 00000000..0d92ce27 --- /dev/null +++ b/plugins/editor/src/editor/ColorHelpers.cpp @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: BSD-2-Clause + +// This code is part of the sfizz library and is licensed under a BSD 2-clause +// license. You should have receive a LICENSE.md file along with the code. +// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz + +#include "ColorHelpers.h" +#include + +SColorRGB::SColorRGB(const CColor &cc) +{ + r = cc.normRed(); + g = cc.normGreen(); + b = cc.normBlue(); + a = cc.normAlpha(); +} + +SColorRGB::SColorRGB(const SColorHCY &hcy) +{ + ColorSpaces::vec3 vhcy{{hcy.h, hcy.c, hcy.y}}; + ColorSpaces::vec3 vrgb = ColorSpaces::hcy_to_rgb(vhcy); + r = vrgb[0]; + g = vrgb[1]; + b = vrgb[2]; + a = hcy.a; +} + +CColor SColorRGB::toColor() const +{ + CColor cc; + cc.setNormRed(r); + cc.setNormGreen(g); + cc.setNormBlue(b); + cc.setNormAlpha(a); + return cc; +} + +SColorHCY::SColorHCY(const SColorRGB &rgb) +{ + ColorSpaces::vec3 vrgb{{rgb.r, rgb.g, rgb.b}}; + ColorSpaces::vec3 vhcy = ColorSpaces::rgb_to_hcy(vrgb); + h = vhcy[0]; + c = vhcy[1]; + y = vhcy[2]; + a = rgb.a; +} diff --git a/plugins/editor/src/editor/ColorHelpers.h b/plugins/editor/src/editor/ColorHelpers.h new file mode 100644 index 00000000..fd484799 --- /dev/null +++ b/plugins/editor/src/editor/ColorHelpers.h @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: BSD-2-Clause + +// This code is part of the sfizz library and is licensed under a BSD 2-clause +// license. You should have receive a LICENSE.md file along with the code. +// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz + +#pragma once +#include "vstgui/lib/ccolor.h" + +using namespace VSTGUI; + +struct SColorRGB; +struct SColorHCY; + +struct SColorRGB { + SColorRGB() = default; + explicit SColorRGB(const CColor &cc); + explicit SColorRGB(const SColorHCY &hcy); + SColorRGB(float r, float g, float b, float a = 1.0) : r(r), g(g), b(b), a(a) {} + CColor toColor() const; + + float r {}, g {}, b {}, a { 1.0 }; +}; + +struct SColorHCY { + SColorHCY() = default; + explicit SColorHCY(const CColor &cc) : SColorHCY(SColorRGB(cc)) {} + explicit SColorHCY(const SColorRGB &rgb); + SColorHCY(float h, float c, float y, float a = 1.0) : h(h), c(c), y(y), a(a) {} + CColor toColor() const { return SColorRGB(*this).toColor(); } + + float h {}, c {}, y {}, a { 1.0 }; +};