Skip to content

Commit 711f76d

Browse files
cmaughansamaaron
authored andcommitted
API
This is a substantial change to the connection between the Qt GUI and the server. A new API library acts as the go between. This CL also introduces a simple test UI written in ImGui as a client to the API. The API is a static library and is currently responsible for: - Finding and initializing paths for logs, etc. - Finding and checking ports - Running various ruby scripts, including the server - Connecting to the supercollider audio api. - Handling incoming osc messages - Detecting startup and shutdown errors - Shutting down the server and osc handler The API does not yet codify all the outward communication to the server, but it does provide a SendOSC method. Eventually it will have type-safe APIs for all communication to the server. Some APIs such as SaveAndRunBuffer, and SaveWorkspaces are implemented, and form the template for the rest of them. The ImGui API has: - A simple editor window, loaded with workspaces - A scope showing the the spectrum analysis - Windows for logs, midi and cues - The ability to run/stop the current text buffer - Shortcut keys ALT+R/ALT+S and a buffer flash to show evaluation The GUI runs best on Windows, but works on Mac/Linux too (it needs some further work for DPI/scaling and window loading support) There is also now a simple unit test application which is run as a github action. This is capable of starting a headless version of SonicPi and playing a note on a virtual audio device. It ensures that on all 3 platforms the API can get to the point where Sonic Pi has been initialized and is ready for playing music. This CL swaps over to using the API from the Qt Gui, but it can work the old way for now by uncommenting QT_OLD_API in the root CMakeLists file (the API and API Gui are always built, this just changes how the main Gui works). The new code contains a streamlined version of the Scope window without all the thread extras, and some more cleanup. - The api uses vcpkg for package management; it is a better system for C++ libraries. It has been tested on Mac/Windows/Linux The sensitve changes in this CL are: - The process management uses a library called reproc; because the API no longer links to Qt. This means that the process loading code is different, although it follows the same flows as before. - The management of the supercollider audio callback is different.
1 parent f2f2580 commit 711f76d

File tree

129 files changed

+92333
-1149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+92333
-1149
lines changed

.github/workflows/build.yml

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Build
22

33
on:
44
push:
5-
branches: [ dev, main, workflow_dispatch, features/new-layout-and-api ]
5+
branches: [ dev, main, workflow_dispatch, features/sp-api ]
66
pull_request:
7-
branches: [ dev, main, workflow_dispatch, features/new-layout-and-api ]
7+
branches: [ dev, main, workflow_dispatch, features/sp-api ]
88

99
jobs:
1010
build:
@@ -97,7 +97,7 @@ jobs:
9797
CC: ${{ matrix.cc }}
9898
QT_INSTALL_LOCATION: ${{env.Qt5_DIR}}
9999
run: |
100-
sudo apt install -y libssl-dev ruby-dev supercollider-server sc3-plugins-server alsa-utils jackd2 libjack-jackd2-dev libjack-jackd2-0 libasound2-dev librtmidi-dev pulseaudio-module-jack
100+
sudo apt install -y pulseaudio dbus-x11 libssl-dev ruby-dev supercollider-server sc3-plugins-server alsa-utils jackd2 libjack-jackd2-dev libjack-jackd2-0 libasound2-dev librtmidi-dev pulseaudio-module-jack
101101
./linux-prebuild.sh --build-aubio
102102
if: matrix.os == 'ubuntu-latest'
103103

@@ -163,4 +163,44 @@ jobs:
163163
run: rake test
164164
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
165165

