diff --git a/README.md b/README.md index c344ec64..367581ab 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Tested in # Downloads The current release can be found in the [vst2_bin/](vst2_bin/) folder. -Here's a snapshot of it: [veeseevstrack_0_6_1_win64_bin-07Jul2018b.7z](dist/veeseevstrack_0_6_1_win64_bin-07Jul2018b.7z) +Here's a snapshot of it: [veeseevstrack_0_6_1_win64_bin-08Jul2018.7z](dist/veeseevstrack_0_6_1_win64_bin-08Jul2018.7z) (64bit) # Demo Video @@ -178,6 +178,12 @@ The following add-on modules are statically linked with the VST plugin: - cf.PATCH - cf.LEDS - cf.DAVE + - DHE-Modules.BoosterStage + - DHE-Modules.Cubic + - DHE-Modules.Hostage + - DHE-Modules.Stage + - DHE-Modules.Swave + - DHE-Modules.Upstage - ESeries.E340 - ErraticInstruments.MPEToCV - ErraticInstruments.QuadMPEToCV @@ -259,6 +265,23 @@ The following add-on modules are statically linked with the VST plugin: - LOGinstruments.Velvet - LOGinstruments.Crystal - modular80.Logistiker + - mscHack.MasterClockx4 + - mscHack.Seq_3x16x16 + - mscHack.SEQ_6x32x16 + - mscHack.Seq_Triad2 + - mscHack.SEQ_Envelope_8 + - mscHack.Maude_221 + - mscHack.ARP700 + - mscHack.SynthDrums + - mscHack.XFade + - mscHack.Mix_1x4_Stereo + - mscHack.Mix_2x4_Stereo + - mscHack.Mix_4x4_Stereo + - mscHack.Mix_24_4_4 + - mscHack.StepDelay + - mscHack.PingPong + - mscHack.Osc_3Ch + - mscHack.Compressor - mtsch_plugins.Sum - mtsch_plugins.Rationals - mtsch_plugins.TriggerPanic diff --git a/dep/dep.7z b/dep/dep.7z index 04de6c09..59ddbbb7 100644 Binary files a/dep/dep.7z and b/dep/dep.7z differ diff --git a/include/global_ui.hpp b/include/global_ui.hpp index ec1a6540..8d624349 100644 --- a/include/global_ui.hpp +++ b/include/global_ui.hpp @@ -100,11 +100,11 @@ struct GlobalUI { window.gFramebufferVg = NULL; window.gPixelRatio = 1.0; window.gWindowRatio = 1.0; -#ifdef USE_VST2 - window.gAllowCursorLock = false; -#else +// #ifdef USE_VST2 +// window.gAllowCursorLock = false; +// #else window.gAllowCursorLock = true; -#endif // USE_VST2 +// #endif // USE_VST2 window.windowX = 0; window.windowY = 0; window.windowWidth = 0; diff --git a/makefile_lib.msvc b/makefile_lib.msvc index 94bb5dce..a79407ab 100644 --- a/makefile_lib.msvc +++ b/makefile_lib.msvc @@ -1,5 +1,5 @@ # -# Makefile for VCV rack lib + Microsoft Visual C++ 2003 / 2005 / 2008 ToolKit +# Makefile for VCV rack lib + Microsoft Visual C++ 2003 / 2005 / 2008 / 2017 ToolKit # # @@ -9,7 +9,13 @@ TARGET_BASENAME=Rack EXTRAFLAGS= -DVERSION=0.6.1 -DARCH_WIN -D_USE_MATH_DEFINES -DRACK_HOST -DUSE_VST2 -DVST2_REPARENT_WINDOW_HACK -Iinclude/ -Idep/include -EXTRALIBS= -LIBPATH:dep/lib/msvc/ jansson.lib +ifeq ($(BUILD_64),y) +EXTRALIBS= -LIBPATH:dep/lib/msvc/x64 +else +EXTRALIBS= -LIBPATH:dep/lib/msvc/x86 +endif + +EXTRALIBS+= jansson.lib # glew.lib glfw.lib gdi32.lib user32.lib kernel32.lib PLAF_OBJ= diff --git a/plugins/community/repos/DHE-Modules/.appveyor.yml b/plugins/community/repos/DHE-Modules/.appveyor.yml new file mode 100644 index 00000000..4270b8b0 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/.appveyor.yml @@ -0,0 +1,19 @@ +version: 1.0.{build} +image: Visual Studio 2017 +test: off + +environment: + MSYSTEM: MINGW64 + +artifacts: + - path: dist\*.zip + +cache: + - c:\tmp\Rack + +install: +- set PATH=C:\msys64\usr\bin;%PATH% +- pacman -S --noconfirm zip unzip mingw-w64-x86_64-cmake + +build_script: +- bash -l %APPVEYOR_BUILD_FOLDER%\script\appveyor-build.sh diff --git a/plugins/community/repos/DHE-Modules/.envrc b/plugins/community/repos/DHE-Modules/.envrc new file mode 100644 index 00000000..e69de29b diff --git a/plugins/community/repos/DHE-Modules/.idea/.name b/plugins/community/repos/DHE-Modules/.idea/.name new file mode 100644 index 00000000..4a362e66 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/.idea/.name @@ -0,0 +1 @@ +DHE_Modules \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/.idea/DHE-Modules.iml b/plugins/community/repos/DHE-Modules/.idea/DHE-Modules.iml new file mode 100644 index 00000000..a2db577e --- /dev/null +++ b/plugins/community/repos/DHE-Modules/.idea/DHE-Modules.iml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/.idea/bashsupport_project.xml b/plugins/community/repos/DHE-Modules/.idea/bashsupport_project.xml new file mode 100644 index 00000000..b76bb103 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/.idea/bashsupport_project.xml @@ -0,0 +1,49 @@ + + + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/.idea/codeStyles/Project.xml b/plugins/community/repos/DHE-Modules/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..30aa626c --- /dev/null +++ b/plugins/community/repos/DHE-Modules/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/.idea/codeStyles/codeStyleConfig.xml b/plugins/community/repos/DHE-Modules/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..a55e7a17 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/.idea/inspectionProfiles/Project_Default.xml b/plugins/community/repos/DHE-Modules/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..146ab09b --- /dev/null +++ b/plugins/community/repos/DHE-Modules/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/.idea/misc.xml b/plugins/community/repos/DHE-Modules/.idea/misc.xml new file mode 100644 index 00000000..e07b970b --- /dev/null +++ b/plugins/community/repos/DHE-Modules/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/.idea/modules.xml b/plugins/community/repos/DHE-Modules/.idea/modules.xml new file mode 100644 index 00000000..b42e6423 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/.idea/runConfigurations/All_Tests.xml b/plugins/community/repos/DHE-Modules/.idea/runConfigurations/All_Tests.xml new file mode 100644 index 00000000..aff2b59e --- /dev/null +++ b/plugins/community/repos/DHE-Modules/.idea/runConfigurations/All_Tests.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/.idea/runConfigurations/Build_Linux.xml b/plugins/community/repos/DHE-Modules/.idea/runConfigurations/Build_Linux.xml new file mode 100644 index 00000000..1122cd60 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/.idea/runConfigurations/Build_Linux.xml @@ -0,0 +1,19 @@ + + + + + + + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/.idea/vcs.xml b/plugins/community/repos/DHE-Modules/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/plugins/community/repos/DHE-Modules/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/CMakeLists.txt b/plugins/community/repos/DHE-Modules/CMakeLists.txt new file mode 100644 index 00000000..f2db1c93 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/CMakeLists.txt @@ -0,0 +1,66 @@ +cmake_minimum_required(VERSION 3.9) +project(DHE_Modules DESCRIPTION "DHE Modules for VCV Rack" VERSION 0.0.0) + +set(CMAKE_OSX_DEPLOYMENT_TARGET 10.7) +if (DEFINED ENV{RACK_DIR}) + set(RACK_DIR "$ENV{RACK_DIR}") +endif (DEFINED ENV{RACK_DIR}) +if (NOT DEFINED RACK_DIR) + set(RACK_DIR ../..) +endif (NOT DEFINED RACK_DIR) + +add_library(rack INTERFACE) +target_include_directories(rack + INTERFACE + ${RACK_DIR}/include + ${RACK_DIR}/dep/include + ) +target_compile_features(rack INTERFACE cxx_std_11) +target_compile_options(rack INTERFACE -stdlib=libc++) + +add_library(plugin SHARED + src/gui/booster-stage-widget.h + src/gui/booster-stage-widget.cpp + src/gui/module-widget.h + src/gui/module-widget.cpp + src/gui/hostage-widget.h + src/gui/hostage-widget.cpp + src/gui/stage-widget.h + src/gui/stage-widget.cpp + src/gui/swave-widget.h + src/gui/swave-widget.cpp + src/gui/upstage-widget.h + src/gui/upstage-widget.cpp + src/modules/booster-stage-module.h + src/modules/hostage-module.h + src/modules/stage-module.h + src/modules/swave-module.h + src/modules/upstage-module.h + src/plugin/dhe-modules.h + src/plugin/dhe-modules.cpp + src/util/controls.h + src/util/d-flip-flop.h + src/util/d-latch.h + src/util/range.h + src/util/latch.h + src/util/ramp.h + src/util/sigmoid.h + src/util/mode.h) +target_link_libraries(plugin + PUBLIC -stdlib=libc++ + PUBLIC rack + PRIVATE "-undefined dynamic_lookup" + ) +target_include_directories(plugin PUBLIC src) + +add_executable(tests + test/catch/catch.hpp + test/runner/main.cpp + test/runner/environment.cpp + test/stage-tests.cpp + test/upstage-tests.cpp + ) +target_compile_features(tests PUBLIC cxx_std_11) +target_compile_options(tests PUBLIC -stdlib=libc++) +target_include_directories(tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/test ${CMAKE_CURRENT_SOURCE_DIR}/src) +target_link_libraries(tests PUBLIC rack -stdlib=libc++) \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/DHE-Modules.json b/plugins/community/repos/DHE-Modules/DHE-Modules.json new file mode 100644 index 00000000..f951a11a --- /dev/null +++ b/plugins/community/repos/DHE-Modules/DHE-Modules.json @@ -0,0 +1,10 @@ +{ + "name": "DHE Modules", + "author": "Dale Emery", + "license": "MIT", + "contactEmail": "dale@dhemery.com", + "manualUrl": "https://dhemery.github.io/DHE-Modules/", + "sourceUrl": "https://github.com/dhemery/DHE-Modules/", + "donateUrl": "https://paypal.me/DaleHEmery/", + "latestVersion": "0.6.0" +} diff --git a/plugins/community/repos/DHE-Modules/LICENSE.txt b/plugins/community/repos/DHE-Modules/LICENSE.txt new file mode 100644 index 00000000..610c6f99 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/LICENSE.txt @@ -0,0 +1,7 @@ +Copyright 2018 Dale H. Emery + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/plugins/community/repos/DHE-Modules/Makefile b/plugins/community/repos/DHE-Modules/Makefile new file mode 100644 index 00000000..86454082 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/Makefile @@ -0,0 +1,34 @@ +SLUG = DHE-Modules +VERSION = 0.6.0 +RACK_DIR ?= ../.. + +FLAGS += -I./src +CFLAGS += +CXXFLAGS += +LDFLAGS += + +SOURCES = $(wildcard src/*/*.cpp) + +DISTRIBUTABLES += $(wildcard LICENSE*) res + +include $(RACK_DIR)/plugin.mk + +MODULE_OBJECTS = $(patsubst %, build/%.o, $(MODULE_SOURCES)) + +TEST_SOURCES = $(wildcard test/runner/*.cpp test/*.cpp) +TEST_OBJECTS = $(patsubst %, build/%.o, $(TEST_SOURCES)) + +$(TEST_OBJECTS): FLAGS+= -I./test + +build/test/runner/main: $(TEST_OBJECTS) + $(CXX) -o $@ $^ + +test: build/test/runner/main + $< + +run: dist + cp -R dist/DHE-Modules $(RACK_DIR)/plugins + make -C $(RACK_DIR) run + +gui: + cd gui && rake clobber all diff --git a/plugins/community/repos/DHE-Modules/README.md b/plugins/community/repos/DHE-Modules/README.md new file mode 100644 index 00000000..11aa34d3 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/README.md @@ -0,0 +1,5 @@ +# DHE Modules + +VCV Rack modules from Dale Emery. + +See the [DHE Modules Site](https://dhemery.github.io/DHE-Modules/) for details. diff --git a/plugins/community/repos/DHE-Modules/docker/make-all.sh b/plugins/community/repos/DHE-Modules/docker/make-all.sh new file mode 100644 index 00000000..af665c21 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/docker/make-all.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -o errexit +set -o nounset +set -o xtrace + +cd "$(dirname "$0")/" +docker image build -t rack:env rack-env/ +docker image build -t rack:dep rack-dep/ +docker image build -t rack:build rack-build/ diff --git a/plugins/community/repos/DHE-Modules/docker/rack-build/Dockerfile b/plugins/community/repos/DHE-Modules/docker/rack-build/Dockerfile new file mode 100644 index 00000000..797e2d3d --- /dev/null +++ b/plugins/community/repos/DHE-Modules/docker/rack-build/Dockerfile @@ -0,0 +1,4 @@ +FROM rack:dep +RUN cd "${VCV_RACK_DIR}" && make +VOLUME /out +CMD bash diff --git a/plugins/community/repos/DHE-Modules/docker/rack-dep/Dockerfile b/plugins/community/repos/DHE-Modules/docker/rack-dep/Dockerfile new file mode 100644 index 00000000..2805a424 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/docker/rack-dep/Dockerfile @@ -0,0 +1,9 @@ +FROM rack:env +ENV VCV_RACK_DIR=/build/Rack +RUN mkdir -p "${VCV_RACK_DIR}" \ + && git clone -n https://github.com/VCVRack/Rack.git "${VCV_RACK_DIR}" || true \ + && cd "${VCV_RACK_DIR}" \ + && git checkout master \ + && git pull \ + && git submodule update --init --recursive \ + && make dep > /dev/null diff --git a/plugins/community/repos/DHE-Modules/docker/rack-env/Dockerfile b/plugins/community/repos/DHE-Modules/docker/rack-env/Dockerfile new file mode 100644 index 00000000..05af0b47 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/docker/rack-env/Dockerfile @@ -0,0 +1,30 @@ +FROM ubuntu +RUN apt-get update \ + && apt-get install -y --no-install-recommends software-properties-common \ + && add-apt-repository -y ppa:ubuntu-toolchain-r/test \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + autoconf \ + automake \ + cmake \ + curl \ + g++ \ + git \ + libasound2-dev \ + libgl1-mesa-dev \ + libglu1-mesa-dev \ + libgtk2.0-dev \ + libtool \ + libudev-dev \ + libxcursor-dev \ + libxinerama-dev\ + libxrandr-dev \ + make \ + tar \ + unzip \ + wget \ + zip \ + zlib1g-dev \ + && add-apt-repository -yr ppa:ubuntu-toolchain-r/test \ + && apt-get autoremove --purge \ + && apt-get clean diff --git a/plugins/community/repos/DHE-Modules/gui/.idea/.rakeTasks b/plugins/community/repos/DHE-Modules/gui/.idea/.rakeTasks new file mode 100644 index 00000000..c98798a2 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/.idea/.rakeTasks @@ -0,0 +1,7 @@ + + diff --git a/plugins/community/repos/DHE-Modules/gui/.idea/encodings.xml b/plugins/community/repos/DHE-Modules/gui/.idea/encodings.xml new file mode 100644 index 00000000..97626ba4 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/gui/.idea/gui.iml b/plugins/community/repos/DHE-Modules/gui/.idea/gui.iml new file mode 100644 index 00000000..3c4780fe --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/.idea/gui.iml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/gui/.idea/inspectionProfiles/Project_Default.xml b/plugins/community/repos/DHE-Modules/gui/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..9466ecad --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,15 @@ + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/gui/.idea/misc.xml b/plugins/community/repos/DHE-Modules/gui/.idea/misc.xml new file mode 100644 index 00000000..e38033af --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/gui/.idea/modules.xml b/plugins/community/repos/DHE-Modules/gui/.idea/modules.xml new file mode 100644 index 00000000..c2b3c36a --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/gui/.idea/vcs.xml b/plugins/community/repos/DHE-Modules/gui/.idea/vcs.xml new file mode 100644 index 00000000..6c0b8635 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/gui/Gemfile b/plugins/community/repos/DHE-Modules/gui/Gemfile new file mode 100644 index 00000000..b2b62dba --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/Gemfile @@ -0,0 +1,5 @@ +source 'https://rubygems.org' + +gem 'jekyll', '~> 3.7' +gem 'rake', '~> 12.3' +gem 'color', '~> 1.8' diff --git a/plugins/community/repos/DHE-Modules/gui/Gemfile.lock b/plugins/community/repos/DHE-Modules/gui/Gemfile.lock new file mode 100644 index 00000000..14dff40e --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/Gemfile.lock @@ -0,0 +1,67 @@ +GEM + remote: https://rubygems.org/ + specs: + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + color (1.8) + colorator (1.1.0) + concurrent-ruby (1.0.5) + em-websocket (0.5.1) + eventmachine (>= 0.12.9) + http_parser.rb (~> 0.6.0) + eventmachine (1.2.5) + ffi (1.9.23) + forwardable-extended (2.6.0) + http_parser.rb (0.6.0) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + jekyll (3.7.3) + addressable (~> 2.4) + colorator (~> 1.0) + em-websocket (~> 0.5) + i18n (~> 0.7) + jekyll-sass-converter (~> 1.0) + jekyll-watch (~> 2.0) + kramdown (~> 1.14) + liquid (~> 4.0) + mercenary (~> 0.3.3) + pathutil (~> 0.9) + rouge (>= 1.7, < 4) + safe_yaml (~> 1.0) + jekyll-sass-converter (1.5.2) + sass (~> 3.4) + jekyll-watch (2.0.0) + listen (~> 3.0) + kramdown (1.16.2) + liquid (4.0.0) + listen (3.1.5) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + ruby_dep (~> 1.2) + mercenary (0.3.6) + pathutil (0.16.1) + forwardable-extended (~> 2.6) + public_suffix (3.0.2) + rake (12.3.0) + rb-fsevent (0.10.3) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + rouge (3.1.1) + ruby_dep (1.5.0) + safe_yaml (1.0.4) + sass (3.5.5) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + +PLATFORMS + ruby + +DEPENDENCIES + color (~> 1.8) + jekyll (~> 3.7) + rake (~> 12.3) + +BUNDLED WITH + 1.16.1 diff --git a/plugins/community/repos/DHE-Modules/gui/Rakefile b/plugins/community/repos/DHE-Modules/gui/Rakefile new file mode 100644 index 00000000..fdaa03ab --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/Rakefile @@ -0,0 +1,67 @@ +require 'rake' +require 'rake/clean' +require 'pathname' + +build_dir = Pathname('_build') +module_dest_dir = Pathname('../res') +image_dest_dir = Pathname('../images') + +directory module_dest_dir +directory image_dest_dir + +control_build_dir = build_dir / 'controls' +control_build_files = "#{control_build_dir}/**/*.svg" +control_build_file_to_dest_file = "%{^#{control_build_dir}/,#{module_dest_dir}/}p" + +image_build_dir = build_dir / 'images' +image_build_files = "#{image_build_dir}/**/*.svg" +image_build_file_to_dest_file = "%{^#{image_build_dir}/,#{image_dest_dir}/}p" + +panel_build_dir = build_dir / 'panels' +panel_build_files = "#{panel_build_dir}/**/*.svg" +panel_build_file_to_dest_file = "%{^#{panel_build_dir}/,#{module_dest_dir}/}X/panel.svg" + +module_source_dir = 'panels' +module_source_files = FileList["#{module_source_dir}/**/*.svg"] +module_source_file_to_dest_dir = "%{^#{module_source_dir}/,#{module_dest_dir}/}X" +module_dest_dirs = module_source_files.pathmap(module_source_file_to_dest_dir) +module_dest_dirs.each { |dir| directory dir } + +desc 'Compile the SVG images' +task :compile do + sh 'bundle exec jekyll b --trace' +end + +task controls: [:compile] + module_dest_dirs do + FileList[control_build_files].each do |build_file| + dest_file = build_file.pathmap(control_build_file_to_dest_file) + sh "xmllint --format #{build_file} > #{dest_file}" + end +end + +task panels: [:compile] + module_dest_dirs do + FileList[panel_build_files].each do |build_file| + dest_file = build_file.pathmap(panel_build_file_to_dest_file) + convert_text_to_paths(build_file, dest_file) + end +end + +task images: [:compile, image_dest_dir] do + FileList[image_build_files].each do |build_file| + dest_file = build_file.pathmap(image_build_file_to_dest_file) + convert_text_to_paths(build_file, dest_file) + end +end + +task all: [:controls, :panels, :images] +task default: :all + +CLEAN.include build_dir +CLOBBER.include module_dest_dir, image_dest_dir + +def convert_text_to_paths(source, dest) + source = Pathname(source).expand_path.to_s + dest = Pathname(dest).expand_path.to_s + sh "/Applications/Inkscape.app/Contents/Resources/script --export-text-to-path --export-plain-svg=#{dest} #{source}" +end + diff --git a/plugins/community/repos/DHE-Modules/gui/_config.yaml b/plugins/community/repos/DHE-Modules/gui/_config.yaml new file mode 100644 index 00000000..b766ca1e --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/_config.yaml @@ -0,0 +1,6 @@ +destination: _build +incremental: false +exclude: + - Gemfile + - Gemfile.lock + - Rakefile diff --git a/plugins/community/repos/DHE-Modules/gui/_layouts/control.svg b/plugins/community/repos/DHE-Modules/gui/_layouts/control.svg new file mode 100644 index 00000000..65d82a5e --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/_layouts/control.svg @@ -0,0 +1,8 @@ +{% assign width = page.width %} +{% assign height = page.height %} + + + {{ content }} + + diff --git a/plugins/community/repos/DHE-Modules/gui/_layouts/panel.svg b/plugins/community/repos/DHE-Modules/gui/_layouts/panel.svg new file mode 100644 index 00000000..7ce46338 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/_layouts/panel.svg @@ -0,0 +1,8 @@ +{% assign height = 128.5 %} +{% assign width = page.width | hp_to_mm %} + + + {{ page | panel }} + {{ content }} + + diff --git a/plugins/community/repos/DHE-Modules/gui/_plugins/controls.rb b/plugins/community/repos/DHE-Modules/gui/_plugins/controls.rb new file mode 100644 index 00000000..06af973d --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/_plugins/controls.rb @@ -0,0 +1,213 @@ +class Bounded + attr_reader :top, :right, :bottom, :left + + def initialize(top:, right:, bottom:, left:) + @top = top + @right = right + @bottom = bottom + @left = left + end + + def width + @right - @left + end + + def height + @bottom - @top + end + + def center + OpenStruct.new(x: width / 2.0 + left, y: height / 2.0 + top) + end + + def translate(delta_x: 0, delta_y: 0) + @top += delta_y + @right += delta_x + @bottom += delta_y + @left += delta_x + end + + def move_center_to(x: center.x, y: center.y) + delta_x = x - center.x + delta_y = y - center.y + translate(delta_x: delta_x, delta_y: delta_y) + end +end + +class Control < Bounded + def initialize(x:, y:, width:, height: width) + super(top: y - height / 2.0, right: x + width / 2.0, bottom: y + height / 2.0, left: x - width / 2.0) + end +end + +class RoundControl < Control + attr_reader :diameter + + def initialize(x:, y:, diameter:) + super(x: x, y: y, width: diameter) + @diameter = diameter + end + + def radius + diameter / 2.0 + end +end + +class ButtonControl < RoundControl + DIAMETER = 6.0 + + def initialize(x: 0.0, y: 0.0, style:, state:, dark:, light:) + super(x: x, y: y, diameter: DIAMETER) + @style = style.to_sym + @state = state.to_sym + @button_color = @style == :dark ? dark : light + if @style == :dark + @state_color = @state == :on ? light : dark + else + @state_color = @state == :on ? dark : light + end + end + + def name + "button-#{@style}-#{@state}" + end + + def align(padding, alignment, other) + new_x = case alignment + when :right_of + other.right + padding + radius + when :left_of + other.left - padding - radius + else + center.x + end + move_center_to(x: new_x, y: other.center.y) + end + + def svg + stroke_width = diameter / 6.0 + circle_diameter = diameter - stroke_width + circle_radius = circle_diameter / 2.0 + %Q[ + + ] + end +end + +class KnobControl < RoundControl + DIAMETER = 12.7 + + def initialize(x: 0.0, y: 0.0, knob_color:, pointer_color:) + super(x: x, y: y, diameter: 12.7) + @knob_color = knob_color + @pointer_color = pointer_color + end + + def name + 'knob-large' + end + + def svg + pointer_width = radius / 8.0 + pointer_length = radius - pointer_width + %Q[ + + + + + ] + end +end + +class PortControl < RoundControl + DIAMETER = 8.4 + + def initialize(x: 0.0, y: 0.0, metal_color:, shadow_color:) + super(x: x, y: y, diameter: 8.4) + @metal_color = metal_color + @shadow_color = shadow_color + end + + def name + 'port' + end + + def svg + stroke_width = diameter * 0.025 + sleeve_diameter = diameter - stroke_width + step = sleeve_diameter / 7.0 + sleeve_radius = sleeve_diameter / 2.0 + ring_radius = sleeve_radius - step + tip_radius = ring_radius - step + %Q[ + + + + + + ] + end +end + +class SwitchControl < Control + WIDTH = 3.0 + + def initialize(x: 0.0, y: 0.0, positions:, state:, dark:, light:) + super(x: x, y: y, width: WIDTH, height: positions * WIDTH) + @positions = positions + @state = state + @dark = dark + @light = light + @position = + case @state + when :high + 1.0 + when :low + -1.0 + else + 0.0 + end + end + + def name + "switch-#{@positions}-#{@state}" + end + + def svg + box_stroke_width = width / 8.0 + interior_inset = box_stroke_width / 2.0 + + box_width = width - box_stroke_width + box_height = height - box_stroke_width + box_left = -width / 2.0 + interior_inset + box_top = -height / 2.0 + interior_inset + + interior_width = box_width - box_stroke_width + interior_height = box_height - box_stroke_width + corner_radius = interior_inset + + knurl_stroke_width = 0.25 + knurl_inset = knurl_stroke_width * 2.0 + knurl_length = interior_width - knurl_inset + knurl_left = knurl_length / -2.0 + knurl_right = knurl_left + knurl_length + knurl_spacing = knurl_stroke_width * 2.0 + + lever_height = knurl_spacing * 4.0 + knurl_stroke_width + lever_inset = knurl_stroke_width + lever_distance = (interior_height - lever_height) / 2.0 - lever_inset + lever_offset = lever_distance * -@position + lever = (-2..2) + .map {|index| knurl_spacing * index + lever_offset} + .map {|y| %Q[]} + .join("\n") + %Q[ + + + #{lever} + + ] + end +end diff --git a/plugins/community/repos/DHE-Modules/gui/_plugins/module-generator.rb b/plugins/community/repos/DHE-Modules/gui/_plugins/module-generator.rb new file mode 100644 index 00000000..6fd27dc0 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/_plugins/module-generator.rb @@ -0,0 +1,78 @@ +require 'rake' +require 'color' +require_relative 'controls' +require_relative 'page-color' + +module DHE + SOURCE_DIR = '/panels' + class PageWithoutAFile < Jekyll::Page + def read_yaml(*) + @data ||= {} + end + end + + class Generator < Jekyll::Generator + include DHE::PageColor + + def generate(site) + module_pages = site.pages.select {|page| page.url.start_with? SOURCE_DIR} + module_pages.each do |module_page| + site.pages += control_pages(module_page) + site.pages << image_page(module_page) + end + end + + def control_page(module_page, control) + page = PageWithoutAFile.new(module_page.site, __dir__, module_page.url.pathmap("%{^#{SOURCE_DIR},controls}X"), control.name.ext('svg')) + page.data['layout'] = 'control' + page.data['width'] = control.width + page.data['height'] = control.height + page.content = control.svg + page + end + + def control_pages(module_page) + controls(module_page).map {|control| control_page(module_page, control)} + end + + def controls(page) + page.data['controls'].flat_map {|type, variants| send(type, page, variants)} + end + + def image_page(module_page) + page = PageWithoutAFile.new(module_page.site, __dir__, module_page.url.pathmap("%{^#{SOURCE_DIR},images}d"), module_page.name) + page.data.merge!(module_page.data) + page.data['draw_controls'] = true + page.data['dark'] = dark(page) + page.data['light'] = light(page) + page.content = module_page.content + page + end + + def buttons(page, variants) + variants.flat_map do |style| + [:off, :on].map do |state| + ButtonControl.new(style: style, state: state, dark: dark(page), light: light(page)) + end + end + end + + def ports(page, _) + PortControl.new(metal_color: light(page), shadow_color: dark(page)) + end + + def knobs(page, _) + KnobControl.new(knob_color: dark(page), pointer_color: light(page)) + end + + def switches(page, variants) + variants.flat_map do |positions| + states = [:high, :low] + states << :mid if positions == 3 + states.map do |state| + SwitchControl.new(positions: positions, state: state, dark: dark(page), light: light(page)) + end + end + end + end +end \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/gui/_plugins/page-color.rb b/plugins/community/repos/DHE-Modules/gui/_plugins/page-color.rb new file mode 100644 index 00000000..c7350193 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/_plugins/page-color.rb @@ -0,0 +1,21 @@ +module DHE + module PageColor + def hslcolor(page) + Color::HSL.new(*page['color']) + end + + def rgbhex(color) + "##{color.to_rgb.hex}" + end + + def light(page) + hsl = hslcolor(page) + hsl.l = 0.97 + rgbhex(hsl) + end + + def dark(page) + rgbhex(hslcolor(page)) + end + end +end \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/gui/_plugins/panel-filters.rb b/plugins/community/repos/DHE-Modules/gui/_plugins/panel-filters.rb new file mode 100644 index 00000000..f5f270ec --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/_plugins/panel-filters.rb @@ -0,0 +1,244 @@ +require 'ostruct' +require_relative 'page-color' +require_relative 'controls' + +module PanelFilters + include DHE::PageColor + + MM_PER_INCH = 25.4 + PX_PER_INCH = 75.0 + PX_PER_MM = PX_PER_INCH / MM_PER_INCH + MM_PER_HP = 5.08 + + STROKE_WIDTH = 0.35 + STROKE_INSET = STROKE_WIDTH / 2.0 + PADDING = 1.0 + + PLUGIN_LABEL_INSET = 9.0 + PANEL_HEIGHT = 128.5 + + PLUGIN_FONT = 12.0 / PX_PER_MM + LARGE_FONT = 9.0 / PX_PER_MM + SMALL_FONT = 7.0 / PX_PER_MM + + class Text + ASCENT_RATIO = 2.0 / 3.0 # For Proxima Nova font + + def initialize(text:, size:, color:) + @text = text + @size = size + @color = color + end + + def ascent + @size * ASCENT_RATIO + end + + def descent + @size - ascent + end + + def svg(x:, y:, attributes:) + %Q[#{@text}] + end + end + + class Label < Bounded + ALIGNMENT_ATTRIBUTES_TEMPLATE = %[dominant-baseline="%s" text-anchor="%s"] + ALIGNMENT_ATTRIBUTES = { + above: ALIGNMENT_ATTRIBUTES_TEMPLATE % %w{baseline middle}, + below: ALIGNMENT_ATTRIBUTES_TEMPLATE % %w{hanging middle}, + right: ALIGNMENT_ATTRIBUTES_TEMPLATE % %w{middle start}, + } + + def initialize(text, padding, alignment, control) + @text = text + @alignment = alignment + case alignment + when :above + @x = control.center.x + @y = control.top - padding + when :below + @x = control.center.x + @y = control.bottom + padding + when :right_of + @x = control.right + padding + @y = control.center.y + else + @x = control.center.x + @y = control.center.y + end + super(top: @y - @text.ascent, right: @x, bottom: @y + @text.descent, left: @x) + end + + def svg + @text.svg(x: @x, y: @y, attributes: ALIGNMENT_ATTRIBUTES[@alignment]) + end + end + + class Box < Bounded + CORNER_RADIUS = 1.0 + BUFFER = PADDING + STROKE_INSET + + def initialize(content_bounds:, border_color:, background_color:) + super(top: content_bounds.top - BUFFER, right: content_bounds.right + BUFFER, bottom: content_bounds.bottom + BUFFER, left: content_bounds.left - BUFFER) + @border_color = border_color + @background_color = background_color + end + + def svg + %Q[ + + ] + end + + def self.around(content:, border_color:, background_color:) + content_bounds = Bounded.new(top: content.map(&:top).min, right: content.map(&:right).max, bottom: content.map(&:bottom).max, left: content.map(&:left).min) + Box.new(content_bounds: content_bounds, border_color: border_color, background_color: background_color) + end + end + + def button(page, x, y, label) + dark = dark(page) + light = light(page) + button = ButtonControl.new(x: x, y: y, style: :dark, state: :off, dark: dark, light: light) + label_text = Text.new(text: label, color: dark, size: SMALL_FONT) + items = [Label.new(label_text, PADDING, :above, button)] + items << button if page['draw_controls'] + items.map(&:svg).join("\n") + end + + def large_knob(page, x, y, label) + dark = dark(page) + light = light(page) + knob = KnobControl.new(x: x, y: y, knob_color: dark, pointer_color: light) + label_text = Text.new(text: label, color: dark, size: LARGE_FONT) + items = [Label.new(label_text, PADDING, :above, knob)] + items << knob if page['draw_controls'] + items.map(&:svg).join("\n") + end + + def cv(page, x, y) + dark = dark(page) + light = light(page) + draw = page['draw_controls'] + port = PortControl.new(x: x, y: y, metal_color: light, shadow_color: dark) + label_text = Text.new(text: 'CV', color: dark, size: SMALL_FONT) + items = [Label.new(label_text, PADDING, :above, port)] + items << port if draw + items.map(&:svg).join("\n") + end + + def port_button(port_x:, port_y:, label:, button_position:, foreground_color:, background_color:, label_color:, metal_color:, shadow_color:, button_style:, draw:) + port = PortControl.new(x: port_x, y: port_y, metal_color: metal_color, shadow_color: shadow_color) + label_text = Text.new(text: label, color: label_color, size: SMALL_FONT) + label = Label.new(label_text, PADDING, :above, port) + button = ButtonControl.new(style: button_style, state: :off, dark: shadow_color, light: metal_color) + button.align(PADDING, button_position, port) + box = Box.around(content: [port, label, button], border_color: foreground_color, background_color: background_color) + items = [box, label] + items += [port, button] if draw + items.map(&:svg).join("\n") + end + + def in_port_button(page, x, y, label) + dark = dark(page) + light = light(page) + draw = page['draw_controls'] + port_button(port_x: x, port_y: y, label: label, button_position: :right_of, foreground_color: dark, background_color: light, label_color: dark, metal_color: light, shadow_color: dark, button_style: :dark, draw: draw) + end + + def out_port_button(page, x, y, label) + dark = dark(page) + light = light(page) + draw = page['draw_controls'] + port_button(port_x: x, port_y: y, label: label, button_position: :left_of, foreground_color: dark, background_color: dark, label_color: light, metal_color: light, shadow_color: dark, button_style: :light, draw: draw) + end + + def port(x:, y:, foreground_color:, background_color:, label:, label_color:, metal_color:, shadow_color:, draw:) + port = PortControl.new(x: x, y: y, metal_color: metal_color, shadow_color: shadow_color) + label_text = Text.new(text: label, color: label_color, size: SMALL_FONT) + label = Label.new(label_text, PADDING, :above, port) + box = Box.around(content: [port, label], border_color: foreground_color, background_color: background_color) + items = [box, label] + items << port if draw + items.map(&:svg).join("\n") + end + + def in_port(page, x, y, label) + dark = dark(page) + light = light(page) + draw = page ['draw_controls'] + port(x: x, y: y, foreground_color: dark, background_color: light, label: label, label_color: dark, metal_color: light, shadow_color: dark, draw: draw) + end + + def out_port(page, x, y, label) + dark = dark(page) + light = light(page) + draw = page ['draw_controls'] + port(x: x, y: y, foreground_color: dark, background_color: dark, label: label, label_color: light, metal_color: light, shadow_color: dark, draw: draw) + end + + def duration_switch(page, x, y) + switch(page, x, y, :mid, '100', '1', '10') + end + + def polarity_switch(page, x, y) + switch(page, x, y, :high, 'UNI', 'BI',) + end + + def shape_switch(page, x, y) + switch(page, x, y, :low, 'S', 'J',) + end + + def switch(page, x, y, position, high, low, mid = nil) + dark = dark(page) + light = light(page) + draw = page['draw_controls'] + switch = SwitchControl.new(x: x, y: y, positions: mid ? 3 : 2, dark: dark, light: light, state: position.to_sym) + high_text = Text.new(text: high, size: SMALL_FONT, color: dark) + low_text = Text.new(text: low, size: SMALL_FONT, color: dark) + items = [ + Label.new(high_text, PADDING + STROKE_INSET, :above, switch), + Label.new(low_text, PADDING + STROKE_INSET, :below, switch), + ] + if mid + mid_text = Text.new(text: mid, size: SMALL_FONT, color: dark) + items << Label.new(mid_text, PADDING / 2.0 + STROKE_INSET, :right_of, switch) + end + items << switch if draw + items.map(&:svg).join("\n") + end + + def panel(page) + dark = dark(page) + light = light(page) + panel = Bounded.new(top: 0.0, right: width(page), bottom: PANEL_HEIGHT, left: 0.0) + name_label_text = Text.new(text: page['title'], color: dark, size: PLUGIN_FONT) + name_label = Label.new(name_label_text, -PLUGIN_LABEL_INSET, :above, panel) + author_label_text = Text.new(text: 'DHE', color: dark, size: PLUGIN_FONT) + author_label = Label.new(author_label_text, -PLUGIN_LABEL_INSET, :below, panel) + box = %Q[] + box + [name_label, author_label].map(&:svg).join("\n") + end + + def connector(page, x1, y1, x2, y2) + %Q[] + end + + def width(page) + hp_to_mm(page['width']) + end + + def mm_to_px(mm) + mm * PX_PER_MM + end + + def hp_to_mm(hp) + hp * MM_PER_HP + end +end + +Liquid::Template.register_filter(PanelFilters) diff --git a/plugins/community/repos/DHE-Modules/gui/panels/booster-stage.svg b/plugins/community/repos/DHE-Modules/gui/panels/booster-stage.svg new file mode 100644 index 00000000..a1f348a5 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/panels/booster-stage.svg @@ -0,0 +1,39 @@ +--- +layout: panel +width: 8 +title: BOOSTER STAGE +color: [0,100,30] +controls: + buttons: [dark, light] + knobs: [] + ports: [] + switches: [2, 3] +--- +{% assign width = page.width | hp_to_mm %} +{% assign left_x = width | divided_by:6.0 | plus:0.333333 %} +{% assign right_x = width | minus:left_x %} +{% assign center_x = width | divided_by:2.0 %} + +{{ page | connector: left_x, 25.0, right_x, 25.0 }} +{{ page | cv: left_x, 25.0 }} +{{ page | large_knob: center_x, 25.0, 'LEVEL' }} +{{ page | polarity_switch: right_x, 25 }} + +{{ page | connector: left_x, 43.5, right_x, 43.5 }} +{{ page | cv: left_x, 43.5 }} +{{ page | large_knob: center_x, 43.5, 'CURVE' }} +{{ page | shape_switch: right_x, 43.5 }} + +{{ page | connector: left_x, 62.0, right_x, 62.0 }} +{{ page | cv: left_x, 62 }} +{{ page | large_knob: center_x, 62.0, 'DURATION' }} +{{ page | duration_switch: right_x, 62 }} + +{{ page | in_port_button: left_x, 82.0, 'DEFER' }} +{{ page | out_port_button: right_x, 82.0, 'ACTIVE' }} + +{{ page | in_port_button: left_x, 97.0, 'TRIG' }} +{{ page | out_port_button: right_x, 97.0, 'EOC' }} + +{{ page | in_port: left_x, 112.0, 'IN' }} +{{ page | out_port: right_x, 112.0, 'OUT' }} diff --git a/plugins/community/repos/DHE-Modules/gui/panels/hostage.svg b/plugins/community/repos/DHE-Modules/gui/panels/hostage.svg new file mode 100644 index 00000000..bf6505db --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/panels/hostage.svg @@ -0,0 +1,30 @@ +--- +layout: panel +width: 5 +title: HOSTAGE +color: [300,100,30] +controls: + knobs: [] + ports: [] + switches: [2, 3] +--- +{% assign width = page.width | hp_to_mm %} +{% assign left_x = width | divided_by:4.0 | plus:0.33333 %} +{% assign right_x = width | minus:left_x %} +{% assign center_x = width | divided_by:2.0 %} + +{{ page | switch: center_x, 25, 'low', 'SUSTAIN', 'HOLD' }} + +{{ page | cv: left_x, 43.5 }} +{{ page | duration_switch: right_x, 43.5 }} + +{{ page | large_knob: center_x, 62.0, 'DURATION' }} + +{{ page | in_port: left_x, 82.0, 'DEFER' }} +{{ page | out_port: right_x, 82.0, 'ACTIVE' }} + +{{ page | in_port: left_x, 97.0, 'GATE' }} +{{ page | out_port: right_x, 97.0, 'EOC' }} + +{{ page | in_port: left_x, 112.0, 'IN' }} +{{ page | out_port: right_x, 112.0, 'OUT' }} diff --git a/plugins/community/repos/DHE-Modules/gui/panels/stage.svg b/plugins/community/repos/DHE-Modules/gui/panels/stage.svg new file mode 100644 index 00000000..c2830d8d --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/panels/stage.svg @@ -0,0 +1,26 @@ +--- +layout: panel +width: 5 +title: STAGE +color: [120,100,30] +controls: + knobs: [] + ports: [] +--- +{% assign width = page.width | hp_to_mm %} +{% assign left_x = width | divided_by:4.0 | plus:0.33333 %} +{% assign right_x = width | minus:left_x %} +{% assign center_x = width | divided_by:2.0 %} + +{{ page | large_knob: center_x, 25.0, 'LEVEL' }} +{{ page | large_knob: center_x, 43.5, 'CURVE' }} +{{ page | large_knob: center_x, 62.0, 'DURATION' }} + +{{ page | in_port: left_x, 82.0, 'DEFER' }} +{{ page | out_port: right_x, 82.0, 'ACTIVE' }} + +{{ page | in_port: left_x, 97.0, 'TRIG' }} +{{ page | out_port: right_x, 97.0, 'EOC' }} + +{{ page | in_port: left_x, 112.0, 'IN' }} +{{ page | out_port: right_x, 112.0, 'OUT' }} diff --git a/plugins/community/repos/DHE-Modules/gui/panels/swave.svg b/plugins/community/repos/DHE-Modules/gui/panels/swave.svg new file mode 100644 index 00000000..aadf5568 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/panels/swave.svg @@ -0,0 +1,19 @@ +--- +layout: panel +width: 4 +title: SWAVE +color: [16,100,50] +controls: + knobs: [] + ports: [] + switches: [2] +--- +{% assign width = page.width | hp_to_mm %} +{% assign center_x = width | divided_by:2.0 %} + +{{ page | shape_switch: center_x, 25 }} +{{ page | large_knob: center_x, 43.5, 'CURVE' }} +{{ page | cv: center_x, 62 }} + +{{ page | in_port: center_x, 97.0, 'IN' }} +{{ page | out_port: center_x, 112.0, 'OUT' }} diff --git a/plugins/community/repos/DHE-Modules/gui/panels/upstage.svg b/plugins/community/repos/DHE-Modules/gui/panels/upstage.svg new file mode 100644 index 00000000..b9cd24d4 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/gui/panels/upstage.svg @@ -0,0 +1,29 @@ +--- +layout: panel +width: 5 +title: UPSTAGE +color: [210,100,30] +controls: + buttons: [dark] + knobs: [] + ports: [] + switches: [2] +--- +{% assign width = page.width | hp_to_mm %} +{% assign left_x = width | divided_by:4.0 | plus:0.33333 %} +{% assign right_x = width | minus:left_x %} +{% assign center_x = width | divided_by:2.0 %} + +{{ page | large_knob: center_x, 25.0, 'LEVEL' }} +{{ page | cv: left_x, 43.5 }} +{{ page | polarity_switch: right_x, 43.5 }} + +{{ page | button: left_x, 62, 'WAIT' }} +{{ page | button: right_x, 62, 'TRIG' }} + +{{ page | in_port: left_x, 82.0, 'WAIT' }} + +{{ page | in_port: left_x, 97.0, 'TRIG' }} +{{ page | out_port: right_x, 97.0, 'TRIG' }} + +{{ page | out_port: right_x, 112.0, 'OUT' }} diff --git a/plugins/community/repos/DHE-Modules/images/booster-stage.svg b/plugins/community/repos/DHE-Modules/images/booster-stage.svg new file mode 100644 index 00000000..a5fa494d --- /dev/null +++ b/plugins/community/repos/DHE-Modules/images/booster-stage.svg @@ -0,0 +1,769 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/images/hostage.svg b/plugins/community/repos/DHE-Modules/images/hostage.svg new file mode 100644 index 00000000..61402103 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/images/hostage.svg @@ -0,0 +1,562 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/images/stage.svg b/plugins/community/repos/DHE-Modules/images/stage.svg new file mode 100644 index 00000000..24e0dac2 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/images/stage.svg @@ -0,0 +1,449 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/images/swave.svg b/plugins/community/repos/DHE-Modules/images/swave.svg new file mode 100644 index 00000000..700fec66 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/images/swave.svg @@ -0,0 +1,262 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/images/upstage.svg b/plugins/community/repos/DHE-Modules/images/upstage.svg new file mode 100644 index 00000000..dfc01a4e --- /dev/null +++ b/plugins/community/repos/DHE-Modules/images/upstage.svg @@ -0,0 +1,424 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/make.objects b/plugins/community/repos/DHE-Modules/make.objects new file mode 100644 index 00000000..c0ecabc4 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/make.objects @@ -0,0 +1,9 @@ +ALL_OBJ= \ + src/gui/booster-stage-widget.o \ + src/gui/cubic-widget.o \ + src/gui/hostage-widget.o \ + src/gui/module-widget.o \ + src/gui/stage-widget.o \ + src/gui/swave-widget.o \ + src/gui/upstage-widget.o \ + src/plugin/dhe-modules.o diff --git a/plugins/community/repos/DHE-Modules/makefile.msvc b/plugins/community/repos/DHE-Modules/makefile.msvc new file mode 100644 index 00000000..1867e010 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/makefile.msvc @@ -0,0 +1,9 @@ +SLUG=DHE-Modules + +include ../../../../dep/yac/install_msvc.mk + +EXTRAFLAGS+= -Isrc/ + +include make.objects + +include ../../../build_plugin.mk diff --git a/plugins/community/repos/DHE-Modules/res/booster-stage/button-dark-off.svg b/plugins/community/repos/DHE-Modules/res/booster-stage/button-dark-off.svg new file mode 100644 index 00000000..f086436e --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/booster-stage/button-dark-off.svg @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/booster-stage/button-dark-on.svg b/plugins/community/repos/DHE-Modules/res/booster-stage/button-dark-on.svg new file mode 100644 index 00000000..60f3959f --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/booster-stage/button-dark-on.svg @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/booster-stage/button-light-off.svg b/plugins/community/repos/DHE-Modules/res/booster-stage/button-light-off.svg new file mode 100644 index 00000000..28b37c35 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/booster-stage/button-light-off.svg @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/booster-stage/button-light-on.svg b/plugins/community/repos/DHE-Modules/res/booster-stage/button-light-on.svg new file mode 100644 index 00000000..409d4766 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/booster-stage/button-light-on.svg @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/booster-stage/knob-large.svg b/plugins/community/repos/DHE-Modules/res/booster-stage/knob-large.svg new file mode 100644 index 00000000..9f4a531b --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/booster-stage/knob-large.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/booster-stage/panel.svg b/plugins/community/repos/DHE-Modules/res/booster-stage/panel.svg new file mode 100644 index 00000000..03f14134 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/booster-stage/panel.svg @@ -0,0 +1,474 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/booster-stage/port.svg b/plugins/community/repos/DHE-Modules/res/booster-stage/port.svg new file mode 100644 index 00000000..d567be85 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/booster-stage/port.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/booster-stage/switch-2-high.svg b/plugins/community/repos/DHE-Modules/res/booster-stage/switch-2-high.svg new file mode 100644 index 00000000..3312b0a7 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/booster-stage/switch-2-high.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/booster-stage/switch-2-low.svg b/plugins/community/repos/DHE-Modules/res/booster-stage/switch-2-low.svg new file mode 100644 index 00000000..45b91740 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/booster-stage/switch-2-low.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/booster-stage/switch-3-high.svg b/plugins/community/repos/DHE-Modules/res/booster-stage/switch-3-high.svg new file mode 100644 index 00000000..29c84e6e --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/booster-stage/switch-3-high.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/booster-stage/switch-3-low.svg b/plugins/community/repos/DHE-Modules/res/booster-stage/switch-3-low.svg new file mode 100644 index 00000000..61597de8 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/booster-stage/switch-3-low.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/booster-stage/switch-3-mid.svg b/plugins/community/repos/DHE-Modules/res/booster-stage/switch-3-mid.svg new file mode 100644 index 00000000..15a84259 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/booster-stage/switch-3-mid.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/cubic/knob-small.svg b/plugins/community/repos/DHE-Modules/res/cubic/knob-small.svg new file mode 100644 index 00000000..24b4026a --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/cubic/knob-small.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/cubic/panel.svg b/plugins/community/repos/DHE-Modules/res/cubic/panel.svg new file mode 100644 index 00000000..01f2dbb4 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/cubic/panel.svg @@ -0,0 +1,273 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/cubic/port.svg b/plugins/community/repos/DHE-Modules/res/cubic/port.svg new file mode 100644 index 00000000..71848d41 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/cubic/port.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/hostage/knob-large.svg b/plugins/community/repos/DHE-Modules/res/hostage/knob-large.svg new file mode 100644 index 00000000..92c1ec49 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/hostage/knob-large.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/hostage/panel.svg b/plugins/community/repos/DHE-Modules/res/hostage/panel.svg new file mode 100644 index 00000000..93d0bd21 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/hostage/panel.svg @@ -0,0 +1,372 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/hostage/port.svg b/plugins/community/repos/DHE-Modules/res/hostage/port.svg new file mode 100644 index 00000000..cb75a644 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/hostage/port.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/hostage/switch-2-high.svg b/plugins/community/repos/DHE-Modules/res/hostage/switch-2-high.svg new file mode 100644 index 00000000..94c9b358 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/hostage/switch-2-high.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/hostage/switch-2-low.svg b/plugins/community/repos/DHE-Modules/res/hostage/switch-2-low.svg new file mode 100644 index 00000000..9b7aef6f --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/hostage/switch-2-low.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/hostage/switch-3-high.svg b/plugins/community/repos/DHE-Modules/res/hostage/switch-3-high.svg new file mode 100644 index 00000000..398c317d --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/hostage/switch-3-high.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/hostage/switch-3-low.svg b/plugins/community/repos/DHE-Modules/res/hostage/switch-3-low.svg new file mode 100644 index 00000000..8ff9662c --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/hostage/switch-3-low.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/hostage/switch-3-mid.svg b/plugins/community/repos/DHE-Modules/res/hostage/switch-3-mid.svg new file mode 100644 index 00000000..e0a31c00 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/hostage/switch-3-mid.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/stage/knob-large.svg b/plugins/community/repos/DHE-Modules/res/stage/knob-large.svg new file mode 100644 index 00000000..e9179b5b --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/stage/knob-large.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/stage/panel.svg b/plugins/community/repos/DHE-Modules/res/stage/panel.svg new file mode 100644 index 00000000..926079fd --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/stage/panel.svg @@ -0,0 +1,308 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/stage/port.svg b/plugins/community/repos/DHE-Modules/res/stage/port.svg new file mode 100644 index 00000000..432350ea --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/stage/port.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/swave/knob-large.svg b/plugins/community/repos/DHE-Modules/res/swave/knob-large.svg new file mode 100644 index 00000000..9ef48fb9 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/swave/knob-large.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/swave/panel.svg b/plugins/community/repos/DHE-Modules/res/swave/panel.svg new file mode 100644 index 00000000..20763d75 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/swave/panel.svg @@ -0,0 +1,169 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/swave/port.svg b/plugins/community/repos/DHE-Modules/res/swave/port.svg new file mode 100644 index 00000000..3f9e71ae --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/swave/port.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/swave/switch-2-high.svg b/plugins/community/repos/DHE-Modules/res/swave/switch-2-high.svg new file mode 100644 index 00000000..eceab81d --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/swave/switch-2-high.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/swave/switch-2-low.svg b/plugins/community/repos/DHE-Modules/res/swave/switch-2-low.svg new file mode 100644 index 00000000..df41e090 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/swave/switch-2-low.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/upstage/button-dark-off.svg b/plugins/community/repos/DHE-Modules/res/upstage/button-dark-off.svg new file mode 100644 index 00000000..94efcaaa --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/upstage/button-dark-off.svg @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/upstage/button-dark-on.svg b/plugins/community/repos/DHE-Modules/res/upstage/button-dark-on.svg new file mode 100644 index 00000000..33868c5c --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/upstage/button-dark-on.svg @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/upstage/knob-large.svg b/plugins/community/repos/DHE-Modules/res/upstage/knob-large.svg new file mode 100644 index 00000000..8d98db91 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/upstage/knob-large.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/upstage/panel.svg b/plugins/community/repos/DHE-Modules/res/upstage/panel.svg new file mode 100644 index 00000000..473cda46 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/upstage/panel.svg @@ -0,0 +1,289 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/upstage/port.svg b/plugins/community/repos/DHE-Modules/res/upstage/port.svg new file mode 100644 index 00000000..10208f2b --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/upstage/port.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/upstage/switch-2-high.svg b/plugins/community/repos/DHE-Modules/res/upstage/switch-2-high.svg new file mode 100644 index 00000000..2e1a54f0 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/upstage/switch-2-high.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/res/upstage/switch-2-low.svg b/plugins/community/repos/DHE-Modules/res/upstage/switch-2-low.svg new file mode 100644 index 00000000..6ba49e0d --- /dev/null +++ b/plugins/community/repos/DHE-Modules/res/upstage/switch-2-low.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/DHE-Modules/script/appveyor-build.sh b/plugins/community/repos/DHE-Modules/script/appveyor-build.sh new file mode 100644 index 00000000..f4d56d0e --- /dev/null +++ b/plugins/community/repos/DHE-Modules/script/appveyor-build.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -o errexit +set -o nounset +set -o xtrace + +echo "MSYSTEM=${MSYSTEM}" +export VCV_PLUGIN_NAME=DHE-Modules +export VCV_PLUGIN_DIR="${APPVEYOR_BUILD_FOLDER}" +export VCV_RACK_DIR=/c/tmp/Rack +export VCV_RACK_COMMIT=master +export VCV_HOME_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +env | sort + +mkdir -p "${VCV_RACK_DIR}" \ +git clone -n https://github.com/VCVRack/Rack.git "${VCV_RACK_DIR}" || true +cd "${VCV_RACK_DIR}" +git checkout ${VCV_RACK_COMMIT} +git pull +git submodule update --init --recursive + +make dep > /dev/null +make + +cd "${VCV_PLUGIN_DIR}" + +make clean test dist RACK_DIR="${VCV_RACK_DIR}" diff --git a/plugins/community/repos/DHE-Modules/script/build-rack.sh b/plugins/community/repos/DHE-Modules/script/build-rack.sh new file mode 100644 index 00000000..8a6d3f2b --- /dev/null +++ b/plugins/community/repos/DHE-Modules/script/build-rack.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# This script uses these environment variables: +# +# VCV_RACK_DIR +# +# The directory in which to clone and build Rack. +# +# VCV_RACK_COMMIT +# +# Which Rack commit to build. + +mkdir -p "${VCV_RACK_DIR}" \ +git clone -n https://github.com/VCVRack/Rack.git "${VCV_RACK_DIR}" || true +cd "${VCV_RACK_DIR}" +git checkout ${VCV_RACK_COMMIT} +git pull +git submodule update --init --recursive + +make dep > /dev/null +make diff --git a/plugins/community/repos/DHE-Modules/src/gui/booster-stage-widget.cpp b/plugins/community/repos/DHE-Modules/src/gui/booster-stage-widget.cpp new file mode 100644 index 00000000..87bdcfd5 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/gui/booster-stage-widget.cpp @@ -0,0 +1,110 @@ +#include +#include +#include "../plugin/dhe-modules.h" + +#include "modules/booster-stage-module.h" +#include "booster-stage-widget.h" + +namespace rack_plugin_DHE_Modules { + +struct BoosterStageButtonDark : rack::SVGSwitch, rack::MomentarySwitch { + BoosterStageButtonDark() { + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/booster-stage/button-dark-off.svg"))); + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/booster-stage/button-dark-on.svg"))); + } +}; + +struct BoosterStageButtonLight : rack::SVGSwitch, rack::MomentarySwitch { + BoosterStageButtonLight() { + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/booster-stage/button-light-off.svg"))); + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/booster-stage/button-light-on.svg"))); + } +}; + +struct BoosterStageKnobLarge : rack::RoundKnob { + BoosterStageKnobLarge() { + setSVG(rack::SVG::load(rack::assetPlugin(plugin, "res/booster-stage/knob-large.svg"))); + shadow->opacity = 0.f; + } +}; + +struct BoosterStagePort : rack::SVGPort { + BoosterStagePort() { + background->svg = rack::SVG::load(assetPlugin(plugin, "res/booster-stage/port.svg")); + background->wrap(); + box.size = background->box.size; + } +}; + +struct BoosterStageSwitch2 : rack::SVGSwitch, rack::ToggleSwitch { + BoosterStageSwitch2() { + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/booster-stage/switch-2-low.svg"))); + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/booster-stage/switch-2-high.svg"))); + } +}; + +struct BoosterStageSwitch3 : rack::SVGSwitch, rack::ToggleSwitch { + BoosterStageSwitch3() { + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/booster-stage/switch-3-low.svg"))); + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/booster-stage/switch-3-mid.svg"))); + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/booster-stage/switch-3-high.svg"))); + } +}; + +BoosterStageWidget::BoosterStageWidget(rack::Module *module) : ModuleWidget(module, 8, "res/booster-stage/panel.svg") { + auto width = 8.f*5.08f; + + auto left_x = width/6.f + 0.3333333f; + auto center_x = width/2.f; + auto right_x = width - left_x; + auto button_port_distance = 7.891f; + auto center_left_x = left_x + button_port_distance; + auto center_right_x = right_x - button_port_distance; + + auto top_row_y = 25.f; + auto row_spacing = 18.5f; + + auto row = 0; + install_input(BoosterStageModule::LEVEL_CV, {left_x, top_row_y + row*row_spacing}); + install_knob(BoosterStageModule::LEVEL_KNOB, {center_x, top_row_y + row*row_spacing}); + install_switch(BoosterStageModule::LEVEL_SWITCH, {right_x, top_row_y + row*row_spacing}, 1, 1); + + row++; + install_input(BoosterStageModule::CURVE_CV, {left_x, top_row_y + row*row_spacing}); + install_knob(BoosterStageModule::CURVE_KNOB, {center_x, top_row_y + row*row_spacing}); + install_switch(BoosterStageModule::SHAPE_SWITCH, {right_x, top_row_y + row*row_spacing}); + + row++; + install_input(BoosterStageModule::DURATION_CV, {left_x, top_row_y + row*row_spacing}); + install_knob(BoosterStageModule::DURATION_KNOB, {center_x, top_row_y + row*row_spacing}); + install_switch(BoosterStageModule::DURATION_SWITCH, {right_x, top_row_y + row*row_spacing}, 2, 1); + + top_row_y = 82.f; + row_spacing = 15.f; + + row = 0; + install_input(BoosterStageModule::DEFER_IN, {left_x, top_row_y + row*row_spacing}); + install_switch(BoosterStageModule::DEFER_BUTTON, {center_left_x, top_row_y + row*row_spacing}); + install_switch(BoosterStageModule::ACTIVE_BUTTON, {center_right_x, top_row_y + row*row_spacing}); + install_output(BoosterStageModule::ACTIVE_OUT, {right_x, top_row_y + row*row_spacing}); + + row++; + install_input(BoosterStageModule::TRIGGER_IN, {left_x, top_row_y + row*row_spacing}); + install_switch(BoosterStageModule::TRIGGER_BUTTON, {center_left_x, top_row_y + row*row_spacing}); + install_switch(BoosterStageModule::EOC_BUTTON, {center_right_x, top_row_y + row*row_spacing}); + install_output(BoosterStageModule::EOC_OUT, {right_x, top_row_y + row*row_spacing}); + + row++; + install_input(BoosterStageModule::ENVELOPE_IN, {left_x, top_row_y + row*row_spacing}); + install_output(BoosterStageModule::ENVELOPE_OUT, {right_x, top_row_y + row*row_spacing}); +} + +} // namespace rack_plugin_DHE_Modules + +using namespace rack_plugin_DHE_Modules; + + +RACK_PLUGIN_MODEL_INIT(DHE_Modules, BoosterStage) { + Model *modelBoosterStage = rack_plugin_DHE_Modules::createModel("Booster Stage", rack::ENVELOPE_GENERATOR_TAG); + return modelBoosterStage; +} diff --git a/plugins/community/repos/DHE-Modules/src/gui/booster-stage-widget.h b/plugins/community/repos/DHE-Modules/src/gui/booster-stage-widget.h new file mode 100644 index 00000000..101b8ad0 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/gui/booster-stage-widget.h @@ -0,0 +1,10 @@ +#pragma once + +#include "module-widget.h" + +namespace rack_plugin_DHE_Modules { + +struct BoosterStageWidget : public ModuleWidget { + explicit BoosterStageWidget(rack::Module *module); +}; +} diff --git a/plugins/community/repos/DHE-Modules/src/gui/cubic-widget.cpp b/plugins/community/repos/DHE-Modules/src/gui/cubic-widget.cpp new file mode 100644 index 00000000..e252a44e --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/gui/cubic-widget.cpp @@ -0,0 +1,72 @@ +#include + +#include "plugin/dhe-modules.h" +#include "modules/cubic-module.h" +#include "cubic-widget.h" + +namespace rack_plugin_DHE_Modules { + +struct CubicKnobsmall : rack::RoundKnob { + CubicKnobsmall() { + setSVG(rack::SVG::load(rack::assetPlugin(plugin, "res/cubic/knob-small.svg"))); + shadow->opacity = 0.f; + } +}; + +struct CubicPort : rack::SVGPort { + CubicPort() { + background->svg = rack::SVG::load(assetPlugin(plugin, "res/cubic/port.svg")); + background->wrap(); + box.size = background->box.size; + } +}; + +CubicWidget::CubicWidget(rack::Module *module) : ModuleWidget(module, 5, "res/cubic/panel.svg") { + auto c_knob_rotation = rack_plugin_DHE_Modules::CubicModule::coefficient_range().normalize(1.f); + auto gain_knob_rotation = rack_plugin_DHE_Modules::CubicModule::gain_range().normalize((1.f)); + auto widget_right_edge = width(); + + auto left_x = width()/4.f + 0.333333f; + auto right_x = widget_right_edge - left_x; + + auto top_row_y = 20.f; + auto row_spacing = 15.f; + + auto row = 0; + install_input(CubicModule::X3_CV, {left_x, top_row_y + row*row_spacing}); + install_knob(CubicModule::X3_KNOB, {right_x, top_row_y + row*row_spacing}); + + row++; + install_input(CubicModule::X2_CV, {left_x, top_row_y + row*row_spacing}); + install_knob(CubicModule::X2_KNOB, {right_x, top_row_y + row*row_spacing}); + + row++; + install_input(CubicModule::X1_CV, {left_x, top_row_y + row*row_spacing}); + install_knob(CubicModule::X1_KNOB, {right_x, top_row_y + row*row_spacing}, c_knob_rotation); + + row++; + install_input(CubicModule::X0_CV, {left_x, top_row_y + row*row_spacing}); + install_knob(CubicModule::X0_KNOB, {right_x, top_row_y + row*row_spacing}); + + top_row_y = 82.f; + row = 0; + install_knob(CubicModule::INPUT_GAIN_KNOB, {left_x, top_row_y + row*row_spacing}, gain_knob_rotation); + install_knob(CubicModule::OUTPUT_GAIN_KNOB, {right_x, top_row_y + row*row_spacing}, gain_knob_rotation); + + row++; + install_input(CubicModule::INPUT_GAIN_CV, {left_x, top_row_y + row*row_spacing}); + install_input(CubicModule::OUTPUT_GAIN_CV, {right_x, top_row_y + row*row_spacing}); + + row++; + install_input(CubicModule::IN, {left_x, top_row_y + row*row_spacing}); + install_output(CubicModule::OUT, {right_x, top_row_y + row*row_spacing}); +} + +} // namespace rack_plugin_DHE_Modules + +using namespace rack_plugin_DHE_Modules; + +RACK_PLUGIN_MODEL_INIT(DHE_Modules, Cubic) { + Model *modelCubic = rack_plugin_DHE_Modules::createModel("Cubic", rack::FUNCTION_GENERATOR_TAG); + return modelCubic; +} diff --git a/plugins/community/repos/DHE-Modules/src/gui/cubic-widget.h b/plugins/community/repos/DHE-Modules/src/gui/cubic-widget.h new file mode 100644 index 00000000..764a38c5 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/gui/cubic-widget.h @@ -0,0 +1,10 @@ +#pragma once + +#include "module-widget.h" + +namespace rack_plugin_DHE_Modules { + +struct CubicWidget : public ModuleWidget { + explicit CubicWidget(rack::Module *module); +}; +} diff --git a/plugins/community/repos/DHE-Modules/src/gui/hostage-widget.cpp b/plugins/community/repos/DHE-Modules/src/gui/hostage-widget.cpp new file mode 100644 index 00000000..ee38e8a1 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/gui/hostage-widget.cpp @@ -0,0 +1,81 @@ +#include + +#include "modules/hostage-module.h" +#include "hostage-widget.h" + +namespace rack_plugin_DHE_Modules { + +struct HostagePort : rack::SVGPort { + HostagePort() { + background->svg = rack::SVG::load(rack::assetPlugin(plugin, "res/hostage/port.svg")); + background->wrap(); + box.size = background->box.size; + } +}; + +struct HostageKnobLarge : rack::RoundKnob { + HostageKnobLarge() { + setSVG(rack::SVG::load(rack::assetPlugin(plugin, "res/hostage/knob-large.svg"))); + shadow->opacity = 0.f; + } +}; + +struct HostageSwitch2 : rack::SVGSwitch, rack::ToggleSwitch { + HostageSwitch2() { + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/hostage/switch-2-low.svg"))); + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/hostage/switch-2-high.svg"))); + } +}; + +struct HostageSwitch3 : rack::SVGSwitch, rack::ToggleSwitch { + HostageSwitch3() { + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/hostage/switch-3-low.svg"))); + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/hostage/switch-3-mid.svg"))); + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/hostage/switch-3-high.svg"))); + } +}; + +HostageWidget::HostageWidget(rack::Module *module) : ModuleWidget(module, 5, "res/hostage/panel.svg") { + auto widget_right_edge = width(); + + auto left_x = width()/4.f + 0.333333f; + auto center_x = widget_right_edge/2.f; + auto right_x = widget_right_edge - left_x; + + auto top_row_y = 25.f; + auto row_spacing = 18.5f; + + auto row = 0; + install_switch(HostageModule::GATE_MODE_SWITCH, {center_x, top_row_y + row*row_spacing}); + + row++; + install_input(HostageModule::DURATION_CV, {left_x, top_row_y + row*row_spacing}); + install_switch(HostageModule::DURATION_SWITCH, {right_x, top_row_y + row*row_spacing}, 2, 1); + + row++; + install_knob(HostageModule::DURATION_KNOB, {center_x, top_row_y + row*row_spacing}); + + top_row_y = 82.f; + row_spacing = 15.f; + + row = 0; + install_input(HostageModule::DEFER_IN, {left_x, top_row_y + row*row_spacing}); + install_output(HostageModule::ACTIVE_OUT, {right_x, top_row_y + row*row_spacing}); + + row++; + install_input(HostageModule::HOLD_GATE_IN, {left_x, top_row_y + row*row_spacing}); + install_output(HostageModule::EOC_OUT, {right_x, top_row_y + row*row_spacing}); + + row++; + install_input(HostageModule::ENVELOPE_IN, {left_x, top_row_y + row*row_spacing}); + install_output(HostageModule::ENVELOPE_OUT, {right_x, top_row_y + row*row_spacing}); +} + +} // namespace rack_plugin_DHE_Modules + +using namespace rack_plugin_DHE_Modules; + +RACK_PLUGIN_MODEL_INIT(DHE_Modules, Hostage) { + Model *modelHostage = rack_plugin_DHE_Modules::createModel("Hostage", rack::ENVELOPE_GENERATOR_TAG); + return modelHostage; +} diff --git a/plugins/community/repos/DHE-Modules/src/gui/hostage-widget.h b/plugins/community/repos/DHE-Modules/src/gui/hostage-widget.h new file mode 100644 index 00000000..b8c32e20 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/gui/hostage-widget.h @@ -0,0 +1,10 @@ +#pragma once + +#include "module-widget.h" + +namespace rack_plugin_DHE_Modules { + +struct HostageWidget : public ModuleWidget { + explicit HostageWidget(rack::Module *module); +}; +} diff --git a/plugins/community/repos/DHE-Modules/src/gui/module-widget.cpp b/plugins/community/repos/DHE-Modules/src/gui/module-widget.cpp new file mode 100644 index 00000000..8afe8df7 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/gui/module-widget.cpp @@ -0,0 +1,57 @@ +#include +#include + +#include +#include +#include + +#include "module-widget.h" + +namespace rack_plugin_DHE_Modules { + +ModuleWidget::ModuleWidget(rack::Module *module, int widget_hp, const char *background) + : rack::ModuleWidget(module) { + box.size = rack::Vec{(float) widget_hp*rack::RACK_GRID_WIDTH, rack::RACK_GRID_HEIGHT}; + + auto *panel = new rack::SVGPanel(); + panel->box.size = box.size; + panel->setBackground(rack::SVG::load(rack::assetPlugin(plugin, background))); + addChild(panel); + + install_screws(); +} + +void ModuleWidget::install_screws() { + + auto screw_diameter = rack::RACK_GRID_WIDTH*MM_PER_IN/SVG_DPI; + auto screw_radius = screw_diameter/2.f; + + auto top = screw_radius; + auto bottom = height() - top; + + auto max_screw_inset = screw_diameter*1.5f; + auto left = std::min(width()/4.f, max_screw_inset); + auto right = width() - left; + + auto screw_positions = std::vector{ + {left, top}, + {left, bottom}, + {right, top}, + {right, bottom} + }; + + std::shuffle(screw_positions.begin(), screw_positions.end(), std::mt19937(std::random_device()())); + + install_screw(screw_positions.back()); + + screw_positions.pop_back(); + + for (auto p : screw_positions) { + install_screw(p); + } +} + +void ModuleWidget::moveTo(rack::Rect &box, rack::Vec center) { + box.pos = center.minus(box.size.mult(0.5f)); +} +} diff --git a/plugins/community/repos/DHE-Modules/src/gui/module-widget.h b/plugins/community/repos/DHE-Modules/src/gui/module-widget.h new file mode 100644 index 00000000..a3fa24f0 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/gui/module-widget.h @@ -0,0 +1,67 @@ +#pragma once + +#include +#include +#include + +#include "plugin/dhe-modules.h" + +namespace rack_plugin_DHE_Modules { + +class ModuleWidget : public rack::ModuleWidget { + +public: + ModuleWidget(rack::Module *module, int widget_hp, const char *background); + + float height() const { + return box.size.y*MM_PER_IN/SVG_DPI; + } + + float width() const { + return box.size.x*MM_PER_IN/SVG_DPI; + } + + template + void install_input(int index, rack::Vec center) { + auto input = rack::Port::create({0, 0}, rack::Port::INPUT, module, index); + moveTo(input->box, rack::mm2px(center)); + addInput(input); + } + + template + void install_knob(int index, rack::Vec center, float initial_rotation = 0.5f) { + install_param(index, center, 0.f, 1.f, initial_rotation); + } + + template + void install_output(int index, rack::Vec center) { + auto output = rack::Port::create({0, 0}, rack::Port::OUTPUT, module, index); + moveTo(output->box, rack::mm2px(center)); + addOutput(output); + } + + template + void install_param(int index, rack::Vec center, float low, float high, float initial) { + auto param = rack::ParamWidget::create({0, 0}, module, index, low, high, initial); + moveTo(param->box, rack::mm2px(center)); + addParam(param); + } + + template + void install_screw(rack::Vec center) { + auto widget = rack::Widget::create({0, 0}); + moveTo(widget->box, rack::mm2px(center)); + addChild(widget); + } + + template + void install_switch(int index, rack::Vec center, int max_position = 1, int initial_position = 0) { + install_param(index, center, 0.f, (float) max_position, (float) initial_position); + } + + static void moveTo(rack::Rect &box, rack::Vec center); + + void install_screws(); +}; + +} diff --git a/plugins/community/repos/DHE-Modules/src/gui/stage-widget.cpp b/plugins/community/repos/DHE-Modules/src/gui/stage-widget.cpp new file mode 100644 index 00000000..49bd1e38 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/gui/stage-widget.cpp @@ -0,0 +1,65 @@ +#include + +#include "modules/stage-module.h" +#include "stage-widget.h" + +namespace rack_plugin_DHE_Modules { + +struct StagePort : rack::SVGPort { + StagePort() { + background->svg = rack::SVG::load(rack::assetPlugin(plugin, "res/stage/port.svg")); + background->wrap(); + box.size = background->box.size; + } +}; + +struct StageKnobLarge : rack::RoundKnob { + StageKnobLarge() { + setSVG(rack::SVG::load(rack::assetPlugin(plugin, "res/stage/knob-large.svg"))); + shadow->opacity = 0.f; + } +}; + +StageWidget::StageWidget(rack::Module *module) : ModuleWidget(module, 5, "res/stage/panel.svg") { + auto widget_right_edge = width(); + + auto left_x = width()/4.f + 0.333333f; + auto center_x = widget_right_edge/2.f; + auto right_x = widget_right_edge - left_x; + + auto top_row_y = 25.f; + auto row_spacing = 18.5f; + + auto row = 0; + install_knob(StageModule::LEVEL_KNOB, {center_x, top_row_y + row*row_spacing}); + + row++; + install_knob(StageModule::CURVE_KNOB, {center_x, top_row_y + row*row_spacing}); + + row++; + install_knob(StageModule::DURATION_KNOB, {center_x, top_row_y + row*row_spacing}); + + top_row_y = 82.f; + row_spacing = 15.f; + + row = 0; + install_input(StageModule::DEFER_IN, {left_x, top_row_y + row*row_spacing}); + install_output(StageModule::ACTIVE_OUT, {right_x, top_row_y + row*row_spacing}); + + row++; + install_input(StageModule::TRIGGER_IN, {left_x, top_row_y + row*row_spacing}); + install_output(StageModule::EOC_OUT, {right_x, top_row_y + row*row_spacing}); + + row++; + install_input(StageModule::ENVELOPE_IN, {left_x, top_row_y + row*row_spacing}); + install_output(StageModule::ENVELOPE_OUT, {right_x, top_row_y + row*row_spacing}); +} + +} // namespace rack_plugin_DHE_Modules + +using namespace rack_plugin_DHE_Modules; + +RACK_PLUGIN_MODEL_INIT(DHE_Modules, Stage) { + Model *modelStage = rack_plugin_DHE_Modules::createModel("Stage", rack::ENVELOPE_GENERATOR_TAG); + return modelStage; +} diff --git a/plugins/community/repos/DHE-Modules/src/gui/stage-widget.h b/plugins/community/repos/DHE-Modules/src/gui/stage-widget.h new file mode 100644 index 00000000..b7e385fe --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/gui/stage-widget.h @@ -0,0 +1,10 @@ +#pragma once + +#include "module-widget.h" + +namespace rack_plugin_DHE_Modules { + +struct StageWidget : public ModuleWidget { + explicit StageWidget(rack::Module *module); +}; +} diff --git a/plugins/community/repos/DHE-Modules/src/gui/swave-widget.cpp b/plugins/community/repos/DHE-Modules/src/gui/swave-widget.cpp new file mode 100644 index 00000000..a7174bd0 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/gui/swave-widget.cpp @@ -0,0 +1,67 @@ +#include + +#include "plugin/dhe-modules.h" +#include "modules/swave-module.h" +#include "swave-widget.h" + +namespace rack_plugin_DHE_Modules { + +struct SwaveKnobLarge : rack::RoundKnob { + SwaveKnobLarge() { + setSVG(rack::SVG::load(rack::assetPlugin(plugin, "res/swave/knob-large.svg"))); + shadow->opacity = 0.f; + } +}; + +struct SwavePort : rack::SVGPort { + SwavePort() { + background->svg = rack::SVG::load(assetPlugin(plugin, "res/swave/port.svg")); + background->wrap(); + box.size = background->box.size; + } +}; + +struct SwaveSwitch2 : rack::SVGSwitch, rack::ToggleSwitch { + SwaveSwitch2() { + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/swave/switch-2-low.svg"))); + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/swave/switch-2-high.svg"))); + } +}; + +SwaveWidget::SwaveWidget(rack::Module *module) : ModuleWidget(module, 4, "res/swave/panel.svg") { + auto widget_right_edge = width(); + + auto center_x = widget_right_edge/2.f; + + auto top_row_y = 25.f; + auto row_spacing = 18.5f; + + auto row = 0; + install_switch(SwaveModule::SHAPE_SWITCH, {center_x, top_row_y + row*row_spacing}, 1, 1); + + row++; + install_knob(SwaveModule::CURVE_KNOB, {center_x, top_row_y + row*row_spacing}); + + row++; + install_input(SwaveModule::CURVE_CV, {center_x, top_row_y + row*row_spacing}); + + top_row_y = 82.f; + row_spacing = 15.f; + + row = 0; + + row++; + install_input(SwaveModule::SWAVE_IN, {center_x, top_row_y + row*row_spacing}); + + row++; + install_output(SwaveModule::SWAVE_OUT, {center_x, top_row_y + row*row_spacing}); +} + +} // namespace rack_plugin_DHE_Modules + +using namespace rack_plugin_DHE_Modules; + +RACK_PLUGIN_MODEL_INIT(DHE_Modules, Swave) { + Model *modelSwave = rack_plugin_DHE_Modules::createModel("Swave", rack::WAVESHAPER_TAG); + return modelSwave; +} diff --git a/plugins/community/repos/DHE-Modules/src/gui/swave-widget.h b/plugins/community/repos/DHE-Modules/src/gui/swave-widget.h new file mode 100644 index 00000000..22ae7863 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/gui/swave-widget.h @@ -0,0 +1,10 @@ +#pragma once + +#include "module-widget.h" + +namespace rack_plugin_DHE_Modules { + +struct SwaveWidget : public ModuleWidget { + explicit SwaveWidget(rack::Module *module); +}; +} diff --git a/plugins/community/repos/DHE-Modules/src/gui/upstage-widget.cpp b/plugins/community/repos/DHE-Modules/src/gui/upstage-widget.cpp new file mode 100644 index 00000000..f70e17b5 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/gui/upstage-widget.cpp @@ -0,0 +1,80 @@ +#include +#include + +#include "modules/upstage-module.h" +#include "upstage-widget.h" + +namespace rack_plugin_DHE_Modules { + +struct UpstageButtonDark : rack::SVGSwitch, rack::MomentarySwitch { + UpstageButtonDark() { + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/upstage/button-dark-off.svg"))); + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/upstage/button-dark-on.svg"))); + } +}; + +struct UpstageKnobLarge : rack::RoundKnob { + UpstageKnobLarge() { + setSVG(rack::SVG::load(rack::assetPlugin(plugin, "res/upstage/knob-large.svg"))); + shadow->opacity = 0.f; + } +}; + +struct UpstagePort : rack::SVGPort { + UpstagePort() { + background->svg = rack::SVG::load(assetPlugin(plugin, "res/upstage/port.svg")); + background->wrap(); + box.size = background->box.size; + } +}; + +struct UpstageSwitch2 : rack::SVGSwitch, rack::ToggleSwitch { + UpstageSwitch2() { + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/upstage/switch-2-low.svg"))); + addFrame(rack::SVG::load(rack::assetPlugin(plugin, "res/upstage/switch-2-high.svg"))); + } +}; + +UpstageWidget::UpstageWidget(rack::Module *module) : ModuleWidget(module, 5, "res/upstage/panel.svg") { + auto widget_right_edge = width(); + + auto left_x = width()/4.f + 0.333333333f; + auto center_x = widget_right_edge/2.f; + auto right_x = widget_right_edge - left_x; + + auto top_row_y = 25.f; + auto row_spacing = 18.5f; + + auto row = 0; + install_knob(UpstageModule::LEVEL_KNOB, {center_x, top_row_y + row*row_spacing}); + + row++; + install_input(UpstageModule::LEVEL_CV, {left_x, top_row_y + row*row_spacing}); + install_switch(UpstageModule::LEVEL_SWITCH, {right_x, top_row_y + row*row_spacing}, 1, 1); + + row++; + install_switch(UpstageModule::WAIT_BUTTON, {left_x, top_row_y + row*row_spacing}); + install_switch(UpstageModule::TRIG_BUTTON, {right_x, top_row_y + row*row_spacing}); + + top_row_y = 82.f; + row_spacing = 15.f; + + row = 0; + install_input(UpstageModule::WAIT_IN, {left_x, top_row_y + row*row_spacing}); + + row++; + install_input(UpstageModule::TRIG_IN, {left_x, top_row_y + row*row_spacing}); + install_output(UpstageModule::TRIG_OUT, {right_x, top_row_y + row*row_spacing}); + + row++; + install_output(UpstageModule::ENVELOPE_OUT, {right_x, top_row_y + row*row_spacing}); +} + +} // namespace rack_plugin_DHE_Modules + +using namespace rack_plugin_DHE_Modules; + +RACK_PLUGIN_MODEL_INIT(DHE_Modules, Upstage) { + Model *modelUpstage = rack_plugin_DHE_Modules::createModel("Upstage", rack::ENVELOPE_GENERATOR_TAG); + return modelUpstage; +} diff --git a/plugins/community/repos/DHE-Modules/src/gui/upstage-widget.h b/plugins/community/repos/DHE-Modules/src/gui/upstage-widget.h new file mode 100644 index 00000000..ec100ee9 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/gui/upstage-widget.h @@ -0,0 +1,10 @@ +#pragma once + +#include "module-widget.h" + +namespace rack_plugin_DHE_Modules { + +struct UpstageWidget : public ModuleWidget { + explicit UpstageWidget(rack::Module *module); +}; +} diff --git a/plugins/community/repos/DHE-Modules/src/modules/booster-stage-module.h b/plugins/community/repos/DHE-Modules/src/modules/booster-stage-module.h new file mode 100644 index 00000000..2a886a76 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/modules/booster-stage-module.h @@ -0,0 +1,170 @@ +#pragma once + +#include +#include +#include + +#include +#include "util/controls.h" +#include "module.h" + +namespace rack_plugin_DHE_Modules { + +#define sMIN(a,b) (((a)>(b))?(b):(a)) +#define sMAX(a,b) (((a)>(b))?(a):(b)) + +struct BoosterStageModule : Module { + Mode stage_mode = {}; + Mode defer_mode = {}; + + // TODO: Move this inside stage mode or an envelope class. + float phase_0_voltage{0.f}; + bool is_active{false}; + bool is_eoc{false}; + + Ramp envelope = Ramp{[this] { return sample_time()/duration_in(); }}; + Ramp eoc_pulse = Ramp{[this] { return sample_time()/1e-3f; }}; + DFlipFlop envelope_trigger = DFlipFlop{[this] { return envelope_gate_in(); }}; + + SubmodeSwitch executor = {[this] { return defer_gate_in(); }, &stage_mode, &defer_mode}; + + BoosterStageModule() + : Module{PARAMETER_COUNT, INPUT_COUNT, OUTPUT_COUNT} { + + defer_mode.on_entry([this] { + is_active = true; + }); + defer_mode.on_step([this] { + send_envelope(envelope_in()); + }); + + stage_mode.on_entry([this] { + is_active = false; + phase_0_voltage = envelope_in(); + envelope_trigger.enable(); + }); + stage_mode.on_step([this] { + envelope_trigger.step(); + envelope.step(); + send_envelope(envelope_voltage(envelope.phase())); // TODO: Move to envelope.on_step() + }); + stage_mode.on_exit([this] { + envelope_trigger.disable(); + envelope.stop(); + }); + + envelope_trigger.on_rise([this] { + phase_0_voltage = envelope_in(); + envelope.start(); + }); + + envelope.on_start([this] { + is_active = true; + }); + envelope.on_completion([this] { + is_active = false; + eoc_pulse.start(); + }); + + eoc_pulse.on_start([this] { + is_eoc = true; + }); + eoc_pulse.on_completion([this] { + is_eoc = false; + }); + + executor.on_step([this] { eoc_pulse.step(); }); + executor.enter(); + } + + void step() override { + executor.step(); + send_active(); + send_eoc(); + } + + float defer_gate_in() const { + return sMAX(input(DEFER_IN), gate_button(DEFER_BUTTON)); + } + + float duration_in() const { + auto rotation = modulated(DURATION_KNOB, DURATION_CV); + const auto &range = Duration::range(param(DURATION_SWITCH)); + return Duration::scaled(rotation, range); + } + + float envelope_gate_in() const { + return sMAX(input(TRIGGER_IN), gate_button(TRIGGER_BUTTON)); + } + + float envelope_in() const { + return input(ENVELOPE_IN); + } + + float envelope_voltage(float phase) const { + return scale(taper(phase), phase_0_voltage, level_in()); + } + + bool is_s_taper() const { + return param(SHAPE_SWITCH) > 0.5; + } + + float level_in() const { + const auto &range = Level::range(param(LEVEL_SWITCH)); + auto rotation = modulated(LEVEL_KNOB, LEVEL_CV); + return Level::scaled(rotation, range); + } + + void send_active() { + outputs[ACTIVE_OUT].value = UNIPOLAR_SIGNAL_RANGE.scale(is_active || param(ACTIVE_BUTTON) > 0.5f); + } + + void send_envelope(float voltage) { + outputs[ENVELOPE_OUT].value = voltage; + } + + void send_eoc() { + outputs[EOC_OUT].value = UNIPOLAR_SIGNAL_RANGE.scale(is_eoc || param(EOC_BUTTON) > 0.5f); + } + + float sample_time() const { + return rack::engineGetSampleTime(); + } + + float taper(float phase) const { + auto rotation = modulated(CURVE_KNOB, CURVE_CV); + return is_s_taper() ? Taper::s(phase, rotation) : Taper::j(phase, rotation); + } + + enum ParameterIds { + ACTIVE_BUTTON, + CURVE_KNOB, + DEFER_BUTTON, + DURATION_KNOB, + DURATION_SWITCH, + EOC_BUTTON, + LEVEL_KNOB, + LEVEL_SWITCH, + SHAPE_SWITCH, + TRIGGER_BUTTON, + PARAMETER_COUNT + }; + + enum InputIds { + CURVE_CV, + DEFER_IN, + DURATION_CV, + LEVEL_CV, + ENVELOPE_IN, + TRIGGER_IN, + INPUT_COUNT + }; + + enum OutputIds { + ACTIVE_OUT, + EOC_OUT, + ENVELOPE_OUT, + OUTPUT_COUNT + }; +}; +} diff --git a/plugins/community/repos/DHE-Modules/src/modules/cubic-module.h b/plugins/community/repos/DHE-Modules/src/modules/cubic-module.h new file mode 100644 index 00000000..5ce0a333 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/modules/cubic-module.h @@ -0,0 +1,71 @@ +#pragma once + +#include "module.h" + +namespace rack_plugin_DHE_Modules { + +struct CubicModule : Module { + CubicModule() : Module{PARAMETER_COUNT, INPUT_COUNT, OUTPUT_COUNT} { + } + + static const Range &gain_range() { + static constexpr auto gain_range = Range{0.f, 2.f}; + return gain_range; + } + + static const Range &coefficient_range() { + static constexpr auto coefficient_range = Range{-2.f, 2.f}; + return coefficient_range; + } + + float gain(int knob, int cv) const { + return gain_range().scale(modulated(knob, cv)); + } + + float coefficient(int knob, int cv) const { + return coefficient_range().scale(modulated(knob, cv)); + } + + float a() const { return coefficient(X3_KNOB, X3_CV); } + float b() const { return coefficient(X2_KNOB, X2_CV); } + float c() const { return coefficient(X1_KNOB, X1_CV); } + float d() const { return coefficient(X0_KNOB, X0_CV); } + float input_gain() const { return gain(INPUT_GAIN_KNOB, INPUT_GAIN_CV); } + float output_gain() const { return gain(OUTPUT_GAIN_KNOB, OUTPUT_GAIN_CV); } + + void step() override { + auto x = input_gain()*input(IN)/5.f; + auto x2 = x*x; + auto x3 = x2*x; + + auto y = output_gain()*(a()*x3 + b()*x2 + c()*x + d()); + + outputs[OUT].value = 5.f*y; + } + + enum ParameterIds { + X3_KNOB, + X2_KNOB, + X1_KNOB, + X0_KNOB, + INPUT_GAIN_KNOB, + OUTPUT_GAIN_KNOB, + PARAMETER_COUNT + }; + enum InputIds { + IN, + X3_CV, + X2_CV, + X1_CV, + X0_CV, + INPUT_GAIN_CV, + OUTPUT_GAIN_CV, + INPUT_COUNT + }; + enum OutputIds { + OUT, + OUTPUT_COUNT + }; +}; + +} diff --git a/plugins/community/repos/DHE-Modules/src/modules/hostage-module.h b/plugins/community/repos/DHE-Modules/src/modules/hostage-module.h new file mode 100644 index 00000000..7164a6a4 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/modules/hostage-module.h @@ -0,0 +1,161 @@ +#pragma once + +#include +#include + +#include "module.h" +#include "util/controls.h" +#include "util/d-flip-flop.h" +#include "util/ramp.h" + +namespace rack_plugin_DHE_Modules { + +struct HostageModule : Module { + + DFlipFlop sustain_gate = DFlipFlop{[this] { return hold_gate_in(); }}; + DFlipFlop sustain_trigger = DFlipFlop{[this] { return hold_gate_in(); }}; + Ramp timer = Ramp{[this] { return sample_time()/duration_in(); }}; + Ramp eoc_pulse = Ramp{[this] { return sample_time()/1e-3f; }}; + + Mode defer_mode = {}; + Mode timed_sustain_mode = {}; + Mode gated_sustain_mode = {}; + SubmodeSwitch sustain_mode = {[this] { return mode_switch_in(); }, &timed_sustain_mode, &gated_sustain_mode}; + SubmodeSwitch executor = {[this] { return defer_gate_in(); }, &sustain_mode, &defer_mode}; + + HostageModule() : Module{PARAMETER_COUNT, INPUT_COUNT, OUTPUT_COUNT} { + defer_mode.on_entry([this] { + send_active(true); + }); + defer_mode.on_step([this] { + send_envelope(envelope_in()); + }); + + timed_sustain_mode.on_entry([this] { + sustain_trigger.enable(); + send_active(false); + send_envelope(envelope_in()); + }); + timed_sustain_mode.on_step([this] { + sustain_trigger.step(); + timer.step(); + }); + timed_sustain_mode.on_exit([this] { + sustain_trigger.disable(); + timer.stop(); + }); + + sustain_trigger.on_rise([this] { + timer.start(); + }); + + timer.on_start([this] { + begin_sustaining(); + }); + timer.on_completion([this] { + end_sustaining(); + }); + + gated_sustain_mode.on_entry([this] { + sustain_gate.step(); + sustain_gate.enable(); + if (sustain_gate.is_high()) begin_sustaining(); + else end_sustaining(); + }); + gated_sustain_mode.on_step([this] { + sustain_gate.step(); + }); + gated_sustain_mode.on_exit([this] { + sustain_gate.disable(); + }); + + sustain_gate.on_rise([this] { + begin_sustaining(); + }); + sustain_gate.on_fall([this] { + end_sustaining(); + }); + + eoc_pulse.on_start([this] { + send_eoc(true); + }); + eoc_pulse.on_completion([this] { + send_eoc(false); + }); + + executor.on_step([this] { eoc_pulse.step(); }); + executor.enter(); + } + + void end_sustaining() { + send_active(false); + eoc_pulse.start(); + } + void begin_sustaining() { send_active(true); } + + void step() override { + executor.step(); + } + + float defer_gate_in() const { + return input(DEFER_IN); + }; + + float mode_switch_in() const { + return param(GATE_MODE_SWITCH); + } + + float duration_in() const { + auto rotation = modulated(DURATION_KNOB, DURATION_CV); + const auto &range = Duration::range(param(DURATION_SWITCH)); + return Duration::scaled(rotation, range); + } + + float hold_gate_in() const { + return input(HOLD_GATE_IN); + } + + float envelope_in() const { + return input(ENVELOPE_IN); + } + + void send_active(bool is_active) { + outputs[ACTIVE_OUT].value = UNIPOLAR_SIGNAL_RANGE.scale(is_active); + } + + void send_envelope(float voltage) { + outputs[ENVELOPE_OUT].value = voltage; + } + + void send_eoc(bool is_pulsing) { + outputs[EOC_OUT].value = UNIPOLAR_SIGNAL_RANGE.scale(is_pulsing); + } + + float sample_time() const { + return rack::engineGetSampleTime(); + } + + enum InputIds { + DEFER_IN, + DURATION_CV, + ENVELOPE_IN, + HOLD_GATE_IN, + INPUT_COUNT + }; + + enum OutputIds { + ACTIVE_OUT, + ENVELOPE_OUT, + EOC_OUT, + OUTPUT_COUNT + }; + + enum ParameterIds { + DURATION_KNOB, + DURATION_SWITCH, + GATE_MODE_SWITCH, + PARAMETER_COUNT + }; +}; + +} diff --git a/plugins/community/repos/DHE-Modules/src/modules/module.h b/plugins/community/repos/DHE-Modules/src/modules/module.h new file mode 100644 index 00000000..32899cae --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/modules/module.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +#include "util/range.h" + +namespace rack_plugin_DHE_Modules { + +struct Module : rack::Module { + Module(int param_count, int input_count, int output_count) + : rack::Module(param_count, input_count, output_count) {} + + float gate_button(int index) const { + return UNIPOLAR_SIGNAL_RANGE.scale(param(index) > 0.5f); + }; + + float input(int index) const { + return inputs[index].value; + } + + float modulated(int param_index, int mod_index) const { + return param(param_index) + input(mod_index)/10.f; + } + + float param(int index) const { + return params[index].value; + } +}; + +} diff --git a/plugins/community/repos/DHE-Modules/src/modules/stage-module.h b/plugins/community/repos/DHE-Modules/src/modules/stage-module.h new file mode 100644 index 00000000..8854f004 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/modules/stage-module.h @@ -0,0 +1,146 @@ +#pragma once + +#include + +#include "module.h" +#include "util/controls.h" +#include "util/d-flip-flop.h" +#include "util/mode.h" +#include "util/ramp.h" +#include "util/range.h" + +namespace rack_plugin_DHE_Modules { + +struct StageModule : public Module { + Mode stage_mode = {}; + Mode defer_mode = {}; + + // TODO: Move this inside stage mode or an envelope class. + float phase_0_voltage{0.f}; + + Ramp envelope = Ramp{[this] { return sample_time()/duration_in(); }}; + DFlipFlop envelope_trigger = DFlipFlop{[this] { return envelope_gate_in(); }}; + Ramp eoc_pulse = Ramp{[this] { return sample_time()/1e-3f; }}; + + SubmodeSwitch executor = {[this] { return defer_gate_in(); }, &stage_mode, &defer_mode}; + + void onReset() override { + Module::onReset(); + } + StageModule() : Module(PARAMETER_COUNT, INPUT_COUNT, OUTPUT_COUNT) { + defer_mode.on_entry([this] { + send_active(true); + }); + defer_mode.on_step([this] { + send_envelope(envelope_in()); + }); + + stage_mode.on_entry([this] { + send_active(false); + phase_0_voltage = envelope_in(); + envelope_trigger.enable(); + }); + stage_mode.on_step([this] { + envelope_trigger.step(); + envelope.step(); + send_envelope(envelope_voltage(envelope.phase())); // TODO: Move to envelope.on_step() + }); + stage_mode.on_exit([this] { + envelope_trigger.disable(); + envelope.stop(); + }); + + envelope_trigger.on_rise([this] { + phase_0_voltage = envelope_in(); + envelope.start(); + }); + + envelope.on_start([this] { + send_active(true); + }); + envelope.on_completion([this] { + send_active(false); + eoc_pulse.start(); + }); + + eoc_pulse.on_start([this] { + send_eoc(true); + }); + eoc_pulse.on_completion([this] { + send_eoc(false); + }); + + executor.on_step([this] { eoc_pulse.step(); }); + executor.enter(); + } + + float defer_gate_in() const { + return input(DEFER_IN); + } + + float duration_in() const { + return Duration::scaled(param(DURATION_KNOB), Duration::MEDIUM_RANGE); + } + + float envelope_gate_in() const { + return input(TRIGGER_IN); + } + + float envelope_in() const { + return input(ENVELOPE_IN); + } + + float envelope_voltage(float phase) const { + return scale(taper(phase), phase_0_voltage, level_in()); + } + + float level_in() const { + return Level::scaled(param(LEVEL_KNOB)); + } + + float sample_time() const { + return rack::engineGetSampleTime(); + } + + void send_active(bool is_active) { + outputs[ACTIVE_OUT].value = UNIPOLAR_SIGNAL_RANGE.scale(is_active); + } + + void send_envelope(float voltage) { + outputs[ENVELOPE_OUT].value = voltage; + } + + void send_eoc(bool is_pulsing) { + outputs[EOC_OUT].value = UNIPOLAR_SIGNAL_RANGE.scale(is_pulsing); + } + + void step() override { + executor.step(); + } + + float taper(float phase) const { + return Taper::j(phase, param(CURVE_KNOB)); + } + + enum ParameterIIds { + DURATION_KNOB, + LEVEL_KNOB, + CURVE_KNOB, + PARAMETER_COUNT + }; + + enum InputIds { + ENVELOPE_IN, + TRIGGER_IN, + DEFER_IN, + INPUT_COUNT + }; + + enum OutputIds { + ENVELOPE_OUT, + EOC_OUT, + ACTIVE_OUT, + OUTPUT_COUNT + }; +}; +} diff --git a/plugins/community/repos/DHE-Modules/src/modules/swave-module.h b/plugins/community/repos/DHE-Modules/src/modules/swave-module.h new file mode 100644 index 00000000..c13f1d6a --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/modules/swave-module.h @@ -0,0 +1,55 @@ +#pragma once + +#include + +#include + +#include "module.h" +#include "util/controls.h" +#include "util/range.h" + +namespace rack_plugin_DHE_Modules { + +struct SwaveModule : Module { + SwaveModule() : Module{PARAMETER_COUNT, INPUT_COUNT, OUTPUT_COUNT} {} + + bool is_s_taper() const { + return param(SHAPE_SWITCH) > 0.5f; + } + + void step() override { + outputs[SWAVE_OUT].value = to_signal(taper(to_phase(swave_in()))); + } + + float swave_in() const { return input(SWAVE_IN); } + + float taper(float phase) const { + auto rotation = modulated(CURVE_KNOB, CURVE_CV); + return is_s_taper() ? Taper::s(phase, rotation) : Taper::j(phase, rotation); + } + + float to_signal(float phase) const { + return BIPOLAR_SIGNAL_RANGE.scale(phase); + } + + float to_phase(float signal) const { + return BIPOLAR_SIGNAL_RANGE.normalize(signal); + } + + enum ParameterIds { + CURVE_KNOB, + SHAPE_SWITCH, + PARAMETER_COUNT + }; + enum InputIds { + CURVE_CV, + SWAVE_IN, + INPUT_COUNT + }; + enum OutputIds { + SWAVE_OUT, + OUTPUT_COUNT + }; +}; + +} diff --git a/plugins/community/repos/DHE-Modules/src/modules/upstage-module.h b/plugins/community/repos/DHE-Modules/src/modules/upstage-module.h new file mode 100644 index 00000000..f752c007 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/modules/upstage-module.h @@ -0,0 +1,57 @@ +#pragma once + +#include + +#include "module.h" +#include "util/controls.h" +#include "util/range.h" + +namespace rack_plugin_DHE_Modules { + +struct UpstageModule : Module { + UpstageModule() : Module{PARAMETER_COUNT, INPUT_COUNT, OUTPUT_COUNT} {} + + float envelope_out() const { + const auto &range = Level::range(params[LEVEL_SWITCH].value); + auto rotation = modulated(LEVEL_KNOB, LEVEL_CV); + return Level::scaled(rotation, range); + } + + bool is_waiting() const { + return std::max(inputs[WAIT_IN].value, gate_button(WAIT_BUTTON)) > 0.5f; + } + + void step() override { + outputs[TRIG_OUT].value = trigger_out(); + outputs[ENVELOPE_OUT].value = envelope_out(); + } + + float trigger_in() const { + return param(TRIG_BUTTON) > 0.5f ? 10.f : input(TRIG_IN); + } + + float trigger_out() const { + return is_waiting() ? 0.f : trigger_in(); + } + + enum ParameterIds { + LEVEL_KNOB, + TRIG_BUTTON, + WAIT_BUTTON, + LEVEL_SWITCH, + PARAMETER_COUNT + }; + enum InputIds { + TRIG_IN, + WAIT_IN, + LEVEL_CV, + INPUT_COUNT + }; + enum OutputIds { + TRIG_OUT, + ENVELOPE_OUT, + OUTPUT_COUNT + }; +}; + +} diff --git a/plugins/community/repos/DHE-Modules/src/plugin/dhe-modules.cpp b/plugins/community/repos/DHE-Modules/src/plugin/dhe-modules.cpp new file mode 100644 index 00000000..1baf416b --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/plugin/dhe-modules.cpp @@ -0,0 +1,21 @@ +#include "dhe-modules.h" + +RACK_PLUGIN_MODEL_DECLARE(DHE_Modules, BoosterStage); +RACK_PLUGIN_MODEL_DECLARE(DHE_Modules, Cubic); +RACK_PLUGIN_MODEL_DECLARE(DHE_Modules, Hostage); +RACK_PLUGIN_MODEL_DECLARE(DHE_Modules, Stage); +RACK_PLUGIN_MODEL_DECLARE(DHE_Modules, Swave); +RACK_PLUGIN_MODEL_DECLARE(DHE_Modules, Upstage); + +RACK_PLUGIN_INIT(DHE_Modules) { + RACK_PLUGIN_INIT_ID(); + + RACK_PLUGIN_INIT_WEBSITE("https://dhemery.github.io/DHE-Modules/"); + + RACK_PLUGIN_MODEL_ADD(DHE_Modules, BoosterStage); + RACK_PLUGIN_MODEL_ADD(DHE_Modules, Cubic); + RACK_PLUGIN_MODEL_ADD(DHE_Modules, Hostage); + RACK_PLUGIN_MODEL_ADD(DHE_Modules, Stage); + RACK_PLUGIN_MODEL_ADD(DHE_Modules, Swave); + RACK_PLUGIN_MODEL_ADD(DHE_Modules, Upstage); +} diff --git a/plugins/community/repos/DHE-Modules/src/plugin/dhe-modules.h b/plugins/community/repos/DHE-Modules/src/plugin/dhe-modules.h new file mode 100644 index 00000000..49cc7eaa --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/plugin/dhe-modules.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +using namespace rack; + +RACK_PLUGIN_DECLARE(DHE_Modules); + +#ifdef USE_VST2 +#define plugin "DHE-Modules" +#endif // USE_VST2 + +namespace rack_plugin_DHE_Modules { +template +static rack::Model *createModel(std::string moduleSlug, TTag... tags) { + return rack::Model::create("DHE-Modules", moduleSlug, moduleSlug, tags...); +} +} diff --git a/plugins/community/repos/DHE-Modules/src/util/controls.h b/plugins/community/repos/DHE-Modules/src/util/controls.h new file mode 100644 index 00000000..30517df7 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/util/controls.h @@ -0,0 +1,79 @@ +#pragma once + +#include "range.h" +#include "sigmoid.h" + +namespace rack_plugin_DHE_Modules { + +namespace Duration { +constexpr auto RANGE_MAX_TO_MIN_RATIO = 1000.f; +constexpr auto MEDIUM_RANGE_MAX = 10.0f; +constexpr auto MEDIUM_RANGE_MIN = MEDIUM_RANGE_MAX/RANGE_MAX_TO_MIN_RATIO; + +constexpr auto SCALE_STEP = 10.f; +constexpr auto SHORT_RANGE = Range{MEDIUM_RANGE_MIN/SCALE_STEP, MEDIUM_RANGE_MAX/SCALE_STEP}; +constexpr auto MEDIUM_RANGE = Range{MEDIUM_RANGE_MIN, MEDIUM_RANGE_MAX}; +constexpr auto LONG_RANGE = Range{MEDIUM_RANGE_MIN*SCALE_STEP, MEDIUM_RANGE_MAX*SCALE_STEP}; + +inline const Range &range(float switch_value) { + return switch_value < 0.5f ? SHORT_RANGE : + switch_value < 1.5f ? MEDIUM_RANGE : LONG_RANGE; +} + +inline float scaled(float rotation, const Range &range) { + // Shapes the J taper to yield ~0.1 given a rotation of 0.5. So if the + // rotation is at dead center, the return value will be ~1/10 of the range's + // maximum. + constexpr auto KNOB_CURVATURE = 0.8f; + + // Assuming a rotation value in the range [0,1], sigmoid() yields a J taper + // in the range [0,1] + auto j_tapered_rotation = sigmoid(rotation, KNOB_CURVATURE); + + // Scale the tapered rotation to the desired range. + return range.scale(j_tapered_rotation); +} +} + +namespace Level { + +inline const Range &range(float switch_value) { + return switch_value > 0.5f ? UNIPOLAR_SIGNAL_RANGE : BIPOLAR_SIGNAL_RANGE; +} + +inline float scaled(float rotation, const Range &range = UNIPOLAR_SIGNAL_RANGE) { + return range.scale(rotation); +} +} + +namespace Taper { + +inline float curvature(float rotation) { + // Scale the rotation to [-1,1] to use the entire range of the sigmoid curve. + auto bipolar_rotation = BIPOLAR_PHASE_RANGE.scale(rotation); + + // This knob curvature gives an S taper that gently increases sensitivity in + // the middle of the rotation and decreases sensitivity toward the ends. + constexpr auto KNOB_CURVATURE = -0.65f; + + // Apply the S taper to the bipolar rotation. + return sigmoid(bipolar_rotation, KNOB_CURVATURE); +} + +inline float j(float phase, float rotation) { + return sigmoid(phase, curvature(rotation)); +} + +inline float s(float phase, float rotation) { + // Scale the phase to [-1,1] to use the entire range of the sigmoid curve. + auto bipolar_phase = BIPOLAR_PHASE_RANGE.scale(phase); + + // Invert the curvature so that rotation greater than 0.5 gives an S taper. + auto s_tapered_bipolar_phase = sigmoid(bipolar_phase, -curvature(rotation)); + + // Scale the tapered phase back to the range [0,1]. + return BIPOLAR_PHASE_RANGE.normalize(s_tapered_bipolar_phase); +} + +} +} diff --git a/plugins/community/repos/DHE-Modules/src/util/d-flip-flop.h b/plugins/community/repos/DHE-Modules/src/util/d-flip-flop.h new file mode 100644 index 00000000..2cbe9c2c --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/util/d-flip-flop.h @@ -0,0 +1,55 @@ +#pragma once + +#include +#include +#include +#include + +#include "latch.h" + +namespace rack_plugin_DHE_Modules { + +/** + * A flip-flop is a latch determines its own state by comparing a signal to the + * specified thresholds. + */ +struct DFlipFlop : public Latch { + /** + * Creates a flip-flop that compares the signal to the given thresholds. + * + * @param signal supplies the signal to evaluate + * @param low_threshold signal value at or below which the flip-flop state is LOW + * @param high_threshold signal value at or above which the flip-flop state is HIGH + */ + DFlipFlop(std::function signal, float low_threshold, float high_threshold) + : signal{std::move(signal)}, + low_threshold{low_threshold}, + high_threshold{high_threshold} {} + + /** + * Creates a flip-flop that compares the signal to a low threshold + * of 0.1 and a high threshold of 0.9. + * + * @param signal supplies the signal to evaluate + */ + explicit DFlipFlop(std::function signal) + : signal{std::move(signal)} {} + + /** + * Sets the state by comparing the signal to the thresholds. + * - Fires 'rise' if the state changes to HIGH. + * - Fires 'fall' if the state changes to LOW. + */ + void step() { + if (signal() >= high_threshold) + set_state(State::HIGH); + else if (signal() <= low_threshold) + set_state(State::LOW); + } + +private: + const std::function signal; + const float low_threshold = {0.1f}; + const float high_threshold = {0.9f}; +}; +} diff --git a/plugins/community/repos/DHE-Modules/src/util/d-latch.h b/plugins/community/repos/DHE-Modules/src/util/d-latch.h new file mode 100644 index 00000000..58b479be --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/util/d-latch.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +#include "latch.h" + +namespace rack_plugin_DHE_Modules { + +/** + * A latch that can be set and reset. + */ +struct DLatch : Latch { + /** + * Sets the latch HIGH. Fires 'rise' if the latch was not already HIGH. + */ + void set() { set_state(State::HIGH); } + + /** + * Sets the latch LOW. Fires 'fall' if the latch was not already LOW. + */ + void reset() { set_state(State::LOW); } +}; +} diff --git a/plugins/community/repos/DHE-Modules/src/util/latch.h b/plugins/community/repos/DHE-Modules/src/util/latch.h new file mode 100644 index 00000000..4173b4b9 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/util/latch.h @@ -0,0 +1,66 @@ +#pragma once + +#include +#include + +namespace rack_plugin_DHE_Modules { + +class Latch { + +public: + bool is_high() const { return state==State::HIGH; } + + /** + * Suspends firing events. + */ + void disable() { + enabled = false; + } + + /** + * Resumes firing events. + */ + void enable() { + enabled = true; + } + + /** + * Registers an action to be called on each rising edge. + * @param action called on each rising edge + */ + void on_rise(std::function action) { + rise_actions.push_back(std::move(action)); + } + + /** + * Registers an action to be called on each falling edge. + * @param action called on each falling edge + */ + void on_fall(std::function action) { + fall_actions.push_back(std::move(action)); + } + +protected: + enum class State { + UNKNOWN, LOW, HIGH + } state = State::UNKNOWN; + + void set_state(State incoming_state) { + if (state==incoming_state) return; + state = incoming_state; + fire(state==State::HIGH ? rise_actions : fall_actions); + } + +private: + bool enabled = true; + std::vector> rise_actions; + std::vector> fall_actions; + + void fire(const std::vector> &actions) const { + if (!enabled) + return; + for (const auto &action : actions) + action(); + } +}; +} diff --git a/plugins/community/repos/DHE-Modules/src/util/mode.h b/plugins/community/repos/DHE-Modules/src/util/mode.h new file mode 100644 index 00000000..82d081d7 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/util/mode.h @@ -0,0 +1,67 @@ +#pragma once + +#include +#include +#include "util/d-flip-flop.h" + +namespace rack_plugin_DHE_Modules { +struct Mode { + void enter() { fire(entry_actions); } + void exit() { fire(exit_actions); } + void step() { fire(step_actions); } + + void on_entry(std::function action) { + entry_actions.push_back(std::move(action)); + } + + void on_exit(std::function action) { + exit_actions.push_back(std::move(action)); + } + + void on_step(std::function action) { + step_actions.push_back(std::move(action)); + } + +private: + void fire(const std::vector> &actions) { + for (const auto &action : actions) action(); + } + + std::vector> entry_actions; + std::vector> exit_actions; + std::vector> step_actions; +}; + +class SubmodeSwitch : public Mode { + DFlipFlop submode_switch; + Mode *submode; + + void enter_submode(Mode *incoming_submode) { + submode->exit(); + submode = incoming_submode; + submode->enter(); + } + +public: + SubmodeSwitch(std::function switch_signal, Mode *low_mode, Mode *high_mode) : + submode_switch{std::move(switch_signal)}, submode{low_mode} { + submode_switch.on_rise([this, high_mode] { + enter_submode(high_mode); + }); + submode_switch.on_fall([this, low_mode] { + enter_submode(low_mode); + }); + + on_entry([this] { + submode->enter(); + }); + on_step([this] { + submode_switch.step(); + submode->step(); + }); + on_exit([this] { + submode->exit(); + }); + } +}; +} diff --git a/plugins/community/repos/DHE-Modules/src/util/ramp.h b/plugins/community/repos/DHE-Modules/src/util/ramp.h new file mode 100644 index 00000000..d8bbfc3d --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/util/ramp.h @@ -0,0 +1,116 @@ +#pragma once + +#include +#include + +#include "d-latch.h" +#include "sigmoid.h" + +namespace rack_plugin_DHE_Modules { + +/** + * A ramp that advances its phase from 0 to 1 in increments supplied by a given + * supplier. + * + * When the phase advances to 1, the ramp fires 'completion' and stops + * advancing. + */ +class Ramp { +public: + /*! + * Constructs a ramp that advances its phase on each step by the amount + * supplied by the given supplier. + * + * The newly constructed ramp is at phase 0 and inactive. + * + * @param phase_increment_supplier supplies the amount to advance the phase on + * each step + */ + explicit Ramp(std::function phase_increment_supplier) + : phase_increment{std::move(phase_increment_supplier)} { + stop(); + } + + /** + * Sets the phase to 0, actives the ramp, and fires 'start'. Subsequent steps + * will advance the phase. + */ + void start() { + progress = 0.0; + active.enable(); + active.set(); + } + + /*! + * Sets the phase to 0 and deactives the ramp. Subsequent steps will not + * advance the phase. + * + * Stopping the ramp does not fire any events. + */ + void stop() { + progress = 0.0; + active.disable(); + active.reset(); + } + + /** + * Advances the phase by the amount supplied by the phase increment supplier. + * + * If the phase advances to 1, the ramp fires 'completion' and becomes + * inactive. + * + * If the ramp is inactive, this function has no effect. + */ + void step() { + if (!is_active()) + return; + + progress = UNIPOLAR_PHASE_RANGE.clamp(progress + phase_increment()); + + if (progress >= 1.0f) { + active.reset(); + }; + } + + /** + * Indicates whether the ramp is active. + * + * @return whether the ramp is active + */ + bool is_active() const { return active.is_high(); } + + /** + * Returns the ramp's phase. + * + * If the ramp is active, the phase indicates the ramp's progress + * from 0 to 1. + * + * If the ramp is inactive, the phase is 1 (if the ramp became inactive by + * completing its advancement) or 0 (if the ramp was stopped). + * + * @return the ramp's phase + */ + float phase() const { return progress; } + + /** + * Registers an action to be called when the ramp starts. + * @param action called when the ramp starts + */ + void on_start(std::function action) { + active.on_rise(std::move(action)); + } + + /** + * Registers an action to be called when the ramp's phase advances to 1. + * @param action called when the ramp's phase advances to 1 + */ + void on_completion(std::function action) { + active.on_fall(std::move(action)); + } + +private: + float progress = 0.0f; + DLatch active{}; + const std::function phase_increment; +}; +} diff --git a/plugins/community/repos/DHE-Modules/src/util/range.h b/plugins/community/repos/DHE-Modules/src/util/range.h new file mode 100644 index 00000000..9f7b406a --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/util/range.h @@ -0,0 +1,41 @@ +#pragma once + +namespace rack_plugin_DHE_Modules { + +inline float scale(float proportion, float lower_bound, float upper_bound) { + return proportion*(upper_bound - lower_bound) + lower_bound; +} + +struct Range { + const float lower_bound; + + const float upper_bound; + + constexpr Range(float lower_bound, float upper_bound) noexcept : lower_bound(lower_bound), upper_bound(upper_bound) {} + + float scale(float proportion) const { + return rack_plugin_DHE_Modules::scale(proportion, lower_bound, upper_bound); + } + + float scale(bool state) const { + return state ? upper_bound : lower_bound; + } + + float normalize(float member) const { + return (member - lower_bound)/(upper_bound - lower_bound); + } + + float clamp(float f) const { + if (f < lower_bound) + return lower_bound; + if (f > upper_bound) + return upper_bound; + return f; + } +}; + +constexpr auto UNIPOLAR_PHASE_RANGE = Range{0.0f, 1.0f}; +constexpr auto BIPOLAR_PHASE_RANGE = Range{-1.0f, 1.0f}; +constexpr auto UNIPOLAR_SIGNAL_RANGE = Range{0.0f, 10.0f}; +constexpr auto BIPOLAR_SIGNAL_RANGE = Range{-5.0f, 5.0f}; +} diff --git a/plugins/community/repos/DHE-Modules/src/util/sigmoid.h b/plugins/community/repos/DHE-Modules/src/util/sigmoid.h new file mode 100644 index 00000000..4e4814d6 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/src/util/sigmoid.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +#include "range.h" + +namespace rack_plugin_DHE_Modules { + +inline float sigmoid(float x, float curvature) { + static constexpr auto precision = 1e-4f; + static constexpr auto max_curvature = 1.0f - precision; + static const auto curvature_range = Range{-max_curvature, max_curvature}; + + curvature = curvature_range.clamp(curvature); + x = BIPOLAR_PHASE_RANGE.clamp(x); + + return (x - x*curvature)/(curvature - std::abs(x)*2.0f*curvature + 1.0f); +} +} diff --git a/plugins/community/repos/DHE-Modules/test/booster-stage-tests.cpp b/plugins/community/repos/DHE-Modules/test/booster-stage-tests.cpp new file mode 100644 index 00000000..1b3bb54d --- /dev/null +++ b/plugins/community/repos/DHE-Modules/test/booster-stage-tests.cpp @@ -0,0 +1,6 @@ +#include +#include "catch/catch.hpp" + +TEST_CASE("Booster Stage Module") { + DHE::BoosterStageModule module{}; +} \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/test/catch/catch.hpp b/plugins/community/repos/DHE-Modules/test/catch/catch.hpp new file mode 100644 index 00000000..160bad07 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/test/catch/catch.hpp @@ -0,0 +1,12749 @@ +/* + * Catch v2.1.1 + * Generated: 2018-01-26 16:04:07.190063 + * ---------------------------------------------------------- + * This file has been merged from multiple headers. Please don't edit it directly + * Copyright (c) 2018 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +// start catch.hpp + + +#ifdef __clang__ +# pragma clang system_header +#elif defined __GNUC__ +# pragma GCC system_header +#endif + +// start catch_suppress_warnings.h + +#ifdef __clang__ +# ifdef __ICC // icpc defines the __clang__ macro +# pragma warning(push) +# pragma warning(disable: 161 1682) +# else // __ICC +# pragma clang diagnostic ignored "-Wunused-variable" +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wpadded" +# pragma clang diagnostic ignored "-Wswitch-enum" +# pragma clang diagnostic ignored "-Wcovered-switch-default" +# endif +#elif defined __GNUC__ +# pragma GCC diagnostic ignored "-Wunused-variable" +# pragma GCC diagnostic ignored "-Wparentheses" +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpadded" +#endif +// end catch_suppress_warnings.h +#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) +# define CATCH_IMPL +# define CATCH_CONFIG_ALL_PARTS +#endif + +// In the impl file, we want to have access to all parts of the headers +// Can also be used to sanely support PCHs +#if defined(CATCH_CONFIG_ALL_PARTS) +# define CATCH_CONFIG_EXTERNAL_INTERFACES +# if defined(CATCH_CONFIG_DISABLE_MATCHERS) +# undef CATCH_CONFIG_DISABLE_MATCHERS +# endif +# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER +#endif + +#if !defined(CATCH_CONFIG_IMPL_ONLY) +// start catch_platform.h + +#ifdef __APPLE__ +# include +# if TARGET_OS_OSX == 1 +# define CATCH_PLATFORM_MAC +# elif TARGET_OS_IPHONE == 1 +# define CATCH_PLATFORM_IPHONE +# endif + +#elif defined(linux) || defined(__linux) || defined(__linux__) +# define CATCH_PLATFORM_LINUX + +#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) +# define CATCH_PLATFORM_WINDOWS +#endif + +// end catch_platform.h + +#ifdef CATCH_IMPL +# ifndef CLARA_CONFIG_MAIN +# define CLARA_CONFIG_MAIN_NOT_DEFINED +# define CLARA_CONFIG_MAIN +# endif +#endif + +// start catch_user_interfaces.h + +namespace Catch { + unsigned int rngSeed(); +} + +// end catch_user_interfaces.h +// start catch_tag_alias_autoregistrar.h + +// start catch_common.h + +// start catch_compiler_capabilities.h + +// Detect a number of compiler features - by compiler +// The following features are defined: +// +// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? +// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? +// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? +// **************** +// Note to maintainers: if new toggles are added please document them +// in configuration.md, too +// **************** + +// In general each macro has a _NO_ form +// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature. +// Many features, at point of detection, define an _INTERNAL_ macro, so they +// can be combined, en-mass, with the _NO_ forms later. + +#ifdef __cplusplus + +# if __cplusplus >= 201402L +# define CATCH_CPP14_OR_GREATER +# endif + +#endif + +#ifdef __clang__ + +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + _Pragma( "clang diagnostic push" ) \ + _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ + _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") +# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ + _Pragma( "clang diagnostic pop" ) + +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + _Pragma( "clang diagnostic push" ) \ + _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) +# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ + _Pragma( "clang diagnostic pop" ) + +#endif // __clang__ + +//////////////////////////////////////////////////////////////////////////////// +// We know some environments not to support full POSIX signals +#if defined(__CYGWIN__) || defined(__QNX__) + +# if !defined(CATCH_CONFIG_POSIX_SIGNALS) +# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +# endif + +#endif + +#ifdef __OS400__ +# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +# define CATCH_CONFIG_COLOUR_NONE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Cygwin +#ifdef __CYGWIN__ + +// Required for some versions of Cygwin to declare gettimeofday +// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin +# define _BSD_SOURCE + +#endif // __CYGWIN__ + +//////////////////////////////////////////////////////////////////////////////// +// Visual C++ +#ifdef _MSC_VER + +// Universal Windows platform does not support SEH +// Or console colours (or console at all...) +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) +# define CATCH_CONFIG_COLOUR_NONE +# else +# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH +# endif + +#endif // _MSC_VER + +//////////////////////////////////////////////////////////////////////////////// + +// Use of __COUNTER__ is suppressed during code analysis in +// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly +// handled by it. +// Otherwise all supported compilers support COUNTER macro, +// but user still might want to turn it off +#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) + #define CATCH_INTERNAL_CONFIG_COUNTER +#endif + +#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) +# define CATCH_CONFIG_COUNTER +#endif +#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) +# define CATCH_CONFIG_WINDOWS_SEH +#endif +// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. +#if !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) +# define CATCH_CONFIG_POSIX_SIGNALS +#endif + +#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS +# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS +# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS +#endif + +// end catch_compiler_capabilities.h +#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line +#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) +#ifdef CATCH_CONFIG_COUNTER +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) +#else +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) +#endif + +#include +#include +#include + +namespace Catch { + + struct CaseSensitive { enum Choice { + Yes, + No + }; }; + + class NonCopyable { + NonCopyable( NonCopyable const& ) = delete; + NonCopyable( NonCopyable && ) = delete; + NonCopyable& operator = ( NonCopyable const& ) = delete; + NonCopyable& operator = ( NonCopyable && ) = delete; + + protected: + NonCopyable(); + virtual ~NonCopyable(); + }; + + struct SourceLineInfo { + + SourceLineInfo() = delete; + SourceLineInfo( char const* _file, std::size_t _line ) noexcept + : file( _file ), + line( _line ) + {} + + SourceLineInfo( SourceLineInfo const& other ) = default; + SourceLineInfo( SourceLineInfo && ) = default; + SourceLineInfo& operator = ( SourceLineInfo const& ) = default; + SourceLineInfo& operator = ( SourceLineInfo && ) = default; + + bool empty() const noexcept; + bool operator == ( SourceLineInfo const& other ) const noexcept; + bool operator < ( SourceLineInfo const& other ) const noexcept; + + char const* file; + std::size_t line; + }; + + std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); + + // Use this in variadic streaming macros to allow + // >> +StreamEndStop + // as well as + // >> stuff +StreamEndStop + struct StreamEndStop { + std::string operator+() const; + }; + template + T const& operator + ( T const& value, StreamEndStop ) { + return value; + } +} + +#define CATCH_INTERNAL_LINEINFO \ + ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) + +// end catch_common.h +namespace Catch { + + struct RegistrarForTagAliases { + RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); + }; + +} // end namespace Catch + +#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS + +// end catch_tag_alias_autoregistrar.h +// start catch_test_registry.h + +// start catch_interfaces_testcase.h + +#include +#include + +namespace Catch { + + class TestSpec; + + struct ITestInvoker { + virtual void invoke () const = 0; + virtual ~ITestInvoker(); + }; + + using ITestCasePtr = std::shared_ptr; + + class TestCase; + struct IConfig; + + struct ITestCaseRegistry { + virtual ~ITestCaseRegistry(); + virtual std::vector const& getAllTests() const = 0; + virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; + }; + + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); + std::vector const& getAllTestCasesSorted( IConfig const& config ); + +} + +// end catch_interfaces_testcase.h +// start catch_stringref.h + +#include +#include +#include + +namespace Catch { + + class StringData; + + /// A non-owning string class (similar to the forthcoming std::string_view) + /// Note that, because a StringRef may be a substring of another string, + /// it may not be null terminated. c_str() must return a null terminated + /// string, however, and so the StringRef will internally take ownership + /// (taking a copy), if necessary. In theory this ownership is not externally + /// visible - but it does mean (substring) StringRefs should not be shared between + /// threads. + class StringRef { + public: + using size_type = std::size_t; + + private: + friend struct StringRefTestAccess; + + char const* m_start; + size_type m_size; + + char* m_data = nullptr; + + void takeOwnership(); + + static constexpr char const* const s_empty = ""; + + public: // construction/ assignment + StringRef() noexcept + : StringRef( s_empty, 0 ) + {} + + StringRef( StringRef const& other ) noexcept + : m_start( other.m_start ), + m_size( other.m_size ) + {} + + StringRef( StringRef&& other ) noexcept + : m_start( other.m_start ), + m_size( other.m_size ), + m_data( other.m_data ) + { + other.m_data = nullptr; + } + + StringRef( char const* rawChars ) noexcept; + + StringRef( char const* rawChars, size_type size ) noexcept + : m_start( rawChars ), + m_size( size ) + {} + + StringRef( std::string const& stdString ) noexcept + : m_start( stdString.c_str() ), + m_size( stdString.size() ) + {} + + ~StringRef() noexcept { + delete[] m_data; + } + + auto operator = ( StringRef const &other ) noexcept -> StringRef& { + delete[] m_data; + m_data = nullptr; + m_start = other.m_start; + m_size = other.m_size; + return *this; + } + + operator std::string() const; + + void swap( StringRef& other ) noexcept; + + public: // operators + auto operator == ( StringRef const& other ) const noexcept -> bool; + auto operator != ( StringRef const& other ) const noexcept -> bool; + + auto operator[] ( size_type index ) const noexcept -> char; + + public: // named queries + auto empty() const noexcept -> bool { + return m_size == 0; + } + auto size() const noexcept -> size_type { + return m_size; + } + + auto numberOfCharacters() const noexcept -> size_type; + auto c_str() const -> char const*; + + public: // substrings and searches + auto substr( size_type start, size_type size ) const noexcept -> StringRef; + + private: // ownership queries - may not be consistent between calls + auto isOwned() const noexcept -> bool; + auto isSubstring() const noexcept -> bool; + auto data() const noexcept -> char const*; + }; + + auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> std::string; + auto operator + ( StringRef const& lhs, char const* rhs ) -> std::string; + auto operator + ( char const* lhs, StringRef const& rhs ) -> std::string; + + auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; + + inline auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { + return StringRef( rawChars, size ); + } + +} // namespace Catch + +// end catch_stringref.h +namespace Catch { + +template +class TestInvokerAsMethod : public ITestInvoker { + void (C::*m_testAsMethod)(); +public: + TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {} + + void invoke() const override { + C obj; + (obj.*m_testAsMethod)(); + } +}; + +auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker*; + +template +auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* { + return new(std::nothrow) TestInvokerAsMethod( testAsMethod ); +} + +struct NameAndTags { + NameAndTags( StringRef name_ = StringRef(), StringRef tags_ = StringRef() ) noexcept; + StringRef name; + StringRef tags; +}; + +struct AutoReg : NonCopyable { + AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept; + ~AutoReg(); +}; + +} // end namespace Catch + +#if defined(CATCH_CONFIG_DISABLE) + #define INTERNAL_CATCH_TESTCASE_NO_REGISTRATION( TestName, ... ) \ + static void TestName() + #define INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION( TestName, ClassName, ... ) \ + namespace{ \ + struct TestName : ClassName { \ + void test(); \ + }; \ + } \ + void TestName::test() + +#endif + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \ + static void TestName(); \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ + static void TestName() + #define INTERNAL_CATCH_TESTCASE( ... ) \ + INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ ) + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ \ + struct TestName : ClassName{ \ + void test(); \ + }; \ + Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \ + } \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ + void TestName::test() + #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \ + INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ ) + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS + +// end catch_test_registry.h +// start catch_capture.hpp + +// start catch_assertionhandler.h + +// start catch_assertioninfo.h + +// start catch_result_type.h + +namespace Catch { + + // ResultWas::OfType enum + struct ResultWas { enum OfType { + Unknown = -1, + Ok = 0, + Info = 1, + Warning = 2, + + FailureBit = 0x10, + + ExpressionFailed = FailureBit | 1, + ExplicitFailure = FailureBit | 2, + + Exception = 0x100 | FailureBit, + + ThrewException = Exception | 1, + DidntThrowException = Exception | 2, + + FatalErrorCondition = 0x200 | FailureBit + + }; }; + + bool isOk( ResultWas::OfType resultType ); + bool isJustInfo( int flags ); + + // ResultDisposition::Flags enum + struct ResultDisposition { enum Flags { + Normal = 0x01, + + ContinueOnFailure = 0x02, // Failures fail test, but execution continues + FalseTest = 0x04, // Prefix expression with ! + SuppressFail = 0x08 // Failures are reported but do not fail the test + }; }; + + ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ); + + bool shouldContinueOnFailure( int flags ); + inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; } + bool shouldSuppressFailure( int flags ); + +} // end namespace Catch + +// end catch_result_type.h +namespace Catch { + + struct AssertionInfo + { + StringRef macroName; + SourceLineInfo lineInfo; + StringRef capturedExpression; + ResultDisposition::Flags resultDisposition; + + // We want to delete this constructor but a compiler bug in 4.8 means + // the struct is then treated as non-aggregate + //AssertionInfo() = delete; + }; + +} // end namespace Catch + +// end catch_assertioninfo.h +// start catch_decomposer.h + +// start catch_tostring.h + +#include +#include +#include +#include +// start catch_stream.h + +#include +#include +#include + +namespace Catch { + + std::ostream& cout(); + std::ostream& cerr(); + std::ostream& clog(); + + class StringRef; + + struct IStream { + virtual ~IStream(); + virtual std::ostream& stream() const = 0; + }; + + auto makeStream( StringRef const &filename ) -> IStream const*; + + class ReusableStringStream { + std::size_t m_index; + std::ostream* m_oss; + public: + ReusableStringStream(); + ~ReusableStringStream(); + + auto str() const -> std::string; + + template + auto operator << ( T const& value ) -> ReusableStringStream& { + *m_oss << value; + return *this; + } + auto get() -> std::ostream& { return *m_oss; } + + static void cleanup(); + }; +} + +// end catch_stream.h + +#ifdef __OBJC__ +// start catch_objc_arc.hpp + +#import + +#ifdef __has_feature +#define CATCH_ARC_ENABLED __has_feature(objc_arc) +#else +#define CATCH_ARC_ENABLED 0 +#endif + +void arcSafeRelease( NSObject* obj ); +id performOptionalSelector( id obj, SEL sel ); + +#if !CATCH_ARC_ENABLED +inline void arcSafeRelease( NSObject* obj ) { + [obj release]; +} +inline id performOptionalSelector( id obj, SEL sel ) { + if( [obj respondsToSelector: sel] ) + return [obj performSelector: sel]; + return nil; +} +#define CATCH_UNSAFE_UNRETAINED +#define CATCH_ARC_STRONG +#else +inline void arcSafeRelease( NSObject* ){} +inline id performOptionalSelector( id obj, SEL sel ) { +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" +#endif + if( [obj respondsToSelector: sel] ) + return [obj performSelector: sel]; +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + return nil; +} +#define CATCH_UNSAFE_UNRETAINED __unsafe_unretained +#define CATCH_ARC_STRONG __strong +#endif + +// end catch_objc_arc.hpp +#endif + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4180) // We attempt to stream a function (address) by const&, which MSVC complains about but is harmless +#endif + +// We need a dummy global operator<< so we can bring it into Catch namespace later +struct Catch_global_namespace_dummy {}; +std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); + +namespace Catch { + // Bring in operator<< from global namespace into Catch namespace + using ::operator<<; + + namespace Detail { + + extern const std::string unprintableString; + + std::string rawMemoryToString( const void *object, std::size_t size ); + + template + std::string rawMemoryToString( const T& object ) { + return rawMemoryToString( &object, sizeof(object) ); + } + + template + class IsStreamInsertable { + template + static auto test(int) + -> decltype(std::declval() << std::declval(), std::true_type()); + + template + static auto test(...)->std::false_type; + + public: + static const bool value = decltype(test(0))::value; + }; + + template + std::string convertUnknownEnumToString( E e ); + + template + typename std::enable_if::value, std::string>::type convertUnstreamable( T const& ) { + return Detail::unprintableString; + }; + template + typename std::enable_if::value, std::string>::type convertUnstreamable( T const& value ) { + return convertUnknownEnumToString( value ); + }; + + } // namespace Detail + + // If we decide for C++14, change these to enable_if_ts + template + struct StringMaker { + template + static + typename std::enable_if<::Catch::Detail::IsStreamInsertable::value, std::string>::type + convert(const Fake& value) { + ReusableStringStream rss; + rss << value; + return rss.str(); + } + + template + static + typename std::enable_if::value, std::string>::type + convert( const Fake& value ) { + return Detail::convertUnstreamable( value ); + } + }; + + namespace Detail { + + // This function dispatches all stringification requests inside of Catch. + // Should be preferably called fully qualified, like ::Catch::Detail::stringify + template + std::string stringify(const T& e) { + return ::Catch::StringMaker::type>::type>::convert(e); + } + + template + std::string convertUnknownEnumToString( E e ) { + return ::Catch::Detail::stringify(static_cast::type>(e)); + } + + } // namespace Detail + + // Some predefined specializations + + template<> + struct StringMaker { + static std::string convert(const std::string& str); + }; + template<> + struct StringMaker { + static std::string convert(const std::wstring& wstr); + }; + + template<> + struct StringMaker { + static std::string convert(char const * str); + }; + template<> + struct StringMaker { + static std::string convert(char * str); + }; + template<> + struct StringMaker { + static std::string convert(wchar_t const * str); + }; + template<> + struct StringMaker { + static std::string convert(wchar_t * str); + }; + + template + struct StringMaker { + static std::string convert(const char* str) { + return ::Catch::Detail::stringify(std::string{ str }); + } + }; + template + struct StringMaker { + static std::string convert(const char* str) { + return ::Catch::Detail::stringify(std::string{ str }); + } + }; + template + struct StringMaker { + static std::string convert(const char* str) { + return ::Catch::Detail::stringify(std::string{ str }); + } + }; + + template<> + struct StringMaker { + static std::string convert(int value); + }; + template<> + struct StringMaker { + static std::string convert(long value); + }; + template<> + struct StringMaker { + static std::string convert(long long value); + }; + template<> + struct StringMaker { + static std::string convert(unsigned int value); + }; + template<> + struct StringMaker { + static std::string convert(unsigned long value); + }; + template<> + struct StringMaker { + static std::string convert(unsigned long long value); + }; + + template<> + struct StringMaker { + static std::string convert(bool b); + }; + + template<> + struct StringMaker { + static std::string convert(char c); + }; + template<> + struct StringMaker { + static std::string convert(signed char c); + }; + template<> + struct StringMaker { + static std::string convert(unsigned char c); + }; + + template<> + struct StringMaker { + static std::string convert(std::nullptr_t); + }; + + template<> + struct StringMaker { + static std::string convert(float value); + }; + template<> + struct StringMaker { + static std::string convert(double value); + }; + + template + struct StringMaker { + template + static std::string convert(U* p) { + if (p) { + return ::Catch::Detail::rawMemoryToString(p); + } else { + return "nullptr"; + } + } + }; + + template + struct StringMaker { + static std::string convert(R C::* p) { + if (p) { + return ::Catch::Detail::rawMemoryToString(p); + } else { + return "nullptr"; + } + } + }; + + namespace Detail { + template + std::string rangeToString(InputIterator first, InputIterator last) { + ReusableStringStream rss; + rss << "{ "; + if (first != last) { + rss << ::Catch::Detail::stringify(*first); + for (++first; first != last; ++first) + rss << ", " << ::Catch::Detail::stringify(*first); + } + rss << " }"; + return rss.str(); + } + } + +#ifdef __OBJC__ + template<> + struct StringMaker { + static std::string convert(NSString * nsstring) { + if (!nsstring) + return "nil"; + return std::string("@") + [nsstring UTF8String]; + } + }; + template<> + struct StringMaker { + static std::string convert(NSObject* nsObject) { + return ::Catch::Detail::stringify([nsObject description]); + } + + }; + namespace Detail { + inline std::string stringify( NSString* nsstring ) { + return StringMaker::convert( nsstring ); + } + + } // namespace Detail +#endif // __OBJC__ + +} // namespace Catch + +////////////////////////////////////////////////////// +// Separate std-lib types stringification, so it can be selectively enabled +// This means that we do not bring in + +#if defined(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS) +# define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER +# define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER +# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER +#endif + +// Separate std::pair specialization +#if defined(CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER) +#include +namespace Catch { + template + struct StringMaker > { + static std::string convert(const std::pair& pair) { + ReusableStringStream rss; + rss << "{ " + << ::Catch::Detail::stringify(pair.first) + << ", " + << ::Catch::Detail::stringify(pair.second) + << " }"; + return rss.str(); + } + }; +} +#endif // CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER + +// Separate std::tuple specialization +#if defined(CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER) +#include +namespace Catch { + namespace Detail { + template< + typename Tuple, + std::size_t N = 0, + bool = (N < std::tuple_size::value) + > + struct TupleElementPrinter { + static void print(const Tuple& tuple, std::ostream& os) { + os << (N ? ", " : " ") + << ::Catch::Detail::stringify(std::get(tuple)); + TupleElementPrinter::print(tuple, os); + } + }; + + template< + typename Tuple, + std::size_t N + > + struct TupleElementPrinter { + static void print(const Tuple&, std::ostream&) {} + }; + + } + + template + struct StringMaker> { + static std::string convert(const std::tuple& tuple) { + ReusableStringStream rss; + rss << '{'; + Detail::TupleElementPrinter>::print(tuple, rss.get()); + rss << " }"; + return rss.str(); + } + }; +} +#endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER + +namespace Catch { + struct not_this_one {}; // Tag type for detecting which begin/ end are being selected + + // Import begin/ end from std here so they are considered alongside the fallback (...) overloads in this namespace + using std::begin; + using std::end; + + not_this_one begin( ... ); + not_this_one end( ... ); + + template + struct is_range { + static const bool value = + !std::is_same())), not_this_one>::value && + !std::is_same())), not_this_one>::value; + }; + + template + std::string rangeToString( Range const& range ) { + return ::Catch::Detail::rangeToString( begin( range ), end( range ) ); + } + + // Handle vector specially + template + std::string rangeToString( std::vector const& v ) { + ReusableStringStream rss; + rss << "{ "; + bool first = true; + for( bool b : v ) { + if( first ) + first = false; + else + rss << ", "; + rss << ::Catch::Detail::stringify( b ); + } + rss << " }"; + return rss.str(); + } + + template + struct StringMaker::value && !std::is_array::value>::type> { + static std::string convert( R const& range ) { + return rangeToString( range ); + } + }; + + template + struct StringMaker { + static std::string convert(T const(&arr)[SZ]) { + return rangeToString(arr); + } + }; + +} // namespace Catch + +// Separate std::chrono::duration specialization +#if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) +#include +#include +#include + +namespace Catch { + +template +struct ratio_string { + static std::string symbol(); +}; + +template +std::string ratio_string::symbol() { + Catch::ReusableStringStream rss; + rss << '[' << Ratio::num << '/' + << Ratio::den << ']'; + return rss.str(); +} +template <> +struct ratio_string { + static std::string symbol(); +}; +template <> +struct ratio_string { + static std::string symbol(); +}; +template <> +struct ratio_string { + static std::string symbol(); +}; +template <> +struct ratio_string { + static std::string symbol(); +}; +template <> +struct ratio_string { + static std::string symbol(); +}; +template <> +struct ratio_string { + static std::string symbol(); +}; + + //////////// + // std::chrono::duration specializations + template + struct StringMaker> { + static std::string convert(std::chrono::duration const& duration) { + ReusableStringStream rss; + rss << duration.count() << ' ' << ratio_string::symbol() << 's'; + return rss.str(); + } + }; + template + struct StringMaker>> { + static std::string convert(std::chrono::duration> const& duration) { + ReusableStringStream rss; + rss << duration.count() << " s"; + return rss.str(); + } + }; + template + struct StringMaker>> { + static std::string convert(std::chrono::duration> const& duration) { + ReusableStringStream rss; + rss << duration.count() << " m"; + return rss.str(); + } + }; + template + struct StringMaker>> { + static std::string convert(std::chrono::duration> const& duration) { + ReusableStringStream rss; + rss << duration.count() << " h"; + return rss.str(); + } + }; + + //////////// + // std::chrono::time_point specialization + // Generic time_point cannot be specialized, only std::chrono::time_point + template + struct StringMaker> { + static std::string convert(std::chrono::time_point const& time_point) { + return ::Catch::Detail::stringify(time_point.time_since_epoch()) + " since epoch"; + } + }; + // std::chrono::time_point specialization + template + struct StringMaker> { + static std::string convert(std::chrono::time_point const& time_point) { + auto converted = std::chrono::system_clock::to_time_t(time_point); + +#ifdef _MSC_VER + std::tm timeInfo = {}; + gmtime_s(&timeInfo, &converted); +#else + std::tm* timeInfo = std::gmtime(&converted); +#endif + + auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); + char timeStamp[timeStampSize]; + const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; + +#ifdef _MSC_VER + std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); +#else + std::strftime(timeStamp, timeStampSize, fmt, timeInfo); +#endif + return std::string(timeStamp); + } + }; +} +#endif // CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +// end catch_tostring.h +#include + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4389) // '==' : signed/unsigned mismatch +#pragma warning(disable:4018) // more "signed/unsigned mismatch" +#pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform) +#pragma warning(disable:4180) // qualifier applied to function type has no meaning +#endif + +namespace Catch { + + struct ITransientExpression { + auto isBinaryExpression() const -> bool { return m_isBinaryExpression; } + auto getResult() const -> bool { return m_result; } + virtual void streamReconstructedExpression( std::ostream &os ) const = 0; + + ITransientExpression( bool isBinaryExpression, bool result ) + : m_isBinaryExpression( isBinaryExpression ), + m_result( result ) + {} + + // We don't actually need a virtual destructor, but many static analysers + // complain if it's not here :-( + virtual ~ITransientExpression(); + + bool m_isBinaryExpression; + bool m_result; + + }; + + void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ); + + template + class BinaryExpr : public ITransientExpression { + LhsT m_lhs; + StringRef m_op; + RhsT m_rhs; + + void streamReconstructedExpression( std::ostream &os ) const override { + formatReconstructedExpression + ( os, Catch::Detail::stringify( m_lhs ), m_op, Catch::Detail::stringify( m_rhs ) ); + } + + public: + BinaryExpr( bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs ) + : ITransientExpression{ true, comparisonResult }, + m_lhs( lhs ), + m_op( op ), + m_rhs( rhs ) + {} + }; + + template + class UnaryExpr : public ITransientExpression { + LhsT m_lhs; + + void streamReconstructedExpression( std::ostream &os ) const override { + os << Catch::Detail::stringify( m_lhs ); + } + + public: + explicit UnaryExpr( LhsT lhs ) + : ITransientExpression{ false, lhs ? true : false }, + m_lhs( lhs ) + {} + }; + + // Specialised comparison functions to handle equality comparisons between ints and pointers (NULL deduces as an int) + template + auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return static_cast(lhs == rhs); }; + template + auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast( rhs ); } + template + auto compareEqual( T* const& lhs, long rhs ) -> bool { return lhs == reinterpret_cast( rhs ); } + template + auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) == rhs; } + template + auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) == rhs; } + + template + auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return static_cast(lhs != rhs); }; + template + auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast( rhs ); } + template + auto compareNotEqual( T* const& lhs, long rhs ) -> bool { return lhs != reinterpret_cast( rhs ); } + template + auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) != rhs; } + template + auto compareNotEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) != rhs; } + + template + class ExprLhs { + LhsT m_lhs; + public: + explicit ExprLhs( LhsT lhs ) : m_lhs( lhs ) {} + + template + auto operator == ( RhsT const& rhs ) -> BinaryExpr const { + return { compareEqual( m_lhs, rhs ), m_lhs, "==", rhs }; + } + auto operator == ( bool rhs ) -> BinaryExpr const { + return { m_lhs == rhs, m_lhs, "==", rhs }; + } + + template + auto operator != ( RhsT const& rhs ) -> BinaryExpr const { + return { compareNotEqual( m_lhs, rhs ), m_lhs, "!=", rhs }; + } + auto operator != ( bool rhs ) -> BinaryExpr const { + return { m_lhs != rhs, m_lhs, "!=", rhs }; + } + + template + auto operator > ( RhsT const& rhs ) -> BinaryExpr const { + return { static_cast(m_lhs > rhs), m_lhs, ">", rhs }; + } + template + auto operator < ( RhsT const& rhs ) -> BinaryExpr const { + return { static_cast(m_lhs < rhs), m_lhs, "<", rhs }; + } + template + auto operator >= ( RhsT const& rhs ) -> BinaryExpr const { + return { static_cast(m_lhs >= rhs), m_lhs, ">=", rhs }; + } + template + auto operator <= ( RhsT const& rhs ) -> BinaryExpr const { + return { static_cast(m_lhs <= rhs), m_lhs, "<=", rhs }; + } + + auto makeUnaryExpr() const -> UnaryExpr { + return UnaryExpr{ m_lhs }; + } + }; + + void handleExpression( ITransientExpression const& expr ); + + template + void handleExpression( ExprLhs const& expr ) { + handleExpression( expr.makeUnaryExpr() ); + } + + struct Decomposer { + template + auto operator <= ( T const& lhs ) -> ExprLhs { + return ExprLhs{ lhs }; + } + + auto operator <=( bool value ) -> ExprLhs { + return ExprLhs{ value }; + } + }; + +} // end namespace Catch + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +// end catch_decomposer.h +// start catch_interfaces_capture.h + +#include + +namespace Catch { + + class AssertionResult; + struct AssertionInfo; + struct SectionInfo; + struct SectionEndInfo; + struct MessageInfo; + struct Counts; + struct BenchmarkInfo; + struct BenchmarkStats; + struct AssertionReaction; + + struct ITransientExpression; + + struct IResultCapture { + + virtual ~IResultCapture(); + + virtual bool sectionStarted( SectionInfo const& sectionInfo, + Counts& assertions ) = 0; + virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0; + virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0; + + virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0; + virtual void benchmarkEnded( BenchmarkStats const& stats ) = 0; + + virtual void pushScopedMessage( MessageInfo const& message ) = 0; + virtual void popScopedMessage( MessageInfo const& message ) = 0; + + virtual void handleFatalErrorCondition( StringRef message ) = 0; + + virtual void handleExpr + ( AssertionInfo const& info, + ITransientExpression const& expr, + AssertionReaction& reaction ) = 0; + virtual void handleMessage + ( AssertionInfo const& info, + ResultWas::OfType resultType, + StringRef const& message, + AssertionReaction& reaction ) = 0; + virtual void handleUnexpectedExceptionNotThrown + ( AssertionInfo const& info, + AssertionReaction& reaction ) = 0; + virtual void handleUnexpectedInflightException + ( AssertionInfo const& info, + std::string const& message, + AssertionReaction& reaction ) = 0; + virtual void handleIncomplete + ( AssertionInfo const& info ) = 0; + virtual void handleNonExpr + ( AssertionInfo const &info, + ResultWas::OfType resultType, + AssertionReaction &reaction ) = 0; + + virtual bool lastAssertionPassed() = 0; + virtual void assertionPassed() = 0; + + // Deprecated, do not use: + virtual std::string getCurrentTestName() const = 0; + virtual const AssertionResult* getLastResult() const = 0; + virtual void exceptionEarlyReported() = 0; + }; + + IResultCapture& getResultCapture(); +} + +// end catch_interfaces_capture.h +namespace Catch { + + struct TestFailureException{}; + struct AssertionResultData; + struct IResultCapture; + class RunContext; + + class LazyExpression { + friend class AssertionHandler; + friend struct AssertionStats; + friend class RunContext; + + ITransientExpression const* m_transientExpression = nullptr; + bool m_isNegated; + public: + LazyExpression( bool isNegated ); + LazyExpression( LazyExpression const& other ); + LazyExpression& operator = ( LazyExpression const& ) = delete; + + explicit operator bool() const; + + friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&; + }; + + struct AssertionReaction { + bool shouldDebugBreak = false; + bool shouldThrow = false; + }; + + class AssertionHandler { + AssertionInfo m_assertionInfo; + AssertionReaction m_reaction; + bool m_completed = false; + IResultCapture& m_resultCapture; + + public: + AssertionHandler + ( StringRef macroName, + SourceLineInfo const& lineInfo, + StringRef capturedExpression, + ResultDisposition::Flags resultDisposition ); + ~AssertionHandler() { + if ( !m_completed ) { + m_resultCapture.handleIncomplete( m_assertionInfo ); + } + } + + template + void handleExpr( ExprLhs const& expr ) { + handleExpr( expr.makeUnaryExpr() ); + } + void handleExpr( ITransientExpression const& expr ); + + void handleMessage(ResultWas::OfType resultType, StringRef const& message); + + void handleExceptionThrownAsExpected(); + void handleUnexpectedExceptionNotThrown(); + void handleExceptionNotThrownAsExpected(); + void handleThrowingCallSkipped(); + void handleUnexpectedInflightException(); + + void complete(); + void setCompleted(); + + // query + auto allowThrows() const -> bool; + }; + + void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ); + +} // namespace Catch + +// end catch_assertionhandler.h +// start catch_message.h + +#include + +namespace Catch { + + struct MessageInfo { + MessageInfo( std::string const& _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ); + + std::string macroName; + std::string message; + SourceLineInfo lineInfo; + ResultWas::OfType type; + unsigned int sequence; + + bool operator == ( MessageInfo const& other ) const; + bool operator < ( MessageInfo const& other ) const; + private: + static unsigned int globalCount; + }; + + struct MessageStream { + + template + MessageStream& operator << ( T const& value ) { + m_stream << value; + return *this; + } + + ReusableStringStream m_stream; + }; + + struct MessageBuilder : MessageStream { + MessageBuilder( std::string const& macroName, + SourceLineInfo const& lineInfo, + ResultWas::OfType type ); + + template + MessageBuilder& operator << ( T const& value ) { + m_stream << value; + return *this; + } + + MessageInfo m_info; + }; + + class ScopedMessage { + public: + explicit ScopedMessage( MessageBuilder const& builder ); + ~ScopedMessage(); + + MessageInfo m_info; + }; + +} // end namespace Catch + +// end catch_message.h +#if !defined(CATCH_CONFIG_DISABLE) + +#if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION) + #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__ +#else + #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION" +#endif + +#if defined(CATCH_CONFIG_FAST_COMPILE) + +/////////////////////////////////////////////////////////////////////////////// +// Another way to speed-up compilation is to omit local try-catch for REQUIRE* +// macros. +#define INTERNAL_CATCH_TRY +#define INTERNAL_CATCH_CATCH( capturer ) + +#else // CATCH_CONFIG_FAST_COMPILE + +#define INTERNAL_CATCH_TRY try +#define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.handleUnexpectedInflightException(); } + +#endif + +#define INTERNAL_CATCH_REACT( handler ) handler.complete(); + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ + INTERNAL_CATCH_TRY { \ + CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ + CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ + } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( (void)0, false && static_cast( !!(__VA_ARGS__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look + // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&. + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \ + INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \ + if( Catch::getResultCapture().lastAssertionPassed() ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \ + INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \ + if( !Catch::getResultCapture().lastAssertionPassed() ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ + try { \ + static_cast(__VA_ARGS__); \ + catchAssertionHandler.handleExceptionNotThrownAsExpected(); \ + } \ + catch( ... ) { \ + catchAssertionHandler.handleUnexpectedInflightException(); \ + } \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \ + if( catchAssertionHandler.allowThrows() ) \ + try { \ + static_cast(__VA_ARGS__); \ + catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ + } \ + catch( ... ) { \ + catchAssertionHandler.handleExceptionThrownAsExpected(); \ + } \ + else \ + catchAssertionHandler.handleThrowingCallSkipped(); \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \ + if( catchAssertionHandler.allowThrows() ) \ + try { \ + static_cast(expr); \ + catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ + } \ + catch( exceptionType const& ) { \ + catchAssertionHandler.handleExceptionThrownAsExpected(); \ + } \ + catch( ... ) { \ + catchAssertionHandler.handleUnexpectedInflightException(); \ + } \ + else \ + catchAssertionHandler.handleThrowingCallSkipped(); \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ + catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_INFO( macroName, log ) \ + Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ); + +/////////////////////////////////////////////////////////////////////////////// +// Although this is matcher-based, it can be used with just a string +#define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ + if( catchAssertionHandler.allowThrows() ) \ + try { \ + static_cast(__VA_ARGS__); \ + catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ + } \ + catch( ... ) { \ + Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher ); \ + } \ + else \ + catchAssertionHandler.handleThrowingCallSkipped(); \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +#endif // CATCH_CONFIG_DISABLE + +// end catch_capture.hpp +// start catch_section.h + +// start catch_section_info.h + +// start catch_totals.h + +#include + +namespace Catch { + + struct Counts { + Counts operator - ( Counts const& other ) const; + Counts& operator += ( Counts const& other ); + + std::size_t total() const; + bool allPassed() const; + bool allOk() const; + + std::size_t passed = 0; + std::size_t failed = 0; + std::size_t failedButOk = 0; + }; + + struct Totals { + + Totals operator - ( Totals const& other ) const; + Totals& operator += ( Totals const& other ); + + Totals delta( Totals const& prevTotals ) const; + + Counts assertions; + Counts testCases; + }; +} + +// end catch_totals.h +#include + +namespace Catch { + + struct SectionInfo { + SectionInfo + ( SourceLineInfo const& _lineInfo, + std::string const& _name, + std::string const& _description = std::string() ); + + std::string name; + std::string description; + SourceLineInfo lineInfo; + }; + + struct SectionEndInfo { + SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds ); + + SectionInfo sectionInfo; + Counts prevAssertions; + double durationInSeconds; + }; + +} // end namespace Catch + +// end catch_section_info.h +// start catch_timer.h + +#include + +namespace Catch { + + auto getCurrentNanosecondsSinceEpoch() -> uint64_t; + auto getEstimatedClockResolution() -> uint64_t; + + class Timer { + uint64_t m_nanoseconds = 0; + public: + void start(); + auto getElapsedNanoseconds() const -> uint64_t; + auto getElapsedMicroseconds() const -> uint64_t; + auto getElapsedMilliseconds() const -> unsigned int; + auto getElapsedSeconds() const -> double; + }; + +} // namespace Catch + +// end catch_timer.h +#include + +namespace Catch { + + class Section : NonCopyable { + public: + Section( SectionInfo const& info ); + ~Section(); + + // This indicates whether the section should be executed or not + explicit operator bool() const; + + private: + SectionInfo m_info; + + std::string m_name; + Counts m_assertions; + bool m_sectionIncluded; + Timer m_timer; + }; + +} // end namespace Catch + + #define INTERNAL_CATCH_SECTION( ... ) \ + if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) + +// end catch_section.h +// start catch_benchmark.h + +#include +#include + +namespace Catch { + + class BenchmarkLooper { + + std::string m_name; + std::size_t m_count = 0; + std::size_t m_iterationsToRun = 1; + uint64_t m_resolution; + Timer m_timer; + + static auto getResolution() -> uint64_t; + public: + // Keep most of this inline as it's on the code path that is being timed + BenchmarkLooper( StringRef name ) + : m_name( name ), + m_resolution( getResolution() ) + { + reportStart(); + m_timer.start(); + } + + explicit operator bool() { + if( m_count < m_iterationsToRun ) + return true; + return needsMoreIterations(); + } + + void increment() { + ++m_count; + } + + void reportStart(); + auto needsMoreIterations() -> bool; + }; + +} // end namespace Catch + +#define BENCHMARK( name ) \ + for( Catch::BenchmarkLooper looper( name ); looper; looper.increment() ) + +// end catch_benchmark.h +// start catch_interfaces_exception.h + +// start catch_interfaces_registry_hub.h + +#include +#include + +namespace Catch { + + class TestCase; + struct ITestCaseRegistry; + struct IExceptionTranslatorRegistry; + struct IExceptionTranslator; + struct IReporterRegistry; + struct IReporterFactory; + struct ITagAliasRegistry; + class StartupExceptionRegistry; + + using IReporterFactoryPtr = std::shared_ptr; + + struct IRegistryHub { + virtual ~IRegistryHub(); + + virtual IReporterRegistry const& getReporterRegistry() const = 0; + virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0; + virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0; + + virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0; + + virtual StartupExceptionRegistry const& getStartupExceptionRegistry() const = 0; + }; + + struct IMutableRegistryHub { + virtual ~IMutableRegistryHub(); + virtual void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) = 0; + virtual void registerListener( IReporterFactoryPtr const& factory ) = 0; + virtual void registerTest( TestCase const& testInfo ) = 0; + virtual void registerTranslator( const IExceptionTranslator* translator ) = 0; + virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0; + virtual void registerStartupException() noexcept = 0; + }; + + IRegistryHub& getRegistryHub(); + IMutableRegistryHub& getMutableRegistryHub(); + void cleanUp(); + std::string translateActiveException(); + +} + +// end catch_interfaces_registry_hub.h +#if defined(CATCH_CONFIG_DISABLE) + #define INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( translatorName, signature) \ + static std::string translatorName( signature ) +#endif + +#include +#include +#include + +namespace Catch { + using exceptionTranslateFunction = std::string(*)(); + + struct IExceptionTranslator; + using ExceptionTranslators = std::vector>; + + struct IExceptionTranslator { + virtual ~IExceptionTranslator(); + virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0; + }; + + struct IExceptionTranslatorRegistry { + virtual ~IExceptionTranslatorRegistry(); + + virtual std::string translateActiveException() const = 0; + }; + + class ExceptionTranslatorRegistrar { + template + class ExceptionTranslator : public IExceptionTranslator { + public: + + ExceptionTranslator( std::string(*translateFunction)( T& ) ) + : m_translateFunction( translateFunction ) + {} + + std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override { + try { + if( it == itEnd ) + std::rethrow_exception(std::current_exception()); + else + return (*it)->translate( it+1, itEnd ); + } + catch( T& ex ) { + return m_translateFunction( ex ); + } + } + + protected: + std::string(*m_translateFunction)( T& ); + }; + + public: + template + ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) { + getMutableRegistryHub().registerTranslator + ( new ExceptionTranslator( translateFunction ) ); + } + }; +} + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \ + static std::string translatorName( signature ); \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ + static std::string translatorName( signature ) + +#define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) + +// end catch_interfaces_exception.h +// start catch_approx.h + +#include +#include + +namespace Catch { +namespace Detail { + + class Approx { + private: + bool equalityComparisonImpl(double other) const; + + public: + explicit Approx ( double value ); + + static Approx custom(); + + template ::value>::type> + Approx operator()( T const& value ) { + Approx approx( static_cast(value) ); + approx.epsilon( m_epsilon ); + approx.margin( m_margin ); + approx.scale( m_scale ); + return approx; + } + + template ::value>::type> + explicit Approx( T const& value ): Approx(static_cast(value)) + {} + + template ::value>::type> + friend bool operator == ( const T& lhs, Approx const& rhs ) { + auto lhs_v = static_cast(lhs); + return rhs.equalityComparisonImpl(lhs_v); + } + + template ::value>::type> + friend bool operator == ( Approx const& lhs, const T& rhs ) { + return operator==( rhs, lhs ); + } + + template ::value>::type> + friend bool operator != ( T const& lhs, Approx const& rhs ) { + return !operator==( lhs, rhs ); + } + + template ::value>::type> + friend bool operator != ( Approx const& lhs, T const& rhs ) { + return !operator==( rhs, lhs ); + } + + template ::value>::type> + friend bool operator <= ( T const& lhs, Approx const& rhs ) { + return static_cast(lhs) < rhs.m_value || lhs == rhs; + } + + template ::value>::type> + friend bool operator <= ( Approx const& lhs, T const& rhs ) { + return lhs.m_value < static_cast(rhs) || lhs == rhs; + } + + template ::value>::type> + friend bool operator >= ( T const& lhs, Approx const& rhs ) { + return static_cast(lhs) > rhs.m_value || lhs == rhs; + } + + template ::value>::type> + friend bool operator >= ( Approx const& lhs, T const& rhs ) { + return lhs.m_value > static_cast(rhs) || lhs == rhs; + } + + template ::value>::type> + Approx& epsilon( T const& newEpsilon ) { + double epsilonAsDouble = static_cast(newEpsilon); + if( epsilonAsDouble < 0 || epsilonAsDouble > 1.0 ) { + throw std::domain_error + ( "Invalid Approx::epsilon: " + + Catch::Detail::stringify( epsilonAsDouble ) + + ", Approx::epsilon has to be between 0 and 1" ); + } + m_epsilon = epsilonAsDouble; + return *this; + } + + template ::value>::type> + Approx& margin( T const& newMargin ) { + double marginAsDouble = static_cast(newMargin); + if( marginAsDouble < 0 ) { + throw std::domain_error + ( "Invalid Approx::margin: " + + Catch::Detail::stringify( marginAsDouble ) + + ", Approx::Margin has to be non-negative." ); + + } + m_margin = marginAsDouble; + return *this; + } + + template ::value>::type> + Approx& scale( T const& newScale ) { + m_scale = static_cast(newScale); + return *this; + } + + std::string toString() const; + + private: + double m_epsilon; + double m_margin; + double m_scale; + double m_value; + }; +} + +template<> +struct StringMaker { + static std::string convert(Catch::Detail::Approx const& value); +}; + +} // end namespace Catch + +// end catch_approx.h +// start catch_string_manip.h + +#include +#include + +namespace Catch { + + bool startsWith( std::string const& s, std::string const& prefix ); + bool startsWith( std::string const& s, char prefix ); + bool endsWith( std::string const& s, std::string const& suffix ); + bool endsWith( std::string const& s, char suffix ); + bool contains( std::string const& s, std::string const& infix ); + void toLowerInPlace( std::string& s ); + std::string toLower( std::string const& s ); + std::string trim( std::string const& str ); + bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); + + struct pluralise { + pluralise( std::size_t count, std::string const& label ); + + friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ); + + std::size_t m_count; + std::string m_label; + }; +} + +// end catch_string_manip.h +#ifndef CATCH_CONFIG_DISABLE_MATCHERS +// start catch_capture_matchers.h + +// start catch_matchers.h + +#include +#include + +namespace Catch { +namespace Matchers { + namespace Impl { + + template struct MatchAllOf; + template struct MatchAnyOf; + template struct MatchNotOf; + + class MatcherUntypedBase { + public: + MatcherUntypedBase() = default; + MatcherUntypedBase ( MatcherUntypedBase const& ) = default; + MatcherUntypedBase& operator = ( MatcherUntypedBase const& ) = delete; + std::string toString() const; + + protected: + virtual ~MatcherUntypedBase(); + virtual std::string describe() const = 0; + mutable std::string m_cachedToString; + }; + + template + struct MatcherMethod { + virtual bool match( ObjectT const& arg ) const = 0; + }; + template + struct MatcherMethod { + virtual bool match( PtrT* arg ) const = 0; + }; + + template + struct MatcherBase : MatcherUntypedBase, MatcherMethod { + + MatchAllOf operator && ( MatcherBase const& other ) const; + MatchAnyOf operator || ( MatcherBase const& other ) const; + MatchNotOf operator ! () const; + }; + + template + struct MatchAllOf : MatcherBase { + bool match( ArgT const& arg ) const override { + for( auto matcher : m_matchers ) { + if (!matcher->match(arg)) + return false; + } + return true; + } + std::string describe() const override { + std::string description; + description.reserve( 4 + m_matchers.size()*32 ); + description += "( "; + bool first = true; + for( auto matcher : m_matchers ) { + if( first ) + first = false; + else + description += " and "; + description += matcher->toString(); + } + description += " )"; + return description; + } + + MatchAllOf& operator && ( MatcherBase const& other ) { + m_matchers.push_back( &other ); + return *this; + } + + std::vector const*> m_matchers; + }; + template + struct MatchAnyOf : MatcherBase { + + bool match( ArgT const& arg ) const override { + for( auto matcher : m_matchers ) { + if (matcher->match(arg)) + return true; + } + return false; + } + std::string describe() const override { + std::string description; + description.reserve( 4 + m_matchers.size()*32 ); + description += "( "; + bool first = true; + for( auto matcher : m_matchers ) { + if( first ) + first = false; + else + description += " or "; + description += matcher->toString(); + } + description += " )"; + return description; + } + + MatchAnyOf& operator || ( MatcherBase const& other ) { + m_matchers.push_back( &other ); + return *this; + } + + std::vector const*> m_matchers; + }; + + template + struct MatchNotOf : MatcherBase { + + MatchNotOf( MatcherBase const& underlyingMatcher ) : m_underlyingMatcher( underlyingMatcher ) {} + + bool match( ArgT const& arg ) const override { + return !m_underlyingMatcher.match( arg ); + } + + std::string describe() const override { + return "not " + m_underlyingMatcher.toString(); + } + MatcherBase const& m_underlyingMatcher; + }; + + template + MatchAllOf MatcherBase::operator && ( MatcherBase const& other ) const { + return MatchAllOf() && *this && other; + } + template + MatchAnyOf MatcherBase::operator || ( MatcherBase const& other ) const { + return MatchAnyOf() || *this || other; + } + template + MatchNotOf MatcherBase::operator ! () const { + return MatchNotOf( *this ); + } + + } // namespace Impl + +} // namespace Matchers + +using namespace Matchers; +using Matchers::Impl::MatcherBase; + +} // namespace Catch + +// end catch_matchers.h +// start catch_matchers_floating.h + +#include +#include + +namespace Catch { +namespace Matchers { + + namespace Floating { + + enum class FloatingPointKind : uint8_t; + + struct WithinAbsMatcher : MatcherBase { + WithinAbsMatcher(double target, double margin); + bool match(double const& matchee) const override; + std::string describe() const override; + private: + double m_target; + double m_margin; + }; + + struct WithinUlpsMatcher : MatcherBase { + WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType); + bool match(double const& matchee) const override; + std::string describe() const override; + private: + double m_target; + int m_ulps; + FloatingPointKind m_type; + }; + + } // namespace Floating + + // The following functions create the actual matcher objects. + // This allows the types to be inferred + Floating::WithinUlpsMatcher WithinULP(double target, int maxUlpDiff); + Floating::WithinUlpsMatcher WithinULP(float target, int maxUlpDiff); + Floating::WithinAbsMatcher WithinAbs(double target, double margin); + +} // namespace Matchers +} // namespace Catch + +// end catch_matchers_floating.h +// start catch_matchers_string.h + +#include + +namespace Catch { +namespace Matchers { + + namespace StdString { + + struct CasedString + { + CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ); + std::string adjustString( std::string const& str ) const; + std::string caseSensitivitySuffix() const; + + CaseSensitive::Choice m_caseSensitivity; + std::string m_str; + }; + + struct StringMatcherBase : MatcherBase { + StringMatcherBase( std::string const& operation, CasedString const& comparator ); + std::string describe() const override; + + CasedString m_comparator; + std::string m_operation; + }; + + struct EqualsMatcher : StringMatcherBase { + EqualsMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; + }; + struct ContainsMatcher : StringMatcherBase { + ContainsMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; + }; + struct StartsWithMatcher : StringMatcherBase { + StartsWithMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; + }; + struct EndsWithMatcher : StringMatcherBase { + EndsWithMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; + }; + + struct RegexMatcher : MatcherBase { + RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity ); + bool match( std::string const& matchee ) const override; + std::string describe() const override; + + private: + std::string m_regex; + CaseSensitive::Choice m_caseSensitivity; + }; + + } // namespace StdString + + // The following functions create the actual matcher objects. + // This allows the types to be inferred + + StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + StdString::RegexMatcher Matches( std::string const& regex, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + +} // namespace Matchers +} // namespace Catch + +// end catch_matchers_string.h +// start catch_matchers_vector.h + +#include + +namespace Catch { +namespace Matchers { + + namespace Vector { + namespace Detail { + template + size_t count(InputIterator first, InputIterator last, T const& item) { + size_t cnt = 0; + for (; first != last; ++first) { + if (*first == item) { + ++cnt; + } + } + return cnt; + } + template + bool contains(InputIterator first, InputIterator last, T const& item) { + for (; first != last; ++first) { + if (*first == item) { + return true; + } + } + return false; + } + } + + template + struct ContainsElementMatcher : MatcherBase> { + + ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {} + + bool match(std::vector const &v) const override { + for (auto const& el : v) { + if (el == m_comparator) { + return true; + } + } + return false; + } + + std::string describe() const override { + return "Contains: " + ::Catch::Detail::stringify( m_comparator ); + } + + T const& m_comparator; + }; + + template + struct ContainsMatcher : MatcherBase> { + + ContainsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} + + bool match(std::vector const &v) const override { + // !TBD: see note in EqualsMatcher + if (m_comparator.size() > v.size()) + return false; + for (auto const& comparator : m_comparator) { + auto present = false; + for (const auto& el : v) { + if (el == comparator) { + present = true; + break; + } + } + if (!present) { + return false; + } + } + return true; + } + std::string describe() const override { + return "Contains: " + ::Catch::Detail::stringify( m_comparator ); + } + + std::vector const& m_comparator; + }; + + template + struct EqualsMatcher : MatcherBase> { + + EqualsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} + + bool match(std::vector const &v) const override { + // !TBD: This currently works if all elements can be compared using != + // - a more general approach would be via a compare template that defaults + // to using !=. but could be specialised for, e.g. std::vector etc + // - then just call that directly + if (m_comparator.size() != v.size()) + return false; + for (std::size_t i = 0; i < v.size(); ++i) + if (m_comparator[i] != v[i]) + return false; + return true; + } + std::string describe() const override { + return "Equals: " + ::Catch::Detail::stringify( m_comparator ); + } + std::vector const& m_comparator; + }; + + template + struct UnorderedEqualsMatcher : MatcherBase> { + UnorderedEqualsMatcher(std::vector const& target) : m_target(target) {} + bool match(std::vector const& vec) const override { + // Note: This is a reimplementation of std::is_permutation, + // because I don't want to include inside the common path + if (m_target.size() != vec.size()) { + return false; + } + auto lfirst = m_target.begin(), llast = m_target.end(); + auto rfirst = vec.begin(), rlast = vec.end(); + // Cut common prefix to optimize checking of permuted parts + while (lfirst != llast && *lfirst != *rfirst) { + ++lfirst; ++rfirst; + } + if (lfirst == llast) { + return true; + } + + for (auto mid = lfirst; mid != llast; ++mid) { + // Skip already counted items + if (Detail::contains(lfirst, mid, *mid)) { + continue; + } + size_t num_vec = Detail::count(rfirst, rlast, *mid); + if (num_vec == 0 || Detail::count(lfirst, llast, *mid) != num_vec) { + return false; + } + } + + return true; + } + + std::string describe() const override { + return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target); + } + private: + std::vector const& m_target; + }; + + } // namespace Vector + + // The following functions create the actual matcher objects. + // This allows the types to be inferred + + template + Vector::ContainsMatcher Contains( std::vector const& comparator ) { + return Vector::ContainsMatcher( comparator ); + } + + template + Vector::ContainsElementMatcher VectorContains( T const& comparator ) { + return Vector::ContainsElementMatcher( comparator ); + } + + template + Vector::EqualsMatcher Equals( std::vector const& comparator ) { + return Vector::EqualsMatcher( comparator ); + } + + template + Vector::UnorderedEqualsMatcher UnorderedEquals(std::vector const& target) { + return Vector::UnorderedEqualsMatcher(target); + } + +} // namespace Matchers +} // namespace Catch + +// end catch_matchers_vector.h +namespace Catch { + + template + class MatchExpr : public ITransientExpression { + ArgT const& m_arg; + MatcherT m_matcher; + StringRef m_matcherString; + public: + MatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef matcherString ) + : ITransientExpression{ true, matcher.match( arg ) }, + m_arg( arg ), + m_matcher( matcher ), + m_matcherString( matcherString ) + {} + + void streamReconstructedExpression( std::ostream &os ) const override { + auto matcherAsString = m_matcher.toString(); + os << Catch::Detail::stringify( m_arg ) << ' '; + if( matcherAsString == Detail::unprintableString ) + os << m_matcherString; + else + os << matcherAsString; + } + }; + + using StringMatcher = Matchers::Impl::MatcherBase; + + void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ); + + template + auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef matcherString ) -> MatchExpr { + return MatchExpr( arg, matcher, matcherString ); + } + +} // namespace Catch + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ + INTERNAL_CATCH_TRY { \ + catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher ) ); \ + } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \ + do { \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ + if( catchAssertionHandler.allowThrows() ) \ + try { \ + static_cast(__VA_ARGS__ ); \ + catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ + } \ + catch( exceptionType const& ex ) { \ + catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher ) ); \ + } \ + catch( ... ) { \ + catchAssertionHandler.handleUnexpectedInflightException(); \ + } \ + else \ + catchAssertionHandler.handleThrowingCallSkipped(); \ + INTERNAL_CATCH_REACT( catchAssertionHandler ) \ + } while( false ) + +// end catch_capture_matchers.h +#endif + +// These files are included here so the single_include script doesn't put them +// in the conditionally compiled sections +// start catch_test_case_info.h + +#include +#include +#include + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + +namespace Catch { + + struct ITestInvoker; + + struct TestCaseInfo { + enum SpecialProperties{ + None = 0, + IsHidden = 1 << 1, + ShouldFail = 1 << 2, + MayFail = 1 << 3, + Throws = 1 << 4, + NonPortable = 1 << 5, + Benchmark = 1 << 6 + }; + + TestCaseInfo( std::string const& _name, + std::string const& _className, + std::string const& _description, + std::vector const& _tags, + SourceLineInfo const& _lineInfo ); + + friend void setTags( TestCaseInfo& testCaseInfo, std::vector tags ); + + bool isHidden() const; + bool throws() const; + bool okToFail() const; + bool expectedToFail() const; + + std::string tagsAsString() const; + + std::string name; + std::string className; + std::string description; + std::vector tags; + std::vector lcaseTags; + SourceLineInfo lineInfo; + SpecialProperties properties; + }; + + class TestCase : public TestCaseInfo { + public: + + TestCase( ITestInvoker* testCase, TestCaseInfo const& info ); + + TestCase withName( std::string const& _newName ) const; + + void invoke() const; + + TestCaseInfo const& getTestCaseInfo() const; + + bool operator == ( TestCase const& other ) const; + bool operator < ( TestCase const& other ) const; + + private: + std::shared_ptr test; + }; + + TestCase makeTestCase( ITestInvoker* testCase, + std::string const& className, + std::string const& name, + std::string const& description, + SourceLineInfo const& lineInfo ); +} + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// end catch_test_case_info.h +// start catch_interfaces_runner.h + +namespace Catch { + + struct IRunner { + virtual ~IRunner(); + virtual bool aborting() const = 0; + }; +} + +// end catch_interfaces_runner.h + +#ifdef __OBJC__ +// start catch_objc.hpp + +#import + +#include + +// NB. Any general catch headers included here must be included +// in catch.hpp first to make sure they are included by the single +// header for non obj-usage + +/////////////////////////////////////////////////////////////////////////////// +// This protocol is really only here for (self) documenting purposes, since +// all its methods are optional. +@protocol OcFixture + +@optional + +-(void) setUp; +-(void) tearDown; + +@end + +namespace Catch { + + class OcMethod : public ITestInvoker { + + public: + OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {} + + virtual void invoke() const { + id obj = [[m_cls alloc] init]; + + performOptionalSelector( obj, @selector(setUp) ); + performOptionalSelector( obj, m_sel ); + performOptionalSelector( obj, @selector(tearDown) ); + + arcSafeRelease( obj ); + } + private: + virtual ~OcMethod() {} + + Class m_cls; + SEL m_sel; + }; + + namespace Detail{ + + inline std::string getAnnotation( Class cls, + std::string const& annotationName, + std::string const& testCaseName ) { + NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()]; + SEL sel = NSSelectorFromString( selStr ); + arcSafeRelease( selStr ); + id value = performOptionalSelector( cls, sel ); + if( value ) + return [(NSString*)value UTF8String]; + return ""; + } + } + + inline std::size_t registerTestMethods() { + std::size_t noTestMethods = 0; + int noClasses = objc_getClassList( nullptr, 0 ); + + Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses); + objc_getClassList( classes, noClasses ); + + for( int c = 0; c < noClasses; c++ ) { + Class cls = classes[c]; + { + u_int count; + Method* methods = class_copyMethodList( cls, &count ); + for( u_int m = 0; m < count ; m++ ) { + SEL selector = method_getName(methods[m]); + std::string methodName = sel_getName(selector); + if( startsWith( methodName, "Catch_TestCase_" ) ) { + std::string testCaseName = methodName.substr( 15 ); + std::string name = Detail::getAnnotation( cls, "Name", testCaseName ); + std::string desc = Detail::getAnnotation( cls, "Description", testCaseName ); + const char* className = class_getName( cls ); + + getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo("",0) ) ); + noTestMethods++; + } + } + free(methods); + } + } + return noTestMethods; + } + +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) + + namespace Matchers { + namespace Impl { + namespace NSStringMatchers { + + struct StringHolder : MatcherBase{ + StringHolder( NSString* substr ) : m_substr( [substr copy] ){} + StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){} + StringHolder() { + arcSafeRelease( m_substr ); + } + + bool match( NSString* arg ) const override { + return false; + } + + NSString* CATCH_ARC_STRONG m_substr; + }; + + struct Equals : StringHolder { + Equals( NSString* substr ) : StringHolder( substr ){} + + bool match( NSString* str ) const override { + return (str != nil || m_substr == nil ) && + [str isEqualToString:m_substr]; + } + + std::string describe() const override { + return "equals string: " + Catch::Detail::stringify( m_substr ); + } + }; + + struct Contains : StringHolder { + Contains( NSString* substr ) : StringHolder( substr ){} + + bool match( NSString* str ) const { + return (str != nil || m_substr == nil ) && + [str rangeOfString:m_substr].location != NSNotFound; + } + + std::string describe() const override { + return "contains string: " + Catch::Detail::stringify( m_substr ); + } + }; + + struct StartsWith : StringHolder { + StartsWith( NSString* substr ) : StringHolder( substr ){} + + bool match( NSString* str ) const override { + return (str != nil || m_substr == nil ) && + [str rangeOfString:m_substr].location == 0; + } + + std::string describe() const override { + return "starts with: " + Catch::Detail::stringify( m_substr ); + } + }; + struct EndsWith : StringHolder { + EndsWith( NSString* substr ) : StringHolder( substr ){} + + bool match( NSString* str ) const override { + return (str != nil || m_substr == nil ) && + [str rangeOfString:m_substr].location == [str length] - [m_substr length]; + } + + std::string describe() const override { + return "ends with: " + Catch::Detail::stringify( m_substr ); + } + }; + + } // namespace NSStringMatchers + } // namespace Impl + + inline Impl::NSStringMatchers::Equals + Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); } + + inline Impl::NSStringMatchers::Contains + Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); } + + inline Impl::NSStringMatchers::StartsWith + StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); } + + inline Impl::NSStringMatchers::EndsWith + EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); } + + } // namespace Matchers + + using namespace Matchers; + +#endif // CATCH_CONFIG_DISABLE_MATCHERS + +} // namespace Catch + +/////////////////////////////////////////////////////////////////////////////// +#define OC_MAKE_UNIQUE_NAME( root, uniqueSuffix ) root##uniqueSuffix +#define OC_TEST_CASE2( name, desc, uniqueSuffix ) \ ++(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Name_test_, uniqueSuffix ) \ +{ \ +return @ name; \ +} \ ++(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Description_test_, uniqueSuffix ) \ +{ \ +return @ desc; \ +} \ +-(void) OC_MAKE_UNIQUE_NAME( Catch_TestCase_test_, uniqueSuffix ) + +#define OC_TEST_CASE( name, desc ) OC_TEST_CASE2( name, desc, __LINE__ ) + +// end catch_objc.hpp +#endif + +#ifdef CATCH_CONFIG_EXTERNAL_INTERFACES +// start catch_external_interfaces.h + +// start catch_reporter_bases.hpp + +// start catch_interfaces_reporter.h + +// start catch_config.hpp + +// start catch_test_spec_parser.h + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + +// start catch_test_spec.h + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + +// start catch_wildcard_pattern.h + +namespace Catch +{ + class WildcardPattern { + enum WildcardPosition { + NoWildcard = 0, + WildcardAtStart = 1, + WildcardAtEnd = 2, + WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd + }; + + public: + + WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity ); + virtual ~WildcardPattern() = default; + virtual bool matches( std::string const& str ) const; + + private: + std::string adjustCase( std::string const& str ) const; + CaseSensitive::Choice m_caseSensitivity; + WildcardPosition m_wildcard = NoWildcard; + std::string m_pattern; + }; +} + +// end catch_wildcard_pattern.h +#include +#include +#include + +namespace Catch { + + class TestSpec { + struct Pattern { + virtual ~Pattern(); + virtual bool matches( TestCaseInfo const& testCase ) const = 0; + }; + using PatternPtr = std::shared_ptr; + + class NamePattern : public Pattern { + public: + NamePattern( std::string const& name ); + virtual ~NamePattern(); + virtual bool matches( TestCaseInfo const& testCase ) const override; + private: + WildcardPattern m_wildcardPattern; + }; + + class TagPattern : public Pattern { + public: + TagPattern( std::string const& tag ); + virtual ~TagPattern(); + virtual bool matches( TestCaseInfo const& testCase ) const override; + private: + std::string m_tag; + }; + + class ExcludedPattern : public Pattern { + public: + ExcludedPattern( PatternPtr const& underlyingPattern ); + virtual ~ExcludedPattern(); + virtual bool matches( TestCaseInfo const& testCase ) const override; + private: + PatternPtr m_underlyingPattern; + }; + + struct Filter { + std::vector m_patterns; + + bool matches( TestCaseInfo const& testCase ) const; + }; + + public: + bool hasFilters() const; + bool matches( TestCaseInfo const& testCase ) const; + + private: + std::vector m_filters; + + friend class TestSpecParser; + }; +} + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// end catch_test_spec.h +// start catch_interfaces_tag_alias_registry.h + +#include + +namespace Catch { + + struct TagAlias; + + struct ITagAliasRegistry { + virtual ~ITagAliasRegistry(); + // Nullptr if not present + virtual TagAlias const* find( std::string const& alias ) const = 0; + virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0; + + static ITagAliasRegistry const& get(); + }; + +} // end namespace Catch + +// end catch_interfaces_tag_alias_registry.h +namespace Catch { + + class TestSpecParser { + enum Mode{ None, Name, QuotedName, Tag, EscapedName }; + Mode m_mode = None; + bool m_exclusion = false; + std::size_t m_start = std::string::npos, m_pos = 0; + std::string m_arg; + std::vector m_escapeChars; + TestSpec::Filter m_currentFilter; + TestSpec m_testSpec; + ITagAliasRegistry const* m_tagAliases = nullptr; + + public: + TestSpecParser( ITagAliasRegistry const& tagAliases ); + + TestSpecParser& parse( std::string const& arg ); + TestSpec testSpec(); + + private: + void visitChar( char c ); + void startNewMode( Mode mode, std::size_t start ); + void escape(); + std::string subString() const; + + template + void addPattern() { + std::string token = subString(); + for( std::size_t i = 0; i < m_escapeChars.size(); ++i ) + token = token.substr( 0, m_escapeChars[i]-m_start-i ) + token.substr( m_escapeChars[i]-m_start-i+1 ); + m_escapeChars.clear(); + if( startsWith( token, "exclude:" ) ) { + m_exclusion = true; + token = token.substr( 8 ); + } + if( !token.empty() ) { + TestSpec::PatternPtr pattern = std::make_shared( token ); + if( m_exclusion ) + pattern = std::make_shared( pattern ); + m_currentFilter.m_patterns.push_back( pattern ); + } + m_exclusion = false; + m_mode = None; + } + + void addFilter(); + }; + TestSpec parseTestSpec( std::string const& arg ); + +} // namespace Catch + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// end catch_test_spec_parser.h +// start catch_interfaces_config.h + +#include +#include +#include +#include + +namespace Catch { + + enum class Verbosity { + Quiet = 0, + Normal, + High + }; + + struct WarnAbout { enum What { + Nothing = 0x00, + NoAssertions = 0x01 + }; }; + + struct ShowDurations { enum OrNot { + DefaultForReporter, + Always, + Never + }; }; + struct RunTests { enum InWhatOrder { + InDeclarationOrder, + InLexicographicalOrder, + InRandomOrder + }; }; + struct UseColour { enum YesOrNo { + Auto, + Yes, + No + }; }; + struct WaitForKeypress { enum When { + Never, + BeforeStart = 1, + BeforeExit = 2, + BeforeStartAndExit = BeforeStart | BeforeExit + }; }; + + class TestSpec; + + struct IConfig : NonCopyable { + + virtual ~IConfig(); + + virtual bool allowThrows() const = 0; + virtual std::ostream& stream() const = 0; + virtual std::string name() const = 0; + virtual bool includeSuccessfulResults() const = 0; + virtual bool shouldDebugBreak() const = 0; + virtual bool warnAboutMissingAssertions() const = 0; + virtual int abortAfter() const = 0; + virtual bool showInvisibles() const = 0; + virtual ShowDurations::OrNot showDurations() const = 0; + virtual TestSpec const& testSpec() const = 0; + virtual RunTests::InWhatOrder runOrder() const = 0; + virtual unsigned int rngSeed() const = 0; + virtual int benchmarkResolutionMultiple() const = 0; + virtual UseColour::YesOrNo useColour() const = 0; + virtual std::vector const& getSectionsToRun() const = 0; + virtual Verbosity verbosity() const = 0; + }; + + using IConfigPtr = std::shared_ptr; +} + +// end catch_interfaces_config.h +// Libstdc++ doesn't like incomplete classes for unique_ptr + +#include +#include +#include + +#ifndef CATCH_CONFIG_CONSOLE_WIDTH +#define CATCH_CONFIG_CONSOLE_WIDTH 80 +#endif + +namespace Catch { + + struct IStream; + + struct ConfigData { + bool listTests = false; + bool listTags = false; + bool listReporters = false; + bool listTestNamesOnly = false; + + bool showSuccessfulTests = false; + bool shouldDebugBreak = false; + bool noThrow = false; + bool showHelp = false; + bool showInvisibles = false; + bool filenamesAsTags = false; + bool libIdentify = false; + + int abortAfter = -1; + unsigned int rngSeed = 0; + int benchmarkResolutionMultiple = 100; + + Verbosity verbosity = Verbosity::Normal; + WarnAbout::What warnings = WarnAbout::Nothing; + ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter; + RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder; + UseColour::YesOrNo useColour = UseColour::Auto; + WaitForKeypress::When waitForKeypress = WaitForKeypress::Never; + + std::string outputFilename; + std::string name; + std::string processName; + + std::vector reporterNames; + std::vector testsOrTags; + std::vector sectionsToRun; + }; + + class Config : public IConfig { + public: + + Config() = default; + Config( ConfigData const& data ); + virtual ~Config() = default; + + std::string const& getFilename() const; + + bool listTests() const; + bool listTestNamesOnly() const; + bool listTags() const; + bool listReporters() const; + + std::string getProcessName() const; + + std::vector const& getReporterNames() const; + std::vector const& getSectionsToRun() const override; + + virtual TestSpec const& testSpec() const override; + + bool showHelp() const; + + // IConfig interface + bool allowThrows() const override; + std::ostream& stream() const override; + std::string name() const override; + bool includeSuccessfulResults() const override; + bool warnAboutMissingAssertions() const override; + ShowDurations::OrNot showDurations() const override; + RunTests::InWhatOrder runOrder() const override; + unsigned int rngSeed() const override; + int benchmarkResolutionMultiple() const override; + UseColour::YesOrNo useColour() const override; + bool shouldDebugBreak() const override; + int abortAfter() const override; + bool showInvisibles() const override; + Verbosity verbosity() const override; + + private: + + IStream const* openStream(); + ConfigData m_data; + + std::unique_ptr m_stream; + TestSpec m_testSpec; + }; + +} // end namespace Catch + +// end catch_config.hpp +// start catch_assertionresult.h + +#include + +namespace Catch { + + struct AssertionResultData + { + AssertionResultData() = delete; + + AssertionResultData( ResultWas::OfType _resultType, LazyExpression const& _lazyExpression ); + + std::string message; + mutable std::string reconstructedExpression; + LazyExpression lazyExpression; + ResultWas::OfType resultType; + + std::string reconstructExpression() const; + }; + + class AssertionResult { + public: + AssertionResult() = delete; + AssertionResult( AssertionInfo const& info, AssertionResultData const& data ); + + bool isOk() const; + bool succeeded() const; + ResultWas::OfType getResultType() const; + bool hasExpression() const; + bool hasMessage() const; + std::string getExpression() const; + std::string getExpressionInMacro() const; + bool hasExpandedExpression() const; + std::string getExpandedExpression() const; + std::string getMessage() const; + SourceLineInfo getSourceInfo() const; + StringRef getTestMacroName() const; + + //protected: + AssertionInfo m_info; + AssertionResultData m_resultData; + }; + +} // end namespace Catch + +// end catch_assertionresult.h +// start catch_option.hpp + +namespace Catch { + + // An optional type + template + class Option { + public: + Option() : nullableValue( nullptr ) {} + Option( T const& _value ) + : nullableValue( new( storage ) T( _value ) ) + {} + Option( Option const& _other ) + : nullableValue( _other ? new( storage ) T( *_other ) : nullptr ) + {} + + ~Option() { + reset(); + } + + Option& operator= ( Option const& _other ) { + if( &_other != this ) { + reset(); + if( _other ) + nullableValue = new( storage ) T( *_other ); + } + return *this; + } + Option& operator = ( T const& _value ) { + reset(); + nullableValue = new( storage ) T( _value ); + return *this; + } + + void reset() { + if( nullableValue ) + nullableValue->~T(); + nullableValue = nullptr; + } + + T& operator*() { return *nullableValue; } + T const& operator*() const { return *nullableValue; } + T* operator->() { return nullableValue; } + const T* operator->() const { return nullableValue; } + + T valueOr( T const& defaultValue ) const { + return nullableValue ? *nullableValue : defaultValue; + } + + bool some() const { return nullableValue != nullptr; } + bool none() const { return nullableValue == nullptr; } + + bool operator !() const { return nullableValue == nullptr; } + explicit operator bool() const { + return some(); + } + + private: + T *nullableValue; + alignas(alignof(T)) char storage[sizeof(T)]; + }; + +} // end namespace Catch + +// end catch_option.hpp +#include +#include +#include +#include +#include + +namespace Catch { + + struct ReporterConfig { + explicit ReporterConfig( IConfigPtr const& _fullConfig ); + + ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream ); + + std::ostream& stream() const; + IConfigPtr fullConfig() const; + + private: + std::ostream* m_stream; + IConfigPtr m_fullConfig; + }; + + struct ReporterPreferences { + bool shouldRedirectStdOut = false; + }; + + template + struct LazyStat : Option { + LazyStat& operator=( T const& _value ) { + Option::operator=( _value ); + used = false; + return *this; + } + void reset() { + Option::reset(); + used = false; + } + bool used = false; + }; + + struct TestRunInfo { + TestRunInfo( std::string const& _name ); + std::string name; + }; + struct GroupInfo { + GroupInfo( std::string const& _name, + std::size_t _groupIndex, + std::size_t _groupsCount ); + + std::string name; + std::size_t groupIndex; + std::size_t groupsCounts; + }; + + struct AssertionStats { + AssertionStats( AssertionResult const& _assertionResult, + std::vector const& _infoMessages, + Totals const& _totals ); + + AssertionStats( AssertionStats const& ) = default; + AssertionStats( AssertionStats && ) = default; + AssertionStats& operator = ( AssertionStats const& ) = default; + AssertionStats& operator = ( AssertionStats && ) = default; + virtual ~AssertionStats(); + + AssertionResult assertionResult; + std::vector infoMessages; + Totals totals; + }; + + struct SectionStats { + SectionStats( SectionInfo const& _sectionInfo, + Counts const& _assertions, + double _durationInSeconds, + bool _missingAssertions ); + SectionStats( SectionStats const& ) = default; + SectionStats( SectionStats && ) = default; + SectionStats& operator = ( SectionStats const& ) = default; + SectionStats& operator = ( SectionStats && ) = default; + virtual ~SectionStats(); + + SectionInfo sectionInfo; + Counts assertions; + double durationInSeconds; + bool missingAssertions; + }; + + struct TestCaseStats { + TestCaseStats( TestCaseInfo const& _testInfo, + Totals const& _totals, + std::string const& _stdOut, + std::string const& _stdErr, + bool _aborting ); + + TestCaseStats( TestCaseStats const& ) = default; + TestCaseStats( TestCaseStats && ) = default; + TestCaseStats& operator = ( TestCaseStats const& ) = default; + TestCaseStats& operator = ( TestCaseStats && ) = default; + virtual ~TestCaseStats(); + + TestCaseInfo testInfo; + Totals totals; + std::string stdOut; + std::string stdErr; + bool aborting; + }; + + struct TestGroupStats { + TestGroupStats( GroupInfo const& _groupInfo, + Totals const& _totals, + bool _aborting ); + TestGroupStats( GroupInfo const& _groupInfo ); + + TestGroupStats( TestGroupStats const& ) = default; + TestGroupStats( TestGroupStats && ) = default; + TestGroupStats& operator = ( TestGroupStats const& ) = default; + TestGroupStats& operator = ( TestGroupStats && ) = default; + virtual ~TestGroupStats(); + + GroupInfo groupInfo; + Totals totals; + bool aborting; + }; + + struct TestRunStats { + TestRunStats( TestRunInfo const& _runInfo, + Totals const& _totals, + bool _aborting ); + + TestRunStats( TestRunStats const& ) = default; + TestRunStats( TestRunStats && ) = default; + TestRunStats& operator = ( TestRunStats const& ) = default; + TestRunStats& operator = ( TestRunStats && ) = default; + virtual ~TestRunStats(); + + TestRunInfo runInfo; + Totals totals; + bool aborting; + }; + + struct BenchmarkInfo { + std::string name; + }; + struct BenchmarkStats { + BenchmarkInfo info; + std::size_t iterations; + uint64_t elapsedTimeInNanoseconds; + }; + + struct IStreamingReporter { + virtual ~IStreamingReporter() = default; + + // Implementing class must also provide the following static methods: + // static std::string getDescription(); + // static std::set getSupportedVerbosities() + + virtual ReporterPreferences getPreferences() const = 0; + + virtual void noMatchingTestCases( std::string const& spec ) = 0; + + virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0; + virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0; + + virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0; + virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0; + + // *** experimental *** + virtual void benchmarkStarting( BenchmarkInfo const& ) {} + + virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0; + + // The return value indicates if the messages buffer should be cleared: + virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0; + + // *** experimental *** + virtual void benchmarkEnded( BenchmarkStats const& ) {} + + virtual void sectionEnded( SectionStats const& sectionStats ) = 0; + virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0; + virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0; + virtual void testRunEnded( TestRunStats const& testRunStats ) = 0; + + virtual void skipTest( TestCaseInfo const& testInfo ) = 0; + + // Default empty implementation provided + virtual void fatalErrorEncountered( StringRef name ); + + virtual bool isMulti() const; + }; + using IStreamingReporterPtr = std::unique_ptr; + + struct IReporterFactory { + virtual ~IReporterFactory(); + virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0; + virtual std::string getDescription() const = 0; + }; + using IReporterFactoryPtr = std::shared_ptr; + + struct IReporterRegistry { + using FactoryMap = std::map; + using Listeners = std::vector; + + virtual ~IReporterRegistry(); + virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0; + virtual FactoryMap const& getFactories() const = 0; + virtual Listeners const& getListeners() const = 0; + }; + + void addReporter( IStreamingReporterPtr& existingReporter, IStreamingReporterPtr&& additionalReporter ); + +} // end namespace Catch + +// end catch_interfaces_reporter.h +#include +#include +#include +#include +#include +#include +#include + +namespace Catch { + void prepareExpandedExpression(AssertionResult& result); + + // Returns double formatted as %.3f (format expected on output) + std::string getFormattedDuration( double duration ); + + template + struct StreamingReporterBase : IStreamingReporter { + + StreamingReporterBase( ReporterConfig const& _config ) + : m_config( _config.fullConfig() ), + stream( _config.stream() ) + { + m_reporterPrefs.shouldRedirectStdOut = false; + if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) ) + throw std::domain_error( "Verbosity level not supported by this reporter" ); + } + + ReporterPreferences getPreferences() const override { + return m_reporterPrefs; + } + + static std::set getSupportedVerbosities() { + return { Verbosity::Normal }; + } + + ~StreamingReporterBase() override = default; + + void noMatchingTestCases(std::string const&) override {} + + void testRunStarting(TestRunInfo const& _testRunInfo) override { + currentTestRunInfo = _testRunInfo; + } + void testGroupStarting(GroupInfo const& _groupInfo) override { + currentGroupInfo = _groupInfo; + } + + void testCaseStarting(TestCaseInfo const& _testInfo) override { + currentTestCaseInfo = _testInfo; + } + void sectionStarting(SectionInfo const& _sectionInfo) override { + m_sectionStack.push_back(_sectionInfo); + } + + void sectionEnded(SectionStats const& /* _sectionStats */) override { + m_sectionStack.pop_back(); + } + void testCaseEnded(TestCaseStats const& /* _testCaseStats */) override { + currentTestCaseInfo.reset(); + } + void testGroupEnded(TestGroupStats const& /* _testGroupStats */) override { + currentGroupInfo.reset(); + } + void testRunEnded(TestRunStats const& /* _testRunStats */) override { + currentTestCaseInfo.reset(); + currentGroupInfo.reset(); + currentTestRunInfo.reset(); + } + + void skipTest(TestCaseInfo const&) override { + // Don't do anything with this by default. + // It can optionally be overridden in the derived class. + } + + IConfigPtr m_config; + std::ostream& stream; + + LazyStat currentTestRunInfo; + LazyStat currentGroupInfo; + LazyStat currentTestCaseInfo; + + std::vector m_sectionStack; + ReporterPreferences m_reporterPrefs; + }; + + template + struct CumulativeReporterBase : IStreamingReporter { + template + struct Node { + explicit Node( T const& _value ) : value( _value ) {} + virtual ~Node() {} + + using ChildNodes = std::vector>; + T value; + ChildNodes children; + }; + struct SectionNode { + explicit SectionNode(SectionStats const& _stats) : stats(_stats) {} + virtual ~SectionNode() = default; + + bool operator == (SectionNode const& other) const { + return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo; + } + bool operator == (std::shared_ptr const& other) const { + return operator==(*other); + } + + SectionStats stats; + using ChildSections = std::vector>; + using Assertions = std::vector; + ChildSections childSections; + Assertions assertions; + std::string stdOut; + std::string stdErr; + }; + + struct BySectionInfo { + BySectionInfo( SectionInfo const& other ) : m_other( other ) {} + BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {} + bool operator() (std::shared_ptr const& node) const { + return ((node->stats.sectionInfo.name == m_other.name) && + (node->stats.sectionInfo.lineInfo == m_other.lineInfo)); + } + void operator=(BySectionInfo const&) = delete; + + private: + SectionInfo const& m_other; + }; + + using TestCaseNode = Node; + using TestGroupNode = Node; + using TestRunNode = Node; + + CumulativeReporterBase( ReporterConfig const& _config ) + : m_config( _config.fullConfig() ), + stream( _config.stream() ) + { + m_reporterPrefs.shouldRedirectStdOut = false; + if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) ) + throw std::domain_error( "Verbosity level not supported by this reporter" ); + } + ~CumulativeReporterBase() override = default; + + ReporterPreferences getPreferences() const override { + return m_reporterPrefs; + } + + static std::set getSupportedVerbosities() { + return { Verbosity::Normal }; + } + + void testRunStarting( TestRunInfo const& ) override {} + void testGroupStarting( GroupInfo const& ) override {} + + void testCaseStarting( TestCaseInfo const& ) override {} + + void sectionStarting( SectionInfo const& sectionInfo ) override { + SectionStats incompleteStats( sectionInfo, Counts(), 0, false ); + std::shared_ptr node; + if( m_sectionStack.empty() ) { + if( !m_rootSection ) + m_rootSection = std::make_shared( incompleteStats ); + node = m_rootSection; + } + else { + SectionNode& parentNode = *m_sectionStack.back(); + auto it = + std::find_if( parentNode.childSections.begin(), + parentNode.childSections.end(), + BySectionInfo( sectionInfo ) ); + if( it == parentNode.childSections.end() ) { + node = std::make_shared( incompleteStats ); + parentNode.childSections.push_back( node ); + } + else + node = *it; + } + m_sectionStack.push_back( node ); + m_deepestSection = std::move(node); + } + + void assertionStarting(AssertionInfo const&) override {} + + bool assertionEnded(AssertionStats const& assertionStats) override { + assert(!m_sectionStack.empty()); + // AssertionResult holds a pointer to a temporary DecomposedExpression, + // which getExpandedExpression() calls to build the expression string. + // Our section stack copy of the assertionResult will likely outlive the + // temporary, so it must be expanded or discarded now to avoid calling + // a destroyed object later. + prepareExpandedExpression(const_cast( assertionStats.assertionResult ) ); + SectionNode& sectionNode = *m_sectionStack.back(); + sectionNode.assertions.push_back(assertionStats); + return true; + } + void sectionEnded(SectionStats const& sectionStats) override { + assert(!m_sectionStack.empty()); + SectionNode& node = *m_sectionStack.back(); + node.stats = sectionStats; + m_sectionStack.pop_back(); + } + void testCaseEnded(TestCaseStats const& testCaseStats) override { + auto node = std::make_shared(testCaseStats); + assert(m_sectionStack.size() == 0); + node->children.push_back(m_rootSection); + m_testCases.push_back(node); + m_rootSection.reset(); + + assert(m_deepestSection); + m_deepestSection->stdOut = testCaseStats.stdOut; + m_deepestSection->stdErr = testCaseStats.stdErr; + } + void testGroupEnded(TestGroupStats const& testGroupStats) override { + auto node = std::make_shared(testGroupStats); + node->children.swap(m_testCases); + m_testGroups.push_back(node); + } + void testRunEnded(TestRunStats const& testRunStats) override { + auto node = std::make_shared(testRunStats); + node->children.swap(m_testGroups); + m_testRuns.push_back(node); + testRunEndedCumulative(); + } + virtual void testRunEndedCumulative() = 0; + + void skipTest(TestCaseInfo const&) override {} + + IConfigPtr m_config; + std::ostream& stream; + std::vector m_assertions; + std::vector>> m_sections; + std::vector> m_testCases; + std::vector> m_testGroups; + + std::vector> m_testRuns; + + std::shared_ptr m_rootSection; + std::shared_ptr m_deepestSection; + std::vector> m_sectionStack; + ReporterPreferences m_reporterPrefs; + }; + + template + char const* getLineOfChars() { + static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0}; + if( !*line ) { + std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 ); + line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0; + } + return line; + } + + struct TestEventListenerBase : StreamingReporterBase { + TestEventListenerBase( ReporterConfig const& _config ); + + void assertionStarting(AssertionInfo const&) override; + bool assertionEnded(AssertionStats const&) override; + }; + +} // end namespace Catch + +// end catch_reporter_bases.hpp +// start catch_console_colour.h + +namespace Catch { + + struct Colour { + enum Code { + None = 0, + + White, + Red, + Green, + Blue, + Cyan, + Yellow, + Grey, + + Bright = 0x10, + + BrightRed = Bright | Red, + BrightGreen = Bright | Green, + LightGrey = Bright | Grey, + BrightWhite = Bright | White, + + // By intention + FileName = LightGrey, + Warning = Yellow, + ResultError = BrightRed, + ResultSuccess = BrightGreen, + ResultExpectedFailure = Warning, + + Error = BrightRed, + Success = Green, + + OriginalExpression = Cyan, + ReconstructedExpression = Yellow, + + SecondaryText = LightGrey, + Headers = White + }; + + // Use constructed object for RAII guard + Colour( Code _colourCode ); + Colour( Colour&& other ) noexcept; + Colour& operator=( Colour&& other ) noexcept; + ~Colour(); + + // Use static method for one-shot changes + static void use( Code _colourCode ); + + private: + bool m_moved = false; + }; + + std::ostream& operator << ( std::ostream& os, Colour const& ); + +} // end namespace Catch + +// end catch_console_colour.h +// start catch_reporter_registrars.hpp + + +namespace Catch { + + template + class ReporterRegistrar { + + class ReporterFactory : public IReporterFactory { + + virtual IStreamingReporterPtr create( ReporterConfig const& config ) const override { + return std::unique_ptr( new T( config ) ); + } + + virtual std::string getDescription() const override { + return T::getDescription(); + } + }; + + public: + + explicit ReporterRegistrar( std::string const& name ) { + getMutableRegistryHub().registerReporter( name, std::make_shared() ); + } + }; + + template + class ListenerRegistrar { + + class ListenerFactory : public IReporterFactory { + + virtual IStreamingReporterPtr create( ReporterConfig const& config ) const override { + return std::unique_ptr( new T( config ) ); + } + virtual std::string getDescription() const override { + return std::string(); + } + }; + + public: + + ListenerRegistrar() { + getMutableRegistryHub().registerListener( std::make_shared() ); + } + }; +} + +#if !defined(CATCH_CONFIG_DISABLE) + +#define CATCH_REGISTER_REPORTER( name, reporterType ) \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::ReporterRegistrar catch_internal_RegistrarFor##reporterType( name ); } \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS + +#define CATCH_REGISTER_LISTENER( listenerType ) \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::ListenerRegistrar catch_internal_RegistrarFor##listenerType; } \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS +#else // CATCH_CONFIG_DISABLE + +#define CATCH_REGISTER_REPORTER(name, reporterType) +#define CATCH_REGISTER_LISTENER(listenerType) + +#endif // CATCH_CONFIG_DISABLE + +// end catch_reporter_registrars.hpp +// Allow users to base their work off existing reporters +// start catch_reporter_compact.h + +namespace Catch { + + struct CompactReporter : StreamingReporterBase { + + using StreamingReporterBase::StreamingReporterBase; + + ~CompactReporter() override; + + static std::string getDescription(); + + ReporterPreferences getPreferences() const override; + + void noMatchingTestCases(std::string const& spec) override; + + void assertionStarting(AssertionInfo const&) override; + + bool assertionEnded(AssertionStats const& _assertionStats) override; + + void sectionEnded(SectionStats const& _sectionStats) override; + + void testRunEnded(TestRunStats const& _testRunStats) override; + + }; + +} // end namespace Catch + +// end catch_reporter_compact.h +// start catch_reporter_console.h + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch + // Note that 4062 (not all labels are handled + // and default is missing) is enabled +#endif + +namespace Catch { + // Fwd decls + struct SummaryColumn; + class TablePrinter; + + struct ConsoleReporter : StreamingReporterBase { + std::unique_ptr m_tablePrinter; + + ConsoleReporter(ReporterConfig const& config); + ~ConsoleReporter() override; + static std::string getDescription(); + + void noMatchingTestCases(std::string const& spec) override; + + void assertionStarting(AssertionInfo const&) override; + + bool assertionEnded(AssertionStats const& _assertionStats) override; + + void sectionStarting(SectionInfo const& _sectionInfo) override; + void sectionEnded(SectionStats const& _sectionStats) override; + + void benchmarkStarting(BenchmarkInfo const& info) override; + void benchmarkEnded(BenchmarkStats const& stats) override; + + void testCaseEnded(TestCaseStats const& _testCaseStats) override; + void testGroupEnded(TestGroupStats const& _testGroupStats) override; + void testRunEnded(TestRunStats const& _testRunStats) override; + + private: + + void lazyPrint(); + + void lazyPrintWithoutClosingBenchmarkTable(); + void lazyPrintRunInfo(); + void lazyPrintGroupInfo(); + void printTestCaseAndSectionHeader(); + + void printClosedHeader(std::string const& _name); + void printOpenHeader(std::string const& _name); + + // if string has a : in first line will set indent to follow it on + // subsequent lines + void printHeaderString(std::string const& _string, std::size_t indent = 0); + + void printTotals(Totals const& totals); + void printSummaryRow(std::string const& label, std::vector const& cols, std::size_t row); + + void printTotalsDivider(Totals const& totals); + void printSummaryDivider(); + + private: + bool m_headerPrinted = false; + }; + +} // end namespace Catch + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +// end catch_reporter_console.h +// start catch_reporter_junit.h + +// start catch_xmlwriter.h + +#include + +namespace Catch { + + class XmlEncode { + public: + enum ForWhat { ForTextNodes, ForAttributes }; + + XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes ); + + void encodeTo( std::ostream& os ) const; + + friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ); + + private: + std::string m_str; + ForWhat m_forWhat; + }; + + class XmlWriter { + public: + + class ScopedElement { + public: + ScopedElement( XmlWriter* writer ); + + ScopedElement( ScopedElement&& other ) noexcept; + ScopedElement& operator=( ScopedElement&& other ) noexcept; + + ~ScopedElement(); + + ScopedElement& writeText( std::string const& text, bool indent = true ); + + template + ScopedElement& writeAttribute( std::string const& name, T const& attribute ) { + m_writer->writeAttribute( name, attribute ); + return *this; + } + + private: + mutable XmlWriter* m_writer = nullptr; + }; + + XmlWriter( std::ostream& os = Catch::cout() ); + ~XmlWriter(); + + XmlWriter( XmlWriter const& ) = delete; + XmlWriter& operator=( XmlWriter const& ) = delete; + + XmlWriter& startElement( std::string const& name ); + + ScopedElement scopedElement( std::string const& name ); + + XmlWriter& endElement(); + + XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ); + + XmlWriter& writeAttribute( std::string const& name, bool attribute ); + + template + XmlWriter& writeAttribute( std::string const& name, T const& attribute ) { + ReusableStringStream rss; + rss << attribute; + return writeAttribute( name, rss.str() ); + } + + XmlWriter& writeText( std::string const& text, bool indent = true ); + + XmlWriter& writeComment( std::string const& text ); + + void writeStylesheetRef( std::string const& url ); + + XmlWriter& writeBlankLine(); + + void ensureTagClosed(); + + private: + + void writeDeclaration(); + + void newlineIfNecessary(); + + bool m_tagIsOpen = false; + bool m_needsNewline = false; + std::vector m_tags; + std::string m_indent; + std::ostream& m_os; + }; + +} + +// end catch_xmlwriter.h +namespace Catch { + + class JunitReporter : public CumulativeReporterBase { + public: + JunitReporter(ReporterConfig const& _config); + + ~JunitReporter() override; + + static std::string getDescription(); + + void noMatchingTestCases(std::string const& /*spec*/) override; + + void testRunStarting(TestRunInfo const& runInfo) override; + + void testGroupStarting(GroupInfo const& groupInfo) override; + + void testCaseStarting(TestCaseInfo const& testCaseInfo) override; + bool assertionEnded(AssertionStats const& assertionStats) override; + + void testCaseEnded(TestCaseStats const& testCaseStats) override; + + void testGroupEnded(TestGroupStats const& testGroupStats) override; + + void testRunEndedCumulative() override; + + void writeGroup(TestGroupNode const& groupNode, double suiteTime); + + void writeTestCase(TestCaseNode const& testCaseNode); + + void writeSection(std::string const& className, + std::string const& rootName, + SectionNode const& sectionNode); + + void writeAssertions(SectionNode const& sectionNode); + void writeAssertion(AssertionStats const& stats); + + XmlWriter xml; + Timer suiteTimer; + std::string stdOutForSuite; + std::string stdErrForSuite; + unsigned int unexpectedExceptions = 0; + bool m_okToFail = false; + }; + +} // end namespace Catch + +// end catch_reporter_junit.h +// start catch_reporter_xml.h + +namespace Catch { + class XmlReporter : public StreamingReporterBase { + public: + XmlReporter(ReporterConfig const& _config); + + ~XmlReporter() override; + + static std::string getDescription(); + + virtual std::string getStylesheetRef() const; + + void writeSourceInfo(SourceLineInfo const& sourceInfo); + + public: // StreamingReporterBase + + void noMatchingTestCases(std::string const& s) override; + + void testRunStarting(TestRunInfo const& testInfo) override; + + void testGroupStarting(GroupInfo const& groupInfo) override; + + void testCaseStarting(TestCaseInfo const& testInfo) override; + + void sectionStarting(SectionInfo const& sectionInfo) override; + + void assertionStarting(AssertionInfo const&) override; + + bool assertionEnded(AssertionStats const& assertionStats) override; + + void sectionEnded(SectionStats const& sectionStats) override; + + void testCaseEnded(TestCaseStats const& testCaseStats) override; + + void testGroupEnded(TestGroupStats const& testGroupStats) override; + + void testRunEnded(TestRunStats const& testRunStats) override; + + private: + Timer m_testCaseTimer; + XmlWriter m_xml; + int m_sectionDepth = 0; + }; + +} // end namespace Catch + +// end catch_reporter_xml.h + +// end catch_external_interfaces.h +#endif + +#endif // ! CATCH_CONFIG_IMPL_ONLY + +#ifdef CATCH_IMPL +// start catch_impl.hpp + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wweak-vtables" +#endif + +// Keep these here for external reporters +// start catch_test_case_tracker.h + +#include +#include +#include + +namespace Catch { +namespace TestCaseTracking { + + struct NameAndLocation { + std::string name; + SourceLineInfo location; + + NameAndLocation( std::string const& _name, SourceLineInfo const& _location ); + }; + + struct ITracker; + + using ITrackerPtr = std::shared_ptr; + + struct ITracker { + virtual ~ITracker(); + + // static queries + virtual NameAndLocation const& nameAndLocation() const = 0; + + // dynamic queries + virtual bool isComplete() const = 0; // Successfully completed or failed + virtual bool isSuccessfullyCompleted() const = 0; + virtual bool isOpen() const = 0; // Started but not complete + virtual bool hasChildren() const = 0; + + virtual ITracker& parent() = 0; + + // actions + virtual void close() = 0; // Successfully complete + virtual void fail() = 0; + virtual void markAsNeedingAnotherRun() = 0; + + virtual void addChild( ITrackerPtr const& child ) = 0; + virtual ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) = 0; + virtual void openChild() = 0; + + // Debug/ checking + virtual bool isSectionTracker() const = 0; + virtual bool isIndexTracker() const = 0; + }; + + class TrackerContext { + + enum RunState { + NotStarted, + Executing, + CompletedCycle + }; + + ITrackerPtr m_rootTracker; + ITracker* m_currentTracker = nullptr; + RunState m_runState = NotStarted; + + public: + + static TrackerContext& instance(); + + ITracker& startRun(); + void endRun(); + + void startCycle(); + void completeCycle(); + + bool completedCycle() const; + ITracker& currentTracker(); + void setCurrentTracker( ITracker* tracker ); + }; + + class TrackerBase : public ITracker { + protected: + enum CycleState { + NotStarted, + Executing, + ExecutingChildren, + NeedsAnotherRun, + CompletedSuccessfully, + Failed + }; + + class TrackerHasName { + NameAndLocation m_nameAndLocation; + public: + TrackerHasName( NameAndLocation const& nameAndLocation ); + bool operator ()( ITrackerPtr const& tracker ) const; + }; + + using Children = std::vector; + NameAndLocation m_nameAndLocation; + TrackerContext& m_ctx; + ITracker* m_parent; + Children m_children; + CycleState m_runState = NotStarted; + + public: + TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ); + + NameAndLocation const& nameAndLocation() const override; + bool isComplete() const override; + bool isSuccessfullyCompleted() const override; + bool isOpen() const override; + bool hasChildren() const override; + + void addChild( ITrackerPtr const& child ) override; + + ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) override; + ITracker& parent() override; + + void openChild() override; + + bool isSectionTracker() const override; + bool isIndexTracker() const override; + + void open(); + + void close() override; + void fail() override; + void markAsNeedingAnotherRun() override; + + private: + void moveToParent(); + void moveToThis(); + }; + + class SectionTracker : public TrackerBase { + std::vector m_filters; + public: + SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ); + + bool isSectionTracker() const override; + + static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ); + + void tryOpen(); + + void addInitialFilters( std::vector const& filters ); + void addNextFilters( std::vector const& filters ); + }; + + class IndexTracker : public TrackerBase { + int m_size; + int m_index = -1; + public: + IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size ); + + bool isIndexTracker() const override; + void close() override; + + static IndexTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size ); + + int index() const; + + void moveNext(); + }; + +} // namespace TestCaseTracking + +using TestCaseTracking::ITracker; +using TestCaseTracking::TrackerContext; +using TestCaseTracking::SectionTracker; +using TestCaseTracking::IndexTracker; + +} // namespace Catch + +// end catch_test_case_tracker.h + +// start catch_leak_detector.h + +namespace Catch { + + struct LeakDetector { + LeakDetector(); + }; + +} +// end catch_leak_detector.h +// Cpp files will be included in the single-header file here +// start catch_approx.cpp + +#include +#include + +namespace { + +// Performs equivalent check of std::fabs(lhs - rhs) <= margin +// But without the subtraction to allow for INFINITY in comparison +bool marginComparison(double lhs, double rhs, double margin) { + return (lhs + margin >= rhs) && (rhs + margin >= lhs); +} + +} + +namespace Catch { +namespace Detail { + + Approx::Approx ( double value ) + : m_epsilon( std::numeric_limits::epsilon()*100 ), + m_margin( 0.0 ), + m_scale( 0.0 ), + m_value( value ) + {} + + Approx Approx::custom() { + return Approx( 0 ); + } + + std::string Approx::toString() const { + ReusableStringStream rss; + rss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )"; + return rss.str(); + } + + bool Approx::equalityComparisonImpl(const double other) const { + // First try with fixed margin, then compute margin based on epsilon, scale and Approx's value + // Thanks to Richard Harris for his help refining the scaled margin value + return marginComparison(m_value, other, m_margin) || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(m_value))); + } + +} // end namespace Detail + +std::string StringMaker::convert(Catch::Detail::Approx const& value) { + return value.toString(); +} + +} // end namespace Catch +// end catch_approx.cpp +// start catch_assertionhandler.cpp + +// start catch_context.h + +#include + +namespace Catch { + + struct IResultCapture; + struct IRunner; + struct IConfig; + struct IMutableContext; + + using IConfigPtr = std::shared_ptr; + + struct IContext + { + virtual ~IContext(); + + virtual IResultCapture* getResultCapture() = 0; + virtual IRunner* getRunner() = 0; + virtual IConfigPtr const& getConfig() const = 0; + }; + + struct IMutableContext : IContext + { + virtual ~IMutableContext(); + virtual void setResultCapture( IResultCapture* resultCapture ) = 0; + virtual void setRunner( IRunner* runner ) = 0; + virtual void setConfig( IConfigPtr const& config ) = 0; + + private: + static IMutableContext *currentContext; + friend IMutableContext& getCurrentMutableContext(); + friend void cleanUpContext(); + static void createContext(); + }; + + inline IMutableContext& getCurrentMutableContext() + { + if( !IMutableContext::currentContext ) + IMutableContext::createContext(); + return *IMutableContext::currentContext; + } + + inline IContext& getCurrentContext() + { + return getCurrentMutableContext(); + } + + void cleanUpContext(); +} + +// end catch_context.h +// start catch_debugger.h + +namespace Catch { + bool isDebuggerActive(); +} + +#ifdef CATCH_PLATFORM_MAC + + #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */ + +#elif defined(CATCH_PLATFORM_LINUX) + // If we can use inline assembler, do it because this allows us to break + // directly at the location of the failing check instead of breaking inside + // raise() called from it, i.e. one stack frame below. + #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64)) + #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */ + #else // Fall back to the generic way. + #include + + #define CATCH_TRAP() raise(SIGTRAP) + #endif +#elif defined(_MSC_VER) + #define CATCH_TRAP() __debugbreak() +#elif defined(__MINGW32__) + extern "C" __declspec(dllimport) void __stdcall DebugBreak(); + #define CATCH_TRAP() DebugBreak() +#endif + +#ifdef CATCH_TRAP + #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } +#else + #define CATCH_BREAK_INTO_DEBUGGER() (void)0, 0 +#endif + +// end catch_debugger.h +// start catch_run_context.h + +// start catch_fatal_condition.h + +#include + +#if defined ( CATCH_PLATFORM_WINDOWS ) ///////////////////////////////////////// +// start catch_windows_h_proxy.h + + +#if defined(CATCH_PLATFORM_WINDOWS) + +#if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX) +# define CATCH_DEFINED_NOMINMAX +# define NOMINMAX +#endif +#if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN) +# define CATCH_DEFINED_WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif + +#ifdef __AFXDLL +#include +#else +#include +#endif + +#ifdef CATCH_DEFINED_NOMINMAX +# undef NOMINMAX +#endif +#ifdef CATCH_DEFINED_WIN32_LEAN_AND_MEAN +# undef WIN32_LEAN_AND_MEAN +#endif + +#endif // defined(CATCH_PLATFORM_WINDOWS) + +// end catch_windows_h_proxy.h + +# if !defined ( CATCH_CONFIG_WINDOWS_SEH ) + +namespace Catch { + struct FatalConditionHandler { + void reset(); + }; +} + +# else // CATCH_CONFIG_WINDOWS_SEH is defined + +namespace Catch { + + struct FatalConditionHandler { + + static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo); + FatalConditionHandler(); + static void reset(); + ~FatalConditionHandler(); + + private: + static bool isSet; + static ULONG guaranteeSize; + static PVOID exceptionHandlerHandle; + }; + +} // namespace Catch + +# endif // CATCH_CONFIG_WINDOWS_SEH + +#else // Not Windows - assumed to be POSIX compatible ////////////////////////// + +# if !defined(CATCH_CONFIG_POSIX_SIGNALS) + +namespace Catch { + struct FatalConditionHandler { + void reset(); + }; +} + +# else // CATCH_CONFIG_POSIX_SIGNALS is defined + +#include + +namespace Catch { + + struct FatalConditionHandler { + + static bool isSet; + static struct sigaction oldSigActions[];// [sizeof(signalDefs) / sizeof(SignalDefs)]; + static stack_t oldSigStack; + static char altStackMem[]; + + static void handleSignal( int sig ); + + FatalConditionHandler(); + ~FatalConditionHandler(); + static void reset(); + }; + +} // namespace Catch + +# endif // CATCH_CONFIG_POSIX_SIGNALS + +#endif // not Windows + +// end catch_fatal_condition.h +#include + +namespace Catch { + + struct IMutableContext; + + /////////////////////////////////////////////////////////////////////////// + + class RunContext : public IResultCapture, public IRunner { + + public: + RunContext( RunContext const& ) = delete; + RunContext& operator =( RunContext const& ) = delete; + + explicit RunContext( IConfigPtr const& _config, IStreamingReporterPtr&& reporter ); + + ~RunContext() override; + + void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ); + void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ); + + Totals runTest(TestCase const& testCase); + + IConfigPtr config() const; + IStreamingReporter& reporter() const; + + public: // IResultCapture + + // Assertion handlers + void handleExpr + ( AssertionInfo const& info, + ITransientExpression const& expr, + AssertionReaction& reaction ) override; + void handleMessage + ( AssertionInfo const& info, + ResultWas::OfType resultType, + StringRef const& message, + AssertionReaction& reaction ) override; + void handleUnexpectedExceptionNotThrown + ( AssertionInfo const& info, + AssertionReaction& reaction ) override; + void handleUnexpectedInflightException + ( AssertionInfo const& info, + std::string const& message, + AssertionReaction& reaction ) override; + void handleIncomplete + ( AssertionInfo const& info ) override; + void handleNonExpr + ( AssertionInfo const &info, + ResultWas::OfType resultType, + AssertionReaction &reaction ) override; + + bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override; + + void sectionEnded( SectionEndInfo const& endInfo ) override; + void sectionEndedEarly( SectionEndInfo const& endInfo ) override; + + void benchmarkStarting( BenchmarkInfo const& info ) override; + void benchmarkEnded( BenchmarkStats const& stats ) override; + + void pushScopedMessage( MessageInfo const& message ) override; + void popScopedMessage( MessageInfo const& message ) override; + + std::string getCurrentTestName() const override; + + const AssertionResult* getLastResult() const override; + + void exceptionEarlyReported() override; + + void handleFatalErrorCondition( StringRef message ) override; + + bool lastAssertionPassed() override; + + void assertionPassed() override; + + public: + // !TBD We need to do this another way! + bool aborting() const override; + + private: + + void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ); + void invokeActiveTestCase(); + + void resetAssertionInfo(); + bool testForMissingAssertions( Counts& assertions ); + + void assertionEnded( AssertionResult const& result ); + void reportExpr + ( AssertionInfo const &info, + ResultWas::OfType resultType, + ITransientExpression const *expr, + bool negated ); + + void populateReaction( AssertionReaction& reaction ); + + private: + + void handleUnfinishedSections(); + + TestRunInfo m_runInfo; + IMutableContext& m_context; + TestCase const* m_activeTestCase = nullptr; + ITracker* m_testCaseTracker; + Option m_lastResult; + + IConfigPtr m_config; + Totals m_totals; + IStreamingReporterPtr m_reporter; + std::vector m_messages; + AssertionInfo m_lastAssertionInfo; + std::vector m_unfinishedSections; + std::vector m_activeSections; + TrackerContext m_trackerContext; + bool m_lastAssertionPassed = false; + bool m_shouldReportUnexpected = true; + bool m_includeSuccessfulResults; + }; + +} // end namespace Catch + +// end catch_run_context.h +namespace Catch { + + auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& { + expr.streamReconstructedExpression( os ); + return os; + } + + LazyExpression::LazyExpression( bool isNegated ) + : m_isNegated( isNegated ) + {} + + LazyExpression::LazyExpression( LazyExpression const& other ) : m_isNegated( other.m_isNegated ) {} + + LazyExpression::operator bool() const { + return m_transientExpression != nullptr; + } + + auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream& { + if( lazyExpr.m_isNegated ) + os << "!"; + + if( lazyExpr ) { + if( lazyExpr.m_isNegated && lazyExpr.m_transientExpression->isBinaryExpression() ) + os << "(" << *lazyExpr.m_transientExpression << ")"; + else + os << *lazyExpr.m_transientExpression; + } + else { + os << "{** error - unchecked empty expression requested **}"; + } + return os; + } + + AssertionHandler::AssertionHandler + ( StringRef macroName, + SourceLineInfo const& lineInfo, + StringRef capturedExpression, + ResultDisposition::Flags resultDisposition ) + : m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition }, + m_resultCapture( getResultCapture() ) + {} + + void AssertionHandler::handleExpr( ITransientExpression const& expr ) { + m_resultCapture.handleExpr( m_assertionInfo, expr, m_reaction ); + } + void AssertionHandler::handleMessage(ResultWas::OfType resultType, StringRef const& message) { + m_resultCapture.handleMessage( m_assertionInfo, resultType, message, m_reaction ); + } + + auto AssertionHandler::allowThrows() const -> bool { + return getCurrentContext().getConfig()->allowThrows(); + } + + void AssertionHandler::complete() { + setCompleted(); + if( m_reaction.shouldDebugBreak ) { + + // If you find your debugger stopping you here then go one level up on the + // call-stack for the code that caused it (typically a failed assertion) + + // (To go back to the test and change execution, jump over the throw, next) + CATCH_BREAK_INTO_DEBUGGER(); + } + if( m_reaction.shouldThrow ) + throw Catch::TestFailureException(); + } + void AssertionHandler::setCompleted() { + m_completed = true; + } + + void AssertionHandler::handleUnexpectedInflightException() { + m_resultCapture.handleUnexpectedInflightException( m_assertionInfo, Catch::translateActiveException(), m_reaction ); + } + + void AssertionHandler::handleExceptionThrownAsExpected() { + m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); + } + void AssertionHandler::handleExceptionNotThrownAsExpected() { + m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); + } + + void AssertionHandler::handleUnexpectedExceptionNotThrown() { + m_resultCapture.handleUnexpectedExceptionNotThrown( m_assertionInfo, m_reaction ); + } + + void AssertionHandler::handleThrowingCallSkipped() { + m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); + } + + // This is the overload that takes a string and infers the Equals matcher from it + // The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp + void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ) { + handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString ); + } + +} // namespace Catch +// end catch_assertionhandler.cpp +// start catch_assertionresult.cpp + +namespace Catch { + AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression): + lazyExpression(_lazyExpression), + resultType(_resultType) {} + + std::string AssertionResultData::reconstructExpression() const { + + if( reconstructedExpression.empty() ) { + if( lazyExpression ) { + ReusableStringStream rss; + rss << lazyExpression; + reconstructedExpression = rss.str(); + } + } + return reconstructedExpression; + } + + AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) + : m_info( info ), + m_resultData( data ) + {} + + // Result was a success + bool AssertionResult::succeeded() const { + return Catch::isOk( m_resultData.resultType ); + } + + // Result was a success, or failure is suppressed + bool AssertionResult::isOk() const { + return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition ); + } + + ResultWas::OfType AssertionResult::getResultType() const { + return m_resultData.resultType; + } + + bool AssertionResult::hasExpression() const { + return m_info.capturedExpression[0] != 0; + } + + bool AssertionResult::hasMessage() const { + return !m_resultData.message.empty(); + } + + std::string AssertionResult::getExpression() const { + if( isFalseTest( m_info.resultDisposition ) ) + return "!(" + m_info.capturedExpression + ")"; + else + return m_info.capturedExpression; + } + + std::string AssertionResult::getExpressionInMacro() const { + std::string expr; + if( m_info.macroName[0] == 0 ) + expr = m_info.capturedExpression; + else { + expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 ); + expr += m_info.macroName.c_str(); + expr += "( "; + expr += m_info.capturedExpression.c_str(); + expr += " )"; + } + return expr; + } + + bool AssertionResult::hasExpandedExpression() const { + return hasExpression() && getExpandedExpression() != getExpression(); + } + + std::string AssertionResult::getExpandedExpression() const { + std::string expr = m_resultData.reconstructExpression(); + return expr.empty() + ? getExpression() + : expr; + } + + std::string AssertionResult::getMessage() const { + return m_resultData.message; + } + SourceLineInfo AssertionResult::getSourceInfo() const { + return m_info.lineInfo; + } + + StringRef AssertionResult::getTestMacroName() const { + return m_info.macroName; + } + +} // end namespace Catch +// end catch_assertionresult.cpp +// start catch_benchmark.cpp + +namespace Catch { + + auto BenchmarkLooper::getResolution() -> uint64_t { + return getEstimatedClockResolution() * getCurrentContext().getConfig()->benchmarkResolutionMultiple(); + } + + void BenchmarkLooper::reportStart() { + getResultCapture().benchmarkStarting( { m_name } ); + } + auto BenchmarkLooper::needsMoreIterations() -> bool { + auto elapsed = m_timer.getElapsedNanoseconds(); + + // Exponentially increasing iterations until we're confident in our timer resolution + if( elapsed < m_resolution ) { + m_iterationsToRun *= 10; + return true; + } + + getResultCapture().benchmarkEnded( { { m_name }, m_count, elapsed } ); + return false; + } + +} // end namespace Catch +// end catch_benchmark.cpp +// start catch_capture_matchers.cpp + +namespace Catch { + + using StringMatcher = Matchers::Impl::MatcherBase; + + // This is the general overload that takes a any string matcher + // There is another overload, in catch_assertinhandler.h/.cpp, that only takes a string and infers + // the Equals matcher (so the header does not mention matchers) + void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ) { + std::string exceptionMessage = Catch::translateActiveException(); + MatchExpr expr( exceptionMessage, matcher, matcherString ); + handler.handleExpr( expr ); + } + +} // namespace Catch +// end catch_capture_matchers.cpp +// start catch_commandline.cpp + +// start catch_commandline.h + +// start catch_clara.h + +// Use Catch's value for console width (store Clara's off to the side, if present) +#ifdef CLARA_CONFIG_CONSOLE_WIDTH +#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH +#undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH +#endif +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH-1 + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wweak-vtables" +#pragma clang diagnostic ignored "-Wexit-time-destructors" +#pragma clang diagnostic ignored "-Wshadow" +#endif + +// start clara.hpp +// Copyright 2017 Two Blue Cubes Ltd. All rights reserved. +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See https://github.com/philsquared/Clara for more details + +// Clara v1.1.1 + + +#ifndef CATCH_CLARA_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_CONFIG_CONSOLE_WIDTH 80 +#endif + +#ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CLARA_CONFIG_CONSOLE_WIDTH +#endif + +// ----------- #included from clara_textflow.hpp ----------- + +// TextFlowCpp +// +// A single-header library for wrapping and laying out basic text, by Phil Nash +// +// This work is licensed under the BSD 2-Clause license. +// See the accompanying LICENSE file, or the one at https://opensource.org/licenses/BSD-2-Clause +// +// This project is hosted at https://github.com/philsquared/textflowcpp + + +#include +#include +#include +#include + +#ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH 80 +#endif + +namespace Catch { namespace clara { namespace TextFlow { + + inline auto isWhitespace( char c ) -> bool { + static std::string chars = " \t\n\r"; + return chars.find( c ) != std::string::npos; + } + inline auto isBreakableBefore( char c ) -> bool { + static std::string chars = "[({<|"; + return chars.find( c ) != std::string::npos; + } + inline auto isBreakableAfter( char c ) -> bool { + static std::string chars = "])}>.,:;*+-=&/\\"; + return chars.find( c ) != std::string::npos; + } + + class Columns; + + class Column { + std::vector m_strings; + size_t m_width = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH; + size_t m_indent = 0; + size_t m_initialIndent = std::string::npos; + + public: + class iterator { + friend Column; + + Column const& m_column; + size_t m_stringIndex = 0; + size_t m_pos = 0; + + size_t m_len = 0; + size_t m_end = 0; + bool m_suffix = false; + + iterator( Column const& column, size_t stringIndex ) + : m_column( column ), + m_stringIndex( stringIndex ) + {} + + auto line() const -> std::string const& { return m_column.m_strings[m_stringIndex]; } + + auto isBoundary( size_t at ) const -> bool { + assert( at > 0 ); + assert( at <= line().size() ); + + return at == line().size() || + ( isWhitespace( line()[at] ) && !isWhitespace( line()[at-1] ) ) || + isBreakableBefore( line()[at] ) || + isBreakableAfter( line()[at-1] ); + } + + void calcLength() { + assert( m_stringIndex < m_column.m_strings.size() ); + + m_suffix = false; + auto width = m_column.m_width-indent(); + m_end = m_pos; + while( m_end < line().size() && line()[m_end] != '\n' ) + ++m_end; + + if( m_end < m_pos + width ) { + m_len = m_end - m_pos; + } + else { + size_t len = width; + while (len > 0 && !isBoundary(m_pos + len)) + --len; + while (len > 0 && isWhitespace( line()[m_pos + len - 1] )) + --len; + + if (len > 0) { + m_len = len; + } else { + m_suffix = true; + m_len = width - 1; + } + } + } + + auto indent() const -> size_t { + auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos; + return initial == std::string::npos ? m_column.m_indent : initial; + } + + auto addIndentAndSuffix(std::string const &plain) const -> std::string { + return std::string( indent(), ' ' ) + (m_suffix ? plain + "-" : plain); + } + + public: + explicit iterator( Column const& column ) : m_column( column ) { + assert( m_column.m_width > m_column.m_indent ); + assert( m_column.m_initialIndent == std::string::npos || m_column.m_width > m_column.m_initialIndent ); + calcLength(); + if( m_len == 0 ) + m_stringIndex++; // Empty string + } + + auto operator *() const -> std::string { + assert( m_stringIndex < m_column.m_strings.size() ); + assert( m_pos <= m_end ); + if( m_pos + m_column.m_width < m_end ) + return addIndentAndSuffix(line().substr(m_pos, m_len)); + else + return addIndentAndSuffix(line().substr(m_pos, m_end - m_pos)); + } + + auto operator ++() -> iterator& { + m_pos += m_len; + if( m_pos < line().size() && line()[m_pos] == '\n' ) + m_pos += 1; + else + while( m_pos < line().size() && isWhitespace( line()[m_pos] ) ) + ++m_pos; + + if( m_pos == line().size() ) { + m_pos = 0; + ++m_stringIndex; + } + if( m_stringIndex < m_column.m_strings.size() ) + calcLength(); + return *this; + } + auto operator ++(int) -> iterator { + iterator prev( *this ); + operator++(); + return prev; + } + + auto operator ==( iterator const& other ) const -> bool { + return + m_pos == other.m_pos && + m_stringIndex == other.m_stringIndex && + &m_column == &other.m_column; + } + auto operator !=( iterator const& other ) const -> bool { + return !operator==( other ); + } + }; + using const_iterator = iterator; + + explicit Column( std::string const& text ) { m_strings.push_back( text ); } + + auto width( size_t newWidth ) -> Column& { + assert( newWidth > 0 ); + m_width = newWidth; + return *this; + } + auto indent( size_t newIndent ) -> Column& { + m_indent = newIndent; + return *this; + } + auto initialIndent( size_t newIndent ) -> Column& { + m_initialIndent = newIndent; + return *this; + } + + auto width() const -> size_t { return m_width; } + auto begin() const -> iterator { return iterator( *this ); } + auto end() const -> iterator { return { *this, m_strings.size() }; } + + inline friend std::ostream& operator << ( std::ostream& os, Column const& col ) { + bool first = true; + for( auto line : col ) { + if( first ) + first = false; + else + os << "\n"; + os << line; + } + return os; + } + + auto operator + ( Column const& other ) -> Columns; + + auto toString() const -> std::string { + std::ostringstream oss; + oss << *this; + return oss.str(); + } + }; + + class Spacer : public Column { + + public: + explicit Spacer( size_t spaceWidth ) : Column( "" ) { + width( spaceWidth ); + } + }; + + class Columns { + std::vector m_columns; + + public: + + class iterator { + friend Columns; + struct EndTag {}; + + std::vector const& m_columns; + std::vector m_iterators; + size_t m_activeIterators; + + iterator( Columns const& columns, EndTag ) + : m_columns( columns.m_columns ), + m_activeIterators( 0 ) + { + m_iterators.reserve( m_columns.size() ); + + for( auto const& col : m_columns ) + m_iterators.push_back( col.end() ); + } + + public: + explicit iterator( Columns const& columns ) + : m_columns( columns.m_columns ), + m_activeIterators( m_columns.size() ) + { + m_iterators.reserve( m_columns.size() ); + + for( auto const& col : m_columns ) + m_iterators.push_back( col.begin() ); + } + + auto operator ==( iterator const& other ) const -> bool { + return m_iterators == other.m_iterators; + } + auto operator !=( iterator const& other ) const -> bool { + return m_iterators != other.m_iterators; + } + auto operator *() const -> std::string { + std::string row, padding; + + for( size_t i = 0; i < m_columns.size(); ++i ) { + auto width = m_columns[i].width(); + if( m_iterators[i] != m_columns[i].end() ) { + std::string col = *m_iterators[i]; + row += padding + col; + if( col.size() < width ) + padding = std::string( width - col.size(), ' ' ); + else + padding = ""; + } + else { + padding += std::string( width, ' ' ); + } + } + return row; + } + auto operator ++() -> iterator& { + for( size_t i = 0; i < m_columns.size(); ++i ) { + if (m_iterators[i] != m_columns[i].end()) + ++m_iterators[i]; + } + return *this; + } + auto operator ++(int) -> iterator { + iterator prev( *this ); + operator++(); + return prev; + } + }; + using const_iterator = iterator; + + auto begin() const -> iterator { return iterator( *this ); } + auto end() const -> iterator { return { *this, iterator::EndTag() }; } + + auto operator += ( Column const& col ) -> Columns& { + m_columns.push_back( col ); + return *this; + } + auto operator + ( Column const& col ) -> Columns { + Columns combined = *this; + combined += col; + return combined; + } + + inline friend std::ostream& operator << ( std::ostream& os, Columns const& cols ) { + + bool first = true; + for( auto line : cols ) { + if( first ) + first = false; + else + os << "\n"; + os << line; + } + return os; + } + + auto toString() const -> std::string { + std::ostringstream oss; + oss << *this; + return oss.str(); + } + }; + + inline auto Column::operator + ( Column const& other ) -> Columns { + Columns cols; + cols += *this; + cols += other; + return cols; + } +}}} // namespace Catch::clara::TextFlow + +// ----------- end of #include from clara_textflow.hpp ----------- +// ........... back in clara.hpp + +#include +#include +#include + +#if !defined(CATCH_PLATFORM_WINDOWS) && ( defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) ) +#define CATCH_PLATFORM_WINDOWS +#endif + +namespace Catch { namespace clara { +namespace detail { + + // Traits for extracting arg and return type of lambdas (for single argument lambdas) + template + struct UnaryLambdaTraits : UnaryLambdaTraits {}; + + template + struct UnaryLambdaTraits { + static const bool isValid = false; + }; + + template + struct UnaryLambdaTraits { + static const bool isValid = true; + using ArgType = typename std::remove_const::type>::type; + using ReturnType = ReturnT; + }; + + class TokenStream; + + // Transport for raw args (copied from main args, or supplied via init list for testing) + class Args { + friend TokenStream; + std::string m_exeName; + std::vector m_args; + + public: + Args( int argc, char *argv[] ) { + m_exeName = argv[0]; + for( int i = 1; i < argc; ++i ) + m_args.push_back( argv[i] ); + } + + Args( std::initializer_list args ) + : m_exeName( *args.begin() ), + m_args( args.begin()+1, args.end() ) + {} + + auto exeName() const -> std::string { + return m_exeName; + } + }; + + // Wraps a token coming from a token stream. These may not directly correspond to strings as a single string + // may encode an option + its argument if the : or = form is used + enum class TokenType { + Option, Argument + }; + struct Token { + TokenType type; + std::string token; + }; + + inline auto isOptPrefix( char c ) -> bool { + return c == '-' +#ifdef CATCH_PLATFORM_WINDOWS + || c == '/' +#endif + ; + } + + // Abstracts iterators into args as a stream of tokens, with option arguments uniformly handled + class TokenStream { + using Iterator = std::vector::const_iterator; + Iterator it; + Iterator itEnd; + std::vector m_tokenBuffer; + + void loadBuffer() { + m_tokenBuffer.resize( 0 ); + + // Skip any empty strings + while( it != itEnd && it->empty() ) + ++it; + + if( it != itEnd ) { + auto const &next = *it; + if( isOptPrefix( next[0] ) ) { + auto delimiterPos = next.find_first_of( " :=" ); + if( delimiterPos != std::string::npos ) { + m_tokenBuffer.push_back( { TokenType::Option, next.substr( 0, delimiterPos ) } ); + m_tokenBuffer.push_back( { TokenType::Argument, next.substr( delimiterPos + 1 ) } ); + } else { + if( next[1] != '-' && next.size() > 2 ) { + std::string opt = "- "; + for( size_t i = 1; i < next.size(); ++i ) { + opt[1] = next[i]; + m_tokenBuffer.push_back( { TokenType::Option, opt } ); + } + } else { + m_tokenBuffer.push_back( { TokenType::Option, next } ); + } + } + } else { + m_tokenBuffer.push_back( { TokenType::Argument, next } ); + } + } + } + + public: + explicit TokenStream( Args const &args ) : TokenStream( args.m_args.begin(), args.m_args.end() ) {} + + TokenStream( Iterator it, Iterator itEnd ) : it( it ), itEnd( itEnd ) { + loadBuffer(); + } + + explicit operator bool() const { + return !m_tokenBuffer.empty() || it != itEnd; + } + + auto count() const -> size_t { return m_tokenBuffer.size() + (itEnd - it); } + + auto operator*() const -> Token { + assert( !m_tokenBuffer.empty() ); + return m_tokenBuffer.front(); + } + + auto operator->() const -> Token const * { + assert( !m_tokenBuffer.empty() ); + return &m_tokenBuffer.front(); + } + + auto operator++() -> TokenStream & { + if( m_tokenBuffer.size() >= 2 ) { + m_tokenBuffer.erase( m_tokenBuffer.begin() ); + } else { + if( it != itEnd ) + ++it; + loadBuffer(); + } + return *this; + } + }; + + class ResultBase { + public: + enum Type { + Ok, LogicError, RuntimeError + }; + + protected: + ResultBase( Type type ) : m_type( type ) {} + virtual ~ResultBase() = default; + + virtual void enforceOk() const = 0; + + Type m_type; + }; + + template + class ResultValueBase : public ResultBase { + public: + auto value() const -> T const & { + enforceOk(); + return m_value; + } + + protected: + ResultValueBase( Type type ) : ResultBase( type ) {} + + ResultValueBase( ResultValueBase const &other ) : ResultBase( other ) { + if( m_type == ResultBase::Ok ) + new( &m_value ) T( other.m_value ); + } + + ResultValueBase( Type, T const &value ) : ResultBase( Ok ) { + new( &m_value ) T( value ); + } + + auto operator=( ResultValueBase const &other ) -> ResultValueBase & { + if( m_type == ResultBase::Ok ) + m_value.~T(); + ResultBase::operator=(other); + if( m_type == ResultBase::Ok ) + new( &m_value ) T( other.m_value ); + return *this; + } + + ~ResultValueBase() override { + if( m_type == Ok ) + m_value.~T(); + } + + union { + T m_value; + }; + }; + + template<> + class ResultValueBase : public ResultBase { + protected: + using ResultBase::ResultBase; + }; + + template + class BasicResult : public ResultValueBase { + public: + template + explicit BasicResult( BasicResult const &other ) + : ResultValueBase( other.type() ), + m_errorMessage( other.errorMessage() ) + { + assert( type() != ResultBase::Ok ); + } + + template + static auto ok( U const &value ) -> BasicResult { return { ResultBase::Ok, value }; } + static auto ok() -> BasicResult { return { ResultBase::Ok }; } + static auto logicError( std::string const &message ) -> BasicResult { return { ResultBase::LogicError, message }; } + static auto runtimeError( std::string const &message ) -> BasicResult { return { ResultBase::RuntimeError, message }; } + + explicit operator bool() const { return m_type == ResultBase::Ok; } + auto type() const -> ResultBase::Type { return m_type; } + auto errorMessage() const -> std::string { return m_errorMessage; } + + protected: + void enforceOk() const override { + // !TBD: If no exceptions, std::terminate here or something + switch( m_type ) { + case ResultBase::LogicError: + throw std::logic_error( m_errorMessage ); + case ResultBase::RuntimeError: + throw std::runtime_error( m_errorMessage ); + case ResultBase::Ok: + break; + } + } + + std::string m_errorMessage; // Only populated if resultType is an error + + BasicResult( ResultBase::Type type, std::string const &message ) + : ResultValueBase(type), + m_errorMessage(message) + { + assert( m_type != ResultBase::Ok ); + } + + using ResultValueBase::ResultValueBase; + using ResultBase::m_type; + }; + + enum class ParseResultType { + Matched, NoMatch, ShortCircuitAll, ShortCircuitSame + }; + + class ParseState { + public: + + ParseState( ParseResultType type, TokenStream const &remainingTokens ) + : m_type(type), + m_remainingTokens( remainingTokens ) + {} + + auto type() const -> ParseResultType { return m_type; } + auto remainingTokens() const -> TokenStream { return m_remainingTokens; } + + private: + ParseResultType m_type; + TokenStream m_remainingTokens; + }; + + using Result = BasicResult; + using ParserResult = BasicResult; + using InternalParseResult = BasicResult; + + struct HelpColumns { + std::string left; + std::string right; + }; + + template + inline auto convertInto( std::string const &source, T& target ) -> ParserResult { + std::stringstream ss; + ss << source; + ss >> target; + if( ss.fail() ) + return ParserResult::runtimeError( "Unable to convert '" + source + "' to destination type" ); + else + return ParserResult::ok( ParseResultType::Matched ); + } + inline auto convertInto( std::string const &source, std::string& target ) -> ParserResult { + target = source; + return ParserResult::ok( ParseResultType::Matched ); + } + inline auto convertInto( std::string const &source, bool &target ) -> ParserResult { + std::string srcLC = source; + std::transform( srcLC.begin(), srcLC.end(), srcLC.begin(), []( char c ) { return static_cast( ::tolower(c) ); } ); + if (srcLC == "y" || srcLC == "1" || srcLC == "true" || srcLC == "yes" || srcLC == "on") + target = true; + else if (srcLC == "n" || srcLC == "0" || srcLC == "false" || srcLC == "no" || srcLC == "off") + target = false; + else + return ParserResult::runtimeError( "Expected a boolean value but did not recognise: '" + source + "'" ); + return ParserResult::ok( ParseResultType::Matched ); + } + + struct NonCopyable { + NonCopyable() = default; + NonCopyable( NonCopyable const & ) = delete; + NonCopyable( NonCopyable && ) = delete; + NonCopyable &operator=( NonCopyable const & ) = delete; + NonCopyable &operator=( NonCopyable && ) = delete; + }; + + struct BoundRef : NonCopyable { + virtual ~BoundRef() = default; + virtual auto isContainer() const -> bool { return false; } + }; + struct BoundValueRefBase : BoundRef { + virtual auto setValue( std::string const &arg ) -> ParserResult = 0; + }; + struct BoundFlagRefBase : BoundRef { + virtual auto setFlag( bool flag ) -> ParserResult = 0; + }; + + template + struct BoundValueRef : BoundValueRefBase { + T &m_ref; + + explicit BoundValueRef( T &ref ) : m_ref( ref ) {} + + auto setValue( std::string const &arg ) -> ParserResult override { + return convertInto( arg, m_ref ); + } + }; + + template + struct BoundValueRef> : BoundValueRefBase { + std::vector &m_ref; + + explicit BoundValueRef( std::vector &ref ) : m_ref( ref ) {} + + auto isContainer() const -> bool override { return true; } + + auto setValue( std::string const &arg ) -> ParserResult override { + T temp; + auto result = convertInto( arg, temp ); + if( result ) + m_ref.push_back( temp ); + return result; + } + }; + + struct BoundFlagRef : BoundFlagRefBase { + bool &m_ref; + + explicit BoundFlagRef( bool &ref ) : m_ref( ref ) {} + + auto setFlag( bool flag ) -> ParserResult override { + m_ref = flag; + return ParserResult::ok( ParseResultType::Matched ); + } + }; + + template + struct LambdaInvoker { + static_assert( std::is_same::value, "Lambda must return void or clara::ParserResult" ); + + template + static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult { + return lambda( arg ); + } + }; + + template<> + struct LambdaInvoker { + template + static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult { + lambda( arg ); + return ParserResult::ok( ParseResultType::Matched ); + } + }; + + template + inline auto invokeLambda( L const &lambda, std::string const &arg ) -> ParserResult { + ArgType temp{}; + auto result = convertInto( arg, temp ); + return !result + ? result + : LambdaInvoker::ReturnType>::invoke( lambda, temp ); + } + + template + struct BoundLambda : BoundValueRefBase { + L m_lambda; + + static_assert( UnaryLambdaTraits::isValid, "Supplied lambda must take exactly one argument" ); + explicit BoundLambda( L const &lambda ) : m_lambda( lambda ) {} + + auto setValue( std::string const &arg ) -> ParserResult override { + return invokeLambda::ArgType>( m_lambda, arg ); + } + }; + + template + struct BoundFlagLambda : BoundFlagRefBase { + L m_lambda; + + static_assert( UnaryLambdaTraits::isValid, "Supplied lambda must take exactly one argument" ); + static_assert( std::is_same::ArgType, bool>::value, "flags must be boolean" ); + + explicit BoundFlagLambda( L const &lambda ) : m_lambda( lambda ) {} + + auto setFlag( bool flag ) -> ParserResult override { + return LambdaInvoker::ReturnType>::invoke( m_lambda, flag ); + } + }; + + enum class Optionality { Optional, Required }; + + struct Parser; + + class ParserBase { + public: + virtual ~ParserBase() = default; + virtual auto validate() const -> Result { return Result::ok(); } + virtual auto parse( std::string const& exeName, TokenStream const &tokens) const -> InternalParseResult = 0; + virtual auto cardinality() const -> size_t { return 1; } + + auto parse( Args const &args ) const -> InternalParseResult { + return parse( args.exeName(), TokenStream( args ) ); + } + }; + + template + class ComposableParserImpl : public ParserBase { + public: + template + auto operator|( T const &other ) const -> Parser; + + template + auto operator+( T const &other ) const -> Parser; + }; + + // Common code and state for Args and Opts + template + class ParserRefImpl : public ComposableParserImpl { + protected: + Optionality m_optionality = Optionality::Optional; + std::shared_ptr m_ref; + std::string m_hint; + std::string m_description; + + explicit ParserRefImpl( std::shared_ptr const &ref ) : m_ref( ref ) {} + + public: + template + ParserRefImpl( T &ref, std::string const &hint ) + : m_ref( std::make_shared>( ref ) ), + m_hint( hint ) + {} + + template + ParserRefImpl( LambdaT const &ref, std::string const &hint ) + : m_ref( std::make_shared>( ref ) ), + m_hint(hint) + {} + + auto operator()( std::string const &description ) -> DerivedT & { + m_description = description; + return static_cast( *this ); + } + + auto optional() -> DerivedT & { + m_optionality = Optionality::Optional; + return static_cast( *this ); + }; + + auto required() -> DerivedT & { + m_optionality = Optionality::Required; + return static_cast( *this ); + }; + + auto isOptional() const -> bool { + return m_optionality == Optionality::Optional; + } + + auto cardinality() const -> size_t override { + if( m_ref->isContainer() ) + return 0; + else + return 1; + } + + auto hint() const -> std::string { return m_hint; } + }; + + class ExeName : public ComposableParserImpl { + std::shared_ptr m_name; + std::shared_ptr m_ref; + + template + static auto makeRef(LambdaT const &lambda) -> std::shared_ptr { + return std::make_shared>( lambda) ; + } + + public: + ExeName() : m_name( std::make_shared( "" ) ) {} + + explicit ExeName( std::string &ref ) : ExeName() { + m_ref = std::make_shared>( ref ); + } + + template + explicit ExeName( LambdaT const& lambda ) : ExeName() { + m_ref = std::make_shared>( lambda ); + } + + // The exe name is not parsed out of the normal tokens, but is handled specially + auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { + return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) ); + } + + auto name() const -> std::string { return *m_name; } + auto set( std::string const& newName ) -> ParserResult { + + auto lastSlash = newName.find_last_of( "\\/" ); + auto filename = ( lastSlash == std::string::npos ) + ? newName + : newName.substr( lastSlash+1 ); + + *m_name = filename; + if( m_ref ) + return m_ref->setValue( filename ); + else + return ParserResult::ok( ParseResultType::Matched ); + } + }; + + class Arg : public ParserRefImpl { + public: + using ParserRefImpl::ParserRefImpl; + + auto parse( std::string const &, TokenStream const &tokens ) const -> InternalParseResult override { + auto validationResult = validate(); + if( !validationResult ) + return InternalParseResult( validationResult ); + + auto remainingTokens = tokens; + auto const &token = *remainingTokens; + if( token.type != TokenType::Argument ) + return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) ); + + assert( dynamic_cast( m_ref.get() ) ); + auto valueRef = static_cast( m_ref.get() ); + + auto result = valueRef->setValue( remainingTokens->token ); + if( !result ) + return InternalParseResult( result ); + else + return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) ); + } + }; + + inline auto normaliseOpt( std::string const &optName ) -> std::string { +#ifdef CATCH_PLATFORM_WINDOWS + if( optName[0] == '/' ) + return "-" + optName.substr( 1 ); + else +#endif + return optName; + } + + class Opt : public ParserRefImpl { + protected: + std::vector m_optNames; + + public: + template + explicit Opt( LambdaT const &ref ) : ParserRefImpl( std::make_shared>( ref ) ) {} + + explicit Opt( bool &ref ) : ParserRefImpl( std::make_shared( ref ) ) {} + + template + Opt( LambdaT const &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} + + template + Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} + + auto operator[]( std::string const &optName ) -> Opt & { + m_optNames.push_back( optName ); + return *this; + } + + auto getHelpColumns() const -> std::vector { + std::ostringstream oss; + bool first = true; + for( auto const &opt : m_optNames ) { + if (first) + first = false; + else + oss << ", "; + oss << opt; + } + if( !m_hint.empty() ) + oss << " <" << m_hint << ">"; + return { { oss.str(), m_description } }; + } + + auto isMatch( std::string const &optToken ) const -> bool { + auto normalisedToken = normaliseOpt( optToken ); + for( auto const &name : m_optNames ) { + if( normaliseOpt( name ) == normalisedToken ) + return true; + } + return false; + } + + using ParserBase::parse; + + auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { + auto validationResult = validate(); + if( !validationResult ) + return InternalParseResult( validationResult ); + + auto remainingTokens = tokens; + if( remainingTokens && remainingTokens->type == TokenType::Option ) { + auto const &token = *remainingTokens; + if( isMatch(token.token ) ) { + if( auto flagRef = dynamic_cast( m_ref.get() ) ) { + auto result = flagRef->setFlag( true ); + if( !result ) + return InternalParseResult( result ); + if( result.value() == ParseResultType::ShortCircuitAll ) + return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) ); + } else { + assert( dynamic_cast( m_ref.get() ) ); + auto valueRef = static_cast( m_ref.get() ); + ++remainingTokens; + if( !remainingTokens ) + return InternalParseResult::runtimeError( "Expected argument following " + token.token ); + auto const &argToken = *remainingTokens; + if( argToken.type != TokenType::Argument ) + return InternalParseResult::runtimeError( "Expected argument following " + token.token ); + auto result = valueRef->setValue( argToken.token ); + if( !result ) + return InternalParseResult( result ); + if( result.value() == ParseResultType::ShortCircuitAll ) + return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) ); + } + return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) ); + } + } + return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) ); + } + + auto validate() const -> Result override { + if( m_optNames.empty() ) + return Result::logicError( "No options supplied to Opt" ); + for( auto const &name : m_optNames ) { + if( name.empty() ) + return Result::logicError( "Option name cannot be empty" ); +#ifdef CATCH_PLATFORM_WINDOWS + if( name[0] != '-' && name[0] != '/' ) + return Result::logicError( "Option name must begin with '-' or '/'" ); +#else + if( name[0] != '-' ) + return Result::logicError( "Option name must begin with '-'" ); +#endif + } + return ParserRefImpl::validate(); + } + }; + + struct Help : Opt { + Help( bool &showHelpFlag ) + : Opt([&]( bool flag ) { + showHelpFlag = flag; + return ParserResult::ok( ParseResultType::ShortCircuitAll ); + }) + { + static_cast( *this ) + ("display usage information") + ["-?"]["-h"]["--help"] + .optional(); + } + }; + + struct Parser : ParserBase { + + mutable ExeName m_exeName; + std::vector m_options; + std::vector m_args; + + auto operator|=( ExeName const &exeName ) -> Parser & { + m_exeName = exeName; + return *this; + } + + auto operator|=( Arg const &arg ) -> Parser & { + m_args.push_back(arg); + return *this; + } + + auto operator|=( Opt const &opt ) -> Parser & { + m_options.push_back(opt); + return *this; + } + + auto operator|=( Parser const &other ) -> Parser & { + m_options.insert(m_options.end(), other.m_options.begin(), other.m_options.end()); + m_args.insert(m_args.end(), other.m_args.begin(), other.m_args.end()); + return *this; + } + + template + auto operator|( T const &other ) const -> Parser { + return Parser( *this ) |= other; + } + + // Forward deprecated interface with '+' instead of '|' + template + auto operator+=( T const &other ) -> Parser & { return operator|=( other ); } + template + auto operator+( T const &other ) const -> Parser { return operator|( other ); } + + auto getHelpColumns() const -> std::vector { + std::vector cols; + for (auto const &o : m_options) { + auto childCols = o.getHelpColumns(); + cols.insert( cols.end(), childCols.begin(), childCols.end() ); + } + return cols; + } + + void writeToStream( std::ostream &os ) const { + if (!m_exeName.name().empty()) { + os << "usage:\n" << " " << m_exeName.name() << " "; + bool required = true, first = true; + for( auto const &arg : m_args ) { + if (first) + first = false; + else + os << " "; + if( arg.isOptional() && required ) { + os << "["; + required = false; + } + os << "<" << arg.hint() << ">"; + if( arg.cardinality() == 0 ) + os << " ... "; + } + if( !required ) + os << "]"; + if( !m_options.empty() ) + os << " options"; + os << "\n\nwhere options are:" << std::endl; + } + + auto rows = getHelpColumns(); + size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; + size_t optWidth = 0; + for( auto const &cols : rows ) + optWidth = (std::max)(optWidth, cols.left.size() + 2); + + optWidth = (std::min)(optWidth, consoleWidth/2); + + for( auto const &cols : rows ) { + auto row = + TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) + + TextFlow::Spacer(4) + + TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth ); + os << row << std::endl; + } + } + + friend auto operator<<( std::ostream &os, Parser const &parser ) -> std::ostream& { + parser.writeToStream( os ); + return os; + } + + auto validate() const -> Result override { + for( auto const &opt : m_options ) { + auto result = opt.validate(); + if( !result ) + return result; + } + for( auto const &arg : m_args ) { + auto result = arg.validate(); + if( !result ) + return result; + } + return Result::ok(); + } + + using ParserBase::parse; + + auto parse( std::string const& exeName, TokenStream const &tokens ) const -> InternalParseResult override { + + struct ParserInfo { + ParserBase const* parser = nullptr; + size_t count = 0; + }; + const size_t totalParsers = m_options.size() + m_args.size(); + assert( totalParsers < 512 ); + // ParserInfo parseInfos[totalParsers]; // <-- this is what we really want to do + ParserInfo parseInfos[512]; + + { + size_t i = 0; + for (auto const &opt : m_options) parseInfos[i++].parser = &opt; + for (auto const &arg : m_args) parseInfos[i++].parser = &arg; + } + + m_exeName.set( exeName ); + + auto result = InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) ); + while( result.value().remainingTokens() ) { + bool tokenParsed = false; + + for( size_t i = 0; i < totalParsers; ++i ) { + auto& parseInfo = parseInfos[i]; + if( parseInfo.parser->cardinality() == 0 || parseInfo.count < parseInfo.parser->cardinality() ) { + result = parseInfo.parser->parse(exeName, result.value().remainingTokens()); + if (!result) + return result; + if (result.value().type() != ParseResultType::NoMatch) { + tokenParsed = true; + ++parseInfo.count; + break; + } + } + } + + if( result.value().type() == ParseResultType::ShortCircuitAll ) + return result; + if( !tokenParsed ) + return InternalParseResult::runtimeError( "Unrecognised token: " + result.value().remainingTokens()->token ); + } + // !TBD Check missing required options + return result; + } + }; + + template + template + auto ComposableParserImpl::operator|( T const &other ) const -> Parser { + return Parser() | static_cast( *this ) | other; + } +} // namespace detail + +// A Combined parser +using detail::Parser; + +// A parser for options +using detail::Opt; + +// A parser for arguments +using detail::Arg; + +// Wrapper for argc, argv from main() +using detail::Args; + +// Specifies the name of the executable +using detail::ExeName; + +// Convenience wrapper for option parser that specifies the help option +using detail::Help; + +// enum of result types from a parse +using detail::ParseResultType; + +// Result type for parser operation +using detail::ParserResult; + +}} // namespace Catch::clara + +// end clara.hpp +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// Restore Clara's value for console width, if present +#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH +#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH +#endif + +// end catch_clara.h +namespace Catch { + + clara::Parser makeCommandLineParser( ConfigData& config ); + +} // end namespace Catch + +// end catch_commandline.h +#include +#include + +namespace Catch { + + clara::Parser makeCommandLineParser( ConfigData& config ) { + + using namespace clara; + + auto const setWarning = [&]( std::string const& warning ) { + if( warning != "NoAssertions" ) + return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" ); + config.warnings = static_cast( config.warnings | WarnAbout::NoAssertions ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const loadTestNamesFromFile = [&]( std::string const& filename ) { + std::ifstream f( filename.c_str() ); + if( !f.is_open() ) + return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" ); + + std::string line; + while( std::getline( f, line ) ) { + line = trim(line); + if( !line.empty() && !startsWith( line, '#' ) ) { + if( !startsWith( line, '"' ) ) + line = '"' + line + '"'; + config.testsOrTags.push_back( line + ',' ); + } + } + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setTestOrder = [&]( std::string const& order ) { + if( startsWith( "declared", order ) ) + config.runOrder = RunTests::InDeclarationOrder; + else if( startsWith( "lexical", order ) ) + config.runOrder = RunTests::InLexicographicalOrder; + else if( startsWith( "random", order ) ) + config.runOrder = RunTests::InRandomOrder; + else + return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setRngSeed = [&]( std::string const& seed ) { + if( seed != "time" ) + return clara::detail::convertInto( seed, config.rngSeed ); + config.rngSeed = static_cast( std::time(nullptr) ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setColourUsage = [&]( std::string const& useColour ) { + auto mode = toLower( useColour ); + + if( mode == "yes" ) + config.useColour = UseColour::Yes; + else if( mode == "no" ) + config.useColour = UseColour::No; + else if( mode == "auto" ) + config.useColour = UseColour::Auto; + else + return ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setWaitForKeypress = [&]( std::string const& keypress ) { + auto keypressLc = toLower( keypress ); + if( keypressLc == "start" ) + config.waitForKeypress = WaitForKeypress::BeforeStart; + else if( keypressLc == "exit" ) + config.waitForKeypress = WaitForKeypress::BeforeExit; + else if( keypressLc == "both" ) + config.waitForKeypress = WaitForKeypress::BeforeStartAndExit; + else + return ParserResult::runtimeError( "keypress argument must be one of: start, exit or both. '" + keypress + "' not recognised" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + auto const setVerbosity = [&]( std::string const& verbosity ) { + auto lcVerbosity = toLower( verbosity ); + if( lcVerbosity == "quiet" ) + config.verbosity = Verbosity::Quiet; + else if( lcVerbosity == "normal" ) + config.verbosity = Verbosity::Normal; + else if( lcVerbosity == "high" ) + config.verbosity = Verbosity::High; + else + return ParserResult::runtimeError( "Unrecognised verbosity, '" + verbosity + "'" ); + return ParserResult::ok( ParseResultType::Matched ); + }; + + auto cli + = ExeName( config.processName ) + | Help( config.showHelp ) + | Opt( config.listTests ) + ["-l"]["--list-tests"] + ( "list all/matching test cases" ) + | Opt( config.listTags ) + ["-t"]["--list-tags"] + ( "list all/matching tags" ) + | Opt( config.showSuccessfulTests ) + ["-s"]["--success"] + ( "include successful tests in output" ) + | Opt( config.shouldDebugBreak ) + ["-b"]["--break"] + ( "break into debugger on failure" ) + | Opt( config.noThrow ) + ["-e"]["--nothrow"] + ( "skip exception tests" ) + | Opt( config.showInvisibles ) + ["-i"]["--invisibles"] + ( "show invisibles (tabs, newlines)" ) + | Opt( config.outputFilename, "filename" ) + ["-o"]["--out"] + ( "output filename" ) + | Opt( config.reporterNames, "name" ) + ["-r"]["--reporter"] + ( "reporter to use (defaults to console)" ) + | Opt( config.name, "name" ) + ["-n"]["--name"] + ( "suite name" ) + | Opt( [&]( bool ){ config.abortAfter = 1; } ) + ["-a"]["--abort"] + ( "abort at first failure" ) + | Opt( [&]( int x ){ config.abortAfter = x; }, "no. failures" ) + ["-x"]["--abortx"] + ( "abort after x failures" ) + | Opt( setWarning, "warning name" ) + ["-w"]["--warn"] + ( "enable warnings" ) + | Opt( [&]( bool flag ) { config.showDurations = flag ? ShowDurations::Always : ShowDurations::Never; }, "yes|no" ) + ["-d"]["--durations"] + ( "show test durations" ) + | Opt( loadTestNamesFromFile, "filename" ) + ["-f"]["--input-file"] + ( "load test names to run from a file" ) + | Opt( config.filenamesAsTags ) + ["-#"]["--filenames-as-tags"] + ( "adds a tag for the filename" ) + | Opt( config.sectionsToRun, "section name" ) + ["-c"]["--section"] + ( "specify section to run" ) + | Opt( setVerbosity, "quiet|normal|high" ) + ["-v"]["--verbosity"] + ( "set output verbosity" ) + | Opt( config.listTestNamesOnly ) + ["--list-test-names-only"] + ( "list all/matching test cases names only" ) + | Opt( config.listReporters ) + ["--list-reporters"] + ( "list all reporters" ) + | Opt( setTestOrder, "decl|lex|rand" ) + ["--order"] + ( "test case order (defaults to decl)" ) + | Opt( setRngSeed, "'time'|number" ) + ["--rng-seed"] + ( "set a specific seed for random numbers" ) + | Opt( setColourUsage, "yes|no" ) + ["--use-colour"] + ( "should output be colourised" ) + | Opt( config.libIdentify ) + ["--libidentify"] + ( "report name and version according to libidentify standard" ) + | Opt( setWaitForKeypress, "start|exit|both" ) + ["--wait-for-keypress"] + ( "waits for a keypress before exiting" ) + | Opt( config.benchmarkResolutionMultiple, "multiplier" ) + ["--benchmark-resolution-multiple"] + ( "multiple of clock resolution to run benchmarks" ) + + | Arg( config.testsOrTags, "test name|pattern|tags" ) + ( "which test or tests to use" ); + + return cli; + } + +} // end namespace Catch +// end catch_commandline.cpp +// start catch_common.cpp + +#include +#include + +namespace Catch { + + bool SourceLineInfo::empty() const noexcept { + return file[0] == '\0'; + } + bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const noexcept { + return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0); + } + bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const noexcept { + return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0)); + } + + std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { +#ifndef __GNUG__ + os << info.file << '(' << info.line << ')'; +#else + os << info.file << ':' << info.line; +#endif + return os; + } + + std::string StreamEndStop::operator+() const { + return std::string(); + } + + NonCopyable::NonCopyable() = default; + NonCopyable::~NonCopyable() = default; + +} +// end catch_common.cpp +// start catch_config.cpp + +// start catch_enforce.h + +#include +#include + +#define CATCH_PREPARE_EXCEPTION( type, msg ) \ + type( static_cast( Catch::ReusableStringStream().get() << msg ).str() ) +#define CATCH_INTERNAL_ERROR( msg ) \ + throw CATCH_PREPARE_EXCEPTION( std::logic_error, CATCH_INTERNAL_LINEINFO << ": Internal Catch error: " << msg); +#define CATCH_ERROR( msg ) \ + throw CATCH_PREPARE_EXCEPTION( std::domain_error, msg ) +#define CATCH_ENFORCE( condition, msg ) \ + do{ if( !(condition) ) CATCH_ERROR( msg ); } while(false) + +// end catch_enforce.h +namespace Catch { + + Config::Config( ConfigData const& data ) + : m_data( data ), + m_stream( openStream() ) + { + if( !data.testsOrTags.empty() ) { + TestSpecParser parser( ITagAliasRegistry::get() ); + for( auto const& testOrTags : data.testsOrTags ) + parser.parse( testOrTags ); + m_testSpec = parser.testSpec(); + } + } + + std::string const& Config::getFilename() const { + return m_data.outputFilename ; + } + + bool Config::listTests() const { return m_data.listTests; } + bool Config::listTestNamesOnly() const { return m_data.listTestNamesOnly; } + bool Config::listTags() const { return m_data.listTags; } + bool Config::listReporters() const { return m_data.listReporters; } + + std::string Config::getProcessName() const { return m_data.processName; } + + std::vector const& Config::getReporterNames() const { return m_data.reporterNames; } + std::vector const& Config::getSectionsToRun() const { return m_data.sectionsToRun; } + + TestSpec const& Config::testSpec() const { return m_testSpec; } + + bool Config::showHelp() const { return m_data.showHelp; } + + // IConfig interface + bool Config::allowThrows() const { return !m_data.noThrow; } + std::ostream& Config::stream() const { return m_stream->stream(); } + std::string Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; } + bool Config::includeSuccessfulResults() const { return m_data.showSuccessfulTests; } + bool Config::warnAboutMissingAssertions() const { return m_data.warnings & WarnAbout::NoAssertions; } + ShowDurations::OrNot Config::showDurations() const { return m_data.showDurations; } + RunTests::InWhatOrder Config::runOrder() const { return m_data.runOrder; } + unsigned int Config::rngSeed() const { return m_data.rngSeed; } + int Config::benchmarkResolutionMultiple() const { return m_data.benchmarkResolutionMultiple; } + UseColour::YesOrNo Config::useColour() const { return m_data.useColour; } + bool Config::shouldDebugBreak() const { return m_data.shouldDebugBreak; } + int Config::abortAfter() const { return m_data.abortAfter; } + bool Config::showInvisibles() const { return m_data.showInvisibles; } + Verbosity Config::verbosity() const { return m_data.verbosity; } + + IStream const* Config::openStream() { + return Catch::makeStream(m_data.outputFilename); + } + +} // end namespace Catch +// end catch_config.cpp +// start catch_console_colour.cpp + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +#endif + +// start catch_errno_guard.h + +namespace Catch { + + class ErrnoGuard { + public: + ErrnoGuard(); + ~ErrnoGuard(); + private: + int m_oldErrno; + }; + +} + +// end catch_errno_guard.h +#include + +namespace Catch { + namespace { + + struct IColourImpl { + virtual ~IColourImpl() = default; + virtual void use( Colour::Code _colourCode ) = 0; + }; + + struct NoColourImpl : IColourImpl { + void use( Colour::Code ) {} + + static IColourImpl* instance() { + static NoColourImpl s_instance; + return &s_instance; + } + }; + + } // anon namespace +} // namespace Catch + +#if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI ) +# ifdef CATCH_PLATFORM_WINDOWS +# define CATCH_CONFIG_COLOUR_WINDOWS +# else +# define CATCH_CONFIG_COLOUR_ANSI +# endif +#endif + +#if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) ///////////////////////////////////////// + +namespace Catch { +namespace { + + class Win32ColourImpl : public IColourImpl { + public: + Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) ) + { + CONSOLE_SCREEN_BUFFER_INFO csbiInfo; + GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo ); + originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY ); + originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY ); + } + + virtual void use( Colour::Code _colourCode ) override { + switch( _colourCode ) { + case Colour::None: return setTextAttribute( originalForegroundAttributes ); + case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); + case Colour::Red: return setTextAttribute( FOREGROUND_RED ); + case Colour::Green: return setTextAttribute( FOREGROUND_GREEN ); + case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE ); + case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN ); + case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN ); + case Colour::Grey: return setTextAttribute( 0 ); + + case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY ); + case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED ); + case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN ); + case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); + + case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" ); + } + } + + private: + void setTextAttribute( WORD _textAttribute ) { + SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes ); + } + HANDLE stdoutHandle; + WORD originalForegroundAttributes; + WORD originalBackgroundAttributes; + }; + + IColourImpl* platformColourInstance() { + static Win32ColourImpl s_instance; + + IConfigPtr config = getCurrentContext().getConfig(); + UseColour::YesOrNo colourMode = config + ? config->useColour() + : UseColour::Auto; + if( colourMode == UseColour::Auto ) + colourMode = UseColour::Yes; + return colourMode == UseColour::Yes + ? &s_instance + : NoColourImpl::instance(); + } + +} // end anon namespace +} // end namespace Catch + +#elif defined( CATCH_CONFIG_COLOUR_ANSI ) ////////////////////////////////////// + +#include + +namespace Catch { +namespace { + + // use POSIX/ ANSI console terminal codes + // Thanks to Adam Strzelecki for original contribution + // (http://github.com/nanoant) + // https://github.com/philsquared/Catch/pull/131 + class PosixColourImpl : public IColourImpl { + public: + virtual void use( Colour::Code _colourCode ) override { + switch( _colourCode ) { + case Colour::None: + case Colour::White: return setColour( "[0m" ); + case Colour::Red: return setColour( "[0;31m" ); + case Colour::Green: return setColour( "[0;32m" ); + case Colour::Blue: return setColour( "[0;34m" ); + case Colour::Cyan: return setColour( "[0;36m" ); + case Colour::Yellow: return setColour( "[0;33m" ); + case Colour::Grey: return setColour( "[1;30m" ); + + case Colour::LightGrey: return setColour( "[0;37m" ); + case Colour::BrightRed: return setColour( "[1;31m" ); + case Colour::BrightGreen: return setColour( "[1;32m" ); + case Colour::BrightWhite: return setColour( "[1;37m" ); + + case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" ); + } + } + static IColourImpl* instance() { + static PosixColourImpl s_instance; + return &s_instance; + } + + private: + void setColour( const char* _escapeCode ) { + Catch::cout() << '\033' << _escapeCode; + } + }; + + bool useColourOnPlatform() { + return +#ifdef CATCH_PLATFORM_MAC + !isDebuggerActive() && +#endif + isatty(STDOUT_FILENO); + } + IColourImpl* platformColourInstance() { + ErrnoGuard guard; + IConfigPtr config = getCurrentContext().getConfig(); + UseColour::YesOrNo colourMode = config + ? config->useColour() + : UseColour::Auto; + if( colourMode == UseColour::Auto ) + colourMode = useColourOnPlatform() + ? UseColour::Yes + : UseColour::No; + return colourMode == UseColour::Yes + ? PosixColourImpl::instance() + : NoColourImpl::instance(); + } + +} // end anon namespace +} // end namespace Catch + +#else // not Windows or ANSI /////////////////////////////////////////////// + +namespace Catch { + + static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); } + +} // end namespace Catch + +#endif // Windows/ ANSI/ None + +namespace Catch { + + Colour::Colour( Code _colourCode ) { use( _colourCode ); } + Colour::Colour( Colour&& rhs ) noexcept { + m_moved = rhs.m_moved; + rhs.m_moved = true; + } + Colour& Colour::operator=( Colour&& rhs ) noexcept { + m_moved = rhs.m_moved; + rhs.m_moved = true; + return *this; + } + + Colour::~Colour(){ if( !m_moved ) use( None ); } + + void Colour::use( Code _colourCode ) { + static IColourImpl* impl = platformColourInstance(); + impl->use( _colourCode ); + } + + std::ostream& operator << ( std::ostream& os, Colour const& ) { + return os; + } + +} // end namespace Catch + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + +// end catch_console_colour.cpp +// start catch_context.cpp + +namespace Catch { + + class Context : public IMutableContext, NonCopyable { + + public: // IContext + virtual IResultCapture* getResultCapture() override { + return m_resultCapture; + } + virtual IRunner* getRunner() override { + return m_runner; + } + + virtual IConfigPtr const& getConfig() const override { + return m_config; + } + + virtual ~Context() override; + + public: // IMutableContext + virtual void setResultCapture( IResultCapture* resultCapture ) override { + m_resultCapture = resultCapture; + } + virtual void setRunner( IRunner* runner ) override { + m_runner = runner; + } + virtual void setConfig( IConfigPtr const& config ) override { + m_config = config; + } + + friend IMutableContext& getCurrentMutableContext(); + + private: + IConfigPtr m_config; + IRunner* m_runner = nullptr; + IResultCapture* m_resultCapture = nullptr; + }; + + IMutableContext *IMutableContext::currentContext = nullptr; + + void IMutableContext::createContext() + { + currentContext = new Context(); + } + + void cleanUpContext() { + delete IMutableContext::currentContext; + IMutableContext::currentContext = nullptr; + } + IContext::~IContext() = default; + IMutableContext::~IMutableContext() = default; + Context::~Context() = default; +} +// end catch_context.cpp +// start catch_debug_console.cpp + +// start catch_debug_console.h + +#include + +namespace Catch { + void writeToDebugConsole( std::string const& text ); +} + +// end catch_debug_console.h +#ifdef CATCH_PLATFORM_WINDOWS + + namespace Catch { + void writeToDebugConsole( std::string const& text ) { + ::OutputDebugStringA( text.c_str() ); + } + } +#else + namespace Catch { + void writeToDebugConsole( std::string const& text ) { + // !TBD: Need a version for Mac/ XCode and other IDEs + Catch::cout() << text; + } + } +#endif // Platform +// end catch_debug_console.cpp +// start catch_debugger.cpp + +#ifdef CATCH_PLATFORM_MAC + +# include +# include +# include +# include +# include +# include +# include + +namespace Catch { + + // The following function is taken directly from the following technical note: + // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html + + // Returns true if the current process is being debugged (either + // running under the debugger or has a debugger attached post facto). + bool isDebuggerActive(){ + + int mib[4]; + struct kinfo_proc info; + std::size_t size; + + // Initialize the flags so that, if sysctl fails for some bizarre + // reason, we get a predictable result. + + info.kp_proc.p_flag = 0; + + // Initialize mib, which tells sysctl the info we want, in this case + // we're looking for information about a specific process ID. + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PID; + mib[3] = getpid(); + + // Call sysctl. + + size = sizeof(info); + if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, nullptr, 0) != 0 ) { + Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl; + return false; + } + + // We're being debugged if the P_TRACED flag is set. + + return ( (info.kp_proc.p_flag & P_TRACED) != 0 ); + } + } // namespace Catch + +#elif defined(CATCH_PLATFORM_LINUX) + #include + #include + + namespace Catch{ + // The standard POSIX way of detecting a debugger is to attempt to + // ptrace() the process, but this needs to be done from a child and not + // this process itself to still allow attaching to this process later + // if wanted, so is rather heavy. Under Linux we have the PID of the + // "debugger" (which doesn't need to be gdb, of course, it could also + // be strace, for example) in /proc/$PID/status, so just get it from + // there instead. + bool isDebuggerActive(){ + // Libstdc++ has a bug, where std::ifstream sets errno to 0 + // This way our users can properly assert over errno values + ErrnoGuard guard; + std::ifstream in("/proc/self/status"); + for( std::string line; std::getline(in, line); ) { + static const int PREFIX_LEN = 11; + if( line.compare(0, PREFIX_LEN, "TracerPid:\t") == 0 ) { + // We're traced if the PID is not 0 and no other PID starts + // with 0 digit, so it's enough to check for just a single + // character. + return line.length() > PREFIX_LEN && line[PREFIX_LEN] != '0'; + } + } + + return false; + } + } // namespace Catch +#elif defined(_MSC_VER) + extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); + namespace Catch { + bool isDebuggerActive() { + return IsDebuggerPresent() != 0; + } + } +#elif defined(__MINGW32__) + extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); + namespace Catch { + bool isDebuggerActive() { + return IsDebuggerPresent() != 0; + } + } +#else + namespace Catch { + bool isDebuggerActive() { return false; } + } +#endif // Platform +// end catch_debugger.cpp +// start catch_decomposer.cpp + +namespace Catch { + + ITransientExpression::~ITransientExpression() = default; + + void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ) { + if( lhs.size() + rhs.size() < 40 && + lhs.find('\n') == std::string::npos && + rhs.find('\n') == std::string::npos ) + os << lhs << " " << op << " " << rhs; + else + os << lhs << "\n" << op << "\n" << rhs; + } +} +// end catch_decomposer.cpp +// start catch_errno_guard.cpp + +#include + +namespace Catch { + ErrnoGuard::ErrnoGuard():m_oldErrno(errno){} + ErrnoGuard::~ErrnoGuard() { errno = m_oldErrno; } +} +// end catch_errno_guard.cpp +// start catch_exception_translator_registry.cpp + +// start catch_exception_translator_registry.h + +#include +#include +#include + +namespace Catch { + + class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { + public: + ~ExceptionTranslatorRegistry(); + virtual void registerTranslator( const IExceptionTranslator* translator ); + virtual std::string translateActiveException() const override; + std::string tryTranslators() const; + + private: + std::vector> m_translators; + }; +} + +// end catch_exception_translator_registry.h +#ifdef __OBJC__ +#import "Foundation/Foundation.h" +#endif + +namespace Catch { + + ExceptionTranslatorRegistry::~ExceptionTranslatorRegistry() { + } + + void ExceptionTranslatorRegistry::registerTranslator( const IExceptionTranslator* translator ) { + m_translators.push_back( std::unique_ptr( translator ) ); + } + + std::string ExceptionTranslatorRegistry::translateActiveException() const { + try { +#ifdef __OBJC__ + // In Objective-C try objective-c exceptions first + @try { + return tryTranslators(); + } + @catch (NSException *exception) { + return Catch::Detail::stringify( [exception description] ); + } +#else + // Compiling a mixed mode project with MSVC means that CLR + // exceptions will be caught in (...) as well. However, these + // do not fill-in std::current_exception and thus lead to crash + // when attempting rethrow. + // /EHa switch also causes structured exceptions to be caught + // here, but they fill-in current_exception properly, so + // at worst the output should be a little weird, instead of + // causing a crash. + if (std::current_exception() == nullptr) { + return "Non C++ exception. Possibly a CLR exception."; + } + return tryTranslators(); +#endif + } + catch( TestFailureException& ) { + std::rethrow_exception(std::current_exception()); + } + catch( std::exception& ex ) { + return ex.what(); + } + catch( std::string& msg ) { + return msg; + } + catch( const char* msg ) { + return msg; + } + catch(...) { + return "Unknown exception"; + } + } + + std::string ExceptionTranslatorRegistry::tryTranslators() const { + if( m_translators.empty() ) + std::rethrow_exception(std::current_exception()); + else + return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() ); + } +} +// end catch_exception_translator_registry.cpp +// start catch_fatal_condition.cpp + +#if defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif + +namespace { + // Report the error condition + void reportFatal( char const * const message ) { + Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( message ); + } +} + +#if defined ( CATCH_PLATFORM_WINDOWS ) ///////////////////////////////////////// + +# if !defined ( CATCH_CONFIG_WINDOWS_SEH ) + +namespace Catch { + void FatalConditionHandler::reset() {} +} + +# else // CATCH_CONFIG_WINDOWS_SEH is defined + +namespace Catch { + struct SignalDefs { DWORD id; const char* name; }; + + // There is no 1-1 mapping between signals and windows exceptions. + // Windows can easily distinguish between SO and SigSegV, + // but SigInt, SigTerm, etc are handled differently. + static SignalDefs signalDefs[] = { + { EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal" }, + { EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow" }, + { EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal" }, + { EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error" }, + }; + + LONG CALLBACK FatalConditionHandler::handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) { + for (auto const& def : signalDefs) { + if (ExceptionInfo->ExceptionRecord->ExceptionCode == def.id) { + reportFatal(def.name); + } + } + // If its not an exception we care about, pass it along. + // This stops us from eating debugger breaks etc. + return EXCEPTION_CONTINUE_SEARCH; + } + + FatalConditionHandler::FatalConditionHandler() { + isSet = true; + // 32k seems enough for Catch to handle stack overflow, + // but the value was found experimentally, so there is no strong guarantee + guaranteeSize = 32 * 1024; + exceptionHandlerHandle = nullptr; + // Register as first handler in current chain + exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException); + // Pass in guarantee size to be filled + SetThreadStackGuarantee(&guaranteeSize); + } + + void FatalConditionHandler::reset() { + if (isSet) { + // Unregister handler and restore the old guarantee + RemoveVectoredExceptionHandler(exceptionHandlerHandle); + SetThreadStackGuarantee(&guaranteeSize); + exceptionHandlerHandle = nullptr; + isSet = false; + } + } + + FatalConditionHandler::~FatalConditionHandler() { + reset(); + } + +bool FatalConditionHandler::isSet = false; +ULONG FatalConditionHandler::guaranteeSize = 0; +PVOID FatalConditionHandler::exceptionHandlerHandle = nullptr; + +} // namespace Catch + +# endif // CATCH_CONFIG_WINDOWS_SEH + +#else // Not Windows - assumed to be POSIX compatible ////////////////////////// + +# if !defined(CATCH_CONFIG_POSIX_SIGNALS) + +namespace Catch { + void FatalConditionHandler::reset() {} +} + +# else // CATCH_CONFIG_POSIX_SIGNALS is defined + +#include + +namespace Catch { + + struct SignalDefs { + int id; + const char* name; + }; + static SignalDefs signalDefs[] = { + { SIGINT, "SIGINT - Terminal interrupt signal" }, + { SIGILL, "SIGILL - Illegal instruction signal" }, + { SIGFPE, "SIGFPE - Floating point error signal" }, + { SIGSEGV, "SIGSEGV - Segmentation violation signal" }, + { SIGTERM, "SIGTERM - Termination request signal" }, + { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" } + }; + + void FatalConditionHandler::handleSignal( int sig ) { + char const * name = ""; + for (auto const& def : signalDefs) { + if (sig == def.id) { + name = def.name; + break; + } + } + reset(); + reportFatal(name); + raise( sig ); + } + + FatalConditionHandler::FatalConditionHandler() { + isSet = true; + stack_t sigStack; + sigStack.ss_sp = altStackMem; + sigStack.ss_size = SIGSTKSZ; + sigStack.ss_flags = 0; + sigaltstack(&sigStack, &oldSigStack); + struct sigaction sa = { }; + + sa.sa_handler = handleSignal; + sa.sa_flags = SA_ONSTACK; + for (std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i) { + sigaction(signalDefs[i].id, &sa, &oldSigActions[i]); + } + } + + FatalConditionHandler::~FatalConditionHandler() { + reset(); + } + + void FatalConditionHandler::reset() { + if( isSet ) { + // Set signals back to previous values -- hopefully nobody overwrote them in the meantime + for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) { + sigaction(signalDefs[i].id, &oldSigActions[i], nullptr); + } + // Return the old stack + sigaltstack(&oldSigStack, nullptr); + isSet = false; + } + } + + bool FatalConditionHandler::isSet = false; + struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {}; + stack_t FatalConditionHandler::oldSigStack = {}; + char FatalConditionHandler::altStackMem[SIGSTKSZ] = {}; + +} // namespace Catch + +# endif // CATCH_CONFIG_POSIX_SIGNALS + +#endif // not Windows + +#if defined(__GNUC__) +# pragma GCC diagnostic pop +#endif +// end catch_fatal_condition.cpp +// start catch_interfaces_capture.cpp + +namespace Catch { + IResultCapture::~IResultCapture() = default; +} +// end catch_interfaces_capture.cpp +// start catch_interfaces_config.cpp + +namespace Catch { + IConfig::~IConfig() = default; +} +// end catch_interfaces_config.cpp +// start catch_interfaces_exception.cpp + +namespace Catch { + IExceptionTranslator::~IExceptionTranslator() = default; + IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() = default; +} +// end catch_interfaces_exception.cpp +// start catch_interfaces_registry_hub.cpp + +namespace Catch { + IRegistryHub::~IRegistryHub() = default; + IMutableRegistryHub::~IMutableRegistryHub() = default; +} +// end catch_interfaces_registry_hub.cpp +// start catch_interfaces_reporter.cpp + +// start catch_reporter_multi.h + +namespace Catch { + + class MultipleReporters : public IStreamingReporter { + using Reporters = std::vector; + Reporters m_reporters; + + public: + void add( IStreamingReporterPtr&& reporter ); + + public: // IStreamingReporter + + ReporterPreferences getPreferences() const override; + + void noMatchingTestCases( std::string const& spec ) override; + + static std::set getSupportedVerbosities(); + + void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override; + void benchmarkEnded( BenchmarkStats const& benchmarkStats ) override; + + void testRunStarting( TestRunInfo const& testRunInfo ) override; + void testGroupStarting( GroupInfo const& groupInfo ) override; + void testCaseStarting( TestCaseInfo const& testInfo ) override; + void sectionStarting( SectionInfo const& sectionInfo ) override; + void assertionStarting( AssertionInfo const& assertionInfo ) override; + + // The return value indicates if the messages buffer should be cleared: + bool assertionEnded( AssertionStats const& assertionStats ) override; + void sectionEnded( SectionStats const& sectionStats ) override; + void testCaseEnded( TestCaseStats const& testCaseStats ) override; + void testGroupEnded( TestGroupStats const& testGroupStats ) override; + void testRunEnded( TestRunStats const& testRunStats ) override; + + void skipTest( TestCaseInfo const& testInfo ) override; + bool isMulti() const override; + + }; + +} // end namespace Catch + +// end catch_reporter_multi.h +namespace Catch { + + ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig ) + : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {} + + ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream ) + : m_stream( &_stream ), m_fullConfig( _fullConfig ) {} + + std::ostream& ReporterConfig::stream() const { return *m_stream; } + IConfigPtr ReporterConfig::fullConfig() const { return m_fullConfig; } + + TestRunInfo::TestRunInfo( std::string const& _name ) : name( _name ) {} + + GroupInfo::GroupInfo( std::string const& _name, + std::size_t _groupIndex, + std::size_t _groupsCount ) + : name( _name ), + groupIndex( _groupIndex ), + groupsCounts( _groupsCount ) + {} + + AssertionStats::AssertionStats( AssertionResult const& _assertionResult, + std::vector const& _infoMessages, + Totals const& _totals ) + : assertionResult( _assertionResult ), + infoMessages( _infoMessages ), + totals( _totals ) + { + assertionResult.m_resultData.lazyExpression.m_transientExpression = _assertionResult.m_resultData.lazyExpression.m_transientExpression; + + if( assertionResult.hasMessage() ) { + // Copy message into messages list. + // !TBD This should have been done earlier, somewhere + MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() ); + builder << assertionResult.getMessage(); + builder.m_info.message = builder.m_stream.str(); + + infoMessages.push_back( builder.m_info ); + } + } + + AssertionStats::~AssertionStats() = default; + + SectionStats::SectionStats( SectionInfo const& _sectionInfo, + Counts const& _assertions, + double _durationInSeconds, + bool _missingAssertions ) + : sectionInfo( _sectionInfo ), + assertions( _assertions ), + durationInSeconds( _durationInSeconds ), + missingAssertions( _missingAssertions ) + {} + + SectionStats::~SectionStats() = default; + + TestCaseStats::TestCaseStats( TestCaseInfo const& _testInfo, + Totals const& _totals, + std::string const& _stdOut, + std::string const& _stdErr, + bool _aborting ) + : testInfo( _testInfo ), + totals( _totals ), + stdOut( _stdOut ), + stdErr( _stdErr ), + aborting( _aborting ) + {} + + TestCaseStats::~TestCaseStats() = default; + + TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo, + Totals const& _totals, + bool _aborting ) + : groupInfo( _groupInfo ), + totals( _totals ), + aborting( _aborting ) + {} + + TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo ) + : groupInfo( _groupInfo ), + aborting( false ) + {} + + TestGroupStats::~TestGroupStats() = default; + + TestRunStats::TestRunStats( TestRunInfo const& _runInfo, + Totals const& _totals, + bool _aborting ) + : runInfo( _runInfo ), + totals( _totals ), + aborting( _aborting ) + {} + + TestRunStats::~TestRunStats() = default; + + void IStreamingReporter::fatalErrorEncountered( StringRef ) {} + bool IStreamingReporter::isMulti() const { return false; } + + IReporterFactory::~IReporterFactory() = default; + IReporterRegistry::~IReporterRegistry() = default; + + void addReporter( IStreamingReporterPtr& existingReporter, IStreamingReporterPtr&& additionalReporter ) { + + if( !existingReporter ) { + existingReporter = std::move( additionalReporter ); + return; + } + + MultipleReporters* multi = nullptr; + + if( existingReporter->isMulti() ) { + multi = static_cast( existingReporter.get() ); + } + else { + auto newMulti = std::unique_ptr( new MultipleReporters ); + newMulti->add( std::move( existingReporter ) ); + multi = newMulti.get(); + existingReporter = std::move( newMulti ); + } + multi->add( std::move( additionalReporter ) ); + } + +} // end namespace Catch +// end catch_interfaces_reporter.cpp +// start catch_interfaces_runner.cpp + +namespace Catch { + IRunner::~IRunner() = default; +} +// end catch_interfaces_runner.cpp +// start catch_interfaces_testcase.cpp + +namespace Catch { + ITestInvoker::~ITestInvoker() = default; + ITestCaseRegistry::~ITestCaseRegistry() = default; +} +// end catch_interfaces_testcase.cpp +// start catch_leak_detector.cpp + +#ifdef CATCH_CONFIG_WINDOWS_CRTDBG +#include + +namespace Catch { + + LeakDetector::LeakDetector() { + int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); + flag |= _CRTDBG_LEAK_CHECK_DF; + flag |= _CRTDBG_ALLOC_MEM_DF; + _CrtSetDbgFlag(flag); + _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); + _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); + // Change this to leaking allocation's number to break there + _CrtSetBreakAlloc(-1); + } +} + +#else + + Catch::LeakDetector::LeakDetector() {} + +#endif +// end catch_leak_detector.cpp +// start catch_list.cpp + +// start catch_list.h + +#include + +namespace Catch { + + std::size_t listTests( Config const& config ); + + std::size_t listTestsNamesOnly( Config const& config ); + + struct TagInfo { + void add( std::string const& spelling ); + std::string all() const; + + std::set spellings; + std::size_t count = 0; + }; + + std::size_t listTags( Config const& config ); + + std::size_t listReporters( Config const& /*config*/ ); + + Option list( Config const& config ); + +} // end namespace Catch + +// end catch_list.h +// start catch_text.h + +namespace Catch { + using namespace clara::TextFlow; +} + +// end catch_text.h +#include +#include +#include + +namespace Catch { + + std::size_t listTests( Config const& config ) { + TestSpec testSpec = config.testSpec(); + if( config.testSpec().hasFilters() ) + Catch::cout() << "Matching test cases:\n"; + else { + Catch::cout() << "All available test cases:\n"; + testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); + } + + auto matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); + for( auto const& testCaseInfo : matchedTestCases ) { + Colour::Code colour = testCaseInfo.isHidden() + ? Colour::SecondaryText + : Colour::None; + Colour colourGuard( colour ); + + Catch::cout() << Column( testCaseInfo.name ).initialIndent( 2 ).indent( 4 ) << "\n"; + if( config.verbosity() >= Verbosity::High ) { + Catch::cout() << Column( Catch::Detail::stringify( testCaseInfo.lineInfo ) ).indent(4) << std::endl; + std::string description = testCaseInfo.description; + if( description.empty() ) + description = "(NO DESCRIPTION)"; + Catch::cout() << Column( description ).indent(4) << std::endl; + } + if( !testCaseInfo.tags.empty() ) + Catch::cout() << Column( testCaseInfo.tagsAsString() ).indent( 6 ) << "\n"; + } + + if( !config.testSpec().hasFilters() ) + Catch::cout() << pluralise( matchedTestCases.size(), "test case" ) << '\n' << std::endl; + else + Catch::cout() << pluralise( matchedTestCases.size(), "matching test case" ) << '\n' << std::endl; + return matchedTestCases.size(); + } + + std::size_t listTestsNamesOnly( Config const& config ) { + TestSpec testSpec = config.testSpec(); + if( !config.testSpec().hasFilters() ) + testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); + std::size_t matchedTests = 0; + std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); + for( auto const& testCaseInfo : matchedTestCases ) { + matchedTests++; + if( startsWith( testCaseInfo.name, '#' ) ) + Catch::cout() << '"' << testCaseInfo.name << '"'; + else + Catch::cout() << testCaseInfo.name; + if ( config.verbosity() >= Verbosity::High ) + Catch::cout() << "\t@" << testCaseInfo.lineInfo; + Catch::cout() << std::endl; + } + return matchedTests; + } + + void TagInfo::add( std::string const& spelling ) { + ++count; + spellings.insert( spelling ); + } + + std::string TagInfo::all() const { + std::string out; + for( auto const& spelling : spellings ) + out += "[" + spelling + "]"; + return out; + } + + std::size_t listTags( Config const& config ) { + TestSpec testSpec = config.testSpec(); + if( config.testSpec().hasFilters() ) + Catch::cout() << "Tags for matching test cases:\n"; + else { + Catch::cout() << "All available tags:\n"; + testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); + } + + std::map tagCounts; + + std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); + for( auto const& testCase : matchedTestCases ) { + for( auto const& tagName : testCase.getTestCaseInfo().tags ) { + std::string lcaseTagName = toLower( tagName ); + auto countIt = tagCounts.find( lcaseTagName ); + if( countIt == tagCounts.end() ) + countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first; + countIt->second.add( tagName ); + } + } + + for( auto const& tagCount : tagCounts ) { + ReusableStringStream rss; + rss << " " << std::setw(2) << tagCount.second.count << " "; + auto str = rss.str(); + auto wrapper = Column( tagCount.second.all() ) + .initialIndent( 0 ) + .indent( str.size() ) + .width( CATCH_CONFIG_CONSOLE_WIDTH-10 ); + Catch::cout() << str << wrapper << '\n'; + } + Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl; + return tagCounts.size(); + } + + std::size_t listReporters( Config const& /*config*/ ) { + Catch::cout() << "Available reporters:\n"; + IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); + std::size_t maxNameLen = 0; + for( auto const& factoryKvp : factories ) + maxNameLen = (std::max)( maxNameLen, factoryKvp.first.size() ); + + for( auto const& factoryKvp : factories ) { + Catch::cout() + << Column( factoryKvp.first + ":" ) + .indent(2) + .width( 5+maxNameLen ) + + Column( factoryKvp.second->getDescription() ) + .initialIndent(0) + .indent(2) + .width( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) + << "\n"; + } + Catch::cout() << std::endl; + return factories.size(); + } + + Option list( Config const& config ) { + Option listedCount; + if( config.listTests() ) + listedCount = listedCount.valueOr(0) + listTests( config ); + if( config.listTestNamesOnly() ) + listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config ); + if( config.listTags() ) + listedCount = listedCount.valueOr(0) + listTags( config ); + if( config.listReporters() ) + listedCount = listedCount.valueOr(0) + listReporters( config ); + return listedCount; + } + +} // end namespace Catch +// end catch_list.cpp +// start catch_matchers.cpp + +namespace Catch { +namespace Matchers { + namespace Impl { + + std::string MatcherUntypedBase::toString() const { + if( m_cachedToString.empty() ) + m_cachedToString = describe(); + return m_cachedToString; + } + + MatcherUntypedBase::~MatcherUntypedBase() = default; + + } // namespace Impl +} // namespace Matchers + +using namespace Matchers; +using Matchers::Impl::MatcherBase; + +} // namespace Catch +// end catch_matchers.cpp +// start catch_matchers_floating.cpp + +#include +#include +#include +#include + +namespace Catch { +namespace Matchers { +namespace Floating { +enum class FloatingPointKind : uint8_t { + Float, + Double +}; +} +} +} + +namespace { + +template +struct Converter; + +template <> +struct Converter { + static_assert(sizeof(float) == sizeof(int32_t), "Important ULP matcher assumption violated"); + Converter(float f) { + std::memcpy(&i, &f, sizeof(f)); + } + int32_t i; +}; + +template <> +struct Converter { + static_assert(sizeof(double) == sizeof(int64_t), "Important ULP matcher assumption violated"); + Converter(double d) { + std::memcpy(&i, &d, sizeof(d)); + } + int64_t i; +}; + +template +auto convert(T t) -> Converter { + return Converter(t); +} + +template +bool almostEqualUlps(FP lhs, FP rhs, int maxUlpDiff) { + // Comparison with NaN should always be false. + // This way we can rule it out before getting into the ugly details + if (std::isnan(lhs) || std::isnan(rhs)) { + return false; + } + + auto lc = convert(lhs); + auto rc = convert(rhs); + + if ((lc.i < 0) != (rc.i < 0)) { + // Potentially we can have +0 and -0 + return lhs == rhs; + } + + auto ulpDiff = std::abs(lc.i - rc.i); + return ulpDiff <= maxUlpDiff; +} + +} + +namespace Catch { +namespace Matchers { +namespace Floating { + WithinAbsMatcher::WithinAbsMatcher(double target, double margin) + :m_target{ target }, m_margin{ margin } { + if (m_margin < 0) { + throw std::domain_error("Allowed margin difference has to be >= 0"); + } + } + + // Performs equivalent check of std::fabs(lhs - rhs) <= margin + // But without the subtraction to allow for INFINITY in comparison + bool WithinAbsMatcher::match(double const& matchee) const { + return (matchee + m_margin >= m_target) && (m_target + m_margin >= m_margin); + } + + std::string WithinAbsMatcher::describe() const { + return "is within " + ::Catch::Detail::stringify(m_margin) + " of " + ::Catch::Detail::stringify(m_target); + } + + WithinUlpsMatcher::WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType) + :m_target{ target }, m_ulps{ ulps }, m_type{ baseType } { + if (m_ulps < 0) { + throw std::domain_error("Allowed ulp difference has to be >= 0"); + } + } + + bool WithinUlpsMatcher::match(double const& matchee) const { + switch (m_type) { + case FloatingPointKind::Float: + return almostEqualUlps(static_cast(matchee), static_cast(m_target), m_ulps); + case FloatingPointKind::Double: + return almostEqualUlps(matchee, m_target, m_ulps); + default: + throw std::domain_error("Unknown FloatingPointKind value"); + } + } + + std::string WithinUlpsMatcher::describe() const { + return "is within " + std::to_string(m_ulps) + " ULPs of " + ::Catch::Detail::stringify(m_target) + ((m_type == FloatingPointKind::Float)? "f" : ""); + } + +}// namespace Floating + +Floating::WithinUlpsMatcher WithinULP(double target, int maxUlpDiff) { + return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Double); +} + +Floating::WithinUlpsMatcher WithinULP(float target, int maxUlpDiff) { + return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Float); +} + +Floating::WithinAbsMatcher WithinAbs(double target, double margin) { + return Floating::WithinAbsMatcher(target, margin); +} + +} // namespace Matchers +} // namespace Catch + +// end catch_matchers_floating.cpp +// start catch_matchers_string.cpp + +#include + +namespace Catch { +namespace Matchers { + + namespace StdString { + + CasedString::CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ) + : m_caseSensitivity( caseSensitivity ), + m_str( adjustString( str ) ) + {} + std::string CasedString::adjustString( std::string const& str ) const { + return m_caseSensitivity == CaseSensitive::No + ? toLower( str ) + : str; + } + std::string CasedString::caseSensitivitySuffix() const { + return m_caseSensitivity == CaseSensitive::No + ? " (case insensitive)" + : std::string(); + } + + StringMatcherBase::StringMatcherBase( std::string const& operation, CasedString const& comparator ) + : m_comparator( comparator ), + m_operation( operation ) { + } + + std::string StringMatcherBase::describe() const { + std::string description; + description.reserve(5 + m_operation.size() + m_comparator.m_str.size() + + m_comparator.caseSensitivitySuffix().size()); + description += m_operation; + description += ": \""; + description += m_comparator.m_str; + description += "\""; + description += m_comparator.caseSensitivitySuffix(); + return description; + } + + EqualsMatcher::EqualsMatcher( CasedString const& comparator ) : StringMatcherBase( "equals", comparator ) {} + + bool EqualsMatcher::match( std::string const& source ) const { + return m_comparator.adjustString( source ) == m_comparator.m_str; + } + + ContainsMatcher::ContainsMatcher( CasedString const& comparator ) : StringMatcherBase( "contains", comparator ) {} + + bool ContainsMatcher::match( std::string const& source ) const { + return contains( m_comparator.adjustString( source ), m_comparator.m_str ); + } + + StartsWithMatcher::StartsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "starts with", comparator ) {} + + bool StartsWithMatcher::match( std::string const& source ) const { + return startsWith( m_comparator.adjustString( source ), m_comparator.m_str ); + } + + EndsWithMatcher::EndsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "ends with", comparator ) {} + + bool EndsWithMatcher::match( std::string const& source ) const { + return endsWith( m_comparator.adjustString( source ), m_comparator.m_str ); + } + + RegexMatcher::RegexMatcher(std::string regex, CaseSensitive::Choice caseSensitivity): m_regex(std::move(regex)), m_caseSensitivity(caseSensitivity) {} + + bool RegexMatcher::match(std::string const& matchee) const { + auto flags = std::regex::ECMAScript; // ECMAScript is the default syntax option anyway + if (m_caseSensitivity == CaseSensitive::Choice::No) { + flags |= std::regex::icase; + } + auto reg = std::regex(m_regex, flags); + return std::regex_match(matchee, reg); + } + + std::string RegexMatcher::describe() const { + return "matches " + ::Catch::Detail::stringify(m_regex) + ((m_caseSensitivity == CaseSensitive::Choice::Yes)? " case sensitively" : " case insensitively"); + } + + } // namespace StdString + + StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::EqualsMatcher( StdString::CasedString( str, caseSensitivity) ); + } + StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::ContainsMatcher( StdString::CasedString( str, caseSensitivity) ); + } + StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::EndsWithMatcher( StdString::CasedString( str, caseSensitivity) ); + } + StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::StartsWithMatcher( StdString::CasedString( str, caseSensitivity) ); + } + + StdString::RegexMatcher Matches(std::string const& regex, CaseSensitive::Choice caseSensitivity) { + return StdString::RegexMatcher(regex, caseSensitivity); + } + +} // namespace Matchers +} // namespace Catch +// end catch_matchers_string.cpp +// start catch_message.cpp + +namespace Catch { + + MessageInfo::MessageInfo( std::string const& _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ) + : macroName( _macroName ), + lineInfo( _lineInfo ), + type( _type ), + sequence( ++globalCount ) + {} + + bool MessageInfo::operator==( MessageInfo const& other ) const { + return sequence == other.sequence; + } + + bool MessageInfo::operator<( MessageInfo const& other ) const { + return sequence < other.sequence; + } + + // This may need protecting if threading support is added + unsigned int MessageInfo::globalCount = 0; + + //////////////////////////////////////////////////////////////////////////// + + Catch::MessageBuilder::MessageBuilder( std::string const& macroName, + SourceLineInfo const& lineInfo, + ResultWas::OfType type ) + :m_info(macroName, lineInfo, type) {} + + //////////////////////////////////////////////////////////////////////////// + + ScopedMessage::ScopedMessage( MessageBuilder const& builder ) + : m_info( builder.m_info ) + { + m_info.message = builder.m_stream.str(); + getResultCapture().pushScopedMessage( m_info ); + } + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4996) // std::uncaught_exception is deprecated in C++17 +#endif + ScopedMessage::~ScopedMessage() { + if ( !std::uncaught_exception() ){ + getResultCapture().popScopedMessage(m_info); + } + } +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +} // end namespace Catch +// end catch_message.cpp +// start catch_random_number_generator.cpp + +// start catch_random_number_generator.h + +#include + +namespace Catch { + + struct IConfig; + + void seedRng( IConfig const& config ); + + unsigned int rngSeed(); + + struct RandomNumberGenerator { + using result_type = unsigned int; + + static constexpr result_type (min)() { return 0; } + static constexpr result_type (max)() { return 1000000; } + + result_type operator()( result_type n ) const; + result_type operator()() const; + + template + static void shuffle( V& vector ) { + RandomNumberGenerator rng; + std::shuffle( vector.begin(), vector.end(), rng ); + } + }; + +} + +// end catch_random_number_generator.h +#include + +namespace Catch { + + void seedRng( IConfig const& config ) { + if( config.rngSeed() != 0 ) + std::srand( config.rngSeed() ); + } + unsigned int rngSeed() { + return getCurrentContext().getConfig()->rngSeed(); + } + + RandomNumberGenerator::result_type RandomNumberGenerator::operator()( result_type n ) const { + return std::rand() % n; + } + RandomNumberGenerator::result_type RandomNumberGenerator::operator()() const { + return std::rand() % (max)(); + } + +} +// end catch_random_number_generator.cpp +// start catch_registry_hub.cpp + +// start catch_test_case_registry_impl.h + +#include +#include +#include +#include + +namespace Catch { + + class TestCase; + struct IConfig; + + std::vector sortTests( IConfig const& config, std::vector const& unsortedTestCases ); + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); + + void enforceNoDuplicateTestCases( std::vector const& functions ); + + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); + std::vector const& getAllTestCasesSorted( IConfig const& config ); + + class TestRegistry : public ITestCaseRegistry { + public: + virtual ~TestRegistry() = default; + + virtual void registerTest( TestCase const& testCase ); + + std::vector const& getAllTests() const override; + std::vector const& getAllTestsSorted( IConfig const& config ) const override; + + private: + std::vector m_functions; + mutable RunTests::InWhatOrder m_currentSortOrder = RunTests::InDeclarationOrder; + mutable std::vector m_sortedFunctions; + std::size_t m_unnamedCount = 0; + std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised + }; + + /////////////////////////////////////////////////////////////////////////// + + class TestInvokerAsFunction : public ITestInvoker { + void(*m_testAsFunction)(); + public: + TestInvokerAsFunction( void(*testAsFunction)() ) noexcept; + + void invoke() const override; + }; + + std::string extractClassName( std::string const& classOrQualifiedMethodName ); + + /////////////////////////////////////////////////////////////////////////// + +} // end namespace Catch + +// end catch_test_case_registry_impl.h +// start catch_reporter_registry.h + +#include + +namespace Catch { + + class ReporterRegistry : public IReporterRegistry { + + public: + + ~ReporterRegistry() override; + + IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override; + + void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ); + void registerListener( IReporterFactoryPtr const& factory ); + + FactoryMap const& getFactories() const override; + Listeners const& getListeners() const override; + + private: + FactoryMap m_factories; + Listeners m_listeners; + }; +} + +// end catch_reporter_registry.h +// start catch_tag_alias_registry.h + +// start catch_tag_alias.h + +#include + +namespace Catch { + + struct TagAlias { + TagAlias(std::string const& _tag, SourceLineInfo _lineInfo); + + std::string tag; + SourceLineInfo lineInfo; + }; + +} // end namespace Catch + +// end catch_tag_alias.h +#include + +namespace Catch { + + class TagAliasRegistry : public ITagAliasRegistry { + public: + ~TagAliasRegistry() override; + TagAlias const* find( std::string const& alias ) const override; + std::string expandAliases( std::string const& unexpandedTestSpec ) const override; + void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ); + + private: + std::map m_registry; + }; + +} // end namespace Catch + +// end catch_tag_alias_registry.h +// start catch_startup_exception_registry.h + +#include +#include + +namespace Catch { + + class StartupExceptionRegistry { + public: + void add(std::exception_ptr const& exception) noexcept; + std::vector const& getExceptions() const noexcept; + private: + std::vector m_exceptions; + }; + +} // end namespace Catch + +// end catch_startup_exception_registry.h +namespace Catch { + + namespace { + + class RegistryHub : public IRegistryHub, public IMutableRegistryHub, + private NonCopyable { + + public: // IRegistryHub + RegistryHub() = default; + IReporterRegistry const& getReporterRegistry() const override { + return m_reporterRegistry; + } + ITestCaseRegistry const& getTestCaseRegistry() const override { + return m_testCaseRegistry; + } + IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() override { + return m_exceptionTranslatorRegistry; + } + ITagAliasRegistry const& getTagAliasRegistry() const override { + return m_tagAliasRegistry; + } + StartupExceptionRegistry const& getStartupExceptionRegistry() const override { + return m_exceptionRegistry; + } + + public: // IMutableRegistryHub + void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override { + m_reporterRegistry.registerReporter( name, factory ); + } + void registerListener( IReporterFactoryPtr const& factory ) override { + m_reporterRegistry.registerListener( factory ); + } + void registerTest( TestCase const& testInfo ) override { + m_testCaseRegistry.registerTest( testInfo ); + } + void registerTranslator( const IExceptionTranslator* translator ) override { + m_exceptionTranslatorRegistry.registerTranslator( translator ); + } + void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override { + m_tagAliasRegistry.add( alias, tag, lineInfo ); + } + void registerStartupException() noexcept override { + m_exceptionRegistry.add(std::current_exception()); + } + + private: + TestRegistry m_testCaseRegistry; + ReporterRegistry m_reporterRegistry; + ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; + TagAliasRegistry m_tagAliasRegistry; + StartupExceptionRegistry m_exceptionRegistry; + }; + + // Single, global, instance + RegistryHub*& getTheRegistryHub() { + static RegistryHub* theRegistryHub = nullptr; + if( !theRegistryHub ) + theRegistryHub = new RegistryHub(); + return theRegistryHub; + } + } + + IRegistryHub& getRegistryHub() { + return *getTheRegistryHub(); + } + IMutableRegistryHub& getMutableRegistryHub() { + return *getTheRegistryHub(); + } + void cleanUp() { + delete getTheRegistryHub(); + getTheRegistryHub() = nullptr; + cleanUpContext(); + ReusableStringStream::cleanup(); + } + std::string translateActiveException() { + return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); + } + +} // end namespace Catch +// end catch_registry_hub.cpp +// start catch_reporter_registry.cpp + +namespace Catch { + + ReporterRegistry::~ReporterRegistry() = default; + + IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfigPtr const& config ) const { + auto it = m_factories.find( name ); + if( it == m_factories.end() ) + return nullptr; + return it->second->create( ReporterConfig( config ) ); + } + + void ReporterRegistry::registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) { + m_factories.emplace(name, factory); + } + void ReporterRegistry::registerListener( IReporterFactoryPtr const& factory ) { + m_listeners.push_back( factory ); + } + + IReporterRegistry::FactoryMap const& ReporterRegistry::getFactories() const { + return m_factories; + } + IReporterRegistry::Listeners const& ReporterRegistry::getListeners() const { + return m_listeners; + } + +} +// end catch_reporter_registry.cpp +// start catch_result_type.cpp + +namespace Catch { + + bool isOk( ResultWas::OfType resultType ) { + return ( resultType & ResultWas::FailureBit ) == 0; + } + bool isJustInfo( int flags ) { + return flags == ResultWas::Info; + } + + ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) { + return static_cast( static_cast( lhs ) | static_cast( rhs ) ); + } + + bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; } + bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; } + +} // end namespace Catch +// end catch_result_type.cpp +// start catch_run_context.cpp + +#include +#include +#include + +namespace Catch { + + class RedirectedStream { + std::ostream& m_originalStream; + std::ostream& m_redirectionStream; + std::streambuf* m_prevBuf; + + public: + RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream ) + : m_originalStream( originalStream ), + m_redirectionStream( redirectionStream ), + m_prevBuf( m_originalStream.rdbuf() ) + { + m_originalStream.rdbuf( m_redirectionStream.rdbuf() ); + } + ~RedirectedStream() { + m_originalStream.rdbuf( m_prevBuf ); + } + }; + + class RedirectedStdOut { + ReusableStringStream m_rss; + RedirectedStream m_cout; + public: + RedirectedStdOut() : m_cout( Catch::cout(), m_rss.get() ) {} + auto str() const -> std::string { return m_rss.str(); } + }; + + // StdErr has two constituent streams in C++, std::cerr and std::clog + // This means that we need to redirect 2 streams into 1 to keep proper + // order of writes + class RedirectedStdErr { + ReusableStringStream m_rss; + RedirectedStream m_cerr; + RedirectedStream m_clog; + public: + RedirectedStdErr() + : m_cerr( Catch::cerr(), m_rss.get() ), + m_clog( Catch::clog(), m_rss.get() ) + {} + auto str() const -> std::string { return m_rss.str(); } + }; + + RunContext::RunContext(IConfigPtr const& _config, IStreamingReporterPtr&& reporter) + : m_runInfo(_config->name()), + m_context(getCurrentMutableContext()), + m_config(_config), + m_reporter(std::move(reporter)), + m_lastAssertionInfo{ "", SourceLineInfo("",0), "", ResultDisposition::Normal }, + m_includeSuccessfulResults( m_config->includeSuccessfulResults() ) + { + m_context.setRunner(this); + m_context.setConfig(m_config); + m_context.setResultCapture(this); + m_reporter->testRunStarting(m_runInfo); + } + + RunContext::~RunContext() { + m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, aborting())); + } + + void RunContext::testGroupStarting(std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount) { + m_reporter->testGroupStarting(GroupInfo(testSpec, groupIndex, groupsCount)); + } + + void RunContext::testGroupEnded(std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount) { + m_reporter->testGroupEnded(TestGroupStats(GroupInfo(testSpec, groupIndex, groupsCount), totals, aborting())); + } + + Totals RunContext::runTest(TestCase const& testCase) { + Totals prevTotals = m_totals; + + std::string redirectedCout; + std::string redirectedCerr; + + TestCaseInfo testInfo = testCase.getTestCaseInfo(); + + m_reporter->testCaseStarting(testInfo); + + m_activeTestCase = &testCase; + + ITracker& rootTracker = m_trackerContext.startRun(); + assert(rootTracker.isSectionTracker()); + static_cast(rootTracker).addInitialFilters(m_config->getSectionsToRun()); + do { + m_trackerContext.startCycle(); + m_testCaseTracker = &SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(testInfo.name, testInfo.lineInfo)); + runCurrentTest(redirectedCout, redirectedCerr); + } while (!m_testCaseTracker->isSuccessfullyCompleted() && !aborting()); + + Totals deltaTotals = m_totals.delta(prevTotals); + if (testInfo.expectedToFail() && deltaTotals.testCases.passed > 0) { + deltaTotals.assertions.failed++; + deltaTotals.testCases.passed--; + deltaTotals.testCases.failed++; + } + m_totals.testCases += deltaTotals.testCases; + m_reporter->testCaseEnded(TestCaseStats(testInfo, + deltaTotals, + redirectedCout, + redirectedCerr, + aborting())); + + m_activeTestCase = nullptr; + m_testCaseTracker = nullptr; + + return deltaTotals; + } + + IConfigPtr RunContext::config() const { + return m_config; + } + + IStreamingReporter& RunContext::reporter() const { + return *m_reporter; + } + + void RunContext::assertionEnded(AssertionResult const & result) { + if (result.getResultType() == ResultWas::Ok) { + m_totals.assertions.passed++; + m_lastAssertionPassed = true; + } else if (!result.isOk()) { + m_lastAssertionPassed = false; + if( m_activeTestCase->getTestCaseInfo().okToFail() ) + m_totals.assertions.failedButOk++; + else + m_totals.assertions.failed++; + } + else { + m_lastAssertionPassed = true; + } + + // We have no use for the return value (whether messages should be cleared), because messages were made scoped + // and should be let to clear themselves out. + static_cast(m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals))); + + // Reset working state + resetAssertionInfo(); + m_lastResult = result; + } + void RunContext::resetAssertionInfo() { + m_lastAssertionInfo.macroName = StringRef(); + m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}"_sr; + } + + bool RunContext::sectionStarted(SectionInfo const & sectionInfo, Counts & assertions) { + ITracker& sectionTracker = SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(sectionInfo.name, sectionInfo.lineInfo)); + if (!sectionTracker.isOpen()) + return false; + m_activeSections.push_back(§ionTracker); + + m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo; + + m_reporter->sectionStarting(sectionInfo); + + assertions = m_totals.assertions; + + return true; + } + + bool RunContext::testForMissingAssertions(Counts& assertions) { + if (assertions.total() != 0) + return false; + if (!m_config->warnAboutMissingAssertions()) + return false; + if (m_trackerContext.currentTracker().hasChildren()) + return false; + m_totals.assertions.failed++; + assertions.failed++; + return true; + } + + void RunContext::sectionEnded(SectionEndInfo const & endInfo) { + Counts assertions = m_totals.assertions - endInfo.prevAssertions; + bool missingAssertions = testForMissingAssertions(assertions); + + if (!m_activeSections.empty()) { + m_activeSections.back()->close(); + m_activeSections.pop_back(); + } + + m_reporter->sectionEnded(SectionStats(endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions)); + m_messages.clear(); + } + + void RunContext::sectionEndedEarly(SectionEndInfo const & endInfo) { + if (m_unfinishedSections.empty()) + m_activeSections.back()->fail(); + else + m_activeSections.back()->close(); + m_activeSections.pop_back(); + + m_unfinishedSections.push_back(endInfo); + } + void RunContext::benchmarkStarting( BenchmarkInfo const& info ) { + m_reporter->benchmarkStarting( info ); + } + void RunContext::benchmarkEnded( BenchmarkStats const& stats ) { + m_reporter->benchmarkEnded( stats ); + } + + void RunContext::pushScopedMessage(MessageInfo const & message) { + m_messages.push_back(message); + } + + void RunContext::popScopedMessage(MessageInfo const & message) { + m_messages.erase(std::remove(m_messages.begin(), m_messages.end(), message), m_messages.end()); + } + + std::string RunContext::getCurrentTestName() const { + return m_activeTestCase + ? m_activeTestCase->getTestCaseInfo().name + : std::string(); + } + + const AssertionResult * RunContext::getLastResult() const { + return &(*m_lastResult); + } + + void RunContext::exceptionEarlyReported() { + m_shouldReportUnexpected = false; + } + + void RunContext::handleFatalErrorCondition( StringRef message ) { + // First notify reporter that bad things happened + m_reporter->fatalErrorEncountered(message); + + // Don't rebuild the result -- the stringification itself can cause more fatal errors + // Instead, fake a result data. + AssertionResultData tempResult( ResultWas::FatalErrorCondition, { false } ); + tempResult.message = message; + AssertionResult result(m_lastAssertionInfo, tempResult); + + assertionEnded(result); + + handleUnfinishedSections(); + + // Recreate section for test case (as we will lose the one that was in scope) + auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); + SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description); + + Counts assertions; + assertions.failed = 1; + SectionStats testCaseSectionStats(testCaseSection, assertions, 0, false); + m_reporter->sectionEnded(testCaseSectionStats); + + auto const& testInfo = m_activeTestCase->getTestCaseInfo(); + + Totals deltaTotals; + deltaTotals.testCases.failed = 1; + deltaTotals.assertions.failed = 1; + m_reporter->testCaseEnded(TestCaseStats(testInfo, + deltaTotals, + std::string(), + std::string(), + false)); + m_totals.testCases.failed++; + testGroupEnded(std::string(), m_totals, 1, 1); + m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, false)); + } + + bool RunContext::lastAssertionPassed() { + return m_lastAssertionPassed; + } + + void RunContext::assertionPassed() { + m_lastAssertionPassed = true; + ++m_totals.assertions.passed; + resetAssertionInfo(); + } + + bool RunContext::aborting() const { + return m_totals.assertions.failed == static_cast(m_config->abortAfter()); + } + + void RunContext::runCurrentTest(std::string & redirectedCout, std::string & redirectedCerr) { + auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); + SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description); + m_reporter->sectionStarting(testCaseSection); + Counts prevAssertions = m_totals.assertions; + double duration = 0; + m_shouldReportUnexpected = true; + m_lastAssertionInfo = { "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal }; + + seedRng(*m_config); + + Timer timer; + try { + if (m_reporter->getPreferences().shouldRedirectStdOut) { + RedirectedStdOut redirectedStdOut; + RedirectedStdErr redirectedStdErr; + timer.start(); + invokeActiveTestCase(); + redirectedCout += redirectedStdOut.str(); + redirectedCerr += redirectedStdErr.str(); + + } else { + timer.start(); + invokeActiveTestCase(); + } + duration = timer.getElapsedSeconds(); + } catch (TestFailureException&) { + // This just means the test was aborted due to failure + } catch (...) { + // Under CATCH_CONFIG_FAST_COMPILE, unexpected exceptions under REQUIRE assertions + // are reported without translation at the point of origin. + if( m_shouldReportUnexpected ) { + AssertionReaction dummyReaction; + handleUnexpectedInflightException( m_lastAssertionInfo, translateActiveException(), dummyReaction ); + } + } + m_testCaseTracker->close(); + handleUnfinishedSections(); + m_messages.clear(); + + Counts assertions = m_totals.assertions - prevAssertions; + bool missingAssertions = testForMissingAssertions(assertions); + SectionStats testCaseSectionStats(testCaseSection, assertions, duration, missingAssertions); + m_reporter->sectionEnded(testCaseSectionStats); + } + + void RunContext::invokeActiveTestCase() { + FatalConditionHandler fatalConditionHandler; // Handle signals + m_activeTestCase->invoke(); + fatalConditionHandler.reset(); + } + + void RunContext::handleUnfinishedSections() { + // If sections ended prematurely due to an exception we stored their + // infos here so we can tear them down outside the unwind process. + for (auto it = m_unfinishedSections.rbegin(), + itEnd = m_unfinishedSections.rend(); + it != itEnd; + ++it) + sectionEnded(*it); + m_unfinishedSections.clear(); + } + + void RunContext::handleExpr( + AssertionInfo const& info, + ITransientExpression const& expr, + AssertionReaction& reaction + ) { + m_reporter->assertionStarting( info ); + + bool negated = isFalseTest( info.resultDisposition ); + bool result = expr.getResult() != negated; + + if( result ) { + if (!m_includeSuccessfulResults) { + assertionPassed(); + } + else { + reportExpr(info, ResultWas::Ok, &expr, negated); + } + } + else { + reportExpr(info, ResultWas::ExpressionFailed, &expr, negated ); + populateReaction( reaction ); + } + } + void RunContext::reportExpr( + AssertionInfo const &info, + ResultWas::OfType resultType, + ITransientExpression const *expr, + bool negated ) { + + m_lastAssertionInfo = info; + AssertionResultData data( resultType, LazyExpression( negated ) ); + + AssertionResult assertionResult{ info, data }; + assertionResult.m_resultData.lazyExpression.m_transientExpression = expr; + + assertionEnded( assertionResult ); + } + + void RunContext::handleMessage( + AssertionInfo const& info, + ResultWas::OfType resultType, + StringRef const& message, + AssertionReaction& reaction + ) { + m_reporter->assertionStarting( info ); + + m_lastAssertionInfo = info; + + AssertionResultData data( resultType, LazyExpression( false ) ); + data.message = message; + AssertionResult assertionResult{ m_lastAssertionInfo, data }; + assertionEnded( assertionResult ); + if( !assertionResult.isOk() ) + populateReaction( reaction ); + } + void RunContext::handleUnexpectedExceptionNotThrown( + AssertionInfo const& info, + AssertionReaction& reaction + ) { + handleNonExpr(info, Catch::ResultWas::DidntThrowException, reaction); + } + + void RunContext::handleUnexpectedInflightException( + AssertionInfo const& info, + std::string const& message, + AssertionReaction& reaction + ) { + m_lastAssertionInfo = info; + + AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); + data.message = message; + AssertionResult assertionResult{ info, data }; + assertionEnded( assertionResult ); + populateReaction( reaction ); + } + + void RunContext::populateReaction( AssertionReaction& reaction ) { + reaction.shouldDebugBreak = m_config->shouldDebugBreak(); + reaction.shouldThrow = aborting() || (m_lastAssertionInfo.resultDisposition & ResultDisposition::Normal); + } + + void RunContext::handleIncomplete( + AssertionInfo const& info + ) { + m_lastAssertionInfo = info; + + AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); + data.message = "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE"; + AssertionResult assertionResult{ info, data }; + assertionEnded( assertionResult ); + } + void RunContext::handleNonExpr( + AssertionInfo const &info, + ResultWas::OfType resultType, + AssertionReaction &reaction + ) { + m_lastAssertionInfo = info; + + AssertionResultData data( resultType, LazyExpression( false ) ); + AssertionResult assertionResult{ info, data }; + assertionEnded( assertionResult ); + + if( !assertionResult.isOk() ) + populateReaction( reaction ); + } + + IResultCapture& getResultCapture() { + if (auto* capture = getCurrentContext().getResultCapture()) + return *capture; + else + CATCH_INTERNAL_ERROR("No result capture instance"); + } +} +// end catch_run_context.cpp +// start catch_section.cpp + +namespace Catch { + + Section::Section( SectionInfo const& info ) + : m_info( info ), + m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) ) + { + m_timer.start(); + } + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4996) // std::uncaught_exception is deprecated in C++17 +#endif + Section::~Section() { + if( m_sectionIncluded ) { + SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() ); + if( std::uncaught_exception() ) + getResultCapture().sectionEndedEarly( endInfo ); + else + getResultCapture().sectionEnded( endInfo ); + } + } +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + + // This indicates whether the section should be executed or not + Section::operator bool() const { + return m_sectionIncluded; + } + +} // end namespace Catch +// end catch_section.cpp +// start catch_section_info.cpp + +namespace Catch { + + SectionInfo::SectionInfo + ( SourceLineInfo const& _lineInfo, + std::string const& _name, + std::string const& _description ) + : name( _name ), + description( _description ), + lineInfo( _lineInfo ) + {} + + SectionEndInfo::SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds ) + : sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds ) + {} + +} // end namespace Catch +// end catch_section_info.cpp +// start catch_session.cpp + +// start catch_session.h + +#include + +namespace Catch { + + class Session : NonCopyable { + public: + + Session(); + ~Session() override; + + void showHelp() const; + void libIdentify(); + + int applyCommandLine( int argc, char* argv[] ); + + void useConfigData( ConfigData const& configData ); + + int run( int argc, char* argv[] ); + #if defined(WIN32) && defined(UNICODE) + int run( int argc, wchar_t* const argv[] ); + #endif + int run(); + + clara::Parser const& cli() const; + void cli( clara::Parser const& newParser ); + ConfigData& configData(); + Config& config(); + private: + int runInternal(); + + clara::Parser m_cli; + ConfigData m_configData; + std::shared_ptr m_config; + bool m_startupExceptions = false; + }; + +} // end namespace Catch + +// end catch_session.h +// start catch_version.h + +#include + +namespace Catch { + + // Versioning information + struct Version { + Version( Version const& ) = delete; + Version& operator=( Version const& ) = delete; + Version( unsigned int _majorVersion, + unsigned int _minorVersion, + unsigned int _patchNumber, + char const * const _branchName, + unsigned int _buildNumber ); + + unsigned int const majorVersion; + unsigned int const minorVersion; + unsigned int const patchNumber; + + // buildNumber is only used if branchName is not null + char const * const branchName; + unsigned int const buildNumber; + + friend std::ostream& operator << ( std::ostream& os, Version const& version ); + }; + + Version const& libraryVersion(); +} + +// end catch_version.h +#include +#include + +namespace Catch { + + namespace { + const int MaxExitCode = 255; + + IStreamingReporterPtr createReporter(std::string const& reporterName, IConfigPtr const& config) { + auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config); + CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << "'"); + + return reporter; + } + +#ifndef CATCH_CONFIG_DEFAULT_REPORTER +#define CATCH_CONFIG_DEFAULT_REPORTER "console" +#endif + + IStreamingReporterPtr makeReporter(std::shared_ptr const& config) { + auto const& reporterNames = config->getReporterNames(); + if (reporterNames.empty()) + return createReporter(CATCH_CONFIG_DEFAULT_REPORTER, config); + + IStreamingReporterPtr reporter; + for (auto const& name : reporterNames) + addReporter(reporter, createReporter(name, config)); + return reporter; + } + +#undef CATCH_CONFIG_DEFAULT_REPORTER + + void addListeners(IStreamingReporterPtr& reporters, IConfigPtr const& config) { + auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners(); + for (auto const& listener : listeners) + addReporter(reporters, listener->create(Catch::ReporterConfig(config))); + } + + Catch::Totals runTests(std::shared_ptr const& config) { + IStreamingReporterPtr reporter = makeReporter(config); + addListeners(reporter, config); + + RunContext context(config, std::move(reporter)); + + Totals totals; + + context.testGroupStarting(config->name(), 1, 1); + + TestSpec testSpec = config->testSpec(); + if (!testSpec.hasFilters()) + testSpec = TestSpecParser(ITagAliasRegistry::get()).parse("~[.]").testSpec(); // All not hidden tests + + auto const& allTestCases = getAllTestCasesSorted(*config); + for (auto const& testCase : allTestCases) { + if (!context.aborting() && matchTest(testCase, testSpec, *config)) + totals += context.runTest(testCase); + else + context.reporter().skipTest(testCase); + } + + context.testGroupEnded(config->name(), totals, 1, 1); + return totals; + } + + void applyFilenamesAsTags(Catch::IConfig const& config) { + auto& tests = const_cast&>(getAllTestCasesSorted(config)); + for (auto& testCase : tests) { + auto tags = testCase.tags; + + std::string filename = testCase.lineInfo.file; + auto lastSlash = filename.find_last_of("\\/"); + if (lastSlash != std::string::npos) { + filename.erase(0, lastSlash); + filename[0] = '#'; + } + + auto lastDot = filename.find_last_of('.'); + if (lastDot != std::string::npos) { + filename.erase(lastDot); + } + + tags.push_back(std::move(filename)); + setTags(testCase, tags); + } + } + + } // anon namespace + + Session::Session() { + static bool alreadyInstantiated = false; + if( alreadyInstantiated ) { + try { CATCH_INTERNAL_ERROR( "Only one instance of Catch::Session can ever be used" ); } + catch(...) { getMutableRegistryHub().registerStartupException(); } + } + + const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions(); + if ( !exceptions.empty() ) { + m_startupExceptions = true; + Colour colourGuard( Colour::Red ); + Catch::cerr() << "Errors occured during startup!" << '\n'; + // iterate over all exceptions and notify user + for ( const auto& ex_ptr : exceptions ) { + try { + std::rethrow_exception(ex_ptr); + } catch ( std::exception const& ex ) { + Catch::cerr() << Column( ex.what() ).indent(2) << '\n'; + } + } + } + + alreadyInstantiated = true; + m_cli = makeCommandLineParser( m_configData ); + } + Session::~Session() { + Catch::cleanUp(); + } + + void Session::showHelp() const { + Catch::cout() + << "\nCatch v" << libraryVersion() << "\n" + << m_cli << std::endl + << "For more detailed usage please see the project docs\n" << std::endl; + } + void Session::libIdentify() { + Catch::cout() + << std::left << std::setw(16) << "description: " << "A Catch test executable\n" + << std::left << std::setw(16) << "category: " << "testframework\n" + << std::left << std::setw(16) << "framework: " << "Catch Test\n" + << std::left << std::setw(16) << "version: " << libraryVersion() << std::endl; + } + + int Session::applyCommandLine( int argc, char* argv[] ) { + if( m_startupExceptions ) + return 1; + + auto result = m_cli.parse( clara::Args( argc, argv ) ); + if( !result ) { + Catch::cerr() + << Colour( Colour::Red ) + << "\nError(s) in input:\n" + << Column( result.errorMessage() ).indent( 2 ) + << "\n\n"; + Catch::cerr() << "Run with -? for usage\n" << std::endl; + return MaxExitCode; + } + + if( m_configData.showHelp ) + showHelp(); + if( m_configData.libIdentify ) + libIdentify(); + m_config.reset(); + return 0; + } + + void Session::useConfigData( ConfigData const& configData ) { + m_configData = configData; + m_config.reset(); + } + + int Session::run( int argc, char* argv[] ) { + if( m_startupExceptions ) + return 1; + int returnCode = applyCommandLine( argc, argv ); + if( returnCode == 0 ) + returnCode = run(); + return returnCode; + } + +#if defined(WIN32) && defined(UNICODE) + int Session::run( int argc, wchar_t* const argv[] ) { + + char **utf8Argv = new char *[ argc ]; + + for ( int i = 0; i < argc; ++i ) { + int bufSize = WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, NULL, 0, NULL, NULL ); + + utf8Argv[ i ] = new char[ bufSize ]; + + WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, NULL, NULL ); + } + + int returnCode = run( argc, utf8Argv ); + + for ( int i = 0; i < argc; ++i ) + delete [] utf8Argv[ i ]; + + delete [] utf8Argv; + + return returnCode; + } +#endif + int Session::run() { + if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) { + Catch::cout() << "...waiting for enter/ return before starting" << std::endl; + static_cast(std::getchar()); + } + int exitCode = runInternal(); + if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) { + Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl; + static_cast(std::getchar()); + } + return exitCode; + } + + clara::Parser const& Session::cli() const { + return m_cli; + } + void Session::cli( clara::Parser const& newParser ) { + m_cli = newParser; + } + ConfigData& Session::configData() { + return m_configData; + } + Config& Session::config() { + if( !m_config ) + m_config = std::make_shared( m_configData ); + return *m_config; + } + + int Session::runInternal() { + if( m_startupExceptions ) + return 1; + + if( m_configData.showHelp || m_configData.libIdentify ) + return 0; + + try + { + config(); // Force config to be constructed + + seedRng( *m_config ); + + if( m_configData.filenamesAsTags ) + applyFilenamesAsTags( *m_config ); + + // Handle list request + if( Option listed = list( config() ) ) + return static_cast( *listed ); + + // Note that on unices only the lower 8 bits are usually used, clamping + // the return value to 255 prevents false negative when some multiple + // of 256 tests has failed + return (std::min)( MaxExitCode, static_cast( runTests( m_config ).assertions.failed ) ); + } + catch( std::exception& ex ) { + Catch::cerr() << ex.what() << std::endl; + return MaxExitCode; + } + } + +} // end namespace Catch +// end catch_session.cpp +// start catch_startup_exception_registry.cpp + +namespace Catch { + void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexcept { + try { + m_exceptions.push_back(exception); + } + catch(...) { + // If we run out of memory during start-up there's really not a lot more we can do about it + std::terminate(); + } + } + + std::vector const& StartupExceptionRegistry::getExceptions() const noexcept { + return m_exceptions; + } + +} // end namespace Catch +// end catch_startup_exception_registry.cpp +// start catch_stream.cpp + +#include +#include +#include +#include +#include +#include + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +#endif + +namespace Catch { + + Catch::IStream::~IStream() = default; + + namespace detail { namespace { + template + class StreamBufImpl : public std::streambuf { + char data[bufferSize]; + WriterF m_writer; + + public: + StreamBufImpl() { + setp( data, data + sizeof(data) ); + } + + ~StreamBufImpl() noexcept { + StreamBufImpl::sync(); + } + + private: + int overflow( int c ) override { + sync(); + + if( c != EOF ) { + if( pbase() == epptr() ) + m_writer( std::string( 1, static_cast( c ) ) ); + else + sputc( static_cast( c ) ); + } + return 0; + } + + int sync() override { + if( pbase() != pptr() ) { + m_writer( std::string( pbase(), static_cast( pptr() - pbase() ) ) ); + setp( pbase(), epptr() ); + } + return 0; + } + }; + + /////////////////////////////////////////////////////////////////////////// + + struct OutputDebugWriter { + + void operator()( std::string const&str ) { + writeToDebugConsole( str ); + } + }; + + /////////////////////////////////////////////////////////////////////////// + + class FileStream : public IStream { + mutable std::ofstream m_ofs; + public: + FileStream( StringRef filename ) { + m_ofs.open( filename.c_str() ); + CATCH_ENFORCE( !m_ofs.fail(), "Unable to open file: '" << filename << "'" ); + } + ~FileStream() override = default; + public: // IStream + std::ostream& stream() const override { + return m_ofs; + } + }; + + /////////////////////////////////////////////////////////////////////////// + + class CoutStream : public IStream { + mutable std::ostream m_os; + public: + // Store the streambuf from cout up-front because + // cout may get redirected when running tests + CoutStream() : m_os( Catch::cout().rdbuf() ) {} + ~CoutStream() override = default; + + public: // IStream + std::ostream& stream() const override { return m_os; } + }; + + /////////////////////////////////////////////////////////////////////////// + + class DebugOutStream : public IStream { + std::unique_ptr> m_streamBuf; + mutable std::ostream m_os; + public: + DebugOutStream() + : m_streamBuf( new StreamBufImpl() ), + m_os( m_streamBuf.get() ) + {} + + ~DebugOutStream() override = default; + + public: // IStream + std::ostream& stream() const override { return m_os; } + }; + + }} // namespace anon::detail + + /////////////////////////////////////////////////////////////////////////// + + auto makeStream( StringRef const &filename ) -> IStream const* { + if( filename.empty() ) + return new detail::CoutStream(); + else if( filename[0] == '%' ) { + if( filename == "%debug" ) + return new detail::DebugOutStream(); + else + CATCH_ERROR( "Unrecognised stream: '" << filename << "'" ); + } + else + return new detail::FileStream( filename ); + } + + // This class encapsulates the idea of a pool of ostringstreams that can be reused. + struct StringStreams { + std::vector> m_streams; + std::vector m_unused; + std::ostringstream m_referenceStream; // Used for copy state/ flags from + static StringStreams* s_instance; + + auto add() -> std::size_t { + if( m_unused.empty() ) { + m_streams.push_back( std::unique_ptr( new std::ostringstream ) ); + return m_streams.size()-1; + } + else { + auto index = m_unused.back(); + m_unused.pop_back(); + return index; + } + } + + void release( std::size_t index ) { + m_streams[index]->copyfmt( m_referenceStream ); // Restore initial flags and other state + m_unused.push_back(index); + } + + // !TBD: put in TLS + static auto instance() -> StringStreams& { + if( !s_instance ) + s_instance = new StringStreams(); + return *s_instance; + } + static void cleanup() { + delete s_instance; + s_instance = nullptr; + } + }; + + StringStreams* StringStreams::s_instance = nullptr; + + void ReusableStringStream::cleanup() { + StringStreams::cleanup(); + } + + ReusableStringStream::ReusableStringStream() + : m_index( StringStreams::instance().add() ), + m_oss( StringStreams::instance().m_streams[m_index].get() ) + {} + + ReusableStringStream::~ReusableStringStream() { + static_cast( m_oss )->str(""); + m_oss->clear(); + StringStreams::instance().release( m_index ); + } + + auto ReusableStringStream::str() const -> std::string { + return static_cast( m_oss )->str(); + } + + /////////////////////////////////////////////////////////////////////////// + +#ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions + std::ostream& cout() { return std::cout; } + std::ostream& cerr() { return std::cerr; } + std::ostream& clog() { return std::clog; } +#endif +} + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif +// end catch_stream.cpp +// start catch_string_manip.cpp + +#include +#include +#include +#include + +namespace Catch { + + bool startsWith( std::string const& s, std::string const& prefix ) { + return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin()); + } + bool startsWith( std::string const& s, char prefix ) { + return !s.empty() && s[0] == prefix; + } + bool endsWith( std::string const& s, std::string const& suffix ) { + return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin()); + } + bool endsWith( std::string const& s, char suffix ) { + return !s.empty() && s[s.size()-1] == suffix; + } + bool contains( std::string const& s, std::string const& infix ) { + return s.find( infix ) != std::string::npos; + } + char toLowerCh(char c) { + return static_cast( std::tolower( c ) ); + } + void toLowerInPlace( std::string& s ) { + std::transform( s.begin(), s.end(), s.begin(), toLowerCh ); + } + std::string toLower( std::string const& s ) { + std::string lc = s; + toLowerInPlace( lc ); + return lc; + } + std::string trim( std::string const& str ) { + static char const* whitespaceChars = "\n\r\t "; + std::string::size_type start = str.find_first_not_of( whitespaceChars ); + std::string::size_type end = str.find_last_not_of( whitespaceChars ); + + return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string(); + } + + bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) { + bool replaced = false; + std::size_t i = str.find( replaceThis ); + while( i != std::string::npos ) { + replaced = true; + str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() ); + if( i < str.size()-withThis.size() ) + i = str.find( replaceThis, i+withThis.size() ); + else + i = std::string::npos; + } + return replaced; + } + + pluralise::pluralise( std::size_t count, std::string const& label ) + : m_count( count ), + m_label( label ) + {} + + std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) { + os << pluraliser.m_count << ' ' << pluraliser.m_label; + if( pluraliser.m_count != 1 ) + os << 's'; + return os; + } + +} +// end catch_string_manip.cpp +// start catch_stringref.cpp + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +#endif + +#include +#include + +namespace Catch { + StringRef::StringRef( char const* rawChars ) noexcept + : StringRef( rawChars, static_cast(std::strlen(rawChars) ) ) + {} + + StringRef::operator std::string() const { + return std::string( m_start, m_size ); + } + + void StringRef::swap( StringRef& other ) noexcept { + std::swap( m_start, other.m_start ); + std::swap( m_size, other.m_size ); + std::swap( m_data, other.m_data ); + } + + auto StringRef::c_str() const -> char const* { + if( isSubstring() ) + const_cast( this )->takeOwnership(); + return m_start; + } + auto StringRef::data() const noexcept -> char const* { + return m_start; + } + + auto StringRef::isOwned() const noexcept -> bool { + return m_data != nullptr; + } + auto StringRef::isSubstring() const noexcept -> bool { + return m_start[m_size] != '\0'; + } + + void StringRef::takeOwnership() { + if( !isOwned() ) { + m_data = new char[m_size+1]; + memcpy( m_data, m_start, m_size ); + m_data[m_size] = '\0'; + m_start = m_data; + } + } + auto StringRef::substr( size_type start, size_type size ) const noexcept -> StringRef { + if( start < m_size ) + return StringRef( m_start+start, size ); + else + return StringRef(); + } + auto StringRef::operator == ( StringRef const& other ) const noexcept -> bool { + return + size() == other.size() && + (std::strncmp( m_start, other.m_start, size() ) == 0); + } + auto StringRef::operator != ( StringRef const& other ) const noexcept -> bool { + return !operator==( other ); + } + + auto StringRef::operator[](size_type index) const noexcept -> char { + return m_start[index]; + } + + auto StringRef::numberOfCharacters() const noexcept -> size_type { + size_type noChars = m_size; + // Make adjustments for uft encodings + for( size_type i=0; i < m_size; ++i ) { + char c = m_start[i]; + if( ( c & 0b11000000 ) == 0b11000000 ) { + if( ( c & 0b11100000 ) == 0b11000000 ) + noChars--; + else if( ( c & 0b11110000 ) == 0b11100000 ) + noChars-=2; + else if( ( c & 0b11111000 ) == 0b11110000 ) + noChars-=3; + } + } + return noChars; + } + + auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> std::string { + std::string str; + str.reserve( lhs.size() + rhs.size() ); + str += lhs; + str += rhs; + return str; + } + auto operator + ( StringRef const& lhs, const char* rhs ) -> std::string { + return std::string( lhs ) + std::string( rhs ); + } + auto operator + ( char const* lhs, StringRef const& rhs ) -> std::string { + return std::string( lhs ) + std::string( rhs ); + } + + auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& { + return os << str.c_str(); + } + +} // namespace Catch + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif +// end catch_stringref.cpp +// start catch_tag_alias.cpp + +namespace Catch { + TagAlias::TagAlias(std::string const & _tag, SourceLineInfo _lineInfo): tag(_tag), lineInfo(_lineInfo) {} +} +// end catch_tag_alias.cpp +// start catch_tag_alias_autoregistrar.cpp + +namespace Catch { + + RegistrarForTagAliases::RegistrarForTagAliases(char const* alias, char const* tag, SourceLineInfo const& lineInfo) { + try { + getMutableRegistryHub().registerTagAlias(alias, tag, lineInfo); + } catch (...) { + // Do not throw when constructing global objects, instead register the exception to be processed later + getMutableRegistryHub().registerStartupException(); + } + } + +} +// end catch_tag_alias_autoregistrar.cpp +// start catch_tag_alias_registry.cpp + +#include + +namespace Catch { + + TagAliasRegistry::~TagAliasRegistry() {} + + TagAlias const* TagAliasRegistry::find( std::string const& alias ) const { + auto it = m_registry.find( alias ); + if( it != m_registry.end() ) + return &(it->second); + else + return nullptr; + } + + std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const { + std::string expandedTestSpec = unexpandedTestSpec; + for( auto const& registryKvp : m_registry ) { + std::size_t pos = expandedTestSpec.find( registryKvp.first ); + if( pos != std::string::npos ) { + expandedTestSpec = expandedTestSpec.substr( 0, pos ) + + registryKvp.second.tag + + expandedTestSpec.substr( pos + registryKvp.first.size() ); + } + } + return expandedTestSpec; + } + + void TagAliasRegistry::add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) { + CATCH_ENFORCE( startsWith(alias, "[@") && endsWith(alias, ']'), + "error: tag alias, '" << alias << "' is not of the form [@alias name].\n" << lineInfo ); + + CATCH_ENFORCE( m_registry.insert(std::make_pair(alias, TagAlias(tag, lineInfo))).second, + "error: tag alias, '" << alias << "' already registered.\n" + << "\tFirst seen at: " << find(alias)->lineInfo << "\n" + << "\tRedefined at: " << lineInfo ); + } + + ITagAliasRegistry::~ITagAliasRegistry() {} + + ITagAliasRegistry const& ITagAliasRegistry::get() { + return getRegistryHub().getTagAliasRegistry(); + } + +} // end namespace Catch +// end catch_tag_alias_registry.cpp +// start catch_test_case_info.cpp + +#include +#include +#include +#include + +namespace Catch { + + TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) { + if( startsWith( tag, '.' ) || + tag == "!hide" ) + return TestCaseInfo::IsHidden; + else if( tag == "!throws" ) + return TestCaseInfo::Throws; + else if( tag == "!shouldfail" ) + return TestCaseInfo::ShouldFail; + else if( tag == "!mayfail" ) + return TestCaseInfo::MayFail; + else if( tag == "!nonportable" ) + return TestCaseInfo::NonPortable; + else if( tag == "!benchmark" ) + return static_cast( TestCaseInfo::Benchmark | TestCaseInfo::IsHidden ); + else + return TestCaseInfo::None; + } + bool isReservedTag( std::string const& tag ) { + return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( tag[0] ); + } + void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) { + CATCH_ENFORCE( !isReservedTag(tag), + "Tag name: [" << tag << "] is not allowed.\n" + << "Tag names starting with non alpha-numeric characters are reserved\n" + << _lineInfo ); + } + + TestCase makeTestCase( ITestInvoker* _testCase, + std::string const& _className, + std::string const& _name, + std::string const& _descOrTags, + SourceLineInfo const& _lineInfo ) + { + bool isHidden = false; + + // Parse out tags + std::vector tags; + std::string desc, tag; + bool inTag = false; + for (char c : _descOrTags) { + if( !inTag ) { + if( c == '[' ) + inTag = true; + else + desc += c; + } + else { + if( c == ']' ) { + TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag ); + if( ( prop & TestCaseInfo::IsHidden ) != 0 ) + isHidden = true; + else if( prop == TestCaseInfo::None ) + enforceNotReservedTag( tag, _lineInfo ); + + tags.push_back( tag ); + tag.clear(); + inTag = false; + } + else + tag += c; + } + } + if( isHidden ) { + tags.push_back( "." ); + } + + TestCaseInfo info( _name, _className, desc, tags, _lineInfo ); + return TestCase( _testCase, info ); + } + + void setTags( TestCaseInfo& testCaseInfo, std::vector tags ) { + std::sort(begin(tags), end(tags)); + tags.erase(std::unique(begin(tags), end(tags)), end(tags)); + testCaseInfo.lcaseTags.clear(); + + for( auto const& tag : tags ) { + std::string lcaseTag = toLower( tag ); + testCaseInfo.properties = static_cast( testCaseInfo.properties | parseSpecialTag( lcaseTag ) ); + testCaseInfo.lcaseTags.push_back( lcaseTag ); + } + testCaseInfo.tags = std::move(tags); + } + + TestCaseInfo::TestCaseInfo( std::string const& _name, + std::string const& _className, + std::string const& _description, + std::vector const& _tags, + SourceLineInfo const& _lineInfo ) + : name( _name ), + className( _className ), + description( _description ), + lineInfo( _lineInfo ), + properties( None ) + { + setTags( *this, _tags ); + } + + bool TestCaseInfo::isHidden() const { + return ( properties & IsHidden ) != 0; + } + bool TestCaseInfo::throws() const { + return ( properties & Throws ) != 0; + } + bool TestCaseInfo::okToFail() const { + return ( properties & (ShouldFail | MayFail ) ) != 0; + } + bool TestCaseInfo::expectedToFail() const { + return ( properties & (ShouldFail ) ) != 0; + } + + std::string TestCaseInfo::tagsAsString() const { + std::string ret; + // '[' and ']' per tag + std::size_t full_size = 2 * tags.size(); + for (const auto& tag : tags) { + full_size += tag.size(); + } + ret.reserve(full_size); + for (const auto& tag : tags) { + ret.push_back('['); + ret.append(tag); + ret.push_back(']'); + } + + return ret; + } + + TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {} + + TestCase TestCase::withName( std::string const& _newName ) const { + TestCase other( *this ); + other.name = _newName; + return other; + } + + void TestCase::invoke() const { + test->invoke(); + } + + bool TestCase::operator == ( TestCase const& other ) const { + return test.get() == other.test.get() && + name == other.name && + className == other.className; + } + + bool TestCase::operator < ( TestCase const& other ) const { + return name < other.name; + } + + TestCaseInfo const& TestCase::getTestCaseInfo() const + { + return *this; + } + +} // end namespace Catch +// end catch_test_case_info.cpp +// start catch_test_case_registry_impl.cpp + +#include + +namespace Catch { + + std::vector sortTests( IConfig const& config, std::vector const& unsortedTestCases ) { + + std::vector sorted = unsortedTestCases; + + switch( config.runOrder() ) { + case RunTests::InLexicographicalOrder: + std::sort( sorted.begin(), sorted.end() ); + break; + case RunTests::InRandomOrder: + seedRng( config ); + RandomNumberGenerator::shuffle( sorted ); + break; + case RunTests::InDeclarationOrder: + // already in declaration order + break; + } + return sorted; + } + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) { + return testSpec.matches( testCase ) && ( config.allowThrows() || !testCase.throws() ); + } + + void enforceNoDuplicateTestCases( std::vector const& functions ) { + std::set seenFunctions; + for( auto const& function : functions ) { + auto prev = seenFunctions.insert( function ); + CATCH_ENFORCE( prev.second, + "error: TEST_CASE( \"" << function.name << "\" ) already defined.\n" + << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n" + << "\tRedefined at " << function.getTestCaseInfo().lineInfo ); + } + } + + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ) { + std::vector filtered; + filtered.reserve( testCases.size() ); + for( auto const& testCase : testCases ) + if( matchTest( testCase, testSpec, config ) ) + filtered.push_back( testCase ); + return filtered; + } + std::vector const& getAllTestCasesSorted( IConfig const& config ) { + return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config ); + } + + void TestRegistry::registerTest( TestCase const& testCase ) { + std::string name = testCase.getTestCaseInfo().name; + if( name.empty() ) { + ReusableStringStream rss; + rss << "Anonymous test case " << ++m_unnamedCount; + return registerTest( testCase.withName( rss.str() ) ); + } + m_functions.push_back( testCase ); + } + + std::vector const& TestRegistry::getAllTests() const { + return m_functions; + } + std::vector const& TestRegistry::getAllTestsSorted( IConfig const& config ) const { + if( m_sortedFunctions.empty() ) + enforceNoDuplicateTestCases( m_functions ); + + if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) { + m_sortedFunctions = sortTests( config, m_functions ); + m_currentSortOrder = config.runOrder(); + } + return m_sortedFunctions; + } + + /////////////////////////////////////////////////////////////////////////// + TestInvokerAsFunction::TestInvokerAsFunction( void(*testAsFunction)() ) noexcept : m_testAsFunction( testAsFunction ) {} + + void TestInvokerAsFunction::invoke() const { + m_testAsFunction(); + } + + std::string extractClassName( std::string const& classOrQualifiedMethodName ) { + std::string className = classOrQualifiedMethodName; + if( startsWith( className, '&' ) ) + { + std::size_t lastColons = className.rfind( "::" ); + std::size_t penultimateColons = className.rfind( "::", lastColons-1 ); + if( penultimateColons == std::string::npos ) + penultimateColons = 1; + className = className.substr( penultimateColons, lastColons-penultimateColons ); + } + return className; + } + +} // end namespace Catch +// end catch_test_case_registry_impl.cpp +// start catch_test_case_tracker.cpp + +#include +#include +#include +#include +#include + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +#endif + +namespace Catch { +namespace TestCaseTracking { + + NameAndLocation::NameAndLocation( std::string const& _name, SourceLineInfo const& _location ) + : name( _name ), + location( _location ) + {} + + ITracker::~ITracker() = default; + + TrackerContext& TrackerContext::instance() { + static TrackerContext s_instance; + return s_instance; + } + + ITracker& TrackerContext::startRun() { + m_rootTracker = std::make_shared( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, nullptr ); + m_currentTracker = nullptr; + m_runState = Executing; + return *m_rootTracker; + } + + void TrackerContext::endRun() { + m_rootTracker.reset(); + m_currentTracker = nullptr; + m_runState = NotStarted; + } + + void TrackerContext::startCycle() { + m_currentTracker = m_rootTracker.get(); + m_runState = Executing; + } + void TrackerContext::completeCycle() { + m_runState = CompletedCycle; + } + + bool TrackerContext::completedCycle() const { + return m_runState == CompletedCycle; + } + ITracker& TrackerContext::currentTracker() { + return *m_currentTracker; + } + void TrackerContext::setCurrentTracker( ITracker* tracker ) { + m_currentTracker = tracker; + } + + TrackerBase::TrackerHasName::TrackerHasName( NameAndLocation const& nameAndLocation ) : m_nameAndLocation( nameAndLocation ) {} + bool TrackerBase::TrackerHasName::operator ()( ITrackerPtr const& tracker ) const { + return + tracker->nameAndLocation().name == m_nameAndLocation.name && + tracker->nameAndLocation().location == m_nameAndLocation.location; + } + + TrackerBase::TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) + : m_nameAndLocation( nameAndLocation ), + m_ctx( ctx ), + m_parent( parent ) + {} + + NameAndLocation const& TrackerBase::nameAndLocation() const { + return m_nameAndLocation; + } + bool TrackerBase::isComplete() const { + return m_runState == CompletedSuccessfully || m_runState == Failed; + } + bool TrackerBase::isSuccessfullyCompleted() const { + return m_runState == CompletedSuccessfully; + } + bool TrackerBase::isOpen() const { + return m_runState != NotStarted && !isComplete(); + } + bool TrackerBase::hasChildren() const { + return !m_children.empty(); + } + + void TrackerBase::addChild( ITrackerPtr const& child ) { + m_children.push_back( child ); + } + + ITrackerPtr TrackerBase::findChild( NameAndLocation const& nameAndLocation ) { + auto it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( nameAndLocation ) ); + return( it != m_children.end() ) + ? *it + : nullptr; + } + ITracker& TrackerBase::parent() { + assert( m_parent ); // Should always be non-null except for root + return *m_parent; + } + + void TrackerBase::openChild() { + if( m_runState != ExecutingChildren ) { + m_runState = ExecutingChildren; + if( m_parent ) + m_parent->openChild(); + } + } + + bool TrackerBase::isSectionTracker() const { return false; } + bool TrackerBase::isIndexTracker() const { return false; } + + void TrackerBase::open() { + m_runState = Executing; + moveToThis(); + if( m_parent ) + m_parent->openChild(); + } + + void TrackerBase::close() { + + // Close any still open children (e.g. generators) + while( &m_ctx.currentTracker() != this ) + m_ctx.currentTracker().close(); + + switch( m_runState ) { + case NeedsAnotherRun: + break; + + case Executing: + m_runState = CompletedSuccessfully; + break; + case ExecutingChildren: + if( m_children.empty() || m_children.back()->isComplete() ) + m_runState = CompletedSuccessfully; + break; + + case NotStarted: + case CompletedSuccessfully: + case Failed: + CATCH_INTERNAL_ERROR( "Illogical state: " << m_runState ); + + default: + CATCH_INTERNAL_ERROR( "Unknown state: " << m_runState ); + } + moveToParent(); + m_ctx.completeCycle(); + } + void TrackerBase::fail() { + m_runState = Failed; + if( m_parent ) + m_parent->markAsNeedingAnotherRun(); + moveToParent(); + m_ctx.completeCycle(); + } + void TrackerBase::markAsNeedingAnotherRun() { + m_runState = NeedsAnotherRun; + } + + void TrackerBase::moveToParent() { + assert( m_parent ); + m_ctx.setCurrentTracker( m_parent ); + } + void TrackerBase::moveToThis() { + m_ctx.setCurrentTracker( this ); + } + + SectionTracker::SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) + : TrackerBase( nameAndLocation, ctx, parent ) + { + if( parent ) { + while( !parent->isSectionTracker() ) + parent = &parent->parent(); + + SectionTracker& parentSection = static_cast( *parent ); + addNextFilters( parentSection.m_filters ); + } + } + + bool SectionTracker::isSectionTracker() const { return true; } + + SectionTracker& SectionTracker::acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) { + std::shared_ptr section; + + ITracker& currentTracker = ctx.currentTracker(); + if( ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) { + assert( childTracker ); + assert( childTracker->isSectionTracker() ); + section = std::static_pointer_cast( childTracker ); + } + else { + section = std::make_shared( nameAndLocation, ctx, ¤tTracker ); + currentTracker.addChild( section ); + } + if( !ctx.completedCycle() ) + section->tryOpen(); + return *section; + } + + void SectionTracker::tryOpen() { + if( !isComplete() && (m_filters.empty() || m_filters[0].empty() || m_filters[0] == m_nameAndLocation.name ) ) + open(); + } + + void SectionTracker::addInitialFilters( std::vector const& filters ) { + if( !filters.empty() ) { + m_filters.push_back(""); // Root - should never be consulted + m_filters.push_back(""); // Test Case - not a section filter + m_filters.insert( m_filters.end(), filters.begin(), filters.end() ); + } + } + void SectionTracker::addNextFilters( std::vector const& filters ) { + if( filters.size() > 1 ) + m_filters.insert( m_filters.end(), ++filters.begin(), filters.end() ); + } + + IndexTracker::IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size ) + : TrackerBase( nameAndLocation, ctx, parent ), + m_size( size ) + {} + + bool IndexTracker::isIndexTracker() const { return true; } + + IndexTracker& IndexTracker::acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size ) { + std::shared_ptr tracker; + + ITracker& currentTracker = ctx.currentTracker(); + if( ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) { + assert( childTracker ); + assert( childTracker->isIndexTracker() ); + tracker = std::static_pointer_cast( childTracker ); + } + else { + tracker = std::make_shared( nameAndLocation, ctx, ¤tTracker, size ); + currentTracker.addChild( tracker ); + } + + if( !ctx.completedCycle() && !tracker->isComplete() ) { + if( tracker->m_runState != ExecutingChildren && tracker->m_runState != NeedsAnotherRun ) + tracker->moveNext(); + tracker->open(); + } + + return *tracker; + } + + int IndexTracker::index() const { return m_index; } + + void IndexTracker::moveNext() { + m_index++; + m_children.clear(); + } + + void IndexTracker::close() { + TrackerBase::close(); + if( m_runState == CompletedSuccessfully && m_index < m_size-1 ) + m_runState = Executing; + } + +} // namespace TestCaseTracking + +using TestCaseTracking::ITracker; +using TestCaseTracking::TrackerContext; +using TestCaseTracking::SectionTracker; +using TestCaseTracking::IndexTracker; + +} // namespace Catch + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif +// end catch_test_case_tracker.cpp +// start catch_test_registry.cpp + +namespace Catch { + + auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker* { + return new(std::nothrow) TestInvokerAsFunction( testAsFunction ); + } + + NameAndTags::NameAndTags( StringRef name_ , StringRef tags_ ) noexcept : name( name_ ), tags( tags_ ) {} + + AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept { + try { + getMutableRegistryHub() + .registerTest( + makeTestCase( + invoker, + extractClassName( classOrMethod ), + nameAndTags.name, + nameAndTags.tags, + lineInfo)); + } catch (...) { + // Do not throw when constructing global objects, instead register the exception to be processed later + getMutableRegistryHub().registerStartupException(); + } + } + + AutoReg::~AutoReg() = default; +} +// end catch_test_registry.cpp +// start catch_test_spec.cpp + +#include +#include +#include +#include + +namespace Catch { + + TestSpec::Pattern::~Pattern() = default; + TestSpec::NamePattern::~NamePattern() = default; + TestSpec::TagPattern::~TagPattern() = default; + TestSpec::ExcludedPattern::~ExcludedPattern() = default; + + TestSpec::NamePattern::NamePattern( std::string const& name ) + : m_wildcardPattern( toLower( name ), CaseSensitive::No ) + {} + bool TestSpec::NamePattern::matches( TestCaseInfo const& testCase ) const { + return m_wildcardPattern.matches( toLower( testCase.name ) ); + } + + TestSpec::TagPattern::TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {} + bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const { + return std::find(begin(testCase.lcaseTags), + end(testCase.lcaseTags), + m_tag) != end(testCase.lcaseTags); + } + + TestSpec::ExcludedPattern::ExcludedPattern( PatternPtr const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {} + bool TestSpec::ExcludedPattern::matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); } + + bool TestSpec::Filter::matches( TestCaseInfo const& testCase ) const { + // All patterns in a filter must match for the filter to be a match + for( auto const& pattern : m_patterns ) { + if( !pattern->matches( testCase ) ) + return false; + } + return true; + } + + bool TestSpec::hasFilters() const { + return !m_filters.empty(); + } + bool TestSpec::matches( TestCaseInfo const& testCase ) const { + // A TestSpec matches if any filter matches + for( auto const& filter : m_filters ) + if( filter.matches( testCase ) ) + return true; + return false; + } +} +// end catch_test_spec.cpp +// start catch_test_spec_parser.cpp + +namespace Catch { + + TestSpecParser::TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {} + + TestSpecParser& TestSpecParser::parse( std::string const& arg ) { + m_mode = None; + m_exclusion = false; + m_start = std::string::npos; + m_arg = m_tagAliases->expandAliases( arg ); + m_escapeChars.clear(); + for( m_pos = 0; m_pos < m_arg.size(); ++m_pos ) + visitChar( m_arg[m_pos] ); + if( m_mode == Name ) + addPattern(); + return *this; + } + TestSpec TestSpecParser::testSpec() { + addFilter(); + return m_testSpec; + } + + void TestSpecParser::visitChar( char c ) { + if( m_mode == None ) { + switch( c ) { + case ' ': return; + case '~': m_exclusion = true; return; + case '[': return startNewMode( Tag, ++m_pos ); + case '"': return startNewMode( QuotedName, ++m_pos ); + case '\\': return escape(); + default: startNewMode( Name, m_pos ); break; + } + } + if( m_mode == Name ) { + if( c == ',' ) { + addPattern(); + addFilter(); + } + else if( c == '[' ) { + if( subString() == "exclude:" ) + m_exclusion = true; + else + addPattern(); + startNewMode( Tag, ++m_pos ); + } + else if( c == '\\' ) + escape(); + } + else if( m_mode == EscapedName ) + m_mode = Name; + else if( m_mode == QuotedName && c == '"' ) + addPattern(); + else if( m_mode == Tag && c == ']' ) + addPattern(); + } + void TestSpecParser::startNewMode( Mode mode, std::size_t start ) { + m_mode = mode; + m_start = start; + } + void TestSpecParser::escape() { + if( m_mode == None ) + m_start = m_pos; + m_mode = EscapedName; + m_escapeChars.push_back( m_pos ); + } + std::string TestSpecParser::subString() const { return m_arg.substr( m_start, m_pos - m_start ); } + + void TestSpecParser::addFilter() { + if( !m_currentFilter.m_patterns.empty() ) { + m_testSpec.m_filters.push_back( m_currentFilter ); + m_currentFilter = TestSpec::Filter(); + } + } + + TestSpec parseTestSpec( std::string const& arg ) { + return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec(); + } + +} // namespace Catch +// end catch_test_spec_parser.cpp +// start catch_timer.cpp + +#include + +namespace Catch { + + auto getCurrentNanosecondsSinceEpoch() -> uint64_t { + return std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); + } + + auto estimateClockResolution() -> uint64_t { + uint64_t sum = 0; + static const uint64_t iterations = 1000000; + + for( std::size_t i = 0; i < iterations; ++i ) { + + uint64_t ticks; + uint64_t baseTicks = getCurrentNanosecondsSinceEpoch(); + do { + ticks = getCurrentNanosecondsSinceEpoch(); + } + while( ticks == baseTicks ); + + auto delta = ticks - baseTicks; + sum += delta; + } + + // We're just taking the mean, here. To do better we could take the std. dev and exclude outliers + // - and potentially do more iterations if there's a high variance. + return sum/iterations; + } + auto getEstimatedClockResolution() -> uint64_t { + static auto s_resolution = estimateClockResolution(); + return s_resolution; + } + + void Timer::start() { + m_nanoseconds = getCurrentNanosecondsSinceEpoch(); + } + auto Timer::getElapsedNanoseconds() const -> uint64_t { + return getCurrentNanosecondsSinceEpoch() - m_nanoseconds; + } + auto Timer::getElapsedMicroseconds() const -> uint64_t { + return getElapsedNanoseconds()/1000; + } + auto Timer::getElapsedMilliseconds() const -> unsigned int { + return static_cast(getElapsedMicroseconds()/1000); + } + auto Timer::getElapsedSeconds() const -> double { + return getElapsedMicroseconds()/1000000.0; + } + +} // namespace Catch +// end catch_timer.cpp +// start catch_tostring.cpp + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +# pragma clang diagnostic ignored "-Wglobal-constructors" +#endif + +// Enable specific decls locally +#if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) +#define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER +#endif + +#include +#include + +namespace Catch { + +namespace Detail { + + const std::string unprintableString = "{?}"; + + namespace { + const int hexThreshold = 255; + + struct Endianness { + enum Arch { Big, Little }; + + static Arch which() { + union _{ + int asInt; + char asChar[sizeof (int)]; + } u; + + u.asInt = 1; + return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little; + } + }; + } + + std::string rawMemoryToString( const void *object, std::size_t size ) { + // Reverse order for little endian architectures + int i = 0, end = static_cast( size ), inc = 1; + if( Endianness::which() == Endianness::Little ) { + i = end-1; + end = inc = -1; + } + + unsigned char const *bytes = static_cast(object); + ReusableStringStream rss; + rss << "0x" << std::setfill('0') << std::hex; + for( ; i != end; i += inc ) + rss << std::setw(2) << static_cast(bytes[i]); + return rss.str(); + } +} + +template +std::string fpToString( T value, int precision ) { + if (std::isnan(value)) { + return "nan"; + } + + ReusableStringStream rss; + rss << std::setprecision( precision ) + << std::fixed + << value; + std::string d = rss.str(); + std::size_t i = d.find_last_not_of( '0' ); + if( i != std::string::npos && i != d.size()-1 ) { + if( d[i] == '.' ) + i++; + d = d.substr( 0, i+1 ); + } + return d; +} + +//// ======================================================= //// +// +// Out-of-line defs for full specialization of StringMaker +// +//// ======================================================= //// + +std::string StringMaker::convert(const std::string& str) { + if (!getCurrentContext().getConfig()->showInvisibles()) { + return '"' + str + '"'; + } + + std::string s("\""); + for (char c : str) { + switch (c) { + case '\n': + s.append("\\n"); + break; + case '\t': + s.append("\\t"); + break; + default: + s.push_back(c); + break; + } + } + s.append("\""); + return s; +} + +std::string StringMaker::convert(const std::wstring& wstr) { + std::string s; + s.reserve(wstr.size()); + for (auto c : wstr) { + s += (c <= 0xff) ? static_cast(c) : '?'; + } + return ::Catch::Detail::stringify(s); +} + +std::string StringMaker::convert(char const* str) { + if (str) { + return ::Catch::Detail::stringify(std::string{ str }); + } else { + return{ "{null string}" }; + } +} +std::string StringMaker::convert(char* str) { + if (str) { + return ::Catch::Detail::stringify(std::string{ str }); + } else { + return{ "{null string}" }; + } +} +std::string StringMaker::convert(wchar_t const * str) { + if (str) { + return ::Catch::Detail::stringify(std::wstring{ str }); + } else { + return{ "{null string}" }; + } +} +std::string StringMaker::convert(wchar_t * str) { + if (str) { + return ::Catch::Detail::stringify(std::wstring{ str }); + } else { + return{ "{null string}" }; + } +} + +std::string StringMaker::convert(int value) { + return ::Catch::Detail::stringify(static_cast(value)); +} +std::string StringMaker::convert(long value) { + return ::Catch::Detail::stringify(static_cast(value)); +} +std::string StringMaker::convert(long long value) { + ReusableStringStream rss; + rss << value; + if (value > Detail::hexThreshold) { + rss << " (0x" << std::hex << value << ')'; + } + return rss.str(); +} + +std::string StringMaker::convert(unsigned int value) { + return ::Catch::Detail::stringify(static_cast(value)); +} +std::string StringMaker::convert(unsigned long value) { + return ::Catch::Detail::stringify(static_cast(value)); +} +std::string StringMaker::convert(unsigned long long value) { + ReusableStringStream rss; + rss << value; + if (value > Detail::hexThreshold) { + rss << " (0x" << std::hex << value << ')'; + } + return rss.str(); +} + +std::string StringMaker::convert(bool b) { + return b ? "true" : "false"; +} + +std::string StringMaker::convert(char value) { + if (value == '\r') { + return "'\\r'"; + } else if (value == '\f') { + return "'\\f'"; + } else if (value == '\n') { + return "'\\n'"; + } else if (value == '\t') { + return "'\\t'"; + } else if ('\0' <= value && value < ' ') { + return ::Catch::Detail::stringify(static_cast(value)); + } else { + char chstr[] = "' '"; + chstr[1] = value; + return chstr; + } +} +std::string StringMaker::convert(signed char c) { + return ::Catch::Detail::stringify(static_cast(c)); +} +std::string StringMaker::convert(unsigned char c) { + return ::Catch::Detail::stringify(static_cast(c)); +} + +std::string StringMaker::convert(std::nullptr_t) { + return "nullptr"; +} + +std::string StringMaker::convert(float value) { + return fpToString(value, 5) + 'f'; +} +std::string StringMaker::convert(double value) { + return fpToString(value, 10); +} + +std::string ratio_string::symbol() { return "a"; } +std::string ratio_string::symbol() { return "f"; } +std::string ratio_string::symbol() { return "p"; } +std::string ratio_string::symbol() { return "n"; } +std::string ratio_string::symbol() { return "u"; } +std::string ratio_string::symbol() { return "m"; } + +} // end namespace Catch + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + +// end catch_tostring.cpp +// start catch_totals.cpp + +namespace Catch { + + Counts Counts::operator - ( Counts const& other ) const { + Counts diff; + diff.passed = passed - other.passed; + diff.failed = failed - other.failed; + diff.failedButOk = failedButOk - other.failedButOk; + return diff; + } + + Counts& Counts::operator += ( Counts const& other ) { + passed += other.passed; + failed += other.failed; + failedButOk += other.failedButOk; + return *this; + } + + std::size_t Counts::total() const { + return passed + failed + failedButOk; + } + bool Counts::allPassed() const { + return failed == 0 && failedButOk == 0; + } + bool Counts::allOk() const { + return failed == 0; + } + + Totals Totals::operator - ( Totals const& other ) const { + Totals diff; + diff.assertions = assertions - other.assertions; + diff.testCases = testCases - other.testCases; + return diff; + } + + Totals& Totals::operator += ( Totals const& other ) { + assertions += other.assertions; + testCases += other.testCases; + return *this; + } + + Totals Totals::delta( Totals const& prevTotals ) const { + Totals diff = *this - prevTotals; + if( diff.assertions.failed > 0 ) + ++diff.testCases.failed; + else if( diff.assertions.failedButOk > 0 ) + ++diff.testCases.failedButOk; + else + ++diff.testCases.passed; + return diff; + } + +} +// end catch_totals.cpp +// start catch_version.cpp + +#include + +namespace Catch { + + Version::Version + ( unsigned int _majorVersion, + unsigned int _minorVersion, + unsigned int _patchNumber, + char const * const _branchName, + unsigned int _buildNumber ) + : majorVersion( _majorVersion ), + minorVersion( _minorVersion ), + patchNumber( _patchNumber ), + branchName( _branchName ), + buildNumber( _buildNumber ) + {} + + std::ostream& operator << ( std::ostream& os, Version const& version ) { + os << version.majorVersion << '.' + << version.minorVersion << '.' + << version.patchNumber; + // branchName is never null -> 0th char is \0 if it is empty + if (version.branchName[0]) { + os << '-' << version.branchName + << '.' << version.buildNumber; + } + return os; + } + + Version const& libraryVersion() { + static Version version( 2, 1, 1, "", 0 ); + return version; + } + +} +// end catch_version.cpp +// start catch_wildcard_pattern.cpp + +#include + +namespace Catch { + + WildcardPattern::WildcardPattern( std::string const& pattern, + CaseSensitive::Choice caseSensitivity ) + : m_caseSensitivity( caseSensitivity ), + m_pattern( adjustCase( pattern ) ) + { + if( startsWith( m_pattern, '*' ) ) { + m_pattern = m_pattern.substr( 1 ); + m_wildcard = WildcardAtStart; + } + if( endsWith( m_pattern, '*' ) ) { + m_pattern = m_pattern.substr( 0, m_pattern.size()-1 ); + m_wildcard = static_cast( m_wildcard | WildcardAtEnd ); + } + } + + bool WildcardPattern::matches( std::string const& str ) const { + switch( m_wildcard ) { + case NoWildcard: + return m_pattern == adjustCase( str ); + case WildcardAtStart: + return endsWith( adjustCase( str ), m_pattern ); + case WildcardAtEnd: + return startsWith( adjustCase( str ), m_pattern ); + case WildcardAtBothEnds: + return contains( adjustCase( str ), m_pattern ); + default: + CATCH_INTERNAL_ERROR( "Unknown enum" ); + } + } + + std::string WildcardPattern::adjustCase( std::string const& str ) const { + return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str; + } +} +// end catch_wildcard_pattern.cpp +// start catch_xmlwriter.cpp + +#include + +namespace Catch { + + XmlEncode::XmlEncode( std::string const& str, ForWhat forWhat ) + : m_str( str ), + m_forWhat( forWhat ) + {} + + void XmlEncode::encodeTo( std::ostream& os ) const { + + // Apostrophe escaping not necessary if we always use " to write attributes + // (see: http://www.w3.org/TR/xml/#syntax) + + for( std::size_t i = 0; i < m_str.size(); ++ i ) { + char c = m_str[i]; + switch( c ) { + case '<': os << "<"; break; + case '&': os << "&"; break; + + case '>': + // See: http://www.w3.org/TR/xml/#syntax + if( i > 2 && m_str[i-1] == ']' && m_str[i-2] == ']' ) + os << ">"; + else + os << c; + break; + + case '\"': + if( m_forWhat == ForAttributes ) + os << """; + else + os << c; + break; + + default: + // Escape control chars - based on contribution by @espenalb in PR #465 and + // by @mrpi PR #588 + if ( ( c >= 0 && c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' ) { + // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0 + os << "\\x" << std::uppercase << std::hex << std::setfill('0') << std::setw(2) + << static_cast( c ); + } + else + os << c; + } + } + } + + std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) { + xmlEncode.encodeTo( os ); + return os; + } + + XmlWriter::ScopedElement::ScopedElement( XmlWriter* writer ) + : m_writer( writer ) + {} + + XmlWriter::ScopedElement::ScopedElement( ScopedElement&& other ) noexcept + : m_writer( other.m_writer ){ + other.m_writer = nullptr; + } + XmlWriter::ScopedElement& XmlWriter::ScopedElement::operator=( ScopedElement&& other ) noexcept { + if ( m_writer ) { + m_writer->endElement(); + } + m_writer = other.m_writer; + other.m_writer = nullptr; + return *this; + } + + XmlWriter::ScopedElement::~ScopedElement() { + if( m_writer ) + m_writer->endElement(); + } + + XmlWriter::ScopedElement& XmlWriter::ScopedElement::writeText( std::string const& text, bool indent ) { + m_writer->writeText( text, indent ); + return *this; + } + + XmlWriter::XmlWriter( std::ostream& os ) : m_os( os ) + { + writeDeclaration(); + } + + XmlWriter::~XmlWriter() { + while( !m_tags.empty() ) + endElement(); + } + + XmlWriter& XmlWriter::startElement( std::string const& name ) { + ensureTagClosed(); + newlineIfNecessary(); + m_os << m_indent << '<' << name; + m_tags.push_back( name ); + m_indent += " "; + m_tagIsOpen = true; + return *this; + } + + XmlWriter::ScopedElement XmlWriter::scopedElement( std::string const& name ) { + ScopedElement scoped( this ); + startElement( name ); + return scoped; + } + + XmlWriter& XmlWriter::endElement() { + newlineIfNecessary(); + m_indent = m_indent.substr( 0, m_indent.size()-2 ); + if( m_tagIsOpen ) { + m_os << "/>"; + m_tagIsOpen = false; + } + else { + m_os << m_indent << ""; + } + m_os << std::endl; + m_tags.pop_back(); + return *this; + } + + XmlWriter& XmlWriter::writeAttribute( std::string const& name, std::string const& attribute ) { + if( !name.empty() && !attribute.empty() ) + m_os << ' ' << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << '"'; + return *this; + } + + XmlWriter& XmlWriter::writeAttribute( std::string const& name, bool attribute ) { + m_os << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"'; + return *this; + } + + XmlWriter& XmlWriter::writeText( std::string const& text, bool indent ) { + if( !text.empty() ){ + bool tagWasOpen = m_tagIsOpen; + ensureTagClosed(); + if( tagWasOpen && indent ) + m_os << m_indent; + m_os << XmlEncode( text ); + m_needsNewline = true; + } + return *this; + } + + XmlWriter& XmlWriter::writeComment( std::string const& text ) { + ensureTagClosed(); + m_os << m_indent << ""; + m_needsNewline = true; + return *this; + } + + void XmlWriter::writeStylesheetRef( std::string const& url ) { + m_os << "\n"; + } + + XmlWriter& XmlWriter::writeBlankLine() { + ensureTagClosed(); + m_os << '\n'; + return *this; + } + + void XmlWriter::ensureTagClosed() { + if( m_tagIsOpen ) { + m_os << ">" << std::endl; + m_tagIsOpen = false; + } + } + + void XmlWriter::writeDeclaration() { + m_os << "\n"; + } + + void XmlWriter::newlineIfNecessary() { + if( m_needsNewline ) { + m_os << std::endl; + m_needsNewline = false; + } + } +} +// end catch_xmlwriter.cpp +// start catch_reporter_bases.cpp + +#include +#include +#include +#include +#include + +namespace Catch { + void prepareExpandedExpression(AssertionResult& result) { + result.getExpandedExpression(); + } + + // Because formatting using c++ streams is stateful, drop down to C is required + // Alternatively we could use stringstream, but its performance is... not good. + std::string getFormattedDuration( double duration ) { + // Max exponent + 1 is required to represent the whole part + // + 1 for decimal point + // + 3 for the 3 decimal places + // + 1 for null terminator + const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; + char buffer[maxDoubleSize]; + + // Save previous errno, to prevent sprintf from overwriting it + ErrnoGuard guard; +#ifdef _MSC_VER + sprintf_s(buffer, "%.3f", duration); +#else + sprintf(buffer, "%.3f", duration); +#endif + return std::string(buffer); + } + + TestEventListenerBase::TestEventListenerBase(ReporterConfig const & _config) + :StreamingReporterBase(_config) {} + + void TestEventListenerBase::assertionStarting(AssertionInfo const &) {} + + bool TestEventListenerBase::assertionEnded(AssertionStats const &) { + return false; + } + +} // end namespace Catch +// end catch_reporter_bases.cpp +// start catch_reporter_compact.cpp + +namespace { + +#ifdef CATCH_PLATFORM_MAC + const char* failedString() { return "FAILED"; } + const char* passedString() { return "PASSED"; } +#else + const char* failedString() { return "failed"; } + const char* passedString() { return "passed"; } +#endif + + // Colour::LightGrey + Catch::Colour::Code dimColour() { return Catch::Colour::FileName; } + + std::string bothOrAll( std::size_t count ) { + return count == 1 ? std::string() : + count == 2 ? "both " : "all " ; + } + +} // anon namespace + +namespace Catch { +namespace { +// Colour, message variants: +// - white: No tests ran. +// - red: Failed [both/all] N test cases, failed [both/all] M assertions. +// - white: Passed [both/all] N test cases (no assertions). +// - red: Failed N tests cases, failed M assertions. +// - green: Passed [both/all] N tests cases with M assertions. +void printTotals(std::ostream& out, const Totals& totals) { + if (totals.testCases.total() == 0) { + out << "No tests ran."; + } else if (totals.testCases.failed == totals.testCases.total()) { + Colour colour(Colour::ResultError); + const std::string qualify_assertions_failed = + totals.assertions.failed == totals.assertions.total() ? + bothOrAll(totals.assertions.failed) : std::string(); + out << + "Failed " << bothOrAll(totals.testCases.failed) + << pluralise(totals.testCases.failed, "test case") << ", " + "failed " << qualify_assertions_failed << + pluralise(totals.assertions.failed, "assertion") << '.'; + } else if (totals.assertions.total() == 0) { + out << + "Passed " << bothOrAll(totals.testCases.total()) + << pluralise(totals.testCases.total(), "test case") + << " (no assertions)."; + } else if (totals.assertions.failed) { + Colour colour(Colour::ResultError); + out << + "Failed " << pluralise(totals.testCases.failed, "test case") << ", " + "failed " << pluralise(totals.assertions.failed, "assertion") << '.'; + } else { + Colour colour(Colour::ResultSuccess); + out << + "Passed " << bothOrAll(totals.testCases.passed) + << pluralise(totals.testCases.passed, "test case") << + " with " << pluralise(totals.assertions.passed, "assertion") << '.'; + } +} + +// Implementation of CompactReporter formatting +class AssertionPrinter { +public: + AssertionPrinter& operator= (AssertionPrinter const&) = delete; + AssertionPrinter(AssertionPrinter const&) = delete; + AssertionPrinter(std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages) + : stream(_stream) + , result(_stats.assertionResult) + , messages(_stats.infoMessages) + , itMessage(_stats.infoMessages.begin()) + , printInfoMessages(_printInfoMessages) {} + + void print() { + printSourceInfo(); + + itMessage = messages.begin(); + + switch (result.getResultType()) { + case ResultWas::Ok: + printResultType(Colour::ResultSuccess, passedString()); + printOriginalExpression(); + printReconstructedExpression(); + if (!result.hasExpression()) + printRemainingMessages(Colour::None); + else + printRemainingMessages(); + break; + case ResultWas::ExpressionFailed: + if (result.isOk()) + printResultType(Colour::ResultSuccess, failedString() + std::string(" - but was ok")); + else + printResultType(Colour::Error, failedString()); + printOriginalExpression(); + printReconstructedExpression(); + printRemainingMessages(); + break; + case ResultWas::ThrewException: + printResultType(Colour::Error, failedString()); + printIssue("unexpected exception with message:"); + printMessage(); + printExpressionWas(); + printRemainingMessages(); + break; + case ResultWas::FatalErrorCondition: + printResultType(Colour::Error, failedString()); + printIssue("fatal error condition with message:"); + printMessage(); + printExpressionWas(); + printRemainingMessages(); + break; + case ResultWas::DidntThrowException: + printResultType(Colour::Error, failedString()); + printIssue("expected exception, got none"); + printExpressionWas(); + printRemainingMessages(); + break; + case ResultWas::Info: + printResultType(Colour::None, "info"); + printMessage(); + printRemainingMessages(); + break; + case ResultWas::Warning: + printResultType(Colour::None, "warning"); + printMessage(); + printRemainingMessages(); + break; + case ResultWas::ExplicitFailure: + printResultType(Colour::Error, failedString()); + printIssue("explicitly"); + printRemainingMessages(Colour::None); + break; + // These cases are here to prevent compiler warnings + case ResultWas::Unknown: + case ResultWas::FailureBit: + case ResultWas::Exception: + printResultType(Colour::Error, "** internal error **"); + break; + } + } + +private: + void printSourceInfo() const { + Colour colourGuard(Colour::FileName); + stream << result.getSourceInfo() << ':'; + } + + void printResultType(Colour::Code colour, std::string const& passOrFail) const { + if (!passOrFail.empty()) { + { + Colour colourGuard(colour); + stream << ' ' << passOrFail; + } + stream << ':'; + } + } + + void printIssue(std::string const& issue) const { + stream << ' ' << issue; + } + + void printExpressionWas() { + if (result.hasExpression()) { + stream << ';'; + { + Colour colour(dimColour()); + stream << " expression was:"; + } + printOriginalExpression(); + } + } + + void printOriginalExpression() const { + if (result.hasExpression()) { + stream << ' ' << result.getExpression(); + } + } + + void printReconstructedExpression() const { + if (result.hasExpandedExpression()) { + { + Colour colour(dimColour()); + stream << " for: "; + } + stream << result.getExpandedExpression(); + } + } + + void printMessage() { + if (itMessage != messages.end()) { + stream << " '" << itMessage->message << '\''; + ++itMessage; + } + } + + void printRemainingMessages(Colour::Code colour = dimColour()) { + if (itMessage == messages.end()) + return; + + // using messages.end() directly yields (or auto) compilation error: + std::vector::const_iterator itEnd = messages.end(); + const std::size_t N = static_cast(std::distance(itMessage, itEnd)); + + { + Colour colourGuard(colour); + stream << " with " << pluralise(N, "message") << ':'; + } + + for (; itMessage != itEnd; ) { + // If this assertion is a warning ignore any INFO messages + if (printInfoMessages || itMessage->type != ResultWas::Info) { + stream << " '" << itMessage->message << '\''; + if (++itMessage != itEnd) { + Colour colourGuard(dimColour()); + stream << " and"; + } + } + } + } + +private: + std::ostream& stream; + AssertionResult const& result; + std::vector messages; + std::vector::const_iterator itMessage; + bool printInfoMessages; +}; + +} // anon namespace + + std::string CompactReporter::getDescription() { + return "Reports test results on a single line, suitable for IDEs"; + } + + ReporterPreferences CompactReporter::getPreferences() const { + ReporterPreferences prefs; + prefs.shouldRedirectStdOut = false; + return prefs; + } + + void CompactReporter::noMatchingTestCases( std::string const& spec ) { + stream << "No test cases matched '" << spec << '\'' << std::endl; + } + + void CompactReporter::assertionStarting( AssertionInfo const& ) {} + + bool CompactReporter::assertionEnded( AssertionStats const& _assertionStats ) { + AssertionResult const& result = _assertionStats.assertionResult; + + bool printInfoMessages = true; + + // Drop out if result was successful and we're not printing those + if( !m_config->includeSuccessfulResults() && result.isOk() ) { + if( result.getResultType() != ResultWas::Warning ) + return false; + printInfoMessages = false; + } + + AssertionPrinter printer( stream, _assertionStats, printInfoMessages ); + printer.print(); + + stream << std::endl; + return true; + } + + void CompactReporter::sectionEnded(SectionStats const& _sectionStats) { + if (m_config->showDurations() == ShowDurations::Always) { + stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl; + } + } + + void CompactReporter::testRunEnded( TestRunStats const& _testRunStats ) { + printTotals( stream, _testRunStats.totals ); + stream << '\n' << std::endl; + StreamingReporterBase::testRunEnded( _testRunStats ); + } + + CompactReporter::~CompactReporter() {} + + CATCH_REGISTER_REPORTER( "compact", CompactReporter ) + +} // end namespace Catch +// end catch_reporter_compact.cpp +// start catch_reporter_console.cpp + +#include +#include + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch + // Note that 4062 (not all labels are handled + // and default is missing) is enabled +#endif + +namespace Catch { + +namespace { + +// Formatter impl for ConsoleReporter +class ConsoleAssertionPrinter { +public: + ConsoleAssertionPrinter& operator= (ConsoleAssertionPrinter const&) = delete; + ConsoleAssertionPrinter(ConsoleAssertionPrinter const&) = delete; + ConsoleAssertionPrinter(std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages) + : stream(_stream), + stats(_stats), + result(_stats.assertionResult), + colour(Colour::None), + message(result.getMessage()), + messages(_stats.infoMessages), + printInfoMessages(_printInfoMessages) { + switch (result.getResultType()) { + case ResultWas::Ok: + colour = Colour::Success; + passOrFail = "PASSED"; + //if( result.hasMessage() ) + if (_stats.infoMessages.size() == 1) + messageLabel = "with message"; + if (_stats.infoMessages.size() > 1) + messageLabel = "with messages"; + break; + case ResultWas::ExpressionFailed: + if (result.isOk()) { + colour = Colour::Success; + passOrFail = "FAILED - but was ok"; + } else { + colour = Colour::Error; + passOrFail = "FAILED"; + } + if (_stats.infoMessages.size() == 1) + messageLabel = "with message"; + if (_stats.infoMessages.size() > 1) + messageLabel = "with messages"; + break; + case ResultWas::ThrewException: + colour = Colour::Error; + passOrFail = "FAILED"; + messageLabel = "due to unexpected exception with "; + if (_stats.infoMessages.size() == 1) + messageLabel += "message"; + if (_stats.infoMessages.size() > 1) + messageLabel += "messages"; + break; + case ResultWas::FatalErrorCondition: + colour = Colour::Error; + passOrFail = "FAILED"; + messageLabel = "due to a fatal error condition"; + break; + case ResultWas::DidntThrowException: + colour = Colour::Error; + passOrFail = "FAILED"; + messageLabel = "because no exception was thrown where one was expected"; + break; + case ResultWas::Info: + messageLabel = "info"; + break; + case ResultWas::Warning: + messageLabel = "warning"; + break; + case ResultWas::ExplicitFailure: + passOrFail = "FAILED"; + colour = Colour::Error; + if (_stats.infoMessages.size() == 1) + messageLabel = "explicitly with message"; + if (_stats.infoMessages.size() > 1) + messageLabel = "explicitly with messages"; + break; + // These cases are here to prevent compiler warnings + case ResultWas::Unknown: + case ResultWas::FailureBit: + case ResultWas::Exception: + passOrFail = "** internal error **"; + colour = Colour::Error; + break; + } + } + + void print() const { + printSourceInfo(); + if (stats.totals.assertions.total() > 0) { + if (result.isOk()) + stream << '\n'; + printResultType(); + printOriginalExpression(); + printReconstructedExpression(); + } else { + stream << '\n'; + } + printMessage(); + } + +private: + void printResultType() const { + if (!passOrFail.empty()) { + Colour colourGuard(colour); + stream << passOrFail << ":\n"; + } + } + void printOriginalExpression() const { + if (result.hasExpression()) { + Colour colourGuard(Colour::OriginalExpression); + stream << " "; + stream << result.getExpressionInMacro(); + stream << '\n'; + } + } + void printReconstructedExpression() const { + if (result.hasExpandedExpression()) { + stream << "with expansion:\n"; + Colour colourGuard(Colour::ReconstructedExpression); + stream << Column(result.getExpandedExpression()).indent(2) << '\n'; + } + } + void printMessage() const { + if (!messageLabel.empty()) + stream << messageLabel << ':' << '\n'; + for (auto const& msg : messages) { + // If this assertion is a warning ignore any INFO messages + if (printInfoMessages || msg.type != ResultWas::Info) + stream << Column(msg.message).indent(2) << '\n'; + } + } + void printSourceInfo() const { + Colour colourGuard(Colour::FileName); + stream << result.getSourceInfo() << ": "; + } + + std::ostream& stream; + AssertionStats const& stats; + AssertionResult const& result; + Colour::Code colour; + std::string passOrFail; + std::string messageLabel; + std::string message; + std::vector messages; + bool printInfoMessages; +}; + +std::size_t makeRatio(std::size_t number, std::size_t total) { + std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number / total : 0; + return (ratio == 0 && number > 0) ? 1 : ratio; +} + +std::size_t& findMax(std::size_t& i, std::size_t& j, std::size_t& k) { + if (i > j && i > k) + return i; + else if (j > k) + return j; + else + return k; +} + +struct ColumnInfo { + enum Justification { Left, Right }; + std::string name; + int width; + Justification justification; +}; +struct ColumnBreak {}; +struct RowBreak {}; + +class Duration { + enum class Unit { + Auto, + Nanoseconds, + Microseconds, + Milliseconds, + Seconds, + Minutes + }; + static const uint64_t s_nanosecondsInAMicrosecond = 1000; + static const uint64_t s_nanosecondsInAMillisecond = 1000 * s_nanosecondsInAMicrosecond; + static const uint64_t s_nanosecondsInASecond = 1000 * s_nanosecondsInAMillisecond; + static const uint64_t s_nanosecondsInAMinute = 60 * s_nanosecondsInASecond; + + uint64_t m_inNanoseconds; + Unit m_units; + +public: + explicit Duration(uint64_t inNanoseconds, Unit units = Unit::Auto) + : m_inNanoseconds(inNanoseconds), + m_units(units) { + if (m_units == Unit::Auto) { + if (m_inNanoseconds < s_nanosecondsInAMicrosecond) + m_units = Unit::Nanoseconds; + else if (m_inNanoseconds < s_nanosecondsInAMillisecond) + m_units = Unit::Microseconds; + else if (m_inNanoseconds < s_nanosecondsInASecond) + m_units = Unit::Milliseconds; + else if (m_inNanoseconds < s_nanosecondsInAMinute) + m_units = Unit::Seconds; + else + m_units = Unit::Minutes; + } + + } + + auto value() const -> double { + switch (m_units) { + case Unit::Microseconds: + return m_inNanoseconds / static_cast(s_nanosecondsInAMicrosecond); + case Unit::Milliseconds: + return m_inNanoseconds / static_cast(s_nanosecondsInAMillisecond); + case Unit::Seconds: + return m_inNanoseconds / static_cast(s_nanosecondsInASecond); + case Unit::Minutes: + return m_inNanoseconds / static_cast(s_nanosecondsInAMinute); + default: + return static_cast(m_inNanoseconds); + } + } + auto unitsAsString() const -> std::string { + switch (m_units) { + case Unit::Nanoseconds: + return "ns"; + case Unit::Microseconds: + return "µs"; + case Unit::Milliseconds: + return "ms"; + case Unit::Seconds: + return "s"; + case Unit::Minutes: + return "m"; + default: + return "** internal error **"; + } + + } + friend auto operator << (std::ostream& os, Duration const& duration) -> std::ostream& { + return os << duration.value() << " " << duration.unitsAsString(); + } +}; +} // end anon namespace + +class TablePrinter { + std::ostream& m_os; + std::vector m_columnInfos; + std::ostringstream m_oss; + int m_currentColumn = -1; + bool m_isOpen = false; + +public: + TablePrinter( std::ostream& os, std::vector columnInfos ) + : m_os( os ), + m_columnInfos( std::move( columnInfos ) ) {} + + auto columnInfos() const -> std::vector const& { + return m_columnInfos; + } + + void open() { + if (!m_isOpen) { + m_isOpen = true; + *this << RowBreak(); + for (auto const& info : m_columnInfos) + *this << info.name << ColumnBreak(); + *this << RowBreak(); + m_os << Catch::getLineOfChars<'-'>() << "\n"; + } + } + void close() { + if (m_isOpen) { + *this << RowBreak(); + m_os << std::endl; + m_isOpen = false; + } + } + + template + friend TablePrinter& operator << (TablePrinter& tp, T const& value) { + tp.m_oss << value; + return tp; + } + + friend TablePrinter& operator << (TablePrinter& tp, ColumnBreak) { + auto colStr = tp.m_oss.str(); + // This takes account of utf8 encodings + auto strSize = Catch::StringRef(colStr).numberOfCharacters(); + tp.m_oss.str(""); + tp.open(); + if (tp.m_currentColumn == static_cast(tp.m_columnInfos.size() - 1)) { + tp.m_currentColumn = -1; + tp.m_os << "\n"; + } + tp.m_currentColumn++; + + auto colInfo = tp.m_columnInfos[tp.m_currentColumn]; + auto padding = (strSize + 2 < static_cast(colInfo.width)) + ? std::string(colInfo.width - (strSize + 2), ' ') + : std::string(); + if (colInfo.justification == ColumnInfo::Left) + tp.m_os << colStr << padding << " "; + else + tp.m_os << padding << colStr << " "; + return tp; + } + + friend TablePrinter& operator << (TablePrinter& tp, RowBreak) { + if (tp.m_currentColumn > 0) { + tp.m_os << "\n"; + tp.m_currentColumn = -1; + } + return tp; + } +}; + +ConsoleReporter::ConsoleReporter(ReporterConfig const& config) + : StreamingReporterBase(config), + m_tablePrinter(new TablePrinter(config.stream(), + { + { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 32, ColumnInfo::Left }, + { "iters", 8, ColumnInfo::Right }, + { "elapsed ns", 14, ColumnInfo::Right }, + { "average", 14, ColumnInfo::Right } + })) {} +ConsoleReporter::~ConsoleReporter() = default; + +std::string ConsoleReporter::getDescription() { + return "Reports test results as plain lines of text"; +} + +void ConsoleReporter::noMatchingTestCases(std::string const& spec) { + stream << "No test cases matched '" << spec << '\'' << std::endl; +} + +void ConsoleReporter::assertionStarting(AssertionInfo const&) {} + +bool ConsoleReporter::assertionEnded(AssertionStats const& _assertionStats) { + AssertionResult const& result = _assertionStats.assertionResult; + + bool includeResults = m_config->includeSuccessfulResults() || !result.isOk(); + + // Drop out if result was successful but we're not printing them. + if (!includeResults && result.getResultType() != ResultWas::Warning) + return false; + + lazyPrint(); + + ConsoleAssertionPrinter printer(stream, _assertionStats, includeResults); + printer.print(); + stream << std::endl; + return true; +} + +void ConsoleReporter::sectionStarting(SectionInfo const& _sectionInfo) { + m_headerPrinted = false; + StreamingReporterBase::sectionStarting(_sectionInfo); +} +void ConsoleReporter::sectionEnded(SectionStats const& _sectionStats) { + m_tablePrinter->close(); + if (_sectionStats.missingAssertions) { + lazyPrint(); + Colour colour(Colour::ResultError); + if (m_sectionStack.size() > 1) + stream << "\nNo assertions in section"; + else + stream << "\nNo assertions in test case"; + stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl; + } + if (m_config->showDurations() == ShowDurations::Always) { + stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl; + } + if (m_headerPrinted) { + m_headerPrinted = false; + } + StreamingReporterBase::sectionEnded(_sectionStats); +} + +void ConsoleReporter::benchmarkStarting(BenchmarkInfo const& info) { + lazyPrintWithoutClosingBenchmarkTable(); + + auto nameCol = Column( info.name ).width( static_cast( m_tablePrinter->columnInfos()[0].width - 2 ) ); + + bool firstLine = true; + for (auto line : nameCol) { + if (!firstLine) + (*m_tablePrinter) << ColumnBreak() << ColumnBreak() << ColumnBreak(); + else + firstLine = false; + + (*m_tablePrinter) << line << ColumnBreak(); + } +} +void ConsoleReporter::benchmarkEnded(BenchmarkStats const& stats) { + Duration average(stats.elapsedTimeInNanoseconds / stats.iterations); + (*m_tablePrinter) + << stats.iterations << ColumnBreak() + << stats.elapsedTimeInNanoseconds << ColumnBreak() + << average << ColumnBreak(); +} + +void ConsoleReporter::testCaseEnded(TestCaseStats const& _testCaseStats) { + m_tablePrinter->close(); + StreamingReporterBase::testCaseEnded(_testCaseStats); + m_headerPrinted = false; +} +void ConsoleReporter::testGroupEnded(TestGroupStats const& _testGroupStats) { + if (currentGroupInfo.used) { + printSummaryDivider(); + stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n"; + printTotals(_testGroupStats.totals); + stream << '\n' << std::endl; + } + StreamingReporterBase::testGroupEnded(_testGroupStats); +} +void ConsoleReporter::testRunEnded(TestRunStats const& _testRunStats) { + printTotalsDivider(_testRunStats.totals); + printTotals(_testRunStats.totals); + stream << std::endl; + StreamingReporterBase::testRunEnded(_testRunStats); +} + +void ConsoleReporter::lazyPrint() { + + m_tablePrinter->close(); + lazyPrintWithoutClosingBenchmarkTable(); +} + +void ConsoleReporter::lazyPrintWithoutClosingBenchmarkTable() { + + if (!currentTestRunInfo.used) + lazyPrintRunInfo(); + if (!currentGroupInfo.used) + lazyPrintGroupInfo(); + + if (!m_headerPrinted) { + printTestCaseAndSectionHeader(); + m_headerPrinted = true; + } +} +void ConsoleReporter::lazyPrintRunInfo() { + stream << '\n' << getLineOfChars<'~'>() << '\n'; + Colour colour(Colour::SecondaryText); + stream << currentTestRunInfo->name + << " is a Catch v" << libraryVersion() << " host application.\n" + << "Run with -? for options\n\n"; + + if (m_config->rngSeed() != 0) + stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n"; + + currentTestRunInfo.used = true; +} +void ConsoleReporter::lazyPrintGroupInfo() { + if (!currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1) { + printClosedHeader("Group: " + currentGroupInfo->name); + currentGroupInfo.used = true; + } +} +void ConsoleReporter::printTestCaseAndSectionHeader() { + assert(!m_sectionStack.empty()); + printOpenHeader(currentTestCaseInfo->name); + + if (m_sectionStack.size() > 1) { + Colour colourGuard(Colour::Headers); + + auto + it = m_sectionStack.begin() + 1, // Skip first section (test case) + itEnd = m_sectionStack.end(); + for (; it != itEnd; ++it) + printHeaderString(it->name, 2); + } + + SourceLineInfo lineInfo = m_sectionStack.back().lineInfo; + + if (!lineInfo.empty()) { + stream << getLineOfChars<'-'>() << '\n'; + Colour colourGuard(Colour::FileName); + stream << lineInfo << '\n'; + } + stream << getLineOfChars<'.'>() << '\n' << std::endl; +} + +void ConsoleReporter::printClosedHeader(std::string const& _name) { + printOpenHeader(_name); + stream << getLineOfChars<'.'>() << '\n'; +} +void ConsoleReporter::printOpenHeader(std::string const& _name) { + stream << getLineOfChars<'-'>() << '\n'; + { + Colour colourGuard(Colour::Headers); + printHeaderString(_name); + } +} + +// if string has a : in first line will set indent to follow it on +// subsequent lines +void ConsoleReporter::printHeaderString(std::string const& _string, std::size_t indent) { + std::size_t i = _string.find(": "); + if (i != std::string::npos) + i += 2; + else + i = 0; + stream << Column(_string).indent(indent + i).initialIndent(indent) << '\n'; +} + +struct SummaryColumn { + + SummaryColumn( std::string _label, Colour::Code _colour ) + : label( std::move( _label ) ), + colour( _colour ) {} + SummaryColumn addRow( std::size_t count ) { + ReusableStringStream rss; + rss << count; + std::string row = rss.str(); + for (auto& oldRow : rows) { + while (oldRow.size() < row.size()) + oldRow = ' ' + oldRow; + while (oldRow.size() > row.size()) + row = ' ' + row; + } + rows.push_back(row); + return *this; + } + + std::string label; + Colour::Code colour; + std::vector rows; + +}; + +void ConsoleReporter::printTotals( Totals const& totals ) { + if (totals.testCases.total() == 0) { + stream << Colour(Colour::Warning) << "No tests ran\n"; + } else if (totals.assertions.total() > 0 && totals.testCases.allPassed()) { + stream << Colour(Colour::ResultSuccess) << "All tests passed"; + stream << " (" + << pluralise(totals.assertions.passed, "assertion") << " in " + << pluralise(totals.testCases.passed, "test case") << ')' + << '\n'; + } else { + + std::vector columns; + columns.push_back(SummaryColumn("", Colour::None) + .addRow(totals.testCases.total()) + .addRow(totals.assertions.total())); + columns.push_back(SummaryColumn("passed", Colour::Success) + .addRow(totals.testCases.passed) + .addRow(totals.assertions.passed)); + columns.push_back(SummaryColumn("failed", Colour::ResultError) + .addRow(totals.testCases.failed) + .addRow(totals.assertions.failed)); + columns.push_back(SummaryColumn("failed as expected", Colour::ResultExpectedFailure) + .addRow(totals.testCases.failedButOk) + .addRow(totals.assertions.failedButOk)); + + printSummaryRow("test cases", columns, 0); + printSummaryRow("assertions", columns, 1); + } +} +void ConsoleReporter::printSummaryRow(std::string const& label, std::vector const& cols, std::size_t row) { + for (auto col : cols) { + std::string value = col.rows[row]; + if (col.label.empty()) { + stream << label << ": "; + if (value != "0") + stream << value; + else + stream << Colour(Colour::Warning) << "- none -"; + } else if (value != "0") { + stream << Colour(Colour::LightGrey) << " | "; + stream << Colour(col.colour) + << value << ' ' << col.label; + } + } + stream << '\n'; +} + +void ConsoleReporter::printTotalsDivider(Totals const& totals) { + if (totals.testCases.total() > 0) { + std::size_t failedRatio = makeRatio(totals.testCases.failed, totals.testCases.total()); + std::size_t failedButOkRatio = makeRatio(totals.testCases.failedButOk, totals.testCases.total()); + std::size_t passedRatio = makeRatio(totals.testCases.passed, totals.testCases.total()); + while (failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH - 1) + findMax(failedRatio, failedButOkRatio, passedRatio)++; + while (failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH - 1) + findMax(failedRatio, failedButOkRatio, passedRatio)--; + + stream << Colour(Colour::Error) << std::string(failedRatio, '='); + stream << Colour(Colour::ResultExpectedFailure) << std::string(failedButOkRatio, '='); + if (totals.testCases.allPassed()) + stream << Colour(Colour::ResultSuccess) << std::string(passedRatio, '='); + else + stream << Colour(Colour::Success) << std::string(passedRatio, '='); + } else { + stream << Colour(Colour::Warning) << std::string(CATCH_CONFIG_CONSOLE_WIDTH - 1, '='); + } + stream << '\n'; +} +void ConsoleReporter::printSummaryDivider() { + stream << getLineOfChars<'-'>() << '\n'; +} + +CATCH_REGISTER_REPORTER("console", ConsoleReporter) + +} // end namespace Catch + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif +// end catch_reporter_console.cpp +// start catch_reporter_junit.cpp + +#include +#include +#include +#include + +namespace Catch { + + namespace { + std::string getCurrentTimestamp() { + // Beware, this is not reentrant because of backward compatibility issues + // Also, UTC only, again because of backward compatibility (%z is C++11) + time_t rawtime; + std::time(&rawtime); + auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); + +#ifdef _MSC_VER + std::tm timeInfo = {}; + gmtime_s(&timeInfo, &rawtime); +#else + std::tm* timeInfo; + timeInfo = std::gmtime(&rawtime); +#endif + + char timeStamp[timeStampSize]; + const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; + +#ifdef _MSC_VER + std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); +#else + std::strftime(timeStamp, timeStampSize, fmt, timeInfo); +#endif + return std::string(timeStamp); + } + + std::string fileNameTag(const std::vector &tags) { + auto it = std::find_if(begin(tags), + end(tags), + [] (std::string const& tag) {return tag.front() == '#'; }); + if (it != tags.end()) + return it->substr(1); + return std::string(); + } + } // anonymous namespace + + JunitReporter::JunitReporter( ReporterConfig const& _config ) + : CumulativeReporterBase( _config ), + xml( _config.stream() ) + { + m_reporterPrefs.shouldRedirectStdOut = true; + } + + JunitReporter::~JunitReporter() {}; + + std::string JunitReporter::getDescription() { + return "Reports test results in an XML format that looks like Ant's junitreport target"; + } + + void JunitReporter::noMatchingTestCases( std::string const& /*spec*/ ) {} + + void JunitReporter::testRunStarting( TestRunInfo const& runInfo ) { + CumulativeReporterBase::testRunStarting( runInfo ); + xml.startElement( "testsuites" ); + } + + void JunitReporter::testGroupStarting( GroupInfo const& groupInfo ) { + suiteTimer.start(); + stdOutForSuite.clear(); + stdErrForSuite.clear(); + unexpectedExceptions = 0; + CumulativeReporterBase::testGroupStarting( groupInfo ); + } + + void JunitReporter::testCaseStarting( TestCaseInfo const& testCaseInfo ) { + m_okToFail = testCaseInfo.okToFail(); + } + + bool JunitReporter::assertionEnded( AssertionStats const& assertionStats ) { + if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException && !m_okToFail ) + unexpectedExceptions++; + return CumulativeReporterBase::assertionEnded( assertionStats ); + } + + void JunitReporter::testCaseEnded( TestCaseStats const& testCaseStats ) { + stdOutForSuite += testCaseStats.stdOut; + stdErrForSuite += testCaseStats.stdErr; + CumulativeReporterBase::testCaseEnded( testCaseStats ); + } + + void JunitReporter::testGroupEnded( TestGroupStats const& testGroupStats ) { + double suiteTime = suiteTimer.getElapsedSeconds(); + CumulativeReporterBase::testGroupEnded( testGroupStats ); + writeGroup( *m_testGroups.back(), suiteTime ); + } + + void JunitReporter::testRunEndedCumulative() { + xml.endElement(); + } + + void JunitReporter::writeGroup( TestGroupNode const& groupNode, double suiteTime ) { + XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" ); + TestGroupStats const& stats = groupNode.value; + xml.writeAttribute( "name", stats.groupInfo.name ); + xml.writeAttribute( "errors", unexpectedExceptions ); + xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions ); + xml.writeAttribute( "tests", stats.totals.assertions.total() ); + xml.writeAttribute( "hostname", "tbd" ); // !TBD + if( m_config->showDurations() == ShowDurations::Never ) + xml.writeAttribute( "time", "" ); + else + xml.writeAttribute( "time", suiteTime ); + xml.writeAttribute( "timestamp", getCurrentTimestamp() ); + + // Write test cases + for( auto const& child : groupNode.children ) + writeTestCase( *child ); + + xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite ), false ); + xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite ), false ); + } + + void JunitReporter::writeTestCase( TestCaseNode const& testCaseNode ) { + TestCaseStats const& stats = testCaseNode.value; + + // All test cases have exactly one section - which represents the + // test case itself. That section may have 0-n nested sections + assert( testCaseNode.children.size() == 1 ); + SectionNode const& rootSection = *testCaseNode.children.front(); + + std::string className = stats.testInfo.className; + + if( className.empty() ) { + className = fileNameTag(stats.testInfo.tags); + if ( className.empty() ) + className = "global"; + } + + if ( !m_config->name().empty() ) + className = m_config->name() + "." + className; + + writeSection( className, "", rootSection ); + } + + void JunitReporter::writeSection( std::string const& className, + std::string const& rootName, + SectionNode const& sectionNode ) { + std::string name = trim( sectionNode.stats.sectionInfo.name ); + if( !rootName.empty() ) + name = rootName + '/' + name; + + if( !sectionNode.assertions.empty() || + !sectionNode.stdOut.empty() || + !sectionNode.stdErr.empty() ) { + XmlWriter::ScopedElement e = xml.scopedElement( "testcase" ); + if( className.empty() ) { + xml.writeAttribute( "classname", name ); + xml.writeAttribute( "name", "root" ); + } + else { + xml.writeAttribute( "classname", className ); + xml.writeAttribute( "name", name ); + } + xml.writeAttribute( "time", ::Catch::Detail::stringify( sectionNode.stats.durationInSeconds ) ); + + writeAssertions( sectionNode ); + + if( !sectionNode.stdOut.empty() ) + xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false ); + if( !sectionNode.stdErr.empty() ) + xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false ); + } + for( auto const& childNode : sectionNode.childSections ) + if( className.empty() ) + writeSection( name, "", *childNode ); + else + writeSection( className, name, *childNode ); + } + + void JunitReporter::writeAssertions( SectionNode const& sectionNode ) { + for( auto const& assertion : sectionNode.assertions ) + writeAssertion( assertion ); + } + + void JunitReporter::writeAssertion( AssertionStats const& stats ) { + AssertionResult const& result = stats.assertionResult; + if( !result.isOk() ) { + std::string elementName; + switch( result.getResultType() ) { + case ResultWas::ThrewException: + case ResultWas::FatalErrorCondition: + elementName = "error"; + break; + case ResultWas::ExplicitFailure: + elementName = "failure"; + break; + case ResultWas::ExpressionFailed: + elementName = "failure"; + break; + case ResultWas::DidntThrowException: + elementName = "failure"; + break; + + // We should never see these here: + case ResultWas::Info: + case ResultWas::Warning: + case ResultWas::Ok: + case ResultWas::Unknown: + case ResultWas::FailureBit: + case ResultWas::Exception: + elementName = "internalError"; + break; + } + + XmlWriter::ScopedElement e = xml.scopedElement( elementName ); + + xml.writeAttribute( "message", result.getExpandedExpression() ); + xml.writeAttribute( "type", result.getTestMacroName() ); + + ReusableStringStream rss; + if( !result.getMessage().empty() ) + rss << result.getMessage() << '\n'; + for( auto const& msg : stats.infoMessages ) + if( msg.type == ResultWas::Info ) + rss << msg.message << '\n'; + + rss << "at " << result.getSourceInfo(); + xml.writeText( rss.str(), false ); + } + } + + CATCH_REGISTER_REPORTER( "junit", JunitReporter ) + +} // end namespace Catch +// end catch_reporter_junit.cpp +// start catch_reporter_multi.cpp + +namespace Catch { + + void MultipleReporters::add( IStreamingReporterPtr&& reporter ) { + m_reporters.push_back( std::move( reporter ) ); + } + + ReporterPreferences MultipleReporters::getPreferences() const { + return m_reporters[0]->getPreferences(); + } + + std::set MultipleReporters::getSupportedVerbosities() { + return std::set{ }; + } + + void MultipleReporters::noMatchingTestCases( std::string const& spec ) { + for( auto const& reporter : m_reporters ) + reporter->noMatchingTestCases( spec ); + } + + void MultipleReporters::benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) { + for( auto const& reporter : m_reporters ) + reporter->benchmarkStarting( benchmarkInfo ); + } + void MultipleReporters::benchmarkEnded( BenchmarkStats const& benchmarkStats ) { + for( auto const& reporter : m_reporters ) + reporter->benchmarkEnded( benchmarkStats ); + } + + void MultipleReporters::testRunStarting( TestRunInfo const& testRunInfo ) { + for( auto const& reporter : m_reporters ) + reporter->testRunStarting( testRunInfo ); + } + + void MultipleReporters::testGroupStarting( GroupInfo const& groupInfo ) { + for( auto const& reporter : m_reporters ) + reporter->testGroupStarting( groupInfo ); + } + + void MultipleReporters::testCaseStarting( TestCaseInfo const& testInfo ) { + for( auto const& reporter : m_reporters ) + reporter->testCaseStarting( testInfo ); + } + + void MultipleReporters::sectionStarting( SectionInfo const& sectionInfo ) { + for( auto const& reporter : m_reporters ) + reporter->sectionStarting( sectionInfo ); + } + + void MultipleReporters::assertionStarting( AssertionInfo const& assertionInfo ) { + for( auto const& reporter : m_reporters ) + reporter->assertionStarting( assertionInfo ); + } + + // The return value indicates if the messages buffer should be cleared: + bool MultipleReporters::assertionEnded( AssertionStats const& assertionStats ) { + bool clearBuffer = false; + for( auto const& reporter : m_reporters ) + clearBuffer |= reporter->assertionEnded( assertionStats ); + return clearBuffer; + } + + void MultipleReporters::sectionEnded( SectionStats const& sectionStats ) { + for( auto const& reporter : m_reporters ) + reporter->sectionEnded( sectionStats ); + } + + void MultipleReporters::testCaseEnded( TestCaseStats const& testCaseStats ) { + for( auto const& reporter : m_reporters ) + reporter->testCaseEnded( testCaseStats ); + } + + void MultipleReporters::testGroupEnded( TestGroupStats const& testGroupStats ) { + for( auto const& reporter : m_reporters ) + reporter->testGroupEnded( testGroupStats ); + } + + void MultipleReporters::testRunEnded( TestRunStats const& testRunStats ) { + for( auto const& reporter : m_reporters ) + reporter->testRunEnded( testRunStats ); + } + + void MultipleReporters::skipTest( TestCaseInfo const& testInfo ) { + for( auto const& reporter : m_reporters ) + reporter->skipTest( testInfo ); + } + + bool MultipleReporters::isMulti() const { + return true; + } + +} // end namespace Catch +// end catch_reporter_multi.cpp +// start catch_reporter_xml.cpp + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch + // Note that 4062 (not all labels are handled + // and default is missing) is enabled +#endif + +namespace Catch { + XmlReporter::XmlReporter( ReporterConfig const& _config ) + : StreamingReporterBase( _config ), + m_xml(_config.stream()) + { + m_reporterPrefs.shouldRedirectStdOut = true; + } + + XmlReporter::~XmlReporter() = default; + + std::string XmlReporter::getDescription() { + return "Reports test results as an XML document"; + } + + std::string XmlReporter::getStylesheetRef() const { + return std::string(); + } + + void XmlReporter::writeSourceInfo( SourceLineInfo const& sourceInfo ) { + m_xml + .writeAttribute( "filename", sourceInfo.file ) + .writeAttribute( "line", sourceInfo.line ); + } + + void XmlReporter::noMatchingTestCases( std::string const& s ) { + StreamingReporterBase::noMatchingTestCases( s ); + } + + void XmlReporter::testRunStarting( TestRunInfo const& testInfo ) { + StreamingReporterBase::testRunStarting( testInfo ); + std::string stylesheetRef = getStylesheetRef(); + if( !stylesheetRef.empty() ) + m_xml.writeStylesheetRef( stylesheetRef ); + m_xml.startElement( "Catch" ); + if( !m_config->name().empty() ) + m_xml.writeAttribute( "name", m_config->name() ); + } + + void XmlReporter::testGroupStarting( GroupInfo const& groupInfo ) { + StreamingReporterBase::testGroupStarting( groupInfo ); + m_xml.startElement( "Group" ) + .writeAttribute( "name", groupInfo.name ); + } + + void XmlReporter::testCaseStarting( TestCaseInfo const& testInfo ) { + StreamingReporterBase::testCaseStarting(testInfo); + m_xml.startElement( "TestCase" ) + .writeAttribute( "name", trim( testInfo.name ) ) + .writeAttribute( "description", testInfo.description ) + .writeAttribute( "tags", testInfo.tagsAsString() ); + + writeSourceInfo( testInfo.lineInfo ); + + if ( m_config->showDurations() == ShowDurations::Always ) + m_testCaseTimer.start(); + m_xml.ensureTagClosed(); + } + + void XmlReporter::sectionStarting( SectionInfo const& sectionInfo ) { + StreamingReporterBase::sectionStarting( sectionInfo ); + if( m_sectionDepth++ > 0 ) { + m_xml.startElement( "Section" ) + .writeAttribute( "name", trim( sectionInfo.name ) ) + .writeAttribute( "description", sectionInfo.description ); + writeSourceInfo( sectionInfo.lineInfo ); + m_xml.ensureTagClosed(); + } + } + + void XmlReporter::assertionStarting( AssertionInfo const& ) { } + + bool XmlReporter::assertionEnded( AssertionStats const& assertionStats ) { + + AssertionResult const& result = assertionStats.assertionResult; + + bool includeResults = m_config->includeSuccessfulResults() || !result.isOk(); + + if( includeResults || result.getResultType() == ResultWas::Warning ) { + // Print any info messages in tags. + for( auto const& msg : assertionStats.infoMessages ) { + if( msg.type == ResultWas::Info && includeResults ) { + m_xml.scopedElement( "Info" ) + .writeText( msg.message ); + } else if ( msg.type == ResultWas::Warning ) { + m_xml.scopedElement( "Warning" ) + .writeText( msg.message ); + } + } + } + + // Drop out if result was successful but we're not printing them. + if( !includeResults && result.getResultType() != ResultWas::Warning ) + return true; + + // Print the expression if there is one. + if( result.hasExpression() ) { + m_xml.startElement( "Expression" ) + .writeAttribute( "success", result.succeeded() ) + .writeAttribute( "type", result.getTestMacroName() ); + + writeSourceInfo( result.getSourceInfo() ); + + m_xml.scopedElement( "Original" ) + .writeText( result.getExpression() ); + m_xml.scopedElement( "Expanded" ) + .writeText( result.getExpandedExpression() ); + } + + // And... Print a result applicable to each result type. + switch( result.getResultType() ) { + case ResultWas::ThrewException: + m_xml.startElement( "Exception" ); + writeSourceInfo( result.getSourceInfo() ); + m_xml.writeText( result.getMessage() ); + m_xml.endElement(); + break; + case ResultWas::FatalErrorCondition: + m_xml.startElement( "FatalErrorCondition" ); + writeSourceInfo( result.getSourceInfo() ); + m_xml.writeText( result.getMessage() ); + m_xml.endElement(); + break; + case ResultWas::Info: + m_xml.scopedElement( "Info" ) + .writeText( result.getMessage() ); + break; + case ResultWas::Warning: + // Warning will already have been written + break; + case ResultWas::ExplicitFailure: + m_xml.startElement( "Failure" ); + writeSourceInfo( result.getSourceInfo() ); + m_xml.writeText( result.getMessage() ); + m_xml.endElement(); + break; + default: + break; + } + + if( result.hasExpression() ) + m_xml.endElement(); + + return true; + } + + void XmlReporter::sectionEnded( SectionStats const& sectionStats ) { + StreamingReporterBase::sectionEnded( sectionStats ); + if( --m_sectionDepth > 0 ) { + XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" ); + e.writeAttribute( "successes", sectionStats.assertions.passed ); + e.writeAttribute( "failures", sectionStats.assertions.failed ); + e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk ); + + if ( m_config->showDurations() == ShowDurations::Always ) + e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds ); + + m_xml.endElement(); + } + } + + void XmlReporter::testCaseEnded( TestCaseStats const& testCaseStats ) { + StreamingReporterBase::testCaseEnded( testCaseStats ); + XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" ); + e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() ); + + if ( m_config->showDurations() == ShowDurations::Always ) + e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() ); + + if( !testCaseStats.stdOut.empty() ) + m_xml.scopedElement( "StdOut" ).writeText( trim( testCaseStats.stdOut ), false ); + if( !testCaseStats.stdErr.empty() ) + m_xml.scopedElement( "StdErr" ).writeText( trim( testCaseStats.stdErr ), false ); + + m_xml.endElement(); + } + + void XmlReporter::testGroupEnded( TestGroupStats const& testGroupStats ) { + StreamingReporterBase::testGroupEnded( testGroupStats ); + // TODO: Check testGroupStats.aborting and act accordingly. + m_xml.scopedElement( "OverallResults" ) + .writeAttribute( "successes", testGroupStats.totals.assertions.passed ) + .writeAttribute( "failures", testGroupStats.totals.assertions.failed ) + .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk ); + m_xml.endElement(); + } + + void XmlReporter::testRunEnded( TestRunStats const& testRunStats ) { + StreamingReporterBase::testRunEnded( testRunStats ); + m_xml.scopedElement( "OverallResults" ) + .writeAttribute( "successes", testRunStats.totals.assertions.passed ) + .writeAttribute( "failures", testRunStats.totals.assertions.failed ) + .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk ); + m_xml.endElement(); + } + + CATCH_REGISTER_REPORTER( "xml", XmlReporter ) + +} // end namespace Catch + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif +// end catch_reporter_xml.cpp + +namespace Catch { + LeakDetector leakDetector; +} + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// end catch_impl.hpp +#endif + +#ifdef CATCH_CONFIG_MAIN +// start catch_default_main.hpp + +#ifndef __OBJC__ + +#if defined(WIN32) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN) +// Standard C/C++ Win32 Unicode wmain entry point +extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) { +#else +// Standard C/C++ main entry point +int main (int argc, char * argv[]) { +#endif + + return Catch::Session().run( argc, argv ); +} + +#else // __OBJC__ + +// Objective-C entry point +int main (int argc, char * const argv[]) { +#if !CATCH_ARC_ENABLED + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; +#endif + + Catch::registerTestMethods(); + int result = Catch::Session().run( argc, (char**)argv ); + +#if !CATCH_ARC_ENABLED + [pool drain]; +#endif + + return result; +} + +#endif // __OBJC__ + +// end catch_default_main.hpp +#endif + +#if !defined(CATCH_CONFIG_IMPL_ONLY) + +#ifdef CLARA_CONFIG_MAIN_NOT_DEFINED +# undef CLARA_CONFIG_MAIN +#endif + +#if !defined(CATCH_CONFIG_DISABLE) +////// +// If this config identifier is defined then all CATCH macros are prefixed with CATCH_ +#ifdef CATCH_CONFIG_PREFIX_ALL + +#define CATCH_REQUIRE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define CATCH_REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) + +#define CATCH_REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, "", __VA_ARGS__ ) +#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) +#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr ) +#endif// CATCH_CONFIG_DISABLE_MATCHERS +#define CATCH_REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ ) + +#define CATCH_CHECK( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CATCH_CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) +#define CATCH_CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CATCH_CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CATCH_CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) + +#define CATCH_CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, "", __VA_ARGS__ ) +#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) +#define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define CATCH_CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) + +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) + +#define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS + +#define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg ) +#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) +#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << ::Catch::Detail::stringify(msg) ) + +#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) +#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) +#define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) +#define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) +#define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) + +#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE() + +// "BDD-style" convenience wrappers +#define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ ) +#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) +#define CATCH_GIVEN( desc ) CATCH_SECTION( std::string( "Given: ") + desc ) +#define CATCH_WHEN( desc ) CATCH_SECTION( std::string( " When: ") + desc ) +#define CATCH_AND_WHEN( desc ) CATCH_SECTION( std::string( " And: ") + desc ) +#define CATCH_THEN( desc ) CATCH_SECTION( std::string( " Then: ") + desc ) +#define CATCH_AND_THEN( desc ) CATCH_SECTION( std::string( " And: ") + desc ) + +// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required +#else + +#define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) + +#define REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) +#define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ ) + +#define CHECK( ... ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) +#define CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) + +#define CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) +#define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) + +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) + +#define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) +#endif // CATCH_CONFIG_DISABLE_MATCHERS + +#define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg ) +#define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) +#define CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << ::Catch::Detail::stringify(msg) ) + +#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) +#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) +#define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) +#define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) +#define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE() + +#endif + +#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) + +// "BDD-style" convenience wrappers +#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ ) +#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) + +#define GIVEN( desc ) SECTION( std::string(" Given: ") + desc ) +#define WHEN( desc ) SECTION( std::string(" When: ") + desc ) +#define AND_WHEN( desc ) SECTION( std::string("And when: ") + desc ) +#define THEN( desc ) SECTION( std::string(" Then: ") + desc ) +#define AND_THEN( desc ) SECTION( std::string(" And: ") + desc ) + +using Catch::Detail::Approx; + +#else +////// +// If this config identifier is defined then all CATCH macros are prefixed with CATCH_ +#ifdef CATCH_CONFIG_PREFIX_ALL + +#define CATCH_REQUIRE( ... ) (void)(0) +#define CATCH_REQUIRE_FALSE( ... ) (void)(0) + +#define CATCH_REQUIRE_THROWS( ... ) (void)(0) +#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0) +#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) (void)(0) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) +#endif// CATCH_CONFIG_DISABLE_MATCHERS +#define CATCH_REQUIRE_NOTHROW( ... ) (void)(0) + +#define CATCH_CHECK( ... ) (void)(0) +#define CATCH_CHECK_FALSE( ... ) (void)(0) +#define CATCH_CHECKED_IF( ... ) if (__VA_ARGS__) +#define CATCH_CHECKED_ELSE( ... ) if (!(__VA_ARGS__)) +#define CATCH_CHECK_NOFAIL( ... ) (void)(0) + +#define CATCH_CHECK_THROWS( ... ) (void)(0) +#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) (void)(0) +#define CATCH_CHECK_THROWS_WITH( expr, matcher ) (void)(0) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define CATCH_CHECK_NOTHROW( ... ) (void)(0) + +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CATCH_CHECK_THAT( arg, matcher ) (void)(0) + +#define CATCH_REQUIRE_THAT( arg, matcher ) (void)(0) +#endif // CATCH_CONFIG_DISABLE_MATCHERS + +#define CATCH_INFO( msg ) (void)(0) +#define CATCH_WARN( msg ) (void)(0) +#define CATCH_CAPTURE( msg ) (void)(0) + +#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) +#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) +#define CATCH_METHOD_AS_TEST_CASE( method, ... ) +#define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0) +#define CATCH_SECTION( ... ) +#define CATCH_FAIL( ... ) (void)(0) +#define CATCH_FAIL_CHECK( ... ) (void)(0) +#define CATCH_SUCCEED( ... ) (void)(0) + +#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) + +// "BDD-style" convenience wrappers +#define CATCH_SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) +#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), className ) +#define CATCH_GIVEN( desc ) +#define CATCH_WHEN( desc ) +#define CATCH_AND_WHEN( desc ) +#define CATCH_THEN( desc ) +#define CATCH_AND_THEN( desc ) + +// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required +#else + +#define REQUIRE( ... ) (void)(0) +#define REQUIRE_FALSE( ... ) (void)(0) + +#define REQUIRE_THROWS( ... ) (void)(0) +#define REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0) +#define REQUIRE_THROWS_WITH( expr, matcher ) (void)(0) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define REQUIRE_NOTHROW( ... ) (void)(0) + +#define CHECK( ... ) (void)(0) +#define CHECK_FALSE( ... ) (void)(0) +#define CHECKED_IF( ... ) if (__VA_ARGS__) +#define CHECKED_ELSE( ... ) if (!(__VA_ARGS__)) +#define CHECK_NOFAIL( ... ) (void)(0) + +#define CHECK_THROWS( ... ) (void)(0) +#define CHECK_THROWS_AS( expr, exceptionType ) (void)(0) +#define CHECK_THROWS_WITH( expr, matcher ) (void)(0) +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) +#endif // CATCH_CONFIG_DISABLE_MATCHERS +#define CHECK_NOTHROW( ... ) (void)(0) + +#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) +#define CHECK_THAT( arg, matcher ) (void)(0) + +#define REQUIRE_THAT( arg, matcher ) (void)(0) +#endif // CATCH_CONFIG_DISABLE_MATCHERS + +#define INFO( msg ) (void)(0) +#define WARN( msg ) (void)(0) +#define CAPTURE( msg ) (void)(0) + +#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) +#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) +#define METHOD_AS_TEST_CASE( method, ... ) +#define REGISTER_TEST_CASE( Function, ... ) (void)(0) +#define SECTION( ... ) +#define FAIL( ... ) (void)(0) +#define FAIL_CHECK( ... ) (void)(0) +#define SUCCEED( ... ) (void)(0) +#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) + +#endif + +#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) + +// "BDD-style" convenience wrappers +#define SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ) ) +#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), className ) + +#define GIVEN( desc ) +#define WHEN( desc ) +#define AND_WHEN( desc ) +#define THEN( desc ) +#define AND_THEN( desc ) + +using Catch::Detail::Approx; + +#endif + +#endif // ! CATCH_CONFIG_IMPL_ONLY + +// start catch_reenable_warnings.h + + +#ifdef __clang__ +# ifdef __ICC // icpc defines the __clang__ macro +# pragma warning(pop) +# else +# pragma clang diagnostic pop +# endif +#elif defined __GNUC__ +# pragma GCC diagnostic pop +#endif + +// end catch_reenable_warnings.h +// end catch.hpp +#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED + diff --git a/plugins/community/repos/DHE-Modules/test/runner/environment.cpp b/plugins/community/repos/DHE-Modules/test/runner/environment.cpp new file mode 100644 index 00000000..bf995bce --- /dev/null +++ b/plugins/community/repos/DHE-Modules/test/runner/environment.cpp @@ -0,0 +1,8 @@ +namespace rack { + +float sampleTime = 1.f/44100.f; + +float engineGetSampleTime() { + return sampleTime; +} +} diff --git a/plugins/community/repos/DHE-Modules/test/runner/main.cpp b/plugins/community/repos/DHE-Modules/test/runner/main.cpp new file mode 100644 index 00000000..f1fa3add --- /dev/null +++ b/plugins/community/repos/DHE-Modules/test/runner/main.cpp @@ -0,0 +1,2 @@ +#define CATCH_CONFIG_MAIN +#include "catch/catch.hpp" \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/test/stage-tests.cpp b/plugins/community/repos/DHE-Modules/test/stage-tests.cpp new file mode 100644 index 00000000..d7017375 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/test/stage-tests.cpp @@ -0,0 +1,6 @@ +#include +#include + +TEST_CASE("Stage Module") { + DHE::StageModule module{}; +} \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/test/swave-tests.cpp b/plugins/community/repos/DHE-Modules/test/swave-tests.cpp new file mode 100644 index 00000000..818e9ce0 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/test/swave-tests.cpp @@ -0,0 +1,6 @@ +#include "catch/catch.hpp" +#include "modules/swave-module.h" + +TEST_CASE("Swave Module") { + DHE::SwaveModule module{}; +} \ No newline at end of file diff --git a/plugins/community/repos/DHE-Modules/test/upstage-tests.cpp b/plugins/community/repos/DHE-Modules/test/upstage-tests.cpp new file mode 100644 index 00000000..da3e7a85 --- /dev/null +++ b/plugins/community/repos/DHE-Modules/test/upstage-tests.cpp @@ -0,0 +1,6 @@ +#include +#include + +TEST_CASE("Upstage Module") { + DHE::UpstageModule module{}; +} \ No newline at end of file diff --git a/plugins/community/repos/HetrickCV/src/BlankPanel.cpp b/plugins/community/repos/HetrickCV/src/BlankPanel.cpp index 472f3cec..39356aa4 100644 --- a/plugins/community/repos/HetrickCV/src/BlankPanel.cpp +++ b/plugins/community/repos/HetrickCV/src/BlankPanel.cpp @@ -189,4 +189,5 @@ using namespace rack_plugin_HetrickCV; RACK_PLUGIN_MODEL_INIT(HetrickCV, BlankPanel) { Model *modelBlankPanel = Model::create("HetrickCV", "BlankPanel", "Blank Panel"); + return modelBlankPanel; } diff --git a/plugins/community/repos/LOGinstruments/src/Compa.cpp b/plugins/community/repos/LOGinstruments/src/Compa.cpp index c05e1a2a..7570f343 100644 --- a/plugins/community/repos/LOGinstruments/src/Compa.cpp +++ b/plugins/community/repos/LOGinstruments/src/Compa.cpp @@ -83,5 +83,6 @@ using namespace rack_plugin_LOGinstruments; RACK_PLUGIN_MODEL_INIT(LOGinstruments, Compa) { Model *modelCompa = Model::create("LOGinstruments", "Compa", "Comparator", DIGITAL_TAG, QUANTIZER_TAG); + return modelCompa; } diff --git a/plugins/community/repos/Qwelk/src/Gate.cpp b/plugins/community/repos/Qwelk/src/Gate.cpp index 283adcbc..6f6caf87 100644 --- a/plugins/community/repos/Qwelk/src/Gate.cpp +++ b/plugins/community/repos/Qwelk/src/Gate.cpp @@ -69,4 +69,5 @@ using namespace rack_plugin_Qwelk; RACK_PLUGIN_MODEL_INIT(Qwelk, Gate) { Model *modelGate = Model::create( TOSTRING(SLUG), "Gate", "Gate", UTILITY_TAG, ATTENUATOR_TAG); + return modelGate; } diff --git a/plugins/community/repos/mscHack/LICENSE.txt b/plugins/community/repos/mscHack/LICENSE.txt new file mode 100644 index 00000000..f901edc3 --- /dev/null +++ b/plugins/community/repos/mscHack/LICENSE.txt @@ -0,0 +1,7 @@ +Copyright (c) 2017 Mark Schack + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/plugins/community/repos/mscHack/Makefile b/plugins/community/repos/mscHack/Makefile new file mode 100644 index 00000000..086d50fe --- /dev/null +++ b/plugins/community/repos/mscHack/Makefile @@ -0,0 +1,9 @@ +RACK_DIR ?= ../.. +SLUG = mscHack +VERSION = 0.6.2 + +FLAGS += -Idep/include +SOURCES += $(wildcard src/*.cpp) +DISTRIBUTABLES += $(wildcard LICENSE*) res + +include $(RACK_DIR)/plugin.mk \ No newline at end of file diff --git a/plugins/community/repos/mscHack/README.md b/plugins/community/repos/mscHack/README.md new file mode 100644 index 00000000..528af0cf --- /dev/null +++ b/plugins/community/repos/mscHack/README.md @@ -0,0 +1,56 @@ +# mscHack Plugins for VCV Rack 0.6.0 + +![screenshot](modules.PNG) + +# Updates +- 14 May 18 [v0.6.2] + - [NEW] "ENVY 9", a 9 channel envelope editor/generator + - All channels synced to an input beat + - 5 speed multipliers + - loop, reverse, ping pong, one shot and two shot modes + - each channel externally triggerable + - each channel external gated hold + - hand drawable patterns + - 24 Channel mixer + - Added pre-fader option for AUXs + - Menu option for Group out pre-mute, and 1.5x mixer gain + - Added pre EQ makeup gain, input signal was being attenuated + - ARP700 + -Added pattern copy; (while paused) Select pattern to copy, press copy button, press pattern to copy to + - SEQ 6x32 + -Copy now like Triad and Arp. Now you can copy patterns between channels + -Added two more output level knobs + -Added a pattern clear button + -improved random pattern generation + - Triad2 + -Now you can copy patterns between channels + +# Includes +- "ENVY 9", a 9 channel envelope editor/generator +- 4 Channel Master Clock +- 3 Channel 16 Step Programmable Sequencer. +- 6 Channel 32 Step Sequencer +- Mixer 1x4, 2x4 and 4x4 (with EQ, 4xAUX buses, and 2 x amplification ) +- Triad Sequencer (Type 2), with Independantly clocked channels +- Synth Drums +- 3 Channel Oscillator with Filter and Amp Envelope (latest has multi oscillator capability) +- Ping Pong Delay +- Compressor (a work in progress...) +- X Fade, 3 stereo channel cross fader +- ARP 700, 7 note arpeggiator. +- Maude 221 wave combiner +- Step Delay + +# Demo Vids +- 4 Channel Master Clock https://www.youtube.com/watch?v=hiQciS8ch5U +- Sequencer: https://www.youtube.com/watch?v=2PN0-UZhocA +- Mixer: https://www.youtube.com/watch?v=QOjSEM3mPqs +- Triad Sequencer https://www.youtube.com/watch?v=InOgQA91cs8 +- Triad Sequencer (Type 2) https://www.youtube.com/watch?v=NAza3lUqkkQ +- Synth Drums https://www.youtube.com/watch?v=zYrtJ2XsbTw +- Pong https://www.youtube.com/watch?v=hTsco8omRT0 +- 3 Channel OSC https://www.youtube.com/watch?v=BV9nWX9Izq0 +- Compressor https://www.youtube.com/watch?v=0F9KCk0IgFU +- X Fade https://www.youtube.com/watch?v=1NN4ly77nXo +- 6 x 32 trigger sequencer https://www.youtube.com/watch?v=S1PB-WaqXt4 +- ARP 700 quicky demo https://www.youtube.com/watch?v=ht9EwXmkDJI diff --git a/plugins/community/repos/mscHack/make.objects b/plugins/community/repos/mscHack/make.objects new file mode 100644 index 00000000..5bd2fdd8 --- /dev/null +++ b/plugins/community/repos/mscHack/make.objects @@ -0,0 +1,21 @@ +ALL_OBJ= \ + src/3Ch_Osc.o \ + src/ARP700.o \ + src/CLog.o \ + src/Compressor.o \ + src/MasterClockx4.o \ + src/Maude221.o \ + src/Mixer_1x4_Stereo.o \ + src/Mixer_24_4_4.o \ + src/Mixer_2x4_Stereo.o \ + src/Mixer_4x4_Stereo.o \ + src/mscHack.o \ + src/mscHack_Control_EnvelopeEdit.o \ + src/PingPong.o \ + src/Seq_3x16x16.o \ + src/SEQ_6x32x16.o \ + src/SEQ_Envelope_8.o \ + src/Seq_Triad2.o \ + src/StepDelay.o \ + src/SynthDrums.o \ + src/XFade.o diff --git a/plugins/community/repos/mscHack/makefile.msvc b/plugins/community/repos/mscHack/makefile.msvc new file mode 100644 index 00000000..5895c1ed --- /dev/null +++ b/plugins/community/repos/mscHack/makefile.msvc @@ -0,0 +1,7 @@ +SLUG=mscHack + +include ../../../../dep/yac/install_msvc.mk + +include make.objects + +include ../../../build_plugin.mk diff --git a/plugins/community/repos/mscHack/modules.PNG b/plugins/community/repos/mscHack/modules.PNG new file mode 100644 index 00000000..63b92e23 Binary files /dev/null and b/plugins/community/repos/mscHack/modules.PNG differ diff --git a/plugins/community/repos/mscHack/res/ARP700.svg b/plugins/community/repos/mscHack/res/ARP700.svg new file mode 100644 index 00000000..9b707087 --- /dev/null +++ b/plugins/community/repos/mscHack/res/ARP700.svg @@ -0,0 +1,1053 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/Compressor.svg b/plugins/community/repos/mscHack/res/Compressor.svg new file mode 100644 index 00000000..5517407b --- /dev/null +++ b/plugins/community/repos/mscHack/res/Compressor.svg @@ -0,0 +1,611 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/MasterClockx4.svg b/plugins/community/repos/mscHack/res/MasterClockx4.svg new file mode 100644 index 00000000..5e6a395b --- /dev/null +++ b/plugins/community/repos/mscHack/res/MasterClockx4.svg @@ -0,0 +1,776 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/Maude221.svg b/plugins/community/repos/mscHack/res/Maude221.svg new file mode 100644 index 00000000..337ef994 --- /dev/null +++ b/plugins/community/repos/mscHack/res/Maude221.svg @@ -0,0 +1,1585 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/Mix_1x4_Stereo.svg b/plugins/community/repos/mscHack/res/Mix_1x4_Stereo.svg new file mode 100644 index 00000000..09619d6b --- /dev/null +++ b/plugins/community/repos/mscHack/res/Mix_1x4_Stereo.svg @@ -0,0 +1,947 @@ + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/Mix_2x4_Stereo.svg b/plugins/community/repos/mscHack/res/Mix_2x4_Stereo.svg new file mode 100644 index 00000000..596f7744 --- /dev/null +++ b/plugins/community/repos/mscHack/res/Mix_2x4_Stereo.svg @@ -0,0 +1,1645 @@ + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/Mix_4x4_Stereo.svg b/plugins/community/repos/mscHack/res/Mix_4x4_Stereo.svg new file mode 100644 index 00000000..37b9bd59 --- /dev/null +++ b/plugins/community/repos/mscHack/res/Mix_4x4_Stereo.svg @@ -0,0 +1,2356 @@ + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/Mixer_24_4_4.svg b/plugins/community/repos/mscHack/res/Mixer_24_4_4.svg new file mode 100644 index 00000000..98b3e504 --- /dev/null +++ b/plugins/community/repos/mscHack/res/Mixer_24_4_4.svg @@ -0,0 +1,2204 @@ + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/OSC3Channel.svg b/plugins/community/repos/mscHack/res/OSC3Channel.svg new file mode 100644 index 00000000..7e26d9dc --- /dev/null +++ b/plugins/community/repos/mscHack/res/OSC3Channel.svg @@ -0,0 +1,1434 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/PingPong.svg b/plugins/community/repos/mscHack/res/PingPong.svg new file mode 100644 index 00000000..62950fb9 --- /dev/null +++ b/plugins/community/repos/mscHack/res/PingPong.svg @@ -0,0 +1,629 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/SEQ_6x32x16.svg b/plugins/community/repos/mscHack/res/SEQ_6x32x16.svg new file mode 100644 index 00000000..07e6dbbb --- /dev/null +++ b/plugins/community/repos/mscHack/res/SEQ_6x32x16.svg @@ -0,0 +1,3997 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/SEQ_Envelope_8.svg b/plugins/community/repos/mscHack/res/SEQ_Envelope_8.svg new file mode 100644 index 00000000..dd93edb5 --- /dev/null +++ b/plugins/community/repos/mscHack/res/SEQ_Envelope_8.svg @@ -0,0 +1,1745 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/Seq_3x16x16.svg b/plugins/community/repos/mscHack/res/Seq_3x16x16.svg new file mode 100644 index 00000000..21210e2c --- /dev/null +++ b/plugins/community/repos/mscHack/res/Seq_3x16x16.svg @@ -0,0 +1,863 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + fgdfgdfgfd + + + + + + + + SOME TEXT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/StepDelay.svg b/plugins/community/repos/mscHack/res/StepDelay.svg new file mode 100644 index 00000000..1b0ac535 --- /dev/null +++ b/plugins/community/repos/mscHack/res/StepDelay.svg @@ -0,0 +1,604 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/SynthDrums.svg b/plugins/community/repos/mscHack/res/SynthDrums.svg new file mode 100644 index 00000000..fed183a2 --- /dev/null +++ b/plugins/community/repos/mscHack/res/SynthDrums.svg @@ -0,0 +1,1538 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/TriadSequencer2.svg b/plugins/community/repos/mscHack/res/TriadSequencer2.svg new file mode 100644 index 00000000..165a94ba --- /dev/null +++ b/plugins/community/repos/mscHack/res/TriadSequencer2.svg @@ -0,0 +1,1303 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/XFade.svg b/plugins/community/repos/mscHack/res/XFade.svg new file mode 100644 index 00000000..2a107a55 --- /dev/null +++ b/plugins/community/repos/mscHack/res/XFade.svg @@ -0,0 +1,548 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_3p_vert_simple_01.svg b/plugins/community/repos/mscHack/res/mschack_3p_vert_simple_01.svg new file mode 100644 index 00000000..24d9e9dd --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_3p_vert_simple_01.svg @@ -0,0 +1,83 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_3p_vert_simple_02.svg b/plugins/community/repos/mscHack/res/mschack_3p_vert_simple_02.svg new file mode 100644 index 00000000..f7751bc2 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_3p_vert_simple_02.svg @@ -0,0 +1,83 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_3p_vert_simple_03.svg b/plugins/community/repos/mscHack/res/mschack_3p_vert_simple_03.svg new file mode 100644 index 00000000..e10ba535 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_3p_vert_simple_03.svg @@ -0,0 +1,83 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_5p_filtersel_01.svg b/plugins/community/repos/mscHack/res/mschack_5p_filtersel_01.svg new file mode 100644 index 00000000..5b987dc1 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_5p_filtersel_01.svg @@ -0,0 +1,118 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + sdffds sdfds + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_5p_filtersel_02.svg b/plugins/community/repos/mscHack/res/mschack_5p_filtersel_02.svg new file mode 100644 index 00000000..13638beb --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_5p_filtersel_02.svg @@ -0,0 +1,114 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + sdffds sdfds + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_5p_filtersel_03.svg b/plugins/community/repos/mscHack/res/mschack_5p_filtersel_03.svg new file mode 100644 index 00000000..4bb37ae7 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_5p_filtersel_03.svg @@ -0,0 +1,114 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + sdffds sdfds + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_5p_filtersel_04.svg b/plugins/community/repos/mscHack/res/mschack_5p_filtersel_04.svg new file mode 100644 index 00000000..be1fb245 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_5p_filtersel_04.svg @@ -0,0 +1,114 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + sdffds sdfds + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_5p_filtersel_05.svg b/plugins/community/repos/mscHack/res/mschack_5p_filtersel_05.svg new file mode 100644 index 00000000..578ddd32 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_5p_filtersel_05.svg @@ -0,0 +1,126 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + sdffds sdfds + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Blue1_26.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Blue1_26.svg new file mode 100644 index 00000000..c2cadf93 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Blue1_26.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Blue2_15.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Blue2_15.svg new file mode 100644 index 00000000..0fdee844 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Blue2_15.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Blue2_26.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Blue2_26.svg new file mode 100644 index 00000000..5abc33ea --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Blue2_26.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Blue2_40.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Blue2_40.svg new file mode 100644 index 00000000..a3f7d1ac --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Blue2_40.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Blue2_56.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Blue2_56.svg new file mode 100644 index 00000000..5781e230 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Blue2_56.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Blue3_15.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Blue3_15.svg new file mode 100644 index 00000000..964273a2 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Blue3_15.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Blue3_20.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Blue3_20.svg new file mode 100644 index 00000000..6d387521 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Blue3_20.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Green1_15.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Green1_15.svg new file mode 100644 index 00000000..e35f3ab5 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Green1_15.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Green1_40.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Green1_40.svg new file mode 100644 index 00000000..2ff4825c --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Green1_40.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Purp1_15.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Purp1_15.svg new file mode 100644 index 00000000..0d82399f --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Purp1_15.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Purp1_20.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Purp1_20.svg new file mode 100644 index 00000000..540e3d50 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Purp1_20.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Red1_15.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Red1_15.svg new file mode 100644 index 00000000..ddfb9b35 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Red1_15.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Red1_20.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Red1_20.svg new file mode 100644 index 00000000..92beda56 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Red1_20.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Yellow1_15.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Yellow1_15.svg new file mode 100644 index 00000000..16583f01 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Yellow1_15.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Yellow1_26.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Yellow1_26.svg new file mode 100644 index 00000000..ce6ed082 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Yellow1_26.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Yellow2_26.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Yellow2_26.svg new file mode 100644 index 00000000..223740db --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Yellow2_26.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Yellow2_40.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Yellow2_40.svg new file mode 100644 index 00000000..bde33c4e --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Yellow2_40.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Yellow2_56.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Yellow2_56.svg new file mode 100644 index 00000000..27a6a222 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Yellow2_56.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Yellow3_15.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Yellow3_15.svg new file mode 100644 index 00000000..444fb53a --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Yellow3_15.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Knob_Yellow3_20.svg b/plugins/community/repos/mscHack/res/mschack_Knob_Yellow3_20.svg new file mode 100644 index 00000000..3260b75d --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Knob_Yellow3_20.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_PortIn_small.svg b/plugins/community/repos/mscHack/res/mschack_PortIn_small.svg new file mode 100644 index 00000000..c81f8ff1 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_PortIn_small.svg @@ -0,0 +1,84 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_PortOut_small.svg b/plugins/community/repos/mscHack/res/mschack_PortOut_small.svg new file mode 100644 index 00000000..50310031 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_PortOut_small.svg @@ -0,0 +1,84 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_Slider02_10x15.svg b/plugins/community/repos/mscHack/res/mschack_Slider02_10x15.svg new file mode 100644 index 00000000..d506aa06 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_Slider02_10x15.svg @@ -0,0 +1,72 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_sliderBG_01.svg b/plugins/community/repos/mscHack/res/mschack_sliderBG_01.svg new file mode 100644 index 00000000..c59242d4 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_sliderBG_01.svg @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_sliderBG_02.svg b/plugins/community/repos/mscHack/res/mschack_sliderBG_02.svg new file mode 100644 index 00000000..d1ab408c --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_sliderBG_02.svg @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_sliderKNOB_01.svg b/plugins/community/repos/mscHack/res/mschack_sliderKNOB_01.svg new file mode 100644 index 00000000..bef02918 --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_sliderKNOB_01.svg @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/plugins/community/repos/mscHack/res/mschack_square_button.svg b/plugins/community/repos/mscHack/res/mschack_square_button.svg new file mode 100644 index 00000000..e5bd877b --- /dev/null +++ b/plugins/community/repos/mscHack/res/mschack_square_button.svg @@ -0,0 +1,65 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/plugins/community/repos/mscHack/src/3Ch_Osc.cpp b/plugins/community/repos/mscHack/src/3Ch_Osc.cpp new file mode 100644 index 00000000..0cba5494 --- /dev/null +++ b/plugins/community/repos/mscHack/src/3Ch_Osc.cpp @@ -0,0 +1,854 @@ +#include "mscHack.hpp" +//#include "mscHack_Controls.hpp" +#include "dsp/digital.hpp" +//#include "CLog.h" + +namespace rack_plugin_mscHack { + +#define nCHANNELS 3 +#define CHANNEL_H 90 +#define CHANNEL_Y 65 +#define CHANNEL_X 10 + +#define MAX_nWAVES 7 +#define MAX_DETUNE 20 //Hz + +#define freqMAX 300.0f +#define ADS_MAX_TIME_SECONDS 0.5f + +#define WAVE_BUFFER_LEN ( 192000 / 20 ) // (9600) based on quality for 20Hz at max sample rate 192000 + +typedef struct +{ + int state; + int a, d, r; + int acount, dcount, rcount, fadecount; + float fainc, frinc, fadeinc; + float out; + bool bTrig; +}ADR_STRUCT; + +typedef struct +{ + int wavetype; + int filtertype; + + // wave + float phase[ MAX_nWAVES ]; + float freq[ MAX_nWAVES ]; + + //filter + float q, f; + + float lp1[ 2 ] = {}, bp1[ 2 ] = {}; + + // ads + ADR_STRUCT adr_wave; + +}OSC_PARAM_STRUCT; + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct Osc_3Ch : Module +{ + enum WaveTypes + { + WAVE_SIN, + WAVE_TRI, + WAVE_SQR, + WAVE_SAW, + WAVE_NOISE, + nWAVEFORMS + }; + + enum ParamIds + { + PARAM_DELAY, + PARAM_ATT = PARAM_DELAY + nCHANNELS, + PARAM_REL = PARAM_ATT + nCHANNELS, + PARAM_REZ = PARAM_REL + nCHANNELS, + PARAM_WAVES = PARAM_REZ + nCHANNELS, + PARAM_CUTOFF = PARAM_WAVES + (nWAVEFORMS * nCHANNELS), + PARAM_RES = PARAM_CUTOFF + nCHANNELS, + PARAM_OUTLVL = PARAM_RES + nCHANNELS, + PARAM_FILTER_MODE = PARAM_OUTLVL + nCHANNELS, + PARAM_nWAVES = PARAM_FILTER_MODE + nCHANNELS, + PARAM_SPREAD = PARAM_nWAVES + nCHANNELS, + PARAM_DETUNE = PARAM_SPREAD + nCHANNELS, + nPARAMS = PARAM_DETUNE + nCHANNELS + }; + + enum InputIds + { + IN_VOCT, + IN_TRIG = IN_VOCT + nCHANNELS, + IN_FILTER = IN_TRIG + nCHANNELS, + IN_REZ = IN_FILTER + nCHANNELS, + IN_LEVEL = IN_REZ + nCHANNELS, + nINPUTS = IN_LEVEL + nCHANNELS, + }; + + enum OutputIds + { + OUTPUT_AUDIO, + nOUTPUTS = OUTPUT_AUDIO + (nCHANNELS * 2) + }; + + enum ADRSTATES + { + ADR_OFF, + ADR_FADE, + ADR_WAIT_PHASE, + ADR_FADE_OUT, + ADR_ATTACK, + ADR_DELAY, + ADR_RELEASE + }; + + enum FILTER_TYPES + { + FILTER_OFF, + FILTER_LP, + FILTER_HP, + FILTER_BP, + FILTER_NT + }; + + bool m_bInitialized = false; + CLog lg; + + SchmittTrigger m_SchTrig[ nCHANNELS ]; + + OSC_PARAM_STRUCT m_Wave[ nCHANNELS ] = {}; + + // waveforms + float m_BufferWave[ nWAVEFORMS ][ WAVE_BUFFER_LEN ] = {}; + + float m_DetuneIn[ nCHANNELS ] = {}; + float m_Detune[ nCHANNELS ][ MAX_nWAVES ][ MAX_nWAVES ]; + + float m_SpreadIn[ nCHANNELS ] = {}; + float m_Pan[ nCHANNELS ][ MAX_nWAVES ][ MAX_nWAVES ][ 2 ]; + + int m_nWaves[ nCHANNELS ] = {}; + + MyLEDButtonStrip *m_pButtonWaveSelect[ nCHANNELS ] = {}; + + // Contructor + Osc_3Ch() : Module( nPARAMS, nINPUTS, nOUTPUTS, 0 ){} + + //----------------------------------------------------- + // MynWaves_Knob + //----------------------------------------------------- + struct MynWaves_Knob : Knob_Yellow3_20_Snap + { + Osc_3Ch *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Osc_3Ch*)module; + + if( mymodule ) + { + param = paramId - Osc_3Ch::PARAM_nWAVES; + mymodule->m_nWaves[ param ] = (int)( value ); + } + + RoundKnob::onChange( e ); + } + }; + + //----------------------------------------------------- + // MyEQHi_Knob + //----------------------------------------------------- + struct MyDetune_Knob : Knob_Yellow3_20 + { + Osc_3Ch *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Osc_3Ch*)module; + + if( mymodule ) + { + param = paramId - Osc_3Ch::PARAM_DETUNE; + + mymodule->m_DetuneIn[ param ] = value; + mymodule->CalcDetune( param ); + } + + RoundKnob::onChange( e ); + } + }; + + //----------------------------------------------------- + // MyEQHi_Knob + //----------------------------------------------------- + struct MySpread_Knob : Knob_Yellow3_20 + { + Osc_3Ch *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Osc_3Ch*)module; + + if( mymodule ) + { + param = paramId - Osc_3Ch::PARAM_SPREAD; + + mymodule->m_SpreadIn[ param ] = value; + mymodule->CalcSpread( param ); + } + + RoundKnob::onChange( e ); + } + }; + + // Overrides + void step() override; + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onRandomize() override; + void onReset() override; + + void CalcSpread( int ch ); + void CalcDetune( int ch ); + void SetWaveLights( void ); + void BuildWaves( void ); + void ChangeFilterCutoff( int ch, float cutfreq ); + void Filter( int ch, float *InL, float *InR ); + float GetWave( int type, float phase ); + float ProcessADR( int ch ); + void GetAudio( int ch, float *pOutL, float *pOutR, float flevel ); +}; + +//----------------------------------------------------- +// Osc_3Ch_WaveSelect +//----------------------------------------------------- +void Osc_3Ch_WaveSelect( void *pClass, int id, int nbutton, bool bOn ) +{ + Osc_3Ch *mymodule; + mymodule = (Osc_3Ch*)pClass; + mymodule->m_Wave[ id ].wavetype = nbutton; +} + +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- + +struct Osc_3Ch_Widget : ModuleWidget { + Osc_3Ch_Widget( Osc_3Ch *module ); +}; + +Osc_3Ch_Widget::Osc_3Ch_Widget( Osc_3Ch *module ) : ModuleWidget(module) +{ + int ch, x, y, x2, y2; + + box.size = Vec( 15*21, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/OSC3Channel.svg"))); + addChild(panel); + } + + //module->lg.Open("OSC3Channel.txt"); + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + y = CHANNEL_Y; + x = CHANNEL_X; + + for( ch = 0; ch < nCHANNELS; ch++ ) + { + x = CHANNEL_X; + + // inputs + addInput(Port::create( Vec( x, y ), Port::INPUT, module, Osc_3Ch::IN_VOCT + ch ) ); + addInput(Port::create( Vec( x, y + 43 ), Port::INPUT, module, Osc_3Ch::IN_TRIG + ch ) ); + + x2 = x + 32; + y2 = y + 52; + + module->m_pButtonWaveSelect[ ch ] = new MyLEDButtonStrip( x2, y2, 11, 11, 5, 8.0, 5, false, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButtonStrip::TYPE_EXCLUSIVE, ch, module, Osc_3Ch_WaveSelect ); + addChild( module->m_pButtonWaveSelect[ ch ] ); + + x2 = x + 24; + y2 = y + 18; + + // params + addParam(ParamWidget::create( Vec( x2, y2 ), module, Osc_3Ch::PARAM_ATT + ch, 0.0, 1.0, 0.0 ) ); + + x2 += 31; + + addParam(ParamWidget::create( Vec( x2, y2 ), module, Osc_3Ch::PARAM_DELAY + ch, 0.0, 1.0, 0.0 ) ); + + x2 += 31; + + addParam(ParamWidget::create( Vec( x2, y2 ), module, Osc_3Ch::PARAM_REL + ch, 0.0, 1.0, 0.0 ) ); + + // waves/detune/spread + x2 = x + 149; + y2 = y + 56; + + addParam(ParamWidget::create( Vec( x + 129, y + 11 ), module, Osc_3Ch::PARAM_nWAVES + ch, 0.0, 6.0, 0.0 ) ); + addParam(ParamWidget::create( Vec( x + 116, y + 48 ), module, Osc_3Ch::PARAM_DETUNE + ch, 0.0, 0.05, 0.0 ) ); + addParam(ParamWidget::create( Vec( x + 116 + 28, y + 48 ), module, Osc_3Ch::PARAM_SPREAD + ch, 0.0, 1.0, 0.0 ) ); + + // inputs + x2 = x + 178; + y2 = y + 51; + + addInput(Port::create( Vec( x2, y2 ), Port::INPUT, module, Osc_3Ch::IN_FILTER + ch ) ); + x2 += 36; + addInput(Port::create( Vec( x2, y2 ), Port::INPUT, module, Osc_3Ch::IN_REZ + ch ) ); + x2 += 40; + addInput(Port::create( Vec( x2, y2 ), Port::INPUT, module, Osc_3Ch::IN_LEVEL + ch ) ); + + // filter + y2 = y + 6; + x2 = x + 167; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Osc_3Ch::PARAM_CUTOFF + ch, 0.0, 0.1, 0.0 ) ); + addParam(ParamWidget::create( Vec( x2 + 43, y2 + 2 ), module, Osc_3Ch::PARAM_FILTER_MODE + ch, 0.0, 4.0, 0.0 ) ); + addParam(ParamWidget::create( Vec( x2 + 46, y2 + 20 ), module, Osc_3Ch::PARAM_RES + ch, 0.0, 1.0, 0.0 ) ); + + // main level + addParam(ParamWidget::create( Vec( x2 + 76, y2 ), module, Osc_3Ch::PARAM_OUTLVL + ch, 0.0, 1.0, 0.0 ) ); + + // outputs + addOutput(Port::create( Vec( x + 283, y + 4 ), Port::OUTPUT, module, Osc_3Ch::OUTPUT_AUDIO + (ch * 2) ) ); + addOutput(Port::create( Vec( x + 283, y + 53 ), Port::OUTPUT, module, Osc_3Ch::OUTPUT_AUDIO + (ch * 2) + 1 ) ); + + y += CHANNEL_H; + module->m_nWaves[ ch ] = 0; + } + + module->m_bInitialized = true; + + module->BuildWaves(); + module->SetWaveLights(); +} + +//----------------------------------------------------- +// Procedure: +// +//----------------------------------------------------- +json_t *Osc_3Ch::toJson() +{ + json_t *gatesJ; + json_t *rootJ = json_object(); + + // wavetypes + gatesJ = json_array(); + + for (int i = 0; i < nCHANNELS; i++) + { + json_t *gateJ = json_integer( m_Wave[ i ].wavetype ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "wavetypes", gatesJ ); + + return rootJ; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void Osc_3Ch::fromJson(json_t *rootJ) +{ + int i; + json_t *StepsJ; + + // wave select + StepsJ = json_object_get( rootJ, "wavetypes" ); + + if (StepsJ) + { + for ( i = 0; i < nCHANNELS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + m_Wave[ i ].wavetype = json_integer_value( gateJ ); + } + } + + // set up parameters + for ( i = 0; i < nCHANNELS; i++) + { + m_nWaves[ i ] = (int)( params[ PARAM_nWAVES + i ].value ); + + m_SpreadIn[ i ] = params[ PARAM_SPREAD + i ].value; + CalcSpread( i ); + m_DetuneIn[ i ] = params[ PARAM_DETUNE + i ].value; + CalcDetune( i ); + } + + SetWaveLights(); +} + +//----------------------------------------------------- +// Procedure: reset +// +//----------------------------------------------------- +void Osc_3Ch::onReset() +{ +} + +//----------------------------------------------------- +// Procedure: randomize +// +//----------------------------------------------------- +void Osc_3Ch::onRandomize() +{ + int ch; + + for( ch = 0; ch < nCHANNELS; ch++ ) + { + m_Wave[ ch ].wavetype = (int)( randomUniform() * (nWAVEFORMS-1) ); + } + + SetWaveLights(); +} + +//----------------------------------------------------- +// Procedure: SetWaveLights +// +//----------------------------------------------------- +void Osc_3Ch::SetWaveLights( void ) +{ + int ch; + + for( ch = 0; ch < nCHANNELS; ch++ ) + m_pButtonWaveSelect[ ch ]->Set( m_Wave[ ch ].wavetype, true ); +} + +//----------------------------------------------------- +// Procedure: initialize +// +//----------------------------------------------------- +//#define DEG2RAD( x ) ( ( x ) * ( 3.14159f / 180.0f ) ) +void Osc_3Ch::BuildWaves( void ) +{ + int i; + float finc, pos, val; + + finc = 360.0 / WAVE_BUFFER_LEN; + pos = 0; + + // create sin wave + for( i = 0; i < WAVE_BUFFER_LEN; i++ ) + { + m_BufferWave[ WAVE_SIN ][ i ] = sin( DEG2RAD( pos ) ); + pos += finc; + } + + // create sqr wave + for( i = 0; i < WAVE_BUFFER_LEN; i++ ) + { + if( i < WAVE_BUFFER_LEN / 2 ) + m_BufferWave[ WAVE_SQR ][ i ] = 1.0; + else + m_BufferWave[ WAVE_SQR ][ i ] = -1.0; + } + + finc = 2.0 / (float)WAVE_BUFFER_LEN; + val = 1.0; + + // create saw wave + for( i = 0; i < WAVE_BUFFER_LEN; i++ ) + { + m_BufferWave[ WAVE_SAW ][ i ] = val; + + val -= finc; + } + + finc = 4 / (float)WAVE_BUFFER_LEN; + val = 0; + + // create tri wave + for( i = 0; i < WAVE_BUFFER_LEN; i++ ) + { + m_BufferWave[ WAVE_TRI ][ i ] = val; + + if( i < WAVE_BUFFER_LEN / 4 ) + val += finc; + else if( i < (WAVE_BUFFER_LEN / 4) * 3 ) + val -= finc; + else if( i < WAVE_BUFFER_LEN ) + val += finc; + } +} + +//----------------------------------------------------- +// Procedure: GetAudio +// +//----------------------------------------------------- +float Osc_3Ch::GetWave( int type, float phase ) +{ + float fval = 0.0; + float ratio = (float)(WAVE_BUFFER_LEN-1) / engineGetSampleRate(); + + switch( type ) + { + case WAVE_SIN: + case WAVE_TRI: + case WAVE_SQR: + case WAVE_SAW: + fval = m_BufferWave[ type ][ int( ( phase * ratio ) + 0.5 ) ]; + break; + + case WAVE_NOISE: + fval = ( randomUniform() > 0.5 ) ? (randomUniform() * -1.0) : randomUniform(); + break; + + default: + break; + } + + return fval; +} + +//----------------------------------------------------- +// Procedure: ProcessADS +// +//----------------------------------------------------- +float Osc_3Ch::ProcessADR( int ch ) +{ + ADR_STRUCT *padr; + + padr = &m_Wave[ ch ].adr_wave; + + // retrig the adsr + if( padr->bTrig ) + { + padr->state = ADR_FADE; + + padr->fadecount = 900; + padr->fadeinc = padr->out / (float)padr->fadecount; + + padr->acount = 40 + (int)( params[ PARAM_ATT + ch ].value * 2.0f * engineGetSampleRate() ); + padr->fainc = 1.0f / (float)padr->acount; + + padr->dcount = (int)( params[ PARAM_DELAY + ch ].value * 4.0f * engineGetSampleRate() ); + + padr->rcount = 20 + (int)( params[ PARAM_REL + ch ].value * 10.0f * engineGetSampleRate() ); + padr->frinc = 1.0f / (float)padr->rcount; + + padr->bTrig = false; + } + + // process + switch( padr->state ) + { + case ADR_FADE: + if( --padr->fadecount <= 0 ) + { + padr->state = ADR_ATTACK; + padr->out = 0.0f; + m_Wave[ ch ].phase[ 0 ] = 0.0f; + m_Wave[ ch ].phase[ 1 ] = 0.0f; + m_Wave[ ch ].phase[ 2 ] = 0.0f; + m_Wave[ ch ].phase[ 3 ] = 0.0f; + m_Wave[ ch ].phase[ 4 ] = 0.0f; + m_Wave[ ch ].phase[ 5 ] = 0.0f; + m_Wave[ ch ].phase[ 6 ] = 0.0f; + } + else + { + padr->out -= padr->fadeinc; + } + + break; + + case ADR_OFF: + padr->out = 0.0f; + break; + + case ADR_ATTACK: + + if( --padr->acount <= 0 ) + { + padr->state = ADR_DELAY; + } + else + { + padr->out += padr->fainc; + } + + break; + + case ADR_DELAY: + padr->out = 1.0f; + if( --padr->dcount <= 0 ) + { + padr->state = ADR_RELEASE; + } + break; + + case ADR_RELEASE: + + if( --padr->rcount <= 0 ) + { + padr->state = ADR_OFF; + padr->out = 0.0f; + } + else + { + padr->out -= padr->frinc; + } + + break; + } + + return clamp( padr->out, 0.0f, 1.0f ); +} + +//----------------------------------------------------- +// Procedure: ChangeFilterCutoff +// +//----------------------------------------------------- +void Osc_3Ch::ChangeFilterCutoff( int ch, float cutfreq ) +{ + float fx, fx2, fx3, fx5, fx7; + + // clamp at 1.0 and 20/samplerate + cutfreq = fmax(cutfreq, 20 / engineGetSampleRate()); + cutfreq = fmin(cutfreq, 1.0); + + // calculate eq rez freq + fx = 3.141592 * (cutfreq * 0.026315789473684210526315789473684) * 2 * 3.141592; + fx2 = fx*fx; + fx3 = fx2*fx; + fx5 = fx3*fx2; + fx7 = fx5*fx2; + + m_Wave[ ch ].f = 2.0 * (fx + - (fx3 * 0.16666666666666666666666666666667) + + (fx5 * 0.0083333333333333333333333333333333) + - (fx7 * 0.0001984126984126984126984126984127)); +} + +//----------------------------------------------------- +// Procedure: Filter +// +//----------------------------------------------------- +#define MULTI (0.33333333333333333333333333333333f) +void Osc_3Ch::Filter( int ch, float *InL, float *InR ) +{ + OSC_PARAM_STRUCT *p; + float rez, hp1; + float input[ 2 ], out[ 2 ], lowpass, bandpass, highpass; + + if( (int)params[ PARAM_FILTER_MODE + ch ].value == 0 ) + return; + + p = &m_Wave[ ch ]; + + rez = 1.0 - params[ PARAM_RES + ch ].value; + + input[ 0 ] = *InL; + input[ 1 ] = *InR; + + // do left and right channels + for( int i = 0; i < 2; i++ ) + { + input[ i ] = input[ i ] + 0.000000001; + + p->lp1[ i ] = p->lp1[ i ] + p->f * p->bp1[ i ]; + hp1 = input[ i ] - p->lp1[ i ] - rez * p->bp1[ i ]; + p->bp1[ i ] = p->f * hp1 + p->bp1[ i ]; + lowpass = p->lp1[ i ]; + highpass = hp1; + bandpass = p->bp1[ i ]; + + p->lp1[ i ] = p->lp1[ i ] + p->f * p->bp1[ i ]; + hp1 = input[ i ] - p->lp1[ i ] - rez * p->bp1[ i ]; + p->bp1[ i ] = p->f * hp1 + p->bp1[ i ]; + lowpass = lowpass + p->lp1[ i ]; + highpass = highpass + hp1; + bandpass = bandpass + p->bp1[ i ]; + + input[ i ] = input[ i ] - 0.000000001; + + p->lp1[ i ] = p->lp1[ i ] + p->f * p->bp1[ i ]; + hp1 = input[ i ] - p->lp1[ i ] - rez * p->bp1[ i ]; + p->bp1[ i ] = p->f * hp1 + p->bp1[ i ]; + + lowpass = (lowpass + p->lp1[ i ]) * MULTI; + highpass = (highpass + hp1) * MULTI; + bandpass = (bandpass + p->bp1[ i ]) * MULTI; + + switch( (int)params[ PARAM_FILTER_MODE + ch ].value ) + { + case FILTER_LP: + out[ i ] = lowpass; + break; + case FILTER_HP: + out[ i ] = highpass; + break; + case FILTER_BP: + out[ i ] = bandpass; + break; + case FILTER_NT: + out[ i ] = lowpass + highpass; + break; + default: + break; + } + } + + *InL = out[ 0 ]; + *InR = out[ 1 ]; +} + +//----------------------------------------------------- +// Procedure: CalcSpread +// +//----------------------------------------------------- +typedef struct +{ + float pan[ 2 ]; + float maxdetune; +}PAN_DETUNE; + +PAN_DETUNE pandet[ 7 ][ 7 ] = +{ + { { {1.0, 1.0}, 0.0 }, { {0.0, 0.0}, 0.0 }, { {0.0, 0.0}, 0.0 }, { {0.0, 0.0}, 0.0 }, { {0.0, 0.0}, 0.0 }, { {0.0, 0.0}, 0.0 }, { {0.0, 0.0}, 0.0 } }, + { { {1.0, 0.5}, 0.1 }, { {0.5, 1.0}, 0.2 }, { {0.0, 0.0}, 0.0 }, { {0.0, 0.0}, 0.0 }, { {0.0, 0.0}, 0.0 }, { {0.0, 0.0}, 0.0 }, { {0.0, 0.0}, 0.0 } }, + { { {1.0, 0.5}, 0.3 }, { {1.0, 1.0}, 0.0 }, { {0.5, 1.0}, 0.2 }, { {0.0, 0.0}, 0.0 }, { {0.0, 0.0}, 0.0 }, { {0.0, 0.0}, 0.0 }, { {0.0, 0.0}, 0.0 } }, + { { {1.0, 0.3}, 0.4 }, { {1.0, 0.5}, 0.2 }, { {0.5, 1.0}, 0.2 }, { {0.3, 1.0}, 0.3 }, { {0.0, 0.0}, 0.0 }, { {0.0, 0.0}, 0.0 }, { {0.0, 0.0}, 0.0 } }, + { { {1.0, 0.3}, 0.5 }, { {1.0, 0.5}, 0.4 }, { {1.0, 1.0}, 0.0 }, { {0.5, 1.0}, 0.3 }, { {0.3, 1.0}, 0.1 }, { {0.0, 0.0}, 0.0 }, { {0.0, 0.0}, 0.0 } }, + { { {1.0, 0.2}, 0.6 }, { {1.0, 0.3}, 0.4 }, { {1.0, 0.5}, 0.2 }, { {0.5, 1.0}, 0.3 }, { {0.3, 1.0}, 0.5 }, { {0.2, 1.0}, 0.8 }, { {0.0, 0.0}, 0.0 } }, + { { {1.0, 0.0}, 0.9 }, { {1.0, 0.2}, 0.7 }, { {1.0, 0.3}, 0.5 }, { {1.0, 1.0}, 0.0 }, { {0.3, 1.0}, 0.4 }, { {0.2, 1.0}, 0.8 }, { {0.0, 1.0}, 1.0 } }, +}; + +void Osc_3Ch::CalcSpread( int ch ) +{ + int used; // number of waves being used by channel + int wave; // values for each individual wave + + // calculate pans for each possible number of waves being used + for( used = 0; used < MAX_nWAVES; used++ ) + { + for( wave = 0; wave <= used; wave++ ) + { + m_Pan[ ch ][ used ][ wave ][ 0 ] = ( 1.0 - m_SpreadIn[ ch ] ) + ( pandet[ used ][ wave ].pan[ 0 ] * m_SpreadIn[ ch ] ); + m_Pan[ ch ][ used ][ wave ][ 1 ] = ( 1.0 - m_SpreadIn[ ch ] ) + ( pandet[ used ][ wave ].pan[ 1 ] * m_SpreadIn[ ch ] ); + } + } +} + +void Osc_3Ch::CalcDetune( int ch ) +{ + int used; // number of waves being used by channel + int wave; // values for each individual wave + + // calculate detunes for each possible number of waves being used + for( used = 0; used < MAX_nWAVES; used++ ) + { + for( wave = 0; wave <= used; wave++ ) + m_Detune[ ch ][ used ][ wave ] = pandet[ used ][ wave ].maxdetune * MAX_DETUNE * m_DetuneIn[ ch ]; + } +} + +//----------------------------------------------------- +// Procedure: GetAudio +// +//----------------------------------------------------- +void Osc_3Ch::GetAudio( int ch, float *pOutL, float *pOutR, float flevel ) +{ + float foutL = 0, foutR = 0, cutoff, adr; + int i; + + for( i = 0; i <= m_nWaves[ ch ]; i++ ) + { + foutL = GetWave( m_Wave[ ch ].wavetype, m_Wave[ ch ].phase[ i ] ) / 2.0; + foutR = foutL; + + foutL *= m_Pan[ ch ][ m_nWaves[ ch ] ][ i ][ 0 ]; + foutR *= m_Pan[ ch ][ m_nWaves[ ch ] ][ i ][ 1 ]; + + // ( 32.7032 is C1 ) ( 4186.01 is C8) + m_Wave[ ch ].phase[ i ] += 32.7032f * clamp( powf( 2.0f, clamp( inputs[ IN_VOCT + ch ].value, 0.0f, VOCT_MAX ) ) + m_Detune[ ch ][ m_nWaves[ ch ] ][ i ], 0.0f, 4186.01f ); + + if( m_Wave[ ch ].phase[ i ] >= engineGetSampleRate() ) + m_Wave[ ch ].phase[ i ] = m_Wave[ ch ].phase[ i ] - engineGetSampleRate(); + + *pOutL += foutL; + *pOutR += foutR; + } + + adr = ProcessADR( ch ); + + *pOutL = *pOutL * adr * flevel; + *pOutR = *pOutR * adr * flevel; + + cutoff = clamp( params[ PARAM_CUTOFF + ch ].value * ( inputs[ IN_FILTER + ch ].normalize( CV_MAX ) / CV_MAX ), 0.0f, 1.0f ); + + ChangeFilterCutoff( ch, cutoff ); + + Filter( ch, pOutL, pOutR ); +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +void Osc_3Ch::step() +{ + int ch; + float outL, outR, flevel; + + if( !m_bInitialized ) + return; + + // check for triggers + for( ch = 0; ch < nCHANNELS; ch++ ) + { + outL = 0.0; + outR = 0.0; + + if( inputs[ IN_TRIG + ch ].active ) + { + if( m_SchTrig[ ch ].process( inputs[ IN_TRIG + ch ].value ) ) + { + m_Wave[ ch ].adr_wave.bTrig = true; + } + } + + flevel = clamp( params[ PARAM_OUTLVL + ch ].value + ( inputs[ IN_LEVEL + ch ].normalize( 0.0 ) / 5.0f ), 0.0f, 1.0f ); + + GetAudio( ch, &outL, &outR, flevel ); + + //outL = clamp( ( outL * AUDIO_MAX ), -AUDIO_MAX, AUDIO_MAX ); + //outR = clamp( ( outR * AUDIO_MAX ), -AUDIO_MAX, AUDIO_MAX ); + + outL = outL * AUDIO_MAX; + outR = outR * AUDIO_MAX; + + outputs[ OUTPUT_AUDIO + (ch * 2 ) ].value = outL; + outputs[ OUTPUT_AUDIO + (ch * 2 ) + 1 ].value = outR; + } +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, Osc_3Ch) { + Model *modelOsc_3Ch = Model::create( "mscHack", "Osc_3Ch_Widget", "OSC 3 Channel", SYNTH_VOICE_TAG, OSCILLATOR_TAG, MULTIPLE_TAG ); + return modelOsc_3Ch; +} diff --git a/plugins/community/repos/mscHack/src/ARP700.cpp b/plugins/community/repos/mscHack/src/ARP700.cpp new file mode 100644 index 00000000..013d6548 --- /dev/null +++ b/plugins/community/repos/mscHack/src/ARP700.cpp @@ -0,0 +1,929 @@ +#include "mscHack.hpp" +//#include "mscHack_Controls.hpp" +#include "dsp/digital.hpp" +//#include "CLog.h" + +namespace rack_plugin_mscHack { + +#define MAX_ARP_PATTERNS 16 +#define MAX_ARP_NOTES 7 +#define SUBSTEP_PER_NOTE 3 + +#define SEMI ( 1.0f / 12.0f ) +#define TRIG_OFF_TICKS 10 + +#define ARP_OFF 0 +#define ARP_ON 1 +#define ARP_REST 2 + +typedef struct +{ + int notesused; + int notes [ MAX_ARP_NOTES ]; + int onoffsel[ MAX_ARP_NOTES ][ SUBSTEP_PER_NOTE ]; + int lensel [ MAX_ARP_NOTES ][ SUBSTEP_PER_NOTE ]; + int lenmod [ MAX_ARP_NOTES ][ SUBSTEP_PER_NOTE ]; + int legato [ MAX_ARP_NOTES ]; + int glide [ MAX_ARP_NOTES ]; + int mode; + int oct; + +}ARP_PATTERN_STRUCT; + +typedef struct +{ + bool bPending; + int pat; +}ARP_PHRASE_CHANGE_STRUCT; + +//------------------------------------------------------ +// sliding window average +/*#define AVG_ARRAY_LEN 4 +#define AVG_AND (AVG_ARRAY_LEN - 1) + +typedef struct +{ + int count; + int avg[ AVG_ARRAY_LEN ]; + int tot; +}SLIDING_AVG_STRUCT;*/ + +typedef struct +{ + // track in clk bpm + //SLIDING_AVG_STRUCT Avg; + int tickcount; + float ftickspersec; + float fbpm; + + // track sync tick + float fsynclen; + float fsynccount; + + bool bClockReset; + int IgnoreClockCount; + +}MAIN_SYNC_CLOCK; + +typedef struct +{ + // timing + bool bTrig; + int pat; + int used; + + int step; + int virtstep; + + ARP_PHRASE_CHANGE_STRUCT pending; + + // track current arp trig + int nextcount; + bool bNextTrig; + + // glide + float fglideInc; + int glideCount; + float fglide; + float fLastNotePlayed; + bool bWasLastNotePlayed; + + // voct out + float fCvStartOut = 0; + float fCvEndOut = 0; + +}PAT_STEP_STRUCT; + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct ARP700 : Module +{ + enum ParamIds + { + nPARAMS + }; + + enum InputIds + { + IN_CLOCK_TRIG, + IN_VOCT_OFF, + IN_PROG_CHANGE, + IN_CLOCK_RESET, + nINPUTS + }; + + enum OutputIds + { + OUT_TRIG, + OUT_VOCTS, + nOUTPUTS + }; + + enum NoteStates + { + STATE_NOTE_OFF, + STATE_NOTE_ON, + STATE_NOTE_REST, + STATE_TRIG_OFF + }; + + CLog lg; + bool m_bInitialized = false; + + // Contructor + ARP700() : Module(nPARAMS, nINPUTS, nOUTPUTS, 0){} + + // pattern + ARP_PATTERN_STRUCT m_PatternSave[ MAX_ARP_PATTERNS ] = {}; + PAT_STEP_STRUCT m_PatCtrl = {}; + + SchmittTrigger m_SchTrigPatternChange; + PatternSelectStrip *m_pPatternSelect = NULL; + + bool m_bCopySrc = false; + + // pattern buttons + MyLEDButtonStrip *m_pButtonOnOff [ MAX_ARP_NOTES ][ SUBSTEP_PER_NOTE ] = {}; + MyLEDButtonStrip *m_pButtonLen [ MAX_ARP_NOTES ][ SUBSTEP_PER_NOTE ] = {}; + MyLEDButtonStrip *m_pButtonLenMod[ MAX_ARP_NOTES ][ SUBSTEP_PER_NOTE ] = {}; + MyLEDButton *m_pButtonGlide [ MAX_ARP_NOTES ] = {}; + MyLEDButton *m_pButtonTrig [ MAX_ARP_NOTES ] = {}; + MyLEDButtonStrip *m_plastbut = NULL; + MyLEDButton *m_pButtonCopy= NULL; + + // clock + SchmittTrigger m_SchTrigClk; + MAIN_SYNC_CLOCK m_Clock; + + // global triggers + SchmittTrigger m_SchTrigGlobalClkReset; + bool m_GlobalClkResetPending = false; + + // keyboard + Keyboard_3Oct_Widget *pKeyboardWidget = NULL; + float m_fKeyNotes[ 37 ]; + float m_VoctOffsetIn = 0; + + // octave + MyLEDButtonStrip *m_pButtonOctaveSelect = NULL; + + // pause + bool m_bPauseState = false; + MyLEDButton *m_pButtonPause; + + // mode + MyLEDButtonStrip *m_pButtonMode = 0; + + // Overrides + void step() override; + void JsonParams( bool bTo, json_t *root); + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onRandomize() override; + void onReset() override; + + void SetPatternSteps( int nSteps ); + void SetOut( void ); + void ChangePattern( int index, bool bForce ); + void SetPendingPattern( int phrase ); + void ArpStep( bool bReset ); + void Copy( bool bOn ); +}; + +//----------------------------------------------------- +// Procedure: ARP700_ModeSelect +//----------------------------------------------------- +void ARP700_ModeSelect( void *pClass, int id, int nbutton, bool bOn ) +{ + ARP700 *mymodule; + mymodule = (ARP700*)pClass; + mymodule->m_PatternSave[ mymodule->m_PatCtrl.pat ].mode = nbutton; +} + +//----------------------------------------------------- +// Procedure: ARP700_NoteOnOff +//----------------------------------------------------- +void ARP700_NoteOnOff( void *pClass, int id, int nbutton, bool bOn ) +{ + int note, param; + ARP700 *mymodule; + mymodule = (ARP700*)pClass; + + note = id / SUBSTEP_PER_NOTE; + param = id - ( SUBSTEP_PER_NOTE * note ); + mymodule->m_PatternSave[ mymodule->m_PatCtrl.pat ].onoffsel[ note ][ param ] = nbutton; +} + +//----------------------------------------------------- +// Procedure: ARP700_NoteLenSelect +//----------------------------------------------------- +void ARP700_NoteLenSelect( void *pClass, int id, int nbutton, bool bOn ) +{ + int note, param; + ARP700 *mymodule; + mymodule = (ARP700*)pClass; + + note = id / SUBSTEP_PER_NOTE; + param = id - ( SUBSTEP_PER_NOTE * note ); + mymodule->m_PatternSave[ mymodule->m_PatCtrl.pat ].lensel[ note ][ param ] = nbutton; +} + +//----------------------------------------------------- +// Procedure: ARP700_OctSelect +//----------------------------------------------------- +void ARP700_OctSelect( void *pClass, int id, int nbutton, bool bOn ) +{ + ARP700 *mymodule; + mymodule = (ARP700*)pClass; + + mymodule->m_PatternSave[ mymodule->m_PatCtrl.pat ].oct = nbutton; +} + +//----------------------------------------------------- +// Procedure: ARP700_mod +//----------------------------------------------------- +void ARP700_mod( void *pClass, int id, int nbutton, bool bOn ) +{ + int note, param; + ARP700 *mymodule; + mymodule = (ARP700*)pClass; + + note = id / SUBSTEP_PER_NOTE; + param = id - ( SUBSTEP_PER_NOTE * note ); + mymodule->m_PatternSave[ mymodule->m_PatCtrl.pat ].lenmod[ note ][ param ] = nbutton; +} + +//----------------------------------------------------- +// Procedure: ARP700_Pause +//----------------------------------------------------- +void ARP700_Pause( void *pClass, int id, bool bOn ) +{ + ARP700 *mymodule; + mymodule = (ARP700*)pClass; + mymodule->m_bPauseState = bOn; +} + +//----------------------------------------------------- +// Procedure: ARP700_Copy +//----------------------------------------------------- +void ARP700_Copy( void *pClass, int id, bool bOn ) +{ + ARP700 *mymodule; + mymodule = (ARP700*)pClass; + mymodule->Copy( bOn ); +} + +//----------------------------------------------------- +// Procedure: ARP700_Glide +//----------------------------------------------------- +void ARP700_Glide( void *pClass, int id, bool bOn ) +{ + ARP700 *mymodule; + mymodule = (ARP700*)pClass; + mymodule->m_PatternSave[ mymodule->m_PatCtrl.pat ].glide[ id ] = bOn; + //mymodule->lg.f("Glide[ %d ] = %d\n", id, bOn ); +} + +//----------------------------------------------------- +// Procedure: ARP700_Trig +//----------------------------------------------------- +void ARP700_Trig( void *pClass, int id, bool bOn ) +{ + ARP700 *mymodule; + mymodule = (ARP700*)pClass; + mymodule->m_PatternSave[ mymodule->m_PatCtrl.pat ].legato[ id ] = bOn; + //mymodule->lg.f("Legato[ %d ] = %d\n", id, bOn ); +} + +//----------------------------------------------------- +// Procedure: NoteChangeCallback +// +//----------------------------------------------------- +void ARP700_Widget_NoteChangeCallback ( void *pClass, int kb, int notepressed, int *pnotes, bool bOn, int button ) +{ + ARP700 *mymodule = (ARP700 *)pClass; + + if( !pClass ) + return; + + memcpy( mymodule->m_PatternSave[ mymodule->m_PatCtrl.pat ].notes, pnotes, sizeof( int ) * MAX_ARP_NOTES ); + mymodule->m_PatternSave[ mymodule->m_PatCtrl.pat ].notesused = mymodule->pKeyboardWidget->m_nKeysOn; +} + +//----------------------------------------------------- +// Procedure: PatternChangeCallback +// +//----------------------------------------------------- +void ARP700_Widget_PatternChangeCallback ( void *pClass, int kb, int pat, int max ) +{ + ARP700 *mymodule = (ARP700 *)pClass; + + if( !mymodule || !mymodule->m_bInitialized ) + return; + + if( mymodule->m_PatCtrl.pat != pat ) + { + if( !mymodule->m_bPauseState && mymodule->inputs[ ARP700::IN_CLOCK_TRIG ].active ) + mymodule->SetPendingPattern( pat ); + else + mymodule->ChangePattern( pat, false ); + + } + else if( mymodule->m_PatCtrl.used != max ) + mymodule->SetPatternSteps( max ); +} + +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- + +struct ARP700_Widget : ModuleWidget { + ARP700_Widget( ARP700 *module ); +}; + +ARP700_Widget::ARP700_Widget( ARP700 *module ) : ModuleWidget(module) +{ + int x, y, note, param; + + box.size = Vec( 15*27, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/ARP700.svg"))); + addChild(panel); + } + + for( int i = 0; i < 37; i++ ) + module->m_fKeyNotes[ i ] = (float)i * SEMI; + + //module->lg.Open("ARP700.txt"); + + // pause button + module->m_pButtonPause = new MyLEDButton( 75, 22, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, 0, module, ARP700_Pause ); + addChild( module->m_pButtonPause ); + + // copy button + module->m_pButtonCopy = new MyLEDButton( 307, 22, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_SWITCH, 0, module, ARP700_Copy ); + addChild( module->m_pButtonCopy ); + + // keyboard widget + module->pKeyboardWidget = new Keyboard_3Oct_Widget( 75, 38, MAX_ARP_NOTES, 0, DWRGB( 255, 128, 64 ), module, ARP700_Widget_NoteChangeCallback, &module->lg ); + addChild( module->pKeyboardWidget ); + + // octave select + module->m_pButtonOctaveSelect = new MyLEDButtonStrip( 307, 104, 11, 11, 3, 8.0, 4, false, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButtonStrip::TYPE_EXCLUSIVE, 0, module, ARP700_OctSelect ); + addChild( module->m_pButtonOctaveSelect ); + + // pattern selects + module->m_pPatternSelect = new PatternSelectStrip( 75, 104, 9, 7, DWRGB( 200, 200, 200 ), DWRGB( 40, 40, 40 ), DWRGB( 112, 104, 102 ), DWRGB( 40, 40, 40 ), MAX_ARP_PATTERNS, 0, module, ARP700_Widget_PatternChangeCallback ); + addChild( module->m_pPatternSelect ); + + x = 60; + + for( note = 0; note < MAX_ARP_NOTES; note++ ) + { + for( param = 0; param < SUBSTEP_PER_NOTE; param++ ) + { + y = 140; + + module->m_pButtonOnOff[ note ][ param ] = new MyLEDButtonStrip( x, y, 12, 12, 2, 10.0, 3, true, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButtonStrip::TYPE_EXCLUSIVE, (note * SUBSTEP_PER_NOTE ) + param, module, ARP700_NoteOnOff ); + addChild( module->m_pButtonOnOff[ note ][ param ] ); + + module->m_pButtonOnOff[ note ][ param ]->SetLEDCol( 1, DWRGB( 0, 255, 0 ) ); + module->m_pButtonOnOff[ note ][ param ]->SetLEDCol( 2, DWRGB( 255, 255, 0 ) ); + + y += 43; + + module->m_pButtonLen[ note ][ param ] = new MyLEDButtonStrip( x, y, 12, 12, 2, 10.0, 6, true, DWRGB( 180, 180, 180 ), DWRGB( 255, 128, 0 ), MyLEDButtonStrip::TYPE_EXCLUSIVE, (note * SUBSTEP_PER_NOTE ) + param, module, ARP700_NoteLenSelect ); + addChild( module->m_pButtonLen[ note ][ param ] ); + + y += 89; + + module->m_pButtonLenMod[ note ][ param ] = new MyLEDButtonStrip( x, y, 12, 12, 2, 10.0, 3, true, DWRGB( 180, 180, 180 ), DWRGB( 255, 128, 0 ), MyLEDButtonStrip::TYPE_EXCLUSIVE_WOFF, (note * SUBSTEP_PER_NOTE ) + param, module, ARP700_mod ); + addChild( module->m_pButtonLenMod[ note ][ param ] ); + + if( param == 1 ) + { + y += 43; + + module->m_pButtonGlide[ note ] = new MyLEDButton( x, y, 12, 12, 10.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_SWITCH, note, module, ARP700_Glide ); + addChild( module->m_pButtonGlide[ note ] ); + + y += 16; + + module->m_pButtonTrig[ note ] = new MyLEDButton( x, y, 12, 12, 10.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_SWITCH, note, module, ARP700_Trig ); + addChild( module->m_pButtonTrig[ note ] ); + } + + x += 14; + } + + x += 5; + } + + // clock trigger + addInput(Port::create( Vec( 44, 21 ), Port::INPUT, module, ARP700::IN_CLOCK_TRIG ) ); + + // VOCT offset input + addInput(Port::create( Vec( 44, 52 ), Port::INPUT, module, ARP700::IN_VOCT_OFF ) ); + + // prog change trigger + addInput(Port::create( Vec( 44, 102 ), Port::INPUT, module, ARP700::IN_PROG_CHANGE ) ); + + // outputs + addOutput(Port::create( Vec( 365, 38 ), Port::OUTPUT, module, ARP700::OUT_VOCTS ) ); + addOutput(Port::create( Vec( 365, 79 ), Port::OUTPUT, module, ARP700::OUT_TRIG ) ); + + // reset inputs + addInput(Port::create( Vec( 14, 21 ), Port::INPUT, module, ARP700::IN_CLOCK_RESET ) ); + + // mode buttons + module->m_pButtonMode = new MyLEDButtonStrip( 154, 360, 12, 12, 7, 10.0, 7, false, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButtonStrip::TYPE_EXCLUSIVE, 0, module, ARP700_ModeSelect ); + addChild( module->m_pButtonMode ); + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + module->m_Clock.fsynclen = 2.0 * 48.0; // default to 120bpm + module->m_Clock.IgnoreClockCount = 2; + module->m_bInitialized = true; + + module->onReset(); +} + +//----------------------------------------------------- +// Procedure: JsonParams +// +//----------------------------------------------------- +void ARP700::JsonParams( bool bTo, json_t *root) +{ + JsonDataBool ( bTo, "m_bPauseState", root, &m_bPauseState, 1 ); + JsonDataInt ( bTo, "m_CurrentPattern", root, &m_PatCtrl.pat, 1 ); + JsonDataInt ( bTo, "m_PatternSave", root, (int*)m_PatternSave, sizeof( m_PatternSave ) / 4 ); + JsonDataInt ( bTo, "m_PatternsUsed", root, &m_PatCtrl.used, 1 ); +} + +//----------------------------------------------------- +// Procedure: toJson +// +//----------------------------------------------------- +json_t *ARP700::toJson() +{ + json_t *root = json_object(); + + if( !root ) + return NULL; + + JsonParams( TOJSON, root ); + + return root; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void ARP700::fromJson( json_t *root ) +{ + JsonParams( FROMJSON, root ); + + m_pButtonPause->Set( m_bPauseState ); + pKeyboardWidget->setkey( m_PatternSave[ m_PatCtrl.pat ].notes ); + + ChangePattern( m_PatCtrl.pat, true ); + + ArpStep( true ); +} + +//----------------------------------------------------- +// Procedure: reset +// +//----------------------------------------------------- +void ARP700::onReset() +{ + int pat, note; + + if( !m_bInitialized ) + return; + + m_pButtonOctaveSelect->Set( 0, true ); + + m_PatCtrl.fCvStartOut = 0; + m_PatCtrl.fCvEndOut = 0; + memset( m_PatternSave, 0, sizeof(m_PatternSave) ); + + for( pat = 0; pat < MAX_ARP_PATTERNS; pat++ ) + { + for( note = 0; note < MAX_ARP_NOTES; note++ ) + m_PatternSave[ pat ].notes[ note ] = -1; + } + + SetPatternSteps( MAX_ARP_PATTERNS - 1 ); + ChangePattern( 0, true ); +} + +//----------------------------------------------------- +// Procedure: randomize +// +//----------------------------------------------------- +void ARP700::onRandomize() +{ +} + +//----------------------------------------------------- +// Procedure: SetPhraseSteps +// +//----------------------------------------------------- +void ARP700::SetPatternSteps( int nSteps ) +{ + if( nSteps < 0 || nSteps >= MAX_ARP_PATTERNS ) + nSteps = 0; + + m_PatCtrl.used = nSteps; +} + +//----------------------------------------------------- +// Procedure: SetOut +// +//----------------------------------------------------- +void ARP700::SetOut( void ) +{ + int note = 0, nstep, substep; + float foct; + + m_VoctOffsetIn = inputs[ IN_VOCT_OFF ].normalize( 0.0 ); + + nstep = m_PatCtrl.step / SUBSTEP_PER_NOTE; + substep = m_PatCtrl.step - ( nstep * SUBSTEP_PER_NOTE ); + + if( m_PatternSave[ m_PatCtrl.pat ].onoffsel[ nstep ][ substep ] == ARP_ON ) + { + note = m_PatternSave[ m_PatCtrl.pat ].notes[ nstep ]; + pKeyboardWidget->setkeyhighlight( note ); + } + else + return; + + if( note > 36 || note < 0 ) + note = 0; + + foct = (float)m_PatternSave[ m_PatCtrl.pat ].oct; + + m_PatCtrl.fCvEndOut = foct + m_fKeyNotes[ note ] + m_VoctOffsetIn; + + // start glide note (last pattern note) + if( m_PatCtrl.bWasLastNotePlayed ) + { + m_PatCtrl.fCvStartOut = m_PatCtrl.fLastNotePlayed + m_VoctOffsetIn; + } + else + { + m_PatCtrl.bWasLastNotePlayed = true; + m_PatCtrl.fCvStartOut = m_PatCtrl.fCvEndOut + m_VoctOffsetIn; + } + + m_PatCtrl.fLastNotePlayed = m_PatCtrl.fCvEndOut + m_VoctOffsetIn; + + if( m_PatternSave[ m_PatCtrl.pat ].glide[ nstep ] ) + { + // glide time + m_PatCtrl.glideCount = 0.2 * engineGetSampleRate(); + m_PatCtrl.fglideInc = 1.0 / (float)m_PatCtrl.glideCount; + + m_PatCtrl.fglide = 1.0; + } + else + { + m_PatCtrl.fglide = 0.0; + m_PatCtrl.glideCount = 0; + } +} + +//----------------------------------------------------- +// Procedure: SetPendingPattern +// +//----------------------------------------------------- +void ARP700::SetPendingPattern( int patin ) +{ + int pattern; + + if( patin < 0 || patin >= MAX_ARP_PATTERNS ) + pattern = ( m_PatCtrl.pat + 1 ) & 0x7; + else + pattern = patin; + + if( pattern > m_PatCtrl.used ) + pattern = 0; + + m_PatCtrl.pending.bPending = true; + m_PatCtrl.pending.pat = pattern; + m_pPatternSelect->SetPat( m_PatCtrl.pat, false ); + m_pPatternSelect->SetPat( pattern, true ); +} + +//----------------------------------------------------- +// Procedure: Copy +// +//----------------------------------------------------- +void ARP700::Copy( bool bOn ) +{ + if( !m_bPauseState || !bOn ) + { + m_bCopySrc = false; + m_pButtonCopy->Set( false ); + } + else if( bOn ) + { + m_bCopySrc = true; + } +} + +//----------------------------------------------------- +// Procedure: ChangePattern +// +//----------------------------------------------------- +void ARP700::ChangePattern( int index, bool bForce ) +{ + int note, param; + + if( !bForce && index == m_PatCtrl.pat ) + return; + + if( index < 0 ) + index = MAX_ARP_PATTERNS - 1; + else if( index >= MAX_ARP_PATTERNS ) + index = 0; + + if( m_bCopySrc ) + { + // do not copy if we are not paused + if( m_bPauseState ) + { + memcpy( &m_PatternSave[ index ], &m_PatternSave[ m_PatCtrl.pat ], sizeof(ARP_PATTERN_STRUCT) ); + m_pButtonCopy->Set( false ); + m_bCopySrc = false; + } + } + + m_PatCtrl.pat = index; + + for( note = 0; note < MAX_ARP_NOTES; note++ ) + { + m_pButtonGlide[ note ]->Set( m_PatternSave[ m_PatCtrl.pat ].glide[ note ] ); + m_pButtonTrig[ note ]->Set( m_PatternSave[ m_PatCtrl.pat ].legato[ note ] ); + + for( param = 0; param < SUBSTEP_PER_NOTE; param++ ) + { + m_pButtonOnOff[ note ][ param ]->Set( m_PatternSave[ m_PatCtrl.pat ].onoffsel[ note ][ param ], true ); + m_pButtonLen[ note ][ param ]->Set( m_PatternSave[ m_PatCtrl.pat ].lensel[ note ][ param ], true ); + m_pButtonLenMod[ note ][ param ]->Set( m_PatternSave[ m_PatCtrl.pat ].lenmod[ note ][ param ], true ); + } + } + + m_pButtonOctaveSelect->Set( m_PatternSave[ m_PatCtrl.pat ].oct, true ); + m_pButtonMode->Set( m_PatternSave[ m_PatCtrl.pat ].mode, true ); + m_pPatternSelect->SetPat( index, false ); + m_pPatternSelect->SetMax( m_PatCtrl.used ); + + // set keyboard keys + pKeyboardWidget->setkey( m_PatternSave[ m_PatCtrl.pat ].notes ); +} + +//----------------------------------------------------- +// Procedure: IncStep +// +//----------------------------------------------------- +#define BASE_TICK_16th 48 // for 16th note + +const float fbasenotelen[ 6 ] = { BASE_TICK_16th * 4, BASE_TICK_16th * 2, BASE_TICK_16th, BASE_TICK_16th / 2, BASE_TICK_16th / 4, BASE_TICK_16th / 8}; + +const int patmode[ 7 ][ 42 ] = +{ + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1 }, + { 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, + { 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, -1 }, + { 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }, + { 0, 20, 1, 19, 2, 18, 3, 17, 4, 16, 5, 15, 6, 14, 7, 13, 8, 12, 9, 11, 10, 10, 11, 9, 12, 8, 13, 7, 14, 6, 15, 5, 16, 4, 17, 3, 18, 2, 19, 1, 20, 0 }, + { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } +}; + +void ARP700::ArpStep( bool bReset ) +{ + int i, nstep, substep, modestp; + + if( !m_PatternSave[ m_PatCtrl.pat ].notesused ) + { + m_PatCtrl.virtstep = -1; + m_PatCtrl.bTrig = false; + return; + } + else + { + if( bReset ) + m_PatCtrl.virtstep = -1; + + // find next used step + for( i = 0; i <= ( SUBSTEP_PER_NOTE * MAX_ARP_NOTES * 2 ); i++ ) + { + m_PatCtrl.virtstep++; + + if( m_PatCtrl.virtstep >= ( SUBSTEP_PER_NOTE * MAX_ARP_NOTES * 2 ) ) + m_PatCtrl.virtstep = 0; + + if( m_PatternSave[ m_PatCtrl.pat ].mode == 6 ) + modestp = (int)( randomUniform() * 20.0f ); + else + modestp = patmode[ m_PatternSave[ m_PatCtrl.pat ].mode ][ m_PatCtrl.virtstep ]; + + if( modestp != -1 ) + { + nstep = modestp / SUBSTEP_PER_NOTE; + substep = modestp - ( nstep * SUBSTEP_PER_NOTE ); + + if( m_PatternSave[ m_PatCtrl.pat ].onoffsel[ nstep ][ substep ] != ARP_OFF ) + { + m_PatCtrl.step = modestp; + goto stepfound; + } + } + else + { + m_PatCtrl.virtstep = -1; + } + } + } + + // if we are here, no step was found + m_PatCtrl.step = -1; + m_PatCtrl.bTrig = false; + return; + +stepfound: + + if( m_PatCtrl.step == 0 ) + { + if( m_PatCtrl.pending.bPending ) + { + m_PatCtrl.pending.bPending = false; + ChangePattern( m_PatCtrl.pending.pat, true ); + } + } + + nstep = m_PatCtrl.step / SUBSTEP_PER_NOTE; + substep = m_PatCtrl.step - ( nstep * SUBSTEP_PER_NOTE ); + + if( m_plastbut ) + m_plastbut->SetHiLightOn( -1 ); + + m_pButtonLen[ nstep ][ substep ]->SetHiLightOn( m_PatternSave[ m_PatCtrl.pat ].lensel[ nstep ][ substep ] ); + m_plastbut = m_pButtonLen[ nstep ][ substep ]; + + // next step length + m_PatCtrl.nextcount = fbasenotelen[ m_PatternSave[ m_PatCtrl.pat ].lensel[ nstep ][ substep ] ]; + + switch( m_PatternSave[ m_PatCtrl.pat ].lenmod[ nstep ][ substep ] ) + { + case 1: // x2 + m_PatCtrl.nextcount *= 2; + break; + case 2: // dotted + m_PatCtrl.nextcount += m_PatCtrl.nextcount / 2; + break; + case 3: // triplet + m_PatCtrl.nextcount = m_PatCtrl.nextcount / 3; + break; + } + + // if this is note on return true + if( m_PatternSave[ m_PatCtrl.pat ].onoffsel[ nstep ][ substep ] == ARP_ON ) + { + SetOut(); + + if( m_PatternSave[ m_PatCtrl.pat ].legato[ nstep ] ) + m_PatCtrl.bTrig = false; + else + m_PatCtrl.bTrig = true; + } +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +void ARP700::step() +{ + bool bSyncTick = false, bResetClk = false; + + if( !m_bInitialized ) + return; + + if( !inputs[ IN_CLOCK_TRIG ].active ) + { + outputs[ OUT_TRIG ].value = 0; + m_Clock.tickcount = 0; + m_Clock.fsynclen = 2.0 * 48.0; // default to 120bpm + m_Clock.fsynccount = 0; + m_Clock.IgnoreClockCount = 2; + + if( m_PatCtrl.pending.bPending ) + { + m_PatCtrl.pending.bPending = false; + ChangePattern( m_PatCtrl.pending.pat, false ); + } + + return; + } + + // global clock reset + m_Clock.bClockReset = ( m_SchTrigGlobalClkReset.process( inputs[ IN_CLOCK_RESET ].normalize( 0.0f ) ) ); + + // pattern change trig + if( !m_bPauseState && m_SchTrigPatternChange.process( inputs[ IN_PROG_CHANGE ].normalize( 0.0f ) ) ) + SetPendingPattern( -1 ); + + // track clock period + if( m_SchTrigClk.process( inputs[ IN_CLOCK_TRIG ].normalize( 0.0f ) ) || m_Clock.bClockReset ) + { + if( m_Clock.bClockReset ) + { + m_Clock.tickcount = 0; + //ArpStep( true ); + m_Clock.bClockReset = false; + m_Clock.IgnoreClockCount = 2; + bResetClk = true; + } + + if( m_Clock.tickcount && --m_Clock.IgnoreClockCount <= 0 ) + { + m_Clock.IgnoreClockCount = 0; + m_Clock.fsynclen = (float)( engineGetSampleRate() / (float)m_Clock.tickcount ) * 48.0; + } + + m_Clock.fsynccount = 0; + bSyncTick = true; + m_Clock.tickcount = 0; + } + else + { + // keep track of sync tick (16th / 12 ) + m_Clock.fsynccount += m_Clock.fsynclen; + if( m_Clock.fsynccount >= engineGetSampleRate() ) + { + m_Clock.fsynccount = m_Clock.fsynccount - engineGetSampleRate(); + bSyncTick = true; + } + } + + m_Clock.tickcount++; + + if( m_bPauseState ) + { + m_PatCtrl.bTrig = false; + + if( m_PatCtrl.pending.bPending ) + { + m_PatCtrl.pending.bPending = false; + ChangePattern( m_PatCtrl.pending.pat, false ); + } + } + else if( bSyncTick ) + { + if( bResetClk ) + m_PatCtrl.nextcount = 0; + else + m_PatCtrl.nextcount--; + + // cut off note one tick early so they don't legato + if( m_PatCtrl.nextcount == 1 ) + m_PatCtrl.bTrig = false; + + else if( m_PatCtrl.nextcount <= 0 ) + ArpStep( bResetClk ); + } + + outputs[ OUT_TRIG ].value = m_PatCtrl.bTrig ? CV_MAX : 0.0; + + if( --m_PatCtrl.glideCount > 0 ) + m_PatCtrl.fglide -= m_PatCtrl.fglideInc; + else + m_PatCtrl.fglide = 0.0; + + outputs[ OUT_VOCTS ].value = ( m_PatCtrl.fCvStartOut * m_PatCtrl.fglide ) + ( m_PatCtrl.fCvEndOut * ( 1.0 - m_PatCtrl.fglide ) ); + +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, ARP700) { + Model *modelARP700 = Model::create( "mscHack", "ARP700", "ARP 700", SEQUENCER_TAG ); + return modelARP700; +} diff --git a/plugins/community/repos/mscHack/src/CLog.cpp b/plugins/community/repos/mscHack/src/CLog.cpp new file mode 100644 index 00000000..935112e6 --- /dev/null +++ b/plugins/community/repos/mscHack/src/CLog.cpp @@ -0,0 +1,204 @@ +#include "rack.hpp" +#include "CLog.h" + +char Days[7][4]= +{ + {"Sun"}, + {"Mon"}, + {"Tue"}, + {"Wed"}, + {"Thu"}, + {"Fri"}, + {"Sat"} +}; + +char Months[12][4]= +{ + {"Jan"}, + {"Feb"}, + {"Mar"}, + {"Apr"}, + {"May"}, + {"Jun"}, + {"Jul"}, + {"Aug"}, + {"Sep"}, + {"Oct"}, + {"Nov"}, + {"Dec"} +}; + +//----------------------------------------------------- +// Function: +// +//----------------------------------------------------- +CLog::CLog() +{ + m_LogLevel = 1; + fp = NULL; + m_LogCallbackFunc = NULL; +} + +//----------------------------------------------------- +// Function: +// +//----------------------------------------------------- +CLog::~CLog() +{ + Close(); +} + +//----------------------------------------------------- +// Function: +// +//----------------------------------------------------- +int CLog::Open( std::string strFileName ) +{ + // test if this file is valid + if ( (fp = fopen( strFileName.c_str(), "w+" ) ) == NULL ) + return 0; + + // return success + return 1; +} + +//----------------------------------------------------- +// Function: +// +//----------------------------------------------------- +void CLog::Close(void) +{ + // if file not open then bail + if (fp) + { + // close the file handle + fclose(fp); + fp = NULL; + } +} + +//----------------------------------------------------- +// Function: SetLogLvl +// +//----------------------------------------------------- +void CLog::SetLogLvl( int level ) +{ + m_LogLevel = level; +} + +//----------------------------------------------------- +// Function: SetCallback +// +//----------------------------------------------------- +void CLog::SetCallback ( LOGCALLBACK *func, void *pClass ) +{ + m_LogCallbackFunc = func; + m_pCallbackClass = pClass; +} + +void CLog::f( std::string string, ... ) +{ + // if file not open then bail + if (!fp) + return; + + //_Xtime_get_ticks( + + va_list arglist; // variable argument list + + // print out the string using the variable number of arguments on stack + va_start( arglist, string ); + vsprintf( (char*)buffer.c_str(), string.c_str(), arglist ); + va_end( arglist ); + + // write string to file + fprintf( fp,(char*)buffer.c_str() ); + + // write string to callback so user can display it somewhere + if( m_LogCallbackFunc ) + m_LogCallbackFunc( m_pCallbackClass, (char*)buffer.c_str() ); + + fflush(fp); +} + +//----------------------------------------------------- +// Function: no timestamp +// +//----------------------------------------------------- +void CLog::fnr( std::string string, ...) +{ + + va_list arglist; // variable argument list + + // if file not open then bail + if (!fp) + return; + + // print out the string using the variable number of arguments on stack + va_start( arglist,string ); + vsprintf( (char*)buffer.c_str(), string.c_str(),arglist ); + va_end( arglist ); + + // write string to file + fprintf( fp, (char*)buffer.c_str() ); + + // write string to callback so user can display it somewhere + if( m_LogCallbackFunc ) + m_LogCallbackFunc( m_pCallbackClass, (char*)buffer.c_str() ); + + fflush(fp); +} + +//----------------------------------------------------- +// Function: mem - memory dump +// +//----------------------------------------------------- +void CLog::mem( unsigned char *pBuff, unsigned int dwSize, unsigned int dwOff ) +{ + int i; + unsigned int Offset=dwOff, index=0; + unsigned char Val[16]; + + // if file not open then bail + if (!fp) + return; + + do{ + f("0x%.4x: ", dwOff); + + Offset+=16; + dwOff+=16; + + for(i=0; i<16; i++) + { + // extra space every four + if(i%4 == 0) + f(" "); + + if( index < dwSize ) + { + Val[i]=pBuff[index]; + f("%.2x ", pBuff[index++]); + } + else + { + Val[i]=0; + f("-- ", pBuff[index++]); + } + } + + // print characters + for(i=0; i<16; i++) + { + if( isprint( Val[i] ) ) + f("%c", Val[i]); + else + f("."); + } + + f("\n"); + + }while(index < dwSize); + + f("\n\n"); +} \ No newline at end of file diff --git a/plugins/community/repos/mscHack/src/CLog.h b/plugins/community/repos/mscHack/src/CLog.h new file mode 100644 index 00000000..50ca7499 --- /dev/null +++ b/plugins/community/repos/mscHack/src/CLog.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include +#include +#include + +typedef void LOGCALLBACK ( void *pClass, char *str ); + +//------------------------------------------------------------- +//------------------------------------------------------------- +class CLog +{ +public: + CLog(); + ~CLog(); + + LOGCALLBACK *m_LogCallbackFunc; + void *m_pCallbackClass; + + int m_LogLevel; + + void SetCallback ( LOGCALLBACK *func, void *pClass ); + void f ( std::string string, ...); + void fnr ( std::string string, ...); + void mem ( unsigned char *pBuff, unsigned int dwSize, unsigned int dwOff ); + + int Open ( std::string strFileName ); + void SetLogLvl ( int level ); + void Close ( void ); + +private: + FILE *fp; + std::string buffer; +}; + + diff --git a/plugins/community/repos/mscHack/src/Compressor.cpp b/plugins/community/repos/mscHack/src/Compressor.cpp new file mode 100644 index 00000000..e2c2a2ad --- /dev/null +++ b/plugins/community/repos/mscHack/src/Compressor.cpp @@ -0,0 +1,423 @@ +#include "mscHack.hpp" +//#include "mscHack_Controls.hpp" +#include "dsp/digital.hpp" +//#include "CLog.h" + +namespace rack_plugin_mscHack { + +typedef struct +{ + int state; + float finc; + int count; + float fade; +}COMP_STATE; + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct Compressor : Module +{ + enum ParamIds + { + PARAM_INGAIN, + PARAM_OUTGAIN, + PARAM_THRESHOLD, + PARAM_RATIO, + PARAM_ATTACK, + PARAM_RELEASE, + PARAM_BYPASS, + PARAM_SIDE_CHAIN, + nPARAMS + }; + + enum InputIds + { + IN_AUDIOL, + IN_AUDIOR, + IN_SIDE_CHAIN, + nINPUTS + }; + + enum OutputIds + { + OUT_AUDIOL, + OUT_AUDIOR, + nOUTPUTS + }; + + enum CompState + { + COMP_DONE, + COMP_START, + COMP_ATTACK, + COMP_RELEASE, + COMP_IDLE + }; + + bool m_bInitialized = false; + CLog lg; + + LEDMeterWidget *m_pLEDMeterIn[ 2 ] = {0}; + CompressorLEDMeterWidget *m_pLEDMeterThreshold = NULL; + CompressorLEDMeterWidget *m_pLEDMeterComp[ 2 ] = {0}; + LEDMeterWidget *m_pLEDMeterOut[ 2 ] = {0}; + + bool m_bBypass = false; + MyLEDButton *m_pButtonBypass = NULL; + + COMP_STATE m_CompL = {}; + COMP_STATE m_CompR = {}; + float m_fThreshold; + + // Contructor + Compressor() : Module(nPARAMS, nINPUTS, nOUTPUTS, 0 ){} + + // Overrides + void step() override; + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onReset() override; + void onRandomize() override; + + bool ProcessCompState( COMP_STATE *pComp, bool bAboveThreshold ); + float Compress( float *pDetectInL, float *pDetectInR ); +}; + +//----------------------------------------------------- +// Compressor_Bypass +//----------------------------------------------------- +void Compressor_Bypass( void *pClass, int id, bool bOn ) +{ + Compressor *mymodule; + mymodule = (Compressor*)pClass; + mymodule->m_bBypass = bOn; +} + +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- + +struct Compressor_Widget : ModuleWidget { + Compressor_Widget( Compressor *module ); +}; + +Compressor_Widget::Compressor_Widget( Compressor *module ) : ModuleWidget(module) +{ + int x, y, y2; + + box.size = Vec( 15*8, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/Compressor.svg"))); + addChild(panel); + } + + //module->lg.Open("Compressor.txt"); + x = 10; + y = 34; + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + // bypass switch + module->m_pButtonBypass = new MyLEDButton( x, y, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, 0, module, Compressor_Bypass ); + addChild( module->m_pButtonBypass ); + + // audio inputs + addInput(Port::create( Vec( x, y + 32 ), Port::INPUT, module, Compressor::IN_AUDIOL ) ); + addInput(Port::create( Vec( x, y + 78 ), Port::INPUT, module, Compressor::IN_AUDIOR ) ); + addInput(Port::create( Vec( x - 1, y + 210 ), Port::INPUT, module, Compressor::IN_SIDE_CHAIN ) ); + + // LED meters + module->m_pLEDMeterIn[ 0 ] = new LEDMeterWidget( x + 22, y + 25, 5, 3, 2, true ); + addChild( module->m_pLEDMeterIn[ 0 ] ); + module->m_pLEDMeterIn[ 1 ] = new LEDMeterWidget( x + 28, y + 25, 5, 3, 2, true ); + addChild( module->m_pLEDMeterIn[ 1 ] ); + + module->m_pLEDMeterThreshold = new CompressorLEDMeterWidget( true, x + 39, y + 25, 5, 3, DWRGB( 245, 10, 174 ), DWRGB( 96, 4, 68 ) ); + addChild( module->m_pLEDMeterThreshold ); + + module->m_pLEDMeterComp[ 0 ] = new CompressorLEDMeterWidget( true, x + 48, y + 25, 5, 3, DWRGB( 0, 128, 255 ), DWRGB( 0, 64, 128 ) ); + addChild( module->m_pLEDMeterComp[ 0 ] ); + module->m_pLEDMeterComp[ 1 ] = new CompressorLEDMeterWidget( true, x + 55, y + 25, 5, 3, DWRGB( 0, 128, 255 ), DWRGB( 0, 64, 128 ) ); + addChild( module->m_pLEDMeterComp[ 1 ] ); + + module->m_pLEDMeterOut[ 0 ] = new LEDMeterWidget( x + 65, y + 25, 5, 3, 2, true ); + addChild( module->m_pLEDMeterOut[ 0 ] ); + module->m_pLEDMeterOut[ 1 ] = new LEDMeterWidget( x + 72, y + 25, 5, 3, 2, true ); + addChild( module->m_pLEDMeterOut[ 1 ] ); + + // audio outputs + addOutput(Port::create( Vec( x + 83, y + 32 ), Port::OUTPUT, module, Compressor::OUT_AUDIOL ) ); + addOutput(Port::create( Vec( x + 83, y + 78 ), Port::OUTPUT, module, Compressor::OUT_AUDIOR ) ); + + // add param knobs + y2 = y + 149; + addParam(ParamWidget::create( Vec( x + 11, y + 113 ), module, Compressor::PARAM_INGAIN, 0.0, 4.0, 1.0 ) ); + addParam(ParamWidget::create( Vec( x + 62, y + 113 ), module, Compressor::PARAM_OUTGAIN, 0.0, 8.0, 1.0 ) ); + addParam(ParamWidget::create( Vec( x - 5, y2 + 20 ), module, Compressor::PARAM_SIDE_CHAIN, 0.0, 1.0, 0.0 ) ); + addParam(ParamWidget::create( Vec( x + 39, y2 ), module, Compressor::PARAM_THRESHOLD, 0.0, 0.99, 0.0 ) ); y2 += 40; + addParam(ParamWidget::create( Vec( x + 39, y2 ), module, Compressor::PARAM_RATIO, 0.0, 2.0, 0.0 ) ); y2 += 40; + addParam(ParamWidget::create( Vec( x + 39, y2 ), module, Compressor::PARAM_ATTACK, 0.0, 1.0, 0.0 ) ); y2 += 40; + addParam(ParamWidget::create( Vec( x + 39, y2 ), module, Compressor::PARAM_RELEASE, 0.0, 1.0, 0.0 ) ); + + //for( int i = 0; i < 15; i++ ) + //module->lg.f("level %d = %.3f\n", i, module->m_pLEDMeterThreshold->flevels[ i ] ); + + module->m_bInitialized = true; +} + +//----------------------------------------------------- +// Procedure: +// +//----------------------------------------------------- +json_t *Compressor::toJson() +{ + json_t *rootJ = json_object(); + + // reverse state + json_object_set_new(rootJ, "m_bBypass", json_boolean (m_bBypass)); + + return rootJ; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void Compressor::fromJson(json_t *rootJ) +{ + // reverse state + json_t *revJ = json_object_get(rootJ, "m_bBypass"); + + if (revJ) + m_bBypass = json_is_true( revJ ); + + m_pButtonBypass->Set( m_bBypass ); +} + +//----------------------------------------------------- +// Procedure: reset +// +//----------------------------------------------------- +void Compressor::onReset() +{ +} + +//----------------------------------------------------- +// Procedure: randomize +// +//----------------------------------------------------- +void Compressor::onRandomize() +{ +} + +//----------------------------------------------------- +// Procedure: ProcessCompStatus +// +//----------------------------------------------------- +#define MAX_ATT_TIME (0.5f) // 500ms +#define MAX_REL_TIME (2.0f) // 2s +bool Compressor::ProcessCompState( COMP_STATE *pComp, bool bAboveThreshold ) +{ + bool bCompressing = true; + + // restart compressor if it has finished + if( bAboveThreshold && ( pComp->state == COMP_IDLE ) ) + { + pComp->state = COMP_START; + } + // ready compressor for restart + else if( !bAboveThreshold && ( pComp->state == COMP_DONE ) ) + { + pComp->state = COMP_IDLE; + } + + switch( pComp->state ) + { + case COMP_START: + pComp->count = 10 + (int)( MAX_ATT_TIME * engineGetSampleRate() * params[ PARAM_ATTACK ].value ); + + pComp->state = COMP_ATTACK; + pComp->finc = (1.0f - pComp->fade) / (float)pComp->count; + + break; + + case COMP_ATTACK: + if( --pComp->count > 0 ) + { + pComp->fade += pComp->finc; + + if( pComp->fade > 1.0f ) + pComp->fade = 1.0f; + } + else + { + pComp->count = 10 + (int)( MAX_REL_TIME * engineGetSampleRate() * params[ PARAM_RELEASE ].value ); + pComp->fade = 1.0f; + pComp->finc = 1.0f / (float)pComp->count; + pComp->state = COMP_RELEASE; + } + + break; + + case COMP_RELEASE: + if( --pComp->count > 0 ) + { + pComp->fade -= pComp->finc; + + if( pComp->fade < 0.0f ) + pComp->fade = 0.0f; + } + else + { + pComp->fade = 0.0f; + pComp->state = COMP_DONE; + bCompressing = false; + } + break; + + case COMP_DONE: + pComp->fade = 0.0f; + bCompressing = false; + break; + + case COMP_IDLE: + pComp->fade = 0.0f; + bCompressing = false; + break; + } + + return bCompressing; +} + +//----------------------------------------------------- +// Procedure: Compress +// +//----------------------------------------------------- +float Compressor::Compress( float *pDetectInL, float *pDetectInR ) +{ + float rat, th, finL, finR, compL = 1.0f, compR = 1.0f; + + m_fThreshold = params[ PARAM_THRESHOLD ].value; + th = 1.0f - m_fThreshold; + rat = params[ PARAM_RATIO ].value; + + finL = fabs( *pDetectInL ); + + if( ProcessCompState( &m_CompL, ( finL > th ) ) ) + compL = 1.0f - ( rat * m_CompL.fade ); + + if( pDetectInR ) + { + finR = fabs( *pDetectInR ); + + if( ProcessCompState( &m_CompR, ( finR > th ) ) ) + compR = 1.0f - ( rat * m_CompR.fade ); + } + else + { + m_CompR.state = COMP_IDLE; + m_CompR.fade = 0.0; + } + + return fmin( compL, compR ); +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +void Compressor::step() +{ + float outL, outR, diffL, diffR, fcomp, fside; + + if( !m_bInitialized ) + return; + + outL = inputs[ IN_AUDIOL ].normalize( 0.0 ) / AUDIO_MAX; + outR = inputs[ IN_AUDIOR ].normalize( 0.0 ) / AUDIO_MAX; + + if( !m_bBypass ) + { + outL = clamp( outL * params[ PARAM_INGAIN ].value, -1.0f, 1.0f ); + outR = clamp( outR * params[ PARAM_INGAIN ].value, -1.0f, 1.0f ); + } + + if( m_pLEDMeterIn[ 0 ] ) + m_pLEDMeterIn[ 0 ]->Process( outL ); + + if( m_pLEDMeterIn[ 1 ] ) + m_pLEDMeterIn[ 1 ]->Process( outR ); + + diffL = fabs( outL ); + diffR = fabs( outR ); + + if( !m_bBypass ) + { + // compress + if( inputs[ IN_SIDE_CHAIN ].active ) + { + fside = clamp( ( inputs[ IN_SIDE_CHAIN ].normalize( 0.0 ) / AUDIO_MAX ) * params[ PARAM_SIDE_CHAIN ].value, -1.0f, 1.0f ); + fcomp = Compress( &fside, NULL ); + } + else + { + fcomp = Compress( &outL, &outR ); + } + + outL *= fcomp; + outR *= fcomp; + + diffL -= fabs( outL ); + diffR -= fabs( outR ); + + if( m_pLEDMeterComp[ 0 ] ) + m_pLEDMeterComp[ 0 ]->Process( diffL ); + + if( m_pLEDMeterComp[ 1 ] ) + m_pLEDMeterComp[ 1 ]->Process( diffR ); + + if( m_pLEDMeterThreshold ) + m_pLEDMeterThreshold->Process( m_fThreshold ); + + outL = clamp( outL * params[ PARAM_OUTGAIN ].value, -1.0f, 1.0f ); + outR = clamp( outR * params[ PARAM_OUTGAIN ].value, -1.0f, 1.0f ); + } + else + { + if( m_pLEDMeterComp[ 0 ] ) + m_pLEDMeterComp[ 0 ]->Process( 0 ); + + if( m_pLEDMeterComp[ 1 ] ) + m_pLEDMeterComp[ 1 ]->Process( 0 ); + + if( m_pLEDMeterThreshold ) + m_pLEDMeterThreshold->Process( 0 ); + } + + if( m_pLEDMeterOut[ 0 ] ) + m_pLEDMeterOut[ 0 ]->Process( outL ); + + if( m_pLEDMeterOut[ 1 ] ) + m_pLEDMeterOut[ 1 ]->Process( outR ); + + outputs[ OUT_AUDIOL ].value = outL * AUDIO_MAX; + outputs[ OUT_AUDIOR ].value = outR * AUDIO_MAX; +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, Compressor) { + Model *modelCompressor = Model::create( "mscHack", "Compressor1", "COMP Basic Compressor", DYNAMICS_TAG ); + return modelCompressor; +} diff --git a/plugins/community/repos/mscHack/src/MasterClockx4.cpp b/plugins/community/repos/mscHack/src/MasterClockx4.cpp new file mode 100644 index 00000000..f888ec67 --- /dev/null +++ b/plugins/community/repos/mscHack/src/MasterClockx4.cpp @@ -0,0 +1,700 @@ +#include "mscHack.hpp" +//#include "mscHack_Controls.hpp" +#include "dsp/digital.hpp" +//#include "CLog.h" + +namespace rack_plugin_mscHack { + +#define nCHANNELS 4 + +#define MID_INDEX 12 +#define CLOCK_DIVS 25 +const int multdisplayval[ CLOCK_DIVS ] = { 32, 24, 16, 12, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 16, 24, 32 }; + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct MasterClockx4 : Module +{ + enum ParamIds + { + PARAM_BPM, + PARAM_MULT, + PARAM_HUMANIZE = PARAM_MULT + nCHANNELS, + nPARAMS + }; + + enum InputIds + { + INPUT_EXT_SYNC, + INPUT_CHAIN = INPUT_EXT_SYNC + nCHANNELS, + nINPUTS + }; + + enum OutputIds + { + OUTPUT_CLK, + OUTPUT_TRIG = OUTPUT_CLK + ( nCHANNELS * 4 ), + OUTPUT_CHAIN = OUTPUT_TRIG + ( nCHANNELS * 4 ), + nOUTPUTS + }; + + bool m_bInitialized = false; + CLog lg; + + float m_fBPM = 120; + + MyLED7DigitDisplay *m_pDigitDisplayMult[ nCHANNELS ] = {}; + MyLED7DigitDisplay *m_pDigitDisplayBPM = NULL; + + MyLEDButton *m_pButtonGlobalStop = NULL; + MyLEDButton *m_pButtonGlobalTrig = NULL; + MyLEDButton *m_pButtonStop[ nCHANNELS ] = {}; + MyLEDButton *m_pButtonTrig[ nCHANNELS ] = {}; + MyLEDButton *m_pButtonTimeX2[ nCHANNELS ] = {}; + + bool m_bGlobalSync = false; + bool m_bStopState[ nCHANNELS ] = {}; + bool m_bGlobalStopState = false; + bool m_bChannelSyncPending[ nCHANNELS ] = {}; + bool m_bTimeX2[ nCHANNELS ] = {}; + + int m_ChannelDivBeatCount[ nCHANNELS ] = {}; + float m_fChannelBeatsPers[ nCHANNELS ] = {}; + float m_fChannelClockCount[ nCHANNELS ] = {}; + int m_ChannelMultSelect[ nCHANNELS ] = {}; + + float m_fHumanize = 0; + float m_bWasChained = false; + + float m_fBeatsPers; + float m_fMainClockCount; + + PulseGenerator m_PulseClock[ nCHANNELS ]; + PulseGenerator m_PulseSync[ nCHANNELS ]; + SchmittTrigger m_SchmittSyncIn[ nCHANNELS ]; + + ParamWidget *m_pBpmKnob = NULL; + ParamWidget *m_pHumanKnob = NULL; + + // Contructor + MasterClockx4() : Module(nPARAMS, nINPUTS, nOUTPUTS, 0){} + + //----------------------------------------------------- + // MyHumanize_Knob + //----------------------------------------------------- + struct MyHumanize_Knob : Knob_Yellow2_26 + { + MasterClockx4 *mymodule; + + void onChange( EventChange &e ) override + { + mymodule = (MasterClockx4*)module; + + if( mymodule && !mymodule->inputs[ INPUT_CHAIN ].active ) + mymodule->GetNewHumanizeVal(); + + RoundKnob::onChange( e ); + } + }; + + //----------------------------------------------------- + // MyBPM_Knob + //----------------------------------------------------- + struct MyBPM_Knob : Knob_Yellow2_56 + { + MasterClockx4 *mymodule; + + void onChange( EventChange &e ) override + { + mymodule = (MasterClockx4*)module; + + if( mymodule && !mymodule->inputs[ INPUT_CHAIN ].active ) + mymodule->BPMChange( value, false ); + + RoundKnob::onChange( e ); + } + }; + + //----------------------------------------------------- + // MyMult_Knob + //----------------------------------------------------- + + struct MyMult_Knob : Knob_Yellow2_26_Snap + { + MasterClockx4 *mymodule; + int param, col; + + void onChange( EventChange &e ) override + { + mymodule = (MasterClockx4*)module; + + if( mymodule ) + { + //if( !mymodule->m_bInitialized ) + //return; + + param = paramId - MasterClockx4::PARAM_MULT; + + if( mymodule->m_ChannelMultSelect[ param ] != (int)value ) + { + mymodule->SetDisplayLED( param, (int)value ); + } + } + + RoundKnob::onChange( e ); + } + }; + + // Overrides + void step() override; + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onReset() override; + + void GetNewHumanizeVal( void ); + void BPMChange( float fbmp, bool bforce ); + void CalcChannelClockRate( int ch ); + void SetDisplayLED( int ch, int val ); +}; + +//----------------------------------------------------- +// MyLEDButton_GlobalStop +//----------------------------------------------------- +void MyLEDButton_GlobalStop( void *pClass, int id, bool bOn ) +{ + MasterClockx4 *mymodule; + mymodule = (MasterClockx4*)pClass; + mymodule->m_bGlobalStopState = bOn; +} + +//----------------------------------------------------- +// MyLEDButton_TimeX2 +//----------------------------------------------------- +void MyLEDButton_TimeX2( void *pClass, int id, bool bOn ) +{ + MasterClockx4 *mymodule; + mymodule = (MasterClockx4*)pClass; + mymodule->m_bTimeX2[ id ] = bOn; + mymodule->SetDisplayLED( id, (int)mymodule->params[ MasterClockx4::PARAM_MULT + id ].value ); +} + +//----------------------------------------------------- +// MyLEDButton_GlobalTrig +//----------------------------------------------------- +void MyLEDButton_GlobalTrig( void *pClass, int id, bool bOn ) +{ + MasterClockx4 *mymodule; + mymodule = (MasterClockx4*)pClass; + mymodule->m_bGlobalSync = true; +} + +//----------------------------------------------------- +// MyLEDButton_ChannelStop +//----------------------------------------------------- +void MyLEDButton_ChannelStop ( void *pClass, int id, bool bOn ) +{ + MasterClockx4 *mymodule; + mymodule = (MasterClockx4*)pClass; + mymodule->m_bStopState[ id ] = bOn; +} + +//----------------------------------------------------- +// MyLEDButton_ChannelSync +//----------------------------------------------------- +void MyLEDButton_ChannelSync( void *pClass, int id, bool bOn ) +{ + MasterClockx4 *mymodule; + mymodule = (MasterClockx4*)pClass; + mymodule->m_bChannelSyncPending[ id ] = true; + + if( mymodule->m_pButtonTrig[ id ] ) + mymodule->m_pButtonTrig[ id ]->Set( true ); +} + +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- + +struct MasterClockx4_Widget : ModuleWidget { + MasterClockx4_Widget( MasterClockx4 *module ); +}; + +MasterClockx4_Widget::MasterClockx4_Widget( MasterClockx4 *module ) : ModuleWidget(module) +{ + int ch, x, y; + + box.size = Vec( 15*18, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin( plugin, "res/MasterClockx4.svg"))); + addChild(panel); + } + + //module->lg.Open("MasterClockx4.txt"); + + // bpm knob + module->m_pBpmKnob = ParamWidget::create( Vec( 9, 50 ), module, MasterClockx4::PARAM_BPM, 60.0, 220.0, 120.0 ); + addParam( module->m_pBpmKnob ); + + // bpm display + module->m_pDigitDisplayBPM = new MyLED7DigitDisplay( 5, 115, 0.055, DWRGB( 0, 0, 0 ), DWRGB( 0xFF, 0xFF, 0xFF ), MyLED7DigitDisplay::TYPE_FLOAT, 5 ); + addChild( module->m_pDigitDisplayBPM ); + + // global stop switch + module->m_pButtonGlobalStop = new MyLEDButton( 22, 144, 25, 25, 20.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, 0, module, MyLEDButton_GlobalStop ); + addChild( module->m_pButtonGlobalStop ); + + // global sync button + module->m_pButtonGlobalTrig = new MyLEDButton( 22, 202, 25, 25, 20.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_MOMENTARY, 0, module, MyLEDButton_GlobalTrig ); + addChild( module->m_pButtonGlobalTrig ); + + // humanize knob + module->m_pHumanKnob = ParamWidget::create( Vec( 22, 235 ), module, MasterClockx4::PARAM_HUMANIZE, 0.0, 1.0, 0.0 ); + addParam( module->m_pHumanKnob ); + + // add chain out + addOutput(Port::create( Vec( 30, 345 ), Port::OUTPUT, module, MasterClockx4::OUTPUT_CHAIN ) ); + + // chain in + addInput(Port::create( Vec( 30, 13 ), Port::INPUT, module, MasterClockx4::INPUT_CHAIN ) ); + + x = 91; + y = 39; + + for( ch = 0; ch < nCHANNELS; ch++ ) + { + // x2 + module->m_pButtonTimeX2[ ch ] = new MyLEDButton( x + 2, y + 2, 11, 11, 9.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_SWITCH, ch, module, MyLEDButton_TimeX2 ); + addChild( module->m_pButtonTimeX2[ ch ] ); + + // clock mult knob + addParam(ParamWidget::create( Vec( x + 13, y + 13 ), module, MasterClockx4::PARAM_MULT + ch, 0, CLOCK_DIVS - 1, MID_INDEX ) ); + + // mult display + module->m_pDigitDisplayMult[ ch ] = new MyLED7DigitDisplay( x + 10, y + 48, 0.07, DWRGB( 0, 0, 0 ), DWRGB( 0xFF, 0xFF, 0xFF ), MyLED7DigitDisplay::TYPE_INT, 2 ); + addChild( module->m_pDigitDisplayMult[ ch ] ); + + // sync triggers + module->m_pButtonTrig[ ch ] = new MyLEDButton( x + 76, y + 4, 19, 19, 15.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_MOMENTARY, ch, module, MyLEDButton_ChannelSync ); + addChild( module->m_pButtonTrig[ ch ] ); + + addInput(Port::create( Vec( x + 54, y + 5 ), Port::INPUT, module, MasterClockx4::INPUT_EXT_SYNC + ch ) ); + addOutput(Port::create( Vec( x + 54, y + 31 ), Port::OUTPUT, module, MasterClockx4::OUTPUT_TRIG + (ch * 4) + 0 ) ); + addOutput(Port::create( Vec( x + 54, y + 53 ), Port::OUTPUT, module, MasterClockx4::OUTPUT_TRIG + (ch * 4) + 1 ) ); + addOutput(Port::create( Vec( x + 77, y + 31 ), Port::OUTPUT, module, MasterClockx4::OUTPUT_TRIG + (ch * 4) + 2 ) ); + addOutput(Port::create( Vec( x + 77, y + 53 ), Port::OUTPUT, module, MasterClockx4::OUTPUT_TRIG + (ch * 4) + 3 ) ); + + // clock out + module->m_pButtonStop[ ch ] = new MyLEDButton( x + 132, y + 4, 19, 19, 15.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, ch, module, MyLEDButton_ChannelStop ); + addChild( module->m_pButtonStop[ ch ] ); + + addOutput(Port::create( Vec( x + 107, y + 31 ), Port::OUTPUT, module, MasterClockx4::OUTPUT_CLK + (ch * 4) + 0 ) ); + addOutput(Port::create( Vec( x + 107, y + 53 ), Port::OUTPUT, module, MasterClockx4::OUTPUT_CLK + (ch * 4) + 1 ) ); + addOutput(Port::create( Vec( x + 130, y + 31 ), Port::OUTPUT, module, MasterClockx4::OUTPUT_CLK + (ch * 4) + 2 ) ); + addOutput(Port::create( Vec( x + 130, y + 53 ), Port::OUTPUT, module, MasterClockx4::OUTPUT_CLK + (ch * 4) + 3 ) ); + + y += 80; + } + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + module->m_bInitialized = true; + + module->onReset(); +} + +//----------------------------------------------------- +// Procedure: +// +//----------------------------------------------------- +json_t *MasterClockx4::toJson() +{ + bool *pbool; + json_t *rootJ = json_object(); + json_t *gateJ; + + // m_bGlobalStopState + json_object_set_new( rootJ, "m_bGlobalStopState", json_boolean (m_bGlobalStopState) ); + + // m_bStopState + pbool = &m_bStopState[ 0 ]; + + json_t *gatesJ = json_array(); + + for (int i = 0; i < nCHANNELS; i++) + { + gateJ = json_boolean( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "m_bStopState", gatesJ ); + + // m_bTimeX2 + pbool = &m_bTimeX2[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < nCHANNELS; i++) + { + gateJ = json_boolean( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "m_bTimeX2", gatesJ ); + return rootJ; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void MasterClockx4::fromJson(json_t *rootJ) +{ + bool *pbool; + json_t *gateJ; + + // m_bGlobalStopState + json_t *revJ = json_object_get(rootJ, "m_bGlobalStopState"); + + if (revJ) + m_bGlobalStopState = json_is_true( revJ ); + + // m_bPauseState + pbool = &m_bStopState[ 0 ]; + + json_t *StepsJ = json_object_get(rootJ, "m_bStopState"); + + if (StepsJ) + { + for (int i = 0; i < nCHANNELS; i++) + { + gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_boolean_value( gateJ ); + } + } + + // m_bTimeX2 + pbool = &m_bTimeX2[ 0 ]; + + StepsJ = json_object_get(rootJ, "m_bTimeX2"); + + if (StepsJ) + { + for (int i = 0; i < nCHANNELS; i++) + { + gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_boolean_value( gateJ ); + } + } + + + m_pButtonGlobalStop->Set( m_bGlobalStopState ); + + for( int ch = 0; ch < nCHANNELS; ch++ ) + { + m_pButtonStop[ ch ]->Set( m_bStopState[ ch ] ); + m_pButtonTimeX2[ ch ]->Set( m_bTimeX2[ ch ] ); + //lg.f( "value = %d\n", (int)params[ PARAM_MULT + ch ].value ); + SetDisplayLED( ch, (int)params[ PARAM_MULT + ch ].value ); + } + + m_fMainClockCount = 0; + BPMChange( params[ PARAM_BPM ].value, true ); + + if( m_pDigitDisplayBPM ) + m_pDigitDisplayBPM->SetFloat( m_fBPM ); +} + +//----------------------------------------------------- +// Procedure: reset +// +//----------------------------------------------------- +void MasterClockx4::onReset() +{ + if( !m_bInitialized ) + return; + + m_fBPM = 120; + + if( m_pDigitDisplayBPM ) + m_pDigitDisplayBPM->SetFloat( m_fBPM ); + + m_bGlobalStopState = false; + m_pButtonGlobalStop->Set( m_bGlobalStopState ); + + for( int ch = 0; ch < nCHANNELS; ch++ ) + { + m_bTimeX2[ ch ] = false; + m_bStopState[ ch ] = false; + m_pButtonStop[ ch ]->Set( m_bStopState[ ch ] ); + SetDisplayLED( ch, MID_INDEX ); + } + + BPMChange( m_fBPM, true ); +} + +//----------------------------------------------------- +// Procedure: SetDisplayLED +// +//----------------------------------------------------- +void MasterClockx4::SetDisplayLED( int ch, int val ) +{ + int col, mult = 1; + + if( !m_bInitialized ) + return; + + if( m_bTimeX2[ ch ] ) + mult = 2; + + if( val < MID_INDEX ) + { + col = DWRGB( 0xFF, 0, 0 ); + } + else if( val > MID_INDEX ) + { + col = DWRGB( 0, 0xFF, 0xFF ); + } + else + { + mult = 1; + col = DWRGB( 0xFF, 0xFF, 0xFF ); + } + + if( m_pDigitDisplayMult[ ch ] ) + { + m_ChannelMultSelect[ ch ] = val; + m_pDigitDisplayMult[ ch ]->SetLEDCol( col ); + + + m_pDigitDisplayMult[ ch ]->SetInt( multdisplayval[ val ] * mult ); + } + + CalcChannelClockRate( ch ); +} + +//----------------------------------------------------- +// Procedure: GetNewHumanizeVal +// +//----------------------------------------------------- +void MasterClockx4::GetNewHumanizeVal( void ) +{ + m_fHumanize = randomUniform() * engineGetSampleRate() * 0.1 * params[ PARAM_HUMANIZE ].value; + + if( randomUniform() > 0.5 ) + m_fHumanize *= -1; +} + +//----------------------------------------------------- +// Procedure: BMPChange +// +//----------------------------------------------------- +void MasterClockx4::BPMChange( float fbpm, bool bforce ) +{ + // don't change if it is already the same + if( !bforce && ( (int)(fbpm * 1000.0f ) == (int)(m_fBPM * 1000.0f ) ) ) + return; + + m_fBPM = fbpm; + m_fBeatsPers = fbpm / 60.0; + + if( m_pDigitDisplayBPM ) + m_pDigitDisplayBPM->SetFloat( m_fBPM ); + + for( int i = 0; i < nCHANNELS; i++ ) + CalcChannelClockRate( i ); +} + +//----------------------------------------------------- +// Procedure: CalcChannelClockRate +// +//----------------------------------------------------- +void MasterClockx4::CalcChannelClockRate( int ch ) +{ + int mult = 1; + + if( m_bTimeX2[ ch ] ) + mult = 2; + + // for beat division just keep a count of beats + if( m_ChannelMultSelect[ ch ] == MID_INDEX ) + m_ChannelDivBeatCount[ ch ] = 1; + if( m_ChannelMultSelect[ ch ] <= MID_INDEX ) + m_ChannelDivBeatCount[ ch ] = multdisplayval[ m_ChannelMultSelect[ ch ] ] * mult; + else + m_fChannelBeatsPers[ ch ] = m_fBeatsPers * (float)( multdisplayval[ m_ChannelMultSelect[ ch ] ] * mult ); +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +void MasterClockx4::step() +{ + int ch, mult = 1; + float fSyncPulseOut, fClkPulseOut; + bool bMainClockTrig = false, bChannelClockTrig; + + if( !m_bInitialized ) + return; + + // use the input chain trigger for our clock + if( inputs[ INPUT_CHAIN ].active ) + { + if( !m_bWasChained ) + { + m_pHumanKnob->visible = false; + m_pBpmKnob->visible = false; + } + + m_bWasChained = true; + + // value of less than zero is a trig + if( inputs[ INPUT_CHAIN ].value < 10.0 ) + { + bMainClockTrig = true; + } + // values greater than zero are the bpm + else + { + BPMChange( inputs[ INPUT_CHAIN ].value, false ); + } + } + else + { + // go back to our bpm if chain removed + if( m_bWasChained ) + { + m_pHumanKnob->visible = true; + m_pBpmKnob->visible = true; + m_bWasChained = false; + BPMChange( params[ PARAM_BPM ].value, false ); + } + + // keep track of main bpm + m_fMainClockCount += m_fBeatsPers; + if( ( m_fMainClockCount + m_fHumanize ) >= engineGetSampleRate() ) + { + m_fMainClockCount = ( m_fMainClockCount + m_fHumanize ) - engineGetSampleRate(); + + GetNewHumanizeVal(); + + bMainClockTrig = true; + } + } + + // send chain + if( outputs[ OUTPUT_CHAIN ].active ) + { + if( bMainClockTrig ) + outputs[ OUTPUT_CHAIN ].value = -1.0; + else + outputs[ OUTPUT_CHAIN ].value = m_fBPM; + } + + for( ch = 0; ch < nCHANNELS; ch++ ) + { + bChannelClockTrig = false; + + // sync triggers + if( m_bGlobalSync || m_SchmittSyncIn[ ch ].process( inputs[ INPUT_EXT_SYNC + ch ].value ) ) + { + if( m_pButtonTrig[ ch ] ) + m_pButtonTrig[ ch ]->Set( true ); + + m_bChannelSyncPending[ ch ] = true; + } + + // sync all triggers to main clock pulse + if( bMainClockTrig ) + { + if( m_bChannelSyncPending[ ch ] ) + { + if( m_pButtonTrig[ ch ] ) + m_pButtonTrig[ ch ]->Set( true ); + + m_bChannelSyncPending[ ch ] = false; + m_PulseSync[ ch ].trigger(1e-3); + + m_ChannelDivBeatCount[ ch ] = 0; + m_fChannelClockCount[ ch ] = 0; + bChannelClockTrig = true; + } + else + { + // divisions of clock will count beats + if( m_ChannelMultSelect[ ch ] <= MID_INDEX ) + { + if( m_bTimeX2[ ch ] ) + mult = 2; + + if( ++m_ChannelDivBeatCount[ ch ] >= ( multdisplayval[ m_ChannelMultSelect[ ch ] ] * mult ) ) + { + m_ChannelDivBeatCount[ ch ] = 0; + bChannelClockTrig = true; + } + } + // multiples of clock will sync with every beat + else + { + m_fChannelClockCount[ ch ] = 0; + bChannelClockTrig = true; + } + } + } + // do multiple clocks + else if( m_ChannelMultSelect[ ch ] > MID_INDEX ) + { + m_fChannelClockCount[ ch ] += m_fChannelBeatsPers[ ch ]; + if( m_fChannelClockCount[ ch ] >= engineGetSampleRate() ) + { + m_fChannelClockCount[ ch ] = m_fChannelClockCount[ ch ] - engineGetSampleRate(); + bChannelClockTrig = true; + } + } + + if( bChannelClockTrig ) + m_PulseClock[ ch ].trigger(1e-3); + + // syncs + fSyncPulseOut = m_PulseSync[ ch ].process( 1.0 / engineGetSampleRate() ) ? CV_MAX : 0.0; + outputs[ OUTPUT_TRIG + (ch * 4) + 0 ].value = fSyncPulseOut; + outputs[ OUTPUT_TRIG + (ch * 4) + 1 ].value = fSyncPulseOut; + outputs[ OUTPUT_TRIG + (ch * 4) + 2 ].value = fSyncPulseOut; + outputs[ OUTPUT_TRIG + (ch * 4) + 3 ].value = fSyncPulseOut; + + // clocks + fClkPulseOut = m_PulseClock[ ch ].process( 1.0 / engineGetSampleRate() ) ? CV_MAX : 0.0; + + if( !m_bGlobalStopState && !m_bStopState[ ch ] ) + { + outputs[ OUTPUT_CLK + (ch * 4) + 0 ].value = fClkPulseOut; + outputs[ OUTPUT_CLK + (ch * 4) + 1 ].value = fClkPulseOut; + outputs[ OUTPUT_CLK + (ch * 4) + 2 ].value = fClkPulseOut; + outputs[ OUTPUT_CLK + (ch * 4) + 3 ].value = fClkPulseOut; + } + } + + m_bGlobalSync = false; +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, MasterClockx4) { + Model *modelMasterClockx4 = Model::create( "mscHack", "MasterClockx4", "Master CLOCK x 4", CLOCK_TAG, QUAD_TAG ); + return modelMasterClockx4; +} diff --git a/plugins/community/repos/mscHack/src/Maude221.cpp b/plugins/community/repos/mscHack/src/Maude221.cpp new file mode 100644 index 00000000..587433d3 --- /dev/null +++ b/plugins/community/repos/mscHack/src/Maude221.cpp @@ -0,0 +1,329 @@ +#include "mscHack.hpp" +//#include "mscHack_Controls.hpp" +#include "dsp/digital.hpp" +//#include "CLog.h" + +namespace rack_plugin_mscHack { + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct Maude_221 : Module +{ + enum ParamIds + { + PARAM_LIMIT_INA, + PARAM_LIMIT_INB, + PARAM_AMP_OUTC, + PARAM_MODE, + PARAM_DCOFF, + PARAM_CVAMTA, + PARAM_CVAMTB, + nPARAMS + }; + + enum InputIds + { + INPUTA, + INPUTB, + INPUTCVA, + INPUTCVB, + nINPUTS + }; + + enum OutputIds + { + OUTPUTC, + nOUTPUTS + }; + + bool m_bInitialized = false; + CLog lg; + + // Contructor + Maude_221() : Module(nPARAMS, nINPUTS, nOUTPUTS){} + + MyLEDButtonStrip *m_pInputA_RectMode = NULL; + MyLEDButtonStrip *m_pInputB_RectMode = NULL; + MyLEDButtonStrip *m_pOutputC_RectMode = NULL; + + int m_RectMode[ 3 ] = {0}; + + // Overrides + void step() override; + void JsonParams( bool bTo, json_t *root); + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onRandomize() override; + void onReset() override; +}; + +//----------------------------------------------------- +// Procedure: Maude_221_RectSelect +//----------------------------------------------------- +void Maude_221_RectSelect( void *pClass, int id, int nbutton, bool bOn ) +{ + Maude_221 *mymodule; + mymodule = (Maude_221*)pClass; + + if( !mymodule || !mymodule->m_bInitialized ) + return; + + mymodule->m_RectMode[ id ] = nbutton; +} + +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- + +struct Maude_221_Widget : ModuleWidget { + Maude_221_Widget( Maude_221 *module ); +}; + +Maude_221_Widget::Maude_221_Widget( Maude_221 *module ) : ModuleWidget(module) +{ + box.size = Vec( 15*8, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/Maude221.svg"))); + addChild(panel); + } + + //module->lg.Open("Maude_221.txt"); + + addInput(Port::create( Vec( 22, 48 ), Port::INPUT, module, Maude_221::INPUTA ) ); + addInput(Port::create( Vec( 79, 48 ), Port::INPUT, module, Maude_221::INPUTB ) ); + + // rectify mode + module->m_pInputA_RectMode = new MyLEDButtonStrip( 15, 81, 12, 12, 0, 11.5, 3, false, DWRGB( 0, 0, 0 ), DWRGB( 180, 180, 180 ), MyLEDButtonStrip::TYPE_EXCLUSIVE, 0, module, Maude_221_RectSelect ); + addChild( module->m_pInputA_RectMode ); + + module->m_pInputB_RectMode = new MyLEDButtonStrip( 71, 81, 12, 12, 0, 11.5, 3, false, DWRGB( 0, 0, 0 ), DWRGB( 180, 180, 180 ), MyLEDButtonStrip::TYPE_EXCLUSIVE, 1, module, Maude_221_RectSelect ); + addChild( module->m_pInputB_RectMode ); + + // limit knobs + addParam(ParamWidget::create( Vec( 12, 106 ), module, Maude_221::PARAM_LIMIT_INA, 1.0, 10.0, 10.0 ) ); + addParam(ParamWidget::create( Vec( 67, 106 ), module, Maude_221::PARAM_LIMIT_INB, 1.0, 10.0, 10.0 ) ); + + // CV amount knobs + addParam(ParamWidget::create( Vec( 8, 152 ), module, Maude_221::PARAM_CVAMTA, 0.0, 1.0, 0.0 ) ); + addParam(ParamWidget::create( Vec( 94, 152 ), module, Maude_221::PARAM_CVAMTB, 0.0, 1.0, 0.0 ) ); + + // limit CV inputs + addInput(Port::create( Vec( 6, 173 ), Port::INPUT, module, Maude_221::INPUTCVA ) ); + addInput(Port::create( Vec( 93, 173 ), Port::INPUT, module, Maude_221::INPUTCVB ) ); + + // mode select knob + addParam(ParamWidget::create( Vec( 47, 188 ), module, Maude_221::PARAM_MODE, 0.0, 4.0, 0.0 ) ); + + // output rectify mode select + module->m_pOutputC_RectMode = new MyLEDButtonStrip( 32, 248, 12, 12, 0, 11.5, 5, false, DWRGB( 0, 0, 0 ), DWRGB( 180, 180, 180 ), MyLEDButtonStrip::TYPE_EXCLUSIVE, 2, module, Maude_221_RectSelect ); + addChild( module->m_pOutputC_RectMode ); + + // output amp + addParam(ParamWidget::create( Vec( 40, 273 ), module, Maude_221::PARAM_AMP_OUTC, 0.0, 2.0, 1.0 ) ); + + // DC Offset + addParam(ParamWidget::create( Vec( 80, 315 ), module, Maude_221::PARAM_DCOFF, -5.0, 5.0, 0.0 ) ); + + // output + addOutput(Port::create( Vec( 50, 344 ), Port::OUTPUT, module, Maude_221::OUTPUTC ) ); + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + module->m_pInputA_RectMode->Set( 1, true ); + module->m_pInputB_RectMode->Set( 1, true ); + module->m_pOutputC_RectMode->Set( 1, true ); + module->m_RectMode[ 0 ] = 1; + module->m_RectMode[ 1 ] = 1; + module->m_RectMode[ 2 ] = 1; + + module->m_bInitialized = true; +} + +//----------------------------------------------------- +// Procedure: JsonParams +// +//----------------------------------------------------- +void Maude_221::JsonParams( bool bTo, json_t *root) +{ + JsonDataInt( bTo, "RectModes", root, m_RectMode, 3 ); +} + +//----------------------------------------------------- +// Procedure: toJson +// +//----------------------------------------------------- +json_t *Maude_221::toJson() +{ + json_t *root = json_object(); + + if( !root ) + return NULL; + + JsonParams( TOJSON, root ); + + return root; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void Maude_221::fromJson( json_t *root ) +{ + JsonParams( FROMJSON, root ); + + m_pInputA_RectMode->Set( m_RectMode[ 0 ], true ); + m_pInputB_RectMode->Set( m_RectMode[ 1 ], true ); + m_pOutputC_RectMode->Set( m_RectMode[ 2 ], true ); +} +//----------------------------------------------------- +// Procedure: reset +// +//----------------------------------------------------- +void Maude_221::onReset() +{ +} + +//----------------------------------------------------- +// Procedure: randomize +// +//----------------------------------------------------- +void Maude_221::onRandomize() +{ +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +void Maude_221::step() +{ + float inA, inB, out = 0.0f, lima, limb; + + if( !m_bInitialized ) + return; + + if( !inputs[ INPUTA ].active && !inputs[ INPUTB ].active ) + { + outputs[ OUTPUTC ].value = 0.0f; + return; + } + + lima = clamp( params[ PARAM_LIMIT_INA ].value + ( inputs[ INPUTCVA ].normalize( 0.0f ) * params[ PARAM_CVAMTA ].value ), -10.0, 10.0 ); + limb = clamp( params[ PARAM_LIMIT_INB ].value + ( inputs[ INPUTCVB ].normalize( 0.0f ) * params[ PARAM_CVAMTB ].value ), -10.0, 10.0 ); + + inA = clamp( inputs[ INPUTA ].normalize( 0.0f ), -lima, lima ); + inB = clamp( inputs[ INPUTB ].normalize( 0.0f ), -limb, limb ); + + switch( m_RectMode[ 0 ] ) + { + case 0: // negative only + if( inA > 0.0f ) + inA = 0.0f; + break; + case 1: // bipolar + break; + case 2: // positive only + if( inA < 0.0f ) + inA = 0.0f; + break; + } + + switch( m_RectMode[ 1 ] ) + { + case 0: // negative only + if( inB > 0.0f ) + inB = 0.0f; + break; + case 1: // bipolar + break; + case 2: // positive only + if( inB < 0.0f ) + inB = 0.0f; + break; + } + + // only do math if both inputs are active + if( inputs[ INPUTA ].active && inputs[ INPUTB ].active ) + { + switch( (int)( params[ PARAM_MODE ].value ) ) + { + case 0: // add + out = inA + inB; + break; + case 1: // subtract + out = inA - inB; + break; + case 2: // multiply + out = sin(inA) * cos(inB); + break; + case 3: // divide + if( fabs( inA ) < fabs( inB ) ) + out = inA; + else + out = inB; + + break; + + case 4: // divide + if( fabs( inA ) > fabs( inB ) ) + out = inA; + else + out = inB; + + break; + } + } + else if( inputs[ INPUTA ].active ) + { + out = inA; + } + else + { + out = inB; + } + + switch( m_RectMode[ 2 ] ) + { + case 0: // negative half wave + if( out > 0.0f ) + out = 0.0f; + break; + case 1: // negative full wave + if( out > 0.0f ) + out = -out; + break; + case 2: // bipolar + break; + case 3: // positive full wave + if( out < 0.0f ) + out = -out; + break; + case 4: // positive half wave + if( out < 0.0f ) + out = 0.0f; + break; + } + + out = ( out * params[ PARAM_AMP_OUTC ].value ) + params[ PARAM_DCOFF ].value; + + outputs[ OUTPUTC ].value = out; +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, Maude_221) { + Model *modelMaude_221 = Model::create( "mscHack", "Maude221", "Maude 221 Wave Combiner", WAVESHAPER_TAG, UTILITY_TAG, MULTIPLE_TAG ); + return modelMaude_221; +} diff --git a/plugins/community/repos/mscHack/src/Mixer_1x4_Stereo.cpp b/plugins/community/repos/mscHack/src/Mixer_1x4_Stereo.cpp new file mode 100644 index 00000000..4b643b9a --- /dev/null +++ b/plugins/community/repos/mscHack/src/Mixer_1x4_Stereo.cpp @@ -0,0 +1,1089 @@ +#include "mscHack.hpp" +//#include "mscHack_Controls.hpp" +//#include "dsp/digital.hpp" +//#include "CLog.h" + +namespace rack_plugin_mscHack { + +#define GROUPS 1 +#define CH_PER_GROUP 4 +#define CHANNELS ( GROUPS * CH_PER_GROUP ) +#define nAUX 4 + +#define GROUP_OFF_X 52 +#define CHANNEL_OFF_X 34 + +#define FADE_MULT (0.0005f) + +#define L 0 +#define R 1 + +#define MUTE_FADE_STATE_IDLE 0 +#define MUTE_FADE_STATE_INC 1 +#define MUTE_FADE_STATE_DEC 2 + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct Mix_1x4_Stereo : Module +{ + enum ParamIds + { + PARAM_MAIN_LEVEL, + PARAM_LEVEL_IN, + PARAM_PAN_IN = PARAM_LEVEL_IN + CHANNELS, + PARAM_GROUP_LEVEL_IN = PARAM_PAN_IN + CHANNELS, + PARAM_GROUP_PAN_IN = PARAM_GROUP_LEVEL_IN + GROUPS, + PARAM_MUTE_BUTTON = PARAM_GROUP_PAN_IN + GROUPS, + PARAM_SOLO_BUTTON = PARAM_MUTE_BUTTON + CHANNELS, + PARAM_GROUP_MUTE = PARAM_SOLO_BUTTON + CHANNELS, + + PARAM_EQ_HI = PARAM_GROUP_MUTE + GROUPS, + PARAM_EQ_MD = PARAM_EQ_HI + CHANNELS, + PARAM_EQ_LO = PARAM_EQ_MD + CHANNELS, + + PARAM_AUX_KNOB = PARAM_EQ_LO + CHANNELS, + PARAM_AUX_PREFADE = PARAM_AUX_KNOB + (GROUPS * nAUX), + PARAM_AUX_OUT = PARAM_AUX_PREFADE + (GROUPS * nAUX), + + nPARAMS = PARAM_AUX_OUT + (nAUX) + }; + + enum InputIds + { + IN_LEFT, + IN_RIGHT = IN_LEFT + CHANNELS, + IN_LEVEL = IN_RIGHT + CHANNELS, + IN_PAN = IN_LEVEL + CHANNELS, + IN_GROUP_LEVEL = IN_PAN + CHANNELS, + IN_GROUP_PAN = IN_GROUP_LEVEL + GROUPS, + nINPUTS = IN_GROUP_PAN + GROUPS + }; + + enum OutputIds + { + OUT_MAINL, + OUT_MAINR, + + OUT_AUXL, + OUT_AUXR = OUT_AUXL + nAUX, + + nOUTPUTS = OUT_AUXR + nAUX + }; + + bool m_bInitialized = false; + CLog lg; + + // mute buttons + bool m_bMuteStates[ CHANNELS ] = {}; + int m_FadeState[ CHANNELS ] = {MUTE_FADE_STATE_IDLE}; + float m_fMuteFade[ CHANNELS ] = {1.0}; + + // solo buttons + bool m_bSoloStates[ CHANNELS ] = {}; + + // group mute buttons + bool m_bGroupMuteStates[ GROUPS ] = {}; + float m_fGroupMuteFade[ GROUPS ] = {}; + int m_GroupFadeState[ GROUPS ] = {MUTE_FADE_STATE_IDLE}; + + // processing + bool m_bMono[ CHANNELS ]; + float m_fSubMix[ GROUPS ][ 3 ] = {}; + + // aux + bool m_bGroupPreFadeAuxStates[ GROUPS ][ nAUX ] = {}; + + // LED Meters + LEDMeterWidget *m_pLEDMeterChannel[ CHANNELS ][ 2 ] ={}; + LEDMeterWidget *m_pLEDMeterGroup[ GROUPS ][ 2 ] ={}; + LEDMeterWidget *m_pLEDMeterMain[ 2 ] ={}; + + // buttons + MyLEDButton *m_pButtonChannelMute[ CHANNELS ] = {}; + MyLEDButton *m_pButtonChannelSolo[ CHANNELS ] = {}; + MyLEDButton *m_pButtonGroupMute[ GROUPS ] = {}; + //MyLEDButton *m_pButtonGroupSolo[ GROUPS ] = {}; + MyLEDButton *m_pButtonAuxPreFader[ GROUPS ][ nAUX ] = {}; + + // EQ Rez + float lp1[ CHANNELS ][ 2 ] = {}, bp1[ CHANNELS ][ 2 ] = {}; + float m_hpIn[ CHANNELS ]; + float m_lpIn[ CHANNELS ]; + float m_mpIn[ CHANNELS ]; + float m_rezIn[ CHANNELS ] = {0}; + float m_Freq; + +#define L 0 +#define R 1 + + // Contructor + Mix_1x4_Stereo() : Module( nPARAMS, nINPUTS, nOUTPUTS, 0 ){} + + //----------------------------------------------------- + // MyEQHi_Knob + //----------------------------------------------------- + struct MyEQHi_Knob : Knob_Green1_15 + { + Mix_1x4_Stereo *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Mix_1x4_Stereo*)module; + + if( mymodule ) + { + param = paramId - Mix_1x4_Stereo::PARAM_EQ_HI; + + mymodule->m_hpIn[ param ] = value; + } + + RoundKnob::onChange( e ); + } + }; + + //----------------------------------------------------- + // MyEQHi_Knob + //----------------------------------------------------- + struct MyEQMid_Knob : Knob_Green1_15 + { + Mix_1x4_Stereo *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Mix_1x4_Stereo*)module; + + if( mymodule ) + { + param = paramId - Mix_1x4_Stereo::PARAM_EQ_MD; + mymodule->m_mpIn[ param ] = value; + } + + RoundKnob::onChange( e ); + } + }; + + //----------------------------------------------------- + // MyEQHi_Knob + //----------------------------------------------------- + struct MyEQLo_Knob : Knob_Green1_15 + { + Mix_1x4_Stereo *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Mix_1x4_Stereo*)module; + + if( mymodule ) + { + param = paramId - Mix_1x4_Stereo::PARAM_EQ_LO; + mymodule->m_lpIn[ param ] = value; + } + + RoundKnob::onChange( e ); + } + }; + + // Overrides + void step() override; + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onRandomize() override{} + void onReset() override; + + void ProcessMuteSolo( int channel, bool bMute, bool bGroup ); + void ProcessEQ( int ch, float *pL, float *pR ); +}; + +//----------------------------------------------------- +// MyLEDButton_Aux +//----------------------------------------------------- +void MyLEDButton_Aux( void *pClass, int id, bool bOn ) +{ + Mix_1x4_Stereo *mymodule; + mymodule = (Mix_1x4_Stereo*)pClass; + + mymodule->m_bGroupPreFadeAuxStates[ 0 ][ id ] = !mymodule->m_bGroupPreFadeAuxStates[ 0 ][ id ]; + mymodule->m_pButtonAuxPreFader[ 0 ][ id ]->Set( mymodule->m_bGroupPreFadeAuxStates[ 0 ][ id ] ); +} + +//----------------------------------------------------- +// MyLEDButton_ChMute +//----------------------------------------------------- +void MyLEDButton_ChMute( void *pClass, int id, bool bOn ) +{ + Mix_1x4_Stereo *mymodule; + mymodule = (Mix_1x4_Stereo*)pClass; + mymodule->ProcessMuteSolo( id, true, false ); +} + +//----------------------------------------------------- +// MyLEDButton_ChSolo +//----------------------------------------------------- +void MyLEDButton_ChSolo( void *pClass, int id, bool bOn ) +{ + Mix_1x4_Stereo *mymodule; + mymodule = (Mix_1x4_Stereo*)pClass; + mymodule->ProcessMuteSolo( id, false, false ); +} + +//----------------------------------------------------- +// MyLEDButton_GroupMute +//----------------------------------------------------- +void MyLEDButton_GroupMute( void *pClass, int id, bool bOn ) +{ + Mix_1x4_Stereo *mymodule; + mymodule = (Mix_1x4_Stereo*)pClass; + mymodule->ProcessMuteSolo( id, true, true ); +} + +//----------------------------------------------------- +// MyLEDButton_GroupSolo +//----------------------------------------------------- +/*void MyLEDButton_GroupSolo( void *pClass, int id, bool bOn ) +{ + Mix_1x4_Stereo *mymodule; + mymodule = (Mix_1x4_Stereo*)pClass; + mymodule->ProcessMuteSolo( id, false, true ); +}*/ + +#define CUTOFF (0.025f) +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- +struct Mix_1x4_Stereo_Widget : ModuleWidget { + Mix_1x4_Stereo_Widget( Mix_1x4_Stereo *module ); +}; + +Mix_1x4_Stereo_Widget::Mix_1x4_Stereo_Widget( Mix_1x4_Stereo *module ) : ModuleWidget(module) +{ + float fx, fx2, fx3, fx5, fx7; + int ch, x, y, i, ybase, x2, y2; + + box.size = Vec( 15*16, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/Mix_1x4_Stereo.svg"))); + addChild(panel); + } + + //module->lg.Open("Mix_1x4_Stereo.txt"); + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + //---------------------------------------------------- + // Add mix sliders + x = 23; + y = 38; + + // main channel + for ( ch = 0; ch < CHANNELS; ch++ ) + { + // Left channel inputs + addInput( Port::create( Vec( x, y ), Port::INPUT, module, Mix_1x4_Stereo::IN_LEFT + ch ) ); + //addInput(Port::create( Vec( x, y ), module, Mix_1x4_Stereo::IN_LEFT + ch ) ); + + y += 25; + + // Right channel inputs + addInput( Port::create( Vec( x, y ), Port::INPUT, module, Mix_1x4_Stereo::IN_RIGHT + ch ) ); + + y += 26; + + // Level knobs + addParam(ParamWidget::create( Vec( x - 5, y ), module, Mix_1x4_Stereo::PARAM_LEVEL_IN + ch, 0.0, AMP_MAX, 0.0 ) ); + + y += 31; + + // Level inputs + addInput(Port::create( Vec( x, y ), Port::INPUT, module, Mix_1x4_Stereo::IN_LEVEL + ch ) ); + + y += 23; + + // pan knobs + addParam(ParamWidget::create( Vec( x - 5, y ), module, Mix_1x4_Stereo::PARAM_PAN_IN + ch, -1.0, 1.0, 0.0 ) ); + + y += 31; + + // Pan inputs + addInput(Port::create( Vec( x, y ), Port::INPUT, module, Mix_1x4_Stereo::IN_PAN + ch ) ); + + y += 22; + + // mute buttons + module->m_pButtonChannelMute[ ch ] = new MyLEDButton( x - 5, y, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, ch, module, MyLEDButton_ChMute ); + addChild( module->m_pButtonChannelMute[ ch ] ); + //y += 26; + + // solo buttons + module->m_pButtonChannelSolo[ ch ] = new MyLEDButton( x + 11, y, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_SWITCH, ch, module, MyLEDButton_ChSolo ); + addChild( module->m_pButtonChannelSolo[ ch ] ); + + y += 22; + y2 = y; + + // eq and rez + addParam(ParamWidget::create( Vec( x - 5, y ), module, Mix_1x4_Stereo::PARAM_EQ_HI + ch, 0.0, 1.0, 0.5 ) ); + + y += 19; + + addParam(ParamWidget::create( Vec( x - 5, y ), module, Mix_1x4_Stereo::PARAM_EQ_MD + ch, 0.0, 1.0, 0.5 ) ); + + y += 19; + + addParam(ParamWidget::create( Vec( x - 5, y ), module, Mix_1x4_Stereo::PARAM_EQ_LO + ch, 0.0, 1.0, 0.5 ) ); + + // LED Meters + module->m_pLEDMeterChannel[ ch ][ 0 ] = new LEDMeterWidget( x + 13, y2 + 30, 4, 1, 1, true ); + addChild( module->m_pLEDMeterChannel[ ch ][ 0 ] ); + module->m_pLEDMeterChannel[ ch ][ 1 ] = new LEDMeterWidget( x + 18, y2 + 30, 4, 1, 1, true ); + addChild( module->m_pLEDMeterChannel[ ch ][ 1 ] ); + + if( ( ch & 3 ) == 3 ) + { + x += GROUP_OFF_X; + } + else + { + x += CHANNEL_OFF_X; + } + + y = 38; + } + + // group mixers + ybase = 278; + x = 12; + for( i = 0; i < GROUPS; i++ ) + { + // mute/solo buttons + x2 = x + 81; + y2 = ybase; + + module->m_pButtonGroupMute[ i ] = new MyLEDButton( x2, y2 + 4, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, i, module, MyLEDButton_GroupMute ); + addChild( module->m_pButtonGroupMute[ i ] ); + + // group level and pan inputs + x2 = x + 79; + y2 = ybase + 23; + + // group VU Meters + module->m_pLEDMeterGroup[ i ][ 0 ] = new LEDMeterWidget( x2 + 2, y2 + 21, 5, 2, 1, true ); + addChild( module->m_pLEDMeterGroup[ i ][ 0 ] ); + module->m_pLEDMeterGroup[ i ][ 1 ] = new LEDMeterWidget( x2 + 9, y2 + 21, 5, 2, 1, true ); + addChild( module->m_pLEDMeterGroup[ i ][ 1 ] ); + + // group level and pan knobs + x2 = x + 105; + y2 = ybase + 17; + + //addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_1x4_Stereo::PARAM_GROUP_LEVEL_IN + i, 0.0, AMP_MAX, 0.0 ) ); + + y2 += 32; + + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_1x4_Stereo::PARAM_GROUP_PAN_IN + i, -1.0, 1.0, 0.0 ) ); + + // aux 1/3 +#define AUX_H 29 + x2 = x + 6; + y2 = ybase + 20; + + module->m_pButtonAuxPreFader[ 0 ][ 0 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, 0, module, MyLEDButton_Aux ); + addChild( module->m_pButtonAuxPreFader[ 0 ][ 0 ] ); + + y2 += AUX_H; + + module->m_pButtonAuxPreFader[ 0 ][ 2 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, 2, module, MyLEDButton_Aux ); + addChild( module->m_pButtonAuxPreFader[ 0 ][ 2 ] ); + + x2 = x + 20; + y2 = ybase + 16; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_1x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 0, 0.0, AMP_MAX, 0.0 ) ); + y2 += AUX_H; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_1x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 2, 0.0, AMP_MAX, 0.0 ) ); + + // aux 2/4 + x2 = x + 38; + y2 = ybase + 28; + + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_1x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 1, 0.0, AMP_MAX, 0.0 ) ); + y2 += AUX_H; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_1x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 3, 0.0, AMP_MAX, 0.0 ) ); + + x2 = x + 62; + y2 = ybase + 32; + + module->m_pButtonAuxPreFader[ 0 ][ 1 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, 1, module, MyLEDButton_Aux ); + addChild( module->m_pButtonAuxPreFader[ 0 ][ 1 ] ); + + y2 += AUX_H; + + module->m_pButtonAuxPreFader[ 0 ][ 3 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, 3, module, MyLEDButton_Aux ); + addChild( module->m_pButtonAuxPreFader[ 0 ][ 3 ] ); + + // account for slight error in pixel conversion to svg area + x += 155; + } + + // main mixer knob + addParam(ParamWidget::create( Vec( 161, 237 ), module, Mix_1x4_Stereo::PARAM_MAIN_LEVEL, 0.0, AMP_MAX, 0.0 ) ); + + module->m_pLEDMeterMain[ 0 ] = new LEDMeterWidget( 161 + 58, 242, 5, 3, 2, true ); + addChild( module->m_pLEDMeterMain[ 0 ] ); + module->m_pLEDMeterMain[ 1 ] = new LEDMeterWidget( 161 + 65, 242, 5, 3, 2, true ); + addChild( module->m_pLEDMeterMain[ 1 ] ); + + // outputs + addOutput(Port::create( Vec( 172, 305 ), Port::OUTPUT, module, Mix_1x4_Stereo::OUT_MAINL ) ); + addOutput(Port::create( Vec( 204, 335 ), Port::OUTPUT, module, Mix_1x4_Stereo::OUT_MAINR ) ); + + // AUX out +#define AUX_OUT_H 42 + x2 = 185; + y2 = 25; + + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_1x4_Stereo::PARAM_AUX_OUT + 0, 0.0, AMP_MAX, 0.0 ) ); y2 += AUX_OUT_H; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_1x4_Stereo::PARAM_AUX_OUT + 1, 0.0, AMP_MAX, 0.0 ) ); y2 += AUX_OUT_H; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_1x4_Stereo::PARAM_AUX_OUT + 2, 0.0, AMP_MAX, 0.0 ) ); y2 += AUX_OUT_H; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_1x4_Stereo::PARAM_AUX_OUT + 3, 0.0, AMP_MAX, 0.0 ) ); + + x2 = 171; + y2 = 45; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_1x4_Stereo::OUT_AUXL ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_1x4_Stereo::OUT_AUXL + 1 ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_1x4_Stereo::OUT_AUXL + 2 ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_1x4_Stereo::OUT_AUXL + 3 ) ); + + x2 = 200; + y2 = 45; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_1x4_Stereo::OUT_AUXR ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_1x4_Stereo::OUT_AUXR + 1 ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_1x4_Stereo::OUT_AUXR + 2 ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_1x4_Stereo::OUT_AUXR + 3 ) ); + + // calculate eq rez freq + fx = 3.141592 * (CUTOFF * 0.026315789473684210526315789473684) * 2 * 3.141592; + fx2 = fx*fx; + fx3 = fx2*fx; + fx5 = fx3*fx2; + fx7 = fx5*fx2; + + module->m_Freq = 2.0 * (fx + - (fx3 * 0.16666666666666666666666666666667) + + (fx5 * 0.0083333333333333333333333333333333) + - (fx7 * 0.0001984126984126984126984126984127)); + + module->m_bInitialized = true; + module->onReset(); +} + +//----------------------------------------------------- +// Procedure: reset +// +//----------------------------------------------------- +void Mix_1x4_Stereo::onReset() +{ + int ch, i, aux; + + if( !m_bInitialized ) + return; + + for( ch = 0; ch < CHANNELS; ch++ ) + { + m_FadeState[ ch ] = MUTE_FADE_STATE_IDLE; + + m_pButtonChannelMute[ ch ]->Set( false ); + m_pButtonChannelSolo[ ch ]->Set( false ); + + m_bMuteStates[ ch ] = false; + m_bSoloStates[ ch ] = false; + m_fMuteFade[ ch ] = 1.0; + } + + for( i = 0; i < GROUPS; i++ ) + { + for( aux = 0; aux < nAUX; aux++ ) + { + m_bGroupPreFadeAuxStates[ i ][ aux ] = false; + m_pButtonAuxPreFader[ i ][ aux ]->Set( false ); + } + + m_GroupFadeState[ i ] = MUTE_FADE_STATE_IDLE; + m_pButtonGroupMute[ i ]->Set( false ); + //m_pButtonGroupSolo[ i ]->Set( false ); + m_bGroupMuteStates[ i ] = false; + m_fGroupMuteFade[ i ] = 1.0; + } +} + +//----------------------------------------------------- +// Procedure: +// +//----------------------------------------------------- +json_t *Mix_1x4_Stereo::toJson() +{ + bool *pbool; + json_t *gatesJ; + json_t *rootJ = json_object(); + + // channel mutes + pbool = &m_bMuteStates[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < CHANNELS; i++) + { + json_t *gateJ = json_integer( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "Mix_1x4_Stereo_channel_mutes", gatesJ ); + + // channel solos + pbool = &m_bSoloStates[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < CHANNELS; i++) + { + json_t *gateJ = json_integer( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "Mix_1x4_Stereo_channel_solos", gatesJ ); + + // group mutes + pbool = &m_bGroupMuteStates[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < GROUPS; i++) + { + json_t *gateJ = json_integer( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "Mix_1x4_Stereo_group_mutes", gatesJ ); + + // AUX states + pbool = &m_bGroupPreFadeAuxStates[ 0 ][ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < GROUPS * nAUX; i++) + { + json_t *gateJ = json_integer( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "Mix_1x4_Stereo_group_AUX_prefade_states", gatesJ ); + + return rootJ; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void Mix_1x4_Stereo::fromJson(json_t *rootJ) +{ + int ch, i, aux; + bool *pbool; + json_t *StepsJ; + bool bSolo[ GROUPS ] = {0}; + + // channel mutes + pbool = &m_bMuteStates[ 0 ]; + + StepsJ = json_object_get( rootJ, "Mix_1x4_Stereo_channel_mutes" ); + + if (StepsJ) + { + for ( i = 0; i < CHANNELS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_integer_value( gateJ ); + } + } + + // channel solos + pbool = &m_bSoloStates[ 0 ]; + + StepsJ = json_object_get( rootJ, "Mix_1x4_Stereo_channel_solos" ); + + if (StepsJ) + { + for ( i = 0; i < CHANNELS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_integer_value( gateJ ); + } + } + + // group mutes + pbool = &m_bGroupMuteStates[ 0 ]; + + StepsJ = json_object_get( rootJ, "Mix_1x4_Stereo_group_mutes" ); + + if (StepsJ) + { + for ( i = 0; i < GROUPS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_integer_value( gateJ ); + } + } + + // AUX states + pbool = &m_bGroupPreFadeAuxStates[ 0 ][ 0 ]; + + StepsJ = json_object_get( rootJ, "Mix_1x4_Stereo_group_AUX_prefade_states" ); + + if (StepsJ) + { + for ( i = 0; i < GROUPS * nAUX; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_integer_value( gateJ ); + } + } + + // anybody soloing? + for( ch = 0; ch < CHANNELS; ch++ ) + { + if( m_bSoloStates[ ch ] ) + { + bSolo[ ch / CH_PER_GROUP ] = true; + } + } + + for( ch = 0; ch < CHANNELS; ch++ ) + { + if( bSolo[ ch / CH_PER_GROUP ] ) + { + // only open soloing channels + if( m_bSoloStates[ ch ] ) + m_fMuteFade[ ch ] = 1.0; + else + m_fMuteFade[ ch ] = 0.0; + } + else + { + // nobody is soloing so just open the non muted channels + m_fMuteFade[ ch ] = m_bMuteStates[ ch ] ? 0.0: 1.0; + } + + m_pButtonChannelMute[ ch ]->Set( m_bMuteStates[ ch ] ); + m_pButtonChannelSolo[ ch ]->Set( m_bSoloStates[ ch ] ); + } + + for( i = 0; i < GROUPS; i++ ) + { + for( aux = 0; aux < nAUX; aux++ ) + m_pButtonAuxPreFader[ i ][ aux ]->Set( m_bGroupPreFadeAuxStates[ i ][ aux ] ); + + m_fGroupMuteFade[ i ] = m_bGroupMuteStates[ i ] ? 0.0: 1.0; + m_pButtonGroupMute[ i ]->Set( m_bGroupMuteStates[ i ] ); + //m_pButtonGroupSolo[ i ]->Set( m_bGroupSoloStates[ i ] ); + } +} + +//----------------------------------------------------- +// Procedure: ProcessMuteSolo +// +//----------------------------------------------------- +void Mix_1x4_Stereo::ProcessMuteSolo( int index, bool bMute, bool bGroup ) +{ + int i, group, si, ei; + bool bSoloEnabled = false, bSoloOff = false; + + if( bGroup ) + { + if( bMute ) + { + m_bGroupMuteStates[ index ] = !m_bGroupMuteStates[ index ]; + + // if mute is off then set volume + if( m_bGroupMuteStates[ index ] ) + { + m_pButtonGroupMute[ index ]->Set( true ); + m_GroupFadeState[ index ] = MUTE_FADE_STATE_DEC; + } + else + { + m_pButtonGroupMute[ index ]->Set( false ); + m_GroupFadeState[ index ] = MUTE_FADE_STATE_INC; + } + } + } + // !bGroup + else + { + group = index / CH_PER_GROUP; + + si = group * CH_PER_GROUP; + ei = si + CH_PER_GROUP; + + if( bMute ) + { + m_bMuteStates[ index ] = !m_bMuteStates[ index ]; + + // turn solo off + if( m_bSoloStates[ index ] ) + { + bSoloOff = true; + m_bSoloStates[ index ] = false; + m_pButtonChannelSolo[ index ]->Set( false ); + } + + // if mute is off then set volume + if( m_bMuteStates[ index ] ) + { + m_pButtonChannelMute[ index ]->Set( true ); + m_FadeState[ index ] = MUTE_FADE_STATE_DEC; + } + else + { + m_pButtonChannelMute[ index ]->Set( false ); + m_FadeState[ index ] = MUTE_FADE_STATE_INC; + } + } + else + { + m_bSoloStates[ index ] = !m_bSoloStates[ index ]; + + // turn mute off + if( m_bMuteStates[ index ] ) + { + m_bMuteStates[ index ] = false; + m_pButtonChannelMute[ index ]->Set( false ); + } + + // toggle solo + if( !m_bSoloStates[ index ] ) + { + bSoloOff = true; + m_pButtonChannelSolo[ index ]->Set( false ); + } + else + { + m_pButtonChannelSolo[ index ]->Set( true ); + } + } + + // is a track soloing? + for( i = si; i < ei; i++ ) + { + if( m_bSoloStates[ i ] ) + { + bSoloEnabled = true; + break; + } + } + + if( bSoloEnabled ) + { + // process solo + for( i = si; i < ei; i++ ) + { + // shut down volume of all not in solo + if( !m_bSoloStates[ i ] ) + { + m_FadeState[ i ] = MUTE_FADE_STATE_DEC; + } + else + { + m_FadeState[ i ] = MUTE_FADE_STATE_INC; + } + } + } + // nobody soloing and just turned solo off then enable all channels that aren't muted + else if( bSoloOff ) + { + // process solo + for( i = si; i < ei; i++ ) + { + // bring back if not muted + if( !m_bMuteStates[ i ] ) + { + m_FadeState[ i ] = MUTE_FADE_STATE_INC; + } + } + } + } +} + +//----------------------------------------------------- +// Procedure: ProcessEQ +// +//----------------------------------------------------- +#define MULTI (0.33333333333333333333333333333333f) +void Mix_1x4_Stereo::ProcessEQ( int ch, float *pL, float *pR ) +{ + float rez, hp1; + float input[ 2 ], out[ 2 ], lowpass, bandpass, highpass; + + input[ L ] = *pL / AUDIO_MAX; + input[ R ] = *pR / AUDIO_MAX; + + rez = 1.00; + + // do left and right channels + for( int i = 0; i < 2; i++ ) + { + input[ i ] = input[ i ] + 0.000000001; + + lp1[ ch ][ i ] = lp1[ ch ][ i ] + m_Freq * bp1[ ch ][ i ]; + hp1 = input[ i ] - lp1[ ch ][ i ] - rez * bp1[ ch ][ i ]; + bp1[ ch ][ i ] = m_Freq * hp1 + bp1[ ch ][ i ]; + lowpass = lp1[ ch ][ i ]; + highpass = hp1; + bandpass = bp1[ ch ][ i ]; + + lp1[ ch ][ i ] = lp1[ ch ][ i ] + m_Freq * bp1[ ch ][ i ]; + hp1 = input[ i ] - lp1[ ch ][ i ] - rez * bp1[ ch ][ i ]; + bp1[ ch ][ i ] = m_Freq * hp1 + bp1[ ch ][ i ]; + lowpass = lowpass + lp1[ ch ][ i ]; + highpass = highpass + hp1; + bandpass = bandpass + bp1[ ch ][ i ]; + + input[ i ] = input[ i ] - 0.000000001; + lp1[ ch ][ i ] = lp1[ ch ][ i ] + m_Freq * bp1[ ch ][ i ]; + hp1 = input[ i ] - lp1[ ch ][ i ] - rez * bp1[ ch ][ i ]; + bp1[ ch ][ i ] = m_Freq * hp1 + bp1[ ch ][ i ]; + + lowpass = (lowpass + lp1[ ch ][ i ]) * MULTI; + highpass = (highpass + hp1) * MULTI; + bandpass = (bandpass + bp1[ ch ][ i ]) * MULTI; + + out[ i ] = ( highpass * m_hpIn[ ch ] ) + ( lowpass * m_lpIn[ ch ] ) + ( bandpass * m_mpIn[ ch ] ); + } + + *pL = clamp( out[ L ] * AUDIO_MAX, -AUDIO_MAX, AUDIO_MAX ); + *pR = clamp( out[ R ] * AUDIO_MAX, -AUDIO_MAX, AUDIO_MAX ); +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +void Mix_1x4_Stereo::step() +{ + int ch, group, aux; + float inL = 0.0, inR = 0.0, inLClean, inRClean, outL, outR, mainL = 0.0, mainR = 0.0; + float inLvl, inPan; + float auxL[ nAUX ] = {}, auxR[ nAUX ] = {}; + bool bGroupActive[ GROUPS ] = {0}; + + if( !m_bInitialized ) + return; + + memset( m_fSubMix, 0, sizeof(m_fSubMix) ); + + // channel mixers + for ( ch = 0; ch < CHANNELS; ch++ ) + { + group = ch / CH_PER_GROUP; + + inLClean = 0.0; + inRClean = 0.0; + inL = 0.0; + inR = 0.0; + + if( inputs[ IN_RIGHT + ch ].active || inputs[ IN_LEFT + ch ].active ) + { + inLvl = clamp( ( params[ PARAM_LEVEL_IN + ch ].value + ( inputs[ IN_LEVEL + ch ].normalize( 0.0f ) / CV_MAX ) ), 0.0f, AMP_MAX ); + + bGroupActive[ group ] = true; + + // check right channel first for possible mono + if( inputs[ IN_RIGHT + ch ].active ) + { + inRClean = inputs[ IN_RIGHT + ch ].value; + inR = inRClean * inLvl; + m_bMono[ ch ] = false; + } + else + m_bMono[ ch ] = true; + + // left channel + if( inputs[ IN_LEFT + ch ].active ) + { + inLClean = inputs[ IN_LEFT + ch ].value; + inL = inLClean * inLvl; + + if( m_bMono[ ch ] ) + { + inRClean = inLClean; + inR = inL; + } + } + + // put output to aux if pre fader + for ( aux = 0; aux < nAUX; aux++ ) + { + if( m_bGroupPreFadeAuxStates[ group ][ aux ] ) + { + auxL[ aux ] += inLClean * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value; + auxR[ aux ] += inRClean * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value; + } + } + + if( m_FadeState[ ch ] == MUTE_FADE_STATE_DEC ) + { + m_fMuteFade[ ch ] -= FADE_MULT; + + if( m_fMuteFade[ ch ] <= 0.0 ) + { + m_fMuteFade[ ch ] = 0.0; + m_FadeState[ ch ] = MUTE_FADE_STATE_IDLE; + } + } + else if( m_FadeState[ ch ] == MUTE_FADE_STATE_INC ) + { + m_fMuteFade[ ch ] += FADE_MULT; + + if( m_fMuteFade[ ch ] >= 1.0 ) + { + m_fMuteFade[ ch ] = 1.0; + m_FadeState[ ch ] = MUTE_FADE_STATE_IDLE; + } + } + + ProcessEQ( ch, &inL, &inR ); + + inL *= m_fMuteFade[ ch ]; + inR *= m_fMuteFade[ ch ]; + + // pan + inPan = clamp( params[ PARAM_PAN_IN + ch ].value + ( inputs[ IN_PAN + ch ].normalize( 0.0f ) / CV_MAX ), -1.0f, 1.0f ); + + //lg.f("pan = %.3f\n", inputs[ IN_PAN + ch ].value ); + + if( inPan <= 0.0 ) + inR *= ( 1.0 + inPan ); + else + inL *= ( 1.0 - inPan ); + + // put output to aux if not pre fader + for ( aux = 0; aux < nAUX; aux++ ) + { + if( !m_bGroupPreFadeAuxStates[ group ][ aux ] ) + { + auxL[ aux ] += inL * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value; + auxR[ aux ] += inR * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value; + } + } + } + // this channel not active + else + { + + } + + m_fSubMix[ group ][ L ] += inL; + m_fSubMix[ group ][ R ] += inR; + + if( m_pLEDMeterChannel[ ch ][ 0 ] ) + m_pLEDMeterChannel[ ch ][ 0 ]->Process( inL / AUDIO_MAX ); + if( m_pLEDMeterChannel[ ch ][ 1 ] ) + m_pLEDMeterChannel[ ch ][ 1 ]->Process( inR / AUDIO_MAX); + } + + // group mixers + for ( group = 0; group < GROUPS; group++ ) + { + outL = 0.0; + outR = 0.0; + + if( bGroupActive[ group ] ) + { + //inLvl = clamp( ( params[ PARAM_GROUP_LEVEL_IN + group ].value + ( inputs[ IN_GROUP_LEVEL + group ].normalize( 0.0f ) / CV_MAX ) ), 0.0f, AMP_MAX ); + + outL = m_fSubMix[ group ][ L ];// * inLvl; + outR = m_fSubMix[ group ][ R ];// * inLvl; + + // pan + inPan = clamp( params[ PARAM_GROUP_PAN_IN + group ].value + ( inputs[ IN_GROUP_PAN + group ].normalize( 0.0f ) / CV_MAX ), -1.0f, 1.0f ); + + if( inPan <= 0.0 ) + outR *= ( 1.0 + inPan ); + else + outL *= ( 1.0 - inPan ); + + if( m_GroupFadeState[ group ] == MUTE_FADE_STATE_DEC ) + { + m_fGroupMuteFade[ group ] -= FADE_MULT; + + if( m_fGroupMuteFade[ group ] <= 0.0 ) + { + m_fGroupMuteFade[ group ] = 0.0; + m_GroupFadeState[ group ] = MUTE_FADE_STATE_IDLE; + } + } + else if( m_GroupFadeState[ group ] == MUTE_FADE_STATE_INC ) + { + m_fGroupMuteFade[ group ] += FADE_MULT; + + if( m_fGroupMuteFade[ group ] >= 1.0 ) + { + m_fGroupMuteFade[ group ] = 1.0; + m_GroupFadeState[ group ] = MUTE_FADE_STATE_IDLE; + } + } + + outL *= m_fGroupMuteFade[ group ]; + outR *= m_fGroupMuteFade[ group ]; + } + + if( m_pLEDMeterGroup[ group ][ 0 ] ) + m_pLEDMeterGroup[ group ][ 0 ]->Process( outL / AUDIO_MAX ); + if( m_pLEDMeterGroup[ group ][ 1 ] ) + m_pLEDMeterGroup[ group ][ 1 ]->Process( outR / AUDIO_MAX ); + + mainL += outL; + mainR += outR; + } + + if( m_pLEDMeterMain[ 0 ] ) + m_pLEDMeterMain[ 0 ]->Process( ( mainL / AUDIO_MAX ) * params[ PARAM_MAIN_LEVEL ].value ); + if( m_pLEDMeterMain[ 1 ] ) + m_pLEDMeterMain[ 1 ]->Process( ( mainR / AUDIO_MAX ) * params[ PARAM_MAIN_LEVEL ].value ); + + // put aux output + for ( aux = 0; aux < nAUX; aux++ ) + { + outputs[ OUT_AUXL + aux ].value = clamp( auxL[ aux ] * params[ PARAM_AUX_OUT + aux ].value, -AUDIO_MAX, AUDIO_MAX ); + outputs[ OUT_AUXR + aux ].value = clamp( auxR[ aux ] * params[ PARAM_AUX_OUT + aux ].value, -AUDIO_MAX, AUDIO_MAX ); + } + + outputs[ OUT_MAINL ].value = clamp( mainL * params[ PARAM_MAIN_LEVEL ].value, -AUDIO_MAX, AUDIO_MAX ); + outputs[ OUT_MAINR ].value = clamp( mainR * params[ PARAM_MAIN_LEVEL ].value, -AUDIO_MAX, AUDIO_MAX ); +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, Mix_1x4_Stereo) { + Model *modelMix_1x4_Stereo = Model::create( "mscHack", "Mix_1x4_Stereo", "MIXER 1x4 Stereo/Mono", MIXER_TAG, EQUALIZER_TAG, PANNING_TAG, AMPLIFIER_TAG, MULTIPLE_TAG ); + return modelMix_1x4_Stereo; +} diff --git a/plugins/community/repos/mscHack/src/Mixer_24_4_4.cpp b/plugins/community/repos/mscHack/src/Mixer_24_4_4.cpp new file mode 100644 index 00000000..7976cf6b --- /dev/null +++ b/plugins/community/repos/mscHack/src/Mixer_24_4_4.cpp @@ -0,0 +1,1088 @@ +#include "mscHack.hpp" + +namespace rack_plugin_mscHack { + +#define nCHANNELS 32 +#define nINCHANNELS 24 +#define nGROUPS 4 +#define nAUX 4 +#define nEQ 3 + +#define FADE_MULT (0.0005f) +#define CUTOFF (0.025f) + +#define L 0 +#define R 1 + +#define MUTE_FADE_STATE_IDLE 0 +#define MUTE_FADE_STATE_INC 1 +#define MUTE_FADE_STATE_DEC 2 + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct Mixer_24_4_4 : Module +{ + enum ParamIds + { + PARAM_LEVEL_OUT, + PARAM_CHLVL, + PARAM_CHPAN = PARAM_CHLVL + nCHANNELS, + PARAM_CHEQHI = PARAM_CHPAN + nCHANNELS, + PARAM_CHEQMD = PARAM_CHEQHI + nCHANNELS, + PARAM_CHEQLO = PARAM_CHEQMD + nCHANNELS, + PARAM_CHAUX = PARAM_CHEQLO + nCHANNELS, + PARAM_AUXLVL = PARAM_CHAUX + ( (nCHANNELS - 4) * nAUX ), + nPARAMS = PARAM_AUXLVL + nAUX, + }; + + enum InputIds + { + IN_LEFT, + IN_RIGHT = IN_LEFT + nCHANNELS, + IN_LEVELCV = IN_RIGHT + nCHANNELS, + IN_PANCV = IN_LEVELCV + nINCHANNELS, + IN_FADEX = IN_PANCV + nINCHANNELS, + IN_FADEY, + nINPUTS + }; + + enum OutputIds + { + OUT_MAINL, + OUT_MAINR, + + OUT_GRPL, + OUT_GRPR = OUT_GRPL + nGROUPS, + + OUT_AUXL = OUT_GRPR + nGROUPS, + OUT_AUXR = OUT_AUXL + nAUX, + + nOUTPUTS = OUT_AUXR + nAUX + }; + + enum LightIds + { + nLIGHTS + }; + + bool m_bInitialized = false; + CLog lg; + + // Contructor + Mixer_24_4_4() : Module(nPARAMS, nINPUTS, nOUTPUTS, nLIGHTS){} + + // mute/solo + bool m_bMuteStates[ nCHANNELS ] = {}; + float m_fMuteFade[ nCHANNELS ] = {}; + int m_FadeState[ nCHANNELS ] = {MUTE_FADE_STATE_IDLE}; + bool m_bSoloStates[ nCHANNELS ] = {}; + bool m_bPreFader[ nINCHANNELS + nGROUPS ] = {}; + + // processing + bool m_bMono[ nCHANNELS ]; + + // LED Meters + LEDMeterWidget *m_pLEDMeterChannel[ nCHANNELS ][ 2 ] ={}; + LEDMeterWidget *m_pLEDMeterMain[ 2 ] ={}; + + // EQ Rez + float lp1[ nCHANNELS ][ 2 ] = {}, bp1[ nCHANNELS ][ 2 ] = {}; + float m_hpIn[ nCHANNELS ]; + float m_lpIn[ nCHANNELS ]; + float m_mpIn[ nCHANNELS ]; + float m_Freq; + + // buttons + MyLEDButton *m_pButtonChannelMute[ nCHANNELS ] = {}; + MyLEDButton *m_pButtonChannelSolo[ nCHANNELS ] = {}; + MyLEDButton *m_pButtonPreFader[ nCHANNELS ] = {}; + + // routing + int m_iRouteGroup[ nINCHANNELS ] = {nGROUPS}; + MyLEDButtonStrip *m_pMultiButtonRoute[ nINCHANNELS ] = {0}; + + bool m_bGroupPreMute = true; + bool m_bGainLevelx2 = false; + + // Overrides + void step() override; + void JsonParams( bool bTo, json_t *root); + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onRandomize() override; + void onReset() override; + void onCreate() override; + void onDelete() override; + + void ProcessMuteSolo( int channel, bool bMute, bool bGroup, bool bOn ); + void ProcessEQ( int ch, float *pL, float *pR ); + void SetControls( int ch ); + + //----------------------------------------------------- + // MyEQHi_Knob + //----------------------------------------------------- + struct MyEQHi_Knob : Knob_Green1_15 + { + Mixer_24_4_4 *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Mixer_24_4_4*)module; + + if( mymodule ) + { + param = paramId - Mixer_24_4_4::PARAM_CHEQHI; + + mymodule->m_hpIn[ param ] = value; + } + + RoundKnob::onChange( e ); + } + }; + + //----------------------------------------------------- + // MyEQHi_Knob + //----------------------------------------------------- + struct MyEQMid_Knob : Knob_Green1_15 + { + Mixer_24_4_4 *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Mixer_24_4_4*)module; + + if( mymodule ) + { + param = paramId - Mixer_24_4_4::PARAM_CHEQMD; + mymodule->m_mpIn[ param ] = value; + } + + RoundKnob::onChange( e ); + } + }; + + //----------------------------------------------------- + // MyEQHi_Knob + //----------------------------------------------------- + struct MyEQLo_Knob : Knob_Green1_15 + { + Mixer_24_4_4 *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Mixer_24_4_4*)module; + + if( mymodule ) + { + param = paramId - Mixer_24_4_4::PARAM_CHEQLO; + mymodule->m_lpIn[ param ] = value; + } + + RoundKnob::onChange( e ); + } + }; +}; + +//----------------------------------------------------- +// MyLEDButton_ChSolo +//----------------------------------------------------- +void Button_ChSolo( void *pClass, int id, bool bOn ) +{ + Mixer_24_4_4 *mymodule; + mymodule = (Mixer_24_4_4*)pClass; + mymodule->ProcessMuteSolo( id, false, false, bOn ); +} + +//----------------------------------------------------- +// MyLEDButton_ChMute +//----------------------------------------------------- +void Button_ChMute( void *pClass, int id, bool bOn ) +{ + Mixer_24_4_4 *mymodule; + mymodule = (Mixer_24_4_4*)pClass; + mymodule->ProcessMuteSolo( id, true, false, bOn ); +} + +//----------------------------------------------------- +// Button_ChPreFader +//----------------------------------------------------- +void Button_ChPreFader( void *pClass, int id, bool bOn ) +{ + Mixer_24_4_4 *mymodule; + mymodule = (Mixer_24_4_4*)pClass; + mymodule->m_bPreFader[ id ] = bOn; +} + +//----------------------------------------------------- +// Procedure: RouteCallback +//----------------------------------------------------- +void RouteCallback( void *pClass, int id, int nbutton, bool bOn ) +{ + Mixer_24_4_4 *mymodule; + mymodule = (Mixer_24_4_4*)pClass; + + if( mymodule ) + { + mymodule->m_iRouteGroup[ id ] = nbutton; + } +} + +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- + +struct Mixer_24_4_4_Widget : ModuleWidget +{ + Menu *createContextMenu() override; + Mixer_24_4_4_Widget( Mixer_24_4_4 *module ); +}; + +Mixer_24_4_4_Widget::Mixer_24_4_4_Widget( Mixer_24_4_4 *module ) : ModuleWidget(module) +{ + Port *pPort; + float fx, fx2, fx3, fx5, fx7; + int ch, x, y, x2, y2; + bool bGroup, bAux, bNormal; + + box.size = Vec( 15*57, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/Mixer_24_4_4.svg"))); + addChild(panel); + } + + //module->lg.Open("Mixer_24_4_4.txt"); + + x = 47; + y = 13; + + for( ch = 0; ch < nCHANNELS; ch++ ) + { + bGroup = false; + bAux = false; + bNormal= false; + + // groups + if( ch < nINCHANNELS ) + bNormal = true; + else if( ch >= nINCHANNELS && ch < ( nINCHANNELS + nGROUPS) ) + bGroup = true; + else + bAux = true; + + x2 = x + 3; + y2 = y + 8; + + // inputs + pPort = Port::create( Vec( x2, y2 ), Port::INPUT, module, Mixer_24_4_4::IN_LEFT + ch ); + addInput( pPort ); y2 += 23; + + if( bGroup ) + pPort->visible = false; + + pPort = Port::create( Vec( x2, y2 ), Port::INPUT, module, Mixer_24_4_4::IN_RIGHT + ch ); + addInput( pPort ); + + if( bGroup ) + pPort->visible = false; + + x2 = x + 4; + y2 += 20; + + // aux sends + if( !bAux ) + { + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mixer_24_4_4::PARAM_CHAUX + (ch * 4) + 0, 0.0, 1.0, 0.0 ) ); + y2 += 17; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mixer_24_4_4::PARAM_CHAUX + (ch * 4) + 1, 0.0, 1.0, 0.0 ) ); + y2 += 17; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mixer_24_4_4::PARAM_CHAUX + (ch * 4) + 2, 0.0, 1.0, 0.0 ) ); + y2 += 17; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mixer_24_4_4::PARAM_CHAUX + (ch * 4) + 3, 0.0, 1.0, 0.0 ) ); + + module->m_pButtonPreFader[ ch ] = new MyLEDButton( x2 - 3, y2 + 15, 7, 7, 5.0f, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 255 ), MyLEDButton::TYPE_SWITCH, ch, module, Button_ChPreFader ); + addChild( module->m_pButtonPreFader[ ch ] ); + + y2 += 24; + } + else + { + switch( ch ) + { + case 28: + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mixer_24_4_4::PARAM_AUXLVL + 0, 0.0, 1.0, 0.0 ) ); + break; + case 29: + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mixer_24_4_4::PARAM_AUXLVL + 1, 0.0, 1.0, 0.0 ) ); + break; + case 30: + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mixer_24_4_4::PARAM_AUXLVL + 2, 0.0, 1.0, 0.0 ) ); + break; + case 31: + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mixer_24_4_4::PARAM_AUXLVL + 3, 0.0, 1.0, 0.0 ) ); + break; + } + + addOutput(Port::create( Vec( x2 - 1, y2 + 22), Port::OUTPUT, module, Mixer_24_4_4::OUT_AUXL + (ch - 28) ) ); + addOutput(Port::create( Vec( x2 - 1, y2 + 47), Port::OUTPUT, module, Mixer_24_4_4::OUT_AUXR + (ch - 28) ) ); + + y2 += 75; + } + + // EQ + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mixer_24_4_4::PARAM_CHEQHI + ch, 0.0, 1.0, 0.5 ) ); + y2 += 18; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mixer_24_4_4::PARAM_CHEQMD + ch, 0.0, 1.0, 0.5 ) ); + y2 += 18; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mixer_24_4_4::PARAM_CHEQLO + ch, 0.0, 1.0, 0.5 ) ); + y2 += 20; + + // CVs + if( bNormal ) + { + addInput(Port::create( Vec( x2 - 1, y2 ), Port::INPUT, module, Mixer_24_4_4::IN_LEVELCV + ch ) ); + y2 += 25; + addInput(Port::create( Vec( x2 - 1, y2 ), Port::INPUT, module, Mixer_24_4_4::IN_PANCV + ch ) ); + } + // group outs + else if( bGroup ) + { + addOutput(Port::create( Vec( x2 - 1, y2 ), Port::OUTPUT, module, Mixer_24_4_4::OUT_GRPL + (ch - nINCHANNELS) ) ); + y2 += 25; + addOutput(Port::create( Vec( x2 - 1, y2 ), Port::OUTPUT, module, Mixer_24_4_4::OUT_GRPR + (ch - nINCHANNELS) ) ); + } + else + y2 += 25; + + y2 += 23; + + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mixer_24_4_4::PARAM_CHPAN + ch, -1.0, 1.0, 0.0 ) ); + + y2 += 19; + + // mute/solo + if( bNormal ) + { + module->m_pButtonChannelMute[ ch ] = new MyLEDButton( x + 3, y2, 8, 8, 6.0f, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, ch, module, Button_ChMute ); + addChild( module->m_pButtonChannelMute[ ch ] ); + + module->m_pButtonChannelSolo[ ch ] = new MyLEDButton( x + 12, y2, 8, 8, 6.0f, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 0 ), MyLEDButton::TYPE_SWITCH, ch, module, Button_ChSolo ); + addChild( module->m_pButtonChannelSolo[ ch ] ); + } + // mute only + else + { + module->m_pButtonChannelMute[ ch ] = new MyLEDButton( x + 7, y2, 8, 8, 6.0f, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, ch, module, Button_ChMute ); + addChild( module->m_pButtonChannelMute[ ch ] ); + } + + // VUMeter + module->m_pLEDMeterChannel[ ch ][ 0 ] = new LEDMeterWidget( x + 7, y + 260, 4, 1, 1, true ); + addChild( module->m_pLEDMeterChannel[ ch ][ 0 ] ); + module->m_pLEDMeterChannel[ ch ][ 1 ] = new LEDMeterWidget( x + 12, y + 260, 4, 1, 1, true ); + addChild( module->m_pLEDMeterChannel[ ch ][ 1 ] ); + + x2 = x + 2; + y2 = y + 290; + + // Group Route + if( bNormal ) + { + module->m_pMultiButtonRoute[ ch ] = new MyLEDButtonStrip( x2, y2, 6, 6, 3, 4.0f, 5, true, DWRGB( 0, 128, 128 ), DWRGB( 0, 255, 255 ), MyLEDButtonStrip::TYPE_EXCLUSIVE, ch, module, RouteCallback ); + addChild( module->m_pMultiButtonRoute[ ch ] ); + } + + // level slider + addParam(ParamWidget::create( Vec( x + 10, y2 - 8 ), module, Mixer_24_4_4::PARAM_CHLVL + ch, 0.0, 1.0, 0.0 ) ); + + x += 23; + } + + // output + addParam(ParamWidget::create( Vec( 788, 256 ), module, Mixer_24_4_4::PARAM_LEVEL_OUT, 0.0, 1.0, 0.5 ) ); + + module->m_pLEDMeterMain[ 0 ] = new LEDMeterWidget( 798, 315, 5, 3, 2, true ); + addChild( module->m_pLEDMeterMain[ 0 ] ); + module->m_pLEDMeterMain[ 1 ] = new LEDMeterWidget( 798 + 7, 315, 5, 3, 2, true ); + addChild( module->m_pLEDMeterMain[ 1 ] ); + + // main outputs + addOutput(Port::create( Vec( 821, 319 ), Port::OUTPUT, module, Mixer_24_4_4::OUT_MAINL ) ); + addOutput(Port::create( Vec( 821, 344 ), Port::OUTPUT, module, Mixer_24_4_4::OUT_MAINR ) ); + + // xfade inputs + addInput(Port::create( Vec( 833, 203 ), Port::INPUT, module, Mixer_24_4_4::IN_FADEX ) ); + addInput(Port::create( Vec( 833, 230 ), Port::INPUT, module, Mixer_24_4_4::IN_FADEY ) ); + + //screw + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + // calculate eq rez freq + fx = 3.141592 * (CUTOFF * 0.026315789473684210526315789473684) * 2 * 3.141592; + fx2 = fx*fx; + fx3 = fx2*fx; + fx5 = fx3*fx2; + fx7 = fx5*fx2; + + module->m_Freq = 2.0 * (fx + - (fx3 * 0.16666666666666666666666666666667) + + (fx5 * 0.0083333333333333333333333333333333) + - (fx7 * 0.0001984126984126984126984126984127)); + + module->m_bInitialized = true; + module->onReset(); +} + +//----------------------------------------------------- +// Procedure: JsonParams +// +//----------------------------------------------------- +void Mixer_24_4_4::JsonParams( bool bTo, json_t *root) +{ + JsonDataBool( bTo, "m_bMuteStates", root, m_bMuteStates, 32 ); + JsonDataBool( bTo, "m_bSoloStates", root, m_bSoloStates, 32 ); + JsonDataInt( bTo, "m_iRouteGroup", root, &m_iRouteGroup[ 0 ], nINCHANNELS ); + JsonDataBool( bTo, "m_bGroupPreMute", root, &m_bGroupPreMute, 1 ); + JsonDataBool( bTo, "m_bGainLevelx2", root, &m_bGainLevelx2, 1 ); + JsonDataBool( bTo, "m_bPreFader", root, m_bPreFader, nINCHANNELS + nGROUPS ); +} + +//----------------------------------------------------- +// Procedure: toJson +// +//----------------------------------------------------- +json_t *Mixer_24_4_4::toJson() +{ + json_t *root = json_object(); + + if( !root ) + return NULL; + + JsonParams( TOJSON, root ); + + return root; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void Mixer_24_4_4::fromJson( json_t *root ) +{ + int ch; + bool bSolo = false; + + JsonParams( FROMJSON, root ); + + // anybody soloing? + for( ch = 0; ch < nCHANNELS; ch++ ) + { + if( m_bSoloStates[ ch ] ) + bSolo = true; + } + + for( ch = 0; ch < nCHANNELS; ch++ ) + { + if( bSolo ) + { + // only open soloing channels + if( m_bSoloStates[ ch ] ) + m_fMuteFade[ ch ] = 1.0; + else + m_fMuteFade[ ch ] = 0.0; + } + else + { + // nobody is soloing so just open the non muted channels + m_fMuteFade[ ch ] = m_bMuteStates[ ch ] ? 0.0: 1.0; + } + + SetControls( ch ); + } +} + +//----------------------------------------------------- +// Procedure: SetControls +// +//----------------------------------------------------- +void Mixer_24_4_4::SetControls( int ch ) +{ + if( !m_bInitialized || ch >= nCHANNELS || ch < 0 ) + return; + + //lg.f("Here\n"); + + if( m_pButtonChannelMute[ ch ] ) + m_pButtonChannelMute[ ch ]->Set( m_bMuteStates[ ch ] ); + + if( m_pButtonChannelSolo[ ch ] ) + m_pButtonChannelSolo[ ch ]->Set( m_bSoloStates[ ch ] ); + + if( ch < nINCHANNELS && m_pMultiButtonRoute[ ch ] ) + m_pMultiButtonRoute[ ch ]->Set( m_iRouteGroup[ ch ], true ); + + if( ch < (nINCHANNELS + nGROUPS ) ) + m_pButtonPreFader[ ch ]->Set( m_bPreFader[ ch ] ); +} + +//----------------------------------------------------- +// Procedure: onCreate +// +//----------------------------------------------------- +void Mixer_24_4_4::onCreate() +{ +} + +//----------------------------------------------------- +// Procedure: onDelete +// +//----------------------------------------------------- +void Mixer_24_4_4::onDelete() +{ +} + +//----------------------------------------------------- +// Procedure: onReset +// +//----------------------------------------------------- +void Mixer_24_4_4::onReset() +{ + int ch; + + if( !m_bInitialized ) + return; + + for( ch = 0; ch < nCHANNELS; ch++ ) + { + m_FadeState[ ch ] = MUTE_FADE_STATE_IDLE; + + m_bMuteStates[ ch ] = false; + m_bSoloStates[ ch ] = false; + m_fMuteFade[ ch ] = 1.0f; + + if( ch < nINCHANNELS ) + m_iRouteGroup[ ch ] = nGROUPS; + + SetControls( ch ); + } +} + +//----------------------------------------------------- +// Procedure: onRandomize +// +//----------------------------------------------------- +void Mixer_24_4_4::onRandomize() +{ +} + +//----------------------------------------------------- +// Procedure: ProcessEQ +// +//----------------------------------------------------- +#define MULTI (0.33333333333333333333333333333333f) +void Mixer_24_4_4::ProcessEQ( int ch, float *pL, float *pR ) +{ + float rez, hp1; + float input[ 2 ], out[ 2 ], lowpass, bandpass, highpass; + + input[ L ] = *pL / AUDIO_MAX; + input[ R ] = *pR / AUDIO_MAX; + + rez = 1.00; + + // do left and right channels + for( int i = 0; i < 2; i++ ) + { + input[ i ] = input[ i ] + 0.000000001; + + lp1[ ch ][ i ] = lp1[ ch ][ i ] + m_Freq * bp1[ ch ][ i ]; + hp1 = input[ i ] - lp1[ ch ][ i ] - rez * bp1[ ch ][ i ]; + bp1[ ch ][ i ] = m_Freq * hp1 + bp1[ ch ][ i ]; + lowpass = lp1[ ch ][ i ]; + highpass = hp1; + bandpass = bp1[ ch ][ i ]; + + lp1[ ch ][ i ] = lp1[ ch ][ i ] + m_Freq * bp1[ ch ][ i ]; + hp1 = input[ i ] - lp1[ ch ][ i ] - rez * bp1[ ch ][ i ]; + bp1[ ch ][ i ] = m_Freq * hp1 + bp1[ ch ][ i ]; + lowpass = lowpass + lp1[ ch ][ i ]; + highpass = highpass + hp1; + bandpass = bandpass + bp1[ ch ][ i ]; + + input[ i ] = input[ i ] - 0.000000001; + lp1[ ch ][ i ] = lp1[ ch ][ i ] + m_Freq * bp1[ ch ][ i ]; + hp1 = input[ i ] - lp1[ ch ][ i ] - rez * bp1[ ch ][ i ]; + bp1[ ch ][ i ] = m_Freq * hp1 + bp1[ ch ][ i ]; + + lowpass = (lowpass + lp1[ ch ][ i ]) * MULTI; + highpass = (highpass + hp1) * MULTI; + bandpass = (bandpass + bp1[ ch ][ i ]) * MULTI; + + out[ i ] = ( highpass * m_hpIn[ ch ] ) + ( lowpass * m_lpIn[ ch ] ) + ( bandpass * m_mpIn[ ch ] ); + } + + *pL = clamp( out[ L ] * AUDIO_MAX, -AUDIO_MAX, AUDIO_MAX ); + *pR = clamp( out[ R ] * AUDIO_MAX, -AUDIO_MAX, AUDIO_MAX ); +} + +//----------------------------------------------------- +// Procedure: ProcessMuteSolo +// +//----------------------------------------------------- +void Mixer_24_4_4::ProcessMuteSolo( int index, bool bMute, bool bGroup, bool bOn ) +{ + int i; + bool bSoloEnabled = false, bSoloGroup[ nGROUPS ] = {}; + + if( bMute ) + { + m_bMuteStates[ index ] = bOn; + + // turn solo off + if( m_bSoloStates[ index ] ) + { + m_bSoloStates[ index ] = false; + m_pButtonChannelSolo[ index ]->Set( false ); + } + + // if mute is off then set volume + if( m_bMuteStates[ index ] ) + { + m_pButtonChannelMute[ index ]->Set( true ); + m_FadeState[ index ] = MUTE_FADE_STATE_DEC; + } + else + { + m_pButtonChannelMute[ index ]->Set( false ); + m_FadeState[ index ] = MUTE_FADE_STATE_INC; + } + } + else + { + m_bSoloStates[ index ] = bOn; + + // turn mute off + if( m_bMuteStates[ index ] ) + { + m_bMuteStates[ index ] = false; + m_pButtonChannelMute[ index ]->Set( false ); + } + + // toggle solo + if( !m_bSoloStates[ index ] ) + { + m_pButtonChannelSolo[ index ]->Set( false ); + } + else + { + m_pButtonChannelSolo[ index ]->Set( true ); + } + } + + // is a track soloing? + for( i = 0; i < nINCHANNELS; i++ ) + { + if( m_bSoloStates[ i ] ) + { + bSoloEnabled = true; + + if( m_iRouteGroup[ i ] != 4 ) + bSoloGroup[ m_iRouteGroup[ i ] ] = true; + } + } + + // somebody is soloing + if( bSoloEnabled ) + { + // process solo + for( i = 0; i < nINCHANNELS; i++ ) + { + // shut down volume of all not in solo + if( !m_bSoloStates[ i ] ) + { + m_FadeState[ i ] = MUTE_FADE_STATE_DEC; + } + else + { + m_FadeState[ i ] = MUTE_FADE_STATE_INC; + } + } + + // process solo for groups if one of the routed inputs is soloing + for( i = nINCHANNELS; i < (nINCHANNELS + 4); i++ ) + { + // shut down volume of all not in solo + if( !bSoloGroup[ i - nINCHANNELS ] ) + { + m_FadeState[ i ] = MUTE_FADE_STATE_DEC; + } + else + { + m_FadeState[ i ] = MUTE_FADE_STATE_INC; + } + } + } + // nobody soloing and just turned solo off then enable all channels that aren't muted + else //if( bSoloOff ) + { + // process solo + for( i = 0; i < nINCHANNELS; i++ ) + { + // bring back if not muted + if( !m_bMuteStates[ i ] ) + { + m_FadeState[ i ] = MUTE_FADE_STATE_INC; + } + } + + // process solo for groups if one of the routed inputs is soloing + for( i = nINCHANNELS; i < (nINCHANNELS + 4); i++ ) + { + // bring back if not muted + if( !m_bMuteStates[ i ] ) + { + m_FadeState[ i ] = MUTE_FADE_STATE_INC; + } + } + } +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +#define SNORMAL 0 +#define SGROUP 1 +#define SAUX 2 +void Mixer_24_4_4::step() +{ + int section = 0; + int ch, aux, group = 0; + float GroupMixL[ nGROUPS ] = {0}, GroupMixR[ nGROUPS ] = {0}, fMixOutL = 0.0f, fMixOutR = 0.0f, inL, inR, flevel, fx, fy, fade[ nGROUPS ]; + float auxL[ nAUX ] = {}, auxR[ nAUX ] = {}; + bool bChannelActive, bGroupActive[ nGROUPS ] = {false}; + float pan, levelmult = 1.0; + + if( !m_bInitialized ) + return; + + if( m_bGainLevelx2 ) + levelmult = 1.5f; + + fade[ 0 ] = 1.0f; + fade[ 1 ] = 1.0f; + fade[ 2 ] = 1.0f; + fade[ 3 ] = 1.0f; + + // calc XFADE + if( inputs[ IN_FADEX ].active || inputs[ IN_FADEY ].active ) + { + fx = clamp( inputs[ IN_FADEX ].normalize( 5.0f ), 0.0f, 10.0f ) / 10.0f; + fy = clamp( inputs[ IN_FADEY ].normalize( 5.0f ), 0.0f, 10.0f ) / 10.0f; + + if( fx > 0.5f || fy < 0.5 ) + fade[ 0 ] = min( (1.0f - fx) * 2, fy * 2 ); + + if( fx < 0.5f || fy < 0.5 ) + fade[ 1 ] = min( fx * 2, fy * 2 ); + + if( fx > 0.5f || fy > 0.5 ) + fade[ 2 ] = min( (1.0f - fx) * 2, (1.0f - fy) * 2 ); + + if( fx < 0.5f || fy > 0.5 ) + fade[ 3 ] = min( fx * 2, (1.0f - fy) * 2 ); + } + + for( ch = 0; ch < nCHANNELS; ch++ ) + { + inL = 0.0f; + inR = 0.0f; + + // normal(0), group(1) or aux channels(2) section + if( ch == nINCHANNELS || ch == ( nINCHANNELS + nGROUPS ) ) + section++; + + bChannelActive = false; + + // see if channel active + if( section != SGROUP ) + { + if( inputs[ IN_LEFT + ch ].active || inputs[ IN_RIGHT + ch ].active ) + bChannelActive = true; + } + else if( section == SGROUP ) + { + group = ch - nINCHANNELS; + + if( bGroupActive[ group ] ) + bChannelActive = true; + } + + if( bChannelActive ) + { + if( section == SNORMAL ) + flevel = clamp( ( params[ PARAM_CHLVL + ch ].value * levelmult ) * ( inputs[ IN_LEVELCV + ch ].normalize( CV_MAX ) / CV_MAX ), 0.0f, levelmult ); + else + flevel = params[ PARAM_CHLVL + ch ].value * levelmult; + + if( section == SGROUP ) + { + // process xfade + inL = GroupMixL[ group ]; + inR = GroupMixR[ group ]; + } + else + { + // check right channel first for possible mono + if( inputs[ IN_RIGHT + ch ].active ) + { + inR = inputs[ IN_RIGHT + ch ].value; + m_bMono[ ch ] = false; + } + else + m_bMono[ ch ] = true; + + // left channel + if( inputs[ IN_LEFT + ch ].active ) + { + inL = inputs[ IN_LEFT + ch ].value; + + if( m_bMono[ ch ] ) + inR = inL; + } + } + + if( m_FadeState[ ch ] == MUTE_FADE_STATE_DEC ) + { + m_fMuteFade[ ch ] -= FADE_MULT; + + if( m_fMuteFade[ ch ] <= 0.0 ) + { + m_fMuteFade[ ch ] = 0.0; + m_FadeState[ ch ] = MUTE_FADE_STATE_IDLE; + } + } + else if( m_FadeState[ ch ] == MUTE_FADE_STATE_INC ) + { + m_fMuteFade[ ch ] += FADE_MULT; + + if( m_fMuteFade[ ch ] >= 1.0 ) + { + m_fMuteFade[ ch ] = 1.0; + m_FadeState[ ch ] = MUTE_FADE_STATE_IDLE; + } + } + + // attenuate for EQ + + ProcessEQ( ch, &inL, &inR ); + inL *= 2.0f; + inR *= 2.0f; + + if( section == SNORMAL ) + pan = clamp( params[ PARAM_CHPAN + ch ].value + ( inputs[ IN_PANCV + ch ].normalize( 0.0 ) / CV_MAX ), -1.0f, 1.0f ); + else + pan = params[ PARAM_CHPAN + ch ].value; + + if( pan <= 0.0 ) + inR *= ( 1.0 + pan ); + else + inL *= ( 1.0 - pan ); + + // put output to aux ( pre fader ) + if( section != SAUX ) + { + if( m_bPreFader[ ch ] ) + { + for ( aux = 0; aux < nAUX; aux++ ) + { + auxL[ aux ] += inL * params[ PARAM_CHAUX + (ch * 4) + aux ].value; + auxR[ aux ] += inR * params[ PARAM_CHAUX + (ch * 4) + aux ].value; + } + } + } + + inL *= flevel; + inR *= flevel; + + if( section == SGROUP ) + { + // process xfade + inL *= fade[ group ]; + inR *= fade[ group ]; + } + + // mute comes before group outputs + if( !m_bGroupPreMute ) + { + inL *= m_fMuteFade[ ch ]; + inR *= m_fMuteFade[ ch ]; + } + + // group output (pre mute) + if( section == SGROUP ) + { + if( bGroupActive[ group ] ) + { + outputs[ OUT_GRPL + group ].value = clamp( inL, -AUDIO_MAX, AUDIO_MAX ); + outputs[ OUT_GRPR + group ].value = clamp( inR, -AUDIO_MAX, AUDIO_MAX ); + } + else + { + outputs[ OUT_GRPL + group ].value = 0.0f; + outputs[ OUT_GRPR + group ].value = 0.0f; + } + } + + // mute comes after group outputs + if( m_bGroupPreMute ) + { + inL *= m_fMuteFade[ ch ]; + inR *= m_fMuteFade[ ch ]; + } + + // put output to aux ( post fader ) + if( section != SAUX ) + { + if( !m_bPreFader[ ch ] ) + { + for ( aux = 0; aux < nAUX; aux++ ) + { + auxL[ aux ] += inL * params[ PARAM_CHAUX + (ch * 4) + aux ].value; + auxR[ aux ] += inR * params[ PARAM_CHAUX + (ch * 4) + aux ].value; + } + } + } + + // non normal input channels go directly to output + if( section != SNORMAL ) + { + fMixOutL += inL; + fMixOutR += inR; + } + else + { + // normal channel direct out + if( m_iRouteGroup[ ch ] == 4 ) + { + fMixOutL += inL; + fMixOutR += inR; + } + // normal channel routed to group + else + { + GroupMixL[ m_iRouteGroup[ ch ] ] += inL; + GroupMixR[ m_iRouteGroup[ ch ] ] += inR; + + bGroupActive[ m_iRouteGroup[ ch ] ] = true; + } + } + } + + if( m_pLEDMeterChannel[ ch ][ 0 ] ) + m_pLEDMeterChannel[ ch ][ 0 ]->Process( inL / AUDIO_MAX ); + if( m_pLEDMeterChannel[ ch ][ 1 ] ) + m_pLEDMeterChannel[ ch ][ 1 ]->Process( inR / AUDIO_MAX); + } + + // apply main level + fMixOutL = clamp( fMixOutL * params[ PARAM_LEVEL_OUT ].value, -AUDIO_MAX, AUDIO_MAX ); + fMixOutR = clamp( fMixOutR * params[ PARAM_LEVEL_OUT ].value, -AUDIO_MAX, AUDIO_MAX ); + + // update main VUMeters + if( m_pLEDMeterMain[ 0 ] ) + m_pLEDMeterMain[ 0 ]->Process( fMixOutL / AUDIO_MAX ); + if( m_pLEDMeterMain[ 1 ] ) + m_pLEDMeterMain[ 1 ]->Process( fMixOutR / AUDIO_MAX ); + + // put aux output + for ( aux = 0; aux < nAUX; aux++ ) + { + outputs[ OUT_AUXL + aux ].value = clamp( auxL[ aux ] * params[ PARAM_AUXLVL + aux ].value, -AUDIO_MAX, AUDIO_MAX ); + outputs[ OUT_AUXR + aux ].value = clamp( auxR[ aux ] * params[ PARAM_AUXLVL + aux ].value, -AUDIO_MAX, AUDIO_MAX ); + } + + outputs[ OUT_MAINL ].value = fMixOutL; + outputs[ OUT_MAINR ].value = fMixOutR; +} + +//----------------------------------------------------- +// Procedure: Group Pre-Mute Menu Item +// +//----------------------------------------------------- +struct Mixer_24_4_4_GroupPreMute : MenuItem +{ + Mixer_24_4_4 *module; + + void onAction(EventAction &e) override + { + module->m_bGroupPreMute = !module->m_bGroupPreMute; + } + + void step() override + { + rightText = (module->m_bGroupPreMute) ? "✔" : ""; + } +}; + +//----------------------------------------------------- +// Procedure: Level Gain x2 Menu Item +// +//----------------------------------------------------- +struct Mixer_24_4_4_Gainx2 : MenuItem +{ + Mixer_24_4_4 *module; + + void onAction(EventAction &e) override + { + module->m_bGainLevelx2 = !module->m_bGainLevelx2; + } + + void step() override + { + rightText = (module->m_bGainLevelx2) ? "✔" : ""; + } +}; + +//----------------------------------------------------- +// Procedure: createContextMenu +// +//----------------------------------------------------- +Menu *Mixer_24_4_4_Widget::createContextMenu() +{ + Menu *menu = ModuleWidget::createContextMenu(); + + Mixer_24_4_4 *mod = dynamic_cast(module); + + assert(mod); + + menu->addChild(construct()); + + menu->addChild(construct(&MenuLabel::text, "---- Group Outputs ----")); + menu->addChild(construct( &MenuItem::text, "Pre-Mute", &Mixer_24_4_4_GroupPreMute::module, mod ) ); + + menu->addChild(construct(&MenuLabel::text, "---- Level Sliders ----")); + menu->addChild(construct( &MenuItem::text, "Gain x1.5", &Mixer_24_4_4_Gainx2::module, mod ) ); + + return menu; +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, Mix_24_4_4) { + Model *modelMix_24_4_4 = Model::create( "mscHack", "Mix_24_4_4", "MIXER 24ch, 4 groups, 4 aux", MIXER_TAG, EQUALIZER_TAG, PANNING_TAG, AMPLIFIER_TAG, MULTIPLE_TAG ); + return modelMix_24_4_4; +} diff --git a/plugins/community/repos/mscHack/src/Mixer_2x4_Stereo.cpp b/plugins/community/repos/mscHack/src/Mixer_2x4_Stereo.cpp new file mode 100644 index 00000000..5787d702 --- /dev/null +++ b/plugins/community/repos/mscHack/src/Mixer_2x4_Stereo.cpp @@ -0,0 +1,1226 @@ +#include "mscHack.hpp" +//#include "mscHack_Controls.hpp" +#include "dsp/digital.hpp" +//#include "CLog.h" + +namespace rack_plugin_mscHack { + +#define GROUPS 2 +#define CH_PER_GROUP 4 +#define CHANNELS ( GROUPS * CH_PER_GROUP ) +#define nAUX 4 + +#define GROUP_OFF_X 52 +#define CHANNEL_OFF_X 34 + +#define FADE_MULT (0.0005f) + +#define L 0 +#define R 1 + +#define MUTE_FADE_STATE_IDLE 0 +#define MUTE_FADE_STATE_INC 1 +#define MUTE_FADE_STATE_DEC 2 + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct Mix_2x4_Stereo : Module +{ + enum ParamIds + { + PARAM_MAIN_LEVEL, + PARAM_LEVEL_IN, + PARAM_PAN_IN = PARAM_LEVEL_IN + CHANNELS, + PARAM_GROUP_LEVEL_IN = PARAM_PAN_IN + CHANNELS, + PARAM_GROUP_PAN_IN = PARAM_GROUP_LEVEL_IN + GROUPS, + PARAM_MUTE_BUTTON = PARAM_GROUP_PAN_IN + GROUPS, + PARAM_SOLO_BUTTON = PARAM_MUTE_BUTTON + CHANNELS, + PARAM_GROUP_MUTE = PARAM_SOLO_BUTTON + CHANNELS, + PARAM_GROUP_SOLO = PARAM_GROUP_MUTE + GROUPS, + + PARAM_EQ_HI = PARAM_GROUP_SOLO + GROUPS, + PARAM_EQ_MD = PARAM_EQ_HI + CHANNELS, + PARAM_EQ_LO = PARAM_EQ_MD + CHANNELS, + + PARAM_AUX_KNOB = PARAM_EQ_LO + CHANNELS, + PARAM_AUX_PREFADE = PARAM_AUX_KNOB + (GROUPS * nAUX), + PARAM_AUX_OUT = PARAM_AUX_PREFADE + (GROUPS * nAUX), + + nPARAMS = PARAM_AUX_OUT + (nAUX) + }; + + enum InputIds + { + IN_LEFT, + IN_RIGHT = IN_LEFT + CHANNELS, + IN_LEVEL = IN_RIGHT + CHANNELS, + IN_PAN = IN_LEVEL + CHANNELS, + IN_GROUP_LEVEL = IN_PAN + CHANNELS, + IN_GROUP_PAN = IN_GROUP_LEVEL + GROUPS, + nINPUTS = IN_GROUP_PAN + GROUPS + }; + + enum OutputIds + { + OUT_MAINL, + OUT_MAINR, + + OUT_AUXL, + OUT_AUXR = OUT_AUXL + nAUX, + + nOUTPUTS = OUT_AUXR + nAUX + }; + + bool m_bInitialized = false; + CLog lg; + + // mute buttons + bool m_bMuteStates[ CHANNELS ] = {}; + float m_fMuteFade[ CHANNELS ] = {1.0}; + + int m_FadeState[ CHANNELS ] = {MUTE_FADE_STATE_IDLE}; + + // solo buttons + bool m_bSoloStates[ CHANNELS ] = {}; + + // group mute buttons + bool m_bGroupMuteStates[ GROUPS ] = {}; + float m_fGroupMuteFade[ GROUPS ] = {1.0}; + + int m_GroupFadeState[ GROUPS ] = {MUTE_FADE_STATE_IDLE}; + + // group solo buttons + bool m_bGroupSoloStates[ GROUPS ] = {}; + + // processing + bool m_bMono[ CHANNELS ]; + float m_fSubMix[ GROUPS ][ 3 ] = {}; + + // aux + bool m_bGroupPreFadeAuxStates[ GROUPS ][ nAUX ] = {}; + + // LED Meters + LEDMeterWidget *m_pLEDMeterChannel[ CHANNELS ][ 2 ] ={}; + LEDMeterWidget *m_pLEDMeterGroup[ GROUPS ][ 2 ] ={}; + LEDMeterWidget *m_pLEDMeterMain[ 2 ] ={}; + + // EQ Rez + float lp1[ CHANNELS ][ 2 ] = {}, bp1[ CHANNELS ][ 2 ] = {}; + float m_hpIn[ CHANNELS ]; + float m_lpIn[ CHANNELS ]; + float m_mpIn[ CHANNELS ]; + float m_rezIn[ CHANNELS ] = {0}; + float m_Freq; + + // buttons + MyLEDButton *m_pButtonChannelMute[ CHANNELS ] = {}; + MyLEDButton *m_pButtonChannelSolo[ CHANNELS ] = {}; + MyLEDButton *m_pButtonGroupMute[ GROUPS ] = {}; + MyLEDButton *m_pButtonGroupSolo[ GROUPS ] = {}; + MyLEDButton *m_pButtonAuxPreFader[ GROUPS ][ nAUX ] = {}; + +#define L 0 +#define R 1 + + // Contructor + Mix_2x4_Stereo() : Module(nPARAMS, nINPUTS, nOUTPUTS, 0 ){} + + //----------------------------------------------------- + // MyEQHi_Knob + //----------------------------------------------------- + struct MyEQHi_Knob : Knob_Green1_15 + { + Mix_2x4_Stereo *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Mix_2x4_Stereo*)module; + + if( mymodule ) + { + param = paramId - Mix_2x4_Stereo::PARAM_EQ_HI; + + mymodule->m_hpIn[ param ] = value; + } + + RoundKnob::onChange( e ); + } + }; + + //----------------------------------------------------- + // MyEQHi_Knob + //----------------------------------------------------- + struct MyEQMid_Knob : Knob_Green1_15 + { + Mix_2x4_Stereo *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Mix_2x4_Stereo*)module; + + if( mymodule ) + { + param = paramId - Mix_2x4_Stereo::PARAM_EQ_MD; + mymodule->m_mpIn[ param ] = value; + } + + RoundKnob::onChange( e ); + } + }; + + //----------------------------------------------------- + // MyEQHi_Knob + //----------------------------------------------------- + struct MyEQLo_Knob : Knob_Green1_15 + { + Mix_2x4_Stereo *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Mix_2x4_Stereo*)module; + + if( mymodule ) + { + param = paramId - Mix_2x4_Stereo::PARAM_EQ_LO; + mymodule->m_lpIn[ param ] = value; + } + + RoundKnob::onChange( e ); + } + }; + + // Overrides + void step() override; + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onRandomize() override{} + void onReset() override; + + void ProcessMuteSolo( int channel, bool bMute, bool bGroup ); + void ProcessEQ( int ch, float *pL, float *pR ); +}; + +//----------------------------------------------------- +// MyLEDButton_Aux +//----------------------------------------------------- +void Mix_2x4_Stereo_MyLEDButton_Aux( void *pClass, int id, bool bOn ) +{ + int ch, i; + + Mix_2x4_Stereo *mymodule; + mymodule = (Mix_2x4_Stereo*)pClass; + + ch = id / nAUX; + i = id - (nAUX * ch); + + mymodule->m_bGroupPreFadeAuxStates[ ch ][ i ] = !mymodule->m_bGroupPreFadeAuxStates[ ch ][ i ]; + mymodule->m_pButtonAuxPreFader[ ch ][ i ]->Set( mymodule->m_bGroupPreFadeAuxStates[ ch ][ i ] ); +} + +//----------------------------------------------------- +// MyLEDButton_ChMute +//----------------------------------------------------- +void Mix_2x4_Stereo_MyLEDButton_ChMute( void *pClass, int id, bool bOn ) +{ + Mix_2x4_Stereo *mymodule; + mymodule = (Mix_2x4_Stereo*)pClass; + mymodule->ProcessMuteSolo( id, true, false ); +} + +//----------------------------------------------------- +// MyLEDButton_ChSolo +//----------------------------------------------------- +void Mix_2x4_Stereo_MyLEDButton_ChSolo( void *pClass, int id, bool bOn ) +{ + Mix_2x4_Stereo *mymodule; + mymodule = (Mix_2x4_Stereo*)pClass; + mymodule->ProcessMuteSolo( id, false, false ); +} + +//----------------------------------------------------- +// MyLEDButton_GroupMute +//----------------------------------------------------- +void Mix_2x4_Stereo_MyLEDButton_GroupMute( void *pClass, int id, bool bOn ) +{ + Mix_2x4_Stereo *mymodule; + mymodule = (Mix_2x4_Stereo*)pClass; + mymodule->ProcessMuteSolo( id, true, true ); +} + +//----------------------------------------------------- +// MyLEDButton_GroupSolo +//----------------------------------------------------- +void Mix_2x4_Stereo_MyLEDButton_GroupSolo( void *pClass, int id, bool bOn ) +{ + Mix_2x4_Stereo *mymodule; + mymodule = (Mix_2x4_Stereo*)pClass; + mymodule->ProcessMuteSolo( id, false, true ); +} + +#define CUTOFF (0.025f) +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- +struct Mix_2x4_Stereo_Widget : ModuleWidget { + Mix_2x4_Stereo_Widget( Mix_2x4_Stereo *module ); +}; + +Mix_2x4_Stereo_Widget::Mix_2x4_Stereo_Widget( Mix_2x4_Stereo *module ) : ModuleWidget(module) +{ + float fx, fx2, fx3, fx5, fx7; + int ch, x, y, i, ybase, x2, y2; + + box.size = Vec( 15*27, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/Mix_2x4_Stereo.svg"))); + addChild(panel); + } + + //module->lg.Open("Mix_2x4_Stereo.txt"); + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + //---------------------------------------------------- + // Add mix sliders + x = 23; + y = 38; + + // main channel + for ( ch = 0; ch < CHANNELS; ch++ ) + { + // Left channel inputs + addInput(Port::create( Vec( x, y ), Port::INPUT, module, Mix_2x4_Stereo::IN_LEFT + ch ) ); + + y += 25; + + // Right channel inputs + addInput(Port::create( Vec( x, y ), Port::INPUT, module, Mix_2x4_Stereo::IN_RIGHT + ch ) ); + + y += 26; + + // Level knobs + addParam(ParamWidget::create( Vec( x - 5, y ), module, Mix_2x4_Stereo::PARAM_LEVEL_IN + ch, 0.0, AMP_MAX, 0.0 ) ); + + y += 31; + + // Level inputs + addInput(Port::create( Vec( x, y ), Port::INPUT, module, Mix_2x4_Stereo::IN_LEVEL + ch ) ); + + y += 23; + + // pan knobs + addParam(ParamWidget::create( Vec( x - 5, y ), module, Mix_2x4_Stereo::PARAM_PAN_IN + ch, -1.0, 1.0, 0.0 ) ); + + y += 31; + + // Pan inputs + addInput(Port::create( Vec( x, y ), Port::INPUT, module, Mix_2x4_Stereo::IN_PAN + ch ) ); + + y += 22; + + // mute buttons + module->m_pButtonChannelMute[ ch ] = new MyLEDButton( x - 5, y, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, ch, module, Mix_2x4_Stereo_MyLEDButton_ChMute ); + addChild( module->m_pButtonChannelMute[ ch ] ); + //y += 26; + + // solo buttons + module->m_pButtonChannelSolo[ ch ] = new MyLEDButton( x + 11, y, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_SWITCH, ch, module, Mix_2x4_Stereo_MyLEDButton_ChSolo ); + addChild( module->m_pButtonChannelSolo[ ch ] ); + + y += 22; + y2 = y; + + // eq and rez + addParam(ParamWidget::create( Vec( x - 5, y ), module, Mix_2x4_Stereo::PARAM_EQ_HI + ch, 0.0, 1.0, 0.5 ) ); + + y += 19; + + addParam(ParamWidget::create( Vec( x - 5, y ), module, Mix_2x4_Stereo::PARAM_EQ_MD + ch, 0.0, 1.0, 0.5 ) ); + + y += 19; + + addParam(ParamWidget::create( Vec( x - 5, y ), module, Mix_2x4_Stereo::PARAM_EQ_LO + ch, 0.0, 1.0, 0.5 ) ); + + // LED Meters + module->m_pLEDMeterChannel[ ch ][ 0 ] = new LEDMeterWidget( x + 13, y2 + 30, 4, 1, 1, true ); + addChild( module->m_pLEDMeterChannel[ ch ][ 0 ] ); + module->m_pLEDMeterChannel[ ch ][ 1 ] = new LEDMeterWidget( x + 18, y2 + 30, 4, 1, 1, true ); + addChild( module->m_pLEDMeterChannel[ ch ][ 1 ] ); + + if( ( ch & 3 ) == 3 ) + { + x += GROUP_OFF_X; + } + else + { + x += CHANNEL_OFF_X; + } + + y = 38; + } + + // group mixera + ybase = 278; + x = 12; + for( i = 0; i < GROUPS; i++ ) + { + // mute/solo buttons + x2 = x + 81; + y2 = ybase; + + module->m_pButtonGroupMute[ i ] = new MyLEDButton( x2, y2 + 4, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, i, module, Mix_2x4_Stereo_MyLEDButton_GroupMute ); + addChild( module->m_pButtonGroupMute[ i ] ); + x2 += 28; + + module->m_pButtonGroupSolo[ i ] = new MyLEDButton( x2, y2 + 4, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_SWITCH, i, module, Mix_2x4_Stereo_MyLEDButton_GroupSolo ); + addChild( module->m_pButtonGroupSolo[ i ] ); + + // group level and pan inputs + x2 = x + 79; + y2 = ybase + 23; + + // group VU Meters + module->m_pLEDMeterGroup[ i ][ 0 ] = new LEDMeterWidget( x2 + 2, y2 + 21, 5, 2, 1, true ); + addChild( module->m_pLEDMeterGroup[ i ][ 0 ] ); + module->m_pLEDMeterGroup[ i ][ 1 ] = new LEDMeterWidget( x2 + 9, y2 + 21, 5, 2, 1, true ); + addChild( module->m_pLEDMeterGroup[ i ][ 1 ] ); + + // group level and pan knobs + x2 = x + 105; + y2 = ybase + 17; + + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_2x4_Stereo::PARAM_GROUP_LEVEL_IN + i, 0.0, AMP_MAX, 0.0 ) ); + + y2 += 32; + + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_2x4_Stereo::PARAM_GROUP_PAN_IN + i, -1.0, 1.0, 0.0 ) ); + + // aux 1/3 +#define AUX_H 29 + x2 = x + 6; + y2 = ybase + 20; + + module->m_pButtonAuxPreFader[ i ][ 0 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, (i * nAUX) + 0, module, Mix_2x4_Stereo_MyLEDButton_Aux ); + addChild( module->m_pButtonAuxPreFader[ i ][ 0 ] ); + + y2 += AUX_H; + + module->m_pButtonAuxPreFader[ i ][ 2 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, (i * nAUX) + 2, module, Mix_2x4_Stereo_MyLEDButton_Aux ); + addChild( module->m_pButtonAuxPreFader[ i ][ 2 ] ); + + x2 = x + 20; + y2 = ybase + 16; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_2x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 0, 0.0, AMP_MAX, 0.0 ) ); + y2 += AUX_H; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_2x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 2, 0.0, AMP_MAX, 0.0 ) ); + + // aux 2/4 + x2 = x + 38; + y2 = ybase + 28; + + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_2x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 1, 0.0, AMP_MAX, 0.0 ) ); + y2 += AUX_H; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_2x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 3, 0.0, AMP_MAX, 0.0 ) ); + + x2 = x + 62; + y2 = ybase + 32; + + module->m_pButtonAuxPreFader[ i ][ 1 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, (i * nAUX) + 1, module, Mix_2x4_Stereo_MyLEDButton_Aux ); + addChild( module->m_pButtonAuxPreFader[ i ][ 1 ] ); + + y2 += AUX_H; + + module->m_pButtonAuxPreFader[ i ][ 3 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, (i * nAUX) + 3, module, Mix_2x4_Stereo_MyLEDButton_Aux ); + addChild( module->m_pButtonAuxPreFader[ i ][ 3 ] ); + + // account for slight error in pixel conversion to svg area + x += 155; + } + + // main mixer knob + addParam(ParamWidget::create( Vec( 317, 237 ), module, Mix_2x4_Stereo::PARAM_MAIN_LEVEL, 0.0, AMP_MAX, 0.0 ) ); + + module->m_pLEDMeterMain[ 0 ] = new LEDMeterWidget( 317 + 58, 242, 5, 3, 2, true ); + addChild( module->m_pLEDMeterMain[ 0 ] ); + module->m_pLEDMeterMain[ 1 ] = new LEDMeterWidget( 317 + 65, 242, 5, 3, 2, true ); + addChild( module->m_pLEDMeterMain[ 1 ] ); + + // outputs + + addOutput(Port::create( Vec( 327, 305 ), Port::OUTPUT, module, Mix_2x4_Stereo::OUT_MAINL ) ); + addOutput(Port::create( Vec( 359, 335 ), Port::OUTPUT, module, Mix_2x4_Stereo::OUT_MAINR ) ); + + // AUX out +#define AUX_OUT_H 42 + x2 = 340; + y2 = 25; + + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_2x4_Stereo::PARAM_AUX_OUT + 0, 0.0, AMP_MAX, 0.0 ) ); y2 += AUX_OUT_H; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_2x4_Stereo::PARAM_AUX_OUT + 1, 0.0, AMP_MAX, 0.0 ) ); y2 += AUX_OUT_H; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_2x4_Stereo::PARAM_AUX_OUT + 2, 0.0, AMP_MAX, 0.0 ) ); y2 += AUX_OUT_H; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_2x4_Stereo::PARAM_AUX_OUT + 3, 0.0, AMP_MAX, 0.0 ) ); + + x2 = 326; + y2 = 45; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_2x4_Stereo::OUT_AUXL ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_2x4_Stereo::OUT_AUXL + 1 ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_2x4_Stereo::OUT_AUXL + 2 ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_2x4_Stereo::OUT_AUXL + 3 ) ); + + x2 = 355; + y2 = 45; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_2x4_Stereo::OUT_AUXR ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_2x4_Stereo::OUT_AUXR + 1 ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_2x4_Stereo::OUT_AUXR + 2 ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_2x4_Stereo::OUT_AUXR + 3 ) ); + + // calculate eq rez freq + fx = 3.141592 * (CUTOFF * 0.026315789473684210526315789473684) * 2 * 3.141592; + fx2 = fx*fx; + fx3 = fx2*fx; + fx5 = fx3*fx2; + fx7 = fx5*fx2; + + module->m_Freq = 2.0 * (fx + - (fx3 * 0.16666666666666666666666666666667) + + (fx5 * 0.0083333333333333333333333333333333) + - (fx7 * 0.0001984126984126984126984126984127)); + + module->m_bInitialized = true; + module->onReset(); +} + +//----------------------------------------------------- +// Procedure: reset +// +//----------------------------------------------------- +void Mix_2x4_Stereo::onReset() +{ + int ch, i, aux; + + if( !m_bInitialized ) + return; + + for( ch = 0; ch < CHANNELS; ch++ ) + { + m_FadeState[ ch ] = MUTE_FADE_STATE_IDLE; + + m_pButtonChannelMute[ ch ]->Set( false ); + m_pButtonChannelSolo[ ch ]->Set( false ); + + m_bMuteStates[ ch ] = false; + m_bSoloStates[ ch ] = false; + m_fMuteFade[ ch ] = 1.0; + } + + for( i = 0; i < GROUPS; i++ ) + { + for( aux = 0; aux < nAUX; aux++ ) + { + m_bGroupPreFadeAuxStates[ i ][ aux ] = false; + m_pButtonAuxPreFader[ i ][ aux ]->Set( false ); + } + + m_GroupFadeState[ i ] = MUTE_FADE_STATE_IDLE; + m_pButtonGroupMute[ i ]->Set( false ); + m_pButtonGroupSolo[ i ]->Set( false ); + m_bGroupMuteStates[ i ] = false; + m_fGroupMuteFade[ i ] = 1.0; + } +} + +//----------------------------------------------------- +// Procedure: +// +//----------------------------------------------------- +json_t *Mix_2x4_Stereo::toJson() +{ + bool *pbool; + json_t *gatesJ; + json_t *rootJ = json_object(); + + // channel mutes + pbool = &m_bMuteStates[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < CHANNELS; i++) + { + json_t *gateJ = json_integer( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "channel mutes", gatesJ ); + + // channel solos + pbool = &m_bSoloStates[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < CHANNELS; i++) + { + json_t *gateJ = json_integer( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "channel solos", gatesJ ); + + // group mutes + pbool = &m_bGroupMuteStates[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < GROUPS; i++) + { + json_t *gateJ = json_integer( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "group mutes", gatesJ ); + + // group solos + pbool = &m_bGroupSoloStates[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < GROUPS; i++) + { + json_t *gateJ = json_integer( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "group solos", gatesJ ); + + // AUX states + pbool = &m_bGroupPreFadeAuxStates[ 0 ][ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < GROUPS * nAUX; i++) + { + json_t *gateJ = json_integer( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "group AUX prefade states", gatesJ ); + + return rootJ; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void Mix_2x4_Stereo::fromJson(json_t *rootJ) +{ + int ch, i, aux; + bool *pbool; + json_t *StepsJ; + bool bSolo[ GROUPS ] = {0}, bGroupSolo = false; + + // channel mutes + pbool = &m_bMuteStates[ 0 ]; + + StepsJ = json_object_get( rootJ, "channel mutes" ); + + if (StepsJ) + { + for ( i = 0; i < CHANNELS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_integer_value( gateJ ); + } + } + + // channel solos + pbool = &m_bSoloStates[ 0 ]; + + StepsJ = json_object_get( rootJ, "channel solos" ); + + if (StepsJ) + { + for ( i = 0; i < CHANNELS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_integer_value( gateJ ); + } + } + + // group mutes + pbool = &m_bGroupMuteStates[ 0 ]; + + StepsJ = json_object_get( rootJ, "group mutes" ); + + if (StepsJ) + { + for ( i = 0; i < GROUPS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_integer_value( gateJ ); + } + } + + // group solos + pbool = &m_bGroupSoloStates[ 0 ]; + + StepsJ = json_object_get( rootJ, "group solos" ); + + if (StepsJ) + { + for ( i = 0; i < GROUPS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_integer_value( gateJ ); + } + } + + // AUX states + pbool = &m_bGroupPreFadeAuxStates[ 0 ][ 0 ]; + + StepsJ = json_object_get( rootJ, "group AUX prefade states" ); + + if (StepsJ) + { + for ( i = 0; i < GROUPS * nAUX; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_integer_value( gateJ ); + } + } + + // anybody soloing? + for( ch = 0; ch < CHANNELS; ch++ ) + { + if( m_bSoloStates[ ch ] ) + { + bSolo[ ch / CH_PER_GROUP ] = true; + } + } + + for( ch = 0; ch < CHANNELS; ch++ ) + { + if( bSolo[ ch / CH_PER_GROUP ] ) + { + // only open soloing channels + if( m_bSoloStates[ ch ] ) + m_fMuteFade[ ch ] = 1.0; + else + m_fMuteFade[ ch ] = 0.0; + } + else + { + // nobody is soloing so just open the non muted channels + m_fMuteFade[ ch ] = m_bMuteStates[ ch ] ? 0.0: 1.0; + } + + m_pButtonChannelMute[ ch ]->Set( m_bMuteStates[ ch ] ); + m_pButtonChannelSolo[ ch ]->Set( m_bSoloStates[ ch ] ); + } + + // anybody group soloing? + for( i = 0; i < GROUPS; i++ ) + { + if( m_bGroupSoloStates[ i ] ) + { + bGroupSolo = true; + break; + } + } + + for( i = 0; i < GROUPS; i++ ) + { + for( aux = 0; aux < nAUX; aux++ ) + m_pButtonAuxPreFader[ i ][ aux ]->Set( m_bGroupPreFadeAuxStates[ i ][ aux ] ); + + if( bGroupSolo ) + { + // only open soloing channels + if( m_bGroupSoloStates[ i ] ) + m_fGroupMuteFade[ i ] = 1.0; + else + m_fGroupMuteFade[ i ] = 0.0; + } + else + { + // nobody is soloing so just open the non muted channels + m_fGroupMuteFade[ i ] = m_bGroupMuteStates[ i ] ? 0.0: 1.0; + } + + m_pButtonGroupMute[ i ]->Set( m_bGroupMuteStates[ i ] ); + m_pButtonGroupSolo[ i ]->Set( m_bGroupSoloStates[ i ] ); + } +} + +//----------------------------------------------------- +// Procedure: ProcessMuteSolo +// +//----------------------------------------------------- +void Mix_2x4_Stereo::ProcessMuteSolo( int index, bool bMute, bool bGroup ) +{ + int i, group, si, ei; + bool bSoloEnabled = false, bSoloOff = false; + + if( bGroup ) + { + if( bMute ) + { + m_bGroupMuteStates[ index ] = !m_bGroupMuteStates[ index ]; + + // turn solo off + if( m_bGroupSoloStates[ index ] ) + { + bSoloOff = true; + m_bGroupSoloStates[ index ] = false; + m_pButtonGroupSolo[ index ]->Set( false ); + } + + // if mute is off then set volume + if( m_bGroupMuteStates[ index ] ) + { + m_pButtonGroupMute[ index ]->Set( true ); + m_GroupFadeState[ index ] = MUTE_FADE_STATE_DEC; + } + else + { + m_pButtonGroupMute[ index ]->Set( false ); + m_GroupFadeState[ index ] = MUTE_FADE_STATE_INC; + } + } + else + { + m_bGroupSoloStates[ index ] = !m_bGroupSoloStates[ index ]; + + // turn mute off + if( m_bGroupMuteStates[ index ] ) + { + m_bGroupMuteStates[ index ] = false; + m_pButtonGroupMute[ index ]->Set( false ); + } + + // shut down volume of all groups not in solo + if( !m_bGroupSoloStates[ index ] ) + { + bSoloOff = true; + m_pButtonGroupSolo[ index ]->Set( false ); + } + else + { + m_pButtonGroupSolo[ index ]->Set( true ); + } + } + + // is a track soloing? + for( i = 0; i < GROUPS; i++ ) + { + if( m_bGroupSoloStates[ i ] ) + { + bSoloEnabled = true; + break; + } + } + + if( bSoloEnabled ) + { + // process solo + for( i = 0; i < GROUPS; i++ ) + { + // shut down volume of all groups not in solo + if( !m_bGroupSoloStates[ i ] ) + { + m_GroupFadeState[ i ] = MUTE_FADE_STATE_DEC; + } + else + { + m_GroupFadeState[ i ] = MUTE_FADE_STATE_INC; + } + } + } + // nobody soloing and just turned solo off then enable all channels that aren't muted + else if( bSoloOff ) + { + // process solo + for( i = 0; i < GROUPS; i++ ) + { + // bring back if not muted + if( !m_bGroupMuteStates[ i ] ) + { + m_GroupFadeState[ i ] = MUTE_FADE_STATE_INC; + } + } + } + } + // !bGroup + else + { + group = index / CH_PER_GROUP; + + si = group * CH_PER_GROUP; + ei = si + CH_PER_GROUP; + + if( bMute ) + { + m_bMuteStates[ index ] = !m_bMuteStates[ index ]; + + // turn solo off + if( m_bSoloStates[ index ] ) + { + bSoloOff = true; + m_bSoloStates[ index ] = false; + m_pButtonChannelSolo[ index ]->Set( false ); + } + + // if mute is off then set volume + if( m_bMuteStates[ index ] ) + { + m_pButtonChannelMute[ index ]->Set( true ); + m_FadeState[ index ] = MUTE_FADE_STATE_DEC; + } + else + { + m_pButtonChannelMute[ index ]->Set( false ); + m_FadeState[ index ] = MUTE_FADE_STATE_INC; + } + } + else + { + m_bSoloStates[ index ] = !m_bSoloStates[ index ]; + + // turn mute off + if( m_bMuteStates[ index ] ) + { + m_bMuteStates[ index ] = false; + m_pButtonChannelMute[ index ]->Set( false ); + } + + // toggle solo + if( !m_bSoloStates[ index ] ) + { + bSoloOff = true; + m_pButtonChannelSolo[ index ]->Set( false ); + } + else + { + m_pButtonChannelSolo[ index ]->Set( true ); + } + } + + // is a track soloing? + for( i = si; i < ei; i++ ) + { + if( m_bSoloStates[ i ] ) + { + bSoloEnabled = true; + break; + } + } + + if( bSoloEnabled ) + { + // process solo + for( i = si; i < ei; i++ ) + { + // shut down volume of all not in solo + if( !m_bSoloStates[ i ] ) + { + m_FadeState[ i ] = MUTE_FADE_STATE_DEC; + } + else + { + m_FadeState[ i ] = MUTE_FADE_STATE_INC; + } + } + } + // nobody soloing and just turned solo off then enable all channels that aren't muted + else if( bSoloOff ) + { + // process solo + for( i = si; i < ei; i++ ) + { + // bring back if not muted + if( !m_bMuteStates[ i ] ) + { + m_FadeState[ i ] = MUTE_FADE_STATE_INC; + } + } + } + } +} + +//----------------------------------------------------- +// Procedure: ProcessEQ +// +//----------------------------------------------------- +#define MULTI (0.33333333333333333333333333333333f) +void Mix_2x4_Stereo::ProcessEQ( int ch, float *pL, float *pR ) +{ + float rez, hp1; + float input[ 2 ], out[ 2 ], lowpass, bandpass, highpass; + + input[ L ] = *pL / AUDIO_MAX; + input[ R ] = *pR / AUDIO_MAX; + + rez = 1.00; + + // do left and right channels + for( int i = 0; i < 2; i++ ) + { + input[ i ] = input[ i ] + 0.000000001; + + lp1[ ch ][ i ] = lp1[ ch ][ i ] + m_Freq * bp1[ ch ][ i ]; + hp1 = input[ i ] - lp1[ ch ][ i ] - rez * bp1[ ch ][ i ]; + bp1[ ch ][ i ] = m_Freq * hp1 + bp1[ ch ][ i ]; + lowpass = lp1[ ch ][ i ]; + highpass = hp1; + bandpass = bp1[ ch ][ i ]; + + lp1[ ch ][ i ] = lp1[ ch ][ i ] + m_Freq * bp1[ ch ][ i ]; + hp1 = input[ i ] - lp1[ ch ][ i ] - rez * bp1[ ch ][ i ]; + bp1[ ch ][ i ] = m_Freq * hp1 + bp1[ ch ][ i ]; + lowpass = lowpass + lp1[ ch ][ i ]; + highpass = highpass + hp1; + bandpass = bandpass + bp1[ ch ][ i ]; + + input[ i ] = input[ i ] - 0.000000001; + lp1[ ch ][ i ] = lp1[ ch ][ i ] + m_Freq * bp1[ ch ][ i ]; + hp1 = input[ i ] - lp1[ ch ][ i ] - rez * bp1[ ch ][ i ]; + bp1[ ch ][ i ] = m_Freq * hp1 + bp1[ ch ][ i ]; + + lowpass = (lowpass + lp1[ ch ][ i ]) * MULTI; + highpass = (highpass + hp1) * MULTI; + bandpass = (bandpass + bp1[ ch ][ i ]) * MULTI; + + out[ i ] = ( highpass * m_hpIn[ ch ] ) + ( lowpass * m_lpIn[ ch ] ) + ( bandpass * m_mpIn[ ch ] ); + } + + *pL = clamp( out[ L ] * AUDIO_MAX, -AUDIO_MAX, AUDIO_MAX ); + *pR = clamp( out[ R ] * AUDIO_MAX, -AUDIO_MAX, AUDIO_MAX ); +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +void Mix_2x4_Stereo::step() +{ + int ch, group, aux; + float inL = 0.0, inR = 0.0, inLClean, inRClean, outL, outR, mainL = 0.0, mainR = 0.0; + float inLvl, inPan; + float auxL[ nAUX ] = {}, auxR[ nAUX ] = {}; + bool bGroupActive[ GROUPS ] = {0}; + + if( !m_bInitialized ) + return; + + memset( m_fSubMix, 0, sizeof(m_fSubMix) ); + + // channel mixers + for ( ch = 0; ch < CHANNELS; ch++ ) + { + group = ch / CH_PER_GROUP; + + inLClean = 0.0; + inRClean = 0.0; + inL = 0.0; + inR = 0.0; + + if( inputs[ IN_RIGHT + ch ].active || inputs[ IN_LEFT + ch ].active ) + { + inLvl = clamp( ( params[ PARAM_LEVEL_IN + ch ].value + ( inputs[ IN_LEVEL + ch ].normalize( 0.0f ) / CV_MAX ) ), 0.0f, AMP_MAX ); + + bGroupActive[ group ] = true; + + // check right channel first for possible mono + if( inputs[ IN_RIGHT + ch ].active ) + { + inRClean = inputs[ IN_RIGHT + ch ].value; + inR = inRClean * inLvl; + m_bMono[ ch ] = false; + } + else + m_bMono[ ch ] = true; + + // left channel + if( inputs[ IN_LEFT + ch ].active ) + { + inLClean = inputs[ IN_LEFT + ch ].value; + inL = inLClean * inLvl; + + if( m_bMono[ ch ] ) + { + inRClean = inLClean; + inR = inL; + } + } + + // put output to aux if pre fader + for ( aux = 0; aux < nAUX; aux++ ) + { + if( m_bGroupPreFadeAuxStates[ group ][ aux ] ) + { + auxL[ aux ] += inLClean * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value; + auxR[ aux ] += inRClean * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value; + } + } + + if( m_FadeState[ ch ] == MUTE_FADE_STATE_DEC ) + { + m_fMuteFade[ ch ] -= FADE_MULT; + + if( m_fMuteFade[ ch ] <= 0.0 ) + { + m_fMuteFade[ ch ] = 0.0; + m_FadeState[ ch ] = MUTE_FADE_STATE_IDLE; + } + } + else if( m_FadeState[ ch ] == MUTE_FADE_STATE_INC ) + { + m_fMuteFade[ ch ] += FADE_MULT; + + if( m_fMuteFade[ ch ] >= 1.0 ) + { + m_fMuteFade[ ch ] = 1.0; + m_FadeState[ ch ] = MUTE_FADE_STATE_IDLE; + } + } + + ProcessEQ( ch, &inL, &inR ); + + inL *= m_fMuteFade[ ch ]; + inR *= m_fMuteFade[ ch ]; + + // pan + inPan = clamp( params[ PARAM_PAN_IN + ch ].value + ( inputs[ IN_PAN + ch ].normalize( 0.0f ) / CV_MAX ), -1.0f, 1.0f ); + + //lg.f("pan = %.3f\n", inputs[ IN_PAN + ch ].value ); + + if( inPan <= 0.0 ) + inR *= ( 1.0 + inPan ); + else + inL *= ( 1.0 - inPan ); + + // put output to aux if not pre fader + for ( aux = 0; aux < nAUX; aux++ ) + { + if( !m_bGroupPreFadeAuxStates[ group ][ aux ] ) + { + auxL[ aux ] += inL * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value; + auxR[ aux ] += inR * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value; + } + } + } + // this channel not active + else + { + + } + + m_fSubMix[ group ][ L ] += inL; + m_fSubMix[ group ][ R ] += inR; + + if( m_pLEDMeterChannel[ ch ][ 0 ] ) + m_pLEDMeterChannel[ ch ][ 0 ]->Process( inL / AUDIO_MAX ); + if( m_pLEDMeterChannel[ ch ][ 1 ] ) + m_pLEDMeterChannel[ ch ][ 1 ]->Process( inR / AUDIO_MAX); + } + + // group mixers + for ( group = 0; group < GROUPS; group++ ) + { + outL = 0.0; + outR = 0.0; + + if( bGroupActive[ group ] ) + { + inLvl = clamp( ( params[ PARAM_GROUP_LEVEL_IN + group ].value + ( inputs[ IN_GROUP_LEVEL + group ].normalize( 0.0f ) / CV_MAX ) ), 0.0f, AMP_MAX ); + + outL = m_fSubMix[ group ][ L ] * inLvl; + outR = m_fSubMix[ group ][ R ] * inLvl; + + // pan + inPan = clamp( params[ PARAM_GROUP_PAN_IN + group ].value + ( inputs[ IN_GROUP_PAN + group ].normalize( 0.0f ) / CV_MAX ), -1.0f, 1.0f ); + + if( inPan <= 0.0 ) + outR *= ( 1.0 + inPan ); + else + outL *= ( 1.0 - inPan ); + + if( m_GroupFadeState[ group ] == MUTE_FADE_STATE_DEC ) + { + m_fGroupMuteFade[ group ] -= FADE_MULT; + + if( m_fGroupMuteFade[ group ] <= 0.0 ) + { + m_fGroupMuteFade[ group ] = 0.0; + m_GroupFadeState[ group ] = MUTE_FADE_STATE_IDLE; + } + } + else if( m_GroupFadeState[ group ] == MUTE_FADE_STATE_INC ) + { + m_fGroupMuteFade[ group ] += FADE_MULT; + + if( m_fGroupMuteFade[ group ] >= 1.0 ) + { + m_fGroupMuteFade[ group ] = 1.0; + m_GroupFadeState[ group ] = MUTE_FADE_STATE_IDLE; + } + } + + outL *= m_fGroupMuteFade[ group ]; + outR *= m_fGroupMuteFade[ group ]; + } + + if( m_pLEDMeterGroup[ group ][ 0 ] ) + m_pLEDMeterGroup[ group ][ 0 ]->Process( outL / AUDIO_MAX ); + if( m_pLEDMeterGroup[ group ][ 1 ] ) + m_pLEDMeterGroup[ group ][ 1 ]->Process( outR / AUDIO_MAX ); + + mainL += outL; + mainR += outR; + } + + if( m_pLEDMeterMain[ 0 ] ) + m_pLEDMeterMain[ 0 ]->Process( ( mainL / AUDIO_MAX ) * params[ PARAM_MAIN_LEVEL ].value ); + if( m_pLEDMeterMain[ 1 ] ) + m_pLEDMeterMain[ 1 ]->Process( ( mainR / AUDIO_MAX ) * params[ PARAM_MAIN_LEVEL ].value ); + + // put aux output + for ( aux = 0; aux < nAUX; aux++ ) + { + outputs[ OUT_AUXL + aux ].value = clamp( auxL[ aux ] * params[ PARAM_AUX_OUT + aux ].value, -AUDIO_MAX, AUDIO_MAX ); + outputs[ OUT_AUXR + aux ].value = clamp( auxR[ aux ] * params[ PARAM_AUX_OUT + aux ].value, -AUDIO_MAX, AUDIO_MAX ); + } + + outputs[ OUT_MAINL ].value = clamp( mainL * params[ PARAM_MAIN_LEVEL ].value, -AUDIO_MAX, AUDIO_MAX ); + outputs[ OUT_MAINR ].value = clamp( mainR * params[ PARAM_MAIN_LEVEL ].value, -AUDIO_MAX, AUDIO_MAX ); +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, Mix_2x4_Stereo) { + Model *modelMix_2x4_Stereo = Model::create( "mscHack", "Mix_2x4_Stereo", "MIXER 2x4 Stereo/Mono", MIXER_TAG, EQUALIZER_TAG, DUAL_TAG, PANNING_TAG, AMPLIFIER_TAG, MULTIPLE_TAG ); + return modelMix_2x4_Stereo; +} diff --git a/plugins/community/repos/mscHack/src/Mixer_4x4_Stereo.cpp b/plugins/community/repos/mscHack/src/Mixer_4x4_Stereo.cpp new file mode 100644 index 00000000..960679e3 --- /dev/null +++ b/plugins/community/repos/mscHack/src/Mixer_4x4_Stereo.cpp @@ -0,0 +1,1233 @@ +#include "mscHack.hpp" +//#include "mscHack_Controls.hpp" +#include "dsp/digital.hpp" +//#include "CLog.h" + +namespace rack_plugin_mscHack { + +#define GROUPS 4 +#define CH_PER_GROUP 4 +#define CHANNELS ( GROUPS * CH_PER_GROUP ) +#define nAUX 4 + +#define GROUP_OFF_X 52 +#define CHANNEL_OFF_X 34 + +#define FADE_MULT (0.0005f) + +#define L 0 +#define R 1 + +#define MUTE_FADE_STATE_IDLE 0 +#define MUTE_FADE_STATE_INC 1 +#define MUTE_FADE_STATE_DEC 2 + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct Mix_4x4_Stereo : Module +{ + enum ParamIds + { + PARAM_MAIN_LEVEL, + PARAM_LEVEL_IN, + PARAM_PAN_IN = PARAM_LEVEL_IN + CHANNELS, + PARAM_GROUP_LEVEL_IN = PARAM_PAN_IN + CHANNELS, + PARAM_GROUP_PAN_IN = PARAM_GROUP_LEVEL_IN + GROUPS, + PARAM_MUTE_BUTTON = PARAM_GROUP_PAN_IN + GROUPS, + PARAM_SOLO_BUTTON = PARAM_MUTE_BUTTON + CHANNELS, + PARAM_GROUP_MUTE = PARAM_SOLO_BUTTON + CHANNELS, + PARAM_GROUP_SOLO = PARAM_GROUP_MUTE + GROUPS, + + PARAM_EQ_HI = PARAM_GROUP_SOLO + GROUPS, + PARAM_EQ_MD = PARAM_EQ_HI + CHANNELS, + PARAM_EQ_LO = PARAM_EQ_MD + CHANNELS, + + PARAM_AUX_KNOB = PARAM_EQ_LO + CHANNELS, + PARAM_AUX_PREFADE = PARAM_AUX_KNOB + (GROUPS * nAUX), + PARAM_AUX_OUT = PARAM_AUX_PREFADE + (GROUPS * nAUX), + + nPARAMS = PARAM_AUX_OUT + (nAUX) + }; + + enum InputIds + { + IN_LEFT, + IN_RIGHT = IN_LEFT + CHANNELS, + IN_LEVEL = IN_RIGHT + CHANNELS, + IN_PAN = IN_LEVEL + CHANNELS, + IN_GROUP_LEVEL = IN_PAN + CHANNELS, + IN_GROUP_PAN = IN_GROUP_LEVEL + GROUPS, + nINPUTS = IN_GROUP_PAN + GROUPS + }; + + enum OutputIds + { + OUT_MAINL, + OUT_MAINR, + + OUT_AUXL, + OUT_AUXR = OUT_AUXL + nAUX, + + nOUTPUTS = OUT_AUXR + nAUX + }; + + bool m_bInitialized = false; + CLog lg; + + // mute buttons + bool m_bMuteStates[ CHANNELS ] = {}; + float m_fMuteFade[ CHANNELS ] = {}; + + int m_FadeState[ CHANNELS ] = {MUTE_FADE_STATE_IDLE}; + + // solo buttons + bool m_bSoloStates[ CHANNELS ] = {}; + + // group mute buttons + bool m_bGroupMuteStates[ GROUPS ] = {}; + float m_fGroupMuteFade[ GROUPS ] = {}; + + int m_GroupFadeState[ GROUPS ] = {MUTE_FADE_STATE_IDLE}; + + // group solo buttons + bool m_bGroupSoloStates[ GROUPS ] = {}; + + // processing + bool m_bMono[ CHANNELS ]; + float m_fSubMix[ GROUPS ][ 3 ] = {}; + + // aux + bool m_bGroupPreFadeAuxStates[ GROUPS ][ nAUX ] = {}; + + // LED Meters + LEDMeterWidget *m_pLEDMeterChannel[ CHANNELS ][ 2 ] ={}; + LEDMeterWidget *m_pLEDMeterGroup[ GROUPS ][ 2 ] ={}; + LEDMeterWidget *m_pLEDMeterMain[ 2 ] ={}; + + // EQ Rez + float lp1[ CHANNELS ][ 2 ] = {}, bp1[ CHANNELS ][ 2 ] = {}; + float m_hpIn[ CHANNELS ]; + float m_lpIn[ CHANNELS ]; + float m_mpIn[ CHANNELS ]; + float m_rezIn[ CHANNELS ] = {0}; + float m_Freq; + + // buttons + MyLEDButton *m_pButtonChannelMute[ CHANNELS ] = {}; + MyLEDButton *m_pButtonChannelSolo[ CHANNELS ] = {}; + MyLEDButton *m_pButtonGroupMute[ GROUPS ] = {}; + MyLEDButton *m_pButtonGroupSolo[ GROUPS ] = {}; + MyLEDButton *m_pButtonAuxPreFader[ GROUPS ][ nAUX ] = {}; + +#define L 0 +#define R 1 + + // Contructor + Mix_4x4_Stereo() : Module(nPARAMS, nINPUTS, nOUTPUTS, 0){} + + //----------------------------------------------------- + // MyEQHi_Knob + //----------------------------------------------------- + struct MyEQHi_Knob : Knob_Green1_15 + { + Mix_4x4_Stereo *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Mix_4x4_Stereo*)module; + + if( mymodule ) + { + param = paramId - Mix_4x4_Stereo::PARAM_EQ_HI; + + mymodule->m_hpIn[ param ] = value; + } + + RoundKnob::onChange( e ); + } + }; + + //----------------------------------------------------- + // MyEQHi_Knob + //----------------------------------------------------- + struct MyEQMid_Knob : Knob_Green1_15 + { + Mix_4x4_Stereo *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Mix_4x4_Stereo*)module; + + if( mymodule ) + { + param = paramId - Mix_4x4_Stereo::PARAM_EQ_MD; + mymodule->m_mpIn[ param ] = value; + } + + RoundKnob::onChange( e ); + } + }; + + //----------------------------------------------------- + // MyEQHi_Knob + //----------------------------------------------------- + struct MyEQLo_Knob : Knob_Green1_15 + { + Mix_4x4_Stereo *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Mix_4x4_Stereo*)module; + + if( mymodule ) + { + param = paramId - Mix_4x4_Stereo::PARAM_EQ_LO; + mymodule->m_lpIn[ param ] = value; + } + + RoundKnob::onChange( e ); + } + }; + + // Overrides + void step() override; + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onRandomize() override{} + void onReset() override; + + void ProcessMuteSolo( int channel, bool bMute, bool bGroup ); + void ProcessEQ( int ch, float *pL, float *pR ); +}; + +//----------------------------------------------------- +// MyLEDButton_Aux +//----------------------------------------------------- +void Mix_4x4_Stereo_MyLEDButton_Aux( void *pClass, int id, bool bOn ) +{ + int ch, i; + + Mix_4x4_Stereo *mymodule; + mymodule = (Mix_4x4_Stereo*)pClass; + + ch = id / nAUX; + i = id - (nAUX * ch); + + mymodule->m_bGroupPreFadeAuxStates[ ch ][ i ] = !mymodule->m_bGroupPreFadeAuxStates[ ch ][ i ]; + mymodule->m_pButtonAuxPreFader[ ch ][ i ]->Set( mymodule->m_bGroupPreFadeAuxStates[ ch ][ i ] ); +} + +//----------------------------------------------------- +// MyLEDButton_ChMute +//----------------------------------------------------- +void Mix_4x4_Stereo_MyLEDButton_ChMute( void *pClass, int id, bool bOn ) +{ + Mix_4x4_Stereo *mymodule; + mymodule = (Mix_4x4_Stereo*)pClass; + mymodule->ProcessMuteSolo( id, true, false ); +} + +//----------------------------------------------------- +// MyLEDButton_ChSolo +//----------------------------------------------------- +void Mix_4x4_Stereo_MyLEDButton_ChSolo( void *pClass, int id, bool bOn ) +{ + Mix_4x4_Stereo *mymodule; + mymodule = (Mix_4x4_Stereo*)pClass; + mymodule->ProcessMuteSolo( id, false, false ); +} + +//----------------------------------------------------- +// MyLEDButton_GroupMute +//----------------------------------------------------- +void Mix_4x4_Stereo_MyLEDButton_GroupMute( void *pClass, int id, bool bOn ) +{ + Mix_4x4_Stereo *mymodule; + mymodule = (Mix_4x4_Stereo*)pClass; + mymodule->ProcessMuteSolo( id, true, true ); +} + +//----------------------------------------------------- +// MyLEDButton_GroupSolo +//----------------------------------------------------- +void Mix_4x4_Stereo_MyLEDButton_GroupSolo( void *pClass, int id, bool bOn ) +{ + Mix_4x4_Stereo *mymodule; + mymodule = (Mix_4x4_Stereo*)pClass; + mymodule->ProcessMuteSolo( id, false, true ); +} + +#define CUTOFF (0.025f) +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- +struct Mix_4x4_Stereo_Widget : ModuleWidget { + Mix_4x4_Stereo_Widget( Mix_4x4_Stereo *module ); +}; + +Mix_4x4_Stereo_Widget::Mix_4x4_Stereo_Widget( Mix_4x4_Stereo *module ) : ModuleWidget(module) +{ + float fx, fx2, fx3, fx5, fx7; + int ch, x, y, i, ybase, x2, y2; + + box.size = Vec( 15*47, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/Mix_4x4_Stereo.svg"))); + addChild(panel); + } + + //module->lg.Open("Mix_4x4_Stereo.txt"); + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + //---------------------------------------------------- + // Add mix sliders + x = 23; + y = 38; + + // main channel + for ( ch = 0; ch < CHANNELS; ch++ ) + { + // Left channel inputs + addInput(Port::create( Vec( x, y ), Port::INPUT, module, Mix_4x4_Stereo::IN_LEFT + ch ) ); + + y += 25; + + // Right channel inputs + addInput(Port::create( Vec( x, y ), Port::INPUT, module, Mix_4x4_Stereo::IN_RIGHT + ch ) ); + + y += 26; + + // Level knobs + addParam(ParamWidget::create( Vec( x - 5, y ), module, Mix_4x4_Stereo::PARAM_LEVEL_IN + ch, 0.0, AMP_MAX, 0.0 ) ); + + y += 31; + + // Level inputs + addInput(Port::create( Vec( x, y ), Port::INPUT, module, Mix_4x4_Stereo::IN_LEVEL + ch ) ); + + y += 23; + + // pan knobs + addParam(ParamWidget::create( Vec( x - 5, y ), module, Mix_4x4_Stereo::PARAM_PAN_IN + ch, -1.0, 1.0, 0.0 ) ); + + y += 31; + + // Pan inputs + addInput(Port::create( Vec( x, y ), Port::INPUT, module, Mix_4x4_Stereo::IN_PAN + ch ) ); + + y += 22; + + // mute buttons + module->m_pButtonChannelMute[ ch ] = new MyLEDButton( x - 5, y, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, ch, module, Mix_4x4_Stereo_MyLEDButton_ChMute ); + addChild( module->m_pButtonChannelMute[ ch ] ); + //y += 26; + + // solo buttons + module->m_pButtonChannelSolo[ ch ] = new MyLEDButton( x + 11, y, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_SWITCH, ch, module, Mix_4x4_Stereo_MyLEDButton_ChSolo ); + addChild( module->m_pButtonChannelSolo[ ch ] ); + + y += 22; + y2 = y; + + // eq and rez + addParam(ParamWidget::create( Vec( x - 5, y ), module, Mix_4x4_Stereo::PARAM_EQ_HI + ch, 0.0, 1.0, 0.5 ) ); + + y += 19; + + addParam(ParamWidget::create( Vec( x - 5, y ), module, Mix_4x4_Stereo::PARAM_EQ_MD + ch, 0.0, 1.0, 0.5 ) ); + + y += 19; + + addParam(ParamWidget::create( Vec( x - 5, y ), module, Mix_4x4_Stereo::PARAM_EQ_LO + ch, 0.0, 1.0, 0.5 ) ); + + // LED Meters + module->m_pLEDMeterChannel[ ch ][ 0 ] = new LEDMeterWidget( x + 13, y2 + 30, 4, 1, 1, true ); + addChild( module->m_pLEDMeterChannel[ ch ][ 0 ] ); + module->m_pLEDMeterChannel[ ch ][ 1 ] = new LEDMeterWidget( x + 18, y2 + 30, 4, 1, 1, true ); + addChild( module->m_pLEDMeterChannel[ ch ][ 1 ] ); + + if( ( ch & 3 ) == 3 ) + { + x += GROUP_OFF_X; + } + else + { + x += CHANNEL_OFF_X; + } + + y = 38; + } + + // group mixera + ybase = 278; + x = 12; + for( i = 0; i < GROUPS; i++ ) + { + // mute/solo buttons + x2 = x + 81; + y2 = ybase; + + module->m_pButtonGroupMute[ i ] = new MyLEDButton( x2, y2 + 4, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, i, module, Mix_4x4_Stereo_MyLEDButton_GroupMute ); + addChild( module->m_pButtonGroupMute[ i ] ); + x2 += 28; + + module->m_pButtonGroupSolo[ i ] = new MyLEDButton( x2, y2 + 4, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_SWITCH, i, module, Mix_4x4_Stereo_MyLEDButton_GroupSolo ); + addChild( module->m_pButtonGroupSolo[ i ] ); + + // group level and pan inputs + x2 = x + 79; + y2 = ybase + 23; + + // group VU Meters + module->m_pLEDMeterGroup[ i ][ 0 ] = new LEDMeterWidget( x2 + 2, y2 + 21, 5, 2, 1, true ); + addChild( module->m_pLEDMeterGroup[ i ][ 0 ] ); + module->m_pLEDMeterGroup[ i ][ 1 ] = new LEDMeterWidget( x2 + 9, y2 + 21, 5, 2, 1, true ); + addChild( module->m_pLEDMeterGroup[ i ][ 1 ] ); + + // group level and pan knobs + x2 = x + 105; + y2 = ybase + 17; + + addParam(ParamWidget::create( Vec( x2, y2 + 3 ), module, Mix_4x4_Stereo::PARAM_GROUP_LEVEL_IN + i, 0.0, AMP_MAX, 0.0 ) ); + + y2 += 32; + + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_GROUP_PAN_IN + i, -1.0, 1.0, 0.0 ) ); + + // aux 1/3 +#define AUX_H 29 + x2 = x + 6; + y2 = ybase + 20; + + module->m_pButtonAuxPreFader[ i ][ 0 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, (i * nAUX) + 0, module, Mix_4x4_Stereo_MyLEDButton_Aux ); + addChild( module->m_pButtonAuxPreFader[ i ][ 0 ] ); + + y2 += AUX_H; + + module->m_pButtonAuxPreFader[ i ][ 2 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, (i * nAUX) + 2, module, Mix_4x4_Stereo_MyLEDButton_Aux ); + addChild( module->m_pButtonAuxPreFader[ i ][ 2 ] ); + + x2 = x + 20; + y2 = ybase + 16; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 0, 0.0, AMP_MAX, 0.0 ) ); + y2 += AUX_H; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 2, 0.0, AMP_MAX, 0.0 ) ); + + // aux 2/4 + x2 = x + 38; + y2 = ybase + 28; + + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 1, 0.0, AMP_MAX, 0.0 ) ); + y2 += AUX_H; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_KNOB + (i * nAUX) + 3, 0.0, AMP_MAX, 0.0 ) ); + + x2 = x + 62; + y2 = ybase + 32; + + module->m_pButtonAuxPreFader[ i ][ 1 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, (i * nAUX) + 1, module, Mix_4x4_Stereo_MyLEDButton_Aux ); + addChild( module->m_pButtonAuxPreFader[ i ][ 1 ] ); + + y2 += AUX_H; + + module->m_pButtonAuxPreFader[ i ][ 3 ] = new MyLEDButton( x2, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, (i * nAUX) + 3, module, Mix_4x4_Stereo_MyLEDButton_Aux ); + addChild( module->m_pButtonAuxPreFader[ i ][ 3 ] ); + + // account for slight error in pixel conversion to svg area + x += 155; + } + + //for( int i = 0; i < 15; i++ ) + //module->lg.f("level %d = %.3f\n", i, module->m_pLEDMeterChannel[ 0 ][ 0 ]->flevels[ i ] ); + + // main mixer knob + addParam(ParamWidget::create( Vec( 626, 237 ), module, Mix_4x4_Stereo::PARAM_MAIN_LEVEL, 0.0, AMP_MAX, 0.0 ) ); + + module->m_pLEDMeterMain[ 0 ] = new LEDMeterWidget( 684, 242, 5, 3, 2, true ); + addChild( module->m_pLEDMeterMain[ 0 ] ); + module->m_pLEDMeterMain[ 1 ] = new LEDMeterWidget( 691, 242, 5, 3, 2, true ); + addChild( module->m_pLEDMeterMain[ 1 ] ); + + // outputs + + addOutput(Port::create( Vec( 636, 305 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_MAINL ) ); + addOutput(Port::create( Vec( 668, 335 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_MAINR ) ); + + // AUX out +#define AUX_OUT_H 42 + x2 = 649; + y2 = 25; + + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_OUT + 0, 0.0, AMP_MAX, 0.0 ) ); y2 += AUX_OUT_H; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_OUT + 1, 0.0, AMP_MAX, 0.0 ) ); y2 += AUX_OUT_H; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_OUT + 2, 0.0, AMP_MAX, 0.0 ) ); y2 += AUX_OUT_H; + addParam(ParamWidget::create( Vec( x2, y2 ), module, Mix_4x4_Stereo::PARAM_AUX_OUT + 3, 0.0, AMP_MAX, 0.0 ) ); + + x2 = 635; + y2 = 45; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXL ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXL + 1 ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXL + 2 ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXL + 3 ) ); + + x2 = 664; + y2 = 45; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXR ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXR + 1 ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXR + 2 ) ); y2 += AUX_OUT_H; + addOutput(Port::create( Vec( x2, y2 ), Port::OUTPUT, module, Mix_4x4_Stereo::OUT_AUXR + 3 ) ); + + // calculate eq rez freq + fx = 3.141592 * (CUTOFF * 0.026315789473684210526315789473684) * 2 * 3.141592; + fx2 = fx*fx; + fx3 = fx2*fx; + fx5 = fx3*fx2; + fx7 = fx5*fx2; + + module->m_Freq = 2.0 * (fx + - (fx3 * 0.16666666666666666666666666666667) + + (fx5 * 0.0083333333333333333333333333333333) + - (fx7 * 0.0001984126984126984126984126984127)); + + module->m_bInitialized = true; + module->onReset(); +} + +//----------------------------------------------------- +// Procedure: reset +// +//----------------------------------------------------- +void Mix_4x4_Stereo::onReset() +{ + int ch, i, aux; + + if( !m_bInitialized ) + return; + + for( ch = 0; ch < CHANNELS; ch++ ) + { + m_FadeState[ ch ] = MUTE_FADE_STATE_IDLE; + + m_pButtonChannelMute[ ch ]->Set( false ); + m_pButtonChannelSolo[ ch ]->Set( false ); + + m_bMuteStates[ ch ] = false; + m_bSoloStates[ ch ] = false; + m_fMuteFade[ ch ] = 1.0; + } + + for( i = 0; i < GROUPS; i++ ) + { + for( aux = 0; aux < nAUX; aux++ ) + { + m_bGroupPreFadeAuxStates[ i ][ aux ] = false; + m_pButtonAuxPreFader[ i ][ aux ]->Set( false ); + } + + m_GroupFadeState[ i ] = MUTE_FADE_STATE_IDLE; + m_pButtonGroupMute[ i ]->Set( false ); + m_pButtonGroupSolo[ i ]->Set( false ); + m_bGroupMuteStates[ i ] = false; + m_fGroupMuteFade[ i ] = 1.0; + } +} + +//----------------------------------------------------- +// Procedure: +// +//----------------------------------------------------- +json_t *Mix_4x4_Stereo::toJson() +{ + bool *pbool; + json_t *gatesJ; + json_t *rootJ = json_object(); + + // channel mutes + pbool = &m_bMuteStates[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < CHANNELS; i++) + { + json_t *gateJ = json_integer( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "channel mutes", gatesJ ); + + // channel solos + pbool = &m_bSoloStates[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < CHANNELS; i++) + { + json_t *gateJ = json_integer( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "channel solos", gatesJ ); + + // group mutes + pbool = &m_bGroupMuteStates[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < GROUPS; i++) + { + json_t *gateJ = json_integer( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "group mutes", gatesJ ); + + // group solos + pbool = &m_bGroupSoloStates[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < GROUPS; i++) + { + json_t *gateJ = json_integer( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "group solos", gatesJ ); + + // AUX states + pbool = &m_bGroupPreFadeAuxStates[ 0 ][ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < GROUPS * nAUX; i++) + { + json_t *gateJ = json_integer( (int) pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "group AUX prefade states", gatesJ ); + + return rootJ; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void Mix_4x4_Stereo::fromJson(json_t *rootJ) +{ + int ch, i, aux; + bool *pbool; + json_t *StepsJ; + bool bSolo[ GROUPS ] = {0}, bGroupSolo = false; + + // channel mutes + pbool = &m_bMuteStates[ 0 ]; + + StepsJ = json_object_get( rootJ, "channel mutes" ); + + if (StepsJ) + { + for ( i = 0; i < CHANNELS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_integer_value( gateJ ); + } + } + + // channel solos + pbool = &m_bSoloStates[ 0 ]; + + StepsJ = json_object_get( rootJ, "channel solos" ); + + if (StepsJ) + { + for ( i = 0; i < CHANNELS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_integer_value( gateJ ); + } + } + + // group mutes + pbool = &m_bGroupMuteStates[ 0 ]; + + StepsJ = json_object_get( rootJ, "group mutes" ); + + if (StepsJ) + { + for ( i = 0; i < GROUPS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_integer_value( gateJ ); + } + } + + // group solos + pbool = &m_bGroupSoloStates[ 0 ]; + + StepsJ = json_object_get( rootJ, "group solos" ); + + if (StepsJ) + { + for ( i = 0; i < GROUPS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_integer_value( gateJ ); + } + } + + // AUX states + pbool = &m_bGroupPreFadeAuxStates[ 0 ][ 0 ]; + + StepsJ = json_object_get( rootJ, "group AUX prefade states" ); + + if (StepsJ) + { + for ( i = 0; i < GROUPS * nAUX; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_integer_value( gateJ ); + } + } + + // anybody soloing? + for( ch = 0; ch < CHANNELS; ch++ ) + { + if( m_bSoloStates[ ch ] ) + { + bSolo[ ch / CH_PER_GROUP ] = true; + } + } + + for( ch = 0; ch < CHANNELS; ch++ ) + { + if( bSolo[ ch / CH_PER_GROUP ] ) + { + // only open soloing channels + if( m_bSoloStates[ ch ] ) + m_fMuteFade[ ch ] = 1.0; + else + m_fMuteFade[ ch ] = 0.0; + } + else + { + // nobody is soloing so just open the non muted channels + m_fMuteFade[ ch ] = m_bMuteStates[ ch ] ? 0.0: 1.0; + } + + m_pButtonChannelMute[ ch ]->Set( m_bMuteStates[ ch ] ); + m_pButtonChannelSolo[ ch ]->Set( m_bSoloStates[ ch ] ); + + //lg.f("channel mute fade = %.3f\n", m_fMuteFade[ ch ] ); + } + + // anybody group soloing? + for( i = 0; i < GROUPS; i++ ) + { + if( m_bGroupSoloStates[ i ] ) + { + bGroupSolo = true; + break; + } + } + + for( i = 0; i < GROUPS; i++ ) + { + for( aux = 0; aux < nAUX; aux++ ) + m_pButtonAuxPreFader[ i ][ aux ]->Set( m_bGroupPreFadeAuxStates[ i ][ aux ] ); + + if( bGroupSolo ) + { + // only open soloing channels + if( m_bGroupSoloStates[ i ] ) + m_fGroupMuteFade[ i ] = 1.0; + else + m_fGroupMuteFade[ i ] = 0.0; + } + else + { + // nobody is soloing so just open the non muted channels + m_fGroupMuteFade[ i ] = m_bGroupMuteStates[ i ] ? 0.0: 1.0; + } + + m_pButtonGroupMute[ i ]->Set( m_bGroupMuteStates[ i ] ); + m_pButtonGroupSolo[ i ]->Set( m_bGroupSoloStates[ i ] ); + + //lg.f("group mute fade = %.3f\n", m_fGroupMuteFade[ i ] ); + } +} + +//----------------------------------------------------- +// Procedure: ProcessMuteSolo +// +//----------------------------------------------------- +void Mix_4x4_Stereo::ProcessMuteSolo( int index, bool bMute, bool bGroup ) +{ + int i, group, si, ei; + bool bSoloEnabled = false, bSoloOff = false; + + if( bGroup ) + { + if( bMute ) + { + m_bGroupMuteStates[ index ] = !m_bGroupMuteStates[ index ]; + + // turn solo off + if( m_bGroupSoloStates[ index ] ) + { + bSoloOff = true; + m_bGroupSoloStates[ index ] = false; + m_pButtonGroupSolo[ index ]->Set( false ); + } + + // if mute is off then set volume + if( m_bGroupMuteStates[ index ] ) + { + m_pButtonGroupMute[ index ]->Set( true ); + m_GroupFadeState[ index ] = MUTE_FADE_STATE_DEC; + } + else + { + m_pButtonGroupMute[ index ]->Set( false ); + m_GroupFadeState[ index ] = MUTE_FADE_STATE_INC; + } + } + else + { + m_bGroupSoloStates[ index ] = !m_bGroupSoloStates[ index ]; + + // turn mute off + if( m_bGroupMuteStates[ index ] ) + { + m_bGroupMuteStates[ index ] = false; + m_pButtonGroupMute[ index ]->Set( false ); + } + + // shut down volume of all groups not in solo + if( !m_bGroupSoloStates[ index ] ) + { + bSoloOff = true; + m_pButtonGroupSolo[ index ]->Set( false ); + } + else + { + m_pButtonGroupSolo[ index ]->Set( true ); + } + } + + // is a track soloing? + for( i = 0; i < GROUPS; i++ ) + { + if( m_bGroupSoloStates[ i ] ) + { + bSoloEnabled = true; + break; + } + } + + if( bSoloEnabled ) + { + // process solo + for( i = 0; i < GROUPS; i++ ) + { + // shut down volume of all groups not in solo + if( !m_bGroupSoloStates[ i ] ) + { + m_GroupFadeState[ i ] = MUTE_FADE_STATE_DEC; + } + else + { + m_GroupFadeState[ i ] = MUTE_FADE_STATE_INC; + } + } + } + // nobody soloing and just turned solo off then enable all channels that aren't muted + else if( bSoloOff ) + { + // process solo + for( i = 0; i < GROUPS; i++ ) + { + // bring back if not muted + if( !m_bGroupMuteStates[ i ] ) + { + m_GroupFadeState[ i ] = MUTE_FADE_STATE_INC; + } + } + } + } + // !bGroup + else + { + group = index / CH_PER_GROUP; + + si = group * CH_PER_GROUP; + ei = si + CH_PER_GROUP; + + if( bMute ) + { + m_bMuteStates[ index ] = !m_bMuteStates[ index ]; + + // turn solo off + if( m_bSoloStates[ index ] ) + { + bSoloOff = true; + m_bSoloStates[ index ] = false; + m_pButtonChannelSolo[ index ]->Set( false ); + } + + // if mute is off then set volume + if( m_bMuteStates[ index ] ) + { + m_pButtonChannelMute[ index ]->Set( true ); + m_FadeState[ index ] = MUTE_FADE_STATE_DEC; + } + else + { + m_pButtonChannelMute[ index ]->Set( false ); + m_FadeState[ index ] = MUTE_FADE_STATE_INC; + } + } + else + { + m_bSoloStates[ index ] = !m_bSoloStates[ index ]; + + // turn mute off + if( m_bMuteStates[ index ] ) + { + m_bMuteStates[ index ] = false; + m_pButtonChannelMute[ index ]->Set( false ); + } + + // toggle solo + if( !m_bSoloStates[ index ] ) + { + bSoloOff = true; + m_pButtonChannelSolo[ index ]->Set( false ); + } + else + { + m_pButtonChannelSolo[ index ]->Set( true ); + } + } + + // is a track soloing? + for( i = si; i < ei; i++ ) + { + if( m_bSoloStates[ i ] ) + { + bSoloEnabled = true; + break; + } + } + + if( bSoloEnabled ) + { + // process solo + for( i = si; i < ei; i++ ) + { + // shut down volume of all not in solo + if( !m_bSoloStates[ i ] ) + { + m_FadeState[ i ] = MUTE_FADE_STATE_DEC; + } + else + { + m_FadeState[ i ] = MUTE_FADE_STATE_INC; + } + } + } + // nobody soloing and just turned solo off then enable all channels that aren't muted + else if( bSoloOff ) + { + // process solo + for( i = si; i < ei; i++ ) + { + // bring back if not muted + if( !m_bMuteStates[ i ] ) + { + m_FadeState[ i ] = MUTE_FADE_STATE_INC; + } + } + } + } +} + +//----------------------------------------------------- +// Procedure: ProcessEQ +// +//----------------------------------------------------- +#define MULTI (0.33333333333333333333333333333333f) +void Mix_4x4_Stereo::ProcessEQ( int ch, float *pL, float *pR ) +{ + float rez, hp1; + float input[ 2 ], out[ 2 ], lowpass, bandpass, highpass; + + input[ L ] = *pL / AUDIO_MAX; + input[ R ] = *pR / AUDIO_MAX; + + rez = 1.00; + + // do left and right channels + for( int i = 0; i < 2; i++ ) + { + input[ i ] = input[ i ] + 0.000000001; + + lp1[ ch ][ i ] = lp1[ ch ][ i ] + m_Freq * bp1[ ch ][ i ]; + hp1 = input[ i ] - lp1[ ch ][ i ] - rez * bp1[ ch ][ i ]; + bp1[ ch ][ i ] = m_Freq * hp1 + bp1[ ch ][ i ]; + lowpass = lp1[ ch ][ i ]; + highpass = hp1; + bandpass = bp1[ ch ][ i ]; + + lp1[ ch ][ i ] = lp1[ ch ][ i ] + m_Freq * bp1[ ch ][ i ]; + hp1 = input[ i ] - lp1[ ch ][ i ] - rez * bp1[ ch ][ i ]; + bp1[ ch ][ i ] = m_Freq * hp1 + bp1[ ch ][ i ]; + lowpass = lowpass + lp1[ ch ][ i ]; + highpass = highpass + hp1; + bandpass = bandpass + bp1[ ch ][ i ]; + + input[ i ] = input[ i ] - 0.000000001; + lp1[ ch ][ i ] = lp1[ ch ][ i ] + m_Freq * bp1[ ch ][ i ]; + hp1 = input[ i ] - lp1[ ch ][ i ] - rez * bp1[ ch ][ i ]; + bp1[ ch ][ i ] = m_Freq * hp1 + bp1[ ch ][ i ]; + + lowpass = (lowpass + lp1[ ch ][ i ]) * MULTI; + highpass = (highpass + hp1) * MULTI; + bandpass = (bandpass + bp1[ ch ][ i ]) * MULTI; + + out[ i ] = ( highpass * m_hpIn[ ch ] ) + ( lowpass * m_lpIn[ ch ] ) + ( bandpass * m_mpIn[ ch ] ); + } + + *pL = clamp( out[ L ] * AUDIO_MAX, -AUDIO_MAX, AUDIO_MAX ); + *pR = clamp( out[ R ] * AUDIO_MAX, -AUDIO_MAX, AUDIO_MAX ); +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +void Mix_4x4_Stereo::step() +{ + int ch, group, aux; + float inL = 0.0, inR = 0.0, inLClean, inRClean, outL, outR, mainL = 0.0, mainR = 0.0; + float inLvl, inPan; + float auxL[ nAUX ] = {}, auxR[ nAUX ] = {}; + bool bGroupActive[ GROUPS ] = {0}; + + if( !m_bInitialized ) + return; + + memset( m_fSubMix, 0, sizeof(m_fSubMix) ); + + // channel mixers + for ( ch = 0; ch < CHANNELS; ch++ ) + { + group = ch / CH_PER_GROUP; + + inLClean = 0.0; + inRClean = 0.0; + inL = 0.0; + inR = 0.0; + + if( inputs[ IN_RIGHT + ch ].active || inputs[ IN_LEFT + ch ].active ) + { + inLvl = clamp( ( params[ PARAM_LEVEL_IN + ch ].value + ( inputs[ IN_LEVEL + ch ].normalize( 0.0f ) / CV_MAX ) ), 0.0f, AMP_MAX ); + + bGroupActive[ group ] = true; + + // check right channel first for possible mono + if( inputs[ IN_RIGHT + ch ].active ) + { + inRClean = inputs[ IN_RIGHT + ch ].value; + inR = inRClean * inLvl; + m_bMono[ ch ] = false; + } + else + m_bMono[ ch ] = true; + + // left channel + if( inputs[ IN_LEFT + ch ].active ) + { + inLClean = inputs[ IN_LEFT + ch ].value; + inL = inLClean * inLvl; + + if( m_bMono[ ch ] ) + { + inRClean = inLClean; + inR = inL; + } + } + + // put output to aux if pre fader + for ( aux = 0; aux < nAUX; aux++ ) + { + if( m_bGroupPreFadeAuxStates[ group ][ aux ] ) + { + auxL[ aux ] += inLClean * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value; + auxR[ aux ] += inRClean * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value; + } + } + + if( m_FadeState[ ch ] == MUTE_FADE_STATE_DEC ) + { + m_fMuteFade[ ch ] -= FADE_MULT; + + if( m_fMuteFade[ ch ] <= 0.0 ) + { + m_fMuteFade[ ch ] = 0.0; + m_FadeState[ ch ] = MUTE_FADE_STATE_IDLE; + } + } + else if( m_FadeState[ ch ] == MUTE_FADE_STATE_INC ) + { + m_fMuteFade[ ch ] += FADE_MULT; + + if( m_fMuteFade[ ch ] >= 1.0 ) + { + m_fMuteFade[ ch ] = 1.0; + m_FadeState[ ch ] = MUTE_FADE_STATE_IDLE; + } + } + + ProcessEQ( ch, &inL, &inR ); + + inL *= m_fMuteFade[ ch ]; + inR *= m_fMuteFade[ ch ]; + + // pan + inPan = clamp( params[ PARAM_PAN_IN + ch ].value + ( inputs[ IN_PAN + ch ].normalize( 0.0f ) / CV_MAX ), -1.0f, 1.0f ); + + //lg.f("pan = %.3f\n", inputs[ IN_PAN + ch ].value ); + + if( inPan <= 0.0 ) + inR *= ( 1.0 + inPan ); + else + inL *= ( 1.0 - inPan ); + + // put output to aux if not pre fader + for ( aux = 0; aux < nAUX; aux++ ) + { + if( !m_bGroupPreFadeAuxStates[ group ][ aux ] ) + { + auxL[ aux ] += inL * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value; + auxR[ aux ] += inR * params[ PARAM_AUX_KNOB + (group * nAUX) + aux ].value; + } + } + } + // this channel not active + else + { + + } + + m_fSubMix[ group ][ L ] += inL; + m_fSubMix[ group ][ R ] += inR; + + if( m_pLEDMeterChannel[ ch ][ 0 ] ) + m_pLEDMeterChannel[ ch ][ 0 ]->Process( inL / AUDIO_MAX ); + if( m_pLEDMeterChannel[ ch ][ 1 ] ) + m_pLEDMeterChannel[ ch ][ 1 ]->Process( inR / AUDIO_MAX); + } + + // group mixers + for ( group = 0; group < GROUPS; group++ ) + { + outL = 0.0; + outR = 0.0; + + if( bGroupActive[ group ] ) + { + inLvl = clamp( ( params[ PARAM_GROUP_LEVEL_IN + group ].value + ( inputs[ IN_GROUP_LEVEL + group ].normalize( 0.0f ) / CV_MAX ) ), 0.0f, AMP_MAX ); + + outL = m_fSubMix[ group ][ L ] * inLvl; + outR = m_fSubMix[ group ][ R ] * inLvl; + + // pan + inPan = clamp( params[ PARAM_GROUP_PAN_IN + group ].value + ( inputs[ IN_GROUP_PAN + group ].normalize( 0.0f ) / CV_MAX ), -1.0f, 1.0f ); + + if( inPan <= 0.0 ) + outR *= ( 1.0 + inPan ); + else + outL *= ( 1.0 - inPan ); + + if( m_GroupFadeState[ group ] == MUTE_FADE_STATE_DEC ) + { + m_fGroupMuteFade[ group ] -= FADE_MULT; + + if( m_fGroupMuteFade[ group ] <= 0.0 ) + { + m_fGroupMuteFade[ group ] = 0.0; + m_GroupFadeState[ group ] = MUTE_FADE_STATE_IDLE; + } + } + else if( m_GroupFadeState[ group ] == MUTE_FADE_STATE_INC ) + { + m_fGroupMuteFade[ group ] += FADE_MULT; + + if( m_fGroupMuteFade[ group ] >= 1.0 ) + { + m_fGroupMuteFade[ group ] = 1.0; + m_GroupFadeState[ group ] = MUTE_FADE_STATE_IDLE; + } + } + + outL *= m_fGroupMuteFade[ group ]; + outR *= m_fGroupMuteFade[ group ]; + } + + if( m_pLEDMeterGroup[ group ][ 0 ] ) + m_pLEDMeterGroup[ group ][ 0 ]->Process( outL / AUDIO_MAX ); + if( m_pLEDMeterGroup[ group ][ 1 ] ) + m_pLEDMeterGroup[ group ][ 1 ]->Process( outR / AUDIO_MAX ); + + mainL += outL; + mainR += outR; + } + + if( m_pLEDMeterMain[ 0 ] ) + m_pLEDMeterMain[ 0 ]->Process( ( mainL / AUDIO_MAX ) * params[ PARAM_MAIN_LEVEL ].value ); + if( m_pLEDMeterMain[ 1 ] ) + m_pLEDMeterMain[ 1 ]->Process( ( mainR / AUDIO_MAX ) * params[ PARAM_MAIN_LEVEL ].value ); + + // put aux output + for ( aux = 0; aux < nAUX; aux++ ) + { + outputs[ OUT_AUXL + aux ].value = clamp( auxL[ aux ] * params[ PARAM_AUX_OUT + aux ].value, -AUDIO_MAX, AUDIO_MAX ); + outputs[ OUT_AUXR + aux ].value = clamp( auxR[ aux ] * params[ PARAM_AUX_OUT + aux ].value, -AUDIO_MAX, AUDIO_MAX ); + } + + outputs[ OUT_MAINL ].value = clamp( mainL * params[ PARAM_MAIN_LEVEL ].value, -AUDIO_MAX, AUDIO_MAX ); + outputs[ OUT_MAINR ].value = clamp( mainR * params[ PARAM_MAIN_LEVEL ].value, -AUDIO_MAX, AUDIO_MAX ); +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, Mix_4x4_Stereo) { + Model *modelMix_4x4_Stereo = Model::create( "mscHack", "Mix_4x4_Stereo(2)", "MIXER 4x4 Stereo/Mono", MIXER_TAG, EQUALIZER_TAG, QUAD_TAG, PANNING_TAG, AMPLIFIER_TAG, MULTIPLE_TAG ); + return modelMix_4x4_Stereo; +} diff --git a/plugins/community/repos/mscHack/src/PingPong.cpp b/plugins/community/repos/mscHack/src/PingPong.cpp new file mode 100644 index 00000000..f03bbe0a --- /dev/null +++ b/plugins/community/repos/mscHack/src/PingPong.cpp @@ -0,0 +1,491 @@ +#include "mscHack.hpp" +//#include "mscHack_Controls.hpp" +#include "dsp/digital.hpp" +//#include "CLog.h" + +namespace rack_plugin_mscHack { + +typedef struct +{ + float lp1, bp1; + float hpIn; + float lpIn; + float mpIn; + +}FILTER_PARAM_STRUCT; + +#define L 0 +#define R 1 + +#define DELAY_BUFF_LEN 0x80000 + +#define MAC_DELAY_SECONDS 4.0f + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct PingPong : Module +{ + enum ParamIds + { + PARAM_DELAYL, + PARAM_DELAYR, + PARAM_LEVEL_FB_LR, + PARAM_LEVEL_FB_LL, + PARAM_LEVEL_FB_RL, + PARAM_LEVEL_FB_RR, + PARAM_CUTOFF, + PARAM_Q, + PARAM_MIX, + PARAM_FILTER_MODE, + PARAM_REVERSE, + nPARAMS + }; + + enum InputIds + { + INPUT_L, + INPUT_R, + INPUT_SYNC, + nINPUTS + }; + + enum OutputIds + { + OUT_L, + OUT_R, + nOUTPUTS + }; + + enum FILTER_TYPES + { + FILTER_OFF, + FILTER_LP, + FILTER_HP, + FILTER_BP, + FILTER_NT + }; + + bool m_bInitialized = false; + CLog lg; + + FILTER_PARAM_STRUCT m_Filter[ 2 ]; + + float m_fCutoff = 0.0; + float m_LastOut[ 2 ] = {}; + float m_DelayBuffer[ 2 ][ DELAY_BUFF_LEN ]; + + int m_DelayIn = 0; + int m_DelayOut[ 2 ] = {0}; + + bool m_bReverseState = false; + + // sync clock + SchmittTrigger m_SchmittSync; + int m_LastSyncCount = 0; + int m_SyncCount = 0; + int m_SyncTime = 0; + + // LAST + int m_LastDelayKnob[ 2 ] = {}; + bool m_bWasSynced = false; + + MyLEDButton *m_pButtonReverse = NULL; + + // Contructor + PingPong() : Module(nPARAMS, nINPUTS, nOUTPUTS, 0){} + + // Overrides + void step() override; + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onRandomize() override; + void onReset() override; + + void ChangeFilterCutoff( float cutfreq ); + float Filter( int ch, float in ); +}; + +//----------------------------------------------------- +// PingPong_Reverse +//----------------------------------------------------- +void PingPong_Reverse( void *pClass, int id, bool bOn ) +{ + float delay; + PingPong *mymodule; + mymodule = (PingPong*)pClass; + + mymodule->m_bReverseState = bOn; + + // recalc delay offsets when going back to forward mode + if( !mymodule->m_bReverseState ) + { + delay = mymodule->params[ PingPong::PARAM_DELAYL ].value * MAC_DELAY_SECONDS * engineGetSampleRate(); + mymodule->m_DelayOut[ L ] = ( mymodule->m_DelayIn - (int)delay ) & 0x7FFFF; + + delay = mymodule->params[ PingPong::PARAM_DELAYR ].value * MAC_DELAY_SECONDS * engineGetSampleRate(); + mymodule->m_DelayOut[ R ] = ( mymodule->m_DelayIn - (int)delay ) & 0x7FFFF; + } +} + +//----------------------------------------------------- +// MyEQHi_Knob +//----------------------------------------------------- +struct MyCutoffKnob : Knob_Green1_40 +{ + PingPong *mymodule; + + void onChange( EventChange &e ) override + { + mymodule = (PingPong*)module; + + if( mymodule ) + { + mymodule->ChangeFilterCutoff( value ); + } + + RoundKnob::onChange( e ); + } +}; + +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- +#define Y_OFF_H 40 +#define X_OFF_W 40 + +struct PingPong_Widget : ModuleWidget { + PingPong_Widget( PingPong *module ); +}; + +PingPong_Widget::PingPong_Widget( PingPong *module ) : ModuleWidget(module) +{ + box.size = Vec( 15*8, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/PingPong.svg"))); + addChild(panel); + } + + //module->lg.Open("PingPong.txt"); + + // sync clock + addInput(Port::create( Vec( 10, 110 ), Port::INPUT, module, PingPong::INPUT_SYNC ) ); + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + // Filter/Res knobs + addParam(ParamWidget::create( Vec( 66, 55 ), module, PingPong::PARAM_FILTER_MODE, 0.0, 4.0, 0.0 ) ); + addParam(ParamWidget::create( Vec( 23, 60 ), module, PingPong::PARAM_CUTOFF, 0.0, 1.0, 0.0 ) ); + addParam(ParamWidget::create( Vec( 73, 79 ), module, PingPong::PARAM_Q, 0.0, 1.0, 0.0 ) ); + + // L Feedback + addParam(ParamWidget::create( Vec( 49, 110 ), module, PingPong::PARAM_LEVEL_FB_LL, 0.0, 1.0, 0.0 ) ); + + // Left + addInput(Port::create( Vec( 10, 154 ), Port::INPUT, module, PingPong::INPUT_L ) ); + addParam(ParamWidget::create( Vec( 38, 143 ), module, PingPong::PARAM_DELAYL, 0.0, 1.0, 0.0 ) ); + addOutput(Port::create( Vec( 90, 154 ), Port::OUTPUT, module, PingPong::OUT_L ) ); + + // R to L level and L to R levels + addParam(ParamWidget::create( Vec( 9, 191 ), module, PingPong::PARAM_LEVEL_FB_RL, 0.0, 1.0, 0.0 ) ); + addParam(ParamWidget::create( Vec( 9, 226 ), module, PingPong::PARAM_LEVEL_FB_LR, 0.0, 1.0, 0.0 ) ); + + // mix knob + addParam(ParamWidget::create( Vec( 77, 199 ), module, PingPong::PARAM_MIX, 0.0, 1.0, 0.0 ) ); + + // Left + addInput(Port::create( Vec( 10, 266 ), Port::INPUT, module, PingPong::INPUT_R ) ); + addParam(ParamWidget::create( Vec( 38, 255 ), module, PingPong::PARAM_DELAYR, 0.0, 1.0, 0.0 ) ); + addOutput(Port::create( Vec( 90, 266 ), Port::OUTPUT, module, PingPong::OUT_R ) ); + + // R Feedback + addParam(ParamWidget::create( Vec( 49, 308 ), module, PingPong::PARAM_LEVEL_FB_RR, 0.0, 1.0, 0.0 ) ); + + // reverse button + module->m_pButtonReverse = new MyLEDButton( 17, 343, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButton::TYPE_SWITCH, 0, module, PingPong_Reverse ); + addChild( module->m_pButtonReverse ); + + module->m_bInitialized = true; +} + +//----------------------------------------------------- +// Procedure: reset +// +//----------------------------------------------------- +void PingPong::onReset() +{ + if( !m_bInitialized ) + return; + + m_pButtonReverse->Set( false ); + m_bReverseState = false; +} + +//----------------------------------------------------- +// Procedure: randomize +// +//----------------------------------------------------- +void PingPong::onRandomize() +{ +} + +//----------------------------------------------------- +// Procedure: +// +//----------------------------------------------------- +json_t *PingPong::toJson() +{ + json_t *rootJ = json_object(); + + // reverse state + json_object_set_new(rootJ, "ReverseState", json_boolean (m_bReverseState)); + + return rootJ; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void PingPong::fromJson(json_t *rootJ) +{ + // reverse state + json_t *revJ = json_object_get(rootJ, "ReverseState"); + + if (revJ) + m_bReverseState = json_is_true( revJ ); + + m_pButtonReverse->Set( m_bReverseState ); +} + +//----------------------------------------------------- +// Procedure: ChangeFilterCutoff +// +//----------------------------------------------------- +void PingPong::ChangeFilterCutoff( float cutfreq ) +{ + float fx, fx2, fx3, fx5, fx7; + + // clamp at 1.0 and 20/samplerate + cutfreq = fmax(cutfreq, 20 / engineGetSampleRate()); + cutfreq = fmin(cutfreq, 1.0); + + // calculate eq rez freq + fx = 3.141592 * (cutfreq * 0.026315789473684210526315789473684) * 2 * 3.141592; + fx2 = fx*fx; + fx3 = fx2*fx; + fx5 = fx3*fx2; + fx7 = fx5*fx2; + + m_fCutoff = 2.0 * (fx + - (fx3 * 0.16666666666666666666666666666667) + + (fx5 * 0.0083333333333333333333333333333333) + - (fx7 * 0.0001984126984126984126984126984127)); +} + +//----------------------------------------------------- +// Procedure: Filter +// +//----------------------------------------------------- +#define MULTI (0.33333333333333333333333333333333f) +float PingPong::Filter( int ch, float in ) +{ + FILTER_PARAM_STRUCT *p; + float rez, hp1, out = 0.0; + float lowpass, highpass, bandpass; + + if( (int)params[ PARAM_FILTER_MODE ].value == 0 ) + return in; + + p = &m_Filter[ ch ]; + + rez = 1.0 - params[ PARAM_Q ].value; + + in = in + 0.000000001; + + p->lp1 = p->lp1 + m_fCutoff * p->bp1; + hp1 = in - p->lp1 - rez * p->bp1; + p->bp1 = m_fCutoff * hp1 + p->bp1; + lowpass = p->lp1; + highpass = hp1; + bandpass = p->bp1; + + p->lp1 = p->lp1 + m_fCutoff * p->bp1; + hp1 = in - p->lp1 - rez * p->bp1; + p->bp1 = m_fCutoff * hp1 + p->bp1; + lowpass = lowpass + p->lp1; + highpass = highpass + hp1; + bandpass = bandpass + p->bp1; + + in = in - 0.000000001; + + p->lp1 = p->lp1 + m_fCutoff * p->bp1; + hp1 = in - p->lp1 - rez * p->bp1; + p->bp1 = m_fCutoff * hp1 + p->bp1; + + lowpass = (lowpass + p->lp1) * MULTI; + highpass = (highpass + hp1) * MULTI; + bandpass = (bandpass + p->bp1) * MULTI; + + switch( (int)params[ PARAM_FILTER_MODE ].value ) + { + case FILTER_LP: + out = lowpass; + break; + case FILTER_HP: + out = highpass; + break; + case FILTER_BP: + out = bandpass; + break; + case FILTER_NT: + out = lowpass + highpass; + break; + default: + break; + } + + return out; +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +float syncQuant[ 10 ] = { 0.125, 0.25, 0.333, 0.375, 0.5, 0.625, 0.666, 0.750, 0.875, 1.0 }; +void PingPong::step() +{ + float outL, outR, inL = 0.0, inR = 0.0, inOrigL = 0.0, inOrigR = 0.0, syncq = 0.0; + bool bMono = false; + int i, dR, dL; + + if( !m_bInitialized ) + return; + + dL = params[ PARAM_DELAYL ].value * MAC_DELAY_SECONDS * engineGetSampleRate(); + dR = params[ PARAM_DELAYR ].value * MAC_DELAY_SECONDS * engineGetSampleRate(); + + // check right channel first for possible mono + if( inputs[ INPUT_SYNC ].active ) + { + m_SyncCount++; + + // sync'd delay + if( m_SchmittSync.process( inputs[ INPUT_SYNC ].value ) ) + { + if( !m_bWasSynced || ( (m_SyncTime / 10) != (m_SyncCount / 10) ) || ( m_LastDelayKnob[ L ] != dL ) || ( m_LastDelayKnob[ R ] != dR ) ) + { + m_SyncTime = m_SyncCount; + + for( i = 0; i < 10; i++ ) + { + if( params[ PARAM_DELAYL ].value <= syncQuant[ i ] ) + { + syncq = syncQuant[ i ] * MAC_DELAY_SECONDS; + break; + } + } + + m_DelayOut[ L ] = ( m_DelayIn - (int)(syncq * m_SyncTime) ) & 0x7FFFF; + + for( i = 0; i < 10; i++ ) + { + if( params[ PARAM_DELAYR ].value <= syncQuant[ i ] ) + { + syncq = syncQuant[ i ] * MAC_DELAY_SECONDS; + break; + } + } + + m_DelayOut[ R ] = ( m_DelayIn - (int)(syncq * m_SyncTime) ) & 0x7FFFF; + } + + m_SyncCount = 0; + } + + m_bWasSynced = true; + } + else + { + // non sync'd delay + if( m_bWasSynced || ( m_LastDelayKnob[ L ] != dL ) ) + m_DelayOut[ L ] = ( m_DelayIn - (int)dL ) & 0x7FFFF; + + if( m_bWasSynced || ( m_LastDelayKnob[ R ] != dR ) ) + m_DelayOut[ R ] = ( m_DelayIn - (int)dR ) & 0x7FFFF; + + m_bWasSynced = false; + m_SyncCount = 0; + } + + m_LastDelayKnob[ L ] = dL; + m_LastDelayKnob[ R ] = dR; + + // check right channel first for possible mono + if( inputs[ INPUT_R ].active ) + { + inR = clamp( inputs[ INPUT_R ].value / AUDIO_MAX, -1.0f, 1.0f ); + inR = Filter( R, inR ); + inOrigR = inR; + bMono = false; + } + else + bMono = true; + + // left channel + if( inputs[ INPUT_L ].active ) + { + inL = clamp( inputs[ INPUT_L ].value / AUDIO_MAX, -1.0f, 1.0f ); + inL = Filter( L, inL ); + inOrigL = inL; + + if( bMono ) + { + inOrigR = inL; + inR = inL; + } + } + + m_DelayBuffer[ L ][ m_DelayIn ] = inL + ( m_LastOut[ L ] * params[ PARAM_LEVEL_FB_LL ].value ) + ( m_LastOut[ R ] * params[ PARAM_LEVEL_FB_RL ].value ); + m_DelayBuffer[ R ][ m_DelayIn ] = inR + ( m_LastOut[ R ] * params[ PARAM_LEVEL_FB_RR ].value ) + ( m_LastOut[ L ] * params[ PARAM_LEVEL_FB_LR ].value ); + + m_DelayIn = ( ( m_DelayIn + 1 ) & 0x7FFFF ); + + outL = m_DelayBuffer[ L ][ m_DelayOut[ L ] ]; + outR = m_DelayBuffer[ R ][ m_DelayOut[ R ] ]; + + if( m_bReverseState ) + { + m_DelayOut[ L ] = ( ( m_DelayOut[ L ] - 1 ) & 0x7FFFF ); + m_DelayOut[ R ] = ( ( m_DelayOut[ R ] - 1 ) & 0x7FFFF ); + } + else + { + m_DelayOut[ L ] = ( ( m_DelayOut[ L ] + 1 ) & 0x7FFFF ); + m_DelayOut[ R ] = ( ( m_DelayOut[ R ] + 1 ) & 0x7FFFF ); + } + + m_LastOut[ L ] = outL; + m_LastOut[ R ] = outR; + + // output + outputs[ OUT_L ].value = clamp( ( inOrigL * ( 1.0f - params[ PARAM_MIX ].value ) ) + ( (outL * AUDIO_MAX) * params[ PARAM_MIX ].value ), -AUDIO_MAX, AUDIO_MAX ); + outputs[ OUT_R ].value = clamp( ( inOrigR * ( 1.0f - params[ PARAM_MIX ].value ) ) + ( (outR * AUDIO_MAX) * params[ PARAM_MIX ].value ), -AUDIO_MAX, AUDIO_MAX ); +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, PingPong) { + Model *modelPingPong = Model::create("mscHack", "PingPong_Widget", "DELAY Ping Pong", DELAY_TAG, PANNING_TAG); + return modelPingPong; +} diff --git a/plugins/community/repos/mscHack/src/SEQ_6x32x16.cpp b/plugins/community/repos/mscHack/src/SEQ_6x32x16.cpp new file mode 100644 index 00000000..97c7b66c --- /dev/null +++ b/plugins/community/repos/mscHack/src/SEQ_6x32x16.cpp @@ -0,0 +1,775 @@ +#include "mscHack.hpp" +//#include "mscHack_Controls.hpp" +#include "dsp/digital.hpp" +//#include "CLog.h" + +namespace rack_plugin_mscHack { + +#define nCHANNELS 6 +#define nSTEPS 32 +#define nPROG 16 + +typedef struct +{ + bool bPending; + int prog; +}PHRASE_CHANGE_STRUCT; + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct SEQ_6x32x16 : Module +{ +#define NO_COPY -1 + + enum ParamIds + { + PARAM_CPY_NEXT, + PARAM_RAND = PARAM_CPY_NEXT + nCHANNELS, + PARAM_PAUSE = PARAM_RAND + nCHANNELS, + PARAM_BILEVEL = PARAM_PAUSE + nCHANNELS, + PARAM_LVL1_KNOB = PARAM_BILEVEL + nCHANNELS, + PARAM_LVL2_KNOB = PARAM_LVL1_KNOB + nCHANNELS, + PARAM_LVL3_KNOB = PARAM_LVL2_KNOB + nCHANNELS, + PARAM_LVL4_KNOB = PARAM_LVL3_KNOB + nCHANNELS, + PARAM_LVL5_KNOB = PARAM_LVL4_KNOB + nCHANNELS, + nPARAMS = PARAM_LVL5_KNOB + nCHANNELS + }; + + enum InputIds + { + IN_GLOBAL_CLK_RESET, + IN_GLOBAL_PAT_CHANGE, + IN_CLK, + IN_PAT_TRIG = IN_CLK + nCHANNELS, + nINPUTS = IN_PAT_TRIG + nCHANNELS + }; + + enum OutputIds + { + OUT_TRIG, + OUT_LEVEL = OUT_TRIG + nCHANNELS, + OUT_BEAT1 = OUT_LEVEL + nCHANNELS, + nOUTPUTS = OUT_BEAT1 + nCHANNELS + }; + + bool m_bInitialized = false; + CLog lg; + + bool m_bPauseState[ nCHANNELS ] = {}; + bool m_bBiLevelState[ nCHANNELS ] = {}; + + SinglePatternClocked32 *m_pPatternDisplay[ nCHANNELS ] = {}; + int m_Pattern[ nCHANNELS ][ nPROG ][ nSTEPS ]; + int m_MaxPat[ nCHANNELS ][ nPROG ] = {}; + + PatternSelectStrip *m_pProgramDisplay[ nCHANNELS ] = {}; + int m_CurrentProg[ nCHANNELS ] = {}; + int m_MaxProg[ nCHANNELS ] = {}; + PHRASE_CHANGE_STRUCT m_ProgPending[ nCHANNELS ] = {}; + + SchmittTrigger m_SchTrigClock[ nCHANNELS ]; + SchmittTrigger m_SchTrigProg[ nCHANNELS ]; + SchmittTrigger m_SchTrigGlobalClkReset; + SchmittTrigger m_SchTrigGlobalProg; + + bool m_bTrig[ nCHANNELS ] = {}; + PulseGenerator m_gatePulse[ nCHANNELS ]; + PulseGenerator m_gateBeatPulse[ nCHANNELS ]; + + // swing + //int m_SwingLen[ nCHANNELS ] = {0}; + //int m_SwingCount[ nCHANNELS ] = {0}; + int m_ClockTick[ nCHANNELS ] = {0}; + + int m_CopySrc = NO_COPY; + + // buttons + MyLEDButton *m_pButtonPause[ nCHANNELS ] = {}; + MyLEDButton *m_pButtonCopy[ nCHANNELS ] = {}; + MyLEDButton *m_pButtonBiLevel[ nCHANNELS ] = {}; + MyLEDButton *m_pButtonRand[ nCHANNELS ] = {}; + MyLEDButton *m_pButtonAutoPat[ nCHANNELS ] = {}; + MyLEDButton *m_pButtonHoldCV[ nCHANNELS ] = {}; + MyLEDButton *m_pButtonClear[ nCHANNELS ] = {}; + + bool m_bAutoPatChange[ nCHANNELS ] = {}; + bool m_bHoldCVState[ nCHANNELS ] = {}; + + float m_fCVRanges[ 3 ] = { 15.0f, 10.0f, 5.0f}; + int m_RangeSelect = 0; + char m_strRange[ 10 ] = {0}; + + // Contructor + SEQ_6x32x16() : Module(nPARAMS, nINPUTS, nOUTPUTS, 0){} + + // Overrides + void step() override; + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onRandomize() override; + void onReset() override; + + void JsonParams( bool bTo, json_t *root); + void CpyNext( int ch ); + void Rand( int ch ); + void ChangeProg( int ch, int prog, bool force ); + void SetPendingProg( int ch, int prog ); + void Copy( int kb, bool bOn ); +}; + +//----------------------------------------------------- +// MyLEDButton_AutoPat +//----------------------------------------------------- +void MyLEDButton_AutoPat( void *pClass, int id, bool bOn ) +{ + SEQ_6x32x16 *mymodule; + mymodule = (SEQ_6x32x16*)pClass; + mymodule->m_bAutoPatChange[ id ] = bOn; +} + +//----------------------------------------------------- +// MyLEDButton_Pause +//----------------------------------------------------- +void MyLEDButton_Pause( void *pClass, int id, bool bOn ) +{ + SEQ_6x32x16 *mymodule; + mymodule = (SEQ_6x32x16*)pClass; + mymodule->m_bPauseState[ id ] = bOn; +} + +//----------------------------------------------------- +// MyLEDButton_HoldCV +//----------------------------------------------------- +void MyLEDButton_HoldCV( void *pClass, int id, bool bOn ) +{ + SEQ_6x32x16 *mymodule; + mymodule = (SEQ_6x32x16*)pClass; + mymodule->m_bHoldCVState[ id ] = bOn; +} + +//----------------------------------------------------- +// MyLEDButton_BiLevel +//----------------------------------------------------- +void MyLEDButton_BiLevel( void *pClass, int id, bool bOn ) +{ + SEQ_6x32x16 *mymodule; + mymodule = (SEQ_6x32x16*)pClass; + mymodule->m_bBiLevelState[ id ] = bOn; +} + +//----------------------------------------------------- +// MyLEDButton_CpyNxt +//----------------------------------------------------- +void MyLEDButton_CpyNxt( void *pClass, int id, bool bOn ) +{ + SEQ_6x32x16 *mymodule; + mymodule = (SEQ_6x32x16*)pClass; + mymodule->Copy( id, bOn ); +} + +//----------------------------------------------------- +// MyLEDButton_Rand +//----------------------------------------------------- +void MyLEDButton_Rand( void *pClass, int id, bool bOn ) +{ + SEQ_6x32x16 *mymodule; + mymodule = (SEQ_6x32x16*)pClass; + mymodule->Rand( id ); +} + +//----------------------------------------------------- +// MyLEDButton_Rand +//----------------------------------------------------- +void MyLEDButton_Clear( void *pClass, int id, bool bOn ) +{ + SEQ_6x32x16 *mymodule; + mymodule = (SEQ_6x32x16*)pClass; + + for( int i = 0; i < nSTEPS; i++ ) + { + mymodule->m_Pattern[ id ][ mymodule->m_CurrentProg[ id ] ][ i ] = 0; + } + + mymodule->m_pPatternDisplay[ id ]->SetPatAll( mymodule->m_Pattern[ id ][ mymodule->m_CurrentProg[ id ] ] ); +} + +//----------------------------------------------------- +// Procedure: PatternChangeCallback +// +//----------------------------------------------------- +void SEQ_6x32x16_PatternChangeCallback ( void *pClass, int ch, int pat, int level, int maxpat ) +{ + SEQ_6x32x16 *mymodule = (SEQ_6x32x16 *)pClass; + + if( !mymodule || !mymodule->m_bInitialized ) + return; + + mymodule->m_MaxPat[ ch ][ mymodule->m_CurrentProg[ ch ] ] = maxpat; + mymodule->m_Pattern[ ch ][ mymodule->m_CurrentProg[ ch ] ] [ pat ] = level; +} + +//----------------------------------------------------- +// Procedure: ProgramChangeCallback +// +//----------------------------------------------------- +void SEQ_6x32x16_ProgramChangeCallback ( void *pClass, int ch, int pat, int max ) +{ + SEQ_6x32x16 *mymodule = (SEQ_6x32x16 *)pClass; + + if( !mymodule || !mymodule->m_bInitialized ) + return; + + if( mymodule->m_MaxProg[ ch ] != max ) + { + mymodule->m_MaxProg[ ch ] = max; + } + else if( mymodule->m_CurrentProg[ ch ] == pat && mymodule->m_bPauseState[ ch ] && mymodule->m_CopySrc != NO_COPY ) + { + mymodule->ChangeProg( ch, pat, true ); + } + else if( mymodule->m_CurrentProg[ ch ] != pat ) + { + if( !mymodule->m_bPauseState[ ch ] && mymodule->inputs[ SEQ_6x32x16::IN_CLK + ch ].active ) + mymodule->SetPendingProg( ch, pat ); + else + mymodule->ChangeProg( ch, pat, false ); + } +} + +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- + +struct SEQ_6x32x16_Widget : ModuleWidget +{ + Menu *createContextMenu() override; + SEQ_6x32x16_Widget( SEQ_6x32x16 *module ); +}; + +SEQ_6x32x16_Widget::SEQ_6x32x16_Widget( SEQ_6x32x16 *module ) : ModuleWidget(module) +{ + int x, y, x2, y2; + ParamWidget *pWidget = NULL; + + box.size = Vec( 15*41, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/SEQ_6x32x16.svg"))); + addChild(panel); + } + + //module->lg.Open("SEQ_6x32x16.txt"); + + x = 7; + y = 22; + + // global inputs + addInput(Port::create( Vec( 204, 357 ), Port::INPUT, module, SEQ_6x32x16::IN_GLOBAL_CLK_RESET ) ); + addInput(Port::create( Vec( 90, 357 ), Port::INPUT, module, SEQ_6x32x16::IN_GLOBAL_PAT_CHANGE ) ); + + for( int ch = 0; ch < nCHANNELS; ch++ ) + { + // inputs + addInput(Port::create( Vec( x + 6, y + 7 ), Port::INPUT, module, SEQ_6x32x16::IN_CLK + ch ) ); + addInput(Port::create( Vec( x + 64, y + 31 ), Port::INPUT, module, SEQ_6x32x16::IN_PAT_TRIG + ch ) ); + + // pattern display + module->m_pPatternDisplay[ ch ] = new SinglePatternClocked32( x + 39, y + 2, 13, 13, 5, 2, 7, DWRGB( 255, 128, 64 ), DWRGB( 18, 9, 0 ), DWRGB( 180, 75, 180 ), DWRGB( 80, 45, 80 ), nSTEPS, ch, module, SEQ_6x32x16_PatternChangeCallback ); + addChild( module->m_pPatternDisplay[ ch ] ); + + // program display + module->m_pProgramDisplay[ ch ] = new PatternSelectStrip( x + 106, y + 31, 9, 7, DWRGB( 180, 180, 0 ), DWRGB( 90, 90, 64 ), DWRGB( 0, 180, 200 ), DWRGB( 0, 90, 90 ), nPROG, ch, module, SEQ_6x32x16_ProgramChangeCallback ); + addChild( module->m_pProgramDisplay[ ch ] ); + + // add knobs + y2 = y + 34; + //pWidget = ParamWidget::create( Vec( x + 374, y2 ), module, SEQ_6x32x16::PARAM_SWING_KNOB + ch, 0.0, 0.6, 0.0 ); + + // removed for now + if( pWidget ) + { + addParam( pWidget ); + pWidget->visible = false; + } + + x2 = x + 447; + addParam(ParamWidget::create( Vec( x2, y2 ), module, SEQ_6x32x16::PARAM_LVL1_KNOB + ch, 0.0, 1.0, 0.25 ) ); x2 += 19; + addParam(ParamWidget::create( Vec( x2, y2 ), module, SEQ_6x32x16::PARAM_LVL2_KNOB + ch, 0.0, 1.0, 0.33 ) ); x2 += 19; + addParam(ParamWidget::create( Vec( x2, y2 ), module, SEQ_6x32x16::PARAM_LVL3_KNOB + ch, 0.0, 1.0, 0.50 ) ); x2 += 19; + addParam(ParamWidget::create( Vec( x2, y2 ), module, SEQ_6x32x16::PARAM_LVL4_KNOB + ch, 0.0, 1.0, 0.75 ) ); x2 += 19; + addParam(ParamWidget::create( Vec( x2, y2 ), module, SEQ_6x32x16::PARAM_LVL5_KNOB + ch, 0.0, 1.0, 0.9 ) ); + + // add buttons + module->m_pButtonAutoPat[ ch ] = new MyLEDButton( x + 55, y + 35, 9, 9, 6.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 0 ), MyLEDButton::TYPE_SWITCH, ch, module, MyLEDButton_AutoPat ); + addChild( module->m_pButtonAutoPat[ ch ] ); + + module->m_pButtonPause[ ch ] = new MyLEDButton( x + 26, y + 10, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, ch, module, MyLEDButton_Pause ); + addChild( module->m_pButtonPause[ ch ] ); + + y2 = y + 33; + module->m_pButtonCopy[ ch ] = new MyLEDButton( x + 290, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 244, 244 ), MyLEDButton::TYPE_SWITCH, ch, module, MyLEDButton_CpyNxt ); + addChild( module->m_pButtonCopy[ ch ] ); + + module->m_pButtonRand[ ch ] = new MyLEDButton( x + 315, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 244, 244 ), MyLEDButton::TYPE_MOMENTARY, ch, module, MyLEDButton_Rand ); + addChild( module->m_pButtonRand[ ch ] ); + + module->m_pButtonClear[ ch ] = new MyLEDButton( x + 340, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 244, 244 ), MyLEDButton::TYPE_MOMENTARY, ch, module, MyLEDButton_Clear ); + addChild( module->m_pButtonClear[ ch ] ); + + module->m_pButtonHoldCV[ ch ] = new MyLEDButton( x + 405, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 244, 244 ), MyLEDButton::TYPE_SWITCH, ch, module, MyLEDButton_HoldCV ); + addChild( module->m_pButtonHoldCV[ ch ] ); + + module->m_pButtonBiLevel[ ch ] = new MyLEDButton( x + 425, y2, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 244, 244 ), MyLEDButton::TYPE_SWITCH, ch, module, MyLEDButton_BiLevel ); + addChild( module->m_pButtonBiLevel[ ch ] ); + + // add outputs + addOutput(Port::create( Vec( x + 580, y + 7 ), Port::OUTPUT, module, SEQ_6x32x16::OUT_TRIG + ch ) ); + addOutput(Port::create( Vec( x + 544, y + 33 ), Port::OUTPUT, module, SEQ_6x32x16::OUT_LEVEL + ch ) ); + addOutput(Port::create( Vec( x + 37, y + 31 ), Port::OUTPUT, module, SEQ_6x32x16::OUT_BEAT1 + ch ) ); + + y += 56; + } + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + module->m_bInitialized = true; + + module->onReset(); +} + +//----------------------------------------------------- +// Procedure: JsonParams +// +//----------------------------------------------------- +void SEQ_6x32x16::JsonParams( bool bTo, json_t *root) +{ + JsonDataBool ( bTo, "m_bPauseState", root, &m_bPauseState[ 0 ], nCHANNELS ); + JsonDataBool ( bTo, "m_bBiLevelState", root, &m_bBiLevelState[ 0 ], nCHANNELS ); + JsonDataInt ( bTo, "m_Pattern", root, &m_Pattern[ 0 ][ 0 ][ 0 ], nCHANNELS * nSTEPS * nPROG ); + JsonDataInt ( bTo, "m_MaxPat", root, &m_MaxPat[ 0 ][ 0 ], nCHANNELS * nPROG ); + JsonDataInt ( bTo, "m_CurrentProg", root, &m_CurrentProg[ 0 ], nCHANNELS ); + JsonDataInt ( bTo, "m_MaxProg", root, &m_MaxProg[ 0 ], nCHANNELS ); + JsonDataBool ( bTo, "m_bAutoPatChange", root, &m_bAutoPatChange[ 0 ], nCHANNELS ); + JsonDataBool ( bTo, "m_bHoldCVState", root, &m_bHoldCVState[ 0 ], nCHANNELS ); + JsonDataInt ( bTo, "m_RangeSelect", root, &m_RangeSelect, 1 ); +} + +//----------------------------------------------------- +// Procedure: toJson +// +//----------------------------------------------------- +json_t *SEQ_6x32x16::toJson() +{ + json_t *root = json_object(); + + if( !root ) + return NULL; + + JsonParams( TOJSON, root ); + + return root; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void SEQ_6x32x16::fromJson( json_t *root ) +{ + JsonParams( FROMJSON, root ); + + for( int ch = 0; ch < nCHANNELS; ch++ ) + { + m_pButtonAutoPat[ ch ]->Set( m_bAutoPatChange[ ch ] ); + m_pButtonPause[ ch ]->Set( m_bPauseState[ ch ] ); + m_pButtonBiLevel[ ch ]->Set( m_bBiLevelState[ ch ] ); + m_pButtonHoldCV[ ch ]->Set( m_bHoldCVState[ ch ] ); + + m_pPatternDisplay[ ch ]->SetPatAll( m_Pattern[ ch ][ m_CurrentProg[ ch ] ] ); + m_pPatternDisplay[ ch ]->SetMax( m_MaxPat[ ch ][ m_CurrentProg[ ch ] ] ); + + m_pProgramDisplay[ ch ]->SetPat( m_CurrentProg[ ch ], false ); + m_pProgramDisplay[ ch ]->SetMax( m_MaxProg[ ch ] ); + } + + sprintf( m_strRange, "%.1fV", m_fCVRanges[ m_RangeSelect ] ); +} + +//----------------------------------------------------- +// Procedure: reset +// +//----------------------------------------------------- +void SEQ_6x32x16::onReset() +{ + if( !m_bInitialized ) + return; + + for( int ch = 0; ch < nCHANNELS; ch++ ) + { + m_pButtonPause[ ch ]->Set( false ); + m_pButtonBiLevel[ ch ]->Set( false ); + } + + memset( m_bPauseState, 0, sizeof(m_bPauseState) ); + memset( m_bBiLevelState, 0, sizeof(m_bBiLevelState) ); + memset( m_Pattern, 0, sizeof(m_Pattern) ); + memset( m_CurrentProg, 0, sizeof(m_CurrentProg) ); + + for( int ch = 0; ch < nCHANNELS; ch++ ) + { + for( int prog = 0; prog < nCHANNELS; prog++ ) + m_MaxPat[ ch ][ prog ] = nSTEPS - 1; + + m_MaxProg[ ch ] = nPROG - 1; + + m_pPatternDisplay[ ch ]->SetPatAll( m_Pattern[ ch ][ 0 ] ); + m_pPatternDisplay[ ch ]->SetMax( m_MaxPat[ ch ][ 0 ] ); + + m_pProgramDisplay[ ch ]->SetPat( 0, false ); + m_pProgramDisplay[ ch ]->SetMax( m_MaxProg[ ch ] ); + + m_pPatternDisplay[ ch ]->SetPatAll( m_Pattern[ ch ][ m_CurrentProg[ ch ] ] ); + + ChangeProg( ch, 0, true ); + } +} + +//----------------------------------------------------- +// Procedure: randomize +// +//----------------------------------------------------- +void SEQ_6x32x16::onRandomize() +{ + for( int ch = 0; ch < nCHANNELS; ch++ ) + { + for( int p = 0; p < nPROG; p++ ) + { + for( int i = 0; i < nSTEPS; i++ ) + { + m_Pattern[ ch ][ p ][ i ] = (int)(randomUniform() * 5.0 ); + } + } + + m_pPatternDisplay[ ch ]->SetPatAll( m_Pattern[ ch ][ m_CurrentProg[ ch ] ] ); + } +} + +//----------------------------------------------------- +// Procedure: Rand +// +//----------------------------------------------------- +void SEQ_6x32x16::Rand( int ch ) +{ + for( int i = 0; i < nSTEPS; i++ ) + { + if( i <= m_MaxPat[ ch ][ m_CurrentProg[ ch ] ] && randomUniform() > 0.5f ) + m_Pattern[ ch ][ m_CurrentProg[ ch ] ][ i ] = (int)(randomUniform() * 5.0 ); + else + m_Pattern[ ch ][ m_CurrentProg[ ch ] ][ i ] = 0; + } + + m_pPatternDisplay[ ch ]->SetPatAll( m_Pattern[ ch ][ m_CurrentProg[ ch ] ] ); +} + +//----------------------------------------------------- +// Procedure: CpyNext +// +//----------------------------------------------------- +void SEQ_6x32x16::CpyNext( int ch ) +{ + int next; + + next = m_CurrentProg[ ch ] + 1; + + if( next >= nPROG ) + return; + + memcpy( m_Pattern[ ch ][ next ], m_Pattern[ ch ][ m_CurrentProg[ ch ] ], sizeof(int) * nSTEPS ); + + if(m_bPauseState[ ch ] || !inputs[ SEQ_6x32x16::IN_CLK + ch ].active ) + ChangeProg( ch, next, false ); +} + +//----------------------------------------------------- +// Procedure: Copy +// +//----------------------------------------------------- +void SEQ_6x32x16::Copy( int ch, bool bOn ) +{ + if( !m_bPauseState[ ch ] || !bOn || m_CopySrc != NO_COPY ) + { + if( m_CopySrc != NO_COPY ) + m_pButtonCopy[ m_CopySrc ]->Set( false ); + + m_CopySrc = NO_COPY; + m_pButtonCopy[ ch ]->Set( false ); + } + else if( bOn ) + { + m_CopySrc = ch; + } +} + +//----------------------------------------------------- +// Procedure: ChangProg +// +//----------------------------------------------------- +void SEQ_6x32x16::ChangeProg( int ch, int prog, bool bforce ) +{ + if( ch < 0 || ch >= nCHANNELS ) + return; + + if( !bforce && prog == m_CurrentProg[ ch ] ) + return; + + if( prog < 0 ) + prog = nPROG - 1; + else if( prog >= nPROG ) + prog = 0; + + if( m_CopySrc != NO_COPY ) + { + if( m_bPauseState[ ch ] ) + { + memcpy( m_Pattern[ ch ][ prog ], m_Pattern[ m_CopySrc ][ m_CurrentProg[ m_CopySrc ] ], sizeof(int) * nSTEPS ); + m_pButtonCopy[ m_CopySrc ]->Set( false ); + m_MaxPat[ ch ][ prog ] = m_MaxPat[ m_CopySrc ][ m_CurrentProg[ m_CopySrc ] ]; + m_CopySrc = NO_COPY; + } + } + + m_CurrentProg[ ch ] = prog; + + m_pPatternDisplay[ ch ]->SetPatAll( m_Pattern[ ch ][ prog ] ); + m_pPatternDisplay[ ch ]->SetMax( m_MaxPat[ ch ][ prog ] ); + m_pProgramDisplay[ ch ]->SetPat( prog, false ); +} + +//----------------------------------------------------- +// Procedure: SetPendingProg +// +//----------------------------------------------------- +void SEQ_6x32x16::SetPendingProg( int ch, int progIn ) +{ + int prog; + + if( progIn < 0 || progIn >= nPROG ) + prog = ( m_CurrentProg[ ch ] + 1 ) & 0xF; + else + prog = progIn; + + if( prog > m_MaxProg[ ch ] ) + prog = 0; + + m_ProgPending[ ch ].bPending = true; + m_ProgPending[ ch ].prog = prog; + m_pProgramDisplay[ ch ]->SetPat( m_CurrentProg[ ch ], false ); + m_pProgramDisplay[ ch ]->SetPat( prog, true ); +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +void SEQ_6x32x16::step() +{ + int ch, level, useclock; + bool bClk, bClkTrig, bClockAtZero = false, bGlobalClk = false, bGlobalProg = false, bTrigOut, bPatTrig[ nCHANNELS ] = {}; + float fout = 0.0; + + if( !m_bInitialized ) + return; + + if( inputs[ IN_GLOBAL_CLK_RESET ].active ) + bGlobalClk = m_SchTrigGlobalClkReset.process( inputs[ IN_GLOBAL_CLK_RESET ].value ); + + if( inputs[ IN_GLOBAL_PAT_CHANGE ].active ) + bGlobalProg= m_SchTrigGlobalProg.process( inputs[ IN_GLOBAL_PAT_CHANGE ].value ); + + // get trigs + for( ch = 0; ch < nCHANNELS; ch++ ) + bPatTrig[ ch ] = m_SchTrigClock[ ch ].process( inputs[ IN_CLK + ch ].normalize( 0.0f ) ); + + for( ch = 0; ch < nCHANNELS; ch++ ) + { + bClkTrig = false; + bClk = false; + bTrigOut = false; + bClockAtZero = false; + useclock = ch; + + // if no keyboard clock active then use kb 0's clock + if( !inputs[ IN_CLK + ch ].active && inputs[ IN_CLK + 0 ].active ) + useclock = 0; + + if( inputs[ IN_CLK + useclock ].active ) + { + // time the clock tick + if( bGlobalClk ) + { + m_pPatternDisplay[ ch ]->ClockReset(); + bClkTrig = true; + bClockAtZero = true; + bClk = true; + } + + // clock + if( bPatTrig[ useclock ] && !bGlobalClk ) + bClkTrig = true; + + bClk = bClkTrig; + + // clock the pattern + if( !m_bPauseState[ ch ] ) + { + if( bGlobalProg || m_SchTrigProg[ ch ].process( inputs[ IN_PAT_TRIG + ch ].value ) ) + SetPendingProg( ch, -1 ); + + // clock in + if( bClk ) + { + if( !bGlobalClk ) + bClockAtZero = m_pPatternDisplay[ ch ]->ClockInc(); + + bTrigOut = ( m_Pattern[ ch ][ m_CurrentProg[ ch ] ][ m_pPatternDisplay[ ch ]->m_PatClk ] ); + } + } + } + // no clock input + else + { + // resolve any left over phrase triggers + if( m_ProgPending[ ch ].bPending ) + { + m_ProgPending[ ch ].bPending = false; + ChangeProg( ch, m_ProgPending[ ch ].prog, true ); + } + + continue; + } + + // auto inc pattern + if( m_bAutoPatChange[ ch ] && bClockAtZero ) + { + SetPendingProg( ch, -1 ); + m_ProgPending[ ch ].bPending = false; + ChangeProg( ch, m_ProgPending[ ch ].prog, true ); + bTrigOut = ( m_Pattern[ ch ][ m_CurrentProg[ ch ] ][ m_pPatternDisplay[ ch ]->m_PatClk ] ); + } + // resolve pattern change + else if( m_ProgPending[ ch ].bPending && bClockAtZero ) + { + m_ProgPending[ ch ].bPending = false; + ChangeProg( ch, m_ProgPending[ ch ].prog, false ); + bTrigOut = ( m_Pattern[ ch ][ m_CurrentProg[ ch ] ][ m_pPatternDisplay[ ch ]->m_PatClk ] ); + } + + // trigger the beat 0 output + if( bClockAtZero ) + m_gateBeatPulse[ ch ].trigger(1e-3); + + outputs[ OUT_BEAT1 + ch ].value = m_gateBeatPulse[ ch ].process( 1.0 / engineGetSampleRate() ) ? CV_MAX : 0.0; + + // trigger out + if( bTrigOut ) + { + m_gatePulse[ ch ].trigger(1e-3); + } + + outputs[ OUT_TRIG + ch ].value = m_gatePulse[ ch ].process( 1.0 / engineGetSampleRate() ) ? CV_MAX : 0.0; + + level = m_Pattern[ ch ][ m_CurrentProg[ ch ] ][ m_pPatternDisplay[ ch ]->m_PatClk ]; + + // get actual level from knobs + switch( level ) + { + case 1: + fout = params[ PARAM_LVL1_KNOB + ch ].value; + break; + case 2: + fout = params[ PARAM_LVL2_KNOB + ch ].value; + break; + case 3: + fout = params[ PARAM_LVL3_KNOB + ch ].value; + break; + case 4: + fout = params[ PARAM_LVL4_KNOB + ch ].value; + break; + case 5: + fout = params[ PARAM_LVL5_KNOB + ch ].value; + break; + default: + if( m_bHoldCVState[ ch ] ) + continue; + else + fout = 0.0f; + } + + // bidirectional convert to -1.0 to 1.0 + if( m_bBiLevelState[ ch ] ) + fout = ( fout * 2 ) - 1.0; + + outputs[ OUT_LEVEL + ch ].value = m_fCVRanges[ m_RangeSelect ] * fout; + } +} + +//----------------------------------------------------- +// Procedure: SEQ_6x32x16_CVRange +// +//----------------------------------------------------- +struct SEQ_6x32x16_CVRange : MenuItem +{ + SEQ_6x32x16 *module; + + void onAction(EventAction &e) override + { + module->m_RangeSelect++; + + if( module->m_RangeSelect > 2 ) + module->m_RangeSelect = 0; + + sprintf( module->m_strRange, "%.1fV", module->m_fCVRanges[ module->m_RangeSelect ] ); + } + + void step() override + { + rightText = module->m_strRange; + } +}; + +//----------------------------------------------------- +// Procedure: createContextMenu +// +//----------------------------------------------------- +Menu *SEQ_6x32x16_Widget::createContextMenu() +{ + Menu *menu = ModuleWidget::createContextMenu(); + + SEQ_6x32x16 *mod = dynamic_cast(module); + + assert(mod); + + menu->addChild(construct()); + + menu->addChild(construct(&MenuLabel::text, "---- CV Output Level ----")); + menu->addChild(construct( &MenuItem::text, "VRange (15, 10, 5):", &SEQ_6x32x16_CVRange::module, mod ) ); + + return menu; +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, SEQ_6x32x16) { + Model *modelSEQ_6x32x16 = Model::create( "mscHack", "Seq_6ch_32step", "SEQ 6 x 32", SEQUENCER_TAG, MULTIPLE_TAG ); + return modelSEQ_6x32x16; +} diff --git a/plugins/community/repos/mscHack/src/SEQ_Envelope_8.cpp b/plugins/community/repos/mscHack/src/SEQ_Envelope_8.cpp new file mode 100644 index 00000000..62ec2cd4 --- /dev/null +++ b/plugins/community/repos/mscHack/src/SEQ_Envelope_8.cpp @@ -0,0 +1,724 @@ +#include "mscHack.hpp" +#include "dsp/digital.hpp" + +namespace rack_plugin_mscHack { + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct SEQ_Envelope_8 : Module +{ +#define nCHANNELS MAX_ENVELOPE_CHANNELS +#define nWAVESETS 4 +#define nTIMESETS 6 + + enum ParamIds + { + PARAM_BAND, + nPARAMS + }; + + enum InputIds + { + INPUT_CLK_RESET, + INPUT_CLK, + INPUT_GLOBAL_TRIG, + INPUT_CH_HOLD, + INPUT_CH_TRIG = INPUT_CH_HOLD + nCHANNELS, + nINPUTS = INPUT_CH_TRIG + nCHANNELS + }; + + enum OutputIds + { + OUTPUT_CV, + nOUTPUTS = OUTPUT_CV + nCHANNELS + }; + + enum LightIds + { + nLIGHTS + }; + + bool m_bInitialized = false; + + CLog lg; + + // Contructor + SEQ_Envelope_8() : Module(nPARAMS, nINPUTS, nOUTPUTS, nLIGHTS){} + + // clock + SchmittTrigger m_SchTrigClk; + + // global triggers + SchmittTrigger m_SchTrigGlobalClkReset; + SchmittTrigger m_SchTrigGlobalTrig; + + // channel triggers + SchmittTrigger m_SchTrigChTrig[ nCHANNELS ] ={}; + + int m_CurrentChannel = 0; + int m_GraphData[ nCHANNELS ][ ENVELOPE_HANDLES ] = {}; + int m_Modes[ nCHANNELS ] ={}; + int m_Ranges[ nCHANNELS ] = {}; + int m_TimeDivs[ nCHANNELS ] = {}; + bool m_bHold[ nCHANNELS ] = {}; + bool m_bGateMode[ nCHANNELS ] = {true}; + int m_HoldPos[ nCHANNELS ] = {}; + bool m_bTrig[ nCHANNELS ] = {}; + + int m_waveSet = 0; + bool m_bCpy = false; + + Widget_EnvelopeEdit *m_pEnvelope = NULL; + MyLEDButtonStrip *m_pButtonChSelect = NULL; + MyLEDButtonStrip *m_pButtonModeSelect = NULL; + MyLEDButtonStrip *m_pButtonRangeSelect = NULL; + MyLEDButtonStrip *m_pButtonTimeSelect = NULL; + MyLEDButton *m_pButtonHold[ nCHANNELS ] = {}; + MyLEDButton *m_pButtonTrig[ nCHANNELS ] = {}; + MyLEDButton *m_pButtonGateMode = NULL; + MyLEDButton *m_pButtonWaveSetBck = NULL; + MyLEDButton *m_pButtonWaveSetFwd = NULL; + MyLEDButton *m_pButtonJoinEnds = NULL; + MyLEDButton *m_pButtonGlobalReset = NULL; + MyLEDButton *m_pButtonDraw = NULL; + MyLEDButton *m_pButtonCopy = NULL; + MyLEDButton *m_pButtonRand = NULL; + MyLEDButton *m_pButtonInvert = NULL; + + Label *m_pTextLabel = NULL; + + int m_BeatCount = 0; + + //----------------------------------------------------- + // Band_Knob + //----------------------------------------------------- + struct Band_Knob : Knob_Yellow2_26 + { + SEQ_Envelope_8 *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (SEQ_Envelope_8*)module; + + if( mymodule ) + mymodule->m_pEnvelope->m_fband = value; + + RoundKnob::onChange( e ); + } + }; + + void ChangeChannel( int ch ); + + // Overrides + void step() override; + void JsonParams( bool bTo, json_t *root); + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onRandomize() override; + void onReset() override; + void onCreate() override; + void onDelete() override; +}; + +//----------------------------------------------------- +// Seq_Triad2_Pause +//----------------------------------------------------- +void EnvelopeEditCALLBACK ( void *pClass, float val ) +{ + char strVal[ 10 ] = {}; + + SEQ_Envelope_8 *mymodule; + mymodule = (SEQ_Envelope_8*)pClass; + + sprintf( strVal, "[%.3fV]", val ); + + mymodule->m_pTextLabel->text = strVal; +} + +//----------------------------------------------------- +// SEQ_Envelope_8_DrawMode +//----------------------------------------------------- +void SEQ_Envelope_8_DrawMode( void *pClass, int id, bool bOn ) +{ + SEQ_Envelope_8 *mymodule; + mymodule = (SEQ_Envelope_8*)pClass; + mymodule->m_pEnvelope->m_bDraw = bOn; +} + +//----------------------------------------------------- +// SEQ_Envelope_8_GateMode +//----------------------------------------------------- +void SEQ_Envelope_8_GateMode( void *pClass, int id, bool bOn ) +{ + SEQ_Envelope_8 *mymodule; + mymodule = (SEQ_Envelope_8*)pClass; + mymodule->m_bGateMode[ mymodule->m_CurrentChannel ] = bOn; + mymodule->m_pEnvelope->setGateMode( mymodule->m_CurrentChannel, bOn ); +} + +//----------------------------------------------------- +// Procedure: SEQ_Envelope_8_ChSelect +//----------------------------------------------------- +void SEQ_Envelope_8_ChSelect( void *pClass, int id, int nbutton, bool bOn ) +{ + SEQ_Envelope_8 *mymodule; + mymodule = (SEQ_Envelope_8*)pClass; + + mymodule->ChangeChannel( nbutton ); +} + +//----------------------------------------------------- +// Procedure: SEQ_Envelope_8_ModeSelect +//----------------------------------------------------- +void SEQ_Envelope_8_ModeSelect( void *pClass, int id, int nbutton, bool bOn ) +{ + SEQ_Envelope_8 *mymodule; + mymodule = (SEQ_Envelope_8*)pClass; + + mymodule->m_Modes[ mymodule->m_CurrentChannel ] = nbutton; + mymodule->m_pEnvelope->setMode( mymodule->m_CurrentChannel, nbutton ); +} + +//----------------------------------------------------- +// Procedure: SEQ_Envelope_8_TimeSelect +//----------------------------------------------------- +void SEQ_Envelope_8_TimeSelect( void *pClass, int id, int nbutton, bool bOn ) +{ + SEQ_Envelope_8 *mymodule; + mymodule = (SEQ_Envelope_8*)pClass; + + mymodule->m_TimeDivs[ mymodule->m_CurrentChannel ] = nbutton; + mymodule->m_pEnvelope->setTimeDiv( mymodule->m_CurrentChannel, nbutton ); +} + +//----------------------------------------------------- +// Procedure: SEQ_Envelope_8_RangeSelect +//----------------------------------------------------- +void SEQ_Envelope_8_RangeSelect( void *pClass, int id, int nbutton, bool bOn ) +{ + SEQ_Envelope_8 *mymodule; + mymodule = (SEQ_Envelope_8*)pClass; + + mymodule->m_Ranges[ mymodule->m_CurrentChannel ] = nbutton; + mymodule->m_pEnvelope->setRange( mymodule->m_CurrentChannel, nbutton ); +} + +//----------------------------------------------------- +// Procedure: SEQ_Envelope_8_Hold +//----------------------------------------------------- +void SEQ_Envelope_8_Hold( void *pClass, int id, bool bOn ) +{ + SEQ_Envelope_8 *mymodule; + mymodule = (SEQ_Envelope_8*)pClass; + + mymodule->m_bHold[ id ] = bOn; +} + +//----------------------------------------------------- +// Procedure: SEQ_Envelope_8_WaveSet +//----------------------------------------------------- +void SEQ_Envelope_8_WaveSet( void *pClass, int id, bool bOn ) +{ + int i; + float a, div; + SEQ_Envelope_8 *mymodule; + mymodule = (SEQ_Envelope_8*)pClass; + + if( id == 0 ) + { + if( ++mymodule->m_waveSet > 6 ) + mymodule->m_waveSet = 0; + } + else + { + if( --mymodule->m_waveSet < 0 ) + mymodule->m_waveSet = 6; + } + + switch( mymodule->m_waveSet ) + { + case 0: + mymodule->m_pEnvelope->resetValAll( mymodule->m_CurrentChannel, 0.0f ); + break; + case 1: + mymodule->m_pEnvelope->resetValAll( mymodule->m_CurrentChannel, 0.5f ); + break; + case 2: // sin + div = (float)(ENVELOPE_HANDLES - 1) / (PI * 2.0f); + for( i = 0; i < ENVELOPE_HANDLES; i++ ) + { + a = ( 1.0f + sinf( (float)i / div ) ) / 2.0f; + mymodule->m_pEnvelope->setVal( mymodule->m_CurrentChannel, i, a ); + } + break; + case 3: // cos + div = (float)(ENVELOPE_HANDLES - 1) / (PI * 2.0f); + for( i = 0; i < ENVELOPE_HANDLES; i++ ) + { + a = ( 1.0f + cosf( (float)i / div ) ) / 2.0f; + mymodule->m_pEnvelope->setVal( mymodule->m_CurrentChannel, i, a ); + } + break; + case 4: // cos half + div = (float)(ENVELOPE_HANDLES - 1) / (PI * 1.0f); + for( i = 0; i < ENVELOPE_HANDLES; i++ ) + { + a = ( 1.0f + cosf( (float)i / div ) ) / 2.0f; + mymodule->m_pEnvelope->setVal( mymodule->m_CurrentChannel, i, a ); + } + break; + case 5: // triangle full + div = 1.0f / 16.0f; + a = 0; + for( i = 0; i < ENVELOPE_HANDLES; i++ ) + { + mymodule->m_pEnvelope->setVal( mymodule->m_CurrentChannel, i, a ); + a += div; + } + break; + case 6: // triangle half + div = 1.0f / 8.0f; + a = 0; + for( i = 0; i < ENVELOPE_HANDLES; i++ ) + { + mymodule->m_pEnvelope->setVal( mymodule->m_CurrentChannel, i, a ); + a += div; + + if( i == 8 ) + a = 0.0f; + } + break; + + default: + break; + } +} + +//----------------------------------------------------- +// Procedure: SEQ_Envelope_8_WaveInvert +//----------------------------------------------------- +void SEQ_Envelope_8_WaveInvert( void *pClass, int id, bool bOn ) +{ + int i; + SEQ_Envelope_8 *mymodule; + mymodule = (SEQ_Envelope_8*)pClass; + + for( i = 0; i < ENVELOPE_HANDLES; i++ ) + mymodule->m_pEnvelope->setVal( mymodule->m_CurrentChannel, i, 1.0f - mymodule->m_pEnvelope->m_HandleVal[ mymodule->m_CurrentChannel ][ i ] ); +} + +//----------------------------------------------------- +// Procedure: SEQ_Envelope_8_WaveRand +//----------------------------------------------------- +void SEQ_Envelope_8_WaveRand( void *pClass, int id, bool bOn ) +{ + int i; + SEQ_Envelope_8 *mymodule; + mymodule = (SEQ_Envelope_8*)pClass; + + for( i = 0; i < ENVELOPE_HANDLES; i++ ) + mymodule->m_pEnvelope->setVal( mymodule->m_CurrentChannel, i, randomUniform() ); +} + +//----------------------------------------------------- +// Procedure: SEQ_Envelope_8_WaveCopy +//----------------------------------------------------- +void SEQ_Envelope_8_WaveCopy( void *pClass, int id, bool bOn ) +{ + SEQ_Envelope_8 *mymodule; + mymodule = (SEQ_Envelope_8*)pClass; + + mymodule->m_bCpy = bOn; +} + +//----------------------------------------------------- +// Procedure: SEQ_Envelope_8_Trig +//----------------------------------------------------- +void SEQ_Envelope_8_Trig( void *pClass, int id, bool bOn ) +{ + SEQ_Envelope_8 *mymodule; + mymodule = (SEQ_Envelope_8*)pClass; + + // global reset + if( id == nCHANNELS ) + { + // turn on all trigs + for( int i = 0; i < nCHANNELS; i++ ) + { + mymodule->m_pButtonTrig[ i ]->Set( bOn ); + mymodule->m_bTrig[ i ] = true; + } + } + else + { + mymodule->m_bTrig[ id ] = true; + } +} + +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- + +struct SEQ_Envelope_8_Widget : ModuleWidget { + SEQ_Envelope_8_Widget( SEQ_Envelope_8 *module ); +}; + +SEQ_Envelope_8_Widget::SEQ_Envelope_8_Widget( SEQ_Envelope_8 *module ) : ModuleWidget(module) +{ + int ch, x=0, y=0 ; + + box.size = Vec( 15*36, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/SEQ_Envelope_8.svg"))); + addChild(panel); + } + + //module->lg.Open("SEQ_Envelope_8.txt"); + // input clock + addInput(Port::create( Vec( 45, 18 ), Port::INPUT, module, SEQ_Envelope_8::INPUT_CLK ) ); + + // input clock reset + addInput(Port::create( Vec( 21, 18 ), Port::INPUT, module, SEQ_Envelope_8::INPUT_CLK_RESET ) ); + + // invert + module->m_pButtonInvert = new MyLEDButton( 95, 23, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_MOMENTARY, 0, module, SEQ_Envelope_8_WaveInvert ); + addChild( module->m_pButtonInvert ); + + // envelope editor + module->m_pEnvelope = new Widget_EnvelopeEdit( 47, 42, 416, 192, 7, module, EnvelopeEditCALLBACK ); + addChild( module->m_pEnvelope ); + + // envelope select buttons + module->m_pButtonChSelect = new MyLEDButtonStrip( 210, 23, 11, 11, 3, 8.0, nCHANNELS, false, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButtonStrip::TYPE_EXCLUSIVE, 0, module, SEQ_Envelope_8_ChSelect ); + addChild( module->m_pButtonChSelect ); + + module->m_pTextLabel = new Label(); + module->m_pTextLabel->box.pos = Vec( 450, 10 ); + module->m_pTextLabel->text = "----"; + addChild( module->m_pTextLabel ); + + // wave set buttons + x = 364; + y = 23; + module->m_pButtonWaveSetBck = new MyLEDButton( x, y, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_MOMENTARY, 0, module, SEQ_Envelope_8_WaveSet ); + addChild( module->m_pButtonWaveSetBck ); + + module->m_pButtonWaveSetFwd = new MyLEDButton( x + 12, y, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_MOMENTARY, 1, module, SEQ_Envelope_8_WaveSet ); + addChild( module->m_pButtonWaveSetFwd ); + + x = 405; + + // random + module->m_pButtonRand = new MyLEDButton( x, y, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_MOMENTARY, 0, module, SEQ_Envelope_8_WaveRand ); + addChild( module->m_pButtonRand ); + + x += 25; + + // copy + module->m_pButtonCopy = new MyLEDButton( x, y, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_SWITCH, 0, module, SEQ_Envelope_8_WaveCopy ); + addChild( module->m_pButtonCopy ); + + // mode select + module->m_pButtonModeSelect = new MyLEDButtonStrip( 109, 256, 11, 11, 8, 8.0, Widget_EnvelopeEdit::nMODES, true, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButtonStrip::TYPE_EXCLUSIVE, 0, module, SEQ_Envelope_8_ModeSelect ); + addChild( module->m_pButtonModeSelect ); + + // time select + module->m_pButtonTimeSelect = new MyLEDButtonStrip( 272, 256, 11, 11, 8, 8.0, nTIMESETS, true, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButtonStrip::TYPE_EXCLUSIVE, 0, module, SEQ_Envelope_8_TimeSelect ); + addChild( module->m_pButtonTimeSelect ); + + // rande select + module->m_pButtonRangeSelect = new MyLEDButtonStrip( 350, 256, 11, 11, 8, 8.0, Widget_EnvelopeEdit::nRANGES, true, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButtonStrip::TYPE_EXCLUSIVE, 0, module, SEQ_Envelope_8_RangeSelect ); + addChild( module->m_pButtonRangeSelect ); + + // draw mode + module->m_pButtonDraw = new MyLEDButton( 48, 237, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 128, 0 ), MyLEDButton::TYPE_SWITCH, 0, module, SEQ_Envelope_8_DrawMode ); + addChild( module->m_pButtonDraw ); + + // gate mode + module->m_pButtonGateMode = new MyLEDButton( 48, 254, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 128, 0 ), MyLEDButton::TYPE_SWITCH, 0, module, SEQ_Envelope_8_GateMode ); + addChild( module->m_pButtonGateMode ); + + // global reset input + addInput(Port::create( Vec( 21, 313 ), Port::INPUT, module, SEQ_Envelope_8::INPUT_GLOBAL_TRIG ) ); + + // global reseet button + module->m_pButtonGlobalReset = new MyLEDButton( 5, 315, 14, 14, 11.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_MOMENTARY, nCHANNELS, module, SEQ_Envelope_8_Trig ); + addChild( module->m_pButtonGlobalReset ); + + // band knob + addParam(ParamWidget::create( Vec( 59.5 , 280 ), module, SEQ_Envelope_8::PARAM_BAND, 0.0, 0.8, 0.333 ) ); + + // inputs, outputs + x=21; + y=53; + for( ch = 0; ch < nCHANNELS; ch++ ) + { + addInput(Port::create( Vec( x, y ), Port::INPUT, module, SEQ_Envelope_8::INPUT_CH_TRIG + ch ) ); + + // trig button + module->m_pButtonTrig[ ch ] = new MyLEDButton( x -16, y + 2, 14, 14, 11.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButton::TYPE_MOMENTARY, ch, module, SEQ_Envelope_8_Trig ); + addChild( module->m_pButtonTrig[ ch ] ); + + // hold button + module->m_pButtonHold[ ch ] = new MyLEDButton( 470, y + 2, 14, 14, 11.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, ch, module, SEQ_Envelope_8_Hold ); + addChild( module->m_pButtonHold[ ch ] ); + + // hold gate input + addInput(Port::create( Vec( 486, y ), Port::INPUT, module, SEQ_Envelope_8::INPUT_CH_HOLD + ch ) ); + + // out cv + addOutput(Port::create( Vec( 516, y ), Port::OUTPUT, module, SEQ_Envelope_8::OUTPUT_CV + ch ) ); + + y += 28; + } + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + module->m_bInitialized = true; +} + +//----------------------------------------------------- +// Procedure: JsonParams +// +//----------------------------------------------------- +void SEQ_Envelope_8::JsonParams( bool bTo, json_t *root) +{ + JsonDataBool( bTo, "m_bHold", root, m_bHold, nCHANNELS ); + JsonDataBool( bTo, "m_bGateMode", root, m_bGateMode, nCHANNELS ); + JsonDataInt( bTo, "m_HoldPos", root, (int*)m_HoldPos, nCHANNELS ); + JsonDataInt( bTo, "m_TimeDivs", root, (int*)m_TimeDivs, nCHANNELS ); + JsonDataInt( bTo, "m_Modes", root, (int*)m_Modes, nCHANNELS ); + JsonDataInt( bTo, "m_Ranges", root, (int*)m_Ranges, nCHANNELS ); + JsonDataInt( bTo, "m_GraphData", root, (int*)m_GraphData, nCHANNELS * ENVELOPE_HANDLES ); +} + +//----------------------------------------------------- +// Procedure: toJson +// +//----------------------------------------------------- +json_t *SEQ_Envelope_8::toJson() +{ + json_t *root = json_object(); + + if( !root ) + return NULL; + + m_pEnvelope->getDataAll( (int*)m_GraphData ); + + for( int i = 0; i < nCHANNELS; i++ ) + m_HoldPos[ i ] = m_pEnvelope->getPos( i ); + + JsonParams( TOJSON, root ); + + return root; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void SEQ_Envelope_8::fromJson( json_t *root ) +{ + int ch; + + JsonParams( FROMJSON, root ); + + for( ch = 0; ch < nCHANNELS; ch++ ) + { + + // hold button + m_pButtonHold[ ch ]->Set( m_bHold[ ch ] ); + + m_pEnvelope->setGateMode( ch, m_bGateMode[ ch ] ); + m_pEnvelope->setMode( ch, m_Modes[ ch ] ); + m_pEnvelope->setRange( ch, m_Ranges[ ch ] ); + m_pEnvelope->setTimeDiv( ch, m_TimeDivs[ ch ] ); + m_pEnvelope->setPos( ch, m_HoldPos[ ch ] ); + } + + m_pEnvelope->setDataAll( (int*)m_GraphData ); + + ChangeChannel( 0 ); +} + +//----------------------------------------------------- +// Procedure: onCreate +// +//----------------------------------------------------- +void SEQ_Envelope_8::onCreate() +{ +} + +//----------------------------------------------------- +// Procedure: onDelete +// +//----------------------------------------------------- +void SEQ_Envelope_8::onDelete() +{ +} + +//----------------------------------------------------- +// Procedure: onReset +// +//----------------------------------------------------- +void SEQ_Envelope_8::onReset() +{ + int ch; + + memset( m_GraphData, 0, sizeof( m_GraphData ) ); + memset( m_bGateMode, 0, sizeof( m_bGateMode ) ); + memset( m_Modes, 0, sizeof( m_Modes ) ); + memset( m_Ranges, 0, sizeof( m_Ranges ) ); + memset( m_GraphData, 0, sizeof( m_GraphData ) ); + memset( m_bHold, 0, sizeof( m_bHold ) ); + + for( ch = 0; ch < nCHANNELS; ch++ ) + { + m_pButtonHold[ ch ]->Set( m_bHold[ ch ] ); + + m_pEnvelope->setGateMode( ch, m_bGateMode[ ch ] ); + m_pEnvelope->setMode( ch, m_Modes[ ch ] ); + m_pEnvelope->setRange( ch, m_Ranges[ ch ] ); + m_pEnvelope->setTimeDiv( ch, m_TimeDivs[ ch ] ); + m_pEnvelope->setPos( ch, m_HoldPos[ ch ] ); + } + + m_pEnvelope->setDataAll( (int*)m_GraphData ); + + ChangeChannel( 0 ); +} + +//----------------------------------------------------- +// Procedure: onRandomize +// +//----------------------------------------------------- +void SEQ_Envelope_8::onRandomize() +{ + int ch, i; + + for( ch = 0; ch < nCHANNELS; ch++ ) + { + for( i = 0; i < ENVELOPE_HANDLES; i++ ) + m_pEnvelope->setVal( ch, i, randomUniform() ); + } +} + +//----------------------------------------------------- +// Procedure: onRandomize +// +//----------------------------------------------------- +void SEQ_Envelope_8::ChangeChannel( int ch ) +{ + int i; + + if( ch < 0 || ch >= nCHANNELS ) + return; + + if( m_bCpy ) + { + m_bCpy = false; + m_pButtonCopy->Set( false ); + + for( i = 0; i < ENVELOPE_HANDLES; i++ ) + { + m_pEnvelope->setVal( ch, i, m_pEnvelope ->m_HandleVal[ m_CurrentChannel ][ i ] ); + } + + m_TimeDivs[ ch ] = m_TimeDivs[ m_CurrentChannel ]; + m_Modes[ ch ] = m_Modes[ m_CurrentChannel ]; + m_Ranges[ ch ] = m_Ranges[ m_CurrentChannel ]; + m_bGateMode[ ch ] = m_bGateMode[ m_CurrentChannel ]; + + m_pEnvelope->setGateMode( ch, m_bGateMode[ ch ] ); + m_pEnvelope->setMode( ch, m_Modes[ ch ] ); + m_pEnvelope->setRange( ch, m_Ranges[ ch ] ); + m_pEnvelope->setTimeDiv( ch, m_TimeDivs[ ch ] ); + } + + m_CurrentChannel = ch; + m_pButtonChSelect->Set( ch, true ); + m_pButtonTimeSelect->Set( m_TimeDivs[ ch ], true ); + m_pButtonModeSelect->Set( m_Modes[ ch ], true ); + m_pButtonRangeSelect->Set( m_Ranges[ ch ], true ); + m_pButtonGateMode->Set( m_bGateMode[ ch ] ); + m_pEnvelope->setView( ch ); +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +void SEQ_Envelope_8::step() +{ + int ch; + bool bHold = false, bTrig = false, bGlobalTrig = false; + //char strVal[ 10 ] = {}; + + if( !m_bInitialized || !inputs[ INPUT_CLK ].active ) + return; + + // global clock reset + m_pEnvelope->m_bClkReset = m_SchTrigGlobalClkReset.process( inputs[ INPUT_CLK_RESET ].normalize( 0.0f ) ); + + m_BeatCount++; + + // track clock period + if( m_SchTrigClk.process( inputs[ INPUT_CLK ].normalize( 0.0f ) ) ) + { + //sprintf( strVal, "%d", m_BeatCount ); + //m_pTextLabel->text = strVal; + m_pEnvelope->setBeatLen( m_BeatCount ); + m_BeatCount = 0; + } + + if( m_SchTrigGlobalTrig.process( inputs[ INPUT_GLOBAL_TRIG ].normalize( 0.0f ) ) ) + { + bGlobalTrig = true; + } + + // process each channel + for( ch = 0; ch < nCHANNELS; ch++ ) + { + // trig, clock reset + bTrig = ( m_SchTrigChTrig[ ch ].process( inputs[ INPUT_CH_TRIG + ch ].normalize( 0.0f ) ) ) || bGlobalTrig; + + if( bTrig ) + m_pButtonTrig[ ch ]->Set( true ); + + if( bTrig || m_bTrig[ ch ] ) + bTrig = true; + + bHold = ( m_bHold[ ch ] || inputs[ INPUT_CH_HOLD + ch ].normalize( 0.0f ) > 2.5f ); + + if( bHold && !m_pButtonHold[ ch ]->m_bOn ) + m_pButtonHold[ ch ]->Set( true ); + else if( !bHold && m_pButtonHold[ ch ]->m_bOn ) + m_pButtonHold[ ch ]->Set( false ); + + // process envelope + outputs[ OUTPUT_CV + ch ].value = m_pEnvelope->procStep( ch, bTrig, bHold ); + + m_bTrig[ ch ] = false; + } + + m_pEnvelope->m_bClkReset = false; +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, SEQ_Envelope_8) { + Model *modelSEQ_Envelope_8 = Model::create( "mscHack", "SEQ_Envelope_8", "ENVY - 9", ENVELOPE_GENERATOR_TAG, MULTIPLE_TAG ); + return modelSEQ_Envelope_8; +} diff --git a/plugins/community/repos/mscHack/src/Seq_3x16x16.cpp b/plugins/community/repos/mscHack/src/Seq_3x16x16.cpp new file mode 100644 index 00000000..a35c8a56 --- /dev/null +++ b/plugins/community/repos/mscHack/src/Seq_3x16x16.cpp @@ -0,0 +1,1011 @@ +#include "mscHack.hpp" +//#include "mscHack_Controls.hpp" +#include "dsp/digital.hpp" +//#include "CLog.h" + +namespace rack_plugin_mscHack { + +#define PATTERNS 16 +#define STEPS 16 +#define CHANNELS 3 +#define LIGHT_LAMBDA ( 0.065f ) +#define CHANNEL_OFF_H 91 + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct Seq_3x16x16 : Module +{ + enum ParamIds + { + PARAM_RAND, + PARAM_CPY_NEXT = PARAM_RAND + CHANNELS, + PARAM_RUN = PARAM_CPY_NEXT + CHANNELS, + PARAM_RESET, + PARAM_SLIDERS, + PARAM_STEPS = PARAM_SLIDERS + ( CHANNELS * STEPS ), + PARAM_PATTERNS = PARAM_STEPS + ( CHANNELS * STEPS ), + PARAM_STEP_NUM = PARAM_PATTERNS + ( CHANNELS * PATTERNS ), + PARAM_GLOBAL_PAT = PARAM_STEP_NUM + ( STEPS ), + nPARAMS = PARAM_GLOBAL_PAT + ( PATTERNS ) + }; + + enum InputIds + { + INPUT_EXT_CLOCK, + INPUT_RESET, + INPUT_GLOBAL_PAT_CHANGE, + INPUT_PAT_CHANGE, + nINPUTS = INPUT_PAT_CHANGE + CHANNELS + }; + + enum OutputIds + { + OUT_GATES, + OUT_CV = OUT_GATES + CHANNELS, + nOUTPUTS = OUT_CV + CHANNELS + }; + + enum LightIds + { + LIGHT_RUN, + LIGHT_RESET, + LIGHT_STEP_NUM, + LIGHT_STEP = LIGHT_STEP_NUM + ( STEPS ), + LIGHT_PAT = LIGHT_STEP + ( CHANNELS * STEPS ), + LIGHT_COPY = LIGHT_PAT + ( CHANNELS * PATTERNS ), + LIGHT_RAND = LIGHT_COPY + CHANNELS, + LIGHT_GLOBAL_PAT = LIGHT_RAND + CHANNELS, + nLIGHTS = LIGHT_GLOBAL_PAT + PATTERNS + }; + + enum GateMode + { + TRIGGER, + RETRIGGER, + CONTINUOUS, + }; + + CLog lg; + bool m_bInitJson = false; + GateMode m_GateMode = TRIGGER; + PulseGenerator m_PulseStep; + bool m_bRunning = true; + float m_fPhase = 0.0; + + // Inputs + SchmittTrigger m_SchTrigClock; + SchmittTrigger m_SchTrigRun; + SchmittTrigger m_SchTrigReset; + SchmittTrigger m_SchTrigPatChange[ CHANNELS ]; + + // random pattern button + SchmittTrigger m_SchTrigRandPat; + + // copy next buttons + SchmittTrigger m_SchTrigCopyNext; + + // number of steps + int m_nSteps = STEPS; + SchmittTrigger m_SchTrigStepNumbers[ STEPS ]; + + // Level settings + ParamWidget *m_pLevelToggleParam2[ CHANNELS ][ STEPS ] = {}; + SchmittTrigger m_SchTrigLevels[ CHANNELS ][ STEPS ]; + float m_fLevels[ PATTERNS ][ CHANNELS ][ STEPS ] = {}; + + // Global Pattern Select + SchmittTrigger m_SchTrigGlobalPatternSelect; + int m_GlobalSelect = 0; + bool m_bGlobalPatternChangePending = false; + int m_GlobalPendingLight = 0; + + // Pattern Select + int m_PatternSelect[ CHANNELS ] = {0}; + SchmittTrigger m_SchTrigPatternSelects[ CHANNELS ][ PATTERNS ]; + bool m_bPatternPending = false; + bool m_bPatternChangePending[ CHANNELS ] = {0}; + int m_PendingLight[ CHANNELS ] = {0}; + + // Steps + int m_CurrentStep = 0; + SchmittTrigger m_SchTrigSteps[ CHANNELS ][ STEPS ]; + bool m_bStepStates[ PATTERNS ][ CHANNELS ][ STEPS ] = {}; + float m_fLightStepLevels[ CHANNELS ][ STEPS ] = {}; + + // Contructor + Seq_3x16x16() : Module( nPARAMS, nINPUTS, nOUTPUTS, nLIGHTS ){} + + // Overrides + void step() override; + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onRandomize() override; + void onReset() override; + + void Randomize_Channel( int ch ); + void CopyNext( int ch ); + void ChangePattern( int ch, int index, bool bForceChange ); + void SetSteps( int nSteps ); + void SetGlobalPattern( int step ); +}; + +//----------------------------------------------------- +// Procedure: MySquareButton_CopyNext +// +//----------------------------------------------------- +struct MySquareButton_CopyNext : MySquareButton +{ + Seq_3x16x16 *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Seq_3x16x16*)module; + + if( mymodule && value == 1.0 ) + { + param = paramId - Seq_3x16x16::PARAM_CPY_NEXT; + mymodule->CopyNext( param ); + } + + MomentarySwitch::onChange( e ); + } +}; + +//----------------------------------------------------- +// Procedure: MySquareButton_Rand +// +//----------------------------------------------------- +struct MySquareButton_Rand : MySquareButton +{ + Seq_3x16x16 *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Seq_3x16x16*)module; + + if( mymodule && value == 1.0 ) + { + param = paramId - Seq_3x16x16::PARAM_RAND; + mymodule->Randomize_Channel( param ); + } + + MomentarySwitch::onChange( e ); + } +}; + +//----------------------------------------------------- +// Procedure: MySquareButton_GlobalPattern +// +//----------------------------------------------------- +struct MySquareButton_GlobalPattern : MySquareButton //SVGSwitch, MomentarySwitch +{ + Seq_3x16x16 *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (Seq_3x16x16*)module; + + if( mymodule && value == 1.0 ) + { + param = paramId - Seq_3x16x16::PARAM_GLOBAL_PAT; + + if( mymodule->m_bRunning ) + { + if( param != mymodule->m_GlobalSelect && !mymodule->m_bGlobalPatternChangePending ) + { + mymodule->m_bGlobalPatternChangePending = true; + mymodule->m_GlobalPendingLight = param; + } + } + else + { + mymodule->SetGlobalPattern( param ); + } + } + + MomentarySwitch::onChange( e ); + } +}; + +//----------------------------------------------------- +// Procedure: MySquareButton_Pattern +// +//----------------------------------------------------- +struct MySquareButton_Pattern : MySquareButton //SVGSwitch, MomentarySwitch +{ + Seq_3x16x16 *mymodule; + int ch, stp, param; + + void onChange( EventChange &e ) override + { + mymodule = (Seq_3x16x16*)module; + + if( mymodule && value == 1.0 ) + { + param = paramId - Seq_3x16x16::PARAM_PATTERNS; + ch = param / STEPS; + stp = param - (ch * STEPS); + + //mymodule->lg.f( (char*)"pat = %d, ch = %d, stp = %d\n", param, ch, stp ); + + if( mymodule->m_bRunning ) + { + if( stp != mymodule->m_PatternSelect[ ch ] && !mymodule->m_bPatternChangePending[ ch ] ) + { + mymodule->m_bPatternPending = true; + mymodule->m_bPatternChangePending[ ch ] = true; + mymodule->m_PendingLight[ ch ] = stp; + } + } + else + { + mymodule->ChangePattern( ch, stp, false ); + } + } + + MomentarySwitch::onChange( e ); + } +}; + +//----------------------------------------------------- +// Procedure: MySquareButton_Step +// +//----------------------------------------------------- +struct MySquareButton_Step : MySquareButton //SVGSwitch, MomentarySwitch +{ + Seq_3x16x16 *mymodule; + int ch, stp, param; + + void onChange( EventChange &e ) override + { + mymodule = (Seq_3x16x16*)module; + + if( mymodule && value == 1.0 ) + { + param = paramId - Seq_3x16x16::PARAM_STEPS; + ch = param / STEPS; + stp = param - (ch * STEPS); + + //lg.f( (char*)"step = %d, ch = %d, stp = %d\n", param, ch, stp ); + mymodule->m_bStepStates[ mymodule->m_PatternSelect[ ch ] ][ ch ][ stp ] = !mymodule->m_bStepStates[ mymodule->m_PatternSelect[ ch ] ][ ch ][ stp ]; + mymodule->lights[ Seq_3x16x16::LIGHT_STEP + ( ch * STEPS ) + stp ].value = mymodule->m_bStepStates[ mymodule->m_PatternSelect[ ch ] ][ ch ][ stp ] ? 1.0f : 0.0f; + } + + MomentarySwitch::onChange( e ); + } +}; + +//----------------------------------------------------- +// Procedure: MySquareButton_Step +// +//----------------------------------------------------- +struct MySquareButton_StepNum : MySquareButton +{ + Seq_3x16x16 *mymodule; + int stp, i; + + void onChange( EventChange &e ) override + { + mymodule = (Seq_3x16x16*)module; + + if( mymodule && value == 1.0 ) + { + stp = paramId - Seq_3x16x16::PARAM_STEP_NUM; + mymodule->SetSteps( stp + 1 ); + } + + MomentarySwitch::onChange( e ); + } +}; + +//----------------------------------------------------- +// Procedure: MySlider_Levels +// +//----------------------------------------------------- +struct MySlider_Levels : MySlider_01 +{ + Seq_3x16x16 *mymodule; + int ch, stp, param; + + void onChange( EventChange &e ) override + { + mymodule = (Seq_3x16x16*)module; + + if( mymodule ) + { + param = paramId - Seq_3x16x16::PARAM_SLIDERS; + ch = param / STEPS; + stp = param - (ch * STEPS); + + //lg.f( "slider = %d, ch = %d, stp = %d, value = %.3f\n", param, ch, stp, value ); + + mymodule->m_fLevels[ mymodule->m_PatternSelect[ ch ] ][ ch ][ stp ] = value; + } + + SVGFader::onChange( e ); + } +}; + +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- + +struct Seq_3x16x16_Widget : ModuleWidget { + Seq_3x16x16_Widget( Seq_3x16x16 *module ); +}; + +Seq_3x16x16_Widget::Seq_3x16x16_Widget( Seq_3x16x16 *module ) : ModuleWidget(module) +{ + int i, ch, stp, x, y; + + box.size = Vec(15*23, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/Seq_3x16x16.svg"))); + addChild(panel); + } + + //module->lg.Open("Seq_3x16x16.txt"); + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + // clk/run button + addParam(ParamWidget::create(Vec( 78, 17 ), module, Seq_3x16x16::PARAM_RUN, 0.0, 1.0, 0.0 ) ); + addChild(ModuleLightWidget::create>( Vec( 78 + 5, 17 + 5 ), module, Seq_3x16x16::LIGHT_RUN ) ); + addInput(Port::create( Vec( 47, 17 ), Port::INPUT, module, Seq_3x16x16::INPUT_EXT_CLOCK ) ); + + // reset button + addParam(ParamWidget::create( Vec( 143, 17 ), module, Seq_3x16x16::PARAM_RESET, 0.0, 1.0, 0.0 ) ); + addChild(ModuleLightWidget::create>( Vec( 143 + 5, 17 + 5 ), module, Seq_3x16x16::LIGHT_RESET ) ); + addInput(Port::create( Vec( 117, 17 ), Port::INPUT, module, Seq_3x16x16::INPUT_RESET ) ); + + //---------------------------------------------------- + // Step Select buttons + + y = 41; + x = 50; + + for ( stp = 0; stp < STEPS; stp++ ) + { + // step button + addParam(ParamWidget::create( Vec( x, y ), module, Seq_3x16x16::PARAM_STEP_NUM + stp, 0.0, 1.0, 0.0 ) ); + addChild(ModuleLightWidget::create>( Vec( x + 2, y + 3 ), module, Seq_3x16x16::LIGHT_STEP_NUM + stp ) ); + + if( ( stp & 0x3 ) == 0x3 ) + x += 20; + else + x += 15; + + module->lights[ Seq_3x16x16::LIGHT_STEP_NUM + stp ].value = 1.0; + } + + //---------------------------------------------------- + // All the Channel buttons + + // channel + for ( ch = 0; ch < CHANNELS; ch++ ) + { + x = 50; + + // step + for ( stp = 0; stp < STEPS; stp++ ) + { + y = 64 + (ch * CHANNEL_OFF_H); + + // level button + module->m_pLevelToggleParam2[ ch ][ stp ] = ParamWidget::create( Vec( x, y ), module, Seq_3x16x16::PARAM_SLIDERS + ( ch * STEPS ) + stp , 0.0, 6.0, 0.0); + addParam( module->m_pLevelToggleParam2[ ch ][ stp ] ); + + y += 46; + + // step button + addParam(ParamWidget::create( Vec( x, y ), module, Seq_3x16x16::PARAM_STEPS + ( ch * STEPS ) + stp, 0.0, 1.0, 0.0 ) ); + addChild(ModuleLightWidget::create>( Vec( x + 2, y + 3 ), module, Seq_3x16x16::LIGHT_STEP + ( ch * STEPS ) + stp ) ); + + if( ( stp & 0x3 ) == 0x3 ) + x += 20; + else + x += 15; + } + + x = 45; + y = 130 + (ch * CHANNEL_OFF_H); + + for ( i = 0; i < PATTERNS; i++ ) + { + // pattern button + addParam(ParamWidget::create( Vec( x, y ), module, Seq_3x16x16::PARAM_PATTERNS + ( ch * PATTERNS ) + i, 0.0, 1.0, 0.0 ) ); + addChild(ModuleLightWidget::create>( Vec( x + 2, y + 3 ), module, Seq_3x16x16::LIGHT_PAT + ( ch * PATTERNS ) + i ) ); + + x += 13; + } + + x = 260; + y = 126 + (ch * CHANNEL_OFF_H); + + // copy next button + addParam(ParamWidget::create( Vec( x, y ), module, Seq_3x16x16::PARAM_CPY_NEXT + ch, 0.0, 1.0, 0.0 ) ); + addChild(ModuleLightWidget::create>( Vec( x + 2, y + 3 ), module, Seq_3x16x16::LIGHT_COPY + ch ) ); + + x = 290; + + // random button + addParam(ParamWidget::create( Vec( x, y ), module, Seq_3x16x16::PARAM_RAND + ch, 0.0, 1.0, 0.0 ) ); + addChild(ModuleLightWidget::create>( Vec( x + 2, y + 3 ), module, Seq_3x16x16::LIGHT_RAND + ch ) ); + + // pattern change input trigger + addInput(Port::create( Vec( 17, 127 + (ch * CHANNEL_OFF_H) ), Port::INPUT, module, Seq_3x16x16::INPUT_PAT_CHANGE + ch ) ); + + x = 310; + y = 65 + (ch * CHANNEL_OFF_H); + + // outputs + addOutput(Port::create( Vec( x, y ), Port::OUTPUT, module, Seq_3x16x16::OUT_CV + ch ) ); + addOutput(Port::create( Vec( x, y + 42 ), Port::OUTPUT, module, Seq_3x16x16::OUT_GATES + ch ) ); + } + + //---------------------------------------------------- + // Global patter select buttons + x = 45; + y = 340; + + for ( stp = 0; stp < PATTERNS; stp++ ) + { + // pattern button + addParam(ParamWidget::create( Vec( x, y ), module, Seq_3x16x16::PARAM_GLOBAL_PAT + stp, 0.0, 1.0, 0.0 ) ); + addChild(ModuleLightWidget::create>( Vec( x + 2, y + 3 ), module, Seq_3x16x16::LIGHT_GLOBAL_PAT + stp ) ); + + x += 13; + } + + // pattern change input trigger + addInput(Port::create( Vec( 17, 338 ), Port::INPUT, module, Seq_3x16x16::INPUT_GLOBAL_PAT_CHANGE ) ); + + module->lights[ Seq_3x16x16::LIGHT_GLOBAL_PAT ].value = 1.0; + module->m_GlobalSelect = 0; + + module->ChangePattern( 0, PATTERNS, false ); + module->ChangePattern( 1, PATTERNS, false ); + module->ChangePattern( 2, PATTERNS, false ); +} + +//----------------------------------------------------- +// Procedure: +// +//----------------------------------------------------- +json_t *Seq_3x16x16::toJson() +{ + bool *pgateState; + float *pfloat; + json_t *rootJ = json_object(); + + // running + json_object_set_new(rootJ, "running", json_boolean (m_bRunning)); + + // steps + pgateState = &m_bStepStates[ 0 ][ 0 ][ 0 ]; + + json_t *gatesJ = json_array(); + + for (int i = 0; i < ( PATTERNS * CHANNELS * STEPS ); i++) + { + json_t *gateJ = json_integer( (int) pgateState[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "steps", gatesJ ); + + // level settings + pfloat = &m_fLevels[ 0 ][ 0 ][ 0 ]; + + json_t *gatesJ_3 = json_array(); + + for (int i = 0; i < ( PATTERNS * CHANNELS * STEPS ); i++) + { + json_t *gateJ = json_real( pfloat[ i ] ); + json_array_append_new(gatesJ_3, gateJ); + } + + json_object_set_new(rootJ, "levelsettings", gatesJ_3); + + // number of steps + json_t *stepsJ = json_integer( m_nSteps ); + json_object_set_new(rootJ, "numberofsteps", stepsJ); + + // gateMode + json_t *gateModeJ = json_integer((int) m_GateMode ); + json_object_set_new(rootJ, "gateMode", gateModeJ); + + return rootJ; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void Seq_3x16x16::fromJson(json_t *rootJ) +{ + bool *pgateState; + float *pfloat; + + // running + json_t *runningJ = json_object_get(rootJ, "running"); + + if (runningJ) + m_bRunning = json_is_true(runningJ); + + // steps + pgateState = &m_bStepStates[ 0 ][ 0 ][ 0 ]; + + json_t *StepsJ = json_object_get(rootJ, "steps"); + + if (StepsJ) + { + for (int i = 0; i < ( PATTERNS * CHANNELS * STEPS ); i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pgateState[ i ] = json_integer_value( gateJ ); + } + } + + // level settings + pfloat = &m_fLevels[ 0 ][ 0 ][ 0 ]; + + json_t *LvlSettingsJ = json_object_get(rootJ, "levelsettings"); + + if (LvlSettingsJ) + { + for (int i = 0; i < ( PATTERNS * CHANNELS * STEPS ); i++) + { + json_t *gateJ = json_array_get(LvlSettingsJ, i); + + if (gateJ) + pfloat[ i ] = json_real_value(gateJ); + + //lg.f("loading %.3f\n", pfloat[ i ] ); + } + } + + // number of steps + json_t *nStepsJ = json_object_get(rootJ, "numberofsteps"); + if (nStepsJ) + m_nSteps = (GateMode)json_integer_value( nStepsJ ); + + // gateMode + json_t *gateModeJ = json_object_get(rootJ, "gateMode"); + if (gateModeJ) + m_GateMode = (GateMode)json_integer_value(gateModeJ); + + SetSteps( m_nSteps ); + + //lg.f("json read complete\n"); + m_bInitJson = true; +} + +//----------------------------------------------------- +// Procedure: reset +// +//----------------------------------------------------- +void Seq_3x16x16::onReset() +{ + //lg.f("init\n"); + memset( m_fLevels, 0, sizeof(m_fLevels) ); + memset( m_bStepStates, 0, sizeof(m_bStepStates) ); + + for( int ch = 0; ch < CHANNELS; ch ++ ) + { + for( int i = 0; i < STEPS; i ++ ) + { + lights[ LIGHT_STEP + ( ch * STEPS ) + i ].value = 0.0; + m_fLightStepLevels[ ch ][ i ] = 0.0; + } + } + + ChangePattern( 0, PATTERNS, false ); + ChangePattern( 1, PATTERNS, false ); + ChangePattern( 2, PATTERNS, false ); + + SetSteps( 16 ); +} + +//----------------------------------------------------- +// Procedure: randomize +// +//----------------------------------------------------- +float stepchance[ 16 ] = { 0.9, 0.5, 0.8, 0.4, 0.9, 0.5, 0.8, 0.4, 0.9, 0.5, 0.8, 0.4, 0.9, 0.5, 0.8, 0.4 }; +void Seq_3x16x16::Randomize_Channel( int ch ) +{ + int stp, pat; + int octave; + + pat = m_PatternSelect[ ch ]; + + octave = (int)( randomUniform() * 4.0 ); + + for( stp = 0; stp < STEPS; stp++ ) + { + m_fLevels[ pat ][ ch ][ stp ] = (float)octave + ( randomUniform() * 2.0 ); + m_bStepStates[ pat ][ ch ][ stp ] = ( randomUniform() < stepchance[ stp ] ) ? true : false; + } + + ChangePattern( ch, pat, true ); +} + +//----------------------------------------------------- +// Procedure: randomize +// +//----------------------------------------------------- +void Seq_3x16x16::onRandomize() +{ + int ch, stp, pat; + int octave; + + for( ch = 0; ch < CHANNELS; ch++ ) + { + for( pat = 0; pat < PATTERNS; pat++ ) + { + octave = (int)( randomUniform() * 4.0 ); + + for( stp = 0; stp < STEPS; stp++ ) + { + m_fLevels[ pat ][ ch ][ stp ] = (float)octave + ( randomUniform() * 2.0 ); + m_bStepStates[ pat ][ ch ][ stp ] = ( randomUniform() < stepchance[ stp ] ) ? true : false; + } + } + } + + ChangePattern( 0, 0, true ); + ChangePattern( 1, 0, true ); + ChangePattern( 2, 0, true ); +} + +//----------------------------------------------------- +// Procedure: CopyNext +// +//----------------------------------------------------- +void Seq_3x16x16::CopyNext( int ch ) +{ + int stp, pat; + + pat = m_PatternSelect[ ch ]; + + // don't copy from the last pattern + if( pat == (PATTERNS - 1) ) + return; + + for( stp = 0; stp < STEPS; stp++ ) + { + m_fLevels[ pat + 1 ][ ch ][ stp ] = m_fLevels[ pat ][ ch ][ stp ]; + m_bStepStates[ pat + 1 ][ ch ][ stp ] = m_bStepStates[ pat ][ ch ][ stp ]; + } + + ChangePattern( ch, pat + 1, true ); +} + +//----------------------------------------------------- +// Procedure: ChangePattern +// +//----------------------------------------------------- +void Seq_3x16x16::ChangePattern( int ch, int index, bool bForceChange ) +{ + int stp, i; + + if( !bForceChange && index == m_PatternSelect[ ch ] ) + return; + + if( index < 0 ) + index = PATTERNS - 1; + else if( index >= PATTERNS ) + index = 0; + + m_PatternSelect[ ch ] = index; + + // update lights + for( stp = 0; stp < STEPS; stp++ ) + lights[ LIGHT_STEP + ( ch * STEPS ) + stp ].value = m_bStepStates[ m_PatternSelect[ ch ] ][ ch ][ stp ] ? 1.0 : 0.0; + + for( i = 0; i < PATTERNS; i++ ) + { + if( m_PatternSelect[ ch ] == i ) + lights[ LIGHT_PAT + ( ch * PATTERNS ) + i ].value = 1.0f; + else + lights[ LIGHT_PAT + ( ch * PATTERNS ) + i ].value = 0.0f; + } + + // step + for( stp = 0; stp < STEPS; stp++ ) + { + // level button + m_pLevelToggleParam2[ ch ][ stp ]->setValue( m_fLevels[ m_PatternSelect[ ch ] ][ ch ][ stp ] ); + } +} + +//----------------------------------------------------- +// Procedure: SetSteps +// +//----------------------------------------------------- +void Seq_3x16x16::SetSteps( int nSteps ) +{ + int i; + + if( nSteps < 1 || nSteps > STEPS ) + nSteps = STEPS; + + m_nSteps = nSteps; + + for ( i = 0; i < STEPS; i++ ) + { + // level button + if( i < nSteps ) + lights[ LIGHT_STEP_NUM + i ].value = 1.0f; + else + lights[ LIGHT_STEP_NUM + i ].value = 0.0f; + } +} + +//----------------------------------------------------- +// Procedure: SetGlobalPattern +// +//----------------------------------------------------- +void Seq_3x16x16::SetGlobalPattern( int step ) +{ + for ( int i = 0; i < PATTERNS; i++ ) + lights[ LIGHT_GLOBAL_PAT + i ].value = 0.0f; + + lights[ LIGHT_GLOBAL_PAT + step ].value = 1.0; + + m_GlobalSelect = step; + + ChangePattern( 0, step, false ); + ChangePattern( 1, step, false ); + ChangePattern( 2, step, false ); +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +void Seq_3x16x16::step() +{ + bool bNextStep = false, bPulse, bGatesOn, bChTrig; + int ch, stp; + float fout, fnote; + int octave; + static float fpendinglight = 0.0f; + static bool bUp = true; + + // pending light value + if( bUp ) + { + fpendinglight += ( 1.0 / engineGetSampleRate() ) * 1.5 ; + + if( fpendinglight >= 0.5f ) + { + fpendinglight = 0.5f; + bUp = false; + } + } + else + { + fpendinglight -= ( 1.0 / engineGetSampleRate() ) * 2; + + if( fpendinglight <= 0.0f ) + { + fpendinglight = 0.0f; + bUp = true; + } + } + + // Run + if( m_SchTrigRun.process( params[ PARAM_RUN ].value ) ) + m_bRunning = !m_bRunning; + + lights[ LIGHT_RUN ].value = m_bRunning ? 1.0f : 0.0f; + + // Random and copy buttons + for( ch = 0; ch < CHANNELS; ch++ ) + { + if( m_SchTrigRandPat.process( params[ PARAM_RAND + ch ].value ) ) + lights[ LIGHT_RAND + ch ].value = 1.0f; + + if( m_SchTrigCopyNext.process( params[ PARAM_CPY_NEXT + ch ].value ) ) + lights[ LIGHT_COPY + ch ].value = 1.0f; + + lights[ LIGHT_RAND + ch ].value -= lights[ LIGHT_RAND + ch ].value / LIGHT_LAMBDA / engineGetSampleRate(); + + lights[ LIGHT_COPY + ch ].value -= lights[ LIGHT_COPY + ch ].value / LIGHT_LAMBDA / engineGetSampleRate(); + } + + if( m_bRunning ) + { + if( inputs[ INPUT_EXT_CLOCK ].active ) + { + // External clock + if( m_SchTrigClock.process( inputs[ INPUT_EXT_CLOCK ].value ) ) + { + m_fPhase = 0.0f; + bNextStep = true; + } + } + } + else + { + // cancel any pending pattern changes + if( m_bGlobalPatternChangePending ) + { + m_bGlobalPatternChangePending = false; + SetGlobalPattern( m_GlobalPendingLight ); + } + + m_bPatternPending = false; + + for( ch = 0; ch < CHANNELS; ch++ ) + { + // pat change trigger + if( m_bPatternChangePending[ ch ] ) + { + m_bPatternChangePending[ ch ] = false; + ChangePattern( ch, m_PendingLight[ ch ], false ); + } + } + } + + // Reset + if( m_SchTrigReset.process( params[ PARAM_RESET ].value + inputs[ INPUT_RESET ].value ) ) + { + m_fPhase = 0.0f; + m_CurrentStep = m_nSteps; + bNextStep = true; + lights[ LIGHT_RESET ].value = 1.0f; + } + + if( bNextStep ) + { + m_CurrentStep += 1; + + if( m_CurrentStep >= m_nSteps ) + m_CurrentStep = 0; + + for( ch = 0; ch < CHANNELS; ch++ ) + m_fLightStepLevels[ ch ][ m_CurrentStep ] = 1.0f; + + m_PulseStep.trigger( 1e-3 ); + + // resolve any pending pattern changes + if( m_CurrentStep == 0 ) + { + if( m_bGlobalPatternChangePending ) + { + m_bGlobalPatternChangePending = false; + + SetGlobalPattern( m_GlobalPendingLight ); + + // cancel other changes on a global change + m_bPatternChangePending[ 0 ] = false; + m_bPatternChangePending[ 1 ] = false; + m_bPatternChangePending[ 2 ] = false; + m_bPatternPending = false; + } + + for( ch = 0; ch < CHANNELS; ch++ ) + { + // pat change trigger + if( m_bPatternChangePending[ ch ] ) + { + m_bPatternChangePending[ ch ] = false; + ChangePattern( ch, m_PendingLight[ ch ], false ); + } + } + } + } + + // global pattern pending change light blinky + if( m_bGlobalPatternChangePending ) + { + lights[ LIGHT_GLOBAL_PAT + m_GlobalPendingLight ].value = fpendinglight; + } + + // channel pattern pending change light blinky + if( m_bPatternPending ) + { + m_bPatternPending = false; + + for( ch = 0; ch < CHANNELS; ch++ ) + { + // pat change trigger + if( m_bPatternChangePending[ ch ] ) + { + m_bPatternPending = true; + lights[ LIGHT_PAT + (ch * PATTERNS) + m_PendingLight[ ch ] ].value = fpendinglight; + } + } + } + + lights[ LIGHT_RESET ].value -= lights[ LIGHT_RESET ].value / LIGHT_LAMBDA / engineGetSampleRate(); + + bPulse = m_PulseStep.process( 1.0 / engineGetSampleRate() ); + + // Step buttons + for( ch = 0; ch < CHANNELS; ch++ ) + { + bChTrig = false; + + for( stp = 0; stp < STEPS; stp++ ) + { + bGatesOn = ( m_bRunning && stp == m_CurrentStep && m_bStepStates[ m_PatternSelect[ ch ] ][ ch ][ stp ] ); + + if( m_GateMode == TRIGGER ) + bGatesOn = bGatesOn && bPulse; + else if( m_GateMode == RETRIGGER ) + bGatesOn = bGatesOn && !bPulse; + + if( bGatesOn ) + bChTrig = true; + + m_fLightStepLevels[ ch ][ stp ] -= m_fLightStepLevels[ ch ][ stp ] / LIGHT_LAMBDA / engineGetSampleRate(); + + lights[ LIGHT_STEP + (ch * STEPS) + stp ].value = m_bStepStates[ m_PatternSelect[ ch ] ][ ch ][ stp ] ? 1.0 - m_fLightStepLevels[ ch ][ stp ] : m_fLightStepLevels[ ch ][ stp ]; + } + + // trigger + outputs[ OUT_GATES + ch ].value = bChTrig ? CV_MAX : 0.0; + } + + // outputs + for( ch = 0; ch < CHANNELS; ch++ ) + { + // set CV + if( m_bRunning && m_bStepStates[ m_PatternSelect[ ch ] ][ ch ][ m_CurrentStep ] ) + { + // quantizie note + fout = params[ PARAM_SLIDERS + ( ch * STEPS ) + m_CurrentStep ].value; + octave = round( fout ); + fnote = round( ( fout - (float)octave ) * 12.0f ); + outputs[ OUT_CV + ch ].value = (float)octave + fnote/12.0f; + } + } + + if( m_bRunning ) + { + // external pattern select change + for( ch = 0; ch < CHANNELS; ch++ ) + { + // pat change trigger - ignore if already pending + if( m_SchTrigPatChange[ ch ].process( inputs[ INPUT_PAT_CHANGE + ch ].value ) && !m_bPatternChangePending[ ch ] ) + { + m_bPatternPending = true; + m_bPatternChangePending[ ch ] = true; + m_PendingLight[ ch ] = ( m_PatternSelect[ ch ] + 1 ) & 0xF; + } + } + + // global pat change trigger - ignore if already pending + if( m_SchTrigGlobalPatternSelect.process( inputs[ INPUT_GLOBAL_PAT_CHANGE ].value ) && !m_bGlobalPatternChangePending ) + { + m_bGlobalPatternChangePending = true; + m_GlobalPendingLight = ( m_GlobalSelect + 1 ) & 0xF; + } + } +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, Seq_3x16x16) { + Model *modelSeq_3x16x16 = Model::create( "mscHack", "Seq_3ch_16step", "SEQ 3 x 16", SEQUENCER_TAG, MULTIPLE_TAG ); + return modelSeq_3x16x16; +} diff --git a/plugins/community/repos/mscHack/src/Seq_Triad2.cpp b/plugins/community/repos/mscHack/src/Seq_Triad2.cpp new file mode 100644 index 00000000..27eed432 --- /dev/null +++ b/plugins/community/repos/mscHack/src/Seq_Triad2.cpp @@ -0,0 +1,1002 @@ +#include "mscHack.hpp" +//#include "mscHack_Controls.hpp" +#include "dsp/digital.hpp" +//#include "CLog.h" + +namespace rack_plugin_mscHack { + +#define nKEYBOARDS 3 +#define nKEYS 37 +#define nOCTAVESEL 5 +#define nPATTERNS 16 +#define nPHRASE_SAVES 8 +#define SEMI ( 1.0f / 12.0f ) + +typedef struct +{ + float fsemi; + +}KEYBOARD_KEY_STRUCT; + +typedef struct +{ + int note; + bool bTrigOff; + int pad[ 6 ]; + +}PATTERN_STRUCT; + +typedef struct +{ + bool bPending; + int phrase; +}PHRASE_CHANGE_STRUCT; + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct Seq_Triad2 : Module +{ +#define NO_COPY -1 + + enum ParamIds + { + PARAM_PAUSE, + PARAM_OCTAVES = PARAM_PAUSE + ( nKEYBOARDS ), + PARAM_GLIDE = PARAM_OCTAVES + (nOCTAVESEL * nKEYBOARDS), + PARAM_TRIGOFF = PARAM_GLIDE + ( nKEYBOARDS ), + nPARAMS = PARAM_TRIGOFF + ( nKEYBOARDS ) + }; + + enum InputIds + { + IN_PATTERN_TRIG, + IN_VOCT_OFF = IN_PATTERN_TRIG + ( nKEYBOARDS ), + IN_PROG_CHANGE = IN_VOCT_OFF + ( nKEYBOARDS ), + IN_CLOCK_RESET = IN_PROG_CHANGE + ( nKEYBOARDS ), + IN_GLOBAL_PAT_CLK, + nINPUTS + }; + + enum OutputIds + { + OUT_TRIG, + OUT_VOCTS = OUT_TRIG + nKEYBOARDS, + nOUTPUTS = OUT_VOCTS + nKEYBOARDS + }; + + CLog lg; + bool m_bInitialized = false; + + // octaves + int m_Octave[ nKEYBOARDS ] = {}; + float m_fCvStartOut[ nKEYBOARDS ] = {}; + float m_fCvEndOut[ nKEYBOARDS ] = {}; + + // patterns + int m_CurrentPattern[ nKEYBOARDS ] = {}; + PATTERN_STRUCT m_PatternNotes[ nKEYBOARDS ][ nPHRASE_SAVES ][ nPATTERNS ] = {}; + SchmittTrigger m_SchTrigPatternSelectInput[ nKEYBOARDS ]; + PatternSelectStrip *m_pPatternSelect[ nKEYBOARDS ] = {}; + + int m_CopySrc = NO_COPY; + + // phrase save + int m_CurrentPhrase[ nKEYBOARDS ] = {}; + PHRASE_CHANGE_STRUCT m_PhrasePending[ nKEYBOARDS ] = {}; + SchmittTrigger m_SchTrigPhraseSelect[ nKEYBOARDS ] = {}; + int m_PhrasesUsed[ nKEYBOARDS ] = {0}; + PatternSelectStrip *m_pPhraseSelect[ nKEYBOARDS ] = {}; + + // number of steps + int m_nSteps[ nKEYBOARDS ][ nPHRASE_SAVES ] = {}; + + // pause button + bool m_bPause[ nKEYBOARDS ] = {}; + + // triggers + bool m_bTrig[ nKEYBOARDS ] = {}; + PulseGenerator m_gatePulse[ nKEYBOARDS ]; + + // global triggers + SchmittTrigger m_SchTrigGlobalClkReset; + SchmittTrigger m_SchTrigGlobalPatChange; + bool m_GlobalClkResetPending = false; + + // glide + float m_fglideInc[ nKEYBOARDS ] = {}; + int m_glideCount[ nKEYBOARDS ] = {}; + float m_fglide[ nKEYBOARDS ] = {}; + float m_fLastNotePlayed[ nKEYBOARDS ]; + bool m_bWasLastNotePlayed[ nKEYBOARDS ] = {}; + + Keyboard_3Oct_Widget *pKeyboardWidget[ nKEYBOARDS ]; + float m_fKeyNotes[ 37 ]; + + float m_VoctOffsetIn[ nKEYBOARDS ] = {}; + + // buttons + MyLEDButtonStrip *m_pButtonOctaveSelect[ nKEYBOARDS ] = {}; + MyLEDButton *m_pButtonPause[ nKEYBOARDS ] = {}; + MyLEDButton *m_pButtonTrig[ nKEYBOARDS ] = {}; + MyLEDButton *m_pButtonCopy[ nKEYBOARDS ] = {}; + + // Contructor + Seq_Triad2() : Module( nPARAMS, nINPUTS, nOUTPUTS, 0 ) + { + int i; + + for( i = 0; i < 37; i++ ) + m_fKeyNotes[ i ] = (float)i * SEMI; + + } + + // Overrides + void step() override; + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onRandomize() override; + void onReset() override; + + void SetPhraseSteps( int kb, int nSteps ); + void SetSteps( int kb, int steps ); + void SetKey( int kb ); + void SetOut( int kb ); + void ChangePattern( int kb, int index, bool bForce, bool bPlay ); + void ChangePhrase( int kb, int index, bool bForce ); + void SetPendingPhrase( int kb, int phrase ); + void Copy( int kb, bool bOn ); +}; + +//----------------------------------------------------- +// Seq_Triad2_OctSelect +//----------------------------------------------------- +void Seq_Triad2_OctSelect( void *pClass, int id, int nbutton, bool bOn ) +{ + Seq_Triad2 *mymodule; + mymodule = (Seq_Triad2*)pClass; + + mymodule->m_Octave[ id ] = nbutton; + mymodule->SetOut( id ); +} + +//----------------------------------------------------- +// Seq_Triad2_Pause +//----------------------------------------------------- +void Seq_Triad2_Pause( void *pClass, int id, bool bOn ) +{ + Seq_Triad2 *mymodule; + mymodule = (Seq_Triad2*)pClass; + mymodule->m_bPause[ id ] = !mymodule->m_bPause[ id ]; +} + +//----------------------------------------------------- +// Seq_Triad2_Trig +//----------------------------------------------------- +void Seq_Triad2_Trig( void *pClass, int id, bool bOn ) +{ + Seq_Triad2 *mymodule; + mymodule = (Seq_Triad2*)pClass; + mymodule->m_PatternNotes[ id ][ mymodule->m_CurrentPhrase[ id ] ][ mymodule->m_CurrentPattern[ id ] ].bTrigOff = !mymodule->m_PatternNotes[ id ][ mymodule->m_CurrentPhrase[ id ] ][ mymodule->m_CurrentPattern[ id ] ].bTrigOff; +} + +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- +void Seq_Triad2_Widget_NoteChangeCallback ( void *pClass, int kb, int notepressed, int *pnotes, bool bOn, int button ) +{ + Seq_Triad2 *mymodule = (Seq_Triad2 *)pClass; + + if( !pClass ) + return; + + // don't allow program unless paused + if( button == 1 && !mymodule->m_bPause[ kb ] ) + return; + + // right click advance step + if( button == 1 ) + { + mymodule->ChangePattern( kb, mymodule->m_CurrentPattern[ kb ] + 1, true, false ); + mymodule->m_PatternNotes[ kb ][ mymodule->m_CurrentPhrase[ kb ] ][ mymodule->m_CurrentPattern[ kb ] ].note = notepressed; + mymodule->SetKey( kb ); + } + else + mymodule->m_PatternNotes[ kb ][ mymodule->m_CurrentPhrase[ kb ] ][ mymodule->m_CurrentPattern[ kb ] ].note = notepressed; + + mymodule->SetOut( kb ); +} + +//----------------------------------------------------- +// Procedure: PatternChangeCallback +// +//----------------------------------------------------- +void Seq_Triad2_Widget_PatternChangeCallback ( void *pClass, int kb, int pat, int max ) +{ + Seq_Triad2 *mymodule = (Seq_Triad2 *)pClass; + + if( !mymodule || !mymodule->m_bInitialized ) + return; + + if( mymodule->m_CurrentPattern[ kb ] != pat ) + mymodule->ChangePattern( kb, pat, false, true ); + else if( mymodule->m_nSteps[ kb ][ mymodule->m_CurrentPhrase[ kb ] ] != max ) + mymodule->SetSteps( kb, max ); +} + +//----------------------------------------------------- +// Procedure: PhraseChangeCallback +// +//----------------------------------------------------- +void Seq_Triad2_Widget_PhraseChangeCallback ( void *pClass, int kb, int pat, int max ) +{ + Seq_Triad2 *mymodule = (Seq_Triad2 *)pClass; + + if( !mymodule || !mymodule->m_bInitialized ) + return; + + if( mymodule->m_PhrasesUsed[ kb ] != max ) + { + mymodule->SetPhraseSteps( kb, max ); + } + else if( mymodule->m_CurrentPhrase[ kb ] == pat && mymodule->m_bPause[ kb ] && mymodule->m_CopySrc != NO_COPY ) + { + mymodule->ChangePhrase( kb, pat, true ); + } + else if( mymodule->m_CurrentPhrase[ kb ] != pat ) + { + if( !mymodule->m_bPause[ kb ] && mymodule->inputs[ Seq_Triad2::IN_PATTERN_TRIG + kb ].active ) + mymodule->SetPendingPhrase( kb, pat ); + else + mymodule->ChangePhrase( kb, pat, false ); + + } +} + +//----------------------------------------------------- +// MyLEDButton_Copy +//----------------------------------------------------- +void MyLEDButton_Copy( void *pClass, int id, bool bOn ) +{ + Seq_Triad2 *mymodule; + mymodule = (Seq_Triad2*)pClass; + mymodule->Copy( id, bOn ); +} + +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- + +struct Seq_Triad2_Widget : ModuleWidget { + Seq_Triad2_Widget( Seq_Triad2 *module ); +}; + +Seq_Triad2_Widget::Seq_Triad2_Widget( Seq_Triad2 *module ) : ModuleWidget(module) +{ + int kb, x, x2, y, y2; + + box.size = Vec( 15*25, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/TriadSequencer2.svg"))); + addChild(panel); + } + + //module->lg.Open("TriadSequencer2.txt"); + + //---------------------------------------------------- + // Keyboard Keys + y = 21; + x = 11; + + for( kb = 0; kb < nKEYBOARDS; kb++ ) + { + // pause button + module->m_pButtonPause[ kb ] = new MyLEDButton( x + 60, y + 4, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, kb, module, Seq_Triad2_Pause ); + addChild( module->m_pButtonPause[ kb ] ); + + // trig button + module->m_pButtonTrig[ kb ] = new MyLEDButton( x + 314, y + 5, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 255, 0, 0 ), MyLEDButton::TYPE_SWITCH, kb, module, Seq_Triad2_Trig ); + addChild( module->m_pButtonTrig[ kb ] ); + + // glide knob + addParam( ParamWidget::create( Vec( x + 235, y + 86 ), module, Seq_Triad2::PARAM_GLIDE + kb, 0.0, 1.0, 0.0 ) ); + + module->m_pButtonCopy[ kb ] = new MyLEDButton( x + 194, y + 89, 11, 11, 8.0, DWRGB( 180, 180, 180 ), DWRGB( 0, 244, 244 ), MyLEDButton::TYPE_SWITCH, kb, module, MyLEDButton_Copy ); + addChild( module->m_pButtonCopy[ kb ] ); + + x2 = x + 274; + + // octave select + module->m_pButtonOctaveSelect[ kb ] = new MyLEDButtonStrip( x2, y + 90, 11, 11, 3, 8.0, nOCTAVESEL, false, DWRGB( 180, 180, 180 ), DWRGB( 0, 255, 255 ), MyLEDButtonStrip::TYPE_EXCLUSIVE, kb, module, Seq_Triad2_OctSelect ); + addChild( module->m_pButtonOctaveSelect[ kb ] ); + + // keyboard widget + module->pKeyboardWidget[ kb ] = new Keyboard_3Oct_Widget( x + 39, y + 19, 1, kb, DWRGB( 255, 128, 64 ), module, Seq_Triad2_Widget_NoteChangeCallback, &module->lg ); + addChild( module->pKeyboardWidget[ kb ] ); + + // pattern selects + module->m_pPatternSelect[ kb ] = new PatternSelectStrip( x + 79, y + 1, 9, 7, DWRGB( 255, 128, 64 ), DWRGB( 128, 64, 0 ), DWRGB( 255, 0, 128 ), DWRGB( 128, 0, 64 ), nPATTERNS, kb, module, Seq_Triad2_Widget_PatternChangeCallback ); + addChild( module->m_pPatternSelect[ kb ] ); + + // phrase selects + module->m_pPhraseSelect[ kb ] = new PatternSelectStrip( x + 79, y + 86, 9, 7, DWRGB( 255, 255, 0 ), DWRGB( 128, 128, 64 ), DWRGB( 0, 255, 255 ), DWRGB( 0, 128, 128 ), nPHRASE_SAVES, kb, module, Seq_Triad2_Widget_PhraseChangeCallback ); + addChild( module->m_pPhraseSelect[ kb ] ); + + x2 = x + 9; + y2 = y + 4; + // prog change trigger + addInput(Port::create( Vec( x2, y2 ), Port::INPUT, module, Seq_Triad2::IN_PATTERN_TRIG + kb ) ); y2 += 40; + + // VOCT offset input + addInput(Port::create( Vec( x2, y2 ), Port::INPUT, module, Seq_Triad2::IN_VOCT_OFF + kb ) ); y2 += 40; + + // prog change trigger + addInput(Port::create( Vec( x2, y2 ), Port::INPUT, module, Seq_Triad2::IN_PROG_CHANGE + kb ) ); + + // outputs + x2 = x + 330; + addOutput(Port::create( Vec( x2, y + 27 ), Port::OUTPUT, module, Seq_Triad2::OUT_VOCTS + kb ) ); + addOutput(Port::create( Vec( x2, y + 68 ), Port::OUTPUT, module, Seq_Triad2::OUT_TRIG + kb ) ); + + y += 111; + } + + // reset inputs + y2 = 357; + addInput(Port::create( Vec( x + 89, y2 ), Port::INPUT, module, Seq_Triad2::IN_CLOCK_RESET ) ); + addInput(Port::create( Vec( x + 166, y2 ), Port::INPUT, module, Seq_Triad2::IN_GLOBAL_PAT_CLK ) ); + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + module->m_bInitialized = true; + + module->onReset(); +} + +//----------------------------------------------------- +// Procedure: reset +// +//----------------------------------------------------- +void Seq_Triad2::onReset() +{ + if( !m_bInitialized ) + return; + + for( int kb = 0; kb < nKEYBOARDS; kb++ ) + m_pButtonOctaveSelect[ kb ]->Set( 0, true ); + + memset( m_fCvStartOut, 0, sizeof(m_fCvStartOut) ); + memset( m_fCvEndOut, 0, sizeof(m_fCvEndOut) ); + memset( m_PatternNotes, 0, sizeof(m_PatternNotes) ); + + for( int kb = 0; kb < nKEYBOARDS; kb++ ) + { + for( int pat = 0; pat < nPHRASE_SAVES; pat++ ) + m_nSteps[ kb ][ pat ] = 3; + + SetPhraseSteps( kb, 3 ); + ChangePattern( kb, 0, true, true ); + ChangePhrase( kb, 0, true ); + } +} + +//----------------------------------------------------- +// Procedure: randomize +// +//----------------------------------------------------- +const int keyscalenotes[ 7 ] = { 0, 2, 4, 5, 7, 9, 11}; +const int keyscalenotes_minor[ 7 ] = { 0, 2, 3, 5, 7, 9, 11}; +void Seq_Triad2::onRandomize() +{ + int kb, pat, phrase, basekey, note; + + for( int kb = 0; kb < nKEYBOARDS; kb++ ) + m_pButtonOctaveSelect[ kb ]->Set( 0, true ); + + memset( m_fCvStartOut, 0, sizeof(m_fCvStartOut) ); + memset( m_fCvEndOut, 0, sizeof(m_fCvEndOut) ); + memset( m_PatternNotes, 0, sizeof(m_PatternNotes) ); + + basekey = (int)(randomUniform() * 24.0); + + for( kb = 0; kb < nKEYBOARDS; kb++ ) + { + m_Octave[ kb ] = (int)( randomUniform() * 4.0 ); + + for( pat = 0; pat < nPATTERNS; pat++ ) + { + for( phrase = 0; phrase < nPHRASE_SAVES; phrase++ ) + { + if( randomUniform() > 0.7 ) + note = keyscalenotes_minor[ (int)(randomUniform() * 7.0 ) ]; + else + note = keyscalenotes[ (int)(randomUniform() * 7.0 ) ]; + + m_PatternNotes[ kb ][ phrase ][ pat ].bTrigOff = ( randomUniform() < 0.10 ); + m_PatternNotes[ kb ][ phrase ][ pat ].note = basekey + note; + } + } + + ChangePattern( kb, 0, true, true ); + } +} + +//----------------------------------------------------- +// Procedure: SetPhraseSteps +// +//----------------------------------------------------- +void Seq_Triad2::SetPhraseSteps( int kb, int nSteps ) +{ + if( nSteps < 0 || nSteps >= nPHRASE_SAVES ) + nSteps = 0; + + m_PhrasesUsed[ kb ] = nSteps; +} + +//----------------------------------------------------- +// Procedure: SetSteps +// +//----------------------------------------------------- +void Seq_Triad2::SetSteps( int kb, int nSteps ) +{ + if( nSteps < 0 || nSteps >= nPATTERNS ) + nSteps = 0; + + m_nSteps[ kb ][ m_CurrentPhrase[ kb ] ] = nSteps; +} + +//----------------------------------------------------- +// Procedure: Copy +// +//----------------------------------------------------- +void Seq_Triad2::Copy( int kb, bool bOn ) +{ + if( kb < 0 || kb >= nKEYBOARDS ) + return; + + if( !m_bPause[ kb ] || !bOn || m_CopySrc != NO_COPY ) + { + if( m_CopySrc != NO_COPY ) + m_pButtonCopy[ m_CopySrc ]->Set( false ); + + m_CopySrc = NO_COPY; + m_pButtonCopy[ kb ]->Set( false ); + } + else if( bOn ) + { + m_CopySrc = kb; + } +} + +//----------------------------------------------------- +// Procedure: SetOut +// +//----------------------------------------------------- +void Seq_Triad2::SetOut( int kb ) +{ + int note; + float foct; + + if( kb < 0 || kb >= nKEYBOARDS ) + return; + + // end glide note (current pattern note) + foct = (float)m_Octave[ kb ]; + + note = m_PatternNotes[ kb ][ m_CurrentPhrase[ kb ] ][ m_CurrentPattern[ kb ] ].note; + + if( note > 36 || note < 0 ) + note = 0; + + m_fCvEndOut[ kb ] = foct + m_fKeyNotes[ note ] + m_VoctOffsetIn[ kb ]; + + // start glide note (last pattern note) + if( m_bWasLastNotePlayed[ kb ] ) + { + m_fCvStartOut[ kb ] = m_fLastNotePlayed[ kb ] + m_VoctOffsetIn[ kb ]; + } + else + { + m_bWasLastNotePlayed[ kb ] = true; + m_fCvStartOut[ kb ] = m_fCvEndOut[ kb ] + m_VoctOffsetIn[ kb ]; + } + + m_fLastNotePlayed[ kb ] = m_fCvEndOut[ kb ] + m_VoctOffsetIn[ kb ]; + + // glide time ( max glide = 0.5 seconds ) + m_glideCount[ kb ] = 1 + (int)( ( params[ PARAM_GLIDE + kb ].value * 0.5 ) * engineGetSampleRate()); + + m_fglideInc[ kb ] = 1.0 / (float)m_glideCount[ kb ]; + + m_fglide[ kb ] = 1.0; + + // always trig on pause + if( m_bPause[ kb ] ) + m_bTrig[ kb ] = true; + else if( !m_PatternNotes[ kb ][ m_CurrentPhrase[ kb ] ][ m_CurrentPattern[ kb ] ].bTrigOff ) + m_bTrig[ kb ] = true; + else + m_bTrig[ kb ] = false; +} + +//----------------------------------------------------- +// Procedure: SetKey +// +//----------------------------------------------------- +void Seq_Triad2::SetKey( int kb ) +{ + pKeyboardWidget[ kb ]->setkey( &m_PatternNotes[ kb ][ m_CurrentPhrase[ kb ] ][ m_CurrentPattern[ kb ] ].note ); +} + +//----------------------------------------------------- +// Procedure: SetPendingPhrase +// +//----------------------------------------------------- +void Seq_Triad2::SetPendingPhrase( int kb, int phraseIn ) +{ + int phrase; + + if( phraseIn < 0 || phraseIn >= nPHRASE_SAVES ) + phrase = ( m_CurrentPhrase[ kb ] + 1 ) & 0x7; + else + phrase = phraseIn; + + if( phrase > m_PhrasesUsed[ kb ] ) + phrase = 0; + + m_PhrasePending[ kb ].bPending = true; + m_PhrasePending[ kb ].phrase = phrase; + m_pPhraseSelect[ kb ]->SetPat( m_CurrentPhrase[ kb ], false ); + m_pPhraseSelect[ kb ]->SetPat( phrase, true ); +} + +//----------------------------------------------------- +// Procedure: ChangePhrase +// +//----------------------------------------------------- +void Seq_Triad2::ChangePhrase( int kb, int index, bool bForce ) +{ + if( kb < 0 || kb >= nKEYBOARDS ) + return; + + if( !bForce && index == m_CurrentPhrase[ kb ] ) + return; + + if( index < 0 ) + index = nPHRASE_SAVES - 1; + else if( index >= nPHRASE_SAVES ) + index = 0; + + if( m_CopySrc != NO_COPY ) + { + // do not copy if we are not paused + if( m_bPause[ kb ] ) + { + memcpy( m_PatternNotes[ kb ][ index ], m_PatternNotes[ m_CopySrc ][ m_CurrentPhrase[ m_CopySrc ] ], sizeof(PATTERN_STRUCT) * nPATTERNS ); + m_pButtonCopy[ m_CopySrc ]->Set( false ); + m_nSteps[ kb ][ index ] = m_nSteps[ m_CopySrc ][ m_CurrentPhrase[ m_CopySrc ] ]; + m_CopySrc = NO_COPY; + } + } + + m_CurrentPhrase[ kb ] = index; + + m_pPhraseSelect[ kb ]->SetPat( index, false ); + m_pPhraseSelect[ kb ]->SetMax( m_PhrasesUsed[ kb ] ); + m_pPatternSelect[ kb ]->SetMax( m_nSteps[ kb ][ index ] ); + + // set keyboard key + SetKey( kb ); + + m_pButtonTrig[ kb ]->Set( m_PatternNotes[ kb ][ m_CurrentPhrase[ kb ] ][ m_CurrentPattern[ kb ] ].bTrigOff ); + + // change octave light + m_pButtonOctaveSelect[ kb ]->Set( m_Octave[ kb ], true ); + + // set output note + SetOut( kb ); +} + +//----------------------------------------------------- +// Procedure: ChangePattern +// +//----------------------------------------------------- +void Seq_Triad2::ChangePattern( int kb, int index, bool bForce, bool bPlay ) +{ + if( kb < 0 || kb >= nKEYBOARDS ) + return; + + if( !bForce && index == m_CurrentPattern[ kb ] ) + return; + + if( index < 0 ) + index = nPATTERNS - 1; + else if( index >= nPATTERNS ) + index = 0; + + // update octave offset immediately when not running + m_VoctOffsetIn[ kb ] = inputs[ IN_VOCT_OFF + kb ].normalize( 0.0 ); + + m_CurrentPattern[ kb ] = index; + + m_pPatternSelect[ kb ]->SetPat( index, false ); + + // set keyboard key + SetKey( kb ); + + m_pButtonTrig[ kb ]->Set( m_PatternNotes[ kb ][ m_CurrentPhrase[ kb ] ][ m_CurrentPattern[ kb ] ].bTrigOff ); + + // change octave light + m_pButtonOctaveSelect[ kb ]->Set( m_Octave[ kb ], true ); + + // set outputted note + if( bPlay ) + SetOut( kb ); +} + +//----------------------------------------------------- +// Procedure: +// +//----------------------------------------------------- +json_t *Seq_Triad2::toJson() +{ + int *pint; + bool *pbool; + json_t *gatesJ; + json_t *rootJ = json_object(); + + // pauses + pbool = &m_bPause[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < nKEYBOARDS; i++) + { + json_t *gateJ = json_integer( (int)pbool[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "m_bPause", gatesJ ); + + // number of steps + pint = (int*)&m_nSteps[ 0 ][ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < nKEYBOARDS * nPHRASE_SAVES; i++) + { + json_t *gateJ = json_integer( pint[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "m_nSteps", gatesJ ); + + // octaves + pint = (int*)&m_Octave[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < nKEYBOARDS; i++) + { + json_t *gateJ = json_integer( pint[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "m_Octave", gatesJ ); + + // phrase select + pint = (int*)&m_CurrentPhrase[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < nKEYBOARDS; i++) + { + json_t *gateJ = json_integer( pint[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "m_CurrentPhrase", gatesJ ); + + // patterns + pint = (int*)&m_PatternNotes[ 0 ][ 0 ][ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < (nPHRASE_SAVES * nPATTERNS * nKEYBOARDS * 8); i++) + { + json_t *gateJ = json_integer( pint[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "m_PatternNotes", gatesJ ); + + + // phrase used + pint = (int*)&m_PhrasesUsed[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < nKEYBOARDS; i++) + { + json_t *gateJ = json_integer( pint[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "m_PhrasesUsed", gatesJ ); + + // current pattern + pint = (int*)&m_CurrentPattern[ 0 ]; + + gatesJ = json_array(); + + for (int i = 0; i < nKEYBOARDS; i++) + { + json_t *gateJ = json_integer( pint[ i ] ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "m_CurrentPattern", gatesJ ); + + return rootJ; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void Seq_Triad2::fromJson(json_t *rootJ) +{ + bool *pbool; + int *pint; + int i; + json_t *StepsJ; + + // pauses + pbool = &m_bPause[ 0 ]; + StepsJ = json_object_get( rootJ, "m_bPause" ); + + if (StepsJ) + { + for ( i = 0; i < nKEYBOARDS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pbool[ i ] = json_integer_value( gateJ ); + } + } + + // number of steps + pint = (int*)&m_nSteps[ 0 ][ 0 ]; + StepsJ = json_object_get( rootJ, "m_nSteps" ); + + if (StepsJ) + { + for ( i = 0; i < nKEYBOARDS * nPHRASE_SAVES; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pint[ i ] = json_integer_value( gateJ ); + } + } + + // octaves + pint = (int*)&m_Octave[ 0 ]; + StepsJ = json_object_get( rootJ, "m_Octave" ); + + if (StepsJ) + { + for ( i = 0; i < nKEYBOARDS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pint[ i ] = json_integer_value( gateJ ); + } + } + + // phrase select + pint = (int*)&m_CurrentPhrase[ 0 ]; + StepsJ = json_object_get( rootJ, "m_CurrentPhrase" ); + + if (StepsJ) + { + for ( i = 0; i < nKEYBOARDS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pint[ i ] = json_integer_value( gateJ ); + } + } + + // all patterns and phrases + pint = (int*)&m_PatternNotes[ 0 ][ 0 ][ 0 ]; + + StepsJ = json_object_get( rootJ, "m_PatternNotes" ); + + if (StepsJ) + { + for ( i = 0; i < (nPHRASE_SAVES * nPATTERNS * nKEYBOARDS * 8); i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pint[ i ] = json_integer_value( gateJ ); + } + } + + // phrase steps + pint = (int*)&m_PhrasesUsed[ 0 ]; + + StepsJ = json_object_get( rootJ, "m_PhrasesUsed" ); + + if (StepsJ) + { + for ( i = 0; i < nKEYBOARDS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pint[ i ] = json_integer_value( gateJ ); + } + } + + // current pattern + pint = (int*)&m_CurrentPattern[ 0 ]; + + StepsJ = json_object_get( rootJ, "m_CurrentPattern" ); + + if (StepsJ) + { + for ( i = 0; i < nKEYBOARDS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + pint[ i ] = json_integer_value( gateJ ); + } + } + + for( i = 0; i < nKEYBOARDS; i++ ) + { + m_pPhraseSelect[ i ]->SetMax( m_PhrasesUsed[ i ] ); + m_pPhraseSelect[ i ]->SetPat( m_CurrentPhrase[ i ], false ); + + m_pPatternSelect[ i ]->SetMax( m_nSteps[ i ][ m_CurrentPhrase[ i ] ] ); + m_pPatternSelect[ i ]->SetPat( m_CurrentPattern[ i ], false ); + + m_pButtonPause[ i ]->Set( m_bPause[ i ] ); + + SetPhraseSteps( i, m_PhrasesUsed[ i ] ); + ChangePhrase( i, m_CurrentPhrase[ i ], true ); + ChangePattern( i, m_CurrentPattern[ i ], true, false ); + } +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +#define LIGHT_LAMBDA ( 0.065f ) +void Seq_Triad2::step() +{ + int kb, useclock; + bool bGlobalPatChange = false, bGlobalClkTriggered = false, PatTrig[ nKEYBOARDS ] = {}; + + if( !m_bInitialized ) + return; + + // global phrase change trigger + if( inputs[ IN_GLOBAL_PAT_CLK ].active ) + { + if( m_SchTrigGlobalPatChange.process( inputs[ IN_GLOBAL_PAT_CLK ].value ) ) + bGlobalPatChange = true; + } + + // global clock reset + if( inputs[ IN_CLOCK_RESET ].active ) + { + if( m_SchTrigGlobalClkReset.process( inputs[ IN_CLOCK_RESET ].value ) ) + m_GlobalClkResetPending = true; + } + + // get trigs + for( kb = 0; kb < nKEYBOARDS; kb++ ) + PatTrig[ kb ] = m_SchTrigPatternSelectInput[ kb ].process( inputs[ IN_PATTERN_TRIG + kb ].value ); + + // process triggered phrase changes + for( kb = 0; kb < nKEYBOARDS; kb++ ) + { + useclock = kb; + + // if no keyboard clock active then use kb 0's clock + if( !inputs[ IN_PATTERN_TRIG + kb ].active && inputs[ IN_PATTERN_TRIG + 0 ].active ) + useclock = 0; + + // phrase change trigger + if( bGlobalPatChange && !m_bPause[ kb ] && inputs[ IN_PATTERN_TRIG + useclock ].active ) + { + SetPendingPhrase( kb, -1 ); + } + else if( inputs[ IN_PROG_CHANGE + kb ].active && !m_bPause[ kb ] && inputs[ IN_PATTERN_TRIG + useclock ].active ) + { + if( m_SchTrigPhraseSelect[ kb ].process( inputs[ IN_PROG_CHANGE + kb ].value ) ) + SetPendingPhrase( kb, -1 ); + } + + // pat change trigger - ignore if already pending + if( inputs[ IN_PATTERN_TRIG + useclock ].active && !m_bPause[ kb ] ) + { + if( PatTrig[ useclock ] ) + { + if( m_GlobalClkResetPending ) + { + bGlobalClkTriggered = true; + m_CurrentPattern[ kb ] = -1; + } + else if( m_CurrentPattern[ kb ] >= ( m_nSteps[ kb ][ m_CurrentPhrase[ kb ] ] ) ) + { + m_CurrentPattern[ kb ] = (nPATTERNS - 1); + } + + ChangePattern( kb, m_CurrentPattern[ kb ] + 1, true, true ); + + if( m_CurrentPattern[ kb ] == 0 ) + { + if( m_PhrasePending[ kb ].bPending ) + { + m_PhrasePending[ kb ].bPending = false; + ChangePhrase( kb, m_PhrasePending[ kb ].phrase, false ); + } + } + } + } + else + { + // resolve any left over phrase triggers + if( m_PhrasePending[ kb ].bPending ) + { + m_PhrasePending[ kb ].bPending = false; + ChangePhrase( kb, m_PhrasePending[ kb ].phrase, false ); + } + } + + if( m_bTrig[ kb ] ) + { + m_bTrig[ kb ] = false; + m_gatePulse[ kb ].trigger(1e-3); + } + + outputs[ OUT_TRIG + kb ].value = m_gatePulse[ kb ].process( 1.0 / engineGetSampleRate() ) ? CV_MAX : 0.0; + + if( --m_glideCount[ kb ] > 0 ) + m_fglide[ kb ] -= m_fglideInc[ kb ]; + else + m_fglide[ kb ] = 0.0; + + outputs[ OUT_VOCTS + kb ].value = ( m_fCvStartOut[ kb ] * m_fglide[ kb ] ) + ( m_fCvEndOut[ kb ] * ( 1.0 - m_fglide[ kb ] ) ); + } + + if( bGlobalClkTriggered ) + m_GlobalClkResetPending = false; +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, Seq_Triad2) { + Model *modelSeq_Triad2 = Model::create( "mscHack", "TriadSeq2", "SEQ Triad 2", SEQUENCER_TAG, MULTIPLE_TAG ); + return modelSeq_Triad2; +} diff --git a/plugins/community/repos/mscHack/src/StepDelay.cpp b/plugins/community/repos/mscHack/src/StepDelay.cpp new file mode 100644 index 00000000..4404e15a --- /dev/null +++ b/plugins/community/repos/mscHack/src/StepDelay.cpp @@ -0,0 +1,523 @@ +#include "mscHack.hpp" +//#include "mscHack_Controls.hpp" +#include "dsp/digital.hpp" +//#include "CLog.h" + +namespace rack_plugin_mscHack { + +#define nDELAYS 8 +#define nSTEPS 4 +#define nBUFFLEN 0x80000 +#define MAX_nWAVES 7 + +typedef struct +{ + // track in clk bpm + //SLIDING_AVG_STRUCT Avg; + int tickcount; + float ftickspersec; + float fbpm; + + // track sync tick + float fsynclen; + float fsynccount; + + bool bClockReset; + +}MAIN_SYNC_CLOCK; + +typedef struct +{ + float lp1[ 2 ] = {}, bp1[ 2 ] = {}; + +}FILTER_PARAM_STRUCT; + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct StepDelay : Module +{ + enum ParamIds + { + PARAM_FILTER_MODE, + PARAM_FILTERF, + PARAM_FILTERQ, + PARAM_LEVEL, + PARAM_PAN = (PARAM_LEVEL + nSTEPS ), + PARAM_FB = (PARAM_PAN + nSTEPS ), + PARAM_DELAY = (PARAM_FB + nSTEPS ), + PARAM_MIX = (PARAM_DELAY + nSTEPS ), + nPARAMS + }; + + enum InputIds + { + IN_CLOCK, + IN_CLK_RESET, + IN_AUDIOL, + IN_AUDIOR, + IN_FILTER_MOD, + nINPUTS + }; + + enum OutputIds + { + OUT_AUDIOL, + OUT_AUDIOR, + nOUTPUTS + }; + + enum FILTER_TYPES + { + FILTER_OFF, + FILTER_LP, + FILTER_HP, + FILTER_BP, + FILTER_NT + }; + + CLog lg; + bool m_bInitialized = false; + + // Contructor + StepDelay() : Module(nPARAMS, nINPUTS, nOUTPUTS, 0){} + + // clock + SchmittTrigger m_SchTrigClk; + MAIN_SYNC_CLOCK m_Clock; + + // global triggers + SchmittTrigger m_SchTrigGlobalClkReset; + bool m_GlobalClkResetPending = false; + + Label *m_pTextLabel[ nSTEPS ] = {}; + + MyLEDButtonStrip *m_pButtonLenMod[ nSTEPS ] = {}; + int m_lenmod[ nSTEPS ] = {0}; + + FILTER_PARAM_STRUCT m_Filter = {}; + float m_fCutoff; + +#define L 0 +#define R 1 + + // buffers + float m_fBuffer[ 2 ][ nBUFFLEN ] = {}; + int m_BufferInOffset = 0; + int m_BufferOutOffset[ nSTEPS ] = {0}; + +//----------------------------------------------------- +// MyDelayKnob +//----------------------------------------------------- +struct MyDelayKnob : Knob_Yellow3_20_Snap +{ + StepDelay *mymodule; + + void onChange( EventChange &e ) override + { + mymodule = (StepDelay*)module; + + if( mymodule ) + { + mymodule->CalcDelays(); + } + + RoundKnob::onChange( e ); + } +}; + + // Overrides + void step() override; + void JsonParams( bool bTo, json_t *root); + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onRandomize() override; + void onReset() override; + + void ChangeFilterCutoff( float cutfreq ); + void Filter( float *InL, float *InR ); + void CalcDelays( void ); + + void BuildWaves( void ); + float GetWave( int type, float phase ); +}; + +//----------------------------------------------------- +// Procedure: LenModCallback +//----------------------------------------------------- +void LenModCallback( void *pClass, int id, int nbutton, bool bOn ) +{ + StepDelay *mymodule; + mymodule = (StepDelay*)pClass; + + if( mymodule ) + { + mymodule->m_lenmod[ id ] = nbutton; + mymodule->CalcDelays(); + } +} + +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- + +struct StepDelay_Widget : ModuleWidget { + StepDelay_Widget( StepDelay *module ); +}; + +StepDelay_Widget::StepDelay_Widget( StepDelay *module ) : ModuleWidget(module) +{ + int steps, x, y; + + box.size = Vec( 15*14, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/StepDelay.svg"))); + addChild(panel); + } + + //module->lg.Open("StepDelay.txt"); + + // Clock Inputs + addInput(Port::create( Vec( 14, 23 ), Port::INPUT, module, StepDelay::IN_CLOCK ) ); + + // Audio Inputs + addInput(Port::create( Vec( 14, 70 ), Port::INPUT, module, StepDelay::IN_AUDIOL ) ); + addInput(Port::create( Vec( 40, 70 ), Port::INPUT, module, StepDelay::IN_AUDIOR ) ); + + // Audio Outputs + addOutput(Port::create( Vec( 14, 109 ), Port::OUTPUT, module, StepDelay::OUT_AUDIOL ) ); + addOutput(Port::create( Vec( 40, 109 ), Port::OUTPUT, module, StepDelay::OUT_AUDIOR ) ); + + // Mix + addParam(ParamWidget::create( Vec( 11, 149 ), module, StepDelay::PARAM_MIX, 0.0, 1.0, 0.5 ) ); + + // Filter knobs + addParam(ParamWidget::create( Vec( 93, 58 ), module, StepDelay::PARAM_FILTERF, 0.0, 1.0, 0.0 ) ); + addParam(ParamWidget::create( Vec( 144, 77 ), module, StepDelay::PARAM_FILTERQ, 0.0, 1.0, 0.0 ) ); + addParam(ParamWidget::create( Vec( 139, 57 ), module, StepDelay::PARAM_FILTER_MODE, 0.0, 4.0, 0.0 ) ); + addInput(Port::create( Vec( 104, 103 ), Port::INPUT, module, StepDelay::IN_FILTER_MOD ) ); + + x = 93; + y = 173; + + for( steps = 0; steps < nSTEPS; steps++ ) + { + y = 173; + + // step knobs + addParam(ParamWidget::create( Vec( x , y ), module, StepDelay::PARAM_LEVEL + steps, 0.0, 1.0, 0.5 ) ); + y += 28; + addParam(ParamWidget::create( Vec( x , y ), module, StepDelay::PARAM_PAN + steps, -1.0, 1.0, 0.0 ) ); + y += 28; + addParam(ParamWidget::create( Vec( x , y ), module, StepDelay::PARAM_FB + steps, 0.0, 1.0, 0.0 ) ); + y += 28; + + addParam(ParamWidget::create( Vec( x , y ), module, StepDelay::PARAM_DELAY + steps, 0.0, (float)(nDELAYS - 1), 0.0 ) ); + + module->m_pTextLabel[ steps ] = new Label(); + module->m_pTextLabel[ steps ]->box.pos = Vec( x - 9, y + 18 ); + module->m_pTextLabel[ steps ]->text = "Delay"; + //module->m_pTextLabel[ steps ]-> + addChild( module->m_pTextLabel[ steps ] ); + + y += 38; + + module->m_pButtonLenMod[ steps ] = new MyLEDButtonStrip( x + 4, y, 12, 12, 2, 10.0, 2, true, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButtonStrip::TYPE_EXCLUSIVE_WOFF, steps, module, LenModCallback ); + addChild( module->m_pButtonLenMod[ steps ] ); + + x += 28; + } + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + module->m_Clock.fsynclen = 2.0 * 48.0; // default to 120bpm + module->CalcDelays(); + + module->m_bInitialized = true; +} + +//----------------------------------------------------- +// Procedure: JsonParams +// +//----------------------------------------------------- +void StepDelay::JsonParams( bool bTo, json_t *root) +{ + JsonDataInt( bTo, "m_lenmod", root, (int*)m_lenmod, nSTEPS ); +} + +//----------------------------------------------------- +// Procedure: toJson +// +//----------------------------------------------------- +json_t *StepDelay::toJson() +{ + json_t *root = json_object(); + + if( !root ) + return NULL; + + JsonParams( TOJSON, root ); + + return root; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void StepDelay::fromJson( json_t *root ) +{ + JsonParams( FROMJSON, root ); + + for( int i = 0; i < nSTEPS; i++ ) + { + m_pButtonLenMod[ i ]->Set( m_lenmod[ i ], true ); + } + + CalcDelays(); +} + +//----------------------------------------------------- +// Procedure: reset +// +//----------------------------------------------------- +void StepDelay::onReset() +{ +} + +//----------------------------------------------------- +// Procedure: randomize +// +//----------------------------------------------------- +void StepDelay::onRandomize() +{ +} + +//----------------------------------------------------- +// Procedure: ChangeFilterCutoff +// +//----------------------------------------------------- +void StepDelay::ChangeFilterCutoff( float cutfreq ) +{ + float fx, fx2, fx3, fx5, fx7; + + // clamp at 1.0 and 20/samplerate + cutfreq = fmax(cutfreq, 20 / engineGetSampleRate()); + cutfreq = fmin(cutfreq, 1.0); + + // calculate eq rez freq + fx = 3.141592 * (cutfreq * 0.026315789473684210526315789473684) * 2 * 3.141592; + fx2 = fx*fx; + fx3 = fx2*fx; + fx5 = fx3*fx2; + fx7 = fx5*fx2; + + m_fCutoff = 2.0 * (fx + - (fx3 * 0.16666666666666666666666666666667) + + (fx5 * 0.0083333333333333333333333333333333) + - (fx7 * 0.0001984126984126984126984126984127)); +} + +//----------------------------------------------------- +// Procedure: Filter +// +//----------------------------------------------------- +#define MULTI (0.33333333333333333333333333333333f) +void StepDelay::Filter( float *InL, float *InR ) +{ + FILTER_PARAM_STRUCT *p; + float rez, hp1; + float input[ 2 ], out[ 2 ] = {0}, lowpass, bandpass, highpass; + + if( (int)params[ PARAM_FILTER_MODE ].value == 0 ) + return; + + ChangeFilterCutoff( clamp( params[ PARAM_FILTERF ].value + clamp( inputs[ IN_FILTER_MOD ].normalize( 0.0f ) / CV_MAX, -1.0f, 1.0f ), -1.0f, 1.0f ) ); + + p = &m_Filter; + + rez = 1.0 - params[ PARAM_FILTERQ ].value; + + input[ 0 ] = clamp( *InL / AUDIO_MAX, -1.0f, 1.0f ); + input[ 1 ] = clamp( *InR / AUDIO_MAX, -1.0f, 1.0f ); + + // do left and right channels + for( int i = 0; i < 2; i++ ) + { + input[ i ] = input[ i ] + 0.000000001; + + p->lp1[ i ] = p->lp1[ i ] + m_fCutoff * p->bp1[ i ]; + hp1 = input[ i ] - p->lp1[ i ] - rez * p->bp1[ i ]; + p->bp1[ i ] = m_fCutoff * hp1 + p->bp1[ i ]; + lowpass = p->lp1[ i ]; + highpass = hp1; + bandpass = p->bp1[ i ]; + + p->lp1[ i ] = p->lp1[ i ] + m_fCutoff * p->bp1[ i ]; + hp1 = input[ i ] - p->lp1[ i ] - rez * p->bp1[ i ]; + p->bp1[ i ] = m_fCutoff * hp1 + p->bp1[ i ]; + lowpass = lowpass + p->lp1[ i ]; + highpass = highpass + hp1; + bandpass = bandpass + p->bp1[ i ]; + + input[ i ] = input[ i ] - 0.000000001; + + p->lp1[ i ] = p->lp1[ i ] + m_fCutoff * p->bp1[ i ]; + hp1 = input[ i ] - p->lp1[ i ] - rez * p->bp1[ i ]; + p->bp1[ i ] = m_fCutoff * hp1 + p->bp1[ i ]; + + lowpass = (lowpass + p->lp1[ i ]) * MULTI; + highpass = (highpass + hp1) * MULTI; + bandpass = (bandpass + p->bp1[ i ]) * MULTI; + + switch( (int)params[ PARAM_FILTER_MODE ].value ) + { + case FILTER_LP: + out[ i ] = lowpass; + break; + case FILTER_HP: + out[ i ] = highpass; + break; + case FILTER_BP: + out[ i ] = bandpass; + break; + case FILTER_NT: + out[ i ] = lowpass + highpass; + break; + default: + break; + } + } + + *InL = out[ 0 ] * AUDIO_MAX; + *InR = out[ 1 ] * AUDIO_MAX; +} + +//----------------------------------------------------- +// Procedure: CalcDelays +// +//----------------------------------------------------- +#define BASE_TICK 48 + +const float fdelaylen[ nDELAYS ] = { 0.0f, 8.0f, 4.0f, 2.0f, 1.0f, 0.5f, 0.25f, 0.125f }; +const float delaymod[ 3 ] = { 1.0f, 1.5f, 0.3333f }; +const char strDelay[ nDELAYS ][ 8 ] = { {" Off"}, {"2Bar"}, {"Bar"}, {" Half"}, {" 4th"}, {" 8th"}, {" 16th"}, {" 32nd"} }; + +void StepDelay::CalcDelays( void ) +{ + int i, delay, delaysum = 0; + + for( i = 0; i < nSTEPS; i++ ) + { + delay = (int)params[ PARAM_DELAY + i ].value; + + if( m_pTextLabel[ i ] ) + m_pTextLabel[ i ]->text = strDelay[ delay ]; + + if( delay ) + { + delaysum += (int)( m_Clock.fsynclen * ( fdelaylen[ delay ] * delaymod[ m_lenmod[ i ] ] ) ); + m_BufferOutOffset[ i ] = ( m_BufferInOffset - delaysum ) & 0x7FFFF; + } + } +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +void StepDelay::step() +{ + int i; + bool bMono = true; + float delayL, delayR, fFbL = 0.0f, fFbR = 0.0f, inLOrig = 0.0f, inROrig = 0.0f, inL = 0.0f, inR = 0.0f, outL = 0.0f, outR = 0.0f, inPan; + + if( !m_bInitialized ) + return; + + // get audio inputs, Mono if L only + if( inputs[ IN_AUDIOR ].active ) + { + // right channel connected, this is not mono + bMono = false; + inR = inputs[ IN_AUDIOR ].value; + } + + if( inputs[ IN_AUDIOL ].active ) + { + inL = inputs[ IN_AUDIOL ].value; + + // mono, make R channel equal left + if( bMono ) + inR = inL; + } + + inLOrig = inL; + inROrig = inR; + + Filter( &inL, &inR ); + + m_Clock.tickcount++; + + // track clock period + if( m_SchTrigClk.process( inputs[ IN_CLOCK ].normalize( 0.0f ) ) ) + { + //m_Clock.fsynclen = (float)( engineGetSampleRate() / (float)m_Clock.tickcount ) * 48.0; + m_Clock.fsynclen = m_Clock.tickcount; + CalcDelays(); + m_Clock.tickcount = 0; + } + + // add delays + for( i = 0; i < nSTEPS; i++ ) + { + // add each activated delay + if( params[ PARAM_DELAY + i ].value != 0 ) + { + // add delay + delayL = m_fBuffer[ L ][ m_BufferOutOffset[ i ] ] * params[ PARAM_LEVEL + i ].value; + delayR = m_fBuffer[ R ][ m_BufferOutOffset[ i ] ] * params[ PARAM_LEVEL + i ].value; + + m_BufferOutOffset[ i ] = ( m_BufferOutOffset[ i ] + 1 ) & 0x7FFFF; + + inPan = params[ PARAM_PAN + i ].value; + + if( inPan <= 0.0 ) + delayR *= ( 1.0 + inPan ); + else + delayL *= ( 1.0 - inPan ); + + outL += delayL; + outR += delayR; + + fFbL += delayL * params[ PARAM_FB + i ].value; + fFbR += delayR * params[ PARAM_FB + i ].value; + } + } + + // main delay buffer + m_fBuffer[ L ][ m_BufferInOffset ] = inL + fFbL; + m_fBuffer[ R ][ m_BufferInOffset ] = inR + fFbR; + + m_BufferInOffset = ( m_BufferInOffset + 1 ) & 0x7FFFF; + + outputs[ OUT_AUDIOL ].value = ( outL * params[ PARAM_MIX ].value ) + ( inLOrig * ( 1.0f - params[ PARAM_MIX ].value ) ); + outputs[ OUT_AUDIOR ].value = ( outR * params[ PARAM_MIX ].value ) + ( inROrig * ( 1.0f - params[ PARAM_MIX ].value ) ); +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, StepDelay) { + Model *modelStepDelay = Model::create( "mscHack", "StepDelay", "DELAY 4 Step Delay", DELAY_TAG, PANNING_TAG ); + return modelStepDelay; +} diff --git a/plugins/community/repos/mscHack/src/SynthDrums.cpp b/plugins/community/repos/mscHack/src/SynthDrums.cpp new file mode 100644 index 00000000..63f91c7e --- /dev/null +++ b/plugins/community/repos/mscHack/src/SynthDrums.cpp @@ -0,0 +1,669 @@ +#include "mscHack.hpp" +//#include "mscHack_Controls.hpp" +#include "dsp/digital.hpp" +//#include "CLog.h" + +namespace rack_plugin_mscHack { + +#define nCHANNELS 3 +#define CHANNEL_H 90 +#define CHANNEL_Y 65 +#define CHANNEL_X 10 + +#define freqMAX 300.0f +#define ADS_MAX_TIME_SECONDS 0.5f + +#define WAVE_BUFFER_LEN ( 192000 / 20 ) // (9600) based on quality for 20Hz at max sample rate 192000 + +typedef struct +{ + int state; + int a, s, r; + int acount, scount, rcount, fadecount; + float fainc, fsinc, frinc, fadeinc; + float out; + bool bTrig; +}ASR_STRUCT; + +typedef struct +{ + int wavetype; + + + // wave + float phase; + + //filter + float q, f; + bool bHighpass; + + float lp1, bp1; + float hpIn; + float lpIn; + float mpIn; + + // ads + ASR_STRUCT adsr_wave; + ASR_STRUCT adsr_freq; + +}OSC_PARAM_STRUCT; + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct SynthDrums : Module +{ + enum WaveTypes + { + WAVE_SIN, + WAVE_TRI, + WAVE_SQR, + WAVE_SAW, + WAVE_NOISE, + nWAVEFORMS + }; + + enum ParamIds + { + PARAM_FREQ, + PARAM_ATT = PARAM_FREQ + nCHANNELS, + PARAM_REL = PARAM_ATT + nCHANNELS, + PARAM_REZ = PARAM_REL + nCHANNELS, + PARAM_WAVES = PARAM_REZ + nCHANNELS, + nPARAMS = PARAM_WAVES + (nWAVEFORMS * nCHANNELS) + }; + + enum InputIds + { + IN_LEVEL, + IN_TRIG = IN_LEVEL + nCHANNELS, + IN_FREQ_MOD = IN_TRIG + nCHANNELS, + nINPUTS = IN_FREQ_MOD + nCHANNELS + }; + + enum OutputIds + { + OUTPUT_AUDIO, + nOUTPUTS = OUTPUT_AUDIO + nCHANNELS + }; + + enum ADSRSTATES + { + ADSR_OFF, + ADSR_FADE, + ADSR_ON, + ADSR_ATTACK, + ADSR_SUSTAIN, + ADSR_RELEASE + }; + + CLog lg; + + SchmittTrigger m_SchTrig[ nCHANNELS ]; + + OSC_PARAM_STRUCT m_Wave[ nCHANNELS ] = {}; + + MyLEDButtonStrip *m_pButtonWaveSelect[ nCHANNELS ] = {}; + + // waveforms + float m_BufferWave[ nWAVEFORMS ][ WAVE_BUFFER_LEN ] = {}; + + // Contructor + SynthDrums() : Module( nPARAMS, nINPUTS, nOUTPUTS, 0 ){} + + //----------------------------------------------------- + // MyParamKnob + //----------------------------------------------------- + struct MyParamFreq : Knob_Yellow2_26 + { + SynthDrums *mymodule; + int param; + + void onChange( EventChange &e ) override + { + mymodule = (SynthDrums*)module; + + if( mymodule ) + { + param = paramId - SynthDrums::PARAM_FREQ; + + if( mymodule->m_Wave[ param ].wavetype == WAVE_NOISE ) + mymodule->ChangeFilterCutoff( param, value ); + else + mymodule->ChangeFilterCutoff( param, 0.6 ); + } + + RoundKnob::onChange( e ); + } + }; + + // Overrides + void step() override; + json_t* toJson() override; + void fromJson(json_t *rootJ) override; + void onRandomize() override; + void onReset() override; + + void SetWaveLights( void ); + void BuildWaves( void ); + void ChangeFilterCutoff( int ch, float cutfreq ); + float Filter( int ch, float in, bool bHighPass ); + float GetWave( int type, float phase ); + float ProcessADS( int ch, bool bWave ); + float GetAudio( int ch ); +}; + +//----------------------------------------------------- +// SynthDrums_WaveSelect +//----------------------------------------------------- +void SynthDrums_WaveSelect( void *pClass, int id, int nbutton, bool bOn ) +{ + SynthDrums *mymodule; + mymodule = (SynthDrums*)pClass; + mymodule->m_Wave[ id ].wavetype = nbutton; +} + +//----------------------------------------------------- +// Procedure: +// +//----------------------------------------------------- +json_t *SynthDrums::toJson() +{ + json_t *gatesJ; + json_t *rootJ = json_object(); + + // wavetypes + gatesJ = json_array(); + + for (int i = 0; i < nCHANNELS; i++) + { + json_t *gateJ = json_integer( m_Wave[ i ].wavetype ); + json_array_append_new( gatesJ, gateJ ); + } + + json_object_set_new( rootJ, "wavetypes", gatesJ ); + + return rootJ; +} + +//----------------------------------------------------- +// Procedure: fromJson +// +//----------------------------------------------------- +void SynthDrums::fromJson(json_t *rootJ) +{ + int i; + json_t *StepsJ; + + // wave select + StepsJ = json_object_get( rootJ, "wavetypes" ); + + if (StepsJ) + { + for ( i = 0; i < nCHANNELS; i++) + { + json_t *gateJ = json_array_get(StepsJ, i); + + if (gateJ) + m_Wave[ i ].wavetype = json_integer_value( gateJ ); + } + } + + SetWaveLights(); +} + +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- + +struct SynthDrums_Widget : ModuleWidget { + SynthDrums_Widget( SynthDrums *module ); +}; + +SynthDrums_Widget::SynthDrums_Widget( SynthDrums *module ) : ModuleWidget(module) +{ + int ch, x, y; + + box.size = Vec( 15*11, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/SynthDrums.svg"))); + addChild(panel); + } + + //module->lg.Open("SynthDrums.txt"); + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + y = CHANNEL_Y; + x = CHANNEL_X; + + for( ch = 0; ch < nCHANNELS; ch++ ) + { + x = CHANNEL_X; + + // IN_FREQ_MOD + addInput(Port::create( Vec( x + 48, y ), Port::INPUT, module, SynthDrums::IN_FREQ_MOD + ch ) ); + + // inputs + addInput(Port::create( Vec( x, y ), Port::INPUT, module, SynthDrums::IN_LEVEL + ch ) ); + + y += 43; + + addInput(Port::create( Vec( x, y ), Port::INPUT, module, SynthDrums::IN_TRIG + ch ) ); + + x += 32; + y += 7; + + // wave select buttons + module->m_pButtonWaveSelect[ ch ] = new MyLEDButtonStrip( x, y, 11, 11, 5, 8.0, 5, false, DWRGB( 180, 180, 180 ), DWRGB( 255, 255, 0 ), MyLEDButtonStrip::TYPE_EXCLUSIVE, ch, module, SynthDrums_WaveSelect ); + addChild( module->m_pButtonWaveSelect[ ch ] ); + + x = CHANNEL_X + 25; + y -= 34; + + // params + addParam(ParamWidget::create( Vec( x, y ), module, SynthDrums::PARAM_FREQ + ch, 0.0, 1.0, 0.0 ) ); + + x += 34; + + addParam(ParamWidget::create( Vec( x, y ), module, SynthDrums::PARAM_ATT + ch, 0.0, 0.1, 0.0 ) ); + + x += 34; + + addParam(ParamWidget::create( Vec( x, y ), module, SynthDrums::PARAM_REL + ch, 0.0, 1.0, 0.0 ) ); + + y -= 15; + x += 34; + + // outputs + addOutput(Port::create( Vec( x, y ), Port::OUTPUT, module, SynthDrums::OUTPUT_AUDIO + ch ) ); + + y += CHANNEL_H; + } + + module->BuildWaves(); + + module->ChangeFilterCutoff( 0, 0.6 ); + module->ChangeFilterCutoff( 1, 0.6 ); + module->ChangeFilterCutoff( 2, 0.6 ); + + module->SetWaveLights(); +} + +//----------------------------------------------------- +// Procedure: reset +// +//----------------------------------------------------- +void SynthDrums::onReset() +{ +} + +//----------------------------------------------------- +// Procedure: randomize +// +//----------------------------------------------------- +void SynthDrums::onRandomize() +{ + int ch; + + for( ch = 0; ch < nCHANNELS; ch++ ) + { + m_Wave[ ch ].wavetype = (int)( randomUniform() * (nWAVEFORMS-1) ); + } + + SetWaveLights(); +} + +//----------------------------------------------------- +// Procedure: SetWaveLights +// +//----------------------------------------------------- +void SynthDrums::SetWaveLights( void ) +{ + int ch; + + for( ch = 0; ch < nCHANNELS; ch++ ) + m_pButtonWaveSelect[ ch ]->Set( m_Wave[ ch ].wavetype, true ); +} + +//----------------------------------------------------- +// Procedure: initialize +// +//----------------------------------------------------- +//#define DEG2RAD( x ) ( ( x ) * ( 3.14159f / 180.0f ) ) +void SynthDrums::BuildWaves( void ) +{ + int i; + float finc, pos, val; + + finc = 360.0 / WAVE_BUFFER_LEN; + pos = 0; + + // create sin wave + for( i = 0; i < WAVE_BUFFER_LEN; i++ ) + { + m_BufferWave[ WAVE_SIN ][ i ] = sin( DEG2RAD( pos ) ); + pos += finc; + } + + // create sqr wave + for( i = 0; i < WAVE_BUFFER_LEN; i++ ) + { + if( i < WAVE_BUFFER_LEN / 2 ) + m_BufferWave[ WAVE_SQR ][ i ] = 1.0; + else + m_BufferWave[ WAVE_SQR ][ i ] = -1.0; + } + + finc = 2.0 / (float)WAVE_BUFFER_LEN; + val = 1.0; + + // create saw wave + for( i = 0; i < WAVE_BUFFER_LEN; i++ ) + { + m_BufferWave[ WAVE_SAW ][ i ] = val; + + val -= finc; + } + + finc = 4 / (float)WAVE_BUFFER_LEN; + val = 0; + + // create tri wave + for( i = 0; i < WAVE_BUFFER_LEN; i++ ) + { + m_BufferWave[ WAVE_TRI ][ i ] = val; + + if( i < WAVE_BUFFER_LEN / 4 ) + val += finc; + else if( i < (WAVE_BUFFER_LEN / 4) * 3 ) + val -= finc; + else if( i < WAVE_BUFFER_LEN ) + val += finc; + } +} + +//----------------------------------------------------- +// Procedure: GetAudio +// +//----------------------------------------------------- +float SynthDrums::GetWave( int type, float phase ) +{ + float fval = 0.0; + float ratio = (float)(WAVE_BUFFER_LEN-1) / engineGetSampleRate(); + + switch( type ) + { + case WAVE_SIN: + case WAVE_TRI: + case WAVE_SQR: + case WAVE_SAW: + fval = m_BufferWave[ type ][ int( ( phase * ratio ) + 0.5 ) ]; + break; + + case WAVE_NOISE: + fval = ( randomUniform() > 0.5 ) ? (randomUniform() * -1.0) : randomUniform(); + break; + + default: + break; + } + + return fval; +} + +//----------------------------------------------------- +// Procedure: ProcessADS +// +//----------------------------------------------------- +float SynthDrums::ProcessADS( int ch, bool bWave ) +{ + ASR_STRUCT *pasr; + + if( bWave ) + pasr = &m_Wave[ ch ].adsr_wave; + else + pasr = &m_Wave[ ch ].adsr_freq; + + // rettrig the adsr + if( pasr->bTrig ) + { + pasr->state = ADSR_FADE; + + pasr->fadecount = 900; + pasr->fadeinc = pasr->out / (float)pasr->fadecount; + + pasr->acount = 20; + pasr->fainc = 1.0 / pasr->acount; + + pasr->scount = 0;//(int)(.1 * engineGetSampleRate()); + pasr->fsinc = 0;//1.0 / pasr->scount; + + if( bWave ) + { + // for the wave asr the release is the waveform release + pasr->rcount = (int)( params[ PARAM_REL + ch ].value * ADS_MAX_TIME_SECONDS * engineGetSampleRate() ); + } + else + { + // for the wave asr the release is the hit + pasr->rcount = (int)( params[ PARAM_ATT + ch ].value * ADS_MAX_TIME_SECONDS * engineGetSampleRate() ); + } + + if( pasr->rcount ) + pasr->frinc = 1.0 / pasr->rcount; + + pasr->bTrig = false; + } + + // process + switch( pasr->state ) + { + case ADSR_FADE: + if( --pasr->fadecount <= 0 ) + { + pasr->state = ADSR_ATTACK; + pasr->out = 0.0f; + m_Wave[ ch ].phase = 0.0; + } + else + { + pasr->out -= pasr->fadeinc; + } + + break; + + case ADSR_OFF: + pasr->out = 0.0; + break; + + case ADSR_ATTACK: + if( --pasr->acount <= 0 ) + { + pasr->state = ADSR_SUSTAIN; + } + else + { + pasr->out += pasr->fainc; + } + break; + + case ADSR_SUSTAIN: + pasr->out = 1.0; + if( --pasr->scount <= 0 ) + { + pasr->state = ADSR_RELEASE; + } + + break; + + case ADSR_RELEASE: + + if( --pasr->rcount <= 0 ) + { + pasr->out = 0.0f; + pasr->state = ADSR_OFF; + } + else + { + pasr->out -= pasr->frinc; + } + break; + } + + return clamp( pasr->out, 0.0f, 1.0f ); +} + +//----------------------------------------------------- +// Procedure: ChangeFilterCutoff +// +//----------------------------------------------------- +void SynthDrums::ChangeFilterCutoff( int ch, float cutfreq ) +{ + float fx, fx2, fx3, fx5, fx7; + + // clamp at 1.0 and 20/samplerate + cutfreq = fmax(cutfreq, 20 / engineGetSampleRate()); + cutfreq = fmin(cutfreq, 1.0); + + // calculate eq rez freq + fx = 3.141592 * (cutfreq * 0.026315789473684210526315789473684) * 2 * 3.141592; + fx2 = fx*fx; + fx3 = fx2*fx; + fx5 = fx3*fx2; + fx7 = fx5*fx2; + + m_Wave[ ch ].f = 2.0 * (fx + - (fx3 * 0.16666666666666666666666666666667) + + (fx5 * 0.0083333333333333333333333333333333) + - (fx7 * 0.0001984126984126984126984126984127)); +} + +//----------------------------------------------------- +// Procedure: Filter +// +//----------------------------------------------------- +#define MULTI (0.33333333333333333333333333333333f) +float SynthDrums::Filter( int ch, float in, bool bHighPass ) +{ + OSC_PARAM_STRUCT *p; + float rez, hp1; + float lowpass, highpass; + + p = &m_Wave[ ch ]; + + rez = 1.00;//1.00 - p->q; + + in = in + 0.000000001; + + p->lp1 = p->lp1 + p->f * p->bp1; + hp1 = in - p->lp1 - rez * p->bp1; + p->bp1 = p->f * hp1 + p->bp1; + lowpass = p->lp1; + highpass = hp1; + //bandpass = p->bp1; + + p->lp1 = p->lp1 + p->f * p->bp1; + hp1 = in - p->lp1 - rez * p->bp1; + p->bp1 = p->f * hp1 + p->bp1; + lowpass = lowpass + p->lp1; + highpass = highpass + hp1; + //bandpass = bandpass + p->bp1; + + in = in - 0.000000001; + + p->lp1 = p->lp1 + p->f * p->bp1; + hp1 = in - p->lp1 - rez * p->bp1; + p->bp1 = p->f * hp1 + p->bp1; + + lowpass = (lowpass + p->lp1) * MULTI; + highpass = (highpass + hp1) * MULTI; + //bandpass = (bandpass + p->bp1) * MULTI; + + if( bHighPass ) + return highpass; + + return lowpass; +} + +//----------------------------------------------------- +// Procedure: GetAudio +// +//----------------------------------------------------- +float SynthDrums::GetAudio( int ch ) +{ + float fout = 0, fenv = 0.0, freq, freqmod; + + if( outputs[ OUTPUT_AUDIO + ch ].active ) + { + freqmod = clamp( inputs[ IN_FREQ_MOD + ch ].value / CV_MAX, 0.0f, 1.0f ); + + // process our second envelope for hit + fenv = ProcessADS( ch, false ); + + // if noise then frequency affects the filter cutoff and not the wave frequency + if( m_Wave[ ch ].wavetype == WAVE_NOISE ) + { + freq = clamp( ( ( freqmod + params[ PARAM_FREQ + ch ].value ) + (fenv*2) ), 0.0f, 1.0f ); + + ChangeFilterCutoff( ch, freq ); + } + // other signals the second ADS affects the frequency for the hit + else + { + m_Wave[ ch ].phase += 35 + ( ( freqmod + params[ PARAM_FREQ + ch ].value ) * freqMAX ) + ( fenv * 400.0f ); + + if( m_Wave[ ch ].phase >= engineGetSampleRate() ) + m_Wave[ ch ].phase = m_Wave[ ch ].phase - engineGetSampleRate(); + } + + fout = ProcessADS( ch, true ) * GetWave( m_Wave[ ch ].wavetype, m_Wave[ ch ].phase ); + fout = Filter( ch, fout, ( m_Wave[ ch ].wavetype == WAVE_NOISE ) ); + } + + return fout; +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +void SynthDrums::step() +{ + int ch; + + // check for triggers + for( ch = 0; ch < nCHANNELS; ch++ ) + { + if( inputs[ IN_TRIG + ch ].active ) + { + if( m_SchTrig[ ch ].process( inputs[ IN_TRIG + ch ].value ) ) + { + m_Wave[ ch ].adsr_freq.bTrig = true; + m_Wave[ ch ].adsr_wave.bTrig = true; + } + } + } + + // process sounds + outputs[ OUTPUT_AUDIO + 0 ].value = GetAudio( 0 ) * AUDIO_MAX * clamp( (inputs[ IN_LEVEL + 0 ].value / CV_MAX), 0.0f, 1.0f ); + outputs[ OUTPUT_AUDIO + 1 ].value = GetAudio( 1 ) * AUDIO_MAX * clamp( (inputs[ IN_LEVEL + 1 ].value / CV_MAX), 0.0f, 1.0f ); + outputs[ OUTPUT_AUDIO + 2 ].value = GetAudio( 2 ) * AUDIO_MAX * clamp( (inputs[ IN_LEVEL + 2 ].value / CV_MAX), 0.0f, 1.0f ); +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, SynthDrums) { + Model *modelSynthDrums = Model::create( "mscHack", "SynthDrums", "SYNTH Drums", DRUM_TAG, MULTIPLE_TAG ); + return modelSynthDrums; +} diff --git a/plugins/community/repos/mscHack/src/XFade.cpp b/plugins/community/repos/mscHack/src/XFade.cpp new file mode 100644 index 00000000..dab0abe9 --- /dev/null +++ b/plugins/community/repos/mscHack/src/XFade.cpp @@ -0,0 +1,165 @@ +#include "mscHack.hpp" +//#include "mscHack_Controls.hpp" +#include "dsp/digital.hpp" +//#include "CLog.h" + +namespace rack_plugin_mscHack { + +#define CHANNELS 3 + +//----------------------------------------------------- +// Module Definition +// +//----------------------------------------------------- +struct XFade : Module +{ + enum ParamIds + { + PARAM_MIX, + PARAM_LEVEL, + nPARAMS + }; + + enum InputIds + { + IN_MIXCV, + IN_AL, + IN_AR = IN_AL + CHANNELS, + IN_BL = IN_AR + CHANNELS, + IN_BR = IN_BL + CHANNELS, + nINPUTS = IN_BR + CHANNELS + }; + + enum OutputIds + { + OUT_L, + OUT_R = OUT_L + CHANNELS, + nOUTPUTS = OUT_R + CHANNELS + }; + + CLog lg; + + // Contructor + XFade() : Module(nPARAMS, nINPUTS, nOUTPUTS){} + + // Overrides + void step() override; + //json_t* toJson() override; + //void fromJson(json_t *rootJ) override; + void onRandomize() override; + void onReset() override; +}; + +//----------------------------------------------------- +// Procedure: Widget +// +//----------------------------------------------------- + +struct XFade_Widget : ModuleWidget { + XFade_Widget( XFade *module ); +}; + +XFade_Widget::XFade_Widget( XFade *module ) : ModuleWidget(module) +{ + int i, x, y; + + box.size = Vec( 15*8, 380); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/XFade.svg"))); + addChild(panel); + } + + //module->lg.Open("XFade.txt"); + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + x = 10; + y = 47; + + for( i = 0; i < CHANNELS; i++ ) + { + // audio A + addInput(Port::create( Vec( x, y ), Port::INPUT, module, XFade::IN_AL + i ) ); + addInput(Port::create( Vec( x + 28, y ), Port::INPUT, module, XFade::IN_AR + i ) ); + + // audio B + addInput(Port::create( Vec( x, y + 32 ), Port::INPUT, module, XFade::IN_BL + i ) ); + addInput(Port::create( Vec( x + 28, y + 32 ), Port::INPUT, module, XFade::IN_BR + i ) ); + + // audio outputs + addOutput(Port::create( Vec( x + 83, y ), Port::OUTPUT, module, XFade::OUT_L + i ) ); + addOutput(Port::create( Vec( x + 83, y + 32 ), Port::OUTPUT, module, XFade::OUT_R + i ) ); + + y += 67; + } + + // mix CV + addInput(Port::create( Vec( 4, 263 ), Port::INPUT, module, XFade::IN_MIXCV) ); + + // mix knobs + addParam(ParamWidget::create( Vec( 30, 243 ), module, XFade::PARAM_MIX, -1.0, 1.0, 0.0 ) ); + addParam(ParamWidget::create( Vec( 30, 313 ), module, XFade::PARAM_LEVEL, 0.0, 2.0, 1.0 ) ); +} + +//----------------------------------------------------- +// Procedure: reset +// +//----------------------------------------------------- +void XFade::onReset() +{ +} + +//----------------------------------------------------- +// Procedure: randomize +// +//----------------------------------------------------- +void XFade::onRandomize() +{ +} + +//----------------------------------------------------- +// Procedure: step +// +//----------------------------------------------------- +void XFade::step() +{ + int i; + float mix, mixa, mixb; + + if( inputs[ IN_MIXCV ].active ) + mix = inputs[ IN_MIXCV ].value / AUDIO_MAX; + else + mix = params[ PARAM_MIX ].value; + + if( mix <= 0.0 ) + { + mixa = 1.0; + mixb = 1.0 + mix; + } + else + { + mixb = 1.0; + mixa = 1.0 - mix; + } + + for( i = 0; i < CHANNELS; i++ ) + { + outputs[ OUT_L + i ].value = ( ( inputs[ IN_AL + i ].value * mixa ) + ( inputs[ IN_BL + i ].value * mixb ) ) * params[ PARAM_LEVEL ].value; + outputs[ OUT_R + i ].value = ( ( inputs[ IN_AR + i ].value * mixa ) + ( inputs[ IN_BR + i ].value * mixb ) ) * params[ PARAM_LEVEL ].value; + } +} + +} // namespace rack_plugin_mscHack + +using namespace rack_plugin_mscHack; + +RACK_PLUGIN_MODEL_INIT(mscHack, XFade) { + Model *modelXFade = Model::create( "mscHack", "XFade", "MIXER Cross Fader 3 Channel", MIXER_TAG, MULTIPLE_TAG ); + return modelXFade; +} diff --git a/plugins/community/repos/mscHack/src/mscHack.cpp b/plugins/community/repos/mscHack/src/mscHack.cpp new file mode 100644 index 00000000..88d8bf11 --- /dev/null +++ b/plugins/community/repos/mscHack/src/mscHack.cpp @@ -0,0 +1,125 @@ +#include "mscHack.hpp" + +RACK_PLUGIN_MODEL_DECLARE(mscHack, MasterClockx4); +RACK_PLUGIN_MODEL_DECLARE(mscHack, Seq_3x16x16); +RACK_PLUGIN_MODEL_DECLARE(mscHack, SEQ_6x32x16); +RACK_PLUGIN_MODEL_DECLARE(mscHack, Seq_Triad2); +RACK_PLUGIN_MODEL_DECLARE(mscHack, SEQ_Envelope_8); +RACK_PLUGIN_MODEL_DECLARE(mscHack, Maude_221); +RACK_PLUGIN_MODEL_DECLARE(mscHack, ARP700); +RACK_PLUGIN_MODEL_DECLARE(mscHack, SynthDrums); +RACK_PLUGIN_MODEL_DECLARE(mscHack, XFade); +RACK_PLUGIN_MODEL_DECLARE(mscHack, Mix_1x4_Stereo); +RACK_PLUGIN_MODEL_DECLARE(mscHack, Mix_2x4_Stereo); +RACK_PLUGIN_MODEL_DECLARE(mscHack, Mix_4x4_Stereo); +RACK_PLUGIN_MODEL_DECLARE(mscHack, Mix_24_4_4); +RACK_PLUGIN_MODEL_DECLARE(mscHack, StepDelay); +RACK_PLUGIN_MODEL_DECLARE(mscHack, PingPong); +RACK_PLUGIN_MODEL_DECLARE(mscHack, Osc_3Ch); +RACK_PLUGIN_MODEL_DECLARE(mscHack, Compressor); + +RACK_PLUGIN_INIT(mscHack) { + RACK_PLUGIN_INIT_ID(); + + RACK_PLUGIN_INIT_WEBSITE("https://github.com/mschack/VCV-Rack-Plugins"); + + RACK_PLUGIN_MODEL_ADD(mscHack, MasterClockx4); + RACK_PLUGIN_MODEL_ADD(mscHack, Seq_3x16x16); + RACK_PLUGIN_MODEL_ADD(mscHack, SEQ_6x32x16); + RACK_PLUGIN_MODEL_ADD(mscHack, Seq_Triad2); + RACK_PLUGIN_MODEL_ADD(mscHack, SEQ_Envelope_8); + RACK_PLUGIN_MODEL_ADD(mscHack, Maude_221); + RACK_PLUGIN_MODEL_ADD(mscHack, ARP700); + RACK_PLUGIN_MODEL_ADD(mscHack, SynthDrums); + RACK_PLUGIN_MODEL_ADD(mscHack, XFade); + RACK_PLUGIN_MODEL_ADD(mscHack, Mix_1x4_Stereo); + RACK_PLUGIN_MODEL_ADD(mscHack, Mix_2x4_Stereo); + RACK_PLUGIN_MODEL_ADD(mscHack, Mix_4x4_Stereo); + RACK_PLUGIN_MODEL_ADD(mscHack, Mix_24_4_4); + RACK_PLUGIN_MODEL_ADD(mscHack, StepDelay); + RACK_PLUGIN_MODEL_ADD(mscHack, PingPong); + RACK_PLUGIN_MODEL_ADD(mscHack, Osc_3Ch); + RACK_PLUGIN_MODEL_ADD(mscHack, Compressor); +} + +//----------------------------------------------------- +// Procedure: JsonDataInt +// +//----------------------------------------------------- +void JsonDataInt( bool bTo, std::string strName, json_t *root, int *pdata, int len ) +{ + int i; + json_t *jsarray, *js; + + if( !pdata || !root || len <= 0 ) + return; + + if( bTo ) + { + jsarray = json_array(); + + for ( i = 0; i < len; i++ ) + { + js = json_integer( pdata[ i ] ); + json_array_append_new( jsarray, js ); + } + + json_object_set_new( root, strName.c_str(), jsarray ); + } + else + { + jsarray = json_object_get( root, strName.c_str() ); + + if( jsarray ) + { + for ( i = 0; i < len; i++) + { + js = json_array_get( jsarray, i ); + + if( js ) + pdata[ i ] = json_integer_value( js ); + } + } + } +} + +//----------------------------------------------------- +// Procedure: JsonDataBool +// +//----------------------------------------------------- +void JsonDataBool( bool bTo, std::string strName, json_t *root, bool *pdata, int len ) +{ + int i; + json_t *jsarray, *js; + + if( !pdata || !root || len <= 0 ) + return; + + if( bTo ) + { + jsarray = json_array(); + + for ( i = 0; i < len; i++ ) + { + js = json_boolean( pdata[ i ] ); + json_array_append_new( jsarray, js ); + } + + json_object_set_new( root, strName.c_str(), jsarray ); + } + else + { + jsarray = json_object_get( root, strName.c_str() ); + + if( jsarray ) + { + for ( i = 0; i < len; i++) + { + js = json_array_get( jsarray, i ); + + if( js ) + pdata[ i ] = json_boolean_value( js ); + } + } + } +} diff --git a/plugins/community/repos/mscHack/src/mscHack.hpp b/plugins/community/repos/mscHack/src/mscHack.hpp new file mode 100644 index 00000000..5a9c2bc8 --- /dev/null +++ b/plugins/community/repos/mscHack/src/mscHack.hpp @@ -0,0 +1,23 @@ +#include "rack.hpp" + +using namespace rack; + +RACK_PLUGIN_DECLARE(mscHack); + +#ifdef USE_VST2 +#define plugin "mscHack" +#endif // USE_VST2 + +#include "CLog.h" +#include "mscHack_Controls.hpp" + +#define CV_MAX (10.0f) +#define AUDIO_MAX (6.0f) +#define VOCT_MAX (6.0f) +#define AMP_MAX (2.0f) + +#define TOJSON true +#define FROMJSON false + +void JsonDataInt( bool bTo, std::string strName, json_t *root, int *pdata, int len ); +void JsonDataBool( bool bTo, std::string strName, json_t *root, bool *pdata, int len ); diff --git a/plugins/community/repos/mscHack/src/mscHack_Control_EnvelopeEdit.cpp b/plugins/community/repos/mscHack/src/mscHack_Control_EnvelopeEdit.cpp new file mode 100644 index 00000000..b90d143d --- /dev/null +++ b/plugins/community/repos/mscHack/src/mscHack_Control_EnvelopeEdit.cpp @@ -0,0 +1,785 @@ +#include "mscHack.hpp" +#include "window.hpp" + +//----------------------------------------------------- +// Procedure: constructor +//----------------------------------------------------- +Widget_EnvelopeEdit::Widget_EnvelopeEdit( int x, int y, int w, int h, int handleSize, void *pClass, EnvelopeEditCALLBACK *pCallback ) +{ + int ch, hd; + + if( !pClass || !pCallback ) + return; + + m_pClass = pClass; + m_pCallback = pCallback; + m_handleSize = handleSize; + + box.pos = Vec( x, y ); + box.size = Vec( w, h ); + + // calc division size (16 divisions, 4 beats x 4 quarter) + m_divw = ( ( (float)w - (float)ENVELOPE_HANDLES) / (float)ENVELOPE_DIVISIONS ) + 1.0f; + + m_handleSizeD2 = ( (float)handleSize / 2.0f ); + + // handle rects + for( ch = 0; ch < MAX_ENVELOPE_CHANNELS; ch++ ) + { + for( hd = 0; hd < ENVELOPE_HANDLES; hd++ ) + { + m_HandleVal[ ch ][ hd ] = 0.5f; + m_HandleCol[ hd ].dwCol = 0xFFFFFF; + } + } + + recalcLine( -1, 0 ); + + m_BeatLen = (int)engineGetSampleRate(); + + m_bInitialized = true; +} + +//----------------------------------------------------- +// Procedure: Val2y +//----------------------------------------------------- +float Widget_EnvelopeEdit::Val2y( float fval ) +{ + return clamp( box.size.y - ( fval * box.size.y ), 0.0f, box.size.y ); +} + +//----------------------------------------------------- +// Procedure: y2Val +//----------------------------------------------------- +float Widget_EnvelopeEdit::y2Val( float fy ) +{ + return clamp( 1.0 - (fy / box.size.y ), 0.0f, 1.0f ); +} + +//----------------------------------------------------- +// Procedure: y2Val +//----------------------------------------------------- +float Widget_EnvelopeEdit::getActualVal( int ch, float inval ) +{ + float val = 0.0f; + + switch( m_Range[ ch ] ) + { + case Widget_EnvelopeEdit_Ranges::RANGE_0to5: + val = inval * 5.0f; + break; + case Widget_EnvelopeEdit_Ranges::RANGE_n5to5: + val = ( ( inval * 2 ) - 1.0 ) * 5.0f; + break; + case Widget_EnvelopeEdit_Ranges::RANGE_0to10: + val = inval * 10.0f; + break; + case Widget_EnvelopeEdit_Ranges::RANGE_n10to10: + val = ( ( inval * 2 ) - 1.0 ) * 10.0f; + break; + } + + return val; +} + +//----------------------------------------------------- +// Function: line_from_points +// +//----------------------------------------------------- +void Widget_EnvelopeEdit::line_from_points( float x1, float y1, float x2, float y2, fLine *L ) +{ + float m; + float xdiff, ydiff; + + if( !L ) + return; + + memset( L, 0, sizeof( fLine ) ); + L->bSet = true; + + xdiff = x2 - x1; + xdiff = fabs( xdiff ); + + ydiff = y2 - y1; + ydiff = fabs( ydiff ); + + // line is vertical + if( xdiff < 0.000000001 ) + { + L->fx = x1; + L->bVert = true; + return; + } + else if( ydiff < 0.000000001 ) + { + L->fy = y1; + L->bHorz = true; + return; + } + + //normal line + m = (y2 - y1) / (x2 - x1); + + // point slope form + //y = mx + b + L->fmx = m; + L->fb = y1 - (m * x1); +} + +//----------------------------------------------------- +// Procedure: valfromline +//----------------------------------------------------- +float Widget_EnvelopeEdit::valfromline( int ch, int handle, float x ) +{ + fLine *L; + + if( m_bGateMode[ ch ] ) + return getActualVal( ch, m_HandleVal[ ch ][ handle ] ); + + L = &m_Lines[ ch ][ handle ]; + + if( L->bHorz ) + return getActualVal( ch, L->fy ); + + return getActualVal( ch, (x * L->fmx) + L->fb ); +} + +//----------------------------------------------------- +// Procedure: recalcLine +//----------------------------------------------------- +void Widget_EnvelopeEdit::recalcLine( int chin, int handle ) +{ + float fx1, fx2, fy1, fy2; + int i; + + // calc all lines + if( chin == -1 ) + { + for( int ch = 0; ch < MAX_ENVELOPE_CHANNELS; ch++ ) + { + for( int h = 0; h < ENVELOPE_DIVISIONS; h++ ) + { + for( int delta = -1; delta < 1; delta++ ) + { + i = ( h + delta ) & 0xF; + + fx1 = (m_divw * i); + fx2 = fx1 + m_divw; + fy1 = m_HandleVal[ ch ][ i ]; + fy2 = m_HandleVal[ ch ][ i + 1 ]; + + line_from_points( fx1, fy1, fx2, fy2, &m_Lines[ ch ][ i ] ); + } + } + } + } + // calc line before and line after handle + else + { + for( int delta = -1; delta < 1; delta++ ) + { + i = ( handle + delta ) & 0xF; + + fx1 = (m_divw * i); + fx2 = fx1 + m_divw; + fy1 = m_HandleVal[ chin ][ i ]; + fy2 = m_HandleVal[ chin ][ i + 1 ]; + + line_from_points( fx1, fy1, fx2, fy2, &m_Lines[ chin ][ i ] ); + } + } +} + +//----------------------------------------------------- +// Procedure: setPos +//----------------------------------------------------- +void Widget_EnvelopeEdit::setView( int ch ) +{ + if( !m_bInitialized && ch < MAX_ENVELOPE_CHANNELS && ch >= 0 ) + return; + + m_currentChannel = ch; +} + +//----------------------------------------------------- +// Procedure: resetVal +//----------------------------------------------------- +void Widget_EnvelopeEdit::resetValAll( int ch, float val ) +{ + if( !m_bInitialized && ch < MAX_ENVELOPE_CHANNELS && ch >= 0 ) + return; + + for( int i = 0; i < ENVELOPE_HANDLES; i++ ) + { + m_HandleVal[ ch ][ i ] = val; + } + + recalcLine( -1, 0 ); +} + +//----------------------------------------------------- +// Procedure: setVal +//----------------------------------------------------- +void Widget_EnvelopeEdit::setVal( int ch, int handle, float val ) +{ + if( !m_bInitialized && ch < MAX_ENVELOPE_CHANNELS && ch >= 0 ) + return; + + m_HandleVal[ ch ][ handle ] = val; + recalcLine( ch, handle ); +} + +//----------------------------------------------------- +// Procedure: setRange +//----------------------------------------------------- +void Widget_EnvelopeEdit::setRange( int ch, int Range ) +{ + if( !m_bInitialized && ch < MAX_ENVELOPE_CHANNELS && ch >= 0 ) + return; + + m_Range[ ch ] = Range; +} + +//----------------------------------------------------- +// Procedure: setMode +//----------------------------------------------------- +void Widget_EnvelopeEdit::setMode( int ch, int Mode ) +{ + if( !m_bInitialized && ch < MAX_ENVELOPE_CHANNELS && ch >= 0 ) + return; + + switch( Mode ) + { + case MODE_LOOP: + m_Clock[ ch ].state = STATE_RUN; + break; + case MODE_REVERSE: + m_Clock[ ch ].state = STATE_RUN_REV; + break; + case MODE_ONESHOT: + m_Clock[ ch ].fpos = 0; + m_Clock[ ch ].state = STATE_WAIT_TRIG; + break; + case MODE_TWOSHOT: + m_Clock[ ch ].fpos = 0; + m_Clock[ ch ].state = STATE_WAIT_TRIG; + break; + case MODE_PINGPONG: + if( m_Clock[ ch ].state == STATE_WAIT_TRIG ) + m_Clock[ ch ].state = STATE_RUN; + else if( m_Clock[ ch ].state == STATE_WAIT_TRIG_REV ) + m_Clock[ ch ].state = STATE_RUN_REV; + + break; + + default: + return; + } + + m_Clock[ ch ].prevstate = m_Clock[ ch ].state; + m_Mode[ ch ] = Mode; +} + +//----------------------------------------------------- +// Procedure: setGateMode +//----------------------------------------------------- +void Widget_EnvelopeEdit::setGateMode( int ch, bool bGate ) +{ + if( !m_bInitialized && ch < MAX_ENVELOPE_CHANNELS && ch >= 0 ) + return; + + m_bGateMode[ ch ] = bGate; +} + +//----------------------------------------------------- +// Procedure: setTimeDiv +//----------------------------------------------------- +void Widget_EnvelopeEdit::setTimeDiv( int ch, int timediv ) +{ + if( !m_bInitialized && ch < MAX_ENVELOPE_CHANNELS && ch >= 0 ) + return; + + m_TimeDiv[ ch ] = timediv; + setBeatLen( m_BeatLen ); +} +//----------------------------------------------------- +// Procedure: setDataAll +//----------------------------------------------------- +int Widget_EnvelopeEdit::getPos( int ch ) +{ + return (int)( m_Clock[ ch ].fpos * 10000.0f ); +} + +//----------------------------------------------------- +// Procedure: setDataAll +//----------------------------------------------------- +void Widget_EnvelopeEdit::setPos( int ch, int pos ) +{ + m_Clock[ ch ].fpos = (float)pos / 10000.0f; +} + +//----------------------------------------------------- +// Procedure: setDataAll +//----------------------------------------------------- +void Widget_EnvelopeEdit::setDataAll( int *pint ) +{ + int i, j, count = 0; + + if( !m_bInitialized ) + return; + + for( i = 0; i < MAX_ENVELOPE_CHANNELS; i++ ) + { + for( j = 0; j < ENVELOPE_HANDLES; j++ ) + { + m_HandleVal[ i ][ j ] = clamp( (float)pint[ count++ ] / 10000.0f, 0.0f, 1.0f ); + } + } + + // recalc all lines + recalcLine( -1, 0 ); +} + +//----------------------------------------------------- +// Procedure: getDataAll +//----------------------------------------------------- +void Widget_EnvelopeEdit::getDataAll( int *pint ) +{ + int i, j, count = 0; + + if( !m_bInitialized ) + return; + + for( i = 0; i < MAX_ENVELOPE_CHANNELS; i++ ) + { + for( j = 0; j < ENVELOPE_HANDLES; j++ ) + { + pint[ count++ ] = (int)( m_HandleVal[ i ][ j ] * 10000.0 ); + } + } +} + +//----------------------------------------------------- +// Procedure: draw +//----------------------------------------------------- +int hdivs[ Widget_EnvelopeEdit::nRANGES ] = { 6, 11, 11, 21 }; +void Widget_EnvelopeEdit::draw( NVGcontext *vg ) +{ + int h; + float x, y, divsize; + float linewidth = 1.0; + + if( !m_bInitialized ) + return; + + // fill bg + nvgBeginPath(vg); + nvgRect(vg, 0, 0, box.size.x-1, box.size.y-1 ); + //nvgFillColor(vg, nvgRGBA(40,40,40,255)); + nvgFillColor(vg, nvgRGBA(57, 10, 10,255)); + nvgFill(vg); + + + nvgStrokeWidth( vg, linewidth ); + nvgStrokeColor( vg, nvgRGBA( 60, 60, 60, 255 ) ); + // draw bounding line + /*nvgBeginPath( vg ); + nvgMoveTo( vg, 0, 0 ); + nvgLineTo( vg, box.size.x - 1, 0 ); + nvgLineTo( vg, box.size.x - 1, box.size.y - 1 ); + nvgLineTo( vg, 0, box.size.y - 1 ); + nvgClosePath( vg ); + nvgStroke( vg );*/ + + x = 0.0; + + // draw vertical lines + for( h = 0; h < ENVELOPE_HANDLES; h++ ) + { + nvgBeginPath(vg); + nvgMoveTo( vg, x, 0 ); + nvgLineTo( vg, x, box.size.y - 1 ); + nvgStroke( vg ); + x += m_divw; + } + + y = 0.0; + + divsize = box.size.y / (float)( hdivs[ m_Range[ m_currentChannel ] ] - 1 ); + + // draw horizontal lines + for( h = 0; h < hdivs[ m_Range[ m_currentChannel ] ]; h++ ) + { + if( h == hdivs[ m_Range[ m_currentChannel ] ] / 2 && ( m_Range[ m_currentChannel ] == RANGE_n5to5 || m_Range[ m_currentChannel ] == RANGE_n10to10 ) ) + nvgStrokeColor( vg, nvgRGBA( 255, 255, 255, 255 ) ); + else + nvgStrokeColor( vg, nvgRGBA( 80, 80, 80, 255 ) ); + + nvgBeginPath(vg); + nvgMoveTo( vg, 0, y ); + nvgLineTo( vg, box.size.x - 1, y ); + nvgStroke( vg ); + y += divsize; + } + + if( m_bGateMode[ m_currentChannel ] ) + { + // draw rects + for( h = 0; h < ENVELOPE_DIVISIONS; h++ ) + { + nvgBeginPath(vg); + nvgRect( vg, h * m_divw, ( 1.0f - m_HandleVal[ m_currentChannel ][ h ] ) * box.size.y, m_divw, box.size.y * m_HandleVal[ m_currentChannel ][ h ] ); + nvgFillColor(vg, nvgRGBA( 157, 100, 100, 128 ) ); + nvgFill(vg); + } + } + else + { + nvgStrokeColor( vg, nvgRGBA( 255, 255, 255, 255 ) ); + nvgBeginPath(vg); + + x = 0; + nvgMoveTo( vg, x, ( 1.0f - m_HandleVal[ m_currentChannel ][ 0 ] ) * box.size.y ); + + // draw lines + for( h = 1; h < ENVELOPE_HANDLES; h++ ) + { + x += m_divw; + nvgLineTo( vg, x, ( 1.0f - m_HandleVal[ m_currentChannel ][ h ] ) * box.size.y ); + } + + nvgStroke( vg ); + + x = 0; + // draw handles + for( h = 0; h < ENVELOPE_DIVISIONS + 1; h++ ) + { + nvgBeginPath(vg); + y = ( 1.0f - m_HandleVal[ m_currentChannel ][ h ] ) * box.size.y; + nvgRect( vg, x - m_handleSizeD2, y - m_handleSizeD2, m_handleSize, m_handleSize ); + nvgFillColor(vg, nvgRGBA( m_HandleCol[ h ].Col[ 2 ], m_HandleCol[ h ].Col[ 1 ], m_HandleCol[ h ].Col[ 0 ],255 ) ); + nvgFill(vg); + + x += m_divw; + } + } + + // draw indicator line + nvgStrokeColor( vg, nvgRGBA( 255, 255, 255, 80 ) ); + nvgBeginPath(vg); + nvgMoveTo( vg, m_fIndicator[ m_currentChannel ] * box.size.x, 0 ); + nvgLineTo( vg, m_fIndicator[ m_currentChannel ] * box.size.x, box.size.y ); + nvgStroke( vg ); +} + +//----------------------------------------------------- +// Procedure: onMouseDown +//----------------------------------------------------- +void Widget_EnvelopeEdit::onMouseDown( EventMouseDown &e ) +{ + int index; + + m_Drag = -1; + e.consumed = false; + + OpaqueWidget::onMouseDown( e ); + + if( !m_bInitialized ) + return; + + if( e.button == 0 ) + { + if( !m_bDraw ) + windowCursorLock(); + + if( m_bGateMode[ m_currentChannel ] ) + m_Drag = clamp( ( e.pos.x / box.size.x ) * (float)ENVELOPE_DIVISIONS, 0.0f, (float)(ENVELOPE_DIVISIONS - 1) ); + else + m_Drag = clamp( ( ( e.pos.x + (m_divw / 2.0f) ) / box.size.x ) * (float)ENVELOPE_DIVISIONS, 0.0f, (float)ENVELOPE_DIVISIONS ); + + m_bDrag = true; + } + else if( e.button == 1 ) + { + if( m_bGateMode[ m_currentChannel ] ) + index = clamp( ( e.pos.x / box.size.x ) * (float)ENVELOPE_DIVISIONS, 0.0f, (float)(ENVELOPE_DIVISIONS - 1) ); + else + index = clamp( ( ( e.pos.x + (m_divw / 2.0f) ) / box.size.x ) * (float)ENVELOPE_DIVISIONS, 0.0f, (float)ENVELOPE_DIVISIONS ); + + m_HandleVal[ m_currentChannel ][ index ] = 0.0f; + } +} + +//----------------------------------------------------- +// Procedure: onDragStart +//----------------------------------------------------- +void Widget_EnvelopeEdit::onDragStart(EventDragStart &e) +{ + e.consumed = true; + //windowCursorLock(); +} + +//----------------------------------------------------- +// Procedure: onDragEnd +//----------------------------------------------------- +void Widget_EnvelopeEdit::onDragEnd(EventDragEnd &e) +{ + e.consumed = true; + windowCursorUnlock(); + m_Drag = -1; +} + +//----------------------------------------------------- +// Procedure: onMouseMove +//----------------------------------------------------- +void Widget_EnvelopeEdit::onMouseMove( EventMouseMove &e ) +{ + OpaqueWidget::onMouseMove( e ); + + if( m_bDrag && m_bDraw ) + { + m_Drawy = e.pos.y; + + if( m_bGateMode[ m_currentChannel ] ) + m_Drag = clamp( ( e.pos.x / box.size.x ) * (float)ENVELOPE_DIVISIONS, 0.0f, (float)(ENVELOPE_DIVISIONS - 1) ); + else + m_Drag = clamp( ( ( e.pos.x + (m_divw / 2.0f) ) / box.size.x ) * (float)ENVELOPE_DIVISIONS, 0.0f, (float)ENVELOPE_DIVISIONS ); + } +} + +//----------------------------------------------------- +// Procedure: onDragMove +//----------------------------------------------------- +void Widget_EnvelopeEdit::onDragMove(EventDragMove &e) +{ + int h, i; + float fband; + float delta = 0.001f; + + e.consumed = true; + + if( !m_bInitialized || !m_bDrag ) + return; + + if( !m_bDraw ) + { + // Drag slower if Mod is held + if (windowIsModPressed()) + delta = 0.00001f; + + m_HandleVal[ m_currentChannel ][ m_Drag ] -= delta * e.mouseRel.y; + m_HandleVal[ m_currentChannel ][ m_Drag ] = clamp( m_HandleVal[ m_currentChannel ][ m_Drag ], 0.0f, 1.0f ); + + if( m_pCallback ) + m_pCallback( m_pClass, getActualVal( m_currentChannel, m_HandleVal[ m_currentChannel ][ m_Drag ] ) ); + + if( m_fband > 0.0001 ) + { + fband = m_fband; + + for( h = -1; h > -4; h -- ) + { + i = m_Drag + h; + + if( i < 0 ) + break; + + m_HandleVal[ m_currentChannel ][ i ] -= (delta * e.mouseRel.y) * fband; + m_HandleVal[ m_currentChannel ][ i ] = clamp( m_HandleVal[ m_currentChannel ][ i ], 0.0f, 1.0f ); + + fband *= 0.6f; + } + + fband = m_fband; + + for( h = 1; h < 4; h ++ ) + { + i = m_Drag + h; + + if( i > ENVELOPE_DIVISIONS ) + break; + + m_HandleVal[ m_currentChannel ][ i ] -= (delta * e.mouseRel.y) * fband; + m_HandleVal[ m_currentChannel ][ i ] = clamp( m_HandleVal[ m_currentChannel ][ i ], 0.0f, 1.0f ); + + fband *= 0.6f; + } + + recalcLine( -1, m_Drag ); + } + else + { + recalcLine( m_currentChannel, m_Drag ); + } + } + else + { + m_HandleVal[ m_currentChannel ][ m_Drag ] = 1.0 - ( m_Drawy / box.size.y ); + m_HandleVal[ m_currentChannel ][ m_Drag ] = clamp( m_HandleVal[ m_currentChannel ][ m_Drag ], 0.0f, 1.0f ); + + if( m_pCallback ) + m_pCallback( m_pClass, getActualVal( m_currentChannel, m_HandleVal[ m_currentChannel ][ m_Drag ] ) ); + + recalcLine( m_currentChannel, m_Drag ); + } +} + +//----------------------------------------------------- +// Procedure: setBeatLen +//----------------------------------------------------- +void Widget_EnvelopeEdit::setBeatLen( int len ) +{ + m_BeatLen = len; + m_bClkd = true; + + if( m_BeatLen <= 0 ) + return; + + for( int i = 0; i < MAX_ENVELOPE_CHANNELS; i++ ) + { + switch( m_TimeDiv[ i ] ) + { + case TIME_64th: + m_Clock[ i ].syncInc = ( ( engineGetSampleRate() / (float)m_BeatLen ) * 16.0 ) / 16.0; + break; + case TIME_32nd: + m_Clock[ i ].syncInc = ( ( engineGetSampleRate() / (float)m_BeatLen ) * 8.0 ) / 16.0; + break; + case TIME_16th: + m_Clock[ i ].syncInc = ( ( engineGetSampleRate() / (float)m_BeatLen ) * 4.0 ) / 16.0; + break; + case TIME_8th: + m_Clock[ i ].syncInc = ( ( engineGetSampleRate() / (float)m_BeatLen ) * 2.0 ) / 16.0; + break; + case TIME_4tr: + m_Clock[ i ].syncInc = ( ( engineGetSampleRate() / (float)m_BeatLen ) * 1.0 ) / 16.0; + break; + case TIME_Bar: + m_Clock[ i ].syncInc = ( ( engineGetSampleRate() / (float)m_BeatLen ) * 0.25 ) / 16.0; + break; + } + } +} + +//----------------------------------------------------- +// Procedure: procStep +//----------------------------------------------------- +bool Widget_EnvelopeEdit::process_state( int ch, bool bTrig, bool bHold ) +{ + switch( m_Clock[ ch ].state ) + { + case STATE_RUN: + case STATE_RUN_REV: + + if( bHold ) + { + m_Clock[ ch ].prevstate = m_Clock[ ch ].state; + m_Clock[ ch ].state = STATE_HOLD; + break; + } + + // run reverse + if( m_Clock[ ch ].state == STATE_RUN_REV ) + { + m_Clock[ ch ].fpos -= m_Clock[ ch ].syncInc; + + if( m_Clock[ ch ].fpos <= 0.0f ) + { + switch( m_Mode[ ch ] ) + { + case MODE_TWOSHOT: + m_Clock[ ch ].fpos = 0; + m_Clock[ ch ].state = STATE_WAIT_TRIG; + break; + + case MODE_PINGPONG: + m_Clock[ ch ].fpos = -m_Clock[ ch ].fpos; + m_Clock[ ch ].state = STATE_RUN; + break; + + case MODE_REVERSE: + default: + m_Clock[ ch ].fpos += engineGetSampleRate(); + } + } + } + // run forward + else + { + m_Clock[ ch ].fpos += m_Clock[ ch ].syncInc; + + if( m_Clock[ ch ].fpos >= engineGetSampleRate() ) + { + switch( m_Mode[ ch ] ) + { + case MODE_ONESHOT: + m_Clock[ ch ].fpos = engineGetSampleRate() - 1.0f;; + m_Clock[ ch ].state = STATE_WAIT_TRIG; + break; + case MODE_TWOSHOT: + m_Clock[ ch ].fpos = engineGetSampleRate() - 1.0f; + m_Clock[ ch ].state = STATE_WAIT_TRIG_REV; + break; + case MODE_PINGPONG: + m_Clock[ ch ].fpos -= (m_Clock[ ch ].fpos - engineGetSampleRate()) * 2.0f; + m_Clock[ ch ].state = STATE_RUN_REV; + break; + case MODE_LOOP: + default: + m_Clock[ ch ].fpos -= engineGetSampleRate(); + } + } + } + + break; + + case STATE_WAIT_TRIG: + if( bTrig ) + { + m_Clock[ ch ].fpos = 0; + m_Clock[ ch ].state = STATE_RUN; + } + break; + case STATE_WAIT_TRIG_REV: + if( bTrig ) + { + m_Clock[ ch ].fpos = engineGetSampleRate(); + m_Clock[ ch ].state = STATE_RUN_REV; + } + break; + + case STATE_HOLD: + if( !bHold ) + { + m_Clock[ ch ].state = m_Clock[ ch ].prevstate; + break; + } + break; + } + + return true; +} + +//----------------------------------------------------- +// Procedure: procStep +//----------------------------------------------------- +float Widget_EnvelopeEdit::procStep( int ch, bool bTrig, bool bHold ) +{ + int handle; + + if( ( m_bClkReset || bTrig ) && !bHold ) + { + if( m_Mode[ ch ] == MODE_REVERSE ) + m_Clock[ ch ].fpos = engineGetSampleRate(); + else + m_Clock[ ch ].fpos = 0; + } + + process_state( ch, bTrig, bHold ); + + m_fIndicator[ ch ] = m_Clock[ ch ].fpos / engineGetSampleRate(); + + handle = (int)( m_Clock[ ch ].fpos / ( engineGetSampleRate() / (float)ENVELOPE_DIVISIONS ) ); + + return valfromline( ch, handle, m_fIndicator[ ch ] * (float) box.size.x ); +} \ No newline at end of file diff --git a/plugins/community/repos/mscHack/src/mscHack_Controls.hpp b/plugins/community/repos/mscHack/src/mscHack_Controls.hpp new file mode 100644 index 00000000..760631a1 --- /dev/null +++ b/plugins/community/repos/mscHack/src/mscHack_Controls.hpp @@ -0,0 +1,2583 @@ +#pragma once + +#define PI 3.14159f +#define DEG2RAD( x ) ( ( x ) * ( PI / 180.0f ) ) +#define RAD2DEG( x ) ( ( x ) * ( 180.0f / PI ) ) + +struct CyanValueLight : ModuleLightWidget +{ + CyanValueLight() + { + addBaseColor( COLOR_CYAN ); + } +}; + +struct OrangeValueLight : ModuleLightWidget +{ + OrangeValueLight() + { + addBaseColor( nvgRGB( 242, 79, 0 ) ); + } +}; + +struct DarkRedValueLight : ModuleLightWidget +{ + DarkRedValueLight() + { + addBaseColor( nvgRGB(0x70, 0, 0x30) ); + } +}; + +struct DarkGreenValueLight : ModuleLightWidget +{ + DarkGreenValueLight() + { + addBaseColor( nvgRGB(0, 0x90, 0x40) );; + } +}; + +struct DarkGreen2ValueLight : ModuleLightWidget +{ + DarkGreen2ValueLight() + { + addBaseColor( nvgRGB(0, 0x40, 0) );; + } +}; + +struct DarkYellow2ValueLight : ModuleLightWidget +{ + DarkYellow2ValueLight() + { + addBaseColor( nvgRGB(0x40, 0x40, 0) );; + } +}; + +#define lvl_to_db( x ) ( 20.0 * log10( x ) ) +#define db_to_lvl( x ) ( 1.0 / pow( 10, x / 20.0 ) ) + +typedef struct +{ + union + { + unsigned int dwCol; + unsigned char Col[ 4 ]; + }; +}RGB_STRUCT; + +#define DWRGB( r, g, b ) (b | g<<8 | r<<16) + +typedef struct +{ + int x, y, x2, y2; +}RECT_STRUCT; + +typedef struct +{ + float fx, fy, fx2, fy2; +}fRECT_STRUCT; + +typedef struct +{ + float fx, fy; +}POINT_STRUCT; + +typedef struct +{ + int nUsed; + POINT_STRUCT p[ 8 ]; +}DRAW_VECT_STRUCT; + +typedef struct +{ + float fx, fy; + float fmx; // as in function y = fx + fn + float fb; + bool bVert; + bool bHorz; + bool bSet; +}fLine; + +//----------------------------------------------------- +// Widget_EnvelopeEdit +//----------------------------------------------------- +#define ENVELOPE_VDIV 8 +#define ENVELOPE_DIVISIONS 16 +#define ENVELOPE_HANDLES ( ENVELOPE_DIVISIONS + 1 ) +#define MAX_ENVELOPE_CHANNELS 9 + +typedef struct +{ + int state, prevstate; + float fpos; + float syncInc; +}EE_CTRL; + + +struct Widget_EnvelopeEdit : OpaqueWidget +{ + typedef void EnvelopeEditCALLBACK ( void *pClass, float val ); + + bool m_bInitialized=false; + bool m_bGateMode[ MAX_ENVELOPE_CHANNELS ] = {false}; + int m_Mode[ MAX_ENVELOPE_CHANNELS ]={MODE_LOOP}; + int m_Range[ MAX_ENVELOPE_CHANNELS ]={RANGE_0to5}; + int m_TimeDiv[ MAX_ENVELOPE_CHANNELS ]={TIME_64th}; + float m_HandleVal[ MAX_ENVELOPE_CHANNELS ][ ENVELOPE_HANDLES ]={}; + fLine m_Lines[ MAX_ENVELOPE_CHANNELS ][ ENVELOPE_HANDLES ]={}; + + float m_divw=0; + float m_handleSize=0, m_handleSizeD2; + int m_currentChannel = 0; + int m_Drag = -1; + float m_fband = 0.0f; + + + bool m_bDrag = false, m_bDraw = false; + float m_Drawy = 0.0f; + + bool m_bClkReset = false; + int m_BeatLen = 0; + + float m_fIndicator[ MAX_ENVELOPE_CHANNELS ] = {}; + + RGB_STRUCT m_HandleCol[ ENVELOPE_HANDLES ]; + EE_CTRL m_Clock[ MAX_ENVELOPE_CHANNELS ] ={}; + + + EnvelopeEditCALLBACK *m_pCallback = NULL; + void *m_pClass = NULL; + + bool m_bClkd = false; + + enum Widget_EnvelopeEdit_Modes + { + MODE_LOOP, + MODE_REVERSE, + MODE_PINGPONG, + MODE_ONESHOT, + MODE_TWOSHOT, + nMODES + }; + + enum Widget_EnvelopeEdit_Ranges + { + RANGE_0to5, + RANGE_n5to5, + RANGE_0to10, + RANGE_n10to10, + nRANGES + }; + + enum Widget_EnvelopeEdit_TimeDivs + { + TIME_64th, + TIME_32nd, + TIME_16th, + TIME_8th, + TIME_4tr, + TIME_Bar, + nTIMEDIVS + }; + + enum Widget_Envelope_States + { + STATE_RUN, + STATE_RUN_REV, + STATE_WAIT_TRIG, + STATE_WAIT_TRIG_REV, + STATE_HOLD, + nSTATES + }; + + Widget_EnvelopeEdit( int x, int y, int w, int h, int handleSize, void *pClass, EnvelopeEditCALLBACK *pCallback ); + + void setView( int ch ); + void resetValAll( int ch, float val ); + void setVal( int ch, int handle, float val ); + void setMode( int ch, int Mode ); + void setRange( int ch, int Range ); + void setGateMode( int ch, bool bGate ); + void setTimeDiv( int ch, int timediv ); + void setBeatLen( int len ); + + int getPos( int ch ); + void setPos( int ch, int pos ); + + void setDataAll( int *pint ); + void getDataAll( int *pint ); + + float getActualVal( int ch, float val ); + + bool process_state( int ch, bool bTrig, bool bHold ); + float procStep( int ch, bool bTrig, bool bHold ); + + float Val2y( float fval ); + float y2Val( float fy ); + + void line_from_points( float x1, float y1, float x2, float y2, fLine *L ); + float valfromline ( int ch, int handle, float x ); + void recalcLine( int ch, int handle ); + + // overrides + void draw( NVGcontext *vg ) override; + void onMouseMove( EventMouseMove &e ) override; + void onMouseDown( EventMouseDown &e ) override; + void onDragStart(EventDragStart &e) override; + void onDragEnd(EventDragEnd &e) override; + void onDragMove(EventDragMove &e) override; +}; + +//----------------------------------------------------- +// MySimpleKnob +//----------------------------------------------------- + +#define MAX_ANGLE 140.0f +#define MIN_ANGLE ( 360.0f - MAX_ANGLE ) +#define RANGE_ANGLE (( MAX_ANGLE * 2.0f ) + 1.0f ) + +struct MySimpleKnob : OpaqueWidget, FramebufferWidget +{ + bool m_bInitialized; + Vec m_Loc; + RGB_STRUCT m_Colour, m_BgColour; + bool m_bNegMode; + float m_radius; + int m_id, m_ch; + float m_fVal; + float m_fangle; + Vec m_Vecpos; + float m_max, m_min, m_default; + int m_nSteps; + void *m_pClass; + + typedef void MySimpleKnobCALLBACK ( void *pClass, int ch, int id, float fval ); + + MySimpleKnobCALLBACK *m_pCallback; + + //----------------------------------------------------- + // Procedure: constructor + //----------------------------------------------------- + MySimpleKnob( void *pClass, float x, float y, float width, unsigned int dwCol, unsigned int dwBgCol, int ch, int id, int nsteps, MySimpleKnobCALLBACK *pCallback, float min, float max, float def ) + { + m_radius = width / 2.0; + m_Loc.x = x + m_radius; + m_Loc.y = y + m_radius; + m_id = id; + m_ch = ch; + m_pClass = pClass; + m_pCallback = pCallback; + m_Colour.dwCol = dwCol; + m_BgColour.dwCol= dwBgCol; + m_nSteps = nsteps; + m_max = max; + m_min = min; + m_default = def; + m_fVal = def; + m_fangle = val2a( def ); + + box.pos = Vec( x, y ); + box.size = Vec( width, width ); + + m_bInitialized = true; + } + + //----------------------------------------------------- + // Procedure: val2a + //----------------------------------------------------- + float val2a( float val ) + { + float a = 0.0f; + + if( m_nSteps ) + { + + } + else + { + a = RANGE_ANGLE * val; + a -= MAX_ANGLE; + } + + return a; + } + + //----------------------------------------------------- + // Procedure: a2val + //----------------------------------------------------- + float a2val( float a ) + { + float val = 0.0f; + + if( m_nSteps ) + { + + } + else + { + a += MAX_ANGLE; + val = a / RANGE_ANGLE; + } + + return val; + } + + //----------------------------------------------------- + // Procedure: draw + //----------------------------------------------------- + void draw( NVGcontext *vg ) override + { + float a1, a2; + float linewidth = m_radius * 0.15f; + + if( !m_bInitialized ) + return; + + a1 = DEG2RAD( 135.0f ); + a2 = DEG2RAD( 45.0f ); + + nvgBeginPath( vg ); + nvgCircle( vg, m_radius, m_radius, m_radius ); + nvgFillColor( vg, nvgRGBA( m_Colour.Col[ 2 ], m_Colour.Col[ 1 ], m_Colour.Col[ 0 ], 255 ) ); + nvgFill( vg ); + + nvgStrokeWidth( vg, linewidth ); + + /*nvgBeginPath( vg ); + nvgStrokeColor( vg, nvgRGBA( m_Colour.Col[ 2 ], m_Colour.Col[ 1 ], m_Colour.Col[ 0 ], 100 ) ); + nvgArc( vg, m_radius, m_radius, m_radius - ( linewidth / 2.0f ), a1, a2, NVG_CW ); + nvgStroke( vg );*/ + + a1 = DEG2RAD( 20.0f ); + a2 = DEG2RAD( 20.0f ); + + nvgBeginPath( vg ); + nvgStrokeColor( vg, nvgRGBA( m_BgColour.Col[ 2 ], m_BgColour.Col[ 1 ], m_BgColour.Col[ 0 ], 255 ) ); + //nvgStrokeColor( vg, nvgRGBA( 255, 255, 255, 160 ) ); + nvgArc( vg, m_radius, m_radius, m_radius, a1, a2, NVG_CW ); + nvgLineTo( vg, m_radius, m_radius ); + nvgStroke( vg ); + + nvgBeginPath( vg ); + nvgCircle( vg, m_radius, m_radius, m_radius * 0.2f ); + nvgFillColor( vg, nvgRGBA( m_Colour.Col[ 2 ], m_Colour.Col[ 1 ], m_Colour.Col[ 0 ], 255 ) ); + nvgFill( vg ); + + dirty = false; + } + + //----------------------------------------------------- + // Procedure: setPos + //----------------------------------------------------- + void setVal( float val ) + { + if( !m_bInitialized ) + return; + + if( val < m_min ) + val = m_min; + else if( val > m_max ) + val = m_max; + + m_fVal = val; + dirty = true; + } + + //----------------------------------------------------- + // Procedure: setCol + //----------------------------------------------------- + void setCol( unsigned int dwCol ) + { + if( !m_bInitialized ) + return; + + m_Colour.dwCol = dwCol; + dirty = true; + } + + //----------------------------------------------------- + // Procedure: setBgCol + //----------------------------------------------------- + void setBgCol( unsigned int dwCol ) + { + if( !m_bInitialized ) + return; + + m_BgColour.dwCol = dwCol; + dirty = true; + } + + //----------------------------------------------------- + // Procedure: onDragStart + //----------------------------------------------------- + void onDragStart(EventDragStart &e) override + { + e.consumed = true; + } + + //----------------------------------------------------- + // Procedure: onDragEnd + //----------------------------------------------------- + void onDragEnd(EventDragEnd &e) override + { + e.consumed = true; + } + + //----------------------------------------------------- + // Procedure: onDragMove + //----------------------------------------------------- + void onDragMove(EventDragMove &e) override + { + m_Vecpos.x = e.mouseRel.x; + m_Vecpos.y = e.mouseRel.y; + + if( m_pCallback ) + m_pCallback( m_pClass, m_ch, m_id, m_fVal ); + + e.consumed = true; + dirty = true; + } +}; + +//----------------------------------------------------- +// MyLED7DigitDisplay +//----------------------------------------------------- +struct MyLED7DigitDisplay : TransparentWidget, FramebufferWidget +{ + bool m_bInitialized = false; + int m_Type; + RGB_STRUCT m_Colour; + RGB_STRUCT m_LEDColour; + int m_iVal; + float m_fVal; + float m_fScale; + float m_fSpace; + float m_MaxDigits; + + enum MyLEDDisplay_Types + { + TYPE_INT, + TYPE_FLOAT + }; + +DRAW_VECT_STRUCT DigitDrawVects[ 8 ] = +{ + { 8, { {58, 0}, {143, 0}, {148, 5}, {148, 9}, {130, 27}, {68, 27}, {51, 10}, {51, 7} } }, // top 0 + { 8, { {39, 17}, {32, 24}, {18, 124}, {24, 130}, {30, 130}, {48, 117}, {59, 33}, {43, 17} } }, // top left 1 + { 8, { {153, 18}, {135, 36}, {124, 118}, {137, 129}, {142, 129}, {151, 122}, {164, 23}, {159, 18} } }, // top right 2 + { 8, { {56, 123}, {35, 137}, {35, 140}, {50, 152}, {111, 152}, {128, 140}, {128, 136}, {114, 123} } }, // middle 3 + { 8, { {24, 145}, {14, 152}, {1, 251}, {7, 257}, {11, 257}, {31, 239}, {41, 156}, {27, 145} } }, // bottom left 4 + { 8, { {137, 145}, {117, 158}, {104, 243}, {119, 258}, {122, 258}, {131, 251}, {147, 152}, {140, 145} } }, // bottom right 5 + { 8, { {38, 247}, {16, 265}, {16, 269}, {22, 275}, {104, 275}, {112, 267}, {112, 264}, {98, 247} } }, // bottom 6 + { 4, { {4 + 154, 240}, {0 + 154, 275}, {32 + 154, 275}, {36 + 154, 240}, {0, 0}, {0, 0}, {0, 0}, {0, 0} } }, // dot +}; + +#define LED_DIGITAL_SCALE_W 160.0f +#define LED_DIGITAL_SCALE_H 275.0f +#define LED_SPACE 210.0f +#define LED_DISPLAY_DIGITS 5 + +int DigitToDisplay[ 10 ][ 8 ] = +{ + { 6, 0, 1, 2, 4, 5, 6, 0 }, // 0 + { 2, 2, 5, 0, 0, 0, 0, 0 }, // 1 + { 5, 0, 2, 3, 4, 6, 0, 0 }, // 2 + { 6, 0, 2, 3, 5, 6, 0, 0 }, // 3 + { 4, 1, 2, 3, 5, 0, 0, 0 }, // 4 + { 5, 0, 1, 3, 5, 6, 0, 0 }, // 5 + { 6, 0, 1, 3, 4, 5, 6, 0 }, // 6 + { 3, 0, 2, 5, 0, 0, 0, 0 }, // 7 + { 7, 0, 1, 2, 3, 4, 5, 6 }, // 8 + { 6, 0, 1, 2, 3, 5, 6, 0 }, // 9 +}; + + //----------------------------------------------------- + // Procedure: Constructor + //----------------------------------------------------- + MyLED7DigitDisplay( int x, int y, float fscale, int colour, int LEDcolour, int type, int maxdigits ) + { + int i, j; + + m_Type = type; + m_Colour.dwCol = colour; + m_LEDColour.dwCol = LEDcolour; + m_fScale = fscale; + m_fSpace = fscale * LED_SPACE; + m_MaxDigits = maxdigits; + + box.pos = Vec( x, y ); + + box.size = Vec( ( ( 5.0f * LED_DIGITAL_SCALE_W ) + ( 4.0f * LED_SPACE ) ) * fscale, LED_DIGITAL_SCALE_H * fscale ); + + // rescale the LED vectors + for( i = 0; i < 8; i++ ) + { + for( j = 0; j < 8; j++ ) + { + DigitDrawVects[ i ].p[ j ].fx *= fscale; + DigitDrawVects[ i ].p[ j ].fy *= fscale; + } + } + + m_bInitialized = true; + } + + //----------------------------------------------------- + // Procedure: SetInt + //----------------------------------------------------- + void SetInt( int ival ) + { + if( !m_bInitialized ) + return; + + if( ival == m_iVal ) + return; + + m_iVal = ival; + dirty = true; + } + + //----------------------------------------------------- + // Procedure: SetFloat + //----------------------------------------------------- + void SetFloat( float fval ) + { + if( !m_bInitialized ) + return; + + if( fval == m_fVal ) + return; + + m_fVal = fval; + dirty = true; + } + + //----------------------------------------------------- + // Procedure: Set + //----------------------------------------------------- + void SetLEDCol( int colour ) + { + m_LEDColour.dwCol = colour; + dirty = true; + } + + //----------------------------------------------------- + // Procedure: Val2Digits + //----------------------------------------------------- + void Val2Digits( int *pdigits ) + { + int temp; + + if( m_Type == TYPE_FLOAT ) + temp = (int)( m_fVal * 100.0 ); + else + temp = m_iVal; + + pdigits[ 0 ] = temp / 10000; + temp -= (pdigits[ 0 ] * 10000 ); + pdigits[ 1 ] = temp / 1000; + temp -= (pdigits[ 1 ] * 1000 ); + pdigits[ 2 ] = temp / 100; + temp -= (pdigits[ 2 ] * 100 ); + pdigits[ 3 ] = temp / 10; + temp -= (pdigits[ 3 ] * 10 ); + pdigits[ 4 ] = temp; + } + + //----------------------------------------------------- + // Procedure: drawvect + //----------------------------------------------------- + void drawvect( NVGcontext *vg, float fx, float fy, DRAW_VECT_STRUCT *pvect, RGB_STRUCT *pRGB, bool bLeadingZero ) + { + int i; + + if( !m_bInitialized ) + return; + + if( bLeadingZero ) + nvgFillColor(vg, nvgRGBA( pRGB->Col[ 2 ], pRGB->Col[ 1 ], pRGB->Col[ 0 ], 0x40 ) ); + else + nvgFillColor(vg, nvgRGB( pRGB->Col[ 2 ], pRGB->Col[ 1 ], pRGB->Col[ 0 ] ) ); + + nvgBeginPath(vg); + + for( i = 0; i < pvect->nUsed; i++ ) + { + if( i == 0 ) + nvgMoveTo(vg, pvect->p[ i ].fx + fx, pvect->p[ i ].fy + fy ); + else + nvgLineTo(vg, pvect->p[ i ].fx + fx, pvect->p[ i ].fy + fy ); + } + + nvgClosePath(vg); + nvgFill(vg); + } + + //----------------------------------------------------- + // Procedure: draw + //----------------------------------------------------- + void draw( NVGcontext *vg ) override + { + int digits[ LED_DISPLAY_DIGITS ] = {}; + float xi; + int i, j; + bool bLeadingZero = true, bLead; + + if( !m_bInitialized ) + return; + + xi = 0; + + // get digits from value + Val2Digits( digits ); + + // draw digits + for( i = (LED_DISPLAY_DIGITS - m_MaxDigits); i < LED_DISPLAY_DIGITS; i++ ) + { + bLead = false; + + if( ( m_Type == TYPE_FLOAT ) && ( i < 2 ) ) + bLead = ( bLeadingZero && digits[ i ] == 0 ); + else if( ( m_Type == TYPE_INT ) && ( i < 4 ) ) + bLead = ( bLeadingZero && digits[ i ] == 0 ); + + for( j = 0; j < DigitToDisplay[ digits[ i ] ][ 0 ]; j++ ) + drawvect( vg, xi, 0, &DigitDrawVects[ DigitToDisplay[ digits[ i ] ][ j + 1 ] ], &m_LEDColour, bLead ); + + if( digits[ i ] != 0 ) + bLeadingZero = false; + + // draw decimal + if( i == 2 && m_Type == TYPE_FLOAT ) + drawvect( vg, xi, 0, &DigitDrawVects[ 7 ], &m_LEDColour, false ); + + xi += m_fSpace; + } + } +}; + +//----------------------------------------------------- +// MyLEDButtonStrip +//----------------------------------------------------- +#define nMAX_STRIP_BUTTONS 32 +struct MyLEDButtonStrip : OpaqueWidget, FramebufferWidget +{ + typedef void MyLEDButtonStripCALLBACK ( void *pClass, int id, int nbutton, bool bOn ); + + bool m_bInitialized = false; + int m_Id; + int m_Type; + int m_nButtons; + bool m_bOn[ nMAX_STRIP_BUTTONS ] = {}; + int m_ExclusiveOn = 0; + int m_HiLightOn = -1; + RGB_STRUCT m_Colour; + RGB_STRUCT m_LEDColour[ nMAX_STRIP_BUTTONS ] = {}; + float m_fLEDsize; + float m_fLEDsize_d2; + + MyLEDButtonStripCALLBACK *m_pCallback; + void *m_pClass; + + RECT_STRUCT m_Rect[ nMAX_STRIP_BUTTONS ]; + + enum MyLEDButton_Types + { + TYPE_EXCLUSIVE, + TYPE_EXCLUSIVE_WOFF, + TYPE_INDEPENDANT + }; + + //----------------------------------------------------- + // Procedure: Constructor + //----------------------------------------------------- + MyLEDButtonStrip( int x, int y, int w, int h, int space, float LEDsize, int nbuttons, bool bVert, int colour, int LEDcolour, int type, int id, void *pClass, MyLEDButtonStripCALLBACK *pCallback ) + { + int i; + + if( nbuttons < 0 || nbuttons > nMAX_STRIP_BUTTONS ) + return; + + m_Id = id; + m_pCallback = pCallback; + m_pClass = pClass; + m_Type = type; + m_Colour.dwCol = colour; + m_nButtons = nbuttons; + m_fLEDsize = LEDsize; + m_fLEDsize_d2 = LEDsize / 2.0f; + + box.pos = Vec( x, y ); + + if( bVert ) + box.size = Vec( w, h * ( nbuttons + space ) ); + else + box.size = Vec( w * ( nbuttons + space ), h ); + + x = 0; + y = 0; + + for( i = 0; i < m_nButtons; i ++) + { + m_LEDColour[ i ].dwCol = LEDcolour; + + m_Rect[ i ].x = x; + m_Rect[ i ].y = y; + m_Rect[ i ].x2 = x + w - 1; + m_Rect[ i ].y2 = y + h - 1; + + if( bVert ) + y += space + h; + else + x += space + w; + } + + m_bInitialized = true; + } + + //----------------------------------------------------- + // Procedure: Set + //----------------------------------------------------- + void SetHiLightOn( int button ) + { + m_HiLightOn = button; + dirty = true; + } + + //----------------------------------------------------- + // Procedure: Set + //----------------------------------------------------- + void Set( int button, bool bOn ) + { + if( !m_bInitialized || button < 0 ) + return; + + if( m_Type == TYPE_EXCLUSIVE_WOFF ) + { + if( button > m_nButtons ) + return; + + m_ExclusiveOn = button; + } + else + { + if( button >= m_nButtons ) + return; + + if( m_Type == TYPE_EXCLUSIVE ) + m_ExclusiveOn = button; + + m_bOn[ button ] = bOn; + } + + dirty = true; + } + + //----------------------------------------------------- + // Procedure: SetLEDCol + //----------------------------------------------------- + void SetLEDCol( int button, int colour ) + { + if( !m_bInitialized || button < 0 || button >= m_nButtons ) + return; + + m_LEDColour[ button ].dwCol = colour; + dirty = true; + } + + //----------------------------------------------------- + // Procedure: draw + //----------------------------------------------------- + void draw(NVGcontext *vg) override + { + float xi, yi; + int i; + char alpha = 0xFF; + + if( !m_bInitialized ) + return; + + for( i = 0; i < m_nButtons; i ++) + { + if( m_HiLightOn == i ) + nvgFillColor( vg, nvgRGB( 255, 255, 255 ) ); + else + nvgFillColor( vg, nvgRGB( m_Colour.Col[ 2 ], m_Colour.Col[ 1 ], m_Colour.Col[ 0 ] ) ); + + // background + nvgBeginPath( vg ); + nvgMoveTo(vg, m_Rect[ i ].x, m_Rect[ i ].y ); + nvgLineTo(vg, m_Rect[ i ].x2, m_Rect[ i ].y ); + nvgLineTo(vg, m_Rect[ i ].x2, m_Rect[ i ].y2 ); + nvgLineTo(vg, m_Rect[ i ].x, m_Rect[ i ].y2 ); + nvgClosePath( vg ); + nvgFill( vg ); + + nvgFillColor( vg, nvgRGB(0x40, 0x40, 0x40) ); + + if( m_HiLightOn == i ) + alpha = 0x40; + + if( m_Type == TYPE_EXCLUSIVE_WOFF ) + { + if( i == ( m_ExclusiveOn - 1 ) ) + nvgFillColor( vg, nvgRGBA( m_LEDColour[ i ].Col[ 2 ], m_LEDColour[ i ].Col[ 1 ], m_LEDColour[ i ].Col[ 0 ], alpha ) ); + } + else if( m_Type == TYPE_EXCLUSIVE ) + { + if( i == m_ExclusiveOn ) + nvgFillColor( vg, nvgRGBA( m_LEDColour[ i ].Col[ 2 ], m_LEDColour[ i ].Col[ 1 ], m_LEDColour[ i ].Col[ 0 ], alpha ) ); + } + else + { + if( m_bOn[ i ] ) + nvgFillColor( vg, nvgRGBA( m_LEDColour[ i ].Col[ 2 ], m_LEDColour[ i ].Col[ 1 ], m_LEDColour[ i ].Col[ 0 ], alpha ) ); + } + + xi = ( ( (float)m_Rect[ i ].x2 + (float)m_Rect[ i ].x ) / 2.0f ) - m_fLEDsize_d2; + yi = ( ( (float)m_Rect[ i ].y2 + (float)m_Rect[ i ].y ) / 2.0f ) - m_fLEDsize_d2; + + nvgBeginPath( vg ); + nvgMoveTo(vg, xi, yi ); + nvgLineTo(vg, xi + m_fLEDsize, yi ); + nvgLineTo(vg, xi + m_fLEDsize, yi + m_fLEDsize ); + nvgLineTo(vg, xi, yi + m_fLEDsize ); + nvgClosePath( vg ); + nvgFill( vg ); + } + } + + //----------------------------------------------------- + // Procedure: isPoint + //----------------------------------------------------- + bool isPoint( RECT_STRUCT *prect, int x, int y ) + { + if( x < prect->x || x > prect->x2 || y < prect->y || y > prect->y2 ) + return false; + + return true; + } + + //----------------------------------------------------- + // Procedure: onMouseDown + //----------------------------------------------------- + void onMouseDown( EventMouseDown &e ) override + { + int i; + e.consumed = false; + + if( !m_bInitialized || e.button != 0 ) + return; + + for( i = 0; i < m_nButtons; i++ ) + { + if( isPoint( &m_Rect[ i ], (int)e.pos.x, (int)e.pos.y ) ) + { + m_bOn[ i ] = !m_bOn[ i ]; + + if( m_Type == TYPE_EXCLUSIVE_WOFF ) + { + if( m_ExclusiveOn == ( i + 1 ) ) + m_ExclusiveOn = 0; + else + m_ExclusiveOn = i + 1; + + if( m_pCallback ) + m_pCallback( m_pClass, m_Id, m_ExclusiveOn, false ); + } + else + { + Set( i, m_bOn[ i ] ); + + if( m_pCallback ) + m_pCallback( m_pClass, m_Id, i, m_bOn[ i ] ); + } + + dirty = true; + e.consumed = true; + return; + } + } + + return; + } +}; + +//----------------------------------------------------- +// MyLEDButton +//----------------------------------------------------- +struct MyLEDButton : OpaqueWidget, FramebufferWidget +{ + typedef void MyLEDButtonCALLBACK ( void *pClass, int id, bool bOn ); + + bool m_bInitialized = false; + int m_Id; + int m_Type; + int m_StepCount = 0; + bool m_bOn = false; + RGB_STRUCT m_Colour; + RGB_STRUCT m_LEDColour; + float m_fLEDsize; + float m_fLEDsize_d2; + + MyLEDButtonCALLBACK *m_pCallback; + void *m_pClass; + + RECT_STRUCT m_Rect; + + enum MyLEDButton_Types + { + TYPE_SWITCH, + TYPE_MOMENTARY + }; + + //----------------------------------------------------- + // Procedure: Constructor + //----------------------------------------------------- + MyLEDButton( int x, int y, int w, int h, float LEDsize, int colour, int LEDcolour, int type, int id, void *pClass, MyLEDButtonCALLBACK *pCallback ) + { + m_Id = id; + m_pCallback = pCallback; + m_pClass = pClass; + m_Type = type; + m_Colour.dwCol = colour; + m_LEDColour.dwCol = LEDcolour; + m_fLEDsize = LEDsize; + m_fLEDsize_d2 = LEDsize / 2.0f; + + box.pos = Vec( x, y ); + box.size = Vec( w, h ); + + m_Rect.x = 0; + m_Rect.y = 0; + m_Rect.x2 = w - 1; + m_Rect.y2 = h - 1; + + m_bInitialized = true; + } + + //----------------------------------------------------- + // Procedure: Set + //----------------------------------------------------- + void Set( bool bOn ) + { + m_bOn = bOn; + dirty = true; + + if( m_Type == TYPE_MOMENTARY && bOn ) + m_StepCount = 8;//(int)( engineGetSampleRate() * 0.05 ); + } + + //----------------------------------------------------- + // Procedure: draw + //----------------------------------------------------- + void draw(NVGcontext *vg) override + { + float xi, yi; + + if( !m_bInitialized ) + return; + + nvgFillColor( vg, nvgRGB( m_Colour.Col[ 2 ], m_Colour.Col[ 1 ], m_Colour.Col[ 0 ] ) ); + + nvgBeginPath( vg ); + nvgRect( vg, 0, 0, box.size.x - 1, box.size.y - 1 ); + nvgClosePath( vg ); + nvgFill( vg ); + + if( !m_bOn ) + nvgFillColor( vg, nvgRGB(0x40, 0x40, 0x40) ); + else + nvgFillColor( vg, nvgRGB( m_LEDColour.Col[ 2 ], m_LEDColour.Col[ 1 ], m_LEDColour.Col[ 0 ] ) ); + + xi = ( ( (float)m_Rect.x2 + (float)m_Rect.x ) / 2.0f ) - m_fLEDsize_d2 ; + yi = ( ( (float)m_Rect.y2 + (float)m_Rect.y ) / 2.0f ) - m_fLEDsize_d2 ; + + nvgBeginPath( vg ); + nvgRoundedRect( vg, xi, yi, m_fLEDsize, m_fLEDsize, 2.5 ); + nvgClosePath( vg ); + nvgFill( vg ); + } + + //----------------------------------------------------- + // Procedure: isPoint + //----------------------------------------------------- + bool isPoint( RECT_STRUCT *prect, int x, int y ) + { + if( x < prect->x || x > prect->x2 || y < prect->y || y > prect->y2 ) + return false; + + return true; + } + + //----------------------------------------------------- + // Procedure: onMouseDown + //----------------------------------------------------- + void onMouseDown( EventMouseDown &e ) override + { + e.consumed = false; + + if( !m_bInitialized || e.button != 0 ) + return; + + if( isPoint( &m_Rect, (int)e.pos.x, (int)e.pos.y ) ) + { + m_bOn = !m_bOn; + + if( m_Type == TYPE_MOMENTARY ) + { + if( m_pCallback ) + { + m_bOn = true; + m_StepCount = 8;//(int)( engineGetSampleRate() * 0.05 ); + m_pCallback( m_pClass, m_Id, true ); + } + } + else + { + if( m_pCallback ) + m_pCallback( m_pClass, m_Id, m_bOn ); + } + + dirty = true; + e.consumed = true; + return; + } + + return; + } + + //----------------------------------------------------- + // Procedure: draw + //----------------------------------------------------- + void step() override + { + if( m_StepCount && ( m_Type == TYPE_MOMENTARY ) ) + { + if( --m_StepCount <= 0 ) + { + m_bOn = false; + m_StepCount = 0; + dirty = true; + } + } + + FramebufferWidget::step(); + } +}; + +//----------------------------------------------------- +// SinglePatternClocked32 +//----------------------------------------------------- +#define MAX_CLK_PAT 32 +#define LEVELS 5 +struct SinglePatternClocked32 : OpaqueWidget, FramebufferWidget +{ + typedef void SINGLEPAT16CALLBACK ( void *pClass, int id, int pat, int level, int maxpat ); + + bool m_bInitialized = false; + int m_Id; + int m_nLEDs; + int m_MaxPat = 0; + int m_PatClk = 0; + int m_PatSelLevel[ MAX_CLK_PAT ] = {0}; + int m_StepCount; + + SINGLEPAT16CALLBACK *m_pCallback; + void *m_pClass; + + RECT_STRUCT m_RectsPatSel[ MAX_CLK_PAT ]; + RGB_STRUCT m_PatCol[ 2 ]; + RECT_STRUCT m_RectsMaxPat[ MAX_CLK_PAT ]; + RGB_STRUCT m_MaxCol[ 2 ]; + + //----------------------------------------------------- + // Procedure: Constructor + //----------------------------------------------------- + SinglePatternClocked32( int x, int y, int w, int h, int mh, int space, int beatspace, int colourPaton, int colourPatoff, int colourMaxon, int colourMaxoff, int nleds, int id, void *pClass, SINGLEPAT16CALLBACK *pCallback ) + { + int i; + + if ( nleds < 2 || nleds > MAX_CLK_PAT ) + return; + + m_Id = id; + m_pCallback = pCallback; + m_pClass = pClass; + m_nLEDs = nleds; + + m_PatCol[ 0 ].dwCol = colourPatoff; + m_PatCol[ 1 ].dwCol = colourPaton; + + m_MaxCol[ 0 ].dwCol = colourMaxoff; + m_MaxCol[ 1 ].dwCol = colourMaxon; + + box.pos = Vec(x, y); + + x = 0; + + for( i = 0; i < m_nLEDs; i++ ) + { + m_RectsMaxPat[ i ].x = x; + m_RectsMaxPat[ i ].y = 0; + m_RectsMaxPat[ i ].x2 = x + w; + m_RectsMaxPat[ i ].y2 = mh; + + m_RectsPatSel[ i ].x = x; + m_RectsPatSel[ i ].y = mh + 2; + m_RectsPatSel[ i ].x2 = x + w; + m_RectsPatSel[ i ].y2 = ( h + mh ) + 2; + + if( ( i & 0x3 ) == 3 ) + x += ( w + beatspace ); + else + x += ( w + space ); + } + + box.size = Vec( x, ( h + mh ) + 2 ); + + m_bInitialized = true; + } + + //----------------------------------------------------- + // Procedure: SetPatAll + //----------------------------------------------------- + void SetPatAll( int *pPat ) + { + if ( !pPat ) + return; + + for( int i = 0; i < m_nLEDs; i++ ) + m_PatSelLevel[ i ] = pPat[ i ];// & 0x3; + + dirty = true; + } + + //----------------------------------------------------- + // Procedure: GetPatAll + //----------------------------------------------------- + void GetPatAll( int *pPat ) + { + if ( !pPat ) + return; + + for( int i = 0; i < m_nLEDs; i++ ) + pPat[ i ] = m_PatSelLevel[ i ]; + + dirty = true; + } + + //----------------------------------------------------- + // Procedure: SetPat + //----------------------------------------------------- + void SetPat( int pat ) + { + if ( pat < 0 || pat >= m_nLEDs ) + return; + + m_PatSelLevel[ pat ] = ( m_PatSelLevel[ pat ] + 1 ); + + if( m_PatSelLevel[ pat ] > LEVELS ) + m_PatSelLevel[ pat ] = 0; + + dirty = true; + } + + //----------------------------------------------------- + // Procedure: SetPat + //----------------------------------------------------- + void ClrPat( int pat ) + { + if ( pat < 0 || pat >= m_nLEDs ) + return; + + m_PatSelLevel[ pat ] = 0; + dirty = true; + } + + //----------------------------------------------------- + // Procedure: ClockInc + //----------------------------------------------------- + bool ClockInc( void ) + { + m_PatClk ++; + + if ( m_PatClk < 0 || m_PatClk > m_MaxPat || m_PatClk >= m_nLEDs ) + m_PatClk = 0; + + dirty = true; + + if( m_PatClk == 0 ) + return true; + + return false; + } + + //----------------------------------------------------- + // Procedure: ClockReset + //----------------------------------------------------- + void ClockReset( void ) + { + m_PatClk = 0; + dirty = true; + } + + //----------------------------------------------------- + // Procedure: SetMax + //----------------------------------------------------- + void SetMax( int max ) + { + m_MaxPat = max; + dirty = true; + } + + //----------------------------------------------------- + // Procedure: draw + //----------------------------------------------------- + void draw(NVGcontext *vg) override + { + float xi, yi; + + RGB_STRUCT rgb = {0}; + int i; + + if( !m_bInitialized ) + return; + + nvgFillColor(vg, nvgRGBA(0, 0, 0, 0xc0)); + nvgBeginPath(vg); + nvgMoveTo(vg, -1, -1 ); + nvgLineTo(vg, box.size.x + 1, -1 ); + nvgLineTo(vg, box.size.x + 1, box.size.y + 1 ); + nvgLineTo(vg, -1, box.size.y + 1 ); + nvgClosePath(vg); + nvgFill(vg); + + nvgStrokeWidth( vg, 0.35 ); + nvgStrokeColor( vg, nvgRGBA( 0xc0, 0xc0, 0xc0, 255 ) ); + + for( i = 0; i < m_nLEDs; i++ ) + { + // max pattern display + if( i <= m_MaxPat ) + nvgFillColor( vg, nvgRGB( m_MaxCol[ 1 ].Col[ 2 ], m_MaxCol[ 1 ].Col[ 1 ], m_MaxCol[ 1 ].Col[ 0 ] ) ); + else + nvgFillColor( vg, nvgRGB( m_MaxCol[ 0 ].Col[ 2 ], m_MaxCol[ 0 ].Col[ 1 ], m_MaxCol[ 0 ].Col[ 0 ] ) ); + + nvgBeginPath(vg); + xi = ( ( (float)m_RectsPatSel[ i ].x2 + (float)m_RectsPatSel[ i ].x ) / 2.0f ); + nvgMoveTo(vg, m_RectsMaxPat[ i ].x, m_RectsMaxPat[ i ].y ); + nvgLineTo(vg, m_RectsMaxPat[ i ].x2, m_RectsMaxPat[ i ].y ); + nvgLineTo(vg, xi, m_RectsMaxPat[ i ].y2 ); + //nvgLineTo(vg, m_RectsMaxPat[ i ].x, m_RectsMaxPat[ i ].y2 ); + nvgClosePath(vg); + nvgFill(vg); + //nvgStroke( vg ); + + // pattern select + rgb.Col[ 0 ] = ( ( m_PatCol[ 1 ].Col[ 0 ] * m_PatSelLevel[ i ] ) + ( m_PatCol[ 0 ].Col[ 0 ] * ( LEVELS - m_PatSelLevel[ i ] ) ) ) / LEVELS; + rgb.Col[ 1 ] = ( ( m_PatCol[ 1 ].Col[ 1 ] * m_PatSelLevel[ i ] ) + ( m_PatCol[ 0 ].Col[ 1 ] * ( LEVELS - m_PatSelLevel[ i ] ) ) ) / LEVELS; + rgb.Col[ 2 ] = ( ( m_PatCol[ 1 ].Col[ 2 ] * m_PatSelLevel[ i ] ) + ( m_PatCol[ 0 ].Col[ 2 ] * ( LEVELS - m_PatSelLevel[ i ] ) ) ) / LEVELS; + + nvgFillColor( vg, nvgRGB( rgb.Col[ 2 ], rgb.Col[ 1 ], rgb.Col[ 0 ] ) ); + + nvgBeginPath(vg); + nvgMoveTo(vg, m_RectsPatSel[ i ].x, m_RectsPatSel[ i ].y ); + nvgLineTo(vg, m_RectsPatSel[ i ].x2, m_RectsPatSel[ i ].y ); + nvgLineTo(vg, m_RectsPatSel[ i ].x2, m_RectsPatSel[ i ].y2 ); + nvgLineTo(vg, m_RectsPatSel[ i ].x, m_RectsPatSel[ i ].y2 ); + nvgClosePath(vg); + nvgFill(vg); + nvgStroke( vg ); + + xi = ( ( (float)m_RectsPatSel[ i ].x2 + (float)m_RectsPatSel[ i ].x ) / 2.0f ) - 2.0f ; + yi = ( ( (float)m_RectsPatSel[ i ].y2 + (float)m_RectsPatSel[ i ].y ) / 2.0f ) - 2.0f ; + + if( i == m_PatClk ) + nvgFillColor( vg, nvgRGBA( 0, 0xFF, 0, 0xFF ) ); + else + nvgFillColor( vg, nvgRGBA( 0, 0, 0, 0xFF ) ); + + nvgBeginPath(vg); + + nvgMoveTo(vg, xi, yi ); + nvgLineTo(vg, xi + 4.0f, yi ); + nvgLineTo(vg, xi + 4.0f, yi + 4.0f ); + nvgLineTo(vg, xi, yi + 4.0f ); + + nvgClosePath(vg); + nvgFill(vg); + } + } + + //----------------------------------------------------- + // Procedure: isPoint + //----------------------------------------------------- + bool isPoint( RECT_STRUCT *prect, int x, int y ) + { + if( x < prect->x || x > prect->x2 || y < prect->y || y > prect->y2 ) + return false; + + return true; + } + + //----------------------------------------------------- + // Procedure: onMouseDown + //----------------------------------------------------- + void onMouseDown( EventMouseDown &e ) override + { + int i; + + e.consumed = false; + + if( !m_bInitialized ) + return; + + for( i = 0; i < m_nLEDs; i++) + { + if( isPoint( &m_RectsPatSel[ i ], (int)e.pos.x, (int)e.pos.y ) ) + { + if( e.button == 0 ) + SetPat( i ); + else + ClrPat( i ); + + if( m_pCallback ) + m_pCallback( m_pClass, m_Id, i, m_PatSelLevel[ i ], m_MaxPat ); + + dirty = true; + e.consumed = true; + return; + } + + else if( isPoint( &m_RectsMaxPat[ i ], (int)e.pos.x, (int)e.pos.y ) ) + { + m_MaxPat = i; + + if( m_pCallback ) + m_pCallback( m_pClass, m_Id, i, m_PatSelLevel[ i ], m_MaxPat ); + + dirty = true; + e.consumed = true; + return; + } + } + + return; + } + + //----------------------------------------------------- + // Procedure: draw + //----------------------------------------------------- + void step() override + { + FramebufferWidget::step(); + } +}; + +//----------------------------------------------------- +// PatternSelectStrip +//----------------------------------------------------- +#define MAX_PAT 32 +struct PatternSelectStrip : OpaqueWidget, FramebufferWidget +{ + typedef void PATCHANGECALLBACK ( void *pClass, int id, int pat, int maxpat ); + + bool m_bInitialized = false; + int m_Id; + int m_nLEDs; + int m_MaxPat = 0; + int m_PatSel = 0; + int m_PatPending = -1; + int m_StepCount; + + PATCHANGECALLBACK *m_pCallback; + void *m_pClass; + + RECT_STRUCT m_RectsMaxPat[ MAX_PAT ]; + RECT_STRUCT m_RectsPatSel[ MAX_PAT ]; + RGB_STRUCT m_PatCol[ 2 ]; + RGB_STRUCT m_MaxCol[ 2 ]; + + //----------------------------------------------------- + // Procedure: Constructor + //----------------------------------------------------- + PatternSelectStrip( int x, int y, int w, int h, int colourPaton, int colourPatoff, int colourMaxon, int colourMaxoff, int nleds, int id, void *pClass, PATCHANGECALLBACK *pCallback ) + { + int i; + + if ( nleds < 0 || nleds > MAX_PAT ) + return; + + m_Id = id; + m_pCallback = pCallback; + m_pClass = pClass; + m_nLEDs = nleds; + + m_PatCol[ 0 ].dwCol = colourPatoff; + m_PatCol[ 1 ].dwCol = colourPaton; + + m_MaxCol[ 0 ].dwCol = colourMaxoff; + m_MaxCol[ 1 ].dwCol = colourMaxon; + + box.pos = Vec(x, y); + box.size = Vec( w * m_nLEDs + ( m_nLEDs * 2 ) - 1, ( h * 2 ) + 2 ); + + x = 0; + + for( i = 0; i < m_nLEDs; i++ ) + { + m_RectsMaxPat[ i ].x = x; + m_RectsMaxPat[ i ].y = 0; + m_RectsMaxPat[ i ].x2 = x + w; + m_RectsMaxPat[ i ].y2 = h; + + m_RectsPatSel[ i ].x = x; + m_RectsPatSel[ i ].y = h + 2; + m_RectsPatSel[ i ].x2 = x + w; + m_RectsPatSel[ i ].y2 = ( h * 2 ) + 2; + + x += ( w + 2 ); + } + + m_bInitialized = true; + } + + //----------------------------------------------------- + // Procedure: SetPat + //----------------------------------------------------- + void SetPat( int pat, bool bPending ) + { + if( bPending ) + m_PatPending = pat; + else + { + m_PatPending = -1; + m_PatSel = pat; + } + + dirty = true; + } + + //----------------------------------------------------- + // Procedure: SetMax + //----------------------------------------------------- + void SetMax( int max ) + { + m_MaxPat = max; + dirty = true; + } + + //----------------------------------------------------- + // Procedure: draw + //----------------------------------------------------- + void draw(NVGcontext *vg) override + { + int i; + float xi; + + if( !m_bInitialized ) + return; + + nvgFillColor(vg, nvgRGBA(0, 0, 0, 0xc0)); + nvgBeginPath(vg); + nvgMoveTo(vg, -1, -1 ); + nvgLineTo(vg, box.size.x + 1, -1 ); + nvgLineTo(vg, box.size.x + 1, box.size.y + 1 ); + nvgLineTo(vg, -1, box.size.y + 1 ); + nvgClosePath(vg); + nvgFill(vg); + + for( i = 0; i < m_nLEDs; i++ ) + { + if( i <= m_MaxPat ) + nvgFillColor( vg, nvgRGB( m_MaxCol[ 1 ].Col[ 2 ], m_MaxCol[ 1 ].Col[ 1 ], m_MaxCol[ 1 ].Col[ 0 ] ) ); + else + nvgFillColor( vg, nvgRGB( m_MaxCol[ 0 ].Col[ 2 ], m_MaxCol[ 0 ].Col[ 1 ], m_MaxCol[ 0 ].Col[ 0 ] ) ); + + + + nvgBeginPath(vg); + xi = ( ( (float)m_RectsPatSel[ i ].x2 + (float)m_RectsPatSel[ i ].x ) / 2.0f ); + nvgMoveTo(vg, m_RectsMaxPat[ i ].x, m_RectsMaxPat[ i ].y ); + nvgLineTo(vg, m_RectsMaxPat[ i ].x2, m_RectsMaxPat[ i ].y ); + nvgLineTo(vg, xi, m_RectsMaxPat[ i ].y2 ); + nvgClosePath(vg); + nvgFill(vg); + + if( m_PatSel == i ) + nvgFillColor( vg, nvgRGB( m_PatCol[ 1 ].Col[ 2 ], m_PatCol[ 1 ].Col[ 1 ], m_PatCol[ 1 ].Col[ 0 ] ) ); + else + nvgFillColor( vg, nvgRGB( m_PatCol[ 0 ].Col[ 2 ], m_PatCol[ 0 ].Col[ 1 ], m_PatCol[ 0 ].Col[ 0 ] ) ); + + nvgBeginPath(vg); + nvgMoveTo(vg, m_RectsPatSel[ i ].x, m_RectsPatSel[ i ].y ); + nvgLineTo(vg, m_RectsPatSel[ i ].x2, m_RectsPatSel[ i ].y ); + nvgLineTo(vg, m_RectsPatSel[ i ].x2, m_RectsPatSel[ i ].y2 ); + nvgLineTo(vg, m_RectsPatSel[ i ].x, m_RectsPatSel[ i ].y2 ); + nvgClosePath(vg); + nvgFill(vg); + + if( m_PatPending == i ) + { + nvgFillColor( vg, nvgRGBA( m_PatCol[ 1 ].Col[ 2 ], m_PatCol[ 1 ].Col[ 1 ], m_PatCol[ 1 ].Col[ 0 ], 0x50 ) ); + + nvgBeginPath(vg); + nvgMoveTo(vg, m_RectsPatSel[ i ].x, m_RectsPatSel[ i ].y ); + nvgLineTo(vg, m_RectsPatSel[ i ].x2, m_RectsPatSel[ i ].y ); + nvgLineTo(vg, m_RectsPatSel[ i ].x2, m_RectsPatSel[ i ].y2 ); + nvgLineTo(vg, m_RectsPatSel[ i ].x, m_RectsPatSel[ i ].y2 ); + nvgClosePath(vg); + nvgFill(vg); + } + } + } + + //----------------------------------------------------- + // Procedure: isPoint + //----------------------------------------------------- + bool isPoint( RECT_STRUCT *prect, int x, int y ) + { + if( x < prect->x || x > prect->x2 || y < prect->y || y > prect->y2 ) + return false; + + return true; + } + + //----------------------------------------------------- + // Procedure: onMouseDown + //----------------------------------------------------- + void onMouseDown( EventMouseDown &e ) override + { + int i; + + e.consumed = false; + + if( !m_bInitialized ) + return; + + if( e.button != 0 ) + return; + + for( i = 0; i < m_nLEDs; i++) + { + if( isPoint( &m_RectsMaxPat[ i ], (int)e.pos.x, (int)e.pos.y ) ) + { + m_MaxPat = i; + + if( m_pCallback ) + m_pCallback( m_pClass, m_Id, m_PatSel, m_MaxPat ); + + dirty = true; + e.consumed = true; + return; + } + + else if( isPoint( &m_RectsPatSel[ i ], (int)e.pos.x, (int)e.pos.y ) ) + { + m_PatSel = i; + + if( m_pCallback ) + m_pCallback( m_pClass, m_Id, m_PatSel, m_MaxPat ); + + e.consumed = true; + return; + } + } + + return; + } + + //----------------------------------------------------- + // Procedure: draw + //----------------------------------------------------- + void step() override + { + FramebufferWidget::step(); + } +}; + +//----------------------------------------------------- +// CompressorLEDMeterWidget +//----------------------------------------------------- +#define nDISPLAY_LEDS 10 +const float fleveldb[ nDISPLAY_LEDS ] = { 0, 3, 6, 10, 20, 30, 40, 50, 60, 80 }; +struct CompressorLEDMeterWidget : TransparentWidget +{ + bool m_bInitialized = false; + bool m_bOn[ nDISPLAY_LEDS ] = {}; + int m_StepCount = 0; + float m_fLargest = 0; + RECT_STRUCT m_Rects[ nDISPLAY_LEDS ]; + RGB_STRUCT m_ColourOn; + RGB_STRUCT m_ColourOff; + bool m_bInvert; + + float flevels[ nDISPLAY_LEDS ]; + + //----------------------------------------------------- + // Procedure: Constructor + //----------------------------------------------------- + CompressorLEDMeterWidget( bool bInvert, int x, int y, int w, int h, int colouron, int colouroff ) + { + int i; + + m_bInvert = bInvert; + m_ColourOn.dwCol = colouron; + m_ColourOff.dwCol = colouroff; + + box.pos = Vec(x, y); + box.size = Vec( w, h * nDISPLAY_LEDS + ( nDISPLAY_LEDS * 2 ) ); + + y = 1; + + for( i = 0; i < nDISPLAY_LEDS; i++ ) + { + flevels[ i ] = db_to_lvl( fleveldb[ i ] ); + + m_Rects[ i ].x = 0; + m_Rects[ i ].y = y; + m_Rects[ i ].x2 = w; + m_Rects[ i ].y2 = y + h; + + y += ( h + 2 ); + } + + m_bInitialized = true; + } + + //----------------------------------------------------- + // Procedure: draw + //----------------------------------------------------- + void draw(NVGcontext *vg) override + { + int i; + + if( !m_bInitialized ) + return; + + nvgFillColor(vg, nvgRGBA(0, 0, 0, 0xc0)); + nvgBeginPath(vg); + nvgMoveTo(vg, -1, -1 ); + nvgLineTo(vg, box.size.x + 1, -1 ); + nvgLineTo(vg, box.size.x + 1, box.size.y + 1 ); + nvgLineTo(vg, -1, box.size.y + 1 ); + nvgClosePath(vg); + nvgFill(vg); + + for( i = 0; i < nDISPLAY_LEDS; i++ ) + { + if( m_bOn[ i ] ) + nvgFillColor( vg, nvgRGB( m_ColourOn.Col[ 2 ], m_ColourOn.Col[ 1 ], m_ColourOn.Col[ 0 ] ) ); + else + nvgFillColor( vg, nvgRGB( m_ColourOff.Col[ 2 ], m_ColourOff.Col[ 1 ], m_ColourOff.Col[ 0 ] ) ); + + nvgBeginPath(vg); + nvgMoveTo(vg, m_Rects[ i ].x, m_Rects[ i ].y ); + nvgLineTo(vg, m_Rects[ i ].x2, m_Rects[ i ].y ); + nvgLineTo(vg, m_Rects[ i ].x2, m_Rects[ i ].y2 ); + nvgLineTo(vg, m_Rects[ i ].x, m_Rects[ i ].y2 ); + nvgClosePath(vg); + nvgFill(vg); + } + } + + //----------------------------------------------------- + // Procedure: Process + //----------------------------------------------------- + void Process( float level ) + { + int steptime = (int)( engineGetSampleRate() * 0.05f ); + int i; + + if( !m_bInitialized ) + return; + + if( fabs( level ) > m_fLargest ) + m_fLargest = fabs( level ); + + // only process every 1/10th of a second + if( ++m_StepCount >= steptime ) + { + m_StepCount = 0; + + if( m_bInvert ) + { + for( i = 0; i < nDISPLAY_LEDS; i++ ) + { + if( m_fLargest >= flevels[ i ] ) + m_bOn[ ( nDISPLAY_LEDS - 1 ) - i ] = true; + else + m_bOn[ ( nDISPLAY_LEDS - 1 ) - i ] = false; + } + } + else + { + for( i = 0; i < nDISPLAY_LEDS; i++ ) + { + if( m_fLargest >= flevels[ i ] ) + m_bOn[ i ] = true; + else + m_bOn[ i ] = false; + } + } + + m_fLargest = 0.0f; + } + } +}; + +//----------------------------------------------------- +// LEDMeterWidget +//----------------------------------------------------- +struct LEDMeterWidget : TransparentWidget +{ + bool m_bInitialized = false; + bool m_bOn[ nDISPLAY_LEDS ] = {}; + int m_space; + int m_StepCount = 0; + bool m_bVert; + float m_fLargest = 0.0; + RECT_STRUCT m_Rects[ nDISPLAY_LEDS ]; + RGB_STRUCT m_ColoursOn[ nDISPLAY_LEDS ]; + RGB_STRUCT m_ColoursOff[ nDISPLAY_LEDS ]; + float flevels[ nDISPLAY_LEDS ] = {}; + + //----------------------------------------------------- + // Procedure: Constructor + //----------------------------------------------------- + LEDMeterWidget( int x, int y, int w, int h, int space, bool bVert ) + { + int i, xoff = 0, yoff = 0, xpos = 0, ypos = 0; + + m_space = space; + box.pos = Vec(x, y); + + if( bVert ) + { + box.size = Vec( w, h * nDISPLAY_LEDS + (m_space * nDISPLAY_LEDS) ); + yoff = h + m_space; + } + else + { + box.size = Vec( w * nDISPLAY_LEDS + (m_space * nDISPLAY_LEDS), h ); + xoff = w + m_space; + } + + for( i = 0; i < nDISPLAY_LEDS; i++ ) + { + flevels[ i ] = db_to_lvl( fleveldb[ i ] ); + + m_Rects[ i ].x = xpos; + m_Rects[ i ].y = ypos; + m_Rects[ i ].x2 = xpos + w; + m_Rects[ i ].y2 = ypos + h; + + // always red + if( i == 0 ) + { + m_ColoursOn[ i ].dwCol = DWRGB( 0xFF, 0, 0 ); + m_ColoursOff[ i ].dwCol= DWRGB( 0x80, 0, 0 ); + } + // yellow + else if( i < 3 ) + { + m_ColoursOn[ i ].dwCol = DWRGB( 0xFF, 0xFF, 0 ); + m_ColoursOff[ i ].dwCol= DWRGB( 0x80, 0x80, 0 ); + } + // green + else + { + m_ColoursOn[ i ].dwCol = DWRGB( 0, 0xFF, 0 ); + m_ColoursOff[ i ].dwCol= DWRGB( 0, 0x80, 0 ); + } + + xpos += xoff; + ypos += yoff; + } + + m_bInitialized = true; + } + + //----------------------------------------------------- + // Procedure: draw + //----------------------------------------------------- + void draw(NVGcontext *vg) override + { + int i; + + if( !m_bInitialized ) + return; + + nvgFillColor(vg, nvgRGBA(0, 0, 0, 0xc0)); + nvgBeginPath(vg); + nvgMoveTo(vg, -1, -1 ); + nvgLineTo(vg, box.size.x + 1, -1 ); + nvgLineTo(vg, box.size.x + 1, box.size.y + 1 ); + nvgLineTo(vg, -1, box.size.y + 1 ); + nvgClosePath(vg); + nvgFill(vg); + + for( i = 0; i < nDISPLAY_LEDS; i++ ) + { + if( m_bOn[ i ] ) + nvgFillColor( vg, nvgRGB( m_ColoursOn[ i ].Col[ 2 ], m_ColoursOn[ i ].Col[ 1 ], m_ColoursOn[ i ].Col[ 0 ] ) ); + else + nvgFillColor( vg, nvgRGB( m_ColoursOff[ i ].Col[ 2 ], m_ColoursOff[ i ].Col[ 1 ], m_ColoursOff[ i ].Col[ 0 ] ) ); + + nvgBeginPath(vg); + nvgMoveTo(vg, m_Rects[ i ].x, m_Rects[ i ].y ); + nvgLineTo(vg, m_Rects[ i ].x2, m_Rects[ i ].y ); + nvgLineTo(vg, m_Rects[ i ].x2, m_Rects[ i ].y2 ); + nvgLineTo(vg, m_Rects[ i ].x, m_Rects[ i ].y2 ); + nvgClosePath(vg); + nvgFill(vg); + } + } + + //----------------------------------------------------- + // Procedure: Process + //----------------------------------------------------- + void Process( float level ) + { + int steptime = (int)( engineGetSampleRate() * 0.05 ); + int i; + + if( !m_bInitialized ) + return; + + if( fabs( level ) > m_fLargest ) + m_fLargest = fabs( level ); + + // only process every 1/10th of a second + if( ++m_StepCount >= steptime ) + { + m_StepCount = 0; + + for( i = 0; i < nDISPLAY_LEDS; i++ ) + { + if( m_fLargest >= flevels[ i ] ) + m_bOn[ i ] = true; + else + m_bOn[ i ] = false; + } + + m_fLargest = 0.0; + } + } +}; + +//----------------------------------------------------- +// Keyboard_3Oct_Widget +//----------------------------------------------------- +struct Keyboard_3Oct_Widget : OpaqueWidget, FramebufferWidget +{ + typedef void NOTECHANGECALLBACK ( void *pClass, int kb, int notepressed, int *pnotes, bool bOn, int button ); + +#define nKEYS 37 +#define MAX_MULT_KEYS 16 +#define OCT_OFFSET_X 91 + + bool m_bInitialized = false; + RGB_STRUCT m_rgb_white, m_rgb_black, m_rgb_on; + CLog *lg; + int m_MaxMultKeys = 1; + int m_KeySave[ MAX_MULT_KEYS ] = {0}; + bool m_bKeyOnList[ nKEYS ] = {false}; + int m_nKeysOn = 0; + int m_KeyOn = 0; + RECT_STRUCT keyrects[ nKEYS ] ={}; + NOTECHANGECALLBACK *pNoteChangeCallback = NULL; + void *m_pClass = NULL; + int m_nKb; + +DRAW_VECT_STRUCT OctaveKeyDrawVects[ nKEYS ] = +{ + { 6, { {1, 1}, {1, 62}, {12, 62}, {12, 39}, {7, 39}, {7, 1}, {0, 0}, {0, 0} } }, + { 4, { {8, 1}, {8, 38}, {16, 38}, {16, 1}, {0, 0}, {0, 0}, {0, 0}, {0, 0} } }, + { 8, { {17, 1}, {17, 39}, {14, 39}, {14, 62}, {25, 62}, {25, 39}, {22, 39}, {22, 1} } }, + { 4, { {23, 1}, {23, 38}, {31, 38}, {31, 1}, {0, 0}, {0, 0}, {0, 0}, {0, 0} } }, + { 6, { {32, 1}, {32, 39}, {27, 39}, {27, 62}, {38, 62}, {38, 1}, {0, 0}, {0, 0} } }, + { 6, { {40, 1}, {40, 62}, {51, 62}, {51, 39}, {46, 39}, {46, 1}, {0, 0}, {0, 0} } }, + { 4, { {47, 1}, {47, 38}, {55, 38}, {55, 1}, {0, 0}, {0, 0}, {0, 0}, {0, 0} } }, + { 8, { {56, 1}, {56, 39}, {53, 39}, {53, 62}, {64, 62}, {64, 39}, {60, 39}, {60, 1} } }, + { 4, { {61, 1}, {61, 38}, {69, 38}, {69, 1}, {0, 0}, {0, 0}, {0, 0}, {0, 0} } }, + { 8, { {70, 1}, {70, 39}, {66, 39}, {66, 62}, {77, 62}, {77, 39}, {74, 39}, {74, 1} } }, + { 4, { {75, 1}, {75, 38}, {83, 38}, {83, 1}, {0, 0}, {0, 0}, {0, 0}, {0, 0} } }, + { 6, { {84, 1}, {84, 39}, {79, 39}, {79, 62}, {90, 62}, {90, 1}, {0, 0}, {0, 0} } }, +}; + +int keysquare_x[ nKEYS ] = +{ + 1, 8, 14, 23, 27, 40, 47, 53, 61, 66, 75, 79 +}; + +DRAW_VECT_STRUCT OctaveKeyHighC [ 1 ] = +{ + { 5, { {1, 1}, {1, 62}, {12, 62}, {12, 44}, {12, 1}, {0, 0}, {0, 0}, {0, 0} } } +}; + + //----------------------------------------------------- + // Procedure: Constructor + //----------------------------------------------------- + Keyboard_3Oct_Widget( int x, int y, int maxkeysel, int nKb, unsigned int rgbon, void *pClass, NOTECHANGECALLBACK *pcallback, CLog *plog ) + { + int i, j, oct = 0; + + if( maxkeysel > MAX_MULT_KEYS ) + return; + + m_MaxMultKeys = maxkeysel; + pNoteChangeCallback = pcallback; + m_pClass = pClass; + m_nKb = nKb; + m_KeyOn = -1; + m_rgb_on.dwCol = rgbon; + + lg = plog; + + box.pos = Vec(x, y); + + // calc key rects and calculate the remainder of the key vec list + for( i = 0; i < nKEYS; i++ ) + { + if( i >= 12 ) + { + oct = i / 12; + + if( i == (nKEYS-1) ) + { + // populate the rest of the key vect table based on the first octave + memcpy( &OctaveKeyDrawVects[ i ], &OctaveKeyHighC[ 0 ], sizeof(DRAW_VECT_STRUCT) ); + + for( j = 0; j < 8; j++ ) + OctaveKeyDrawVects[ i ].p[ j ].fx = OctaveKeyHighC[ 0 ].p[ j ].fx + ( OCT_OFFSET_X * oct ); + + keysquare_x[ i ] = keysquare_x[ 0 ] + ( OCT_OFFSET_X * oct ); + } + else + { + // populate the rest of the key vect table based on the first octave + memcpy( &OctaveKeyDrawVects[ i ], &OctaveKeyDrawVects[ i - ( oct * 12 ) ], sizeof(DRAW_VECT_STRUCT) ); + + for( j = 0; j < 8; j++ ) + OctaveKeyDrawVects[ i ].p[ j ].fx = OctaveKeyDrawVects[ i - ( oct * 12 ) ].p[ j ].fx + ( OCT_OFFSET_X * oct ); + + keysquare_x[ i ] = keysquare_x[ i - ( oct * 12 ) ] + ( OCT_OFFSET_X * oct ); + } + } + + // build the key rects for key press detection + keyrects[ i ].x = keysquare_x[ i ]- 1; + keyrects[ i ].y = 1; + + if( OctaveKeyDrawVects[ i ].nUsed == 4 ) + { + // black key + keyrects[ i ].x2 = keyrects[ i ].x + 9; + keyrects[ i ].y2 = keyrects[ i ].y + 43; + } + else + { + // white key + keyrects[ i ].x2 = keyrects[ i ].x + 14; + keyrects[ i ].y2 = keyrects[ i ].y + 67; + } + } + + box.size = Vec( keyrects[ (nKEYS-1) ].x2, 62 ); + + m_rgb_white.dwCol = DWRGB( 215, 207, 198 ); + m_rgb_black.dwCol = 0; + memset( m_KeySave, 0xFF, sizeof(m_KeySave) ); + + m_bInitialized = true; + } + + //----------------------------------------------------- + // Procedure: addtokeylist + //----------------------------------------------------- + void addtokeylist( int key, int button ) + { + int count = 0; + bool bOn = false; + + // single key + if( m_MaxMultKeys == 1 ) + { + m_KeySave[ 0 ] = key; + bOn = true; + } + else + { + // if key is off we are turning it on, check max keys + if( !m_bKeyOnList[ key ] ) + { + // ignore if we already have max keys + if( ( m_nKeysOn + 1 ) > m_MaxMultKeys ) + return; + + bOn = true; + m_nKeysOn++; + m_bKeyOnList[ key ] = true; + } + else + { + m_nKeysOn--; + m_bKeyOnList[ key ] = false; + } + + memset( m_KeySave, 0xFF, sizeof(m_KeySave) ); + + // build key list + for( int i = 0; i < nKEYS; i++ ) + { + if( m_bKeyOnList[ i ] ) + m_KeySave[ count++ ] = i; + } + } + + if( pNoteChangeCallback ) + pNoteChangeCallback( m_pClass, m_nKb, key, m_KeySave, bOn, button ); + } + + //----------------------------------------------------- + // Procedure: isPoint + //----------------------------------------------------- + bool isPoint( RECT_STRUCT *prect, int x, int y ) + { + if( x < prect->x || x > prect->x2 || y < prect->y || y > prect->y2 ) + return false; + + return true; + } + + //----------------------------------------------------- + // Procedure: onMouseDown + //----------------------------------------------------- + void onMouseDown( EventMouseDown &e ) override + { + int i; + + e.consumed = false; + + if( !m_bInitialized ) + return; + + // check black keys first they are on top + for( i = 0; i < nKEYS; i++) + { + if( OctaveKeyDrawVects[ i ].nUsed == 4 && isPoint( &keyrects[ i ], (int)e.pos.x, (int)e.pos.y ) ) + { + addtokeylist( i, e.button ); + dirty = true; + e.consumed = true; + return; + } + } + + // check white keys + for( i = 0; i < nKEYS; i++) + { + if( OctaveKeyDrawVects[ i ].nUsed != 4 && isPoint( &keyrects[ i ], (int)e.pos.x, (int)e.pos.y ) ) + { + addtokeylist( i, e.button ); + dirty = true; + e.consumed = true; + return; + } + } + + return; + } + + //----------------------------------------------------- + // Procedure: setkey + //----------------------------------------------------- + void setkey( int *pkey ) + { + memset( m_bKeyOnList, 0, sizeof( m_bKeyOnList ) ); + memset( m_KeySave, 0xFF, sizeof( m_KeySave ) ); + m_nKeysOn = 0; + + // build key list + for( int i = 0; i < m_MaxMultKeys; i++ ) + { + if( pkey[ i ] != -1 ) + { + m_nKeysOn++; + m_bKeyOnList[ pkey[ i ] ] = true; + m_KeySave[ i ] = pkey[ i ]; + } + } + + dirty = true; + } + + //----------------------------------------------------- + // Procedure: setkeyhighlight + //----------------------------------------------------- + void setkeyhighlight( int key ) + { + m_KeyOn = key; + dirty = true; + } + + //----------------------------------------------------- + // Procedure: drawkey + //----------------------------------------------------- + void drawkey( NVGcontext *vg, int key, bool bOn ) + { + int i; + + if( !m_bInitialized ) + return; + + if( key < 0 || key >= nKEYS ) + return; + + if( bOn ) + { + // hilite on + if( key == m_KeyOn ) + nvgFillColor( vg, nvgRGBA( m_rgb_on.Col[ 2 ], m_rgb_on.Col[ 1 ], m_rgb_on.Col[ 0 ], 0x80 ) ); + // normal on + else + nvgFillColor( vg, nvgRGB( m_rgb_on.Col[ 2 ], m_rgb_on.Col[ 1 ], m_rgb_on.Col[ 0 ] ) ); + } + else + { + if( OctaveKeyDrawVects[ key ].nUsed == 4 ) + nvgFillColor( vg, nvgRGB( m_rgb_black.Col[ 2 ], m_rgb_black.Col[ 1 ], m_rgb_black.Col[ 0 ] ) ); + else + nvgFillColor( vg, nvgRGB( m_rgb_white.Col[ 2 ], m_rgb_white.Col[ 1 ], m_rgb_white.Col[ 0 ] ) ); + } + + // draw key + nvgBeginPath(vg); + + for( i = 0; i < OctaveKeyDrawVects[ key ].nUsed; i++ ) + { + if( i == 0 ) + nvgMoveTo(vg, (float)OctaveKeyDrawVects[ key ].p[ i ].fx, (float)OctaveKeyDrawVects[ key ].p[ i ].fy ); + else + nvgLineTo(vg, (float)OctaveKeyDrawVects[ key ].p[ i ].fx, (float)OctaveKeyDrawVects[ key ].p[ i ].fy ); + } + + nvgClosePath(vg); + nvgFill(vg); + } + + //----------------------------------------------------- + // Procedure: draw + //----------------------------------------------------- + void draw( NVGcontext *vg ) override + { + int key; + + for( key = 0; key < nKEYS; key++ ) + drawkey( vg, key, false ); + + for( key = 0; key < m_MaxMultKeys; key++ ) + { + if( m_KeySave[ key ] != -1 ) + drawkey( vg, m_KeySave[ key ], true ); + } + } +}; + +//----------------------------------------------------- +// Procedure: MySquareButton +// +//----------------------------------------------------- +struct MySquareButton : SVGSwitch, MomentarySwitch +{ + MySquareButton() + { + addFrame(SVG::load(assetPlugin(plugin,"res/mschack_square_button.svg"))); + sw->wrap(); + box.size = sw->box.size; + } +}; + +//----------------------------------------------------- +// Procedure: MySquareButton2 +// +//----------------------------------------------------- +struct MySquareButton2 : SVGSwitch, MomentarySwitch +{ + MySquareButton2() + { + addFrame(SVG::load(assetPlugin(plugin,"res/mschack_Square_Button2.svg"))); + sw->wrap(); + box.size = sw->box.size; + } +}; + +//----------------------------------------------------- +// Procedure: PianoWhiteKey +// +//----------------------------------------------------- +struct PianoWhiteKey : SVGSwitch, ToggleSwitch +{ + PianoWhiteKey() + { + addFrame(SVG::load(assetPlugin(plugin,"res/mschack_WhiteKeyOff.svg"))); + addFrame(SVG::load(assetPlugin(plugin,"res/mschack_WhiteKeyOn.svg"))); + sw->wrap(); + box.size = sw->box.size; + } +}; + +//----------------------------------------------------- +// Procedure: PianoBlackKey +// +//----------------------------------------------------- +struct PianoBlackKey : SVGSwitch, ToggleSwitch +{ + PianoBlackKey() + { + addFrame(SVG::load(assetPlugin(plugin,"res/mschack_BlackKeyOff.svg"))); + addFrame(SVG::load(assetPlugin(plugin,"res/mschack_BlackKeyOn.svg"))); + sw->wrap(); + box.size = sw->box.size; + } +}; + +//----------------------------------------------------- +// Procedure: MyToggle1 +// +//----------------------------------------------------- +struct MyToggle1 : SVGSwitch, ToggleSwitch +{ + MyToggle1() + { + addFrame(SVG::load(assetPlugin(plugin,"res/mschack_3p_vert_simple_01.svg"))); + addFrame(SVG::load(assetPlugin(plugin,"res/mschack_3p_vert_simple_02.svg"))); + addFrame(SVG::load(assetPlugin(plugin,"res/mschack_3p_vert_simple_03.svg"))); + + sw->wrap(); + box.size = sw->box.size; + } +}; + +//----------------------------------------------------- +// Procedure: FilterSelectToggle +// +//----------------------------------------------------- +struct FilterSelectToggle : SVGSwitch, ToggleSwitch +{ + FilterSelectToggle() + { + addFrame(SVG::load(assetPlugin(plugin,"res/mschack_5p_filtersel_01.svg"))); + addFrame(SVG::load(assetPlugin(plugin,"res/mschack_5p_filtersel_02.svg"))); + addFrame(SVG::load(assetPlugin(plugin,"res/mschack_5p_filtersel_03.svg"))); + addFrame(SVG::load(assetPlugin(plugin,"res/mschack_5p_filtersel_04.svg"))); + addFrame(SVG::load(assetPlugin(plugin,"res/mschack_5p_filtersel_05.svg"))); + + sw->wrap(); + box.size = sw->box.size; + } +}; + +//----------------------------------------------------- +// Sliders +// +//----------------------------------------------------- +struct MySlider_01 : SVGFader +{ + MySlider_01() + { + + Vec margin = Vec(0, 0); + maxHandlePos = Vec(0, -4).plus(margin); + minHandlePos = Vec(0, 33).plus(margin); + + background->svg = SVG::load(assetPlugin(plugin,"res/mschack_sliderBG_01.svg")); + background->wrap(); + background->box.pos = margin; + box.size = background->box.size.plus(margin.mult(2)); + + handle->svg = SVG::load(assetPlugin(plugin,"res/mschack_sliderKNOB_01.svg")); + handle->wrap(); + } +}; + +struct Slider02_10x15 : SVGFader +{ + Slider02_10x15() + { + + Vec margin = Vec(4, 0); + maxHandlePos = Vec(-3, 0).plus(margin); + minHandlePos = Vec(-3, 60).plus(margin); + + background->svg = SVG::load(assetPlugin(plugin,"res/mschack_sliderBG_02.svg")); + background->wrap(); + background->box.pos = margin; + box.size = background->box.size.plus(margin.mult(2)); + + handle->svg = SVG::load(assetPlugin(plugin,"res/mschack_Slider02_10x15.svg")); + handle->wrap(); + } +}; + +//----------------------------------------------------- +// Procedure: MyPortInSmall +// +//----------------------------------------------------- +struct MyPortInSmall : SVGPort +{ + MyPortInSmall() + { + background->svg = SVG::load(assetPlugin(plugin, "res/mschack_PortIn_small.svg" ) ); + background->wrap(); + box.size = background->box.size; + } +}; + +//----------------------------------------------------- +// Procedure: MyPortOutSmall +// +//----------------------------------------------------- +struct MyPortOutSmall : SVGPort +{ + MyPortOutSmall() + { + background->svg = SVG::load(assetPlugin(plugin, "res/mschack_PortOut_small.svg" ) ); + background->wrap(); + box.size = background->box.size; + } +}; + +//----------------------------------------------------- +// Red1 +// +//----------------------------------------------------- +struct Knob_Red1_20 : RoundKnob +{ + Knob_Red1_20() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Red1_20.svg" ))); + } +}; + +struct Knob_Red1_15 : RoundKnob +{ + Knob_Red1_15() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Red1_15.svg" ))); + } +}; + +//----------------------------------------------------- +// Purp1 +// +//----------------------------------------------------- +struct Knob_Purp1_20 : RoundKnob +{ + Knob_Purp1_20() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Purp1_20.svg" ))); + } +}; + +struct Knob_Purp1_15 : RoundKnob +{ + Knob_Purp1_15() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Purp1_15.svg" ))); + } +}; + + +//----------------------------------------------------- +// Green1 +// +//----------------------------------------------------- +struct Knob_Green1_15 : RoundKnob +{ + Knob_Green1_15() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Green1_15.svg" ))); + } +}; + +struct Knob_Green1_40 : RoundKnob +{ + Knob_Green1_40() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Green1_40.svg" ))); + } +}; + +//----------------------------------------------------- +// Blue1 +// +//----------------------------------------------------- +struct Knob_Blue1_26 : RoundKnob +{ + Knob_Blue1_26() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Blue1_26.svg" ))); + } +}; + +//----------------------------------------------------- +// Blue2 +// +//----------------------------------------------------- +struct Knob_Blue2_26 : RoundKnob +{ + Knob_Blue2_26() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Blue2_26.svg" ))); + } +}; + +struct Knob_Blue2_26_Snap : RoundKnob +{ + Knob_Blue2_26_Snap() + { + snap = true; + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Blue2_26.svg" ))); + } +}; + +struct Knob_Blue2_15 : RoundKnob +{ + Knob_Blue2_15() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Blue2_15.svg" ))); + } +}; + +struct Knob_Blue2_40 : RoundKnob +{ + Knob_Blue2_40() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Blue2_40.svg" ))); + } +}; + +struct Knob_Blue2_56 : RoundKnob +{ + Knob_Blue2_56() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Blue2_56.svg" ))); + //box.size = Vec(56, 56); + } +}; + +//----------------------------------------------------- +// Blue3 +// +//----------------------------------------------------- +struct Knob_Blue3_20 : RoundKnob +{ + Knob_Blue3_20() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Blue3_20.svg" ))); + } +}; + +struct Knob_Blue3_15 : RoundKnob +{ + Knob_Blue3_15() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Blue3_15.svg" ))); + } +}; + +//----------------------------------------------------- +// Yellow1 +// +//----------------------------------------------------- +struct Knob_Yellow1_26 : RoundKnob +{ + Knob_Yellow1_26() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Yellow1_26.svg" ))); + } +}; + +struct Knob_Yellow1_15 : RoundKnob +{ + Knob_Yellow1_15() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Yellow1_15.svg" ))); + } +}; + +//----------------------------------------------------- +// Yellow2 +// +//----------------------------------------------------- +struct Knob_Yellow2_26 : RoundKnob +{ + Knob_Yellow2_26() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Yellow2_26.svg" ))); + } +}; + +struct Knob_Yellow2_26_Snap : RoundKnob +{ + Knob_Yellow2_26_Snap() + { + snap = true; + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Yellow2_26.svg" ))); + } +}; + +struct Knob_Yellow2_40 : RoundKnob +{ + Knob_Yellow2_40() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Yellow2_40.svg" ))); + } +}; + +struct Knob_Yellow2_56 : RoundKnob +{ + Knob_Yellow2_56() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Yellow2_56.svg" ))); + } +}; + +struct Knob_Yellow2_56_Snap : RoundKnob +{ + Knob_Yellow2_56_Snap() + { + snap = true; + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Yellow2_56.svg" ))); + } +}; +//----------------------------------------------------- +// Yellow3 +// +//----------------------------------------------------- +struct Knob_Yellow3_15 : RoundKnob +{ + Knob_Yellow3_15() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Yellow3_15.svg" ))); + } +}; + +struct Knob_Yellow3_20 : RoundKnob +{ + Knob_Yellow3_20() + { + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Yellow3_20.svg" ))); + } +}; + +struct Knob_Yellow3_20_Snap : RoundKnob +{ + Knob_Yellow3_20_Snap() + { + snap = true; + setSVG(SVG::load(assetPlugin(plugin, "res/mschack_Knob_Yellow3_20.svg" ))); + } +}; \ No newline at end of file diff --git a/plugins/makefile.msvc b/plugins/makefile.msvc index 88413277..03e01682 100644 --- a/plugins/makefile.msvc +++ b/plugins/makefile.msvc @@ -17,6 +17,7 @@ bin: $(call run_make,Bidoo,bin) $(call run_make,Bogaudio,bin) $(call run_make,cf,bin) + $(call run_make,DHE-Modules,bin) $(call run_make,ErraticInstruments,bin) $(call run_make,ESeries,bin) $(call run_make,FrozenWasteland,bin) @@ -28,6 +29,7 @@ bin: $(call run_make,LOGinstruments,bin) $(call run_make,ML_modules,bin) $(call run_make,modular80,bin) + $(call run_make,mscHack,bin) $(call run_make,mtsch-plugins,bin) $(call run_make,NauModular,bin) # $(call run_make,ParableInstruments,bin) @@ -51,6 +53,7 @@ clean: $(call run_make,Bidoo,clean) $(call run_make,Bogaudio,clean) $(call run_make,cf,clean) + $(call run_make,DHE-Modules,clean) $(call run_make,ErraticInstruments,clean) $(call run_make,ESeries,clean) $(call run_make,FrozenWasteland,clean) @@ -62,6 +65,7 @@ clean: $(call run_make,LOGinstruments,clean) $(call run_make,ML_modules,clean) $(call run_make,modular80,clean) + $(call run_make,mscHack,clean) $(call run_make,mtsch-plugins,clean) $(call run_make,NauModular,clean) # $(call run_make,ParableInstruments,clean) diff --git a/src/main.cpp b/src/main.cpp index b8995244..7ec4b116 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -110,7 +110,7 @@ int vst2_init(int argc, char* argv[]) { void vst2_editor_create(void) { windowInit(); - // settingsLoad(assetLocal("settings.json")); + settingsLoad(assetLocal("settings.json")); glfwHideWindow(rack::global_ui->window.gWindow); } diff --git a/src/plugin.cpp b/src/plugin.cpp index b555dd9e..7946d62f 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -574,6 +574,7 @@ extern void init_plugin_Befaco (rack::Plugin *p); extern void init_plugin_Bidoo (rack::Plugin *p); extern void init_plugin_Bogaudio (rack::Plugin *p); extern void init_plugin_cf (rack::Plugin *p); +extern void init_plugin_DHE_Modules (rack::Plugin *p); extern void init_plugin_ErraticInstruments (rack::Plugin *p); extern void init_plugin_ESeries (rack::Plugin *p); extern void init_plugin_FrozenWasteland (rack::Plugin *p); @@ -585,6 +586,7 @@ extern void init_plugin_LindenbergResearch (rack::Plugin *p); extern void init_plugin_LOGinstruments (rack::Plugin *p); extern void init_plugin_ML_modules (rack::Plugin *p); extern void init_plugin_modular80 (rack::Plugin *p); +extern void init_plugin_mscHack (rack::Plugin *p); extern void init_plugin_mtsch_plugins (rack::Plugin *p); extern void init_plugin_NauModular (rack::Plugin *p); // extern void init_plugin_ParableInstruments (rack::Plugin *p); // alternative "Clouds" module (crashes) @@ -632,6 +634,7 @@ void vst2_load_static_rack_plugins(void) { vst2_load_static_rack_plugin("Bidoo", &init_plugin_Bidoo); vst2_load_static_rack_plugin("Bogaudio", &init_plugin_Bogaudio); vst2_load_static_rack_plugin("cf", &init_plugin_cf); + vst2_load_static_rack_plugin("DHE-Modules", &init_plugin_DHE_Modules); vst2_load_static_rack_plugin("ErraticInstruments", &init_plugin_ErraticInstruments); vst2_load_static_rack_plugin("ESeries", &init_plugin_ESeries); vst2_load_static_rack_plugin("FrozenWasteland", &init_plugin_FrozenWasteland); @@ -643,6 +646,7 @@ void vst2_load_static_rack_plugins(void) { vst2_load_static_rack_plugin("LOGinstruments", &init_plugin_LOGinstruments); vst2_load_static_rack_plugin("ML_modules", &init_plugin_ML_modules); vst2_load_static_rack_plugin("modular80", &init_plugin_modular80); + vst2_load_static_rack_plugin("mscHack", &init_plugin_mscHack); vst2_load_static_rack_plugin("mtsch_plugins", &init_plugin_mtsch_plugins); vst2_load_static_rack_plugin("NauModular", &init_plugin_NauModular); // vst2_load_static_rack_plugin("ParableInstruments", &init_plugin_ParableInstruments); diff --git a/src/settings.cpp b/src/settings.cpp index 6d9fcbce..d6251607 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -87,7 +87,11 @@ static void settingsFromJson(json_t *rootJ) { if (windowSizeJ) { double width, height; json_unpack(windowSizeJ, "[F, F]", &width, &height); +#ifdef USE_VST2 + // (note) calling windowSetWindowSize() causes the window to be not resizable initially, and when it is moved, it reverts to a default size (TBI) +#else windowSetWindowSize(Vec(width, height)); +#endif // USE_VST2 } // windowPos @@ -95,7 +99,9 @@ static void settingsFromJson(json_t *rootJ) { if (windowPosJ) { double x, y; json_unpack(windowPosJ, "[F, F]", &x, &y); +#ifndef USE_VST2 windowSetWindowPos(Vec(x, y)); +#endif // USE_VST2 } // opacity @@ -120,17 +126,19 @@ static void settingsFromJson(json_t *rootJ) { if (allowCursorLockJ) { global_ui->window.gAllowCursorLock = json_is_true(allowCursorLockJ); -#ifdef USE_VST2 - global_ui->window.gAllowCursorLock = 0; -#endif // USE_VST2 +// #ifdef USE_VST2 +// global_ui->window.gAllowCursorLock = 0; +// #endif // USE_VST2 } +#ifndef USE_VST2 // sampleRate json_t *sampleRateJ = json_object_get(rootJ, "sampleRate"); if (sampleRateJ) { float sampleRate = json_number_value(sampleRateJ); engineSetSampleRate(sampleRate); } +#endif // USE_VST2 // lastPath json_t *lastPathJ = json_object_get(rootJ, "lastPath"); diff --git a/src/window.cpp b/src/window.cpp index 625d38c7..25520ae6 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -618,7 +618,7 @@ Vec windowGetWindowPos() { void windowSetWindowPos(Vec pos) { int x = pos.x; int y = pos.y; - glfwSetWindowPos(global_ui->window.gWindow, x, y); + glfwSetWindowPos(global_ui->window.gWindow, x, y); } bool windowIsMaximized() { diff --git a/vst2_bin/CHANGELOG_VST.txt b/vst2_bin/CHANGELOG_VST.txt index fdd6f955..dbfcbf9a 100644 --- a/vst2_bin/CHANGELOG_VST.txt +++ b/vst2_bin/CHANGELOG_VST.txt @@ -1,3 +1,33 @@ +** July 8th, 2018 +- add module DHE-Modules.BoosterStage +- add module DHE-Modules.Cubic +- add module DHE-Modules.Hostage +- add module DHE-Modules.Stage +- add module DHE-Modules.Swave +- add module DHE-Modules.Upstage +- add module mscHack.MasterClockx4 +- add module mscHack.Seq_3x16x16 +- add module mscHack.SEQ_6x32x16 +- add module mscHack.Seq_Triad2 +- add module mscHack.SEQ_Envelope_8 +- add module mscHack.Maude_221 +- add module mscHack.ARP700 +- add module mscHack.SynthDrums +- add module mscHack.XFade +- add module mscHack.Mix_1x4_Stereo +- add module mscHack.Mix_2x4_Stereo +- add module mscHack.Mix_4x4_Stereo +- add module mscHack.Mix_24_4_4 +- add module mscHack.StepDelay +- add module mscHack.PingPong +- add module mscHack.Osc_3Ch +- add module mscHack.Compressor +- add x86/32bit build (you are completely on your own this this -- please upgrade to x64!) +- fix: load "settings.json" when plugin is initialized + (note: the windowSize/windowPos and sampleRate are ignored) +- change: "allowCursorLock" is now enabled by default + + ** July 7th, 2018 - add module Bidoo.DTROY - add module Bidoo.BORDL diff --git a/vst2_bin/README_vst2.txt b/vst2_bin/README_vst2.txt index 9a51af94..429312cf 100644 --- a/vst2_bin/README_vst2.txt +++ b/vst2_bin/README_vst2.txt @@ -171,6 +171,12 @@ The VST2 plugin includes the following add-on modules: - cf.PATCH - cf.LEDS - cf.DAVE + - DHE-Modules.BoosterStage + - DHE-Modules.Cubic + - DHE-Modules.Hostage + - DHE-Modules.Stage + - DHE-Modules.Swave + - DHE-Modules.Upstage - ESeries.E340 - ErraticInstruments.MPEToCV - ErraticInstruments.QuadMPEToCV @@ -252,6 +258,23 @@ The VST2 plugin includes the following add-on modules: - LOGinstruments.Velvet - LOGinstruments.Crystal - modular80.Logistiker + - mscHack.MasterClockx4 + - mscHack.Seq_3x16x16 + - mscHack.SEQ_6x32x16 + - mscHack.Seq_Triad2 + - mscHack.SEQ_Envelope_8 + - mscHack.Maude_221 + - mscHack.ARP700 + - mscHack.SynthDrums + - mscHack.XFade + - mscHack.Mix_1x4_Stereo + - mscHack.Mix_2x4_Stereo + - mscHack.Mix_4x4_Stereo + - mscHack.Mix_24_4_4 + - mscHack.StepDelay + - mscHack.PingPong + - mscHack.Osc_3Ch + - mscHack.Compressor - mtsch_plugins.Sum - mtsch_plugins.Rationals - mtsch_plugins.TriggerPanic diff --git a/vst2_bin/log.txt b/vst2_bin/log.txt index 4d4255b6..26b0a9fd 100644 --- a/vst2_bin/log.txt +++ b/vst2_bin/log.txt @@ -1,103 +1,72 @@ [0.000 info src/main.cpp:63] VeeSeeVST Rack 0.6.1 [0.000 info src/main.cpp:66] Global directory: f:\git\VeeSeeVSTRack\vst2_bin\/ [0.000 info src/main.cpp:67] Local directory: f:\git\VeeSeeVSTRack\vst2_bin\/ -[0.000 info src/plugin.cpp:625] vcvrack: Loaded static plugin AS 0.6.1 -[0.000 info src/plugin.cpp:625] vcvrack: Loaded static plugin AudibleInstruments 0.6.1 -[0.001 info src/plugin.cpp:625] vcvrack: Loaded static plugin Befaco 0.6.1 -[0.002 info src/plugin.cpp:625] vcvrack: Loaded static plugin Bidoo 0.6.1 -[0.002 info src/plugin.cpp:625] vcvrack: Loaded static plugin Bogaudio 0.6.1 -[0.002 info src/plugin.cpp:625] vcvrack: Loaded static plugin cf 0.6.1 -[0.002 info src/plugin.cpp:625] vcvrack: Loaded static plugin ErraticInstruments 0.6.1 -[0.002 info src/plugin.cpp:625] vcvrack: Loaded static plugin ESeries 0.6.1 -[0.003 info src/plugin.cpp:625] vcvrack: Loaded static plugin FrozenWasteland 0.6.1 -[0.003 info src/plugin.cpp:625] vcvrack: Loaded static plugin Fundamental 0.6.1 -[0.003 info src/plugin.cpp:625] vcvrack: Loaded static plugin HetrickCV 0.6.1 -[0.003 info src/plugin.cpp:625] vcvrack: Loaded static plugin huaba 0.6.1 -[0.003 info src/plugin.cpp:625] vcvrack: Loaded static plugin Koralfx-Modules 0.6.1 -[0.004 info src/plugin.cpp:625] vcvrack: Loaded static plugin LindenbergResearch 0.6.1 -[0.004 info src/plugin.cpp:625] vcvrack: Loaded static plugin LOGinstruments 0.6.1 -[0.004 info src/plugin.cpp:625] vcvrack: Loaded static plugin ML_modules 0.6.1 -[0.004 info src/plugin.cpp:625] vcvrack: Loaded static plugin modular80 0.6.1 -[0.004 info src/plugin.cpp:625] vcvrack: Loaded static plugin mtsch-plugins 0.6.1 -[0.004 info src/plugin.cpp:625] vcvrack: Loaded static plugin NauModular 0.6.1 -[0.004 info src/plugin.cpp:625] vcvrack: Loaded static plugin Qwelk 0.6.1 -[0.005 info src/plugin.cpp:625] vcvrack: Loaded static plugin SonusModular 0.6.1 -[0.005 info src/plugin.cpp:625] vcvrack: Loaded static plugin Southpole-parasites 0.6.1 -[0.006 info src/plugin.cpp:625] vcvrack: Loaded static plugin squinkylabs-plug1 0.6.1 -[0.006 info src/plugin.cpp:625] vcvrack: Loaded static plugin SubmarineFree 0.6.1 -[0.006 info src/plugin.cpp:625] vcvrack: Loaded static plugin Template 0.6.1 -[0.006 info src/plugin.cpp:625] vcvrack: Loaded static plugin trowaSoft 0.6.1 -[0.006 info src/plugin.cpp:625] vcvrack: Loaded static plugin Valley 0.6.1 -[0.006 info src/plugin.cpp:625] vcvrack: Loaded static plugin VultModules 0.6.1 -[0.007 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_146097_cc.svg -[0.007 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_31859_cc.svg -[0.007 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_1343816_cc.svg -[0.008 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_1343811_cc.svg -[0.008 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_1084369_cc.svg -[0.008 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_1745061_cc.svg -[0.008 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_1240789_cc.svg -[0.008 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_305536_cc.svg -[0.008 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_468341_cc.svg -[0.202 info src/window.cpp:703] Loaded font f:\git\VeeSeeVSTRack\vst2_bin\/res/fonts/DejaVuSans.ttf -[0.305 info src/app/RackWidget.cpp:192] Loading patch from string -[0.307 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/Core/AudioInterface.svg -[0.307 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/ScrewSilver.svg -[0.307 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/PJ301M.svg -[0.307 info src/window.cpp:703] Loaded font f:\git\VeeSeeVSTRack\vst2_bin\/res/fonts/ShareTechMono-Regular.ttf -[0.308 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/Core/MIDIToCVInterface.svg -[0.309 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Fundamental/res/VCA.svg -[0.309 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/RoundLargeBlackKnob.svg +[0.000 info src/plugin.cpp:627] vcvrack: Loaded static plugin AS 0.6.1 +[0.000 info src/plugin.cpp:627] vcvrack: Loaded static plugin AudibleInstruments 0.6.1 +[0.002 info src/plugin.cpp:627] vcvrack: Loaded static plugin Befaco 0.6.1 +[0.002 info src/plugin.cpp:627] vcvrack: Loaded static plugin Bidoo 0.6.1 +[0.003 info src/plugin.cpp:627] vcvrack: Loaded static plugin Bogaudio 0.6.1 +[0.003 info src/plugin.cpp:627] vcvrack: Loaded static plugin cf 0.6.1 +[0.003 info src/plugin.cpp:627] vcvrack: Loaded static plugin DHE-Modules 0.6.1 +[0.003 info src/plugin.cpp:627] vcvrack: Loaded static plugin ErraticInstruments 0.6.1 +[0.003 info src/plugin.cpp:627] vcvrack: Loaded static plugin ESeries 0.6.1 +[0.004 info src/plugin.cpp:627] vcvrack: Loaded static plugin FrozenWasteland 0.6.1 +[0.004 info src/plugin.cpp:627] vcvrack: Loaded static plugin Fundamental 0.6.1 +[0.004 info src/plugin.cpp:627] vcvrack: Loaded static plugin HetrickCV 0.6.1 +[0.004 info src/plugin.cpp:627] vcvrack: Loaded static plugin huaba 0.6.1 +[0.004 info src/plugin.cpp:627] vcvrack: Loaded static plugin Koralfx-Modules 0.6.1 +[0.004 info src/plugin.cpp:627] vcvrack: Loaded static plugin LindenbergResearch 0.6.1 +[0.005 info src/plugin.cpp:627] vcvrack: Loaded static plugin LOGinstruments 0.6.1 +[0.005 info src/plugin.cpp:627] vcvrack: Loaded static plugin ML_modules 0.6.1 +[0.005 info src/plugin.cpp:627] vcvrack: Loaded static plugin modular80 0.6.1 +[0.005 info src/plugin.cpp:627] vcvrack: Loaded static plugin mscHack 0.6.1 +[0.005 info src/plugin.cpp:627] vcvrack: Loaded static plugin mtsch-plugins 0.6.1 +[0.005 info src/plugin.cpp:627] vcvrack: Loaded static plugin NauModular 0.6.1 +[0.006 info src/plugin.cpp:627] vcvrack: Loaded static plugin Qwelk 0.6.1 +[0.007 info src/plugin.cpp:627] vcvrack: Loaded static plugin SonusModular 0.6.1 +[0.007 info src/plugin.cpp:627] vcvrack: Loaded static plugin Southpole-parasites 0.6.1 +[0.007 info src/plugin.cpp:627] vcvrack: Loaded static plugin squinkylabs-plug1 0.6.1 +[0.007 info src/plugin.cpp:627] vcvrack: Loaded static plugin SubmarineFree 0.6.1 +[0.007 info src/plugin.cpp:627] vcvrack: Loaded static plugin Template 0.6.1 +[0.007 info src/plugin.cpp:627] vcvrack: Loaded static plugin trowaSoft 0.6.1 +[0.008 info src/plugin.cpp:627] vcvrack: Loaded static plugin Valley 0.6.1 +[0.008 info src/plugin.cpp:627] vcvrack: Loaded static plugin VultModules 0.6.1 +[0.008 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_146097_cc.svg +[0.008 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_31859_cc.svg +[0.008 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_1343816_cc.svg +[0.009 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_1343811_cc.svg +[0.010 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_1084369_cc.svg +[0.010 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_1745061_cc.svg +[0.010 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_1240789_cc.svg +[0.010 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_305536_cc.svg +[0.010 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/icons/noun_468341_cc.svg +[0.196 info src/window.cpp:703] Loaded font f:\git\VeeSeeVSTRack\vst2_bin\/res/fonts/DejaVuSans.ttf +[0.198 info src/settings.cpp:185] Loading settings f:\git\VeeSeeVSTRack\vst2_bin\/settings.json +[0.299 info src/app/RackWidget.cpp:192] Loading patch from string +[0.300 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/Core/AudioInterface.svg +[0.301 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/ScrewSilver.svg +[0.301 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/PJ301M.svg +[0.301 info src/window.cpp:703] Loaded font f:\git\VeeSeeVSTRack\vst2_bin\/res/fonts/ShareTechMono-Regular.ttf +[0.302 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/Core/MIDIToCVInterface.svg +[0.305 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/XCO.svg +[0.305 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/knob_68px.svg +[0.305 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/knob_16px.svg +[0.306 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/button_9px_0.svg +[0.306 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/button_9px_1.svg +[0.306 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/knob_38px.svg +[0.306 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/slider_switch_2_14px_0.svg +[0.306 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/slider_switch_2_14px_1.svg +[0.307 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/port.svg +[0.307 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Fundamental/res/VCA.svg +[0.308 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/RoundLargeBlackKnob.svg +[0.308 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Fundamental/res/VCF.svg +[0.309 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/RoundHugeBlackKnob.svg [0.310 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/AS/res/ADSR.svg -[0.311 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/AS/res/as-hexscrew.svg -[0.311 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/AS/res/as-SlidePot.svg +[0.310 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/AS/res/as-hexscrew.svg +[0.310 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/AS/res/as-SlidePot.svg [0.311 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/AS/res/as-SlidePotHandle.svg -[0.312 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/AS/res/as-PJ301M.svg -[0.313 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Fundamental/res/VCMixer.svg +[0.311 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/AS/res/as-PJ301M.svg +[0.312 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Fundamental/res/VCMixer.svg [0.313 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/LEDSlider.svg [0.313 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/LEDSliderGreenHandle.svg -[0.314 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Fundamental/res/VCF.svg -[0.314 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/RoundHugeBlackKnob.svg -[0.316 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bidoo/res/CLACOS.svg -[0.316 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/Trimpot.svg -[0.317 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bidoo/res/ComponentLibrary/BlueTrimpotBidoo.svg -[0.317 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bidoo/res/ComponentLibrary/TinyPJ301M.svg -[0.317 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/Trimpot.svg -[0.317 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/Trimpot.svg -[0.317 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/Trimpot.svg -[0.318 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/CKSS_0.svg -[0.318 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/CKSS_1.svg -[0.318 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bidoo/res/ComponentLibrary/LargeBlueKnobBidoo.svg -[0.318 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/Trimpot.svg -[0.318 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/Trimpot.svg -[0.320 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/LFO.svg -[0.320 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/knob_68px.svg -[0.321 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/button_9px_0.svg -[0.321 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/button_9px_1.svg -[0.321 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/knob_26px.svg -[0.321 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/knob_16px.svg -[0.321 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/Bogaudio/res/port.svg -[0.322 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/SonusModular/res/twoff.svg -[0.322 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/SonusModular/res/screw.svg -[0.323 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/SonusModular/res/knob.svg -[0.348 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/AudibleInstruments/res/Clouds.svg -[0.348 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/Rogan3PSRed.svg -[0.348 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/Rogan3PSGreen.svg -[0.349 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/Rogan3PSWhite.svg -[0.349 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/Rogan1PSRed.svg -[0.349 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/Rogan1PSGreen.svg -[0.349 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/Rogan1PSWhite.svg -[0.350 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/Rogan1PSBlue.svg -[0.350 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/CKD6_0.svg -[0.350 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/CKD6_1.svg -[0.350 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/TL1105_0.svg -[0.350 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\/res/ComponentLibrary/TL1105_1.svg -[0.351 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/AS/res/SawOSC.svg -[0.352 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/AS/res/as-knobBlack.svg -[0.353 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/LindenbergResearch/res/SimpleFilter.svg -[0.353 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/LindenbergResearch/res/ScrewDark.svg -[0.354 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/LindenbergResearch/res/BigKnob.svg -[0.354 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/LindenbergResearch/res/MiddleKnob.svg -[0.354 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/LindenbergResearch/res/SmallKnob.svg -[0.354 info src/window.cpp:754] Loaded SVG f:\git\VeeSeeVSTRack\vst2_bin\plugins/LindenbergResearch/res/IOPortB.svg -[28.751 info src/app/RackWidget.cpp:154] Saving patch to string -[30.201 info src/app/RackWidget.cpp:154] Saving patch to string +[16.370 info src/app/RackWidget.cpp:154] Saving patch to string diff --git a/vst2_bin/plugins/DHE-Modules/DHE-Modules.json b/vst2_bin/plugins/DHE-Modules/DHE-Modules.json new file mode 100644 index 00000000..f951a11a --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/DHE-Modules.json @@ -0,0 +1,10 @@ +{ + "name": "DHE Modules", + "author": "Dale Emery", + "license": "MIT", + "contactEmail": "dale@dhemery.com", + "manualUrl": "https://dhemery.github.io/DHE-Modules/", + "sourceUrl": "https://github.com/dhemery/DHE-Modules/", + "donateUrl": "https://paypal.me/DaleHEmery/", + "latestVersion": "0.6.0" +} diff --git a/vst2_bin/plugins/DHE-Modules/LICENSE.txt b/vst2_bin/plugins/DHE-Modules/LICENSE.txt new file mode 100644 index 00000000..610c6f99 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/LICENSE.txt @@ -0,0 +1,7 @@ +Copyright 2018 Dale H. Emery + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vst2_bin/plugins/DHE-Modules/README.md b/vst2_bin/plugins/DHE-Modules/README.md new file mode 100644 index 00000000..11aa34d3 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/README.md @@ -0,0 +1,5 @@ +# DHE Modules + +VCV Rack modules from Dale Emery. + +See the [DHE Modules Site](https://dhemery.github.io/DHE-Modules/) for details. diff --git a/vst2_bin/plugins/DHE-Modules/res/booster-stage/button-dark-off.svg b/vst2_bin/plugins/DHE-Modules/res/booster-stage/button-dark-off.svg new file mode 100644 index 00000000..f086436e --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/booster-stage/button-dark-off.svg @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/booster-stage/button-dark-on.svg b/vst2_bin/plugins/DHE-Modules/res/booster-stage/button-dark-on.svg new file mode 100644 index 00000000..60f3959f --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/booster-stage/button-dark-on.svg @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/booster-stage/button-light-off.svg b/vst2_bin/plugins/DHE-Modules/res/booster-stage/button-light-off.svg new file mode 100644 index 00000000..28b37c35 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/booster-stage/button-light-off.svg @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/booster-stage/button-light-on.svg b/vst2_bin/plugins/DHE-Modules/res/booster-stage/button-light-on.svg new file mode 100644 index 00000000..409d4766 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/booster-stage/button-light-on.svg @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/booster-stage/knob-large.svg b/vst2_bin/plugins/DHE-Modules/res/booster-stage/knob-large.svg new file mode 100644 index 00000000..9f4a531b --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/booster-stage/knob-large.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/booster-stage/panel.svg b/vst2_bin/plugins/DHE-Modules/res/booster-stage/panel.svg new file mode 100644 index 00000000..03f14134 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/booster-stage/panel.svg @@ -0,0 +1,474 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/booster-stage/port.svg b/vst2_bin/plugins/DHE-Modules/res/booster-stage/port.svg new file mode 100644 index 00000000..d567be85 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/booster-stage/port.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/booster-stage/switch-2-high.svg b/vst2_bin/plugins/DHE-Modules/res/booster-stage/switch-2-high.svg new file mode 100644 index 00000000..3312b0a7 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/booster-stage/switch-2-high.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/booster-stage/switch-2-low.svg b/vst2_bin/plugins/DHE-Modules/res/booster-stage/switch-2-low.svg new file mode 100644 index 00000000..45b91740 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/booster-stage/switch-2-low.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/booster-stage/switch-3-high.svg b/vst2_bin/plugins/DHE-Modules/res/booster-stage/switch-3-high.svg new file mode 100644 index 00000000..29c84e6e --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/booster-stage/switch-3-high.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/booster-stage/switch-3-low.svg b/vst2_bin/plugins/DHE-Modules/res/booster-stage/switch-3-low.svg new file mode 100644 index 00000000..61597de8 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/booster-stage/switch-3-low.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/booster-stage/switch-3-mid.svg b/vst2_bin/plugins/DHE-Modules/res/booster-stage/switch-3-mid.svg new file mode 100644 index 00000000..15a84259 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/booster-stage/switch-3-mid.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/cubic/knob-small.svg b/vst2_bin/plugins/DHE-Modules/res/cubic/knob-small.svg new file mode 100644 index 00000000..24b4026a --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/cubic/knob-small.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/cubic/panel.svg b/vst2_bin/plugins/DHE-Modules/res/cubic/panel.svg new file mode 100644 index 00000000..01f2dbb4 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/cubic/panel.svg @@ -0,0 +1,273 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/cubic/port.svg b/vst2_bin/plugins/DHE-Modules/res/cubic/port.svg new file mode 100644 index 00000000..71848d41 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/cubic/port.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/hostage/knob-large.svg b/vst2_bin/plugins/DHE-Modules/res/hostage/knob-large.svg new file mode 100644 index 00000000..92c1ec49 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/hostage/knob-large.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/hostage/panel.svg b/vst2_bin/plugins/DHE-Modules/res/hostage/panel.svg new file mode 100644 index 00000000..93d0bd21 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/hostage/panel.svg @@ -0,0 +1,372 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/hostage/port.svg b/vst2_bin/plugins/DHE-Modules/res/hostage/port.svg new file mode 100644 index 00000000..cb75a644 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/hostage/port.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/hostage/switch-2-high.svg b/vst2_bin/plugins/DHE-Modules/res/hostage/switch-2-high.svg new file mode 100644 index 00000000..94c9b358 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/hostage/switch-2-high.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/hostage/switch-2-low.svg b/vst2_bin/plugins/DHE-Modules/res/hostage/switch-2-low.svg new file mode 100644 index 00000000..9b7aef6f --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/hostage/switch-2-low.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/hostage/switch-3-high.svg b/vst2_bin/plugins/DHE-Modules/res/hostage/switch-3-high.svg new file mode 100644 index 00000000..398c317d --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/hostage/switch-3-high.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/hostage/switch-3-low.svg b/vst2_bin/plugins/DHE-Modules/res/hostage/switch-3-low.svg new file mode 100644 index 00000000..8ff9662c --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/hostage/switch-3-low.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/hostage/switch-3-mid.svg b/vst2_bin/plugins/DHE-Modules/res/hostage/switch-3-mid.svg new file mode 100644 index 00000000..e0a31c00 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/hostage/switch-3-mid.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/stage/knob-large.svg b/vst2_bin/plugins/DHE-Modules/res/stage/knob-large.svg new file mode 100644 index 00000000..e9179b5b --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/stage/knob-large.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/stage/panel.svg b/vst2_bin/plugins/DHE-Modules/res/stage/panel.svg new file mode 100644 index 00000000..926079fd --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/stage/panel.svg @@ -0,0 +1,308 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/stage/port.svg b/vst2_bin/plugins/DHE-Modules/res/stage/port.svg new file mode 100644 index 00000000..432350ea --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/stage/port.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/swave/knob-large.svg b/vst2_bin/plugins/DHE-Modules/res/swave/knob-large.svg new file mode 100644 index 00000000..9ef48fb9 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/swave/knob-large.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/swave/panel.svg b/vst2_bin/plugins/DHE-Modules/res/swave/panel.svg new file mode 100644 index 00000000..20763d75 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/swave/panel.svg @@ -0,0 +1,169 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/swave/port.svg b/vst2_bin/plugins/DHE-Modules/res/swave/port.svg new file mode 100644 index 00000000..3f9e71ae --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/swave/port.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/swave/switch-2-high.svg b/vst2_bin/plugins/DHE-Modules/res/swave/switch-2-high.svg new file mode 100644 index 00000000..eceab81d --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/swave/switch-2-high.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/swave/switch-2-low.svg b/vst2_bin/plugins/DHE-Modules/res/swave/switch-2-low.svg new file mode 100644 index 00000000..df41e090 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/swave/switch-2-low.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/upstage/button-dark-off.svg b/vst2_bin/plugins/DHE-Modules/res/upstage/button-dark-off.svg new file mode 100644 index 00000000..94efcaaa --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/upstage/button-dark-off.svg @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/upstage/button-dark-on.svg b/vst2_bin/plugins/DHE-Modules/res/upstage/button-dark-on.svg new file mode 100644 index 00000000..33868c5c --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/upstage/button-dark-on.svg @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/upstage/knob-large.svg b/vst2_bin/plugins/DHE-Modules/res/upstage/knob-large.svg new file mode 100644 index 00000000..8d98db91 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/upstage/knob-large.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/upstage/panel.svg b/vst2_bin/plugins/DHE-Modules/res/upstage/panel.svg new file mode 100644 index 00000000..473cda46 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/upstage/panel.svg @@ -0,0 +1,289 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/upstage/port.svg b/vst2_bin/plugins/DHE-Modules/res/upstage/port.svg new file mode 100644 index 00000000..10208f2b --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/upstage/port.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/upstage/switch-2-high.svg b/vst2_bin/plugins/DHE-Modules/res/upstage/switch-2-high.svg new file mode 100644 index 00000000..2e1a54f0 --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/upstage/switch-2-high.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/DHE-Modules/res/upstage/switch-2-low.svg b/vst2_bin/plugins/DHE-Modules/res/upstage/switch-2-low.svg new file mode 100644 index 00000000..6ba49e0d --- /dev/null +++ b/vst2_bin/plugins/DHE-Modules/res/upstage/switch-2-low.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/LICENSE.txt b/vst2_bin/plugins/mscHack/LICENSE.txt new file mode 100644 index 00000000..f901edc3 --- /dev/null +++ b/vst2_bin/plugins/mscHack/LICENSE.txt @@ -0,0 +1,7 @@ +Copyright (c) 2017 Mark Schack + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/vst2_bin/plugins/mscHack/README.md b/vst2_bin/plugins/mscHack/README.md new file mode 100644 index 00000000..528af0cf --- /dev/null +++ b/vst2_bin/plugins/mscHack/README.md @@ -0,0 +1,56 @@ +# mscHack Plugins for VCV Rack 0.6.0 + +![screenshot](modules.PNG) + +# Updates +- 14 May 18 [v0.6.2] + - [NEW] "ENVY 9", a 9 channel envelope editor/generator + - All channels synced to an input beat + - 5 speed multipliers + - loop, reverse, ping pong, one shot and two shot modes + - each channel externally triggerable + - each channel external gated hold + - hand drawable patterns + - 24 Channel mixer + - Added pre-fader option for AUXs + - Menu option for Group out pre-mute, and 1.5x mixer gain + - Added pre EQ makeup gain, input signal was being attenuated + - ARP700 + -Added pattern copy; (while paused) Select pattern to copy, press copy button, press pattern to copy to + - SEQ 6x32 + -Copy now like Triad and Arp. Now you can copy patterns between channels + -Added two more output level knobs + -Added a pattern clear button + -improved random pattern generation + - Triad2 + -Now you can copy patterns between channels + +# Includes +- "ENVY 9", a 9 channel envelope editor/generator +- 4 Channel Master Clock +- 3 Channel 16 Step Programmable Sequencer. +- 6 Channel 32 Step Sequencer +- Mixer 1x4, 2x4 and 4x4 (with EQ, 4xAUX buses, and 2 x amplification ) +- Triad Sequencer (Type 2), with Independantly clocked channels +- Synth Drums +- 3 Channel Oscillator with Filter and Amp Envelope (latest has multi oscillator capability) +- Ping Pong Delay +- Compressor (a work in progress...) +- X Fade, 3 stereo channel cross fader +- ARP 700, 7 note arpeggiator. +- Maude 221 wave combiner +- Step Delay + +# Demo Vids +- 4 Channel Master Clock https://www.youtube.com/watch?v=hiQciS8ch5U +- Sequencer: https://www.youtube.com/watch?v=2PN0-UZhocA +- Mixer: https://www.youtube.com/watch?v=QOjSEM3mPqs +- Triad Sequencer https://www.youtube.com/watch?v=InOgQA91cs8 +- Triad Sequencer (Type 2) https://www.youtube.com/watch?v=NAza3lUqkkQ +- Synth Drums https://www.youtube.com/watch?v=zYrtJ2XsbTw +- Pong https://www.youtube.com/watch?v=hTsco8omRT0 +- 3 Channel OSC https://www.youtube.com/watch?v=BV9nWX9Izq0 +- Compressor https://www.youtube.com/watch?v=0F9KCk0IgFU +- X Fade https://www.youtube.com/watch?v=1NN4ly77nXo +- 6 x 32 trigger sequencer https://www.youtube.com/watch?v=S1PB-WaqXt4 +- ARP 700 quicky demo https://www.youtube.com/watch?v=ht9EwXmkDJI diff --git a/vst2_bin/plugins/mscHack/modules.PNG b/vst2_bin/plugins/mscHack/modules.PNG new file mode 100644 index 00000000..63b92e23 Binary files /dev/null and b/vst2_bin/plugins/mscHack/modules.PNG differ diff --git a/vst2_bin/plugins/mscHack/res/ARP700.svg b/vst2_bin/plugins/mscHack/res/ARP700.svg new file mode 100644 index 00000000..9b707087 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/ARP700.svg @@ -0,0 +1,1053 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/Compressor.svg b/vst2_bin/plugins/mscHack/res/Compressor.svg new file mode 100644 index 00000000..5517407b --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/Compressor.svg @@ -0,0 +1,611 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/MasterClockx4.svg b/vst2_bin/plugins/mscHack/res/MasterClockx4.svg new file mode 100644 index 00000000..5e6a395b --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/MasterClockx4.svg @@ -0,0 +1,776 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/Maude221.svg b/vst2_bin/plugins/mscHack/res/Maude221.svg new file mode 100644 index 00000000..337ef994 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/Maude221.svg @@ -0,0 +1,1585 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/Mix_1x4_Stereo.svg b/vst2_bin/plugins/mscHack/res/Mix_1x4_Stereo.svg new file mode 100644 index 00000000..09619d6b --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/Mix_1x4_Stereo.svg @@ -0,0 +1,947 @@ + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/Mix_2x4_Stereo.svg b/vst2_bin/plugins/mscHack/res/Mix_2x4_Stereo.svg new file mode 100644 index 00000000..596f7744 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/Mix_2x4_Stereo.svg @@ -0,0 +1,1645 @@ + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/Mix_4x4_Stereo.svg b/vst2_bin/plugins/mscHack/res/Mix_4x4_Stereo.svg new file mode 100644 index 00000000..37b9bd59 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/Mix_4x4_Stereo.svg @@ -0,0 +1,2356 @@ + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/Mixer_24_4_4.svg b/vst2_bin/plugins/mscHack/res/Mixer_24_4_4.svg new file mode 100644 index 00000000..98b3e504 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/Mixer_24_4_4.svg @@ -0,0 +1,2204 @@ + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/OSC3Channel.svg b/vst2_bin/plugins/mscHack/res/OSC3Channel.svg new file mode 100644 index 00000000..7e26d9dc --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/OSC3Channel.svg @@ -0,0 +1,1434 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/PingPong.svg b/vst2_bin/plugins/mscHack/res/PingPong.svg new file mode 100644 index 00000000..62950fb9 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/PingPong.svg @@ -0,0 +1,629 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/SEQ_6x32x16.svg b/vst2_bin/plugins/mscHack/res/SEQ_6x32x16.svg new file mode 100644 index 00000000..07e6dbbb --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/SEQ_6x32x16.svg @@ -0,0 +1,3997 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/SEQ_Envelope_8.svg b/vst2_bin/plugins/mscHack/res/SEQ_Envelope_8.svg new file mode 100644 index 00000000..dd93edb5 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/SEQ_Envelope_8.svg @@ -0,0 +1,1745 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/Seq_3x16x16.svg b/vst2_bin/plugins/mscHack/res/Seq_3x16x16.svg new file mode 100644 index 00000000..21210e2c --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/Seq_3x16x16.svg @@ -0,0 +1,863 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + fgdfgdfgfd + + + + + + + + SOME TEXT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/StepDelay.svg b/vst2_bin/plugins/mscHack/res/StepDelay.svg new file mode 100644 index 00000000..1b0ac535 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/StepDelay.svg @@ -0,0 +1,604 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/SynthDrums.svg b/vst2_bin/plugins/mscHack/res/SynthDrums.svg new file mode 100644 index 00000000..fed183a2 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/SynthDrums.svg @@ -0,0 +1,1538 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/TriadSequencer2.svg b/vst2_bin/plugins/mscHack/res/TriadSequencer2.svg new file mode 100644 index 00000000..165a94ba --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/TriadSequencer2.svg @@ -0,0 +1,1303 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/XFade.svg b/vst2_bin/plugins/mscHack/res/XFade.svg new file mode 100644 index 00000000..2a107a55 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/XFade.svg @@ -0,0 +1,548 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_3p_vert_simple_01.svg b/vst2_bin/plugins/mscHack/res/mschack_3p_vert_simple_01.svg new file mode 100644 index 00000000..24d9e9dd --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_3p_vert_simple_01.svg @@ -0,0 +1,83 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_3p_vert_simple_02.svg b/vst2_bin/plugins/mscHack/res/mschack_3p_vert_simple_02.svg new file mode 100644 index 00000000..f7751bc2 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_3p_vert_simple_02.svg @@ -0,0 +1,83 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_3p_vert_simple_03.svg b/vst2_bin/plugins/mscHack/res/mschack_3p_vert_simple_03.svg new file mode 100644 index 00000000..e10ba535 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_3p_vert_simple_03.svg @@ -0,0 +1,83 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_5p_filtersel_01.svg b/vst2_bin/plugins/mscHack/res/mschack_5p_filtersel_01.svg new file mode 100644 index 00000000..5b987dc1 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_5p_filtersel_01.svg @@ -0,0 +1,118 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + sdffds sdfds + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_5p_filtersel_02.svg b/vst2_bin/plugins/mscHack/res/mschack_5p_filtersel_02.svg new file mode 100644 index 00000000..13638beb --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_5p_filtersel_02.svg @@ -0,0 +1,114 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + sdffds sdfds + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_5p_filtersel_03.svg b/vst2_bin/plugins/mscHack/res/mschack_5p_filtersel_03.svg new file mode 100644 index 00000000..4bb37ae7 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_5p_filtersel_03.svg @@ -0,0 +1,114 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + sdffds sdfds + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_5p_filtersel_04.svg b/vst2_bin/plugins/mscHack/res/mschack_5p_filtersel_04.svg new file mode 100644 index 00000000..be1fb245 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_5p_filtersel_04.svg @@ -0,0 +1,114 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + sdffds sdfds + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_5p_filtersel_05.svg b/vst2_bin/plugins/mscHack/res/mschack_5p_filtersel_05.svg new file mode 100644 index 00000000..578ddd32 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_5p_filtersel_05.svg @@ -0,0 +1,126 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + sdffds sdfds + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue1_26.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue1_26.svg new file mode 100644 index 00000000..c2cadf93 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue1_26.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue2_15.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue2_15.svg new file mode 100644 index 00000000..0fdee844 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue2_15.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue2_26.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue2_26.svg new file mode 100644 index 00000000..5abc33ea --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue2_26.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue2_40.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue2_40.svg new file mode 100644 index 00000000..a3f7d1ac --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue2_40.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue2_56.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue2_56.svg new file mode 100644 index 00000000..5781e230 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue2_56.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue3_15.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue3_15.svg new file mode 100644 index 00000000..964273a2 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue3_15.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue3_20.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue3_20.svg new file mode 100644 index 00000000..6d387521 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Blue3_20.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Green1_15.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Green1_15.svg new file mode 100644 index 00000000..e35f3ab5 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Green1_15.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Green1_40.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Green1_40.svg new file mode 100644 index 00000000..2ff4825c --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Green1_40.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Purp1_15.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Purp1_15.svg new file mode 100644 index 00000000..0d82399f --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Purp1_15.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Purp1_20.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Purp1_20.svg new file mode 100644 index 00000000..540e3d50 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Purp1_20.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Red1_15.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Red1_15.svg new file mode 100644 index 00000000..ddfb9b35 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Red1_15.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Red1_20.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Red1_20.svg new file mode 100644 index 00000000..92beda56 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Red1_20.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow1_15.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow1_15.svg new file mode 100644 index 00000000..16583f01 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow1_15.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow1_26.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow1_26.svg new file mode 100644 index 00000000..ce6ed082 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow1_26.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow2_26.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow2_26.svg new file mode 100644 index 00000000..223740db --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow2_26.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow2_40.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow2_40.svg new file mode 100644 index 00000000..bde33c4e --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow2_40.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow2_56.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow2_56.svg new file mode 100644 index 00000000..27a6a222 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow2_56.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow3_15.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow3_15.svg new file mode 100644 index 00000000..444fb53a --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow3_15.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow3_20.svg b/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow3_20.svg new file mode 100644 index 00000000..3260b75d --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Knob_Yellow3_20.svg @@ -0,0 +1,73 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_PortIn_small.svg b/vst2_bin/plugins/mscHack/res/mschack_PortIn_small.svg new file mode 100644 index 00000000..c81f8ff1 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_PortIn_small.svg @@ -0,0 +1,84 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_PortOut_small.svg b/vst2_bin/plugins/mscHack/res/mschack_PortOut_small.svg new file mode 100644 index 00000000..50310031 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_PortOut_small.svg @@ -0,0 +1,84 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_Slider02_10x15.svg b/vst2_bin/plugins/mscHack/res/mschack_Slider02_10x15.svg new file mode 100644 index 00000000..d506aa06 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_Slider02_10x15.svg @@ -0,0 +1,72 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_sliderBG_01.svg b/vst2_bin/plugins/mscHack/res/mschack_sliderBG_01.svg new file mode 100644 index 00000000..c59242d4 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_sliderBG_01.svg @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_sliderBG_02.svg b/vst2_bin/plugins/mscHack/res/mschack_sliderBG_02.svg new file mode 100644 index 00000000..d1ab408c --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_sliderBG_02.svg @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_sliderKNOB_01.svg b/vst2_bin/plugins/mscHack/res/mschack_sliderKNOB_01.svg new file mode 100644 index 00000000..bef02918 --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_sliderKNOB_01.svg @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/vst2_bin/plugins/mscHack/res/mschack_square_button.svg b/vst2_bin/plugins/mscHack/res/mschack_square_button.svg new file mode 100644 index 00000000..e5bd877b --- /dev/null +++ b/vst2_bin/plugins/mscHack/res/mschack_square_button.svg @@ -0,0 +1,65 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/vst2_bin/settings.json b/vst2_bin/settings.json index 6cb8705c..ddf01467 100644 --- a/vst2_bin/settings.json +++ b/vst2_bin/settings.json @@ -1,8 +1,8 @@ { "token": "", "windowSize": [ - 640.0, - 480.0 + 1240.0, + 810.0 ], "windowPos": [ 60.0, @@ -19,4 +19,4 @@ }, "powerMeter": false, "checkVersion": true -} \ No newline at end of file +} diff --git a/vst2_bin/veeseevstrack_effect.dll__AVX2 b/vst2_bin/veeseevstrack_effect.dll__X86_LEGACY similarity index 83% rename from vst2_bin/veeseevstrack_effect.dll__AVX2 rename to vst2_bin/veeseevstrack_effect.dll__X86_LEGACY index a78ee941..74b382d0 100644 Binary files a/vst2_bin/veeseevstrack_effect.dll__AVX2 and b/vst2_bin/veeseevstrack_effect.dll__X86_LEGACY differ diff --git a/vst2_bin/veeseevstrack_instr.dll__ b/vst2_bin/veeseevstrack_instr.dll__ index 6dad2dfd..25e830af 100644 Binary files a/vst2_bin/veeseevstrack_instr.dll__ and b/vst2_bin/veeseevstrack_instr.dll__ differ diff --git a/vst2_bin/veeseevstrack_instr.dll__AVX2__ b/vst2_bin/veeseevstrack_instr.dll__X86_LEGACY__ similarity index 83% rename from vst2_bin/veeseevstrack_instr.dll__AVX2__ rename to vst2_bin/veeseevstrack_instr.dll__X86_LEGACY__ index 8d550fb5..7cd62293 100644 Binary files a/vst2_bin/veeseevstrack_instr.dll__AVX2__ and b/vst2_bin/veeseevstrack_instr.dll__X86_LEGACY__ differ diff --git a/vst2_common_msvc_pre.mk b/vst2_common_msvc_pre.mk index 9dc98227..dbfbf5d7 100644 --- a/vst2_common_msvc_pre.mk +++ b/vst2_common_msvc_pre.mk @@ -2,6 +2,14 @@ EXTRAFLAGS+= -DARCH_WIN EXTRAFLAGS+= -DVST2_REPARENT_WINDOW_HACK EXTRAFLAGS+= -I../../dev/vstsdk2.4/pluginterfaces/vst2.x/ -EXTRALIBS= Rack.lib -LIBPATH:dep/lib/msvc/ libspeexdsp.lib glew.lib glfw.lib opengl32.lib gdi32.lib user32.lib kernel32.lib Comdlg32.lib Shell32.lib ws2_32.lib winmm.lib +EXTRALIBS= Rack.lib + +ifeq ($(BUILD_64),y) +EXTRALIBS+= -LIBPATH:dep/lib/msvc/x64 +else +EXTRALIBS+= -LIBPATH:dep/lib/msvc/x86 +endif + +EXTRALIBS+= libspeexdsp.lib glew.lib glfw.lib opengl32.lib gdi32.lib user32.lib kernel32.lib Comdlg32.lib Shell32.lib ws2_32.lib winmm.lib plugin_lib = $(PLUGIN_DIR)/$(1)/$(1).lib diff --git a/vst2_common_staticlibs.mk b/vst2_common_staticlibs.mk index 8766e8b1..36153e76 100644 --- a/vst2_common_staticlibs.mk +++ b/vst2_common_staticlibs.mk @@ -5,6 +5,7 @@ EXTRALIBS+= $(call plugin_lib,Befaco) EXTRALIBS+= $(call plugin_lib,Bidoo) EXTRALIBS+= $(call plugin_lib,Bogaudio) EXTRALIBS+= $(call plugin_lib,cf) +EXTRALIBS+= $(call plugin_lib,DHE-Modules) EXTRALIBS+= $(call plugin_lib,ErraticInstruments) EXTRALIBS+= $(call plugin_lib,ESeries) EXTRALIBS+= $(call plugin_lib,FrozenWasteland) @@ -16,6 +17,7 @@ EXTRALIBS+= $(call plugin_lib,LindenbergResearch) EXTRALIBS+= $(call plugin_lib,LOGinstruments) EXTRALIBS+= $(call plugin_lib,ML_modules) EXTRALIBS+= $(call plugin_lib,modular80) +EXTRALIBS+= $(call plugin_lib,mscHack) EXTRALIBS+= $(call plugin_lib,mtsch-plugins) EXTRALIBS+= $(call plugin_lib,NauModular) #EXTRALIBS+= $(call plugin_lib,ParableInstruments)