Skip to content

Commit

Permalink
Merge branch 'dev' into gabberkick_synth
Browse files Browse the repository at this point in the history
  • Loading branch information
samaaron authored Oct 9, 2023
2 parents 3356b5a + 329ab58 commit 0a11266
Show file tree
Hide file tree
Showing 2,444 changed files with 200,079 additions and 63,119 deletions.
44 changes: 44 additions & 0 deletions SYNTH_DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,47 @@ Lastly, as with built-in synths, you would call the synth by name with a symbol.
Eg: `synth :piTest`.

We look forward to hearing about your synth and FX creations - have fun!

## Gated synths

As described above, standard Sonic Pi synths always self-terminate. That is, they have an ADSR envelope with a finite duration, so they finish, and then they are automatically cleaned up from memory. This is a design decicision which aims at preventing users from starting synths that never terminate and finally fill up processor and memory.

Gated synths are non-standard in Sonic Pi. They use an envelope that is kept open at sustain level at a defined *release node* until a special parameter, the *gate* is set to 0. Only then they start the release phase after which they finally terminate. At this point they are cleaned up, just like the standard synths. The problem with gated synths is that you have to have a handle on a synth, so that later you can ``control`` the gate to 0. You obtain this handle by assigning the result from ``play`` or ``synth`` to a variable, like so:

```
a = play 60
```

On the contrary, if you miss this assignment, there will be no way to control the synth and set the gate to 0, so it will run forever, and the only way to stop it is to stop the entire run.

However, gated synths can be fun, especially with external MIDI keyboards. The expected behaviour for playing music over a keyboard would be as described above: When the key is hit, the envelope progresses through the attack and decay phases, but it is kept at sustain level until the key is released.

Sonic Pi comes with gated synths, but they are not directly accessible as standard synths, nor are they listed in the built-in help system. If you want to use them, you can find the sources in these directories

```
etc/synthdefs/designs/overtone/sonic-pi/src/sonic_pi/gated
etc/synthdefs/designs/supercollider/gated
```
and the compiled ones in

```
etc/synthdefs/compiled/gated
```

Using them requires loading them. A simple usage example would be:

```
load_synthdefs "<<path-to-your-sonic-pi-repo-fork>>/etc/synthdefs/compiled/gated"
use_synth 'sonic-pi-fm_gated'
sth = play 43
sleep 4
control sth, gate: 0
```

Some final notes:

- It is perfectly possible to play the standards synths with a MIDI keyboard. Using gated synths is a bit more straightforward, e. g. when trying to get the synth to use the release phase as selected with the `release:` parameter. Look for "MIDI keyboard" on [in-thread](https://in-thread.sonic-pi.net/) for examples of how a MIDI keyboard handler can be made, with or without gated synths.

- Some synths have been left out on purpose. The `:dull_bell` and `:pretty_bell` synths depend on the interrelations of the envelopes of their partials and no reasonable way of adding a gate parameter was found. Also, merely percussive synths like the SC808 group of synths were not enabled to be used with a gate.

- On some synths, e. g. `:kalimba`, it is necessary to reduce the default `:release` in order for the gate to take effect.
2 changes: 1 addition & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

option(WITH_QT_GUI_WEBENGINE "Include experimental webengine functionality" ON)
option(WITH_QT_GUI_WEBENGINE "Include experimental webengine functionality" OFF)

set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})

Expand Down
2 changes: 1 addition & 1 deletion app/external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
include(GNUInstallDirs)
include(ExternalProject)

set(CMAKE_OSX_DEPLOYMENT_TARGET '10.15')
set(CMAKE_OSX_DEPLOYMENT_TARGET "13")