166+
- name: API Tests - Mac
167+
working-directory: ${{github.workspace}}/app/build/api-tests
168+
run: ctest --verbose
169+
if: matrix.os == 'macos-latest'
170+
171+
- name: API Tests - Linux
172+
working-directory: ${{github.workspace}}/app/build/api-tests
173+
run: |
174+
jackd -d dummy &
175+
ctest --verbose
176+
if: matrix.os == 'ubuntu-latest'
177+
178+
- name: API Tests Windows - Install Scream Audio Device
179+
shell: powershell
180+
run: |
181+
Start-Service audio*
182+
Invoke-WebRequest https://github.com/duncanthrax/scream/releases/download/3.6/Scream3.6.zip -OutFile C:\Scream3.6.zip
183+
Extract-7Zip -Path C:\Scream3.6.zip -DestinationPath C:\Scream
184+
$cert = (Get-AuthenticodeSignature C:\Scream\Install\driver\Scream.sys).SignerCertificate
185+
$store = [System.Security.Cryptography.X509Certificates.X509Store]::new("TrustedPublisher", "LocalMachine")
186+
$store.Open("ReadWrite")
187+
$store.Add($cert)
188+
$store.Close()
189+
cd C:\Scream\Install\driver
190+
C:\Scream\Install\helpers\devcon install Scream.inf *Scream
191+
if: matrix.os == 'windows-latest'
192+
193+
- name: API Tests - Windows
194+
shell: cmd
195+
working-directory: ${{github.workspace}}/app/build/api-tests
196+
run: ctest --verbose
197+
if: matrix.os == 'windows-latest'
198+
199+
- name: Archive Logs
200+
uses: actions/upload-artifact@v2
201+
with:
202+
name: Logs_${{matrix.title}}_${{matrix.build_type}}
203+
path: |
204+
~/.sonic-pi/log/*.log
205+
166206

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ build32
3232
# Core dumps
3333
*.dump
3434

35+
# Ignore vcpkg
36+
app/vcpkg
37+
3538
# QT GUI
3639
# --------
3740

app/CMakeLists.txt

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
11
cmake_minimum_required(VERSION 3.13)
22

3-
project(SonicPi)
3+
message(STATUS " CMakeLists: Sonic Pi")
4+
5+
# Sonic Pi Requires a C++ 17 Compiler to build it
6+
set(CMAKE_CXX_STANDARD 17)
7+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
8+
9+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
10+
11+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
12+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
13+
14+
#set (QT_OLD_API 1)
15+
16+
if(APPLE)
17+
set(CMAKE_OSX_DEPLOYMENT_TARGET '10.13')
18+
endif()
419

520
set(APP_ROOT ${CMAKE_CURRENT_LIST_DIR})
621

7-
add_subdirectory(api)
22+
# Different triplet for windows
23+
if (WIN32)
24+
set(VCPKG_TARGET_TRIPLET x64-windows-static-md CACHE STRING "triplet")
25+
endif()
826

27+
# vcpkg toolchain - Must be declared before project
28+
set(CMAKE_TOOLCHAIN_FILE ${APP_ROOT}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file")
29+
30+
project(SonicPi)
31+
32+
list(APPEND CMAKE_MODULE_PATH ${APP_ROOT}/cmake)
33+
include(cmake/utils.cmake)
34+
include(cmake/common.cmake)
35+
36+
configure_file(${APP_ROOT}/cmake/config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
37+
38+
add_subdirectory(api)
39+
add_subdirectory(api-tests)
940
add_subdirectory(gui)
1041

app/api-tests/CMakeLists.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
project(api-tests)
2+
3+
set(TESTS_ROOT ${CMAKE_CURRENT_LIST_DIR})
4+
5+
find_package(Catch2 CONFIG REQUIRED)
6+
7+
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
8+
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
9+
10+
list(APPEND TEST_SOURCES
11+
${TESTS_ROOT}/CMakeLists.txt
12+
${TESTS_ROOT}/main.cpp)
13+
14+
file(GLOB_RECURSE FOUND_TEST_SOURCES "${APP_ROOT}/*.test.cpp")
15+
16+
enable_testing()
17+
18+
set (TEST_SOURCES
19+
${FOUND_TEST_SOURCES}
20+
${TEST_SOURCES}
21+
)
22+
23+
add_executable(${PROJECT_NAME} ${TEST_SOURCES})
24+
25+
target_include_directories(${PROJECT_NAME} PRIVATE
26+
${CMAKE_BINARY_DIR}
27+
include
28+
)
29+
30+
31+
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
32+
find_package(Threads REQUIRED)
33+
set(PLATFORM_LINKLIBS
34+
Threads::Threads
35+
)
36+
endif()
37+
38+
target_link_libraries(${PROJECT_NAME}
39+
PRIVATE
40+
SonicPi::API
41+
Catch2::Catch2
42+
${PLATFORM_LINKLIBS}
43+
${CMAKE_THREAD_LIBS_INIT})
44+
45+
add_test(${PROJECT_NAME} ${PROJECT_NAME})
46+
47+
SOURCE_GROUP(tests REGULAR_EXPRESSION ".*.test.(cpp|h)+")
48+
SOURCE_GROUP(tests FILES ${TEST_SOURCES})
49+

app/api-tests/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define CATCH_CONFIG_MAIN
2+
#include "catch2/catch.hpp"

app/api-tests/tests.runsettings

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RunSettings>
3+
<!-- Configurations that affect the Test Framework -->
4+
<RunConfiguration>
5+
<MaxCpuCount>4</MaxCpuCount>
6+
<ResultsDirectory>.\TestResults</ResultsDirectory><!-- Path relative to solution directory -->
7+
<TestSessionTimeout>60000</TestSessionTimeout><!-- Milliseconds -->
8+
</RunConfiguration>
9+
10+
<!-- Adapter Specific sections -->
11+
12+
<!-- Catch2 adapter -->
13+
<Catch2Adapter disabled="false">
14+
<DebugBreak>on</DebugBreak>
15+
<DiscoverTimeout>500</DiscoverTimeout>
16+
<FilenameFilter>^api-tests</FilenameFilter>
17+
<IncludeHidden>true</IncludeHidden>
18+
<Logging>Normal</Logging>
19+
<MessageFormat>StatsOnly</MessageFormat>
20+
<StackTraceFormat>ShortInfo</StackTraceFormat>
21+
<StackTracePointReplacement>,</StackTracePointReplacement>
22+
<TestCaseTimeout>20000</TestCaseTimeout><!-- Milliseconds -->
23+
<WorkingDirectory></WorkingDirectory>
24+
<WorkingDirectoryRoot>Executable</WorkingDirectoryRoot>
25+
</Catch2Adapter>
26+
27+
</RunSettings>

app/api/CMakeLists.txt

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,101 @@
1-
project(SonicPiAPI VERSION 0.0.0.1)
1+
project(sonic-pi-api VERSION 0.0.0.1)
22

33
set(API_ROOT ${CMAKE_CURRENT_LIST_DIR})
44

5-
set(API_SRC ${API_ROOT}/src/api.cpp)
5+
set(API_SRC
6+
${API_ROOT}/src/sonicpi_api.cpp
7+
${API_ROOT}/src/string_utils.cpp
8+
${API_ROOT}/src/file_utils.cpp
69

7-
add_library(${PROJECT_NAME} STATIC ${API_SRC})
8-
add_library(SonicPi::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
10+
${API_ROOT}/include/api/string_utils.h
11+
${API_ROOT}/include/api/file_utils.h
12+
${API_ROOT}/include/api/logger.h
13+
14+
${APP_ROOT}/external/TLSF-2.4.6/src/tlsf.c
15+
)
16+
17+
set(OSC_SRC
18+
# Osc
19+
${API_ROOT}/src/osc/osc_handler.cpp
20+
${API_ROOT}/src/osc/osc_sender.cpp
21+
${API_ROOT}/src/osc/osc_server.cpp
22+
${API_ROOT}/src/osc/tcp_osc_server.cpp
23+
${API_ROOT}/src/osc/udp_osc_server.cpp
24+
25+
${API_ROOT}/include/api/osc/osc_handler.h
26+
${API_ROOT}/include/api/osc/osc_sender.h
27+
${API_ROOT}/include/api/osc/osc_server.h
28+
${API_ROOT}/include/api/osc/tcp_osc_server.h
29+
${API_ROOT}/include/api/osc/udp_osc_server.h
30+
${API_ROOT}/include/api/osc/osc_pkt.hh
31+
${API_ROOT}/include/api/osc/udp.hh
32+
)
33+
34+
set(BUFFER_SRC
35+
${API_ROOT}/src/audio/audio_processor.cpp
36+
${API_ROOT}/include/api/audio/audio_processor.h
37+
${API_ROOT}/include/api/audio/scope_buffer.hpp
38+
${API_ROOT}/include/api/audio/server_shm.hpp)
39+
40+
add_library(${PROJECT_NAME} STATIC ${API_SRC} ${OSC_SRC} ${BUFFER_SRC})
41+
add_library(SonicPi::API ALIAS ${PROJECT_NAME})
42+
43+
# For finding home path, etc.
44+
find_package(platform_folders CONFIG REQUIRED)
45+
46+
# For running child processes
47+
find_package(reproc CONFIG REQUIRED)
48+
find_package(reproc++ CONFIG REQUIRED)
49+
50+
find_package(unofficial-kissfft CONFIG REQUIRED)
951

1052
target_include_directories(${PROJECT_NAME}
1153
PUBLIC
1254
${API_ROOT}/include
55+
${APP_ROOT}/external/ghc_filesystem/include
56+
PRIVATE
57+
${APP_ROOT}/external
58+
${APP_ROOT}/external/scsynth-boost-1.74.0
59+
${APP_ROOT}/external/TLSF-2.4.6/src
60+
)
61+
62+
target_link_libraries(${PROJECT_NAME}
63+
PRIVATE
64+
sago::platform_folders
65+
reproc
66+
reproc++
67+
unofficial::kissfft::kissfft
68+
)
69+
70+
# Windows
71+
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
72+
find_package(crossguid CONFIG REQUIRED)
73+
target_link_libraries(${PROJECT_NAME}
74+
PRIVATE
75+
crossguid
76+
)
77+
endif()
78+
79+
# Linux
80+
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
81+
find_package(crossguid CONFIG REQUIRED)
82+
target_link_libraries(${PROJECT_NAME}
83+
PUBLIC
84+
stdc++fs
85+
PRIVATE
86+
crossguid
1387
)
88+
endif()
89+
90+
# Mac
91+
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
92+
target_link_libraries(${PROJECT_NAME}
93+
PRIVATE
94+
)
95+
endif()
96+
97+
target_compile_definitions(${PROJECT_NAME} PUBLIC _CRT_SECURE_NO_WARNINGS _WINSOCK_DEPRECATED_NO_WARNINGS BOOST_DATE_TIME_NO_LIB WIN32_LEAN_AND_MEAN)
98+
99+
source_group ("Api" FILES ${API_SRC})
100+
source_group ("Api\\Osc" FILES ${OSC_SRC})
101+
source_group ("Api\\Audio" FILES ${BUFFER_SRC})

app/api/TODO.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
API TODO:
2+
3+
Fix mac deploy target back to .13 and substitute filesystem
4+
Fix win thread priority
5+
Add TCP functionality for future
6+
More unit tests
7+
Figure out CI for Windows virtual audio device

app/api/include/api/api.h

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)