Skip to content

Commit

Permalink
Merged Vkav v0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Dougal-s committed Jan 30, 2021
1 parent 3611558 commit 6217b8c
Show file tree
Hide file tree
Showing 86 changed files with 1,730 additions and 1,226 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ IncludeCategories:
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentPPDirectives: BeforeHash
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
Expand Down
113 changes: 81 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.12)

project(Vkav VERSION 0.5.0 LANGUAGES CXX)
project(Vkav VERSION 0.6.0 LANGUAGES CXX)

configure_file(include/Version.hpp.in Version.hpp)

Expand All @@ -12,13 +12,13 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

add_compile_options(
"$<$<CONFIG:DEBUG>:-O0;-g3;-ggdb;-Wall;-Wextra>"
"$<$<CONFIG:ASAN>:-O0;-g3;-ggdb;-Wall;-Wextra;-fno-omit-frame-pointer;-fsanitize=address>"
"$<$<CONFIG:RELEASE>:-O3;-march=native;-DNDEBUG>"
"$<$<CONFIG:DEBUG>:-O0;-g3;-ggdb;-Wall;-Wextra;-Wpedantic>"
"$<$<CONFIG:ASAN>:-O0;-g3;-ggdb;-Wall;-Wextra;-fno-omit-frame-pointer;-fsanitize=address>"
"$<$<CONFIG:RELEASE>:-O3;-DNDEBUG>"
)

add_link_options(
"$<$<CONFIG:ASAN>:-fno-omit-frame-pointer;-fsanitize=address>"
"$<$<CONFIG:ASAN>:-fno-omit-frame-pointer;-fsanitize=address>"
)

# Platform specific flags
Expand All @@ -44,17 +44,11 @@ if (NOT DEFINED AUDIO_BACKEND)
endif()


add_library(audioModule
src/CoreAudio.cpp
src/PulseAudio.cpp
src/PulseAudioAsync.cpp
src/WASAPI.cpp
src/libsoundio.cpp
)
add_library(audioModule)
target_include_directories(audioModule PRIVATE include)

if (${AUDIO_BACKEND} MATCHES COREAUDIO)
target_compile_definitions(audioModule PRIVATE -DCOREAUDIO)
target_sources(audioModule PRIVATE src/CoreAudio.cpp)
find_library(coreAudio CoreAudio)
if (NOT coreAudio)
message(FATAL_ERROR "Unable to locate CoreAudio!")
Expand All @@ -67,21 +61,21 @@ elseif (${AUDIO_BACKEND} MATCHES PULSEAUDIO)
endif()
find_library(pulseAudioSimple pulse-simple)
if (pulseAudioSimple)
target_compile_definitions(audioModule PRIVATE -DPULSEAUDIO)
target_sources(audioModule PRIVATE src/PulseAudio.cpp)
target_link_libraries(audioModule PRIVATE ${pulseAudioSimple} -lpthread)
else()
target_compile_definitions(audioModule PRIVATE -DPULSEAUDIO_ASYNC)
target_sources(audioModule PRIVATE src/PulseAudioAsync.cpp)
endif()
target_link_libraries(audioModule PRIVATE ${pulseAudio})
elseif (${AUDIO_BACKEND} MATCHES WASAPI)
target_compile_definitions(audioModule PRIVATE -DWASAPI)
target_sources(audioModule PRIVATE src/WASAPI.cpp)
find_library(WASAPI wasapi)
if (NOT WASAPI)
message(FATAL_ERROR "Unable to locate WASAPI!")
endif()
target_link_libraries(audioModule PRIVATE ${WASAPI})
elseif (${AUDIO_BACKEND} MATCHES LIBSOUNDIO)
target_compile_definitions(audioModule PRIVATE -DLIBSOUNDIO)
target_sources(audioModule PRIVATE src/libsoundio.cpp)
find_library(libsoundio soundio)
find_path(libsoundioIncludeDir NAMES soundio/soundio.h)
if (NOT libsoundio)
Expand All @@ -94,8 +88,8 @@ endif()
add_library(graphicsModule
src/Render.cpp
src/Image.cpp
src/X11.cpp
src/Calculate.cpp
src/ModuleConfig.cpp
)
target_include_directories(graphicsModule
PRIVATE
Expand All @@ -116,23 +110,27 @@ else()
target_link_libraries(graphicsModule PRIVATE ${GLFW})
endif()

set(VULKAN_SDK_LIB_PATH "/usr/lib/x86_64-linux-gnu")
set(VULKAN_SDK_LAYER_PATH "/usr/share/vulkan/explicit_layer.d")

if (DEFINED VULKAN_SDK_PATH)
if (${CMAKE_SYSTEM_NAME} MATCHES Linux)
target_include_directories(graphicsModule PRIVATE ${VULKAN_SDK_PATH}/x86_64/include)
target_link_libraries(graphicsModule PRIVATE -L${VULKAN_SDK_PATH}/x86_64/lib)
target_link_libraries(graphicsModule PRIVATE vulkan)
set(VULKAN_SDK_LIB_PATH ${VULKAN_SDK_PATH}/x86_64/lib)
set(VULKAN_SDK_LAYER_PATH ${VULKAN_SDK_PATH}/x86_64/etc/vulkan/explicit_layer.d)

set(VULKAN_SDK_LIB_PATH "${VULKAN_SDK_PATH}/x86_64/lib")
set(VULKAN_SDK_LAYER_PATH "${VULKAN_SDK_PATH}/x86_64/etc/vulkan/explicit_layer.d")

set(ENV_VARS LD_LIBRARY_PATH=${VULKAN_SDK_LIB_PATH} VK_LAYER_PATH=${VULKAN_SDK_LAYER_PATH})
elseif (${CMAKE_SYSTEM_NAME} MATCHES Windows)
elseif (${CMAKE_SYSTEM_NAME} MATCHES Darwin)
target_include_directories(graphicsModule PRIVATE ${VULKAN_SDK_PATH}/macOS/include)
target_link_libraries(graphicsModule PRIVATE -L${VULKAN_SDK_PATH}/macOS/lib)
target_link_libraries(graphicsModule PRIVATE vulkan)
set(VULKAN_ICD_FILENAMES ${VULKAN_SDK_PATH}/macOS/etc/vulkan/icd.d/MoltenVK_icd.json)
set(VULKAN_SDK_LAYER_PATH ${VULKAN_SDK_PATH}/macOS/etc/vulkan/explicit_layer.d)

set(VULKAN_ICD_FILENAMES "${VULKAN_SDK_PATH}/macOS/etc/vulkan/icd.d/MoltenVK_icd.json")
set(VULKAN_SDK_DYLIB_PATH "${VULKAN_SDK_PATH}/macOS/lib:$DYLD_LIBRARY_PATH")
set(VULKAN_SDK_LAYER_PATH "${VULKAN_SDK_PATH}/macOS/etc/vulkan/explicit_layer.d")

set(ENV_VARS VK_ICD_FILENAMES=${VULKAN_ICD_FILENAMES} DYLD_LIBRARY_PATH=${VULKAN_SDK_LIB_PATH} VK_LAYER_PATH=${VULKAN_SDK_LAYER_PATH})
endif()
else()
find_package(Vulkan REQUIRED)
Expand All @@ -143,7 +141,8 @@ option(INCLUDE_X11 "Include X11 for extra functionality on X11 systems" ON)
if (INCLUDE_X11)
find_package(X11)
if (${X11_FOUND})
target_compile_definitions(graphicsModule PRIVATE -DNATIVE_WINDOW_HINTS_SUPPORTED -DX11)
target_compile_definitions(graphicsModule PRIVATE -DNATIVE_WINDOW_HINTS_SUPPORTED)
target_sources(graphicsModule PRIVATE src/X11.cpp)
target_include_directories(graphicsModule PRIVATE ${X11_INCLUDE_DIR})
target_link_libraries(graphicsModule PRIVATE ${X11_LIBRARIES})
endif()
Expand All @@ -168,7 +167,7 @@ endif()

add_executable(vkav
src/Vkav.cpp
src/Proccess.cpp
src/Process.cpp
src/Settings.cpp
src/Data.cpp
src/Calculate.cpp
Expand All @@ -183,8 +182,8 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION MATCHES
target_link_libraries(vkav -lstdc++fs)
endif()

if (NOT ${CMAKE_SYSTEM_NAME} MATCHES Windows AND ${CMAKE_BUILD_TYPE} MATCHES release)
add_custom_command(TARGET vkav POST_BUILD COMMAND strip --strip-all vkav)
if (${CMAKE_BUILD_TYPE} MATCHES Release)
add_custom_command(TARGET vkav POST_BUILD COMMAND ${CMAKE_STRIP} vkav)
endif()

# Installer
Expand Down Expand Up @@ -213,12 +212,62 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES Windows)
elseif (${CMAKE_SYSTEM_NAME} MATCHES Darwin)
endif()

# For formatting source code
# compile modules
if (NOT DEFINED GLSLC_PATH)
if (DEFINED VULKAN_SDK_PATH)
set(GLSLC_PATH ${VULKAN_SDK_PATH}/x86_64/bin/glslc)
else()
set(GLSLC_PATH glslc)
endif()
endif()

add_custom_target(shaders)
function(add_module MODULE STAGES)
string(REPLACE " " "_" MODULE_NAME "${MODULE}")
add_custom_target(${MODULE_NAME})
foreach(STAGE RANGE 1 ${STAGES})
if (EXISTS "${CMAKE_SOURCE_DIR}/src/modules/${MODULE}/${STAGE}/shader.vert")
set(VERT_COMMAND ${GLSLC_PATH} -O shader.vert -o vert.spv)
else()
set(VERT_COMMAND "")
endif()

add_custom_target(
${MODULE_NAME}_STAGE_${STAGE}
COMMAND ${GLSLC_PATH} -O shader.frag -o frag.spv
COMMAND ${VERT_COMMAND}
BYPRODUCTS frag.spv vert.spv
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/src/modules/${MODULE}/${STAGE}"
)
add_dependencies(${MODULE_NAME} ${MODULE_NAME}_STAGE_${STAGE})
endforeach()
add_dependencies(shaders ${MODULE_NAME})
endfunction()

add_module(background 1)
add_module(bars 1)
add_module(eclipse 2)
add_module(fragment 1)
add_module(logo 1)
add_module(mist 1)
add_module(octahedron 1)
add_module("octahedron 2" 3)
add_module(orbital 1)
add_module(radial 1)
add_module(rings 1)

# Formatting source code
file(GLOB src
"include/*.h"
"src/*.cpp"
)

add_custom_target(format clang-format -style=file -i ${src})

add_custom_target(run VK_ICD_FILENAMES=${VULKAN_ICD_FILENAMES} LD_LIBRARY_PATH=${VULKAN_SDK_LIB_PATH} VK_LAYER_PATH=${VULKAN_SDK_LAYER_PATH} ./vkav)
add_custom_target(run ${ENV_VARS} ./vkav)

# Unit Tests
option(BUILD_TESTS "Build unit tests" OFF)
if (BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Dougal Stewart
Copyright (c) 2021 Dougal Stewart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 3 additions & 4 deletions MacOS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ Once you have installed the [Vulkan SDK](https://vulkan.lunarg.com/sdk/home#mac)
```
$ ./build.sh VULKAN_SDK_PATH
```
where `VULKAN_SDK_PATH` is the absolute path to the vulkan sdk, in order to create the .app bundle.
Once that is done, vkav can be installed by moving the .app bundle into the applications directory.
where `VULKAN_SDK_PATH` is the absolute path to the vulkan sdk. The script will build a .app bundle which can
then be installed to the applications directory.
*Note: the script does not package application dependencies*

You may want to create a symlink from `/usr/local/bin` to `Vkav.app/Contents/Macos/start.sh` so that
you can run vkav from the command line and pass command line arguments.
You may want to create a symlink from `/usr/local/bin` to `Vkav.app/Contents/Macos/start.sh` to allow vkav to be run from the command line.
4 changes: 2 additions & 2 deletions MacOS/Vkav.app/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.5.0</string>
<string>0.6.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>0.5.0</string>
<string>0.6.0</string>
</dict>
</plist>
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ To install the config files to a user accessible location, run:
```
$ vkav --install-config
```
This will copy the config files from "/etc/Vkav" to "~/.config/Vkav".
This will copy the config files from "/etc/vkav" to "~/.config/vkav".


#### MacOS (>= 10.15):
Expand Down Expand Up @@ -86,7 +86,7 @@ To run Vkav simply execute:
$ vkav
```

Config files can be located in "~/.config/vkav" on Linux and in ~/Library/Preferences/vkav on MacOS
Config files can be located in "~/.config/vkav" on Linux and "~/Library/Preferences/vkav" on MacOS
once the user has executed `Vkav --install-config`.

## License
Expand Down
2 changes: 1 addition & 1 deletion deb-package/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ mkdir "vkav/usr/share/applications"
cp "../vkav.desktop" "vkav/usr/share/applications"

dpkg-deb --build vkav
mv ./vkav.deb ./vkav_0.5.0_$(uname -m).deb
mv ./vkav.deb ./vkav_0.6.0_$(uname -m).deb
2 changes: 1 addition & 1 deletion deb-package/vkav/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: vkav
Version: 0.5-1
Version: 0.6-1
Section: base
Priority: optional
Architecture: amd64
Expand Down
28 changes: 15 additions & 13 deletions include/Audio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,33 @@
#include <string>
struct AudioData;

struct AudioSettings {
unsigned char channels = 2;
size_t sampleSize = 64;
size_t bufferSize = 2048;
uint32_t sampleRate = 5625;
std::string sinkName;
};

class AudioSampler {
public:
struct Settings {
unsigned char channels = 2;
size_t sampleSize = 64;
size_t bufferSize = 2048;
uint32_t sampleRate = 5625;
std::string sinkName;
};

AudioSampler() = default;
AudioSampler(const Settings& audioSettings);
~AudioSampler();

AudioSampler& operator=(AudioSampler&& other) noexcept;

bool running() const;
bool modified() const;
int ups() const;

void start(const AudioSettings& audioSettings);

void stop();

void copyData(AudioData& audioData);

void rethrowExceptions();

private:
class AudioSamplerImpl;
AudioSamplerImpl* audioSamplerImpl;
AudioSamplerImpl* audioSamplerImpl = nullptr;
};

#endif
4 changes: 2 additions & 2 deletions include/Calculate.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <string>
#include <string_view>

template <class NumType>
NumType calculate(const std::string& expression);
NumType calculate(std::string_view expression);
2 changes: 1 addition & 1 deletion include/Data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct AudioData {

AudioData();

void allocate(size_t bufferSize, size_t lrBufferSize);
void allocate(size_t channels, size_t channelSize);

~AudioData();
};
Expand Down
45 changes: 45 additions & 0 deletions include/ModuleConfig.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <iosfwd>
#include <optional>
#include <stdexcept>
#include <string>
#include <variant>
#include <vector>

class ParseException : private std::runtime_error {
uint32_t m_line;
public:
ParseException(const std::string& what_arg, uint32_t line) : std::runtime_error(what_arg), m_line{line} {}
ParseException(const char* what_arg, uint32_t line) : std::runtime_error(what_arg), m_line{line} {}
ParseException(const ParseException& other) noexcept : std::runtime_error(other), m_line{other.m_line} {};

ParseException& operator=(const ParseException& other) noexcept {
std::runtime_error::operator=(other);
m_line = other.m_line;
return *this;
}

virtual const char* what() const noexcept { return std::runtime_error::what(); }

uint32_t line() const noexcept { return m_line; }
};

struct ModuleConfig {
struct Parameter {
uint32_t id;
std::variant<uint32_t, int32_t, float> value;
};

struct Resource {
uint32_t id;
std::string path;
};

std::optional<std::string> moduleName;
std::optional<uint32_t> vertexCount;

std::vector<Parameter> params;

std::vector<Resource> images;
};

ModuleConfig parseConfig(std::istream& stream);
Loading

0 comments on commit 6217b8c

Please sign in to comment.