# sp_midi
ExternalProject_Add(sp_midi
Expand Down
66 changes: 66 additions & 0 deletions app/external/sp_link/external_libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
cmake_minimum_required(VERSION 3.0)
project(Link)

set(ERLANG_INCLUDE_PATH "/usr/local/lib/erlang/usr/include" CACHE PATH "Path to erlang includes")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# ___ _ _
# / _ \ _ __ | |_(_) ___ _ __ ___
# | | | | '_ \| __| |/ _ \| '_ \/ __|
# | |_| | |_) | |_| | (_) | | | \__ \
# \___/| .__/ \__|_|\___/|_| |_|___/
# |_|

# Note: Please use the LINK_* prefix for all project-specific options

if(UNIX)
option(LINK_ENABLE_ASAN "Build with Address Sanitizier (ASan)" OFF)
option(LINK_BUILD_JACK "Build example applications with JACK support" OFF)
endif()

if(WIN32)
option(LINK_BUILD_ASIO "Build example applications with ASIO driver" ON)
option(LINK_BUILD_VLD "Build with VLD support (VLD must be installed separately)" OFF)
endif()

# ____ _ _
# | _ \ __ _| |_| |__ ___
# | |_) / _` | __| '_ \/ __|
# | __/ (_| | |_| | | \__ \
# |_| \__,_|\__|_| |_|___/
#

# Other CMake files must be included only after declaring build options
include(cmake_include/ConfigureCompileFlags.cmake)
include(cmake_include/CatchConfig.cmake)
include(AbletonLinkConfig.cmake)
include(extensions/abl_link/abl_link.cmake)

add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(examples)
add_subdirectory(extensions/abl_link)

# ____
# / ___| _ _ _ __ ___ _ __ ___ __ _ _ __ _ _
# \___ \| | | | '_ ` _ \| '_ ` _ \ / _` | '__| | | |
# ___) | |_| | | | | | | | | | | | (_| | | | |_| |
# |____/ \__,_|_| |_| |_|_| |_| |_|\__,_|_| \__, |
# |___/

message(STATUS "Build options")

get_cmake_property(all_variables VARIABLES)
string(REGEX MATCHALL "(^|;)LINK_[A-Z_]+" link_variables "${all_variables}")
foreach(variable ${link_variables})
message(" ${variable}: ${${variable}}")
endforeach()

message(STATUS "Build configuration")

if(CMAKE_BUILD_TYPE)
message(" Build type: ${CMAKE_BUILD_TYPE}")
else()
message(" Build type: Set by IDE")
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|kFreeBSD|GNU")
INTERFACE_COMPILE_DEFINITIONS
LINK_PLATFORM_LINUX=1
)
set_property(TARGET Ableton::Link APPEND PROPERTY
INTERFACE_LINK_LIBRARIES
atomic
pthread
)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/cmake_include/AsioStandaloneConfig.cmake)
Expand Down
9 changes: 6 additions & 3 deletions app/external/sp_link/external_libs/link/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.5)
project(Link)

set(ERLANG_INCLUDE_PATH "/usr/local/lib/erlang/usr/include" CACHE PATH "Path to erlang includes")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# ___ _ _
Expand All @@ -24,6 +22,8 @@ if(WIN32)
option(LINK_BUILD_VLD "Build with VLD support (VLD must be installed separately)" OFF)
endif()

option(LINK_BUILD_TESTS "Build unit test binaries" ON)

# ____ _ _
# | _ \ __ _| |_| |__ ___
# | |_) / _` | __| '_ \/ __|
Expand All @@ -38,7 +38,9 @@ include(AbletonLinkConfig.cmake)
include(extensions/abl_link/abl_link.cmake)

add_subdirectory(include)
if(LINK_BUILD_TESTS)
add_subdirectory(src)
endif()
add_subdirectory(examples)
add_subdirectory(extensions/abl_link)

Expand All @@ -64,3 +66,4 @@ if(CMAKE_BUILD_TYPE)
else()
message(" Build type: Set by IDE")
endif()

4 changes: 2 additions & 2 deletions app/external/sp_link/external_libs/link/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ would like to incorporate Link into a proprietary software application, please c

# Building and Running Link Examples

Link relies on `asio-standalone` and `catch` as submodules. After checking out the
Link relies on `asio-standalone` as a submodule. After checking out the
main repositories, those submodules have to be loaded using

```
Expand Down Expand Up @@ -108,7 +108,7 @@ implementations. Please see:
[platforms/darwin/Clock.hpp](include/ableton/platforms/darwin/Clock.hpp)
- Windows clock implementation in
[platforms/windows/Clock.hpp](include/ableton/platforms/windows/Clock.hpp)
- C++ standard library `std::chrono::high_resolution_clock`-based implementation in
- C++ standard library `std::chrono::steady_clock`-based implementation in
[platforms/stl/Clock.hpp](include/ableton/platforms/stl/Clock.hpp)

Using the system time correctly in the context of an audio callback gets a little
Expand Down
Empty file modified app/external/sp_link/external_libs/link/ci/build.py
100644 → 100755
Empty file.
Empty file modified app/external/sp_link/external_libs/link/ci/check-formatting.py
100644 → 100755
Empty file.
Empty file modified app/external/sp_link/external_libs/link/ci/configure.py
100644 → 100755
Empty file.
Empty file modified app/external/sp_link/external_libs/link/ci/run-tests.py
100644 → 100755
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.5)

set(build_flags_COMMON_LIST)
set(build_flags_DEBUG_LIST)
Expand Down Expand Up @@ -128,6 +128,8 @@ elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
"/wd4868" # Compiler may not enforce left-to-right evaluation order in braced initializer list
"/wd5026" # Move constructor was implicitly defined as deleted
"/wd5027" # Move assignment operator was implicitly defined as deleted
"/wd5262" # implicit fall-through
"/wd5264" # 'variable-name': 'const' variable is not used
)
endif()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.5)
project(LinkExamples)

# _ ____ ___ ___
Expand All @@ -11,7 +11,7 @@ project(LinkExamples)
if(WIN32)
function(configure_asio asio_sdk_path_OUT)
# ASIO-related path/file variables
set(asio_download_root "https:/download.steinberg.net/sdk_downloads")
set(asio_download_root "https://download.steinberg.net/sdk_downloads")
set(asio_file_name "asiosdk_2.3.3_2019-06-14.zip")
set(asio_dir_name "asiosdk_2.3.3_2019-06-14")
set(asio_working_dir "${CMAKE_BINARY_DIR}/modules")
Expand Down Expand Up @@ -96,10 +96,6 @@ source_group("Audio Sources" FILES ${linkhut_audio_SOURCES})
#

function(configure_linkhut_executable target)
if(CMAKE_SYSTEM_NAME MATCHES "Linux|kFreeBSD|GNU")
target_link_libraries(${target} atomic pthread)
endif()

target_link_libraries(${target} Ableton::Link)
endfunction()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
sdkconfig
sdkconfig.old
managed_components
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
dependencies:
espressif/asio:
component_hash: 27069b3f640bb58e2cbceb6bc13dd8f791a2c11b38080543f1858b6104e45b98
source:
service_url: https://api.components.espressif.com/
type: service
version: 1.14.1~3
idf:
component_hash: null
source:
type: idf
version: 5.1.1
manifest_hash: 10a682a6641cabbc6127f743d9e310d694820bf50bb2627e140bb20ba4a940e0
target: esp32
version: 1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## IDF Component Manager Manifest File
dependencies:
espressif/asio: "*"
## Required IDF version
idf:
version: ">=4.1.0"
# # Put list of dependencies here
# # For components maintained by Espressif:
# component: "~1.0.0"
# # For 3rd party components:
# username/component: ">=1.0.0,<2.0.0"
# username2/component2:
# version: "~1.0.0"
# # For transient dependencies `public` flag can be set.
# # `public` flag doesn't have an effect dependencies of the `main` component.
# # All dependencies of `main` are public by default.
# public: true
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <ableton/Link.hpp>
#include <driver/gpio.h>
#include <driver/timer.h>
#include <driver/gptimer.h>
#include <esp_event.h>
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
Expand All @@ -21,38 +21,6 @@ char* if_indextoname(unsigned int ifIndex, char* ifName)
return nullptr;
}

void IRAM_ATTR timer_group0_isr(void* userParam)
{
static BaseType_t xHigherPriorityTaskWoken = pdFALSE;

TIMERG0.int_clr_timers.t0 = 1;
TIMERG0.hw_timer[0].config.alarm_en = 1;

xSemaphoreGiveFromISR(userParam, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken)
{
portYIELD_FROM_ISR();
}
}

void timerGroup0Init(int timerPeriodUS, void* userParam)
{
timer_config_t config = {.alarm_en = TIMER_ALARM_EN,
.counter_en = TIMER_PAUSE,
.intr_type = TIMER_INTR_LEVEL,
.counter_dir = TIMER_COUNT_UP,
.auto_reload = TIMER_AUTORELOAD_EN,
.divider = 80};

timer_init(TIMER_GROUP_0, TIMER_0, &config);
timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0);
timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, timerPeriodUS);
timer_enable_intr(TIMER_GROUP_0, TIMER_0);
timer_isr_register(TIMER_GROUP_0, TIMER_0, &timer_group0_isr, userParam, 0, nullptr);

timer_start(TIMER_GROUP_0, TIMER_0);
}

void printTask(void* userParam)
{
auto link = static_cast<ableton::Link*>(userParam);
Expand All @@ -73,7 +41,6 @@ void printTask(void* userParam)

void tickTask(void* userParam)
{
SemaphoreHandle_t handle = static_cast<SemaphoreHandle_t>(userParam);
ableton::Link link(120.0f);
link.enable(true);

Expand All @@ -86,12 +53,10 @@ void tickTask(void* userParam)

while (true)
{
xSemaphoreTake(handle, portMAX_DELAY);

const auto state = link.captureAudioSessionState();
const auto phase = state.phaseAtTime(link.clock().micros(), 1.);
gpio_set_level(LED, fmodf(phase, 1.) < 0.1);
portYIELD();
vTaskDelay(1);
}
}

Expand All @@ -102,8 +67,5 @@ extern "C" void app_main()
ESP_ERROR_CHECK(esp_event_loop_create_default());
ESP_ERROR_CHECK(example_connect());

SemaphoreHandle_t tickSemphr = xSemaphoreCreateBinary();
timerGroup0Init(100, tickSemphr);

xTaskCreate(tickTask, "tick", 8192, tickSemphr, configMAX_PRIORITIES - 1, nullptr);
xTaskCreate(tickTask, "tick", 8192, nullptr, configMAX_PRIORITIES - 1, nullptr);
}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
CONFIG_COMPILER_CXX_EXCEPTIONS=y
CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@ target_include_directories(abl_link PUBLIC
set_property(TARGET abl_link PROPERTY C_STANDARD 11)

target_link_libraries(abl_link Ableton::Link)

if(CMAKE_SYSTEM_NAME MATCHES "Linux|kFreeBSD|GNU")
target_link_libraries(abl_link atomic pthread)
endif()
Loading

0 comments on commit 0a11266

Please sign in to comment.