aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt299
-rw-r--r--Plugin.cmake14
-rw-r--r--README.md13
-rw-r--r--cmake/CompilerOptimizations.cmake53
-rw-r--r--cmake/Modules/FindCsound.cmake53
-rw-r--r--examples/test.csd6
-rw-r--r--examples/test2.csd61
-rw-r--r--src/opcodes.cpp6
8 files changed, 352 insertions, 153 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f88e6a1..612d056 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,178 +1,203 @@
-project("csound_sdl")
+# from https://github.com/csound/plugins : common CMake operations
+cmake_minimum_required(VERSION 2.8.12)
+project(Csound-plugins)
-cmake_minimum_required(VERSION 3.8)
-
-set(APIVERSION "6.0")
+if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
+ set(CMAKE_COMPILER_IS_CLANG 1)
+endif()
-# Release or Debug
-set(CMAKE_BUILD_TYPE "Release")
+# C++11 needed
+if(NOT MSVC)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+endif()
-# force make to print the command lines
-set(CMAKE_VERBOSE_MAKEFILE on)
+set(APIVERSION "6.0")
-# path to Csound cmake module
+set(CMAKE_MACOSX_RPATH 1)
+set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
-# set compilation flags
-set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11 -fpermissive -fPIC -w -DUSE_DOUBLE -DB64BIT")
-
-# options
-option(USE_LIB64 "Set to on to set installation dir for libs to lib64" OFF)
-option(USE_DOUBLE "Use doubles for audio calculations" ON)
-option(CPP11 "c++11" ON)
-
-set(BUILDING_CSOUND_PLUGINS ON)
-
-# ----------------------------------------------
-
-include(FindCsound)
-include(FindSDL2)
-
+include(TestBigEndian)
+include(CheckFunctionExists)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
-# -----------------------------------------------
-
-function(addflag flag flagname)
- check_c_compiler_flag(${flag} ${flagname})
- if (${flagname})
- # message(STATUS "Setting C flag ${flag}")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
- endif()
- check_cxx_compiler_flag(${flag} CXX_${flagname})
- if (CXX_${flagname})
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
- endif()
-endfunction(addflag)
-
-
-MACRO(SUBDIRLIST result curdir)
- FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
- SET(dirlist "")
- FOREACH(child ${children})
- message(STATUS "looking at ${child}")
- IF(IS_DIRECTORY ${curdir}/${child})
- LIST(APPEND dirlist ${child})
- ENDIF()
- ENDFOREACH()
- SET(${result} ${dirlist})
-ENDMACRO()
-
-
-MACRO(ADD_ALL_SUBDIRECTORIES directory)
- subdirlist(SUBDIRS ${directory})
- message(STATUS "Found subdirs: ${SUBDIRS}")
- foreach(SUBDIR ${SUBDIRS})
- set(thissubdir "${directory}/${SUBDIR}")
- if(EXISTS "${directory}/${SUBDIR}/CMakeLists.txt")
- message(STATUS "Adding subdir: ${thissubdir}")
- add_subdirectory(${directory}/${SUBDIR})
- else()
- message(WARNING "Skipping ${directory}/${SUBDIR} because no CMakeLists.txt file was found")
- endif()
- endforeach()
-ENDMACRO()
-
-
+### COMPILER OPTIMIZATION FLAGS
+option(USE_COMPILER_OPTIMIZATIONS "Use the default Csound compiler optimization flags" ON)
+if(USE_COMPILER_OPTIMIZATIONS)
+ include(${CMAKE_SOURCE_DIR}/cmake/CompilerOptimizations.cmake)
+endif()
-# set optimization flags
-if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
- add_definitions(-fvisibility=hidden)
- if(NATIVE)
- add_definitions(-march=native)
- endif()
-
- include(CheckCCompilerFlag)
- include(CheckCXXCompilerFlag)
+if(APPLE)
+ set(OSX_VERSION " ")
+endif()
- addflag(-msse HAS_SSE)
- addflag(-msse2 HAS_SSE2)
- addflag(-mfgpath=sse HAS_FPMATH_SSE)
-
+## USER OPTIONS ##
+# Optional targets, they should all default to ON (check_deps will disable them if not possible to build)
+option(USE_DOUBLE "Set to use double-precision floating point for audio samples." ON)
+option(USE_LRINT "Use lrint/lrintf for converting floating point values to integers." ON)
+option(BUILD_RELEASE "Build for release" ON)
+option(USE_GIT_COMMIT "Show the git commit in version information" ON)
+
+# in Release configuration, set NDEBUG
+if(${CMAKE_BUILD_TYPE} MATCHES "Release")
+message("-----> Release mode")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG")
+elseif(${CMAKE_BUILD_TYPE} MATCHES "Debug")
+message("-----> Debug mode")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBETA")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBETA")
endif()
-if(MINGW)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mstackrealign")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mstackrealign")
+# set -Werror if in Debug configuration
+if(NOT MSVC AND NOT WASM)
+ set(CMAKE_CXX_FLAGS_RELEASE "-O3 ")
+ set(CMAKE_C_FLAGS_RELEASE "-O3 ")
+ if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-missing-field-initializers")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wno-missing-field-initializers")
+ endif()
endif()
-addflag(-ftree-vectorize HAS_TREE_VECTORIZE)
-addflag(-ffast-math HAS_FAST_MATH)
-addflag(-fomit-frame-pointer HAS_OMIT_FRAME_POINTER)
+if(CMAKE_SYSTEM_NAME MATCHES "Linux")
+ set(LINUX YES)
+else()
+ set(LINUX NO)
+endif()
-# -------------------------------------------------------------------
+set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
-set(CS_FRAMEWORK_DEST "~/Library/Frameworks")
+check_c_compiler_flag(-fvisibility=hidden HAS_VISIBILITY_HIDDEN)
+check_cxx_compiler_flag(-fvisibility=hidden HAS_CXX_VISIBILITY_HIDDEN)
+if (HAS_VISIBILITY_HIDDEN)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
+endif()
+if (HAS_CXX_VISIBILITY_HIDDEN)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+endif()
+
+check_c_compiler_flag(-std=gnu99 HAS_GNU99)
+if (HAS_GNU99)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
+endif()
+if (HAS_CXX_VISIBILITY_HIDDEN)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+endif()
+find_package(Csound)
+option(USE_LIB64 "Set to on to set installation directory for libraries to lib64" OFF)
if(USE_LIB64)
- set(LIBRARY_INSTALL_DIR "lib64")
- add_definitions("-DLIB64")
+ set(LIBRARY_INSTALL_DIR "lib64")
+ add_definitions("-DLIB64")
else()
- set(LIBRARY_INSTALL_DIR "lib")
+ set(LIBRARY_INSTALL_DIR "lib")
endif()
-
message(STATUS "LIBRARY INSTALL DIR: ${LIBRARY_INSTALL_DIR}")
-# -------------------------------------------------------------------
-
-
if(USE_DOUBLE)
- message(STATUS ">>> using doubles")
-
- if(APPLE)
- set(CSOUNDLIB "CsoundLib64")
- set(PLUGIN_INSTALL_DIR "${CS_FRAMEWORK_DEST}/${CSOUNDLIB}.framework/Versions/${APIVERSION}/Resources/Opcodes64")
- else()
- set(CSOUNDLIB "csound64")
+ message(STATUS "Building with 64-bit floats")
set(PLUGIN_INSTALL_DIR "${LIBRARY_INSTALL_DIR}/csound/plugins64-${APIVERSION}")
- endif()
+ if(APPLE)
+ set(PLUGIN_INSTALL_DIR "${CS_FRAMEWORK_DEST}/${CSOUNDLIB}.framework/Versions/${APIVERSION}/Resources/Opcodes64")
+ endif()
else()
- message(STATUS ">>> not using doubles")
- if(APPLE)
- set(CSOUNDLIB "CsoundLib")
- set(PLUGIN_INSTALL_DIR "${CS_FRAMEWORK_DEST}/${CSOUNDLIB}.framework/Versions/${APIVERSION}/Resources/Opcodes")
- else()
- set(CSOUNDLIB "csound")
+ message(STATUS "Building with 32-bit floats")
set(PLUGIN_INSTALL_DIR "${LIBRARY_INSTALL_DIR}/csound/plugins-${APIVERSION}")
- endif()
-endif()
-
-
-# -------------------------------------------------------------------
-
-# Csound opcode build
-find_package(Csound)
-
-
-set(BUILD_PLUGINS_DIR ${CMAKE_CURRENT_BINARY_DIR})
-
-if(NOT CSOUND_FOUND)
- message(FATAL_ERROR "Csound installation not found")
+ if(APPLE)
+ set(PLUGIN_INSTALL_DIR "${CS_FRAMEWORK_DEST}/${CSOUNDLIB}.framework/Versions/${APIVERSION}/Resources/Opcodes")
+ endif()
endif()
-if(NOT SDL2_FOUND)
- message(FATAL_ERROR "SDL2 cannot be found")
-endif()
+# Checks if dependencies for an enabled target are fulfilled.
+# If FAIL_MISSING is true and the dependencies are not fulfilled,
+# it will abort the cmake run.
+# If FAIL_MISSING is false, it will set the option to OFF.
+# If the target is not enabled, it will do nothing.
+# example: check_deps(BUILD_NEW_PARSER FLEX_EXECUTABLE BISON_EXECUTABLE)
+function(check_deps option)
+ if(${option})
+ set(i 1)
+ while( ${i} LESS ${ARGC} )
+ set(dep ${ARGV${i}})
+ if(NOT ${dep})
+ if(FAIL_MISSING)
+ message(FATAL_ERROR
+ "${option} is enabled, but ${dep}=\"${${dep}}\"")
+ else()
+ message(STATUS "${dep}=\"${${dep}}\", so disabling ${option}")
+ set(${option} OFF PARENT_SCOPE)
+ # Set it in the local scope too
+ set(${option} OFF)
+ endif()
+ endif()
+ math(EXPR i "${i}+1")
+ endwhile()
+ endif()
+ if(${option})
+ message(STATUS "${option} is enabled.")
+ else()
+ message(STATUS "${option} is disabled.")
+ endif()
+endfunction(check_deps)
+
+# Utility function to make plugins. All plugin targets should use this as it
+# sets up output directory set in top-level CmakeLists.txt
+# and adds the appropriate install target
+#
+# libname - name of library to produce
+# srcs - list of src files (must be quoted if a list)
+# extralibs (OPTIONAL) - extra libraries to link the plugin to
+#
+# NB - this was moved here as it needs some VARS defined above
+# for setting up the framework
+function(make_plugin libname srcs)
+ if(APPLE)
+ add_library(${libname} SHARED ${srcs})
+ else()
+ add_library(${libname} MODULE ${srcs})
+ endif()
-set(CPPFILES src/opcodes.cpp)
+ set(i 2)
+ while( ${i} LESS ${ARGC} )
+ target_link_libraries(${libname} ${ARGV${i}})
+ math(EXPR i "${i}+1")
+ endwhile()
+ set_target_properties(${libname} PROPERTIES
+ RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+ install(TARGETS ${libname}
+ LIBRARY DESTINATION "${PLUGIN_INSTALL_DIR}"
+ ARCHIVE DESTINATION "${PLUGIN_INSTALL_DIR}" )
+endfunction(make_plugin)
-include_directories(${CSOUND_INCLUDE_DIRS})
-include_directories(include)
+# Linux does not have a separate libintl, it is part of libc
+set(LIBINTL_AVAIL (LIBINTL_LIBRARY OR LINUX))
+if(LINUX)
+ message(STATUS "Building on Linux.")
+ add_definitions(-DLINUX -DPIPES -D_GNU_SOURCE -DHAVE_SOCKETS)
+ list(APPEND libcsound_LIBS ${MATH_LIBRARY} dl)
-link_libraries(${SDL2_LIBRARY})
-include_directories(${SDL2_INCLUDE_DIR})
+endif()
-add_library(sdl SHARED ${CPPFILES})
+if(APPLE AND NOT IOS)
+ message(STATUS "Building on OSX")
+ add_definitions(-DMACOSX -DPIPES -DNO_FLTK_THREADS -DHAVE_SOCKETS)
+ find_library(ACCELERATE_LIBRARY Accelerate)
+ find_path(VECLIB_PATH "Accelerate/Accelerate.h")
+ include_directories(${VECLIB_PATH})
+ list(APPEND libcsound_LIBS ${MATH_LIBRARY} dl ${ACCELERATE_LIBRARY})
+endif()
-set_target_properties(sdl PROPERTIES
- RUNTIME_OUTPUT_DIRECTORY ${BUILD_PLUGINS_DIR}
- LIBRARY_OUTPUT_DIRECTORY ${BUILD_PLUGINS_DIR})
-
-install(TARGETS sdl LIBRARY DESTINATION "${PLUGIN_INSTALL_DIR}" )
+if(WIN32)
+ add_definitions(-DWIN32)
+endif()
+include(Plugin.cmake)
diff --git a/Plugin.cmake b/Plugin.cmake
new file mode 100644
index 0000000..34c700b
--- /dev/null
+++ b/Plugin.cmake
@@ -0,0 +1,14 @@
+set(PLUGIN_NAME sdl)
+set(INCLUDES ${CSOUND_INCLUDE_DIRS})
+set(LIBS "")
+
+# Dependencies
+find_package(SDL2)
+check_deps(SDL2_FOUND)
+list(APPEND LIBS ${SDL2_LIBRARY})
+list(APPEND INCLUDES ${SDL2_INCLUDE_DIR})
+
+# Source files
+set(CPPFILES src/opcodes.cpp)
+make_plugin(${PLUGIN_NAME} "${CPPFILES}" ${LIBS})
+target_include_directories(${PLUGIN_NAME} PRIVATE ${INCLUDES})
diff --git a/README.md b/README.md
index ef0aecc..52a3bdf 100644
--- a/README.md
+++ b/README.md
@@ -4,12 +4,12 @@ csound-sdl provides a simple interface for (currently quite) low level SDL calls
## Requirements
- Csound libraries
- - Cmake
+ - Cmake >= 2.8.12
- LibSDL2
## Building
-Create a build directory at the top of the source tree, execute *cmake ..*, *make* and optionally *make install* as root. If the latter is not used/possible then the resulting libsdl.so can be used with the *--opcode-lib* flag in Csound. eg:
+Create a build directory at the top of the source tree, execute *cmake ..*, *make* and optionally *make install* as root. If the latter is not used/possible then the resulting module can be used with the *--opcode-lib* flag in Csound. eg:
cd csound-sdl
mkdir build && cd build
@@ -20,7 +20,9 @@ Create a build directory at the top of the source tree, execute *cmake ..*, *mak
## Opcode overview
### sdlinit
*ihandle, kmousetrigger, kmousex, kmousey sdlinit Swindowname, iwidth, iheight, ifps*
+
Initialise the SDL window.
+
- ihandle: the handle to be used by further SDL opcodes to write to that window
- kmousetrigger: fires when mouse button is clicked in the window
- kmousex: reports mouse X position in window, normalised from 0 to 1
@@ -33,7 +35,9 @@ Initialise the SDL window.
### sdlcolour
*ihandle sdlcolour kred, kgreen, kblue, kalpha*
+
Set a colour to be used in later drawing.
+
- ihandle: the handle for the colour to be used by further SDL opcodes
- kred: red amount with range 0 to 255
@@ -43,7 +47,9 @@ Set a colour to be used in later drawing.
### sdlrect
*sdlrect iwindow, icolour, kx, ky, kwidth, kheight*
+
Create a rectangle.
+
- iwindow: the window handle from sdlinit
- icolour: the colour handle from sdlcolour
- kx: X position
@@ -53,10 +59,13 @@ Create a rectangle.
## sdlline
*sdlline iwindow, icolour, kx1, ky1, kx2, ky2*
+
Create a line.
+
- iwindow: the window handle from sdlinit
- icolour: the colour handle from sdlcolour
- kx1: X position of start point
- ky1: Y position of start point
- kx2: X position of end point
- ky2: Y position of end point
+
diff --git a/cmake/CompilerOptimizations.cmake b/cmake/CompilerOptimizations.cmake
new file mode 100644
index 0000000..543daf8
--- /dev/null
+++ b/cmake/CompilerOptimizations.cmake
@@ -0,0 +1,53 @@
+
+check_c_compiler_flag(-ftree-vectorize HAS_TREE_VECTORIZE)
+check_cxx_compiler_flag(-ftree-vectorize HAS_CXX_TREE_VECTORIZE)
+if (HAS_TREE_VECTORISE)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftree-vectorize")
+endif()
+if (HAS_CXX_TREE_VECTORISE)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftree-vectorize")
+endif()
+
+
+check_c_compiler_flag(-ffast-math HAS_FAST_MATH)
+check_cxx_compiler_flag(-ffast-math HAS_CXX_FAST_MATH)
+if (HAS_FAST_MATH AND NOT MINGW)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffast-math")
+endif()
+if (HAS_CXX_FAST_MATH AND NOT MINGW)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math")
+endif()
+
+
+
+if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+check_c_compiler_flag(-mfpmath=sse HAS_FPMATH_SSE)
+check_cxx_compiler_flag(-mfpmath=sse HAS_CXX_FPMATH_SSE)
+ if (HAS_FPMATH_SSE)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpmath=sse")
+endif()
+if (HAS_CXX_FPMATH_SSE)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=sse")
+endif()
+
+endif()
+
+
+check_c_compiler_flag(-msse2 HAS_SSE2)
+check_cxx_compiler_flag(-msse2 HAS_CXX_SSE2)
+ if (HAS_SSE2 AND NOT IOS AND NOT WASM)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
+endif()
+if (HAS_CXX_SSE2 AND NOT IOS AND NOT WASM)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
+endif()
+
+
+check_c_compiler_flag(-fomit-frame-pointer HAS_OMIT_FRAME_POINTER)
+check_cxx_compiler_flag(-fomit-frame-pointer HAS_CXX_OMIT_FRAME_POINTER)
+if (HAS_OMIT_FRAME_POINTER)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer")
+endif()
+if (HAS_CXX_OMIT_FRAME_POINTER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fomit-frame-pointer")
+endif()
diff --git a/cmake/Modules/FindCsound.cmake b/cmake/Modules/FindCsound.cmake
index e55b269..24c90d9 100644
--- a/cmake/Modules/FindCsound.cmake
+++ b/cmake/Modules/FindCsound.cmake
@@ -4,20 +4,53 @@
# CSOUND_INCLUDE_DIRS - The Csound include directories.
# CSOUND_LIBRARIES - The libraries needed to use the Csound library.
-if(APPLE)
-find_path(CSOUND_INCLUDE_DIR csound.h HINTS /Library/Frameworks/CsoundLib64.framework/Headers
-"$ENV{HOME}/Library/Frameworks/CsoundLib64.framework/Headers")
-else()
-find_path(CSOUND_INCLUDE_DIR csound.h PATH_SUFFIXES csound)
-endif()
+# RKnight 2021-07-21 : quick copy paste hack to deal with 32 bit if not using double
+
+if(USE_DOUBLE)
+ # 64 bit
+ if(APPLE)
+ find_path(CSOUND_INCLUDE_DIR csound.h HINTS /Library/Frameworks/CsoundLib64.framework/Headers
+ "$ENV{HOME}/Library/Frameworks/CsoundLib64.framework/Headers")
+ elseif(WIN32)
+ find_path(CSOUND_INCLUDE_DIR csound.h PATH_SUFFIXES csound
+ HINTS "c:\\Program Files\\Csound6_x64\\include")
+ else()
+ find_path(CSOUND_INCLUDE_DIR csound.h PATH_SUFFIXES csound)
+ endif()
+
+ if(APPLE)
+ find_library(CSOUND_LIBRARY NAMES CsoundLib64 HINTS /Library/Frameworks/CsoundLib64.framework/
+ "$ENV{HOME}/Library/Frameworks/CsoundLib64.framework")
+ elseif(WIN32)
+ find_library(CSOUND_LIBRARY NAMES csound64 HINTS "c:\\Program Files\\Csound6_x64\\lib")
+ else()
+ find_library(CSOUND_LIBRARY NAMES csound64 csound)
+ endif()
-if(APPLE)
-find_library(CSOUND_LIBRARY NAMES CsoundLib64 HINTS /Library/Frameworks/CsoundLib64.framework/
-"$ENV{HOME}/Library/Frameworks/CsoundLib64.framework")
else()
-find_library(CSOUND_LIBRARY NAMES csound64 csound)
+ # 32 bit
+ if(APPLE)
+ find_path(CSOUND_INCLUDE_DIR csound.h HINTS /Library/Frameworks/CsoundLib.framework/Headers
+ "$ENV{HOME}/Library/Frameworks/CsoundLib.framework/Headers")
+ elseif(WIN32)
+ find_path(CSOUND_INCLUDE_DIR csound.h PATH_SUFFIXES csound
+ HINTS "c:\\Program Files (x86)\\Csound6\\include")
+ else()
+ find_path(CSOUND_INCLUDE_DIR csound.h PATH_SUFFIXES csound)
+ endif()
+
+ if(APPLE)
+ find_library(CSOUND_LIBRARY NAMES CsoundLib HINTS /Library/Frameworks/CsoundLib.framework/
+ "$ENV{HOME}/Library/Frameworks/CsoundLib.framework")
+ elseif(WIN32)
+ find_library(CSOUND_LIBRARY NAMES csound HINTS "c:\\Program Files (x86)\\Csound6\\lib")
+ else()
+ find_library(CSOUND_LIBRARY NAMES csound csound)
+ endif()
+
endif()
+
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set CSOUND_FOUND to TRUE
# if all listed variables are TRUE
diff --git a/examples/test.csd b/examples/test.csd
index 3e528cf..e5e80f1 100644
--- a/examples/test.csd
+++ b/examples/test.csd
@@ -1,7 +1,6 @@
<CsoundSynthesizer>
<CsOptions>
-odac
---opcode-lib=/home/bargepole/bpcheckout/csound-dev/sdltest/sdllib.so
</CsOptions>
<CsInstruments>
sr = 44100
@@ -9,6 +8,11 @@ kr = 4410
nchnls = 2
0dbfs = 1
seed 0
+/*
+ SDL example 1
+ Oscillator triggering a rectangle, a moving line and mouse input
+*/
+
gisdl init -1
gicol init -1
diff --git a/examples/test2.csd b/examples/test2.csd
new file mode 100644
index 0000000..3e0dfa3
--- /dev/null
+++ b/examples/test2.csd
@@ -0,0 +1,61 @@
+<CsoundSynthesizer>
+<CsOptions>
+-odac
+-m0
+</CsOptions>
+<CsInstruments>
+sr = 44100
+kr = 441
+nchnls = 2
+0dbfs = 1
+seed 0
+/*
+ SDL Example 2
+ Mouse triggered clusters of rectangles
+*/
+
+gisdl init -1
+gicol init -1
+
+instr 1
+ gisdl, ktrig, kx, ky sdlinit "A SDL Window", 1000, 1000, 30
+ schedkwhen ktrig, 0.05, 0, 2, 0, 1, kx, ky
+ kc = abs(oscil(40, 0.2))
+ ibg sdlcolour kc, kc, kc, 0
+ sdlrect gisdl, ibg, 0, 0, 10, 10
+endin
+
+
+instr 2
+ ix init p4
+ iy init p5
+ inum random 5, 20
+ index = 0
+ while (index < inum) do
+ event_i "i", 3, random(0, 0.5), random(0.5, 1.5), random(ix-0.05, ix+0.05), random(iy-0.05, iy+0.05)
+ index += 1
+ od
+endin
+
+instr 3
+ kc1 line 0, p3, random(100, 255)
+ kc2 line 0, p3, random(100, 255)
+ icol sdlcolour kc1, kc2, kc2, 255
+ kx init p4
+ ky init p5
+ isize random 0.01, 0.05
+ sdlrect gisdl, icol, kx, ky, isize, isize
+
+ iamp = 0.3 + (p5*0.7)
+ kamp line iamp, p3, 0
+ ipitch = 100 + (p4*1000)
+ a1 oscil kamp, ipitch
+ outs a1*0.01, a1*0.01
+endin
+
+
+</CsInstruments>
+<CsScore>
+i1 0 6000
+</CsScore>
+</CsoundSynthesizer>
diff --git a/src/opcodes.cpp b/src/opcodes.cpp
index 1531029..04be9e8 100644
--- a/src/opcodes.cpp
+++ b/src/opcodes.cpp
@@ -103,17 +103,17 @@ struct sdlinit : csnd::Plugin<4, 4> {
sdl->screen_height = ySize;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
- throw std::runtime_error(csound->strdup(SDL_GetError()));
+ throw std::runtime_error(csound->strdup((char*) SDL_GetError()));
}
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
sdl->window = SDL_CreateWindow(windowName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, xSize, ySize, SDL_WINDOW_SHOWN );
if (sdl->window == NULL) {
- throw std::runtime_error(csound->strdup(SDL_GetError()));
+ throw std::runtime_error(csound->strdup((char*) SDL_GetError()));
}
sdl->renderer = SDL_CreateRenderer(sdl->window, -1, SDL_RENDERER_ACCELERATED);
if (sdl->renderer == NULL) {
- throw std::runtime_error(csound->strdup(SDL_GetError()));
+ throw std::runtime_error(csound->strdup((char*) SDL_GetError()));
}
sdl->initialised = true;
